|
@@ -1,13 +1,16 @@
|
|
|
-package cn.iocoder.yudao.module.relations.service.contractinfo;
|
|
|
+package cn.iocoder.yudao.module.relations.service.contract;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
|
import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
|
|
|
-import cn.iocoder.yudao.module.relations.controller.admin.contractinfo.vo.RelationsContractInfoPageReqVO;
|
|
|
-import cn.iocoder.yudao.module.relations.controller.admin.contractinfo.vo.RelationsContractInfoSaveReqVO;
|
|
|
-import cn.iocoder.yudao.module.relations.dal.dataobject.contractinfo.RelationsContractInfoDO;
|
|
|
-import cn.iocoder.yudao.module.relations.dal.mysql.contractinfo.RelationsContractInfoMapper;
|
|
|
+import cn.iocoder.yudao.module.infra.api.file.FileApi;
|
|
|
+import cn.iocoder.yudao.module.relations.controller.admin.contract.vo.RelationsContractPageReqVO;
|
|
|
+import cn.iocoder.yudao.module.relations.controller.admin.contract.vo.RelationsContractSaveReqVO;
|
|
|
+import cn.iocoder.yudao.module.relations.dal.dataobject.contract.RelationsContractDO;
|
|
|
+import cn.iocoder.yudao.module.relations.dal.mysql.contract.RelationsContractMapper;
|
|
|
import cn.iocoder.yudao.module.relations.enums.contractinfo.ContractInfoStatusEnum;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
@@ -29,21 +32,23 @@ import static cn.iocoder.yudao.module.relations.enums.ErrorCodeConstants.RELATIO
|
|
|
*/
|
|
|
@Service
|
|
|
@Validated
|
|
|
-public class RelationsContractInfoServiceImpl implements RelationsContractInfoService {
|
|
|
+public class RelationsContractServiceImpl implements RelationsContractService {
|
|
|
|
|
|
@Resource
|
|
|
- private RelationsContractInfoMapper contractInfoMapper;
|
|
|
+ private RelationsContractMapper contractInfoMapper;
|
|
|
+ @Resource
|
|
|
+ private FileApi fileApi;
|
|
|
|
|
|
@Override
|
|
|
@TenantIgnore
|
|
|
- public Long createContractInfo(RelationsContractInfoSaveReqVO createReqVO) {
|
|
|
+ public Long createContractInfo(RelationsContractSaveReqVO createReqVO) {
|
|
|
// 查询该员工是否有合同存在
|
|
|
- List<RelationsContractInfoDO> list = contractInfoMapper.selectPage(new RelationsContractInfoPageReqVO().setEmployeeId(createReqVO.getEmployeeId())).getList();
|
|
|
+ List<RelationsContractDO> list = contractInfoMapper.selectPage(new RelationsContractPageReqVO().setEmployeeId(createReqVO.getEmployeeId())).getList();
|
|
|
// 检查查询结果是否为空
|
|
|
if (!CollUtil.isEmpty(list)) {
|
|
|
// 更新状态
|
|
|
- List<RelationsContractInfoDO> toUpdate = new ArrayList<>();
|
|
|
- for (RelationsContractInfoDO contract : list) {
|
|
|
+ List<RelationsContractDO> toUpdate = new ArrayList<>();
|
|
|
+ for (RelationsContractDO contract : list) {
|
|
|
contract.setStatus(ContractInfoStatusEnum.HISTORY.getStatus());
|
|
|
toUpdate.add(contract);
|
|
|
}
|
|
@@ -53,22 +58,26 @@ public class RelationsContractInfoServiceImpl implements RelationsContractInfoSe
|
|
|
}
|
|
|
}
|
|
|
// 插入
|
|
|
- // 生成id
|
|
|
- createReqVO.setInfoId(IdUtil.fastSimpleUUID());
|
|
|
- RelationsContractInfoDO contractInfo = BeanUtils.toBean(createReqVO, RelationsContractInfoDO.class);
|
|
|
+ String infoId = IdUtil.fastSimpleUUID();
|
|
|
+ createReqVO.setContractId(infoId);
|
|
|
+ RelationsContractDO contractInfo = BeanUtils.toBean(createReqVO, RelationsContractDO.class);
|
|
|
contractInfo.setStatus(ContractInfoStatusEnum.LATEST.getStatus());
|
|
|
contractInfoMapper.insert(contractInfo);
|
|
|
+ // 保存业务uuid到附件中
|
|
|
+ this.saveFileList(createReqVO.getFileIdList(), infoId);
|
|
|
// 返回
|
|
|
return contractInfo.getId();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@TenantIgnore
|
|
|
- public void updateContractInfo(RelationsContractInfoSaveReqVO updateReqVO) {
|
|
|
+ public void updateContractInfo(RelationsContractSaveReqVO updateReqVO) {
|
|
|
// 校验存在
|
|
|
validateContractInfoExists(updateReqVO.getId());
|
|
|
+ // 保存业务uuid到附件中
|
|
|
+ this.saveFileList(updateReqVO.getFileIdList(), updateReqVO.getContractId());
|
|
|
// 更新
|
|
|
- RelationsContractInfoDO updateObj = BeanUtils.toBean(updateReqVO, RelationsContractInfoDO.class);
|
|
|
+ RelationsContractDO updateObj = BeanUtils.toBean(updateReqVO, RelationsContractDO.class);
|
|
|
contractInfoMapper.updateById(updateObj);
|
|
|
}
|
|
|
|
|
@@ -90,13 +99,13 @@ public class RelationsContractInfoServiceImpl implements RelationsContractInfoSe
|
|
|
|
|
|
@Override
|
|
|
@TenantIgnore
|
|
|
- public RelationsContractInfoDO getContractInfo(Long id) {
|
|
|
+ public RelationsContractDO getContractInfo(Long id) {
|
|
|
return contractInfoMapper.selectById(id);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@TenantIgnore
|
|
|
- public PageResult<RelationsContractInfoDO> getContractInfoPage(RelationsContractInfoPageReqVO pageReqVO) {
|
|
|
+ public PageResult<RelationsContractDO> getContractInfoPage(RelationsContractPageReqVO pageReqVO) {
|
|
|
return contractInfoMapper.selectPage(pageReqVO);
|
|
|
}
|
|
|
|
|
@@ -104,28 +113,28 @@ public class RelationsContractInfoServiceImpl implements RelationsContractInfoSe
|
|
|
@TenantIgnore
|
|
|
public int effectiveContractInfo() {
|
|
|
// 1. 查询状态为已完成且已到合同开始日期的合同
|
|
|
- List<RelationsContractInfoDO> doneContracts = contractInfoMapper.selectListByStatusAndEffectiveDateGe(
|
|
|
+ List<RelationsContractDO> doneContracts = contractInfoMapper.selectListByStatusAndEffectiveDateGe(
|
|
|
null, LocalDate.now());
|
|
|
if (CollUtil.isEmpty(doneContracts)) {
|
|
|
return 0;
|
|
|
}
|
|
|
// 2. 收集所有需要查询的员工ID
|
|
|
Set<Long> employeeIds = new HashSet<>();
|
|
|
- for (RelationsContractInfoDO contract : doneContracts) {
|
|
|
+ for (RelationsContractDO contract : doneContracts) {
|
|
|
employeeIds.add(contract.getEmployeeId());
|
|
|
}
|
|
|
// 3. 一次性查询所有员工ID对应的“有效”状态合同
|
|
|
- List<RelationsContractInfoDO> contracts = contractInfoMapper.selectListByStatusAndEmployeeIds(
|
|
|
+ List<RelationsContractDO> contracts = contractInfoMapper.selectListByStatusAndEmployeeIds(
|
|
|
null, employeeIds);
|
|
|
- Map<Long, List<RelationsContractInfoDO>> employeeToEffectiveContracts = contracts.stream()
|
|
|
- .collect(Collectors.groupingBy(RelationsContractInfoDO::getEmployeeId));
|
|
|
+ Map<Long, List<RelationsContractDO>> employeeToEffectiveContracts = contracts.stream()
|
|
|
+ .collect(Collectors.groupingBy(RelationsContractDO::getEmployeeId));
|
|
|
// 4. 更新状态
|
|
|
- List<RelationsContractInfoDO> toUpdate = new ArrayList<>();
|
|
|
- for (RelationsContractInfoDO contract : doneContracts) {
|
|
|
- List<RelationsContractInfoDO> effectives = employeeToEffectiveContracts.getOrDefault(contract.getEmployeeId(), Collections.emptyList());
|
|
|
+ List<RelationsContractDO> toUpdate = new ArrayList<>();
|
|
|
+ for (RelationsContractDO contract : doneContracts) {
|
|
|
+ List<RelationsContractDO> effectives = employeeToEffectiveContracts.getOrDefault(contract.getEmployeeId(), Collections.emptyList());
|
|
|
// List<RelationsContractInfoDO> effectives = contractInfoMapper.selectListByStatusAndEmployeeId(ContractInfoStatusEnum.EFFECTIVE.getStatus(), contract.getEmployeeId());
|
|
|
// 标记所有当前有效的合同为已弃用
|
|
|
- for (RelationsContractInfoDO effective : effectives) {
|
|
|
+ for (RelationsContractDO effective : effectives) {
|
|
|
effective.setStatus(ContractInfoStatusEnum.HISTORY.getStatus());
|
|
|
toUpdate.add(effective);
|
|
|
}
|
|
@@ -141,5 +150,13 @@ public class RelationsContractInfoServiceImpl implements RelationsContractInfoSe
|
|
|
return doneContracts.size();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 保存业务uuid到附件中
|
|
|
+ */
|
|
|
+ private void saveFileList(List<Long> fileIdList, String serviceId) {
|
|
|
+ if (CollectionUtil.isNotEmpty(fileIdList) && StrUtil.isNotEmpty(serviceId)) {
|
|
|
+ fileApi.updateFileBiz(fileIdList, serviceId);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
}
|