From 5653726bd247bd9c49591695fda5afe8ae42f4b1 Mon Sep 17 00:00:00 2001 From: xiao-fajia <1665375861@qq.com> Date: Fri, 9 Aug 2024 09:09:10 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=81=E4=B8=9A=E7=AE=A1=E7=90=86-=E5=91=98?= =?UTF-8?q?=E5=B7=A5=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/CommonErrorCodeConstants.java | 1 + .../impl/CompanyStaffChangeServiceImpl.java | 41 ++++++++++++++----- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/dl-module-base/src/main/java/cn/iocoder/yudao/common/CommonErrorCodeConstants.java b/dl-module-base/src/main/java/cn/iocoder/yudao/common/CommonErrorCodeConstants.java index 5032d26f..b02002c7 100644 --- a/dl-module-base/src/main/java/cn/iocoder/yudao/common/CommonErrorCodeConstants.java +++ b/dl-module-base/src/main/java/cn/iocoder/yudao/common/CommonErrorCodeConstants.java @@ -7,4 +7,5 @@ public interface CommonErrorCodeConstants extends ErrorCodeConstants { /** 企业管理-员工管理 */ ErrorCode UNIQUE_CODE_CREATE_REPEAT = new ErrorCode(2_002_000_000, "唯一推广码生成失败"); + ErrorCode STAFF_CHANGE_CREATE_REPEAT = new ErrorCode(2_002_000_001, "交出或接收员工已有交接记录"); } diff --git a/dl-module-company/src/main/java/cn/iocoder/yudao/module/staff/service/impl/CompanyStaffChangeServiceImpl.java b/dl-module-company/src/main/java/cn/iocoder/yudao/module/staff/service/impl/CompanyStaffChangeServiceImpl.java index 7e8ac643..f9b82bfc 100644 --- a/dl-module-company/src/main/java/cn/iocoder/yudao/module/staff/service/impl/CompanyStaffChangeServiceImpl.java +++ b/dl-module-company/src/main/java/cn/iocoder/yudao/module/staff/service/impl/CompanyStaffChangeServiceImpl.java @@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.staff.service.impl; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.util.ObjectUtil; +import cn.iocoder.yudao.common.CommonErrorCodeConstants; import cn.iocoder.yudao.module.staff.entity.CompanyStaff; import cn.iocoder.yudao.module.staff.entity.CompanyStaffChange; import cn.iocoder.yudao.module.staff.mapper.CompanyStaffChangeMapper; @@ -13,13 +14,15 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.springframework.stereotype.Service; import javax.annotation.Resource; -import java.util.List; + +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; /** * 企业管理-员工交接记录 接口实现类 + * * @author 小李 * @date 15:40 2024/8/8 -**/ + **/ @Service public class CompanyStaffChangeServiceImpl extends ServiceImpl implements CompanyStaffChangeService { @@ -28,34 +31,50 @@ public class CompanyStaffChangeServiceImpl extends ServiceImpl().and(itme -> { + itme.eq("old_user_id", staffChangeRespVO.getOldUserId()) + .eq("new_user_id", staffChangeRespVO.getNewUserId()); + }).or().eq("old_user_id", staffChangeRespVO.getOldUserId()) + .or().eq("new_user_id", staffChangeRespVO.getNewUserId())); + if (ObjectUtil.isNotEmpty(staffChange)) { + throw exception(CommonErrorCodeConstants.STAFF_CHANGE_CREATE_REPEAT); + } baseMapper.insert(staffChangeRespVO); // TODO 交接工作记录待完成 } /** * 查询交接双方信息 + * + * @param id 接收方员工ID * @author 小李 * @date 18:26 2024/8/8 - * @param id 接收方员工ID **/ @Override - public CompanyStaffChangeRespVO getChangeStaff(String id){ + public CompanyStaffChangeRespVO getChangeStaff(String id) { /** 构造返回对象 */ CompanyStaffChangeRespVO result = null; // 1 根据当前ID获取员工记录 - CompanyStaff newStaff = staffService.getOne(new QueryWrapper().eq("id", id)); + CompanyStaff staff = staffService.getOne(new QueryWrapper().eq("id", id)); // 2 根据获取的员工信息中的userId获取交接记录 - CompanyStaffChange staffChange = baseMapper.selectOne(new QueryWrapper().eq("new_user_id", newStaff.getUserId())); - if (ObjectUtil.isNotEmpty(staffChange)){ - result = new CompanyStaffChangeRespVO(); + CompanyStaffChange staffChange = baseMapper.selectOne(new QueryWrapper() + .eq("new_user_id", staff.getUserId()) + .or() + .eq("old_user_id", staff.getUserId()) + ); + if (ObjectUtil.isNotEmpty(staffChange)) { + result = new CompanyStaffChangeRespVO(); BeanUtil.copyProperties(staffChange, result); - // 3 根据交接记录中老员工的userId查老员工信息 + // 3 根据交接记录中新老员工的userId查新老员工信息 CompanyStaff oldStaff = staffService.getOne(new QueryWrapper().eq("user_id", staffChange.getOldUserId())); + CompanyStaff newStaff = staffService.getOne(new QueryWrapper().eq("user_id", staffChange.getNewUserId())); result.setNewStaff(newStaff); result.setOldStaff(oldStaff); }