2022-03-22 21:01:38 +08:00
|
|
|
package com.engine.salary.service.impl;
|
|
|
|
|
|
|
|
|
|
import com.engine.common.util.ServiceUtil;
|
|
|
|
|
import com.engine.core.impl.Service;
|
2022-03-23 13:52:43 +08:00
|
|
|
import com.engine.hrm.biz.OrganizationShowSetBiz;
|
|
|
|
|
import com.engine.salary.biz.EmployBiz;
|
2022-03-22 21:01:38 +08:00
|
|
|
import com.engine.salary.biz.SalarySobRangeBiz;
|
2022-03-23 18:41:38 +08:00
|
|
|
import com.engine.salary.entity.datacollection.DataCollectionEmployee;
|
|
|
|
|
import com.engine.salary.entity.hrm.DeptInfo;
|
|
|
|
|
import com.engine.salary.entity.hrm.PositionInfo;
|
|
|
|
|
import com.engine.salary.entity.salarysob.bo.SalarySobRangeBO;
|
2022-03-22 21:01:38 +08:00
|
|
|
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;
|
2022-03-23 18:41:38 +08:00
|
|
|
import com.engine.salary.util.page.PageInfo;
|
|
|
|
|
import com.engine.salary.util.page.PageUtil;
|
|
|
|
|
import com.engine.salary.util.valid.ValidUtil;
|
2022-03-22 21:01:38 +08:00
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
2022-03-23 18:41:38 +08:00
|
|
|
import org.apache.commons.lang3.StringUtils;
|
2022-03-22 21:01:38 +08:00
|
|
|
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();
|
2022-03-23 13:52:43 +08:00
|
|
|
private EmployBiz employBiz = new EmployBiz();
|
|
|
|
|
OrganizationShowSetBiz orgBiz = new OrganizationShowSetBiz();
|
|
|
|
|
|
2022-03-22 21:01:38 +08:00
|
|
|
|
|
|
|
|
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
|
2022-03-23 18:41:38 +08:00
|
|
|
public PageInfo<SalarySobRangeListDTO> listPageByParamAndIncludeType(SalarySobRangeQueryParam queryParam, Integer includeType) {
|
2022-03-22 21:01:38 +08:00
|
|
|
// 查询人员范围
|
|
|
|
|
List<SalarySobRangePO> salarySobRangePOS = listBySalarySobIdAndIncludeType(queryParam.getSalarySobId(), includeType);
|
|
|
|
|
// 查询人员信息
|
2022-03-23 18:41:38 +08:00
|
|
|
List<Long> employeeIds = salarySobRangePOS.stream()
|
2022-03-22 21:01:38 +08:00
|
|
|
.filter(e -> Objects.equals(e.getTargetType(), TargetTypeEnum.EMPLOYEE.getValue()))
|
|
|
|
|
.map(SalarySobRangePO::getTargetId)
|
|
|
|
|
.collect(Collectors.toList());
|
2022-03-23 18:41:38 +08:00
|
|
|
List<DataCollectionEmployee> empInfos = employBiz.getEmployeeByIds(employeeIds);
|
2022-03-23 13:52:43 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
// 查询部门信息
|
2022-03-23 18:41:38 +08:00
|
|
|
List<DeptInfo> deptInfos = salarySobRangePOS.stream()
|
2022-03-22 21:01:38 +08:00
|
|
|
.filter(e -> Objects.equals(e.getTargetType(), TargetTypeEnum.DEPT.getValue()))
|
|
|
|
|
.map(SalarySobRangePO::getTargetId)
|
2022-03-23 18:41:38 +08:00
|
|
|
.map(id -> {
|
|
|
|
|
return DeptInfo.builder().id(id).name(orgBiz.getDepartmentShow(String.valueOf(id), "0", "-")).build();
|
|
|
|
|
})
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 查询岗位信息
|
|
|
|
|
List<Long> positionIds = salarySobRangePOS.stream()
|
|
|
|
|
.filter(e -> Objects.equals(e.getTargetType(), TargetTypeEnum.POSITION.getValue()))
|
|
|
|
|
.map(SalarySobRangePO::getTargetId)
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
List<PositionInfo> positionInfos = employBiz.listPositionInfo(positionIds);
|
|
|
|
|
|
|
|
|
|
// 薪资账套的人员范围po转换成列表dto
|
|
|
|
|
List<SalarySobRangeListDTO> salarySobRangeListDTOS = SalarySobRangeBO.convert2ListDTO(salarySobRangePOS, empInfos, deptInfos, positionInfos);
|
|
|
|
|
// 根据对象名称过滤
|
|
|
|
|
if (StringUtils.isNotEmpty(queryParam.getTargetName())) {
|
|
|
|
|
salarySobRangeListDTOS = salarySobRangeListDTOS.stream()
|
|
|
|
|
.filter(salarySobRangeListDTO -> salarySobRangeListDTO.getTargetName().contains(queryParam.getTargetName()))
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
}
|
|
|
|
|
// 填充总数和当页数据
|
|
|
|
|
PageInfo<SalarySobRangeListDTO> pageInfo = new PageInfo<SalarySobRangeListDTO>(salarySobRangeListDTOS,SalarySobRangeListDTO.class);
|
|
|
|
|
pageInfo.setTotal(salarySobRangeListDTOS.size());
|
|
|
|
|
pageInfo.setList(PageUtil.subList(queryParam.getCurrent(), queryParam.getPageSize(), salarySobRangeListDTOS));
|
|
|
|
|
return pageInfo;
|
2022-03-22 21:01:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void save(SalarySobRangeSaveParam saveParam) {
|
2022-03-23 18:41:38 +08:00
|
|
|
|
|
|
|
|
ValidUtil.doValidator(saveParam);
|
|
|
|
|
|
2022-03-22 21:01:38 +08:00
|
|
|
// 查询薪资账套
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|