weaver-hrm-salary/src/com/engine/salary/service/impl/SalarySobRangeServiceImpl.java

204 lines
9.9 KiB
Java
Raw Normal View History

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;
2022-06-09 17:45:28 +08:00
import com.engine.salary.entity.hrm.SubCompanyInfo;
2022-03-23 18:41:38 +08:00
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;
2022-05-25 13:10:03 +08:00
import com.engine.salary.util.page.SalaryPageUtil;
2022-03-23 18:41:38 +08:00
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 {
2022-03-23 20:54:08 +08:00
private SalarySobRangeBiz salarySobRangeBiz = new SalarySobRangeBiz();
2022-03-23 13:52:43 +08:00
private EmployBiz employBiz = new EmployBiz();
2022-03-25 18:05:07 +08:00
private OrganizationShowSetBiz orgBiz = new OrganizationShowSetBiz();
2022-03-23 13:52:43 +08:00
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();
}
2022-03-23 20:54:08 +08:00
return salarySobRangeBiz.listSome(SalarySobRangePO.builder().ids(ids).build());
2022-03-22 21:01:38 +08:00
}
@Override
public List<SalarySobRangePO> listBySalarySobIdAndIncludeType(Long salarySobId, Integer includeType) {
2022-03-23 20:54:08 +08:00
return salarySobRangeBiz.listSome(SalarySobRangePO.builder().salarySobId(salarySobId).includeType(includeType).build());
2022-03-22 21:01:38 +08:00
}
@Override
public List<SalarySobRangePO> listAllSalarySobRange() {
return salarySobRangeBiz.listSome(SalarySobRangePO.builder().build());
}
2022-03-22 21:01:38 +08:00
@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());
2022-06-09 17:45:28 +08:00
// 查询分部信息
List<SubCompanyInfo> subCompanyInfos = salarySobRangePOS.stream()
.filter(e -> Objects.equals(e.getTargetType(), TargetTypeEnum.SUBCOMPANY.getValue()))
.map(SalarySobRangePO::getTargetId)
.map(id -> {
return SubCompanyInfo.builder().id(id).name(orgBiz.getSubcompanyShow(String.valueOf(id), "0", "-")).build();
})
.collect(Collectors.toList());
2022-03-23 18:41:38 +08:00
// 查询岗位信息
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
2022-06-09 17:45:28 +08:00
List<SalarySobRangeListDTO> salarySobRangeListDTOS = SalarySobRangeBO.convert2ListDTO(salarySobRangePOS, empInfos, deptInfos,subCompanyInfos, positionInfos);
2022-03-23 18:41:38 +08:00
// 根据对象名称过滤
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());
2022-05-25 13:10:03 +08:00
pageInfo.setList(SalaryPageUtil.subList(queryParam.getCurrent(), queryParam.getPageSize(), salarySobRangeListDTOS));
2022-08-16 17:26:16 +08:00
pageInfo.setPageNum(queryParam.getCurrent());
pageInfo.setPageSize(queryParam.getPageSize());
2022-03-23 18:41:38 +08:00
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())) {
2022-03-23 20:54:08 +08:00
salarySobRangeBiz.batchInsert(result.getNeedInsertSalarySobRanges());
2022-03-22 21:01:38 +08:00
}
if (CollectionUtils.isNotEmpty(result.getNeedUpdateSalarySobRanges())) {
2022-03-23 20:54:08 +08:00
result.getNeedUpdateSalarySobRanges().forEach(e -> salarySobRangeBiz.updateById(e));
2022-03-22 21:01:38 +08:00
}
// 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);
// 删除薪资账套的人员范围
2022-03-23 20:54:08 +08:00
salarySobRangeBiz.deleteByIds(ids);
2022-03-22 21:01:38 +08:00
// 查询薪资账套
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) {
2022-03-23 20:54:08 +08:00
salarySobRangeBiz.deleteBySalarySobIds(salarySobIds);
2022-03-22 21:01:38 +08:00
}
@Override
public void updateEmployeeStatuses(SalarySobRangePO item) {
salarySobRangeBiz.updateEmployeeStatuses(item);
}
2022-03-22 21:01:38 +08:00
}