diff --git a/bonus-admin/src/main/java/com/bonus/web/controller/system/SysDeptController.java b/bonus-admin/src/main/java/com/bonus/web/controller/system/SysDeptController.java index 48ba1f0..6d80002 100644 --- a/bonus-admin/src/main/java/com/bonus/web/controller/system/SysDeptController.java +++ b/bonus-admin/src/main/java/com/bonus/web/controller/system/SysDeptController.java @@ -33,8 +33,7 @@ import com.bonus.system.service.ISysDeptService; */ @RestController @RequestMapping("/system/dept") -public class SysDeptController extends BaseController -{ +public class SysDeptController extends BaseController { @Autowired private ISysDeptService deptService; @@ -43,8 +42,7 @@ public class SysDeptController extends BaseController */ @RequiresPermissions("system:dept:list") @GetMapping("/list") - public AjaxResult list(SysDept dept) - { + public AjaxResult list(SysDept dept) { List depts = deptService.selectDeptList(dept); return success(depts); } @@ -53,10 +51,9 @@ public class SysDeptController extends BaseController * 查询部门列表(排除节点) */ @RequiresPermissions("system:dept:list") - @SysLog(title = "部门管理", businessType = OperaType.QUERY,module = "部门管理->查询部门列表", details = "查询部门列表") + @SysLog(title = "部门管理", businessType = OperaType.QUERY, module = "部门管理->查询部门列表", details = "查询部门列表") @GetMapping("/list/exclude/{deptId}") - public AjaxResult excludeChild(@PathVariable(value = "deptId", required = false) Long deptId) - { + public AjaxResult excludeChild(@PathVariable(value = "deptId", required = false) Long deptId) { List depts = deptService.selectDeptList(new SysDept()); depts.removeIf(d -> d.getDeptId().intValue() == deptId || ArrayUtils.contains(StringUtils.split(d.getAncestors(), ","), deptId + "")); return success(depts); @@ -67,9 +64,8 @@ public class SysDeptController extends BaseController */ @RequiresPermissions("system:dept:query") @GetMapping(value = "/{deptId}") - @SysLog(title = "部门管理", businessType = OperaType.QUERY,module = "部门管理->根据部门编号获取详细信息", details = "根据部门编号获取详细信息") - public AjaxResult getInfo(@PathVariable Long deptId) - { + @SysLog(title = "部门管理", businessType = OperaType.QUERY, module = "部门管理->根据部门编号获取详细信息", details = "根据部门编号获取详细信息") + public AjaxResult getInfo(@PathVariable Long deptId) { deptService.checkDeptDataScope(deptId); return success(deptService.selectDeptById(deptId)); } @@ -78,12 +74,10 @@ public class SysDeptController extends BaseController * 新增部门 */ @RequiresPermissions("system:dept:add") - @SysLog(title = "部门管理", businessType = OperaType.INSERT,module = "部门管理->新增部门", details = "新增部门") + @SysLog(title = "部门管理", businessType = OperaType.INSERT, module = "部门管理->新增部门", details = "新增部门") @PostMapping - public AjaxResult add(@Validated @RequestBody SysDept dept) - { - if (!deptService.checkDeptNameUnique(dept)) - { + public AjaxResult add(@Validated @RequestBody SysDept dept) { + if (!deptService.checkDeptNameUnique(dept)) { return error("新增部门'" + dept.getDeptName() + "'失败,部门名称已存在"); } dept.setCreateBy(getUsername()); @@ -94,22 +88,29 @@ public class SysDeptController extends BaseController * 修改部门 */ @RequiresPermissions("system:dept:edit") - @SysLog(title = "部门管理", businessType = OperaType.UPDATE,module = "部门管理->修改部门", details = "修改部门") + @SysLog(title = "部门管理", businessType = OperaType.UPDATE, module = "部门管理->修改部门", details = "修改部门") @PutMapping - public AjaxResult edit(@Validated @RequestBody SysDept dept) - { + public AjaxResult edit(@Validated @RequestBody SysDept dept) { Long deptId = dept.getDeptId(); + // 如果该部门已被使用,则无法修改 + Integer num = deptService.getTransferApplyDeptId(deptId); + if (num > 0) { + return error("该部门或其子部门已被档案申请使用,请勿修改"); + } + Integer num1 = deptService.getSysUserDeptId(deptId); + if (num1 > 0) { + return error("该部门或其子部门已被用户管理使用,请勿修改"); + } + Integer num2 = deptService.getTransferIssueDeptId(deptId); + if (num2 > 0) { + return error("该部门或其子部门已被档案移交问题管理,请勿修改"); + } deptService.checkDeptDataScope(deptId); - if (!deptService.checkDeptNameUnique(dept)) - { + if (!deptService.checkDeptNameUnique(dept)) { return error("修改部门'" + dept.getDeptName() + "'失败,部门名称已存在"); - } - else if (dept.getParentId().equals(deptId)) - { + } else if (dept.getParentId().equals(deptId)) { return error("修改部门'" + dept.getDeptName() + "'失败,上级部门不能是自己"); - } - else if (StringUtils.equals(UserConstants.DEPT_DISABLE, dept.getStatus()) && deptService.selectNormalChildrenDeptById(deptId) > 0) - { + } else if (StringUtils.equals(UserConstants.DEPT_DISABLE, dept.getStatus()) && deptService.selectNormalChildrenDeptById(deptId) > 0) { return error("该部门包含未停用的子部门!"); } dept.setUpdateBy(getUsername()); @@ -120,16 +121,26 @@ public class SysDeptController extends BaseController * 删除部门 */ @RequiresPermissions("system:dept:remove") - @SysLog(title = "部门管理", businessType = OperaType.DELETE,module = "部门管理->删除部门", details = "删除部门") + @SysLog(title = "部门管理", businessType = OperaType.DELETE, module = "部门管理->删除部门", details = "删除部门") @DeleteMapping("/{deptId}") - public AjaxResult remove(@PathVariable Long deptId) - { - if (deptService.hasChildByDeptId(deptId)) - { + public AjaxResult remove(@PathVariable Long deptId) { + // 如果该部门已被使用,则无法删除 + Integer num = deptService.getTransferApplyDeptId(deptId); + if (num > 0) { + return error("该部门或其子部门已被档案申请使用,请勿删除"); + } + Integer num1 = deptService.getSysUserDeptId(deptId); + if (num1 > 0) { + return error("该部门或其子部门已被用户管理使用,请勿删除"); + } + Integer num2 = deptService.getTransferIssueDeptId(deptId); + if (num2 > 0) { + return error("该部门或其子部门已被档案移交问题管理,请勿删除"); + } + if (deptService.hasChildByDeptId(deptId)) { return warn("存在下级部门,不允许删除"); } - if (deptService.checkDeptExistUser(deptId)) - { + if (deptService.checkDeptExistUser(deptId)) { return warn("部门存在用户,不允许删除"); } deptService.checkDeptDataScope(deptId); diff --git a/bonus-system/src/main/java/com/bonus/system/mapper/SysDeptMapper.java b/bonus-system/src/main/java/com/bonus/system/mapper/SysDeptMapper.java index 43b0e07..fabfc3e 100644 --- a/bonus-system/src/main/java/com/bonus/system/mapper/SysDeptMapper.java +++ b/bonus-system/src/main/java/com/bonus/system/mapper/SysDeptMapper.java @@ -115,4 +115,10 @@ public interface SysDeptMapper * @return 结果 */ public int deleteDeptById(Long deptId); + + Integer getTransferApplyDeptId(Long deptId); + + Integer getSysUserDeptId(Long deptId); + + Integer getTransferIssueDeptId(Long deptId); } diff --git a/bonus-system/src/main/java/com/bonus/system/service/ISysDeptService.java b/bonus-system/src/main/java/com/bonus/system/service/ISysDeptService.java index c1131a0..b1c87c7 100644 --- a/bonus-system/src/main/java/com/bonus/system/service/ISysDeptService.java +++ b/bonus-system/src/main/java/com/bonus/system/service/ISysDeptService.java @@ -121,4 +121,10 @@ public interface ISysDeptService * @return 结果 */ public int deleteDeptById(Long deptId); + + Integer getTransferApplyDeptId(Long deptId); + + Integer getSysUserDeptId(Long deptId); + + Integer getTransferIssueDeptId(Long deptId); } diff --git a/bonus-system/src/main/java/com/bonus/system/service/impl/SysDeptServiceImpl.java b/bonus-system/src/main/java/com/bonus/system/service/impl/SysDeptServiceImpl.java index 8b1a557..472df81 100644 --- a/bonus-system/src/main/java/com/bonus/system/service/impl/SysDeptServiceImpl.java +++ b/bonus-system/src/main/java/com/bonus/system/service/impl/SysDeptServiceImpl.java @@ -297,6 +297,21 @@ public class SysDeptServiceImpl implements ISysDeptService return deptMapper.deleteDeptById(deptId); } + @Override + public Integer getTransferApplyDeptId(Long deptId) { + return deptMapper.getTransferApplyDeptId(deptId); + } + + @Override + public Integer getSysUserDeptId(Long deptId) { + return deptMapper.getSysUserDeptId(deptId); + } + + @Override + public Integer getTransferIssueDeptId(Long deptId) { + return deptMapper.getTransferIssueDeptId(deptId); + } + /** * 递归列表 */ diff --git a/bonus-system/src/main/resources/mapper/system/SysDeptMapper.xml b/bonus-system/src/main/resources/mapper/system/SysDeptMapper.xml index cb409dd..d6eeae2 100644 --- a/bonus-system/src/main/resources/mapper/system/SysDeptMapper.xml +++ b/bonus-system/src/main/resources/mapper/system/SysDeptMapper.xml @@ -86,8 +86,59 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" where dept_name=#{deptName} and parent_id = #{parentId} and del_flag = '0' limit 1 + + + + + insert into da_ky_sys_dept( dept_id, parent_id,