| | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.ruoyi.common.core.constant.CacheNames; |
| | | import com.ruoyi.common.core.constant.UserConstants; |
| | | import com.ruoyi.common.core.exception.ServiceException; |
| | | import com.ruoyi.common.core.service.DeptService; |
| | | import com.ruoyi.common.core.utils.SpringUtils; |
| | | import com.ruoyi.common.core.utils.StringUtils; |
| | | import com.ruoyi.common.core.utils.TreeBuildUtils; |
| | | import com.ruoyi.common.mybatis.helper.DataBaseHelper; |
| | | import com.ruoyi.common.redis.utils.CacheUtils; |
| | | import com.ruoyi.common.satoken.utils.LoginHelper; |
| | | import com.ruoyi.system.domain.SysDept; |
| | | import com.ruoyi.system.domain.SysRole; |
| | | import com.ruoyi.system.domain.SysUser; |
| | | import com.ruoyi.common.core.exception.ServiceException; |
| | | import com.ruoyi.common.mybatis.helper.DataBaseHelper; |
| | | import com.ruoyi.common.satoken.utils.LoginHelper; |
| | | import com.ruoyi.common.core.utils.StringUtils; |
| | | import com.ruoyi.common.core.utils.TreeBuildUtils; |
| | | import com.ruoyi.system.domain.bo.SysDeptBo; |
| | | import com.ruoyi.system.domain.vo.SysDeptVo; |
| | | import com.ruoyi.system.mapper.SysDeptMapper; |
| | |
| | | import com.ruoyi.system.mapper.SysUserMapper; |
| | | import com.ruoyi.system.service.ISysDeptService; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.cache.annotation.CacheEvict; |
| | | import org.springframework.cache.annotation.Cacheable; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.ArrayList; |
| | |
| | | */ |
| | | @RequiredArgsConstructor |
| | | @Service |
| | | public class SysDeptServiceImpl implements ISysDeptService { |
| | | public class SysDeptServiceImpl implements ISysDeptService, DeptService { |
| | | |
| | | private final SysDeptMapper baseMapper; |
| | | private final SysRoleMapper roleMapper; |
| | |
| | | * @param deptId é¨é¨ID |
| | | * @return é¨é¨ä¿¡æ¯ |
| | | */ |
| | | @Cacheable(cacheNames = CacheNames.SYS_DEPT, key = "#deptId") |
| | | @Override |
| | | public SysDeptVo selectDeptById(Long deptId) { |
| | | SysDeptVo dept = baseMapper.selectVoById(deptId); |
| | |
| | | .select(SysDept::getDeptName).eq(SysDept::getDeptId, dept.getParentId())); |
| | | dept.setParentName(ObjectUtil.isNotNull(parentDept) ? parentDept.getDeptName() : null); |
| | | return dept; |
| | | } |
| | | |
| | | /** |
| | | * éè¿é¨é¨IDæ¥è¯¢é¨é¨åç§° |
| | | * |
| | | * @param deptIds é¨é¨ID串éå·åé |
| | | * @return é¨é¨å称串éå·åé |
| | | */ |
| | | @Override |
| | | public String selectDeptNameByIds(String deptIds) { |
| | | List<String> list = new ArrayList<>(); |
| | | for (Long id : Arrays.stream(deptIds.split(",")).map(Long::parseLong).toList()) { |
| | | SysDeptVo vo = SpringUtils.getAopProxy(this).selectDeptById(id); |
| | | if (ObjectUtil.isNotNull(vo)) { |
| | | list.add(vo.getDeptName()); |
| | | } |
| | | } |
| | | return String.join(",", list); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @param bo é¨é¨ä¿¡æ¯ |
| | | * @return ç»æ |
| | | */ |
| | | @CacheEvict(cacheNames = CacheNames.SYS_DEPT, key = "#bo.deptId") |
| | | @Override |
| | | public int updateDept(SysDeptBo bo) { |
| | | SysDept dept = BeanUtil.toBean(bo, SysDept.class); |
| | |
| | | list.add(dept); |
| | | } |
| | | if (CollUtil.isNotEmpty(list)) { |
| | | baseMapper.updateBatchById(list); |
| | | if (baseMapper.updateBatchById(list)) { |
| | | list.forEach(dept -> CacheUtils.evict(CacheNames.SYS_DEPT, dept.getDeptId())); |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | * @param deptId é¨é¨ID |
| | | * @return ç»æ |
| | | */ |
| | | @CacheEvict(cacheNames = CacheNames.SYS_DEPT, key = "#deptId") |
| | | @Override |
| | | public int deleteDeptById(Long deptId) { |
| | | return baseMapper.deleteById(deptId); |