feat():部门DDD完善
parent
23a50b66db
commit
03b9b7a72b
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue