New file |
| | |
| | | package com.ycl.service.user.impl; |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ycl.api.BasePageDTO; |
| | | import com.ycl.entity.depart.UmsDepart; |
| | | import com.ycl.entity.user.*; |
| | | import com.ycl.mapper.user.AdminMenuRelationMapper; |
| | | import com.ycl.mapper.user.UmsAdminRoleRelationMapper; |
| | | import com.ycl.mapper.user.UmsDepartManageMapper; |
| | | import com.ycl.mapper.user.UmsRoleMenuRelationMapper; |
| | | import com.ycl.service.depart.UmsDepartService; |
| | | import com.ycl.service.user.UmsAdminService; |
| | | import com.ycl.service.user.UmsDepartManageService; |
| | | import com.ycl.vo.depart.DepartVO; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * <p> |
| | | * 服务实现类 |
| | | * </p> |
| | | * |
| | | * @author lyq |
| | | * @since 2022-09-09 |
| | | */ |
| | | @Service |
| | | public class UmsDepartManageServiceImpl extends ServiceImpl<UmsDepartManageMapper, UmsDepartManage> implements UmsDepartManageService { |
| | | |
| | | @Resource |
| | | private UmsDepartManageMapper umsDepartManageMapper; |
| | | @Resource |
| | | private UmsDepartService sccgDepartService; |
| | | @Resource |
| | | private UmsAdminService umsAdminService; |
| | | @Resource |
| | | UmsAdminRoleRelationMapper umsAdminRoleRelationMapper; |
| | | @Resource |
| | | AdminMenuRelationMapper adminMenuRelationMapper; |
| | | @Resource |
| | | UmsRoleMenuRelationMapper roleMenuRelationMapper; |
| | | |
| | | @Override |
| | | public List<UmsDepartManage> queryByDepartId(Long departId) { |
| | | List<UmsDepartManage> umsAdminDeparts = umsDepartManageMapper.selectList(new LambdaQueryWrapper<UmsDepartManage>() |
| | | .eq(UmsDepartManage::getDepartId, departId)); |
| | | if (CollUtil.isNotEmpty(umsAdminDeparts)) { |
| | | return umsAdminDeparts; |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | @Override |
| | | public List<UmsDepartManage> queryByUserId(long userId) { |
| | | List<UmsDepartManage> umsAdminDeparts = umsDepartManageMapper.selectList(new LambdaQueryWrapper<UmsDepartManage>().eq(UmsDepartManage::getUserId, userId)); |
| | | if (CollUtil.isNotEmpty(umsAdminDeparts)) { |
| | | return umsAdminDeparts; |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | @Override |
| | | public void deletedByDepartId(long departId) { |
| | | umsDepartManageMapper.deletedByDepartId(departId); |
| | | } |
| | | |
| | | @Override |
| | | public BasePageDTO belongDepart(long userId, int current, int pageSize) { |
| | | BasePageDTO basePageDTO = new BasePageDTO(); |
| | | Long count = umsDepartManageMapper.selectCount(new LambdaQueryWrapper<UmsDepartManage>().eq(UmsDepartManage::getUserId, userId)); |
| | | basePageDTO.setTotal(count); |
| | | if (count > 0) { |
| | | current = (current - 1) * pageSize; |
| | | List<UmsDepartManage> departList = umsDepartManageMapper.selectPageByUserId(userId, current, pageSize); |
| | | List<DepartVO.AdminDepartInfoVO> adminDepartInfoVOS = new ArrayList<>(); |
| | | DepartVO.AdminDepartInfoVO adminDepartInfoVO = null; |
| | | for (UmsDepartManage umsAdminDepart : departList) { |
| | | adminDepartInfoVO = new DepartVO.AdminDepartInfoVO(); |
| | | UmsDepart sccgDepart = sccgDepartService.loadDepartById(umsAdminDepart.getDepartId()); |
| | | UmsAdmin umsAdmin = umsAdminService.getById(userId); |
| | | adminDepartInfoVO.setDepartId(umsAdminDepart.getDepartId()); |
| | | adminDepartInfoVO.setDepartName(sccgDepart.getDepartName()); |
| | | adminDepartInfoVO.setDepartDes(sccgDepart.getDepartDes()); |
| | | adminDepartInfoVO.setDepartType(sccgDepart.getDepartType()); |
| | | adminDepartInfoVO.setUserId(userId); |
| | | adminDepartInfoVO.setUserName(umsAdmin.getUsername()); |
| | | adminDepartInfoVOS.add(adminDepartInfoVO); |
| | | } |
| | | basePageDTO.setRecords(adminDepartInfoVOS); |
| | | } |
| | | return basePageDTO; |
| | | } |
| | | |
| | | @Override |
| | | public void userUpdateRoles(Long id, List<Long> roles) { |
| | | //解除用户角色绑定 |
| | | umsAdminRoleRelationMapper.delete(new LambdaQueryWrapper<UmsAdminRoleRelation>().eq(UmsAdminRoleRelation::getAdminId, id)); |
| | | //解除用户绑定角色绑定菜单 |
| | | adminMenuRelationMapper.delete(new LambdaQueryWrapper<AdminMenuRelation>().eq(AdminMenuRelation::getAdminId, id)); |
| | | //绑定角色于用户 |
| | | if (!roles.isEmpty()) { |
| | | for (Long role : roles) { |
| | | UmsAdminRoleRelation urr = new UmsAdminRoleRelation(); |
| | | urr.setAdminId(id); |
| | | urr.setRoleId(role); |
| | | umsAdminRoleRelationMapper.insert(urr); |
| | | } |
| | | } |
| | | //绑定菜单于用户 |
| | | ArrayList<UmsRoleMenuRelation> umsRoleMenuRelations = new ArrayList<>(); |
| | | for (Long role : roles) { |
| | | umsRoleMenuRelations.addAll(roleMenuRelationMapper |
| | | .selectList(new LambdaQueryWrapper<UmsRoleMenuRelation>() |
| | | .eq(UmsRoleMenuRelation::getRoleId, role))); |
| | | } |
| | | umsRoleMenuRelations |
| | | .stream() |
| | | .map(item -> item.getMenuId()) |
| | | .collect(Collectors.toList()) |
| | | .stream() |
| | | .distinct() |
| | | .collect(Collectors.toList()) |
| | | .stream() |
| | | .forEach(item -> { |
| | | AdminMenuRelation adminMenuRelation = new AdminMenuRelation(); |
| | | adminMenuRelation.setAdminId(id); |
| | | adminMenuRelation.setMenuId(item); |
| | | adminMenuRelationMapper.insert(adminMenuRelation); |
| | | }); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void userUpdateDepart(Long userId,Long departId) { |
| | | umsDepartManageMapper.delete(new LambdaQueryWrapper<UmsDepartManage>().eq(UmsDepartManage::getUserId,userId)); |
| | | UmsDepartManage umsDepartManage = new UmsDepartManage(); |
| | | umsDepartManage.setUserId(userId); |
| | | umsDepartManage.setCreateTime(new Date()); |
| | | umsDepartManage.setDepartId(departId); |
| | | umsDepartManageMapper.insert(umsDepartManage); |
| | | } |
| | | } |