| | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ycl.dto.UmsMenuNode; |
| | | import com.ycl.entity.dict.DataDictionary; |
| | | import com.ycl.entity.user.*; |
| | | import com.ycl.mapper.dict.DataDictionaryMapper; |
| | | import com.ycl.mapper.dict.DataDictionary2Mapper; |
| | | import com.ycl.mapper.user.UmsMenuMapper; |
| | | import com.ycl.mapper.user.UmsResourceMapper; |
| | | import com.ycl.mapper.user.UmsRoleMapper; |
| | | import com.ycl.service.user.UmsAdminCacheService; |
| | | import com.ycl.service.user.UmsRoleMenuRelationService; |
| | | import com.ycl.service.user.UmsRoleResourceRelationService; |
| | | import com.ycl.service.user.UmsRoleService; |
| | | import com.ycl.service.user.*; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | |
| | | * Created by macro on 2018/9/30. |
| | | */ |
| | | @Service |
| | | public class UmsRoleServiceImpl extends ServiceImpl<UmsRoleMapper, UmsRole>implements UmsRoleService { |
| | | public class UmsRoleServiceImpl extends ServiceImpl<UmsRoleMapper, UmsRole> implements UmsRoleService { |
| | | @Autowired |
| | | private UmsAdminCacheService adminCacheService; |
| | | @Autowired |
| | | private UmsRoleMenuRelationService roleMenuRelationService; |
| | | @Autowired |
| | | private UmsRoleResourceRelationService roleResourceRelationService; |
| | | |
| | | private UmsMenuService umsMenuService; |
| | | |
| | | @Autowired |
| | | public void setUmsMenuService(UmsMenuService umsMenuService) { |
| | | this.umsMenuService = umsMenuService; |
| | | } |
| | | |
| | | @Resource |
| | | private UmsMenuMapper umsMenuMapper; |
| | | @Resource |
| | | private UmsResourceMapper umsResourceMapper; |
| | | @Resource |
| | | private DataDictionaryMapper dataDictionaryMapper; |
| | | private DataDictionary2Mapper dataDictionary2Mapper; |
| | | |
| | | @Override |
| | | public boolean create(UmsRole role) { |
| | | role.setCreateTime(new Date()); |
| | |
| | | |
| | | @Override |
| | | public Page<UmsRole> list(String keyword, Integer pageSize, Integer pageNum) { |
| | | Page<UmsRole> page = new Page<>(pageNum,pageSize); |
| | | Page<UmsRole> page = new Page<>(pageNum, pageSize); |
| | | QueryWrapper<UmsRole> wrapper = new QueryWrapper<>(); |
| | | LambdaQueryWrapper<UmsRole> lambda = wrapper.lambda(); |
| | | if(StrUtil.isNotEmpty(keyword)){ |
| | | lambda.like(UmsRole::getName,keyword); |
| | | if (StrUtil.isNotEmpty(keyword)) { |
| | | lambda.like(UmsRole::getName, keyword); |
| | | } |
| | | Page<UmsRole> resultPage = page(page, wrapper); |
| | | List<UmsRole> roles = resultPage.getRecords(); |
| | | List<Long> types = roles.stream().map(UmsRole::getType).collect(Collectors.toList()); |
| | | |
| | | LambdaQueryWrapper<DataDictionary> dicQuery = new LambdaQueryWrapper<>(); |
| | | dicQuery.in(DataDictionary::getId, types); |
| | | List<DataDictionary> dics = dataDictionaryMapper.selectList(dicQuery); |
| | | for (UmsRole role : roles) { |
| | | for (DataDictionary dic : dics) { |
| | | if (dic.getId().equals(role.getType())) { |
| | | role.setTypeText(dic.getName()); |
| | | if (types.size() > 0) { |
| | | LambdaQueryWrapper<DataDictionary> dicQuery = new LambdaQueryWrapper<>(); |
| | | dicQuery.in(DataDictionary::getId, types); |
| | | List<DataDictionary> dics = dataDictionary2Mapper.selectList(dicQuery); |
| | | for (UmsRole role : roles) { |
| | | for (DataDictionary dic : dics) { |
| | | if (dic.getId().equals(role.getType())) { |
| | | role.setTypeText(dic.getName()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | @Override |
| | | public List<UmsMenu> getMenuList(Long adminId) { |
| | | return umsMenuMapper.getMenuList(adminId); |
| | | public List<UmsMenuNode> getMenuList(Long adminId) { |
| | | List<UmsMenu> menuList = umsMenuMapper.getMenuList(adminId); |
| | | List<UmsMenuNode> result = menuList.stream() |
| | | .filter(menu -> menu.getParentId().equals(0L)) |
| | | .map(menu -> umsMenuService.covertMenuNode(menu, menuList)).collect(Collectors.toList()); |
| | | return result; |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public List<UmsRole> getRoleListByCodes(List<String> codes) { |
| | | LambdaQueryWrapper<UmsRole> wrapper = new LambdaQueryWrapper<UmsRole>().in(UmsRole::getCode, codes); |
| | | return baseMapper.selectList(wrapper); |
| | | } |
| | | |
| | | @Override |
| | |
| | | public int allocMenu(Long roleId, List<Long> menuIds) { |
| | | //先删除原有关系 |
| | | QueryWrapper<UmsRoleMenuRelation> wrapper = new QueryWrapper<>(); |
| | | wrapper.lambda().eq(UmsRoleMenuRelation::getRoleId,roleId); |
| | | wrapper.lambda().eq(UmsRoleMenuRelation::getRoleId, roleId); |
| | | roleMenuRelationService.remove(wrapper); |
| | | //批量插入新关系 |
| | | List<UmsRoleMenuRelation> relationList = new ArrayList<>(); |
| | |
| | | public int allocResource(Long roleId, List<Long> resourceIds) { |
| | | //先删除原有关系 |
| | | QueryWrapper<UmsRoleResourceRelation> wrapper = new QueryWrapper<>(); |
| | | wrapper.lambda().eq(UmsRoleResourceRelation::getRoleId,roleId); |
| | | wrapper.lambda().eq(UmsRoleResourceRelation::getRoleId, roleId); |
| | | roleResourceRelationService.remove(wrapper); |
| | | //批量插入新关系 |
| | | List<UmsRoleResourceRelation> relationList = new ArrayList<>(); |
| | |
| | | public Boolean updateStatusBatch(List<Long> ids, Integer status) { |
| | | List<UmsRole> roles = new ArrayList<>(); |
| | | for (Long id : ids) { |
| | | UmsRole umsRole = UmsRole.builder(). |
| | | UmsRole umsRole = UmsRole.builder(). |
| | | id(id).status(status).build(); |
| | | roles.add(umsRole); |
| | | } |
| | | updateBatchById(roles,roles.size()); |
| | | updateBatchById(roles, roles.size()); |
| | | adminCacheService.delResourceListByRoleIds(ids); |
| | | return true; |
| | | } |