|
@@ -1,16 +1,24 @@
|
|
|
package cn.iocoder.yudao.module.relations.service.contractinfo;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.util.IdUtil;
|
|
|
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.relations.enums.contractinfo.ContractInfoStatusEnum;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
|
import static cn.iocoder.yudao.module.relations.enums.ErrorCodeConstants.RELATIONS_CONTRACT_INFO_NOT_EXISTS;
|
|
|
|
|
@@ -27,15 +35,35 @@ public class RelationsContractInfoServiceImpl implements RelationsContractInfoSe
|
|
|
private RelationsContractInfoMapper contractInfoMapper;
|
|
|
|
|
|
@Override
|
|
|
+ @TenantIgnore
|
|
|
public Long createContractInfo(RelationsContractInfoSaveReqVO createReqVO) {
|
|
|
+
|
|
|
+ List<RelationsContractInfoDO> list = contractInfoMapper.selectPage(new RelationsContractInfoPageReqVO().setEmployeeId(createReqVO.getEmployeeId())).getList();
|
|
|
+
|
|
|
+ if (!CollUtil.isEmpty(list)) {
|
|
|
+
|
|
|
+ List<RelationsContractInfoDO> toUpdate = new ArrayList<>();
|
|
|
+ for (RelationsContractInfoDO contract : list) {
|
|
|
+ contract.setStatus(ContractInfoStatusEnum.HISTORY.getStatus());
|
|
|
+ toUpdate.add(contract);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!toUpdate.isEmpty()) {
|
|
|
+ contractInfoMapper.updateBatch(toUpdate);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+
|
|
|
+ createReqVO.setInfoId(IdUtil.fastSimpleUUID());
|
|
|
RelationsContractInfoDO contractInfo = BeanUtils.toBean(createReqVO, RelationsContractInfoDO.class);
|
|
|
+ contractInfo.setStatus(ContractInfoStatusEnum.LATEST.getStatus());
|
|
|
contractInfoMapper.insert(contractInfo);
|
|
|
|
|
|
return contractInfo.getId();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ @TenantIgnore
|
|
|
public void updateContractInfo(RelationsContractInfoSaveReqVO updateReqVO) {
|
|
|
|
|
|
validateContractInfoExists(updateReqVO.getId());
|
|
@@ -45,6 +73,7 @@ public class RelationsContractInfoServiceImpl implements RelationsContractInfoSe
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ @TenantIgnore
|
|
|
public void deleteContractInfo(Long id) {
|
|
|
|
|
|
validateContractInfoExists(id);
|
|
@@ -52,6 +81,7 @@ public class RelationsContractInfoServiceImpl implements RelationsContractInfoSe
|
|
|
contractInfoMapper.deleteById(id);
|
|
|
}
|
|
|
|
|
|
+ @TenantIgnore
|
|
|
private void validateContractInfoExists(Long id) {
|
|
|
if (contractInfoMapper.selectById(id) == null) {
|
|
|
throw exception(RELATIONS_CONTRACT_INFO_NOT_EXISTS);
|
|
@@ -59,13 +89,57 @@ public class RelationsContractInfoServiceImpl implements RelationsContractInfoSe
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ @TenantIgnore
|
|
|
public RelationsContractInfoDO getContractInfo(Long id) {
|
|
|
return contractInfoMapper.selectById(id);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ @TenantIgnore
|
|
|
public PageResult<RelationsContractInfoDO> getContractInfoPage(RelationsContractInfoPageReqVO pageReqVO) {
|
|
|
return contractInfoMapper.selectPage(pageReqVO);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ @TenantIgnore
|
|
|
+ public int effectiveContractInfo() {
|
|
|
+
|
|
|
+ List<RelationsContractInfoDO> doneContracts = contractInfoMapper.selectListByStatusAndEffectiveDateGe(
|
|
|
+ null, LocalDate.now());
|
|
|
+ if (CollUtil.isEmpty(doneContracts)) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ Set<Long> employeeIds = new HashSet<>();
|
|
|
+ for (RelationsContractInfoDO contract : doneContracts) {
|
|
|
+ employeeIds.add(contract.getEmployeeId());
|
|
|
+ }
|
|
|
+
|
|
|
+ List<RelationsContractInfoDO> contracts = contractInfoMapper.selectListByStatusAndEmployeeIds(
|
|
|
+ null, employeeIds);
|
|
|
+ Map<Long, List<RelationsContractInfoDO>> employeeToEffectiveContracts = contracts.stream()
|
|
|
+ .collect(Collectors.groupingBy(RelationsContractInfoDO::getEmployeeId));
|
|
|
+
|
|
|
+ List<RelationsContractInfoDO> toUpdate = new ArrayList<>();
|
|
|
+ for (RelationsContractInfoDO contract : doneContracts) {
|
|
|
+ List<RelationsContractInfoDO> effectives = employeeToEffectiveContracts.getOrDefault(contract.getEmployeeId(), Collections.emptyList());
|
|
|
+
|
|
|
+
|
|
|
+ for (RelationsContractInfoDO effective : effectives) {
|
|
|
+ effective.setStatus(ContractInfoStatusEnum.HISTORY.getStatus());
|
|
|
+ toUpdate.add(effective);
|
|
|
+ }
|
|
|
+
|
|
|
+ contract.setStatus(ContractInfoStatusEnum.LATEST.getStatus());
|
|
|
+ toUpdate.add(contract);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!toUpdate.isEmpty()) {
|
|
|
+ contractInfoMapper.updateBatch(toUpdate);
|
|
|
+ }
|
|
|
+
|
|
|
+ return doneContracts.size();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|