dev:岗位管理代码规范

main
SondonYong 2025-11-10 16:02:05 +08:00
parent b3d883831c
commit 53cec84911
9 changed files with 19 additions and 93 deletions

View File

@ -39,20 +39,12 @@ public class PostController {
@PostMapping("/save")
public SingleResponse<PostCO> add(@Validated @RequestBody PostAddCmd cmd) {
// SSOUser ssoUser = AuthContext.getCurrentUser();
// 监管端不用校验, 企业端必填
// if(cmd.getCorpFlag() == 2 && cmd.getSupervisionFlag() == null){
// throw new BizException("是否监管岗位不能为空");
// }
return postService.add(cmd);
}
@ApiOperation("修改")
@PutMapping("/edit")
public SingleResponse edit(@Validated @RequestBody PostUpdateCmd cmd) {
// 监管端不用校验, 企业端必填
// if(cmd.getCorpFlag() == 2 && cmd.getSupervisionFlag() == null){
// throw new BizException("是否监管岗位不能为空");
// }
postService.edit(cmd);
return SingleResponse.buildSuccess();
}
@ -63,11 +55,6 @@ public class PostController {
if(qry.getCorpFlag() == 2){
qry.setEqCorpinfoId(AuthContext.getTenantId());
}
// 数据类型转换
if(StrUtil.isNotBlank(qry.getDepartmentIdString())){
qry.setEqDepartmentId(Long.valueOf(qry.getDepartmentIdString()));
}
return postService.listPage(qry);
}
@ -77,17 +64,6 @@ public class PostController {
if(qry.getCorpFlag() == 2){
qry.setCorpinfoId(AuthContext.getTenantId());
}
// 数据类型转换
if(StrUtil.isNotBlank(qry.getDepartmentIdString())){
qry.setDepartmentId(Long.valueOf(qry.getDepartmentIdString()));
}
if(qry.getPostIdsString() != null && qry.getPostIdsString().length > 0){
qry.setPostIds(Arrays.stream(qry.getPostIdsString())
.filter(Objects::nonNull) // 过滤掉null
.filter(str -> !str.trim().isEmpty()) // 过滤掉空字符串
.map(Long::valueOf)
.toArray(Long[]::new));
}
return postService.list(qry);
}
@ -110,19 +86,10 @@ public class PostController {
@PutMapping("/removeBatch")
public Response removeBatch(@Validated @RequestBody PostRemoveCmd cmd) {
if(cmd.getIdsString()== null || cmd.getIdsString().length == 0){
if(cmd.getIds()== null || cmd.getIds().length == 0){
throw new BizException("请选择要删除的项。");
}
// 数据类型转换
if(cmd.getIdsString() != null && cmd.getIdsString().length > 0){
cmd.setIds(Arrays.stream(cmd.getIdsString())
.filter(Objects::nonNull) // 过滤掉null
.filter(str -> !str.trim().isEmpty()) // 过滤掉空字符串
.map(Long::valueOf)
.toArray(Long[]::new));
}
postService.removeBatch(cmd.getIds());
return SingleResponse.buildSuccess();
}

View File

@ -33,18 +33,6 @@ public class PostAddExe {
@Transactional(rollbackFor = Exception.class)
public boolean execute(PostAddCmd cmd) {
// 数据类型转换
if(StrUtil.isNotBlank(cmd.getDepartmentIdString())){
cmd.setDepartmentId(Long.valueOf(cmd.getDepartmentIdString()));
}
// if(cmd.getDepartmentIdsString() != null && cmd.getDepartmentIdsString().length > 0){
// cmd.setDepartmentIds(Arrays.stream(cmd.getDepartmentIdsString())
// .filter(Objects::nonNull) // 过滤掉null
// .filter(str -> !str.trim().isEmpty()) // 过滤掉空字符串
// .map(Long::valueOf)
// .toArray(Long[]::new));
// }
PostE postE = new PostE();
BeanUtils.copyProperties(cmd, postE);
boolean res = false;

View File

@ -1,10 +1,12 @@
package com.zcloud.basic.info.command;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zcloud.basic.info.domain.gateway.PostDepartmentGateway;
import com.zcloud.basic.info.domain.gateway.PostGateway;
import com.alibaba.cola.exception.BizException;
import com.zcloud.basic.info.domain.model.UserE;
import com.zcloud.basic.info.persistence.dataobject.DepartmentDO;
import com.zcloud.basic.info.persistence.dataobject.PostDO;
import com.zcloud.basic.info.persistence.dataobject.UserDO;
@ -40,14 +42,10 @@ public class PostRemoveExe {
@Transactional(rollbackFor = Exception.class)
public boolean execute(Long id) {
// 这段代码后续放到user的方法中, 校验是否有人员使用该岗位
QueryWrapper queryWrapper = new QueryWrapper();
queryWrapper.eq("post_id", id);
queryWrapper.eq("delete_enum", "FALSE");
List userPostList = userRepository.list(queryWrapper);
if (userPostList != null && userPostList.size() > 0) {
throw new BizException("岗位有相应人员,请解除相关岗位信息后删除。");
}
// 校验是否有人员使用该岗位
List<UserDO> userDOS = userRepository.listByPostId(id);
UserE userE = new UserE();
userE.checkNull(BeanUtil.copyToList(userDOS, UserE.class));
boolean res = postGateway.deletedPostById(id);
postDepartmentGateway.deletedPostDepartment(id);
@ -64,14 +62,10 @@ public class PostRemoveExe {
if (ids == null || ids.length == 0) {
throw new BizException("岗位ID不能为空");
}
// 这段代码后续放到user的方法中, 校验是否有人员使用该岗位
QueryWrapper<UserDO> queryWrapper = new QueryWrapper();
queryWrapper.in("post_id", ids);
queryWrapper.eq("delete_enum", "FALSE");
List<UserDO> userPostList = userRepository.list(queryWrapper);
if (userPostList != null && userPostList.size() > 0) {
throw new BizException("岗位有相应人员,请解除相关岗位信息后删除。");
}
// 校验是否有人员使用该岗位
List<UserDO> userDOS = userRepository.listByPostIds(ids);
UserE userE = new UserE();
userE.checkNull(BeanUtil.copyToList(userDOS, UserE.class));
boolean res = postGateway.deletedPostByIds(ids);
postDepartmentGateway.deletedPostDepartment(ids);

View File

@ -40,21 +40,6 @@ public class PostUpdateExe {
@Transactional(rollbackFor = Exception.class)
public void execute(PostUpdateCmd postUpdateCmd) {
// 数据类型转换
if(StrUtil.isNotBlank(postUpdateCmd.getIdString())){
postUpdateCmd.setId(Long.valueOf(postUpdateCmd.getIdString()));
}
if(StrUtil.isNotBlank(postUpdateCmd.getDepartmentIdString())){
postUpdateCmd.setDepartmentId(Long.valueOf(postUpdateCmd.getDepartmentIdString()));
}
// if(postUpdateCmd.getDepartmentIdsString() != null && postUpdateCmd.getDepartmentIdsString().length > 0){
// postUpdateCmd.setDepartmentIds(Arrays.stream(postUpdateCmd.getDepartmentIdsString())
// .filter(Objects::nonNull) // 过滤掉null
// .filter(str -> !str.trim().isEmpty()) // 过滤掉空字符串
// .map(Long::valueOf)
// .toArray(Long[]::new));
// }
PostDO postDO = postRepository.getById(postUpdateCmd.getId());
if (postDO == null) {
throw new BizException("岗位不存在");

View File

@ -20,9 +20,8 @@ import javax.validation.constraints.*;
@NoArgsConstructor
@AllArgsConstructor
public class PostAddCmd extends Command {
@ApiModelProperty(value = "部门id", name = "departmentIdString", required = true)
@ApiModelProperty(value = "部门id", name = "departmentId", required = true)
@NotEmpty(message = "部门id不能为空")
private String departmentIdString;
private Long departmentId;
@ApiModelProperty(value = "岗位名称", name = "postName", required = true)
@ -33,9 +32,8 @@ public class PostAddCmd extends Command {
@NotEmpty(message = "岗位职责不能为空")
private String remarks;
@ApiModelProperty(value = "企业id", name = "corpinfoIdString", required = true)
@ApiModelProperty(value = "企业id", name = "corpinfoId", required = true)
@NotEmpty(message = "企业id不能为空")
private String corpinfoIdString;
private Long corpinfoId;
@ApiModelProperty(value = "企业名称", name = "corpinfoName", required = true)

View File

@ -32,15 +32,13 @@ public class PostListQry {
// 监管端/企业端标识,1-监管端, 2-企业端
private Integer corpFlag;
@ApiModelProperty(value = "主键id集合", name = "postIdsString")
@ApiModelProperty(value = "主键id集合", name = "postIds")
// 主键id集合
private String[] postIdsString;
private Long[] postIds;
@ApiModelProperty(value = "部门id", name = "departmentIdString", required = true)
@ApiModelProperty(value = "部门id", name = "departmentId", required = true)
@NotEmpty(message = "部门id不能为空")
// 部门id
private String departmentIdString;
private Long departmentId;
@ApiModelProperty(value = "企业id", name = "corpinfoId", required = true)

View File

@ -33,10 +33,9 @@ public class PostPageQry extends PageQuery {
// 监管端/企业端标识,1-监管端, 2-企业端
private Integer corpFlag;
@ApiModelProperty(value = "部门id", name = "departmentIdString", required = true)
@ApiModelProperty(value = "部门id", name = "eqDepartmentId", required = true)
@NotEmpty(message = "部门id不能为空")
// 部门id
private String departmentIdString;
private Long eqDepartmentId;
@ApiModelProperty(value = "企业id", name = "eqCorpinfoId")

View File

@ -21,9 +21,8 @@ import javax.validation.constraints.*;
@AllArgsConstructor
public class PostRemoveCmd extends Command {
@ApiModelProperty(value = "主键", name = "idsString", required = true)
@ApiModelProperty(value = "主键", name = "ids", required = true)
@NotEmpty(message = "主键不能为空")
private String[] idsString;
private Long[] ids;
}

View File

@ -20,14 +20,12 @@ import javax.validation.constraints.*;
@NoArgsConstructor
@AllArgsConstructor
public class PostUpdateCmd extends Command {
@ApiModelProperty(value = "主键", name = "idString", required = true)
@ApiModelProperty(value = "主键", name = "id", required = true)
@NotEmpty(message = "主键不能为空")
private String idString;
private Long id;
@ApiModelProperty(value = "部门id", name = "departmentIdString", required = true)
@ApiModelProperty(value = "部门id", name = "departmentId", required = true)
@NotEmpty(message = "部门id不能为空")
private String departmentIdString;
private Long departmentId;
@ApiModelProperty(value = "岗位名称", name = "postName", required = true)