161 lines
8.5 KiB
Java
161 lines
8.5 KiB
Java
package com.engine.salary.service.impl;
|
|
|
|
import com.engine.common.util.ServiceUtil;
|
|
import com.engine.core.impl.Service;
|
|
import com.engine.salary.biz.SalarySobRangeBiz;
|
|
import com.engine.salary.entity.salarysob.bo.SalarySobRangeSaveBO;
|
|
import com.engine.salary.entity.salarysob.dto.SalarySobRangeListDTO;
|
|
import com.engine.salary.entity.salarysob.param.SalarySobRangeQueryParam;
|
|
import com.engine.salary.entity.salarysob.param.SalarySobRangeSaveParam;
|
|
import com.engine.salary.entity.salarysob.po.SalarySobPO;
|
|
import com.engine.salary.entity.salarysob.po.SalarySobRangePO;
|
|
import com.engine.salary.enums.salarysob.TargetTypeEnum;
|
|
import com.engine.salary.exception.SalaryRunTimeException;
|
|
import com.engine.salary.service.SalarySobRangeService;
|
|
import com.engine.salary.service.SalarySobService;
|
|
import com.engine.salary.util.SalaryEntityUtil;
|
|
import com.engine.salary.util.SalaryI18nUtil;
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
import org.apache.commons.lang3.math.NumberUtils;
|
|
import weaver.hrm.User;
|
|
|
|
import java.util.*;
|
|
import java.util.stream.Collectors;
|
|
|
|
/**
|
|
* 薪资账套人员范围
|
|
* <p>Copyright: Copyright (c) 2022</p>
|
|
* <p>Company: 泛微软件</p>
|
|
*
|
|
* @author qiantao
|
|
* @version 1.0
|
|
**/
|
|
public class SalarySobRangeServiceImpl extends Service implements SalarySobRangeService {
|
|
|
|
private SalarySobRangeBiz salarySobRangeMapper = new SalarySobRangeBiz();
|
|
|
|
private SalarySobService getSalarySobService(User user) {
|
|
return (SalarySobService) ServiceUtil.getService(SalarySobServiceImpl.class, user);
|
|
}
|
|
|
|
|
|
// private ComInfoCache comInfoCache;
|
|
// private LoggerTemplate salarySobLoggerTemplate;
|
|
|
|
@Override
|
|
public List<SalarySobRangePO> listByIds(Collection<Long> ids) {
|
|
if (CollectionUtils.isEmpty(ids)) {
|
|
return Collections.emptyList();
|
|
}
|
|
return salarySobRangeMapper.listSome(SalarySobRangePO.builder().ids(ids).build());
|
|
}
|
|
|
|
@Override
|
|
public List<SalarySobRangePO> listBySalarySobIdAndIncludeType(Long salarySobId, Integer includeType) {
|
|
return salarySobRangeMapper.listSome(SalarySobRangePO.builder().salarySobId(salarySobId).includeType(includeType).build());
|
|
}
|
|
|
|
@Override
|
|
public List<SalarySobRangeListDTO> listPageByParamAndIncludeType(SalarySobRangeQueryParam queryParam, Integer includeType) {
|
|
// 查询人员范围
|
|
List<SalarySobRangePO> salarySobRangePOS = listBySalarySobIdAndIncludeType(queryParam.getSalarySobId(), includeType);
|
|
// 查询人员信息
|
|
List<Object> employeeIds = salarySobRangePOS.stream()
|
|
.filter(e -> Objects.equals(e.getTargetType(), TargetTypeEnum.EMPLOYEE.getValue()))
|
|
.map(SalarySobRangePO::getTargetId)
|
|
.collect(Collectors.toList());
|
|
// todo 缓存获取人员信息 List<HrmEmployeeComInfo> employeeComInfos = comInfoCache.getCacheList(HrmEmployeeComInfo.class, employeeIds);
|
|
// 查询部分信息
|
|
List<Object> departmentIds = salarySobRangePOS.stream()
|
|
.filter(e -> Objects.equals(e.getTargetType(), TargetTypeEnum.DEPT.getValue()))
|
|
.map(SalarySobRangePO::getTargetId)
|
|
.collect(Collectors.toList());
|
|
// todo List<HrmDepartmentComInfo> departmentComInfos = comInfoCache.getCacheList(HrmDepartmentComInfo.class, departmentIds);
|
|
// 查询岗位信息
|
|
List<Object> positionIds = salarySobRangePOS.stream()
|
|
.filter(e -> Objects.equals(e.getTargetType(), TargetTypeEnum.POSITION.getValue()))
|
|
.map(SalarySobRangePO::getTargetId)
|
|
.collect(Collectors.toList());
|
|
// todo List<HrmPositionComInfo> positionComInfos = comInfoCache.getCacheList(HrmPositionComInfo.class, positionIds);
|
|
// // 分页参数
|
|
// Page<SalarySobRangeListDTO> dtoPage = SalaryPageUtil.buildPage(queryParam.getCurrent(), queryParam.getPageSize());
|
|
// // 薪资账套的人员范围po转换成列表dto
|
|
// List<SalarySobRangeListDTO> salarySobRangeListDTOS = SalarySobRangeBO.convert2ListDTO(salarySobRangePOS, employeeComInfos, departmentComInfos, positionComInfos);
|
|
// // 根据对象名称过滤
|
|
// if (StringUtils.isNotEmpty(queryParam.getTargetName())) {
|
|
// salarySobRangeListDTOS = salarySobRangeListDTOS.stream()
|
|
// .filter(salarySobRangeListDTO -> salarySobRangeListDTO.getTargetName().contains(queryParam.getTargetName()))
|
|
// .collect(Collectors.toList());
|
|
// }
|
|
// // 填充总数和当页数据
|
|
// dtoPage.setTotal(salarySobRangeListDTOS.size());
|
|
// dtoPage.setRecords(SalaryPageUtil.subList((int) dtoPage.getCurrent(), (int) dtoPage.getSize(), salarySobRangeListDTOS));
|
|
// return dtoPage;
|
|
return null;
|
|
}
|
|
|
|
@Override
|
|
public void save(SalarySobRangeSaveParam saveParam) {
|
|
// 查询薪资账套
|
|
SalarySobPO salarySobPO = getSalarySobService(user).getById(saveParam.getSalarySobId());
|
|
if (Objects.isNull(salarySobPO)) {
|
|
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98379, "参数错误,薪资账套不存在或者已被删除"));
|
|
}
|
|
// 查询已有的人员范围
|
|
List<SalarySobRangePO> salarySobRangePOS = listBySalarySobIdAndIncludeType(saveParam.getSalarySobId(), saveParam.getIncludeType());
|
|
// 处理一下本次的保存参数(如果原来添加过对应的人员(/部门/岗位),那么本次不需要新增,只需要更新)
|
|
SalarySobRangeSaveBO.Result result = SalarySobRangeSaveBO.handle(salarySobRangePOS, saveParam, (long) user.getUID());
|
|
// 保存
|
|
if (CollectionUtils.isNotEmpty(result.getNeedInsertSalarySobRanges())) {
|
|
salarySobRangeMapper.batchInsert(result.getNeedInsertSalarySobRanges());
|
|
}
|
|
if (CollectionUtils.isNotEmpty(result.getNeedUpdateSalarySobRanges())) {
|
|
result.getNeedUpdateSalarySobRanges().forEach(e -> salarySobRangeMapper.updateById(e));
|
|
}
|
|
// todo 记录日志
|
|
// String operateTypeName = Objects.equals(saveParam.getIncludeType(), NumberUtils.INTEGER_ONE) ?
|
|
// SalaryI18nUtil.getI18nLabel(98601, "关联人员范围新增对象") : SalaryI18nUtil.getI18nLabel(98602, "从范围中排除新增对象");
|
|
// LoggerContext<SalarySobRangeSaveParam> loggerContext = new LoggerContext<>();
|
|
// loggerContext.setTargetId("" + salarySobPO.getId());
|
|
// loggerContext.setTargetName(salarySobPO.getName());
|
|
// loggerContext.setOperateType(OperateTypeEnum.UPDATE.getValue());
|
|
// loggerContext.setOperateTypeName(operateTypeName);
|
|
// loggerContext.setOperatedesc(operateTypeName);
|
|
// loggerContext.setNewValues(saveParam);
|
|
// salarySobLoggerTemplate.write(loggerContext);
|
|
}
|
|
|
|
@Override
|
|
public void deleteByIds(Collection<Long> ids) {
|
|
// 查询薪资账套的人员范围
|
|
List<SalarySobRangePO> salarySobRangePOS = listByIds(ids);
|
|
if (CollectionUtils.isEmpty(salarySobRangePOS)) {
|
|
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98604, "数据不存在或已被删除"));
|
|
}
|
|
ids = SalaryEntityUtil.properties(salarySobRangePOS, SalarySobRangePO::getId);
|
|
// 删除薪资账套的人员范围
|
|
salarySobRangeMapper.deleteByIds(ids);
|
|
// 查询薪资账套
|
|
Set<Long> salarySobIds = SalaryEntityUtil.properties(salarySobRangePOS, SalarySobRangePO::getSalarySobId);
|
|
List<SalarySobPO> salarySobPOS = getSalarySobService(user).listByIds(salarySobIds);
|
|
// 是"关联人员范围"还是"从范围中排除"
|
|
Integer includeType = salarySobRangePOS.get(0).getIncludeType();
|
|
// todo 记录日志
|
|
String operateTypeName = Objects.equals(includeType, NumberUtils.INTEGER_ONE) ?
|
|
SalaryI18nUtil.getI18nLabel(98605, "关联人员范围删除对象") : SalaryI18nUtil.getI18nLabel(98606, "从范围中排除删除对象");
|
|
// salarySobPOS.forEach(salarySobPO -> {
|
|
// LoggerContext<SalarySobPO> loggerContext = new LoggerContext<>();
|
|
// loggerContext.setTargetId("" + salarySobPO.getId());
|
|
// loggerContext.setTargetName(salarySobPO.getName());
|
|
// loggerContext.setOperateType(OperateTypeEnum.DELETE.getValue());
|
|
// loggerContext.setOperateTypeName(operateTypeName);
|
|
// loggerContext.setOperatedesc(operateTypeName);
|
|
// });
|
|
}
|
|
|
|
@Override
|
|
public void deleteBySalarySobIds(Collection<Long> salarySobIds) {
|
|
salarySobRangeMapper.deleteBySalarySobIds(salarySobIds);
|
|
}
|
|
}
|