From 1cdb6459f1e05b23f15920fe90aad5e6e7f1d061 Mon Sep 17 00:00:00 2001 From: xiangpei <xiangpei@timesnew.cn> Date: 星期三, 19 二月 2025 14:06:16 +0800 Subject: [PATCH] 部门新增修改接口调整 --- system/src/main/java/com/ycl/system/service/impl/SysDeptServiceImpl.java | 52 +++++++++++++++++++++++++++++----------------------- 1 files changed, 29 insertions(+), 23 deletions(-) diff --git a/system/src/main/java/com/ycl/system/service/impl/SysDeptServiceImpl.java b/system/src/main/java/com/ycl/system/service/impl/SysDeptServiceImpl.java index 6e291af..7154ec4 100644 --- a/system/src/main/java/com/ycl/system/service/impl/SysDeptServiceImpl.java +++ b/system/src/main/java/com/ycl/system/service/impl/SysDeptServiceImpl.java @@ -6,6 +6,7 @@ import com.ycl.common.base.Result; import com.ycl.common.core.domain.StringTreeSelect; import com.ycl.system.domain.base.BaseSelect; +import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.ycl.common.annotation.DataScope; @@ -29,13 +30,12 @@ * @author ycl */ @Service +@RequiredArgsConstructor public class SysDeptServiceImpl implements ISysDeptService { - @Autowired - private SysDeptMapper deptMapper; - @Autowired - private SysRoleMapper roleMapper; + private final SysDeptMapper deptMapper; + private final SysRoleMapper roleMapper; /** * 鏌ヨ閮ㄩ棬绠$悊鏁版嵁 @@ -262,13 +262,18 @@ @Override public int insertDept(SysDept dept) { - SysDept info = deptMapper.selectDeptById(dept.getParentId()); - // 濡傛灉鐖惰妭鐐逛笉涓烘甯哥姸鎬�,鍒欎笉鍏佽鏂板瀛愯妭鐐� - if (!UserConstants.DEPT_NORMAL.equals(info.getStatus())) - { - throw new ServiceException("閮ㄩ棬鍋滅敤锛屼笉鍏佽鏂板"); + if (Objects.nonNull(dept.getParentId())) { + SysDept info = deptMapper.selectDeptById(dept.getParentId()); + // 濡傛灉鐖惰妭鐐逛笉涓烘甯哥姸鎬�,鍒欎笉鍏佽鏂板瀛愯妭鐐� + if (!UserConstants.DEPT_NORMAL.equals(info.getStatus())) + { + throw new ServiceException("涓婄骇閮ㄩ棬宸插仠鐢紝涓嶅厑璁告柊澧炰笅绾ч儴闂�"); + } + dept.setAncestors(info.getAncestors() + "," + dept.getParentId()); + } else { + dept.setParentId(0L); + dept.setAncestors(""); } - dept.setAncestors(info.getAncestors() + "," + dept.getParentId()); return deptMapper.insertDept(dept); } @@ -281,22 +286,23 @@ @Override public int updateDept(SysDept dept) { - SysDept newParentDept = deptMapper.selectDeptById(dept.getParentId()); SysDept oldDept = deptMapper.selectDeptById(dept.getDeptId()); - if (StringUtils.isNotNull(newParentDept) && StringUtils.isNotNull(oldDept)) - { - String newAncestors = newParentDept.getAncestors() + "," + newParentDept.getDeptId(); - String oldAncestors = oldDept.getAncestors(); - dept.setAncestors(newAncestors); - updateDeptChildren(dept.getDeptId(), newAncestors, oldAncestors); + if (Objects.isNull(oldDept)) { + throw new RuntimeException("淇敼閮ㄩ棬琚垹闄ゆ垨涓嶅瓨鍦�"); + } + if (Objects.nonNull(dept.getParentId())) { + SysDept newParentDept = deptMapper.selectDeptById(dept.getParentId()); + if (Objects.nonNull(newParentDept)) { + String newAncestors = newParentDept.getAncestors() + "," + newParentDept.getDeptId(); + String oldAncestors = oldDept.getAncestors(); + dept.setAncestors(newAncestors); + updateDeptChildren(dept.getDeptId(), newAncestors, oldAncestors); + } + } else { + dept.setDeptId(0L); + dept.setAncestors(""); } int result = deptMapper.updateDept(dept); - if (UserConstants.DEPT_NORMAL.equals(dept.getStatus()) && StringUtils.isNotEmpty(dept.getAncestors()) - && !StringUtils.equals("0", dept.getAncestors())) - { - // 濡傛灉璇ラ儴闂ㄦ槸鍚敤鐘舵�侊紝鍒欏惎鐢ㄨ閮ㄩ棬鐨勬墍鏈変笂绾ч儴闂� - updateParentDeptStatusNormal(dept); - } return result; } -- Gitblit v1.8.0