代码提交

This commit is contained in:
liang.chao 2025-09-29 17:30:33 +08:00
parent 83478dfffa
commit f6cbf24b67
5 changed files with 123 additions and 34 deletions

View File

@ -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<SysDept> 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<SysDept> 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);

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}
/**
* 递归列表
*/

View File

@ -86,8 +86,59 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<include refid="selectDeptVo"/>
where dept_name=#{deptName} and parent_id = #{parentId} and del_flag = '0' limit 1
</select>
<select id="getTransferApplyDeptId" resultType="java.lang.Integer">
WITH RECURSIVE DeptTree AS (
SELECT dept_id
FROM da_ky_sys_dept
WHERE dept_id = #{deptId}
<insert id="insertDept" parameterType="SysDept">
UNION ALL
SELECT d.dept_id
FROM da_ky_sys_dept d
INNER JOIN DeptTree dt ON d.parent_id = dt.dept_id
)
SELECT COUNT(*)
FROM da_ky_transfer_apply t
INNER JOIN DeptTree dt ON t.dept_id = dt.dept_id
WHERE t.del_flag = '1'
</select>
<select id="getSysUserDeptId" resultType="java.lang.Integer">
WITH RECURSIVE DeptTree AS (
SELECT dept_id
FROM da_ky_sys_dept
WHERE dept_id = #{deptId}
UNION ALL
SELECT d.dept_id
FROM da_ky_sys_dept d
INNER JOIN DeptTree dt ON d.parent_id = dt.dept_id
)
SELECT COUNT(*)
FROM da_ky_sys_user t
INNER JOIN DeptTree dt ON t.dept_id = dt.dept_id
WHERE t.del_flag = '0'
</select>
<select id="getTransferIssueDeptId" resultType="java.lang.Integer">
WITH RECURSIVE DeptTree AS (
SELECT dept_id
FROM da_ky_sys_dept
WHERE dept_id = #{deptId}
UNION ALL
SELECT d.dept_id
FROM da_ky_sys_dept d
INNER JOIN DeptTree dt ON d.parent_id = dt.dept_id
)
SELECT COUNT(*)
FROM da_ky_transfer_issue t
INNER JOIN DeptTree dt ON t.dept_id = dt.dept_id
WHERE t.del_flag = '1'
</select>
<insert id="insertDept" parameterType="SysDept">
insert into da_ky_sys_dept(
<if test="deptId != null and deptId != 0">dept_id,</if>
<if test="parentId != null and parentId != 0">parent_id,</if>