dev:岗位管理-删除校验;名称重复校验
parent
e12b513afd
commit
367cb33c29
|
|
@ -1,12 +1,18 @@
|
|||
package com.zcloud.basic.info.command;
|
||||
|
||||
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.gateway.UserGateway;
|
||||
import com.zcloud.basic.info.persistence.dataobject.UserDO;
|
||||
import com.zcloud.basic.info.persistence.repository.UserRepository;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* web-app
|
||||
|
|
@ -19,9 +25,19 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
public class PostRemoveExe {
|
||||
private final PostGateway postGateway;
|
||||
private final PostDepartmentGateway postDepartmentGateway;
|
||||
private final UserRepository userRepository;
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean execute(Long id) {
|
||||
// todo 校验是否有人员使用该岗位
|
||||
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("删除失败,该岗位正在被使用");
|
||||
}
|
||||
|
||||
boolean res = postGateway.deletedPostById(id);
|
||||
postDepartmentGateway.deletedPostDepartment(id);
|
||||
if (!res) {
|
||||
|
|
@ -32,6 +48,20 @@ public class PostRemoveExe {
|
|||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean execute(Long[] ids) {
|
||||
|
||||
if (ids == null || ids.length == 0) {
|
||||
throw new BizException("岗位ID不能为空");
|
||||
}
|
||||
|
||||
// todo 校验是否有人员使用该岗位
|
||||
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("删除失败,有岗位正在被使用");
|
||||
}
|
||||
|
||||
boolean res = postGateway.deletedPostByIds(ids);
|
||||
postDepartmentGateway.deletedPostDepartment(ids);
|
||||
if (!res) {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package com.zcloud.basic.info.gatewayimpl;
|
||||
|
||||
import com.alibaba.cola.exception.BizException;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.zcloud.basic.info.domain.gateway.PostGateway;
|
||||
import com.zcloud.basic.info.domain.model.PostE;
|
||||
import com.zcloud.basic.info.persistence.dataobject.PostDO;
|
||||
|
|
@ -12,6 +14,7 @@ import org.springframework.stereotype.Service;
|
|||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* web-infrastructure
|
||||
|
|
@ -26,6 +29,16 @@ public class PostGatewayImpl implements PostGateway {
|
|||
|
||||
@Override
|
||||
public Long add(PostE postE) {
|
||||
|
||||
QueryWrapper<PostDO> wrapper = new QueryWrapper<>();
|
||||
wrapper.eq("department_id", postE.getDepartmentId());
|
||||
wrapper.eq("post_name", postE.getPostName());
|
||||
wrapper.eq("delete_enum", "FALSE");
|
||||
List<PostDO> postDOList = postRepository.list(wrapper);
|
||||
if(postDOList != null && postDOList.size() > 0) {
|
||||
throw new BizException("保存失败,该岗位名称已存在");
|
||||
}
|
||||
|
||||
PostDO d = new PostDO();
|
||||
BeanUtils.copyProperties(postE, d);
|
||||
if(StringUtils.isEmpty(d.getPostId())){
|
||||
|
|
@ -37,6 +50,17 @@ public class PostGatewayImpl implements PostGateway {
|
|||
|
||||
@Override
|
||||
public Boolean update(PostE postE) {
|
||||
|
||||
QueryWrapper<PostDO> wrapper = new QueryWrapper<>();
|
||||
wrapper.ne("id", postE.getId());
|
||||
wrapper.eq("department_id", postE.getDepartmentId());
|
||||
wrapper.eq("post_name", postE.getPostName());
|
||||
wrapper.eq("delete_enum", "FALSE");
|
||||
List<PostDO> postDOList = postRepository.list(wrapper);
|
||||
if(postDOList != null && postDOList.size() > 0) {
|
||||
throw new BizException("修改失败,该岗位名称已存在");
|
||||
}
|
||||
|
||||
PostDO d = new PostDO();
|
||||
BeanUtils.copyProperties(postE, d);
|
||||
postRepository.updateById(d);
|
||||
|
|
|
|||
Loading…
Reference in New Issue