From c55157dce03981e85a20e7b9e3540c6218c53daf Mon Sep 17 00:00:00 2001 From: Yjoioooo <693337446@qq.com> Date: 星期二, 21 三月 2023 20:17:30 +0800 Subject: [PATCH] update 规范不公开方法访问控制修饰符为private --- ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java | 52 +++++++++++++++++++++++++++------------------------- 1 files changed, 27 insertions(+), 25 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 7b71a6f..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 @@ -1,6 +1,5 @@ package com.ruoyi.system.service.impl; -import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.convert.Convert; import cn.hutool.core.lang.tree.Tree; @@ -12,6 +11,7 @@ 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.MapstructUtils; import com.ruoyi.common.core.utils.SpringUtils; import com.ruoyi.common.core.utils.StringUtils; import com.ruoyi.common.core.utils.TreeBuildUtils; @@ -64,12 +64,11 @@ /** * 鏌ヨ閮ㄩ棬鏍戠粨鏋勪俊鎭� * - * @param dept 閮ㄩ棬淇℃伅 + * @param bo 閮ㄩ棬淇℃伅 * @return 閮ㄩ棬鏍戜俊鎭泦鍚� */ @Override - public List<Tree<Long>> selectDeptTreeList(SysDept dept) { - SysDeptBo bo = BeanUtil.toBean(dept, SysDeptBo.class); + public List<Tree<Long>> selectDeptTreeList(SysDeptBo bo) { LambdaQueryWrapper<SysDept> lqw = buildQueryWrapper(bo); List<SysDept> depts = baseMapper.selectList(lqw); return buildDeptTreeSelect(depts); @@ -198,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; } /** @@ -216,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("娌℃湁鏉冮檺璁块棶閮ㄩ棬鏁版嵁锛�"); } } @@ -239,7 +237,7 @@ if (!UserConstants.DEPT_NORMAL.equals(info.getStatus())) { throw new ServiceException("閮ㄩ棬鍋滅敤锛屼笉鍏佽鏂板"); } - SysDept dept = BeanUtil.toBean(bo, SysDept.class); + SysDept dept = MapstructUtils.convert(bo, SysDept.class); dept.setAncestors(info.getAncestors() + StringUtils.SEPARATOR + dept.getParentId()); return baseMapper.insert(dept); } @@ -253,14 +251,18 @@ @CacheEvict(cacheNames = CacheNames.SYS_DEPT, key = "#bo.deptId") @Override public int updateDept(SysDeptBo bo) { - SysDept dept = BeanUtil.toBean(bo, SysDept.class); - SysDept newParentDept = baseMapper.selectById(dept.getParentId()); + SysDept dept = MapstructUtils.convert(bo, SysDept.class); 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()) @@ -291,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