diff --git a/cloud-modules/cloud-modules-system/src/main/java/com/muyu/system/controller/SysDeptController.java b/cloud-modules/cloud-modules-system/src/main/java/com/muyu/system/controller/SysDeptController.java index 1bf2de6..5fbd9bf 100644 --- a/cloud-modules/cloud-modules-system/src/main/java/com/muyu/system/controller/SysDeptController.java +++ b/cloud-modules/cloud-modules-system/src/main/java/com/muyu/system/controller/SysDeptController.java @@ -13,6 +13,7 @@ import com.muyu.system.domain.model.CheckDeptNameUniqueModel; import com.muyu.system.domain.model.SysDeptPageQueryModel; import com.muyu.system.domain.rep.SysDeptAddReq; import com.muyu.system.domain.rep.SysDeptListReq; +import com.muyu.system.domain.rep.SysDeptUpdReq; import com.muyu.system.service.SysDeptService; import io.swagger.v3.oas.annotations.tags.Tag; import org.apache.commons.lang3.ArrayUtils; @@ -73,7 +74,7 @@ public class SysDeptController extends BaseController { @Log(title = "部门管理", businessType = BusinessType.INSERT) @PostMapping public Result add (@Validated @RequestBody SysDeptAddReq sysDeptAddReq) { - if (!deptService.checkDeptNameUnique(CheckDeptNameUniqueModel.of(sysDeptAddReq.getDeptName()))) { + if (deptService.checkDeptNameUnique(CheckDeptNameUniqueModel.of(sysDeptAddReq.getDeptName()))) { return error("新增部门'" + sysDeptAddReq.getDeptName() + "'失败,部门名称已存在"); } deptService.insertDept(sysDeptAddReq.buildSysDept()); @@ -85,21 +86,19 @@ public class SysDeptController extends BaseController { */ @RequiresPermissions("system:dept:edit") @Log(title = "部门管理", businessType = BusinessType.UPDATE) - @PutMapping - public Result edit (@Validated @RequestBody SysDept dept) { - Long deptId = dept.getDeptId(); + @PutMapping("/{deptId}") + public Result edit (@PathVariable("deptId")Long deptId, @Validated @RequestBody SysDeptUpdReq sysDeptUpdReq) { deptService.checkDeptDataScope(deptId); - if (!deptService.checkDeptNameUnique( - CheckDeptNameUniqueModel.of(dept.getDeptName(),deptId,dept.getParentId()) + if (deptService.checkDeptNameUnique( + CheckDeptNameUniqueModel.of(sysDeptUpdReq.getDeptName(), deptId, sysDeptUpdReq.getParentId()) )) { - return error("修改部门'" + dept.getDeptName() + "'失败,部门名称已存在"); - } else if (dept.getParentId().equals(deptId)) { - return error("修改部门'" + dept.getDeptName() + "'失败,上级部门不能是自己"); - } else if (StringUtils.equals(UserConstants.DEPT_DISABLE, dept.getStatus()) && deptService.selectNormalChildrenDeptById(deptId) > 0) { + return error("修改部门'" + sysDeptUpdReq.getDeptName() + "'失败,部门名称已存在"); + } else if (sysDeptUpdReq.getParentId().equals(deptId)) { + return error("修改部门'" + sysDeptUpdReq.getDeptName() + "'失败,上级部门不能是自己"); + } else if (StringUtils.equals(UserConstants.DEPT_DISABLE, sysDeptUpdReq.getStatus()) && deptService.selectNormalChildrenDeptById(deptId) > 0) { return error("该部门包含未停用的子部门!"); } - dept.setUpdateBy(SecurityUtils.getUsername()); - deptService.updateDept(dept); + deptService.updateDept(sysDeptUpdReq.buildSysDept(deptId)); return success(); } diff --git a/cloud-modules/cloud-modules-system/src/main/java/com/muyu/system/domain/rep/SysDeptAddReq.java b/cloud-modules/cloud-modules-system/src/main/java/com/muyu/system/domain/rep/SysDeptAddReq.java index 23fc330..d9bff89 100644 --- a/cloud-modules/cloud-modules-system/src/main/java/com/muyu/system/domain/rep/SysDeptAddReq.java +++ b/cloud-modules/cloud-modules-system/src/main/java/com/muyu/system/domain/rep/SysDeptAddReq.java @@ -1,6 +1,7 @@ package com.muyu.system.domain.rep; import com.baomidou.mybatisplus.annotation.TableField; +import com.muyu.common.core.enums.SysDelFlag; import com.muyu.common.security.utils.SecurityUtils; import com.muyu.common.system.domain.SysDept; import lombok.AllArgsConstructor; @@ -55,17 +56,13 @@ public class SysDeptAddReq { */ private String status; - /** - * 删除标志(0代表存在 2代表删除) - */ - private String delFlag; public SysDept buildSysDept(){ return SysDept.builder() .deptName(this.deptName) .orderNum(this.orderNum) .email(this.email) - .delFlag(this.delFlag) + .delFlag(SysDelFlag.EXIST.getCode()) .phone(this.phone) .status(this.status) .leader(this.leader) diff --git a/cloud-modules/cloud-modules-system/src/main/java/com/muyu/system/domain/rep/SysDeptUpdReq.java b/cloud-modules/cloud-modules-system/src/main/java/com/muyu/system/domain/rep/SysDeptUpdReq.java new file mode 100644 index 0000000..4656934 --- /dev/null +++ b/cloud-modules/cloud-modules-system/src/main/java/com/muyu/system/domain/rep/SysDeptUpdReq.java @@ -0,0 +1,71 @@ +package com.muyu.system.domain.rep; + +import com.muyu.common.core.enums.SysDelFlag; +import com.muyu.common.security.utils.SecurityUtils; +import com.muyu.common.system.domain.SysDept; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * @author dongzeliang + * @version 1.0 + * @description: 部门管理修改请求对象 + * @date 2025/1/27 09:40 + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class SysDeptUpdReq { + + /** + * 父部门ID + */ + private Long parentId; + + /** + * 部门名称 + */ + private String deptName; + + /** + * 显示顺序 + */ + private Integer orderNum; + + /** + * 负责人 + */ + private String leader; + + /** + * 联系电话 + */ + private String phone; + + /** + * 邮箱 + */ + private String email; + + /** + * 部门状态:0正常,1停用 + */ + private String status; + + public SysDept buildSysDept(Long deptId) { + return SysDept.builder() + .deptId(deptId) + .deptName(this.deptName) + .orderNum(this.orderNum) + .email(this.email) + .phone(this.phone) + .status(this.status) + .leader(this.leader) + .parentId(this.parentId) + .updateBy(SecurityUtils.getUsername()) + .build(); + } +} diff --git a/cloud-modules/cloud-modules-system/src/main/java/com/muyu/system/service/impl/SysDeptServiceImpl.java b/cloud-modules/cloud-modules-system/src/main/java/com/muyu/system/service/impl/SysDeptServiceImpl.java index c705233..398d6e1 100644 --- a/cloud-modules/cloud-modules-system/src/main/java/com/muyu/system/service/impl/SysDeptServiceImpl.java +++ b/cloud-modules/cloud-modules-system/src/main/java/com/muyu/system/service/impl/SysDeptServiceImpl.java @@ -50,7 +50,7 @@ public class SysDeptServiceImpl extends ServiceImpl LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.like(StringUtils.isNotEmpty(sysDeptPageQueryModel.getDeptName()),SysDept::getDeptName, sysDeptPageQueryModel.getDeptName()); queryWrapper.eq(StringUtils.isNotEmpty(sysDeptPageQueryModel.getStatus()),SysDept::getStatus,sysDeptPageQueryModel.getStatus()); - queryWrapper.eq(SysDept::getStatus, SysDelFlag.EXIST.getCode()); + queryWrapper.eq(SysDept::getDelFlag, SysNormalDisable.ENABLE.getCode()); return this.list(queryWrapper); } @@ -307,7 +307,7 @@ public class SysDeptServiceImpl extends ServiceImpl @Override public void deleteDeptById (Long deptId) { LambdaUpdateWrapper updateWrapper = new LambdaUpdateWrapper<>(); - updateWrapper.set(SysDept::getStatus, SysDelFlag.NOT_EXIST.getCode()); + updateWrapper.set(SysDept::getDelFlag, SysDelFlag.NOT_EXIST.getCode()); updateWrapper.eq(SysDept::getDeptId, deptId); this.update(updateWrapper); } @@ -358,7 +358,7 @@ public class SysDeptServiceImpl extends ServiceImpl @Override public List selectChildrenDeptById (Long deptId){ LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); - queryWrapper.apply("FIND_IN_SET('" + deptId + "', type)"); + queryWrapper.apply("FIND_IN_SET('" + deptId + "', ancestors)"); return this.list(queryWrapper); } }