From 367cb33c29ceec8c9e4218f2cc268d85660e41d2 Mon Sep 17 00:00:00 2001 From: SondonYong Date: Tue, 4 Nov 2025 17:18:28 +0800 Subject: [PATCH] =?UTF-8?q?dev:=E5=B2=97=E4=BD=8D=E7=AE=A1=E7=90=86-?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=A0=A1=E9=AA=8C;=E5=90=8D=E7=A7=B0?= =?UTF-8?q?=E9=87=8D=E5=A4=8D=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../basic/info/command/PostRemoveExe.java | 30 +++++++++++++++++++ .../info/gatewayimpl/PostGatewayImpl.java | 24 +++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/web-app/src/main/java/com/zcloud/basic/info/command/PostRemoveExe.java b/web-app/src/main/java/com/zcloud/basic/info/command/PostRemoveExe.java index 0572ca5..036080c 100644 --- a/web-app/src/main/java/com/zcloud/basic/info/command/PostRemoveExe.java +++ b/web-app/src/main/java/com/zcloud/basic/info/command/PostRemoveExe.java @@ -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 queryWrapper = new QueryWrapper(); + queryWrapper.in("post_id", ids); + queryWrapper.eq("delete_enum", "FALSE"); + List userPostList = userRepository.list(queryWrapper); + if (userPostList != null && userPostList.size() > 0) { + throw new BizException("删除失败,有岗位正在被使用"); + } + boolean res = postGateway.deletedPostByIds(ids); postDepartmentGateway.deletedPostDepartment(ids); if (!res) { diff --git a/web-infrastructure/src/main/java/com/zcloud/basic/info/gatewayimpl/PostGatewayImpl.java b/web-infrastructure/src/main/java/com/zcloud/basic/info/gatewayimpl/PostGatewayImpl.java index c827a3a..04efcb8 100644 --- a/web-infrastructure/src/main/java/com/zcloud/basic/info/gatewayimpl/PostGatewayImpl.java +++ b/web-infrastructure/src/main/java/com/zcloud/basic/info/gatewayimpl/PostGatewayImpl.java @@ -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 wrapper = new QueryWrapper<>(); + wrapper.eq("department_id", postE.getDepartmentId()); + wrapper.eq("post_name", postE.getPostName()); + wrapper.eq("delete_enum", "FALSE"); + List 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 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 postDOList = postRepository.list(wrapper); + if(postDOList != null && postDOList.size() > 0) { + throw new BizException("修改失败,该岗位名称已存在"); + } + PostDO d = new PostDO(); BeanUtils.copyProperties(postE, d); postRepository.updateById(d);