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.model.SysDeptPageQueryModel;
import com.muyu.system.domain.rep.SysDeptAddReq; import com.muyu.system.domain.rep.SysDeptAddReq;
import com.muyu.system.domain.rep.SysDeptListReq; import com.muyu.system.domain.rep.SysDeptListReq;
import com.muyu.system.domain.rep.SysDeptUpdReq;
import com.muyu.system.service.SysDeptService; import com.muyu.system.service.SysDeptService;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.ArrayUtils;
@ -73,7 +74,7 @@ public class SysDeptController extends BaseController {
@Log(title = "部门管理", businessType = BusinessType.INSERT) @Log(title = "部门管理", businessType = BusinessType.INSERT)
@PostMapping @PostMapping
public Result<String> add (@Validated @RequestBody SysDeptAddReq sysDeptAddReq) { 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() + "'失败,部门名称已存在"); return error("新增部门'" + sysDeptAddReq.getDeptName() + "'失败,部门名称已存在");
} }
deptService.insertDept(sysDeptAddReq.buildSysDept()); deptService.insertDept(sysDeptAddReq.buildSysDept());
@ -85,21 +86,19 @@ public class SysDeptController extends BaseController {
*/ */
@RequiresPermissions("system:dept:edit") @RequiresPermissions("system:dept:edit")
@Log(title = "部门管理", businessType = BusinessType.UPDATE) @Log(title = "部门管理", businessType = BusinessType.UPDATE)
@PutMapping @PutMapping("/{deptId}")
public Result edit (@Validated @RequestBody SysDept dept) { public Result<String> edit (@PathVariable("deptId")Long deptId, @Validated @RequestBody SysDeptUpdReq sysDeptUpdReq) {
Long deptId = dept.getDeptId();
deptService.checkDeptDataScope(deptId); deptService.checkDeptDataScope(deptId);
if (!deptService.checkDeptNameUnique( if (deptService.checkDeptNameUnique(
CheckDeptNameUniqueModel.of(dept.getDeptName(),deptId,dept.getParentId()) CheckDeptNameUniqueModel.of(sysDeptUpdReq.getDeptName(), deptId, sysDeptUpdReq.getParentId())
)) { )) {
return error("修改部门'" + dept.getDeptName() + "'失败,部门名称已存在"); return error("修改部门'" + sysDeptUpdReq.getDeptName() + "'失败,部门名称已存在");
} else if (dept.getParentId().equals(deptId)) { } else if (sysDeptUpdReq.getParentId().equals(deptId)) {
return error("修改部门'" + dept.getDeptName() + "'失败,上级部门不能是自己"); return error("修改部门'" + sysDeptUpdReq.getDeptName() + "'失败,上级部门不能是自己");
} else if (StringUtils.equals(UserConstants.DEPT_DISABLE, dept.getStatus()) && deptService.selectNormalChildrenDeptById(deptId) > 0) { } else if (StringUtils.equals(UserConstants.DEPT_DISABLE, sysDeptUpdReq.getStatus()) && deptService.selectNormalChildrenDeptById(deptId) > 0) {
return error("该部门包含未停用的子部门!"); return error("该部门包含未停用的子部门!");
} }
dept.setUpdateBy(SecurityUtils.getUsername()); deptService.updateDept(sysDeptUpdReq.buildSysDept(deptId));
deptService.updateDept(dept);
return success(); return success();
} }

View File

@ -1,6 +1,7 @@
package com.muyu.system.domain.rep; package com.muyu.system.domain.rep;
import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableField;
import com.muyu.common.core.enums.SysDelFlag;
import com.muyu.common.security.utils.SecurityUtils; import com.muyu.common.security.utils.SecurityUtils;
import com.muyu.common.system.domain.SysDept; import com.muyu.common.system.domain.SysDept;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
@ -55,17 +56,13 @@ public class SysDeptAddReq {
*/ */
private String status; private String status;
/**
* 0 2
*/
private String delFlag;
public SysDept buildSysDept(){ public SysDept buildSysDept(){
return SysDept.builder() return SysDept.builder()
.deptName(this.deptName) .deptName(this.deptName)
.orderNum(this.orderNum) .orderNum(this.orderNum)
.email(this.email) .email(this.email)
.delFlag(this.delFlag) .delFlag(SysDelFlag.EXIST.getCode())
.phone(this.phone) .phone(this.phone)
.status(this.status) .status(this.status)
.leader(this.leader) .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<>(); LambdaQueryWrapper<SysDept> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.like(StringUtils.isNotEmpty(sysDeptPageQueryModel.getDeptName()),SysDept::getDeptName, sysDeptPageQueryModel.getDeptName()); queryWrapper.like(StringUtils.isNotEmpty(sysDeptPageQueryModel.getDeptName()),SysDept::getDeptName, sysDeptPageQueryModel.getDeptName());
queryWrapper.eq(StringUtils.isNotEmpty(sysDeptPageQueryModel.getStatus()),SysDept::getStatus,sysDeptPageQueryModel.getStatus()); 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); return this.list(queryWrapper);
} }
@ -307,7 +307,7 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept>
@Override @Override
public void deleteDeptById (Long deptId) { public void deleteDeptById (Long deptId) {
LambdaUpdateWrapper<SysDept> updateWrapper = new LambdaUpdateWrapper<>(); 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); updateWrapper.eq(SysDept::getDeptId, deptId);
this.update(updateWrapper); this.update(updateWrapper);
} }
@ -358,7 +358,7 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept>
@Override @Override
public List<SysDept> selectChildrenDeptById (Long deptId){ public List<SysDept> selectChildrenDeptById (Long deptId){
LambdaQueryWrapper<SysDept> queryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<SysDept> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.apply("FIND_IN_SET('" + deptId + "', type)"); queryWrapper.apply("FIND_IN_SET('" + deptId + "', ancestors)");
return this.list(queryWrapper); return this.list(queryWrapper);
} }
} }