From 2e92773b8ce9e70615e61c84136bbedd702aad8c Mon Sep 17 00:00:00 2001 From: 疯狂的狮子li <15040126243@163.com> Date: 星期五, 31 三月 2023 10:19:28 +0800 Subject: [PATCH] update 优化 角色 sort 值一样的排序问题 --- ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java | 41 ++++++++++++++++++++++------------------- 1 files changed, 22 insertions(+), 19 deletions(-) diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java index 4feff89..43b895a 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java @@ -197,15 +197,12 @@ * @return 缁撴灉 */ @Override - public String checkDeptNameUnique(SysDeptBo dept) { + public boolean checkDeptNameUnique(SysDeptBo dept) { boolean exist = baseMapper.exists(new LambdaQueryWrapper<SysDept>() .eq(SysDept::getDeptName, dept.getDeptName()) .eq(SysDept::getParentId, dept.getParentId()) .ne(ObjectUtil.isNotNull(dept.getDeptId()), SysDept::getDeptId, dept.getDeptId())); - if (exist) { - return UserConstants.NOT_UNIQUE; - } - return UserConstants.UNIQUE; + return !exist; } /** @@ -215,13 +212,15 @@ */ @Override public void checkDeptDataScope(Long deptId) { - if (!LoginHelper.isSuperAdmin()) { - SysDeptBo dept = new SysDeptBo(); - dept.setDeptId(deptId); - List<SysDeptVo> depts = this.selectDeptList(dept); - if (CollUtil.isEmpty(depts)) { - throw new ServiceException("娌℃湁鏉冮檺璁块棶閮ㄩ棬鏁版嵁锛�"); - } + if (ObjectUtil.isNull(deptId)) { + return; + } + if (LoginHelper.isSuperAdmin()) { + return; + } + SysDeptVo dept = baseMapper.selectDeptById(deptId); + if (ObjectUtil.isNull(dept)) { + throw new ServiceException("娌℃湁鏉冮檺璁块棶閮ㄩ棬鏁版嵁锛�"); } } @@ -253,13 +252,17 @@ @Override public int updateDept(SysDeptBo bo) { SysDept dept = MapstructUtils.convert(bo, SysDept.class); - SysDept newParentDept = baseMapper.selectById(dept.getParentId()); SysDept oldDept = baseMapper.selectById(dept.getDeptId()); - if (ObjectUtil.isNotNull(newParentDept) && ObjectUtil.isNotNull(oldDept)) { - String newAncestors = newParentDept.getAncestors() + StringUtils.SEPARATOR + newParentDept.getDeptId(); - String oldAncestors = oldDept.getAncestors(); - dept.setAncestors(newAncestors); - updateDeptChildren(dept.getDeptId(), newAncestors, oldAncestors); + if (!oldDept.getParentId().equals(dept.getParentId())) { + // 濡傛灉鏄柊鐖堕儴闂� 鍒欐牎楠屾槸鍚﹀叿鏈夋柊鐖堕儴闂ㄦ潈闄� 閬垮厤瓒婃潈 + this.checkDeptDataScope(dept.getParentId()); + SysDept newParentDept = baseMapper.selectById(dept.getParentId()); + if (ObjectUtil.isNotNull(newParentDept) && ObjectUtil.isNotNull(oldDept)) { + String newAncestors = newParentDept.getAncestors() + StringUtils.SEPARATOR + newParentDept.getDeptId(); + String oldAncestors = oldDept.getAncestors(); + dept.setAncestors(newAncestors); + updateDeptChildren(dept.getDeptId(), newAncestors, oldAncestors); + } } int result = baseMapper.updateById(dept); if (UserConstants.DEPT_NORMAL.equals(dept.getStatus()) && StringUtils.isNotEmpty(dept.getAncestors()) @@ -290,7 +293,7 @@ * @param newAncestors 鏂扮殑鐖禝D闆嗗悎 * @param oldAncestors 鏃х殑鐖禝D闆嗗悎 */ - public void updateDeptChildren(Long deptId, String newAncestors, String oldAncestors) { + private void updateDeptChildren(Long deptId, String newAncestors, String oldAncestors) { List<SysDept> children = baseMapper.selectList(new LambdaQueryWrapper<SysDept>() .apply(DataBaseHelper.findInSet(deptId, "ancestors"))); List<SysDept> list = new ArrayList<>(); -- Gitblit v1.9.3