|
@@ -7,7 +7,9 @@ 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.infra.api.file.FileApi;
|
|
|
+import cn.iocoder.yudao.module.infra.api.file.dto.FileDTO;
|
|
|
import cn.iocoder.yudao.module.relations.controller.admin.contract.vo.RelationsContractPageReqVO;
|
|
|
+import cn.iocoder.yudao.module.relations.controller.admin.contract.vo.RelationsContractRespVO;
|
|
|
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;
|
|
@@ -35,7 +37,7 @@ import static cn.iocoder.yudao.module.relations.enums.ErrorCodeConstants.RELATIO
|
|
|
public class RelationsContractServiceImpl implements RelationsContractService {
|
|
|
|
|
|
@Resource
|
|
|
- private RelationsContractMapper contractInfoMapper;
|
|
|
+ private RelationsContractMapper contractMapper;
|
|
|
@Resource
|
|
|
private FileApi fileApi;
|
|
|
|
|
@@ -43,7 +45,7 @@ public class RelationsContractServiceImpl implements RelationsContractService {
|
|
|
@TenantIgnore
|
|
|
public Long createContractInfo(RelationsContractSaveReqVO createReqVO) {
|
|
|
// 查询该员工是否有合同存在
|
|
|
- List<RelationsContractDO> list = contractInfoMapper.selectPage(new RelationsContractPageReqVO().setEmployeeId(createReqVO.getEmployeeId())).getList();
|
|
|
+ List<RelationsContractDO> list = contractMapper.selectPage(new RelationsContractPageReqVO().setEmployeeId(createReqVO.getEmployeeId())).getList();
|
|
|
// 检查查询结果是否为空
|
|
|
if (!CollUtil.isEmpty(list)) {
|
|
|
// 更新状态
|
|
@@ -54,7 +56,7 @@ public class RelationsContractServiceImpl implements RelationsContractService {
|
|
|
}
|
|
|
// 批量更新
|
|
|
if (!toUpdate.isEmpty()) {
|
|
|
- contractInfoMapper.updateBatch(toUpdate);
|
|
|
+ contractMapper.updateBatch(toUpdate);
|
|
|
}
|
|
|
}
|
|
|
// 插入
|
|
@@ -62,7 +64,7 @@ public class RelationsContractServiceImpl implements RelationsContractService {
|
|
|
createReqVO.setContractId(infoId);
|
|
|
RelationsContractDO contractInfo = BeanUtils.toBean(createReqVO, RelationsContractDO.class);
|
|
|
contractInfo.setStatus(ContractInfoStatusEnum.LATEST.getStatus());
|
|
|
- contractInfoMapper.insert(contractInfo);
|
|
|
+ contractMapper.insert(contractInfo);
|
|
|
// 保存业务uuid到附件中
|
|
|
this.saveFileList(createReqVO.getFileIdList(), infoId);
|
|
|
// 返回
|
|
@@ -78,7 +80,7 @@ public class RelationsContractServiceImpl implements RelationsContractService {
|
|
|
this.saveFileList(updateReqVO.getFileIdList(), updateReqVO.getContractId());
|
|
|
// 更新
|
|
|
RelationsContractDO updateObj = BeanUtils.toBean(updateReqVO, RelationsContractDO.class);
|
|
|
- contractInfoMapper.updateById(updateObj);
|
|
|
+ contractMapper.updateById(updateObj);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -87,12 +89,12 @@ public class RelationsContractServiceImpl implements RelationsContractService {
|
|
|
// 校验存在
|
|
|
validateContractInfoExists(id);
|
|
|
// 删除
|
|
|
- contractInfoMapper.deleteById(id);
|
|
|
+ contractMapper.deleteById(id);
|
|
|
}
|
|
|
|
|
|
@TenantIgnore
|
|
|
private void validateContractInfoExists(Long id) {
|
|
|
- if (contractInfoMapper.selectById(id) == null) {
|
|
|
+ if (contractMapper.selectById(id) == null) {
|
|
|
throw exception(RELATIONS_CONTRACT_INFO_NOT_EXISTS);
|
|
|
}
|
|
|
}
|
|
@@ -100,20 +102,48 @@ public class RelationsContractServiceImpl implements RelationsContractService {
|
|
|
@Override
|
|
|
@TenantIgnore
|
|
|
public RelationsContractDO getContractInfo(Long id) {
|
|
|
- return contractInfoMapper.selectById(id);
|
|
|
+ return contractMapper.selectById(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @TenantIgnore
|
|
|
+ public RelationsContractRespVO getById(Long id) {
|
|
|
+ // 第一步:检查ID是否为空
|
|
|
+ if (id == null) {
|
|
|
+ throw new IllegalArgumentException("ID cannot be null");
|
|
|
+ }
|
|
|
+ // 第二步:从数据库获取数据
|
|
|
+ RelationsContractDO contractDO = contractMapper.selectById(id);
|
|
|
+ if (contractDO == null) {
|
|
|
+ throw exception(RELATIONS_CONTRACT_INFO_NOT_EXISTS);
|
|
|
+ }
|
|
|
+ // 第三步:将DO对象转换为VO对象
|
|
|
+ RelationsContractRespVO respVO = BeanUtils.toBean(contractDO, RelationsContractRespVO.class);
|
|
|
+ if (respVO == null) {
|
|
|
+ // 理论上BeanUtils.toBean不应该返回null,但为了安全起见,还是检查一下
|
|
|
+ throw new RuntimeException("Failed to convert DO to VO");
|
|
|
+ }
|
|
|
+ // 第四步:获取附件列表
|
|
|
+ List<FileDTO> fileList = fileApi.getFileDTOListByBiz(contractDO.getContractId());
|
|
|
+ if (fileList != null) {
|
|
|
+ // 如果fileList不为null,则设置到VO对象中
|
|
|
+ respVO.setFileList(fileList);
|
|
|
+ }
|
|
|
+ // 第五步:返回VO对象
|
|
|
+ return respVO;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@TenantIgnore
|
|
|
public PageResult<RelationsContractDO> getContractInfoPage(RelationsContractPageReqVO pageReqVO) {
|
|
|
- return contractInfoMapper.selectPage(pageReqVO);
|
|
|
+ return contractMapper.selectPage(pageReqVO);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@TenantIgnore
|
|
|
public int effectiveContractInfo() {
|
|
|
// 1. 查询状态为已完成且已到合同开始日期的合同
|
|
|
- List<RelationsContractDO> doneContracts = contractInfoMapper.selectListByStatusAndEffectiveDateGe(
|
|
|
+ List<RelationsContractDO> doneContracts = contractMapper.selectListByStatusAndEffectiveDateGe(
|
|
|
null, LocalDate.now());
|
|
|
if (CollUtil.isEmpty(doneContracts)) {
|
|
|
return 0;
|
|
@@ -124,7 +154,7 @@ public class RelationsContractServiceImpl implements RelationsContractService {
|
|
|
employeeIds.add(contract.getEmployeeId());
|
|
|
}
|
|
|
// 3. 一次性查询所有员工ID对应的“有效”状态合同
|
|
|
- List<RelationsContractDO> contracts = contractInfoMapper.selectListByStatusAndEmployeeIds(
|
|
|
+ List<RelationsContractDO> contracts = contractMapper.selectListByStatusAndEmployeeIds(
|
|
|
null, employeeIds);
|
|
|
Map<Long, List<RelationsContractDO>> employeeToEffectiveContracts = contracts.stream()
|
|
|
.collect(Collectors.groupingBy(RelationsContractDO::getEmployeeId));
|
|
@@ -144,7 +174,7 @@ public class RelationsContractServiceImpl implements RelationsContractService {
|
|
|
}
|
|
|
// 5. 批量更新
|
|
|
if (!toUpdate.isEmpty()) {
|
|
|
- contractInfoMapper.updateBatch(toUpdate);
|
|
|
+ contractMapper.updateBatch(toUpdate);
|
|
|
}
|
|
|
// 返回更新的合同数量
|
|
|
return doneContracts.size();
|
|
@@ -153,6 +183,7 @@ public class RelationsContractServiceImpl implements RelationsContractService {
|
|
|
/**
|
|
|
* 保存业务uuid到附件中
|
|
|
*/
|
|
|
+ @TenantIgnore
|
|
|
private void saveFileList(List<Long> fileIdList, String serviceId) {
|
|
|
if (CollectionUtil.isNotEmpty(fileIdList) && StrUtil.isNotEmpty(serviceId)) {
|
|
|
fileApi.updateFileBiz(fileIdList, serviceId);
|