feat():部门DDD完善

boot3.0
dongzeliang 2025-01-27 10:28:39 +08:00
parent 23a50b66db
commit 03b9b7a72b
4 changed files with 87 additions and 20 deletions

View File

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

View File

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

View File

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

View File

@ -50,7 +50,7 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept>
LambdaQueryWrapper<SysDept> 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<SysDeptMapper, SysDept>
@Override
public void deleteDeptById (Long deptId) {
LambdaUpdateWrapper<SysDept> 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<SysDeptMapper, SysDept>
@Override
public List<SysDept> selectChildrenDeptById (Long deptId){
LambdaQueryWrapper<SysDept> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.apply("FIND_IN_SET('" + deptId + "', type)");
queryWrapper.apply("FIND_IN_SET('" + deptId + "', ancestors)");
return this.list(queryWrapper);
}
}