weaver-hrm-salary/src/com/engine/salary/service/impl/SalaryComparisonResultServi...

278 lines
15 KiB
Java
Raw Normal View History

2022-04-13 14:18:00 +08:00
package com.engine.salary.service.impl;
import com.engine.common.util.ServiceUtil;
import com.engine.core.impl.Service;
2022-05-24 09:23:17 +08:00
import com.engine.salary.encrypt.AESEncryptUtil;
2022-05-31 16:02:41 +08:00
import com.engine.salary.encrypt.salaryacct.ExcelAcctResultPOEncrypt;
2022-04-13 14:18:00 +08:00
import com.engine.salary.entity.datacollection.DataCollectionEmployee;
import com.engine.salary.entity.salaryacct.bo.SalaryAcctResultBO;
import com.engine.salary.entity.salaryacct.dto.SalaryComparisonResultListDTO;
import com.engine.salary.entity.salaryacct.param.SalaryAcctEmployeeQueryParam;
import com.engine.salary.entity.salaryacct.param.SalaryComparisonResultQueryParam;
import com.engine.salary.entity.salaryacct.po.ExcelAcctResultPO;
import com.engine.salary.entity.salaryacct.po.SalaryAcctEmployeePO;
import com.engine.salary.entity.salaryacct.po.SalaryAcctRecordPO;
import com.engine.salary.entity.salaryacct.po.SalaryAcctResultPO;
2022-04-14 20:46:17 +08:00
import com.engine.salary.entity.salaryformula.ExpressFormula;
2022-04-13 14:18:00 +08:00
import com.engine.salary.entity.salaryitem.po.SalaryItemPO;
import com.engine.salary.entity.salarysob.bo.SalarySobItemAggregateBO;
import com.engine.salary.entity.salarysob.dto.SalarySobItemAggregateDTO;
import com.engine.salary.entity.salarysob.po.SalarySobEmpFieldPO;
import com.engine.salary.entity.salarysob.po.SalarySobItemGroupPO;
import com.engine.salary.entity.salarysob.po.SalarySobItemPO;
import com.engine.salary.entity.salarysob.po.SalarySobPO;
2022-05-31 16:41:11 +08:00
import com.engine.salary.entity.taxagent.po.TaxAgentPO;
2022-04-13 14:18:00 +08:00
import com.engine.salary.exception.SalaryRunTimeException;
import com.engine.salary.mapper.salaryacct.ExcelAcctResultMapper;
import com.engine.salary.service.*;
import com.engine.salary.util.SalaryEntityUtil;
import com.engine.salary.util.SalaryI18nUtil;
import com.engine.salary.util.db.MapperProxyFactory;
2022-05-26 15:45:37 +08:00
import com.engine.salary.util.page.Column;
2022-04-13 14:18:00 +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-05-30 18:59:48 +08:00
import com.google.common.collect.Lists;
2022-04-13 14:18:00 +08:00
import com.google.common.collect.Sets;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
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 SalaryComparisonResultServiceImpl extends Service implements SalaryComparisonResultService {
private ExcelAcctResultMapper getExcelAcctResultMapper() {
return MapperProxyFactory.getProxy(ExcelAcctResultMapper.class);
}
private SalaryAcctResultService getSalaryAcctResultService(User user) {
2022-07-18 09:38:12 +08:00
return ServiceUtil.getService(SalaryAcctResultServiceImpl.class, user);
2022-04-13 14:18:00 +08:00
}
private SalaryAcctEmployeeService getSalaryAcctEmployeeService(User user) {
2022-07-18 09:38:12 +08:00
return ServiceUtil.getService(SalaryAcctEmployeeServiceImpl.class, user);
2022-04-13 14:18:00 +08:00
}
private SalarySobItemService getSalarySobItemService(User user) {
2022-07-18 09:38:12 +08:00
return ServiceUtil.getService(SalarySobItemServiceImpl.class, user);
2022-04-13 14:18:00 +08:00
}
private SalaryAcctRecordService getSalaryAcctRecordService(User user) {
2022-07-18 09:38:12 +08:00
return ServiceUtil.getService(SalaryAcctRecordServiceImpl.class, user);
2022-04-13 14:18:00 +08:00
}
private SalarySobEmpFieldService getSalarySobEmpFieldService(User user) {
2022-07-18 09:38:12 +08:00
return ServiceUtil.getService(SalarySobEmpFieldServiceImpl.class, user);
2022-04-13 14:18:00 +08:00
}
private SalaryEmployeeService getSalaryEmployeeService(User user) {
2022-07-18 09:38:12 +08:00
return ServiceUtil.getService(SalaryEmployeeServiceImpl.class, user);
2022-04-13 14:18:00 +08:00
}
2022-05-31 16:41:11 +08:00
2022-05-31 21:05:59 +08:00
private TaxAgentService getTaxAgentService(User user) {
return ServiceUtil.getService(TaxAgentServiceImpl.class, user);
2022-05-31 16:41:11 +08:00
}
2022-04-13 14:18:00 +08:00
private SalaryFormulaService getSalaryFormulaService(User user) {
2022-07-18 09:38:12 +08:00
return ServiceUtil.getService(SalaryFormulaServiceImpl.class, user);
2022-04-13 14:18:00 +08:00
}
private SalaryItemService getSalaryItemService(User user) {
2022-07-18 09:38:12 +08:00
return ServiceUtil.getService(SalaryItemServiceImpl.class, user);
2022-04-13 14:18:00 +08:00
}
private SalarySobService getSalarySobService(User user) {
2022-07-18 09:38:12 +08:00
return ServiceUtil.getService(SalarySobServiceImpl.class, user);
2022-04-13 14:18:00 +08:00
}
private SalarySobItemGroupService getSalarySobItemGroupService(User user) {
2022-07-18 09:38:12 +08:00
return ServiceUtil.getService(SalarySobItemGroupServiceImpl.class, user);
2022-04-13 14:18:00 +08:00
}
@Override
public List<ExcelAcctResultPO> listBySalaryAcctRecordId(Long salaryAcctRecordId) {
2022-05-24 09:23:17 +08:00
List<ExcelAcctResultPO> excelAcctResultPOS = getExcelAcctResultMapper().listSome(ExcelAcctResultPO.builder().salaryAcctRecordId(salaryAcctRecordId).build());
2022-05-31 16:02:41 +08:00
return ExcelAcctResultPOEncrypt.decryptList(excelAcctResultPOS);
2022-04-13 14:18:00 +08:00
}
@Override
public List<ExcelAcctResultPO> listBySalaryAcctEmployeeIds(Collection<Long> salaryAcctEmployeeIds) {
if (CollectionUtils.isEmpty(salaryAcctEmployeeIds)) {
return Collections.emptyList();
}
2022-05-24 09:23:17 +08:00
List<ExcelAcctResultPO> excelAcctResultPOS = getExcelAcctResultMapper().listSome(ExcelAcctResultPO.builder().salaryAcctEmpIds(salaryAcctEmployeeIds).build());
2022-05-31 16:02:41 +08:00
return ExcelAcctResultPOEncrypt.decryptList(excelAcctResultPOS);
2022-04-13 14:18:00 +08:00
}
@Override
public SalaryComparisonResultListDTO listPageByParam(SalaryComparisonResultQueryParam queryParam) {
return listByParam(true, queryParam);
}
@Override
public SalaryComparisonResultListDTO listByParam(SalaryComparisonResultQueryParam queryParam) {
return listByParam(false, queryParam);
}
/**
* 根据薪资核算人员查询薪资核算线下对比结果
*
* @param queryParam 列表查询条件
* @return
*/
private SalaryComparisonResultListDTO listByParam(boolean needPage, SalaryComparisonResultQueryParam queryParam) {
// 查询薪资核算记录
SalaryAcctRecordPO salaryAcctRecordPO = getSalaryAcctRecordService(user).getById(queryParam.getSalaryAcctRecordId());
if (Objects.isNull(salaryAcctRecordPO)) {
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98747, "薪资核算记录不存在或已被删除"));
}
// 查询薪资核算所用薪资账套
SalarySobPO salarySobPO = getSalarySobService(user).getById(salaryAcctRecordPO.getSalarySobId());
// 查询薪资核算所用的薪资账套的员工信息字段
List<SalarySobEmpFieldPO> salarySobEmpFieldPOS = getSalarySobEmpFieldService(user).listBySalarySobId(salaryAcctRecordPO.getSalarySobId());
// 查询薪资账套的薪资项目分类
List<SalarySobItemGroupPO> salarySobItemGroupPOS = getSalarySobItemGroupService(user).listBySalarySobId(salaryAcctRecordPO.getSalarySobId());
// 查询薪资核算所用薪资账套的薪资项目副本
List<SalarySobItemPO> salarySobItemPOS = getSalarySobItemService(user).listBySalarySobId(salaryAcctRecordPO.getSalarySobId());
// 查询公式详情
Set<Long> formulaIds = SalaryEntityUtil.properties(salarySobItemPOS, SalarySobItemPO::getFormulaId);
2022-04-26 16:42:22 +08:00
List<ExpressFormula> expressFormulas = getSalaryFormulaService(user).listExpressFormula(formulaIds);
2022-04-13 14:18:00 +08:00
// 转换成
Map<Long, String> expressFormulaMap = SalaryEntityUtil.convert2Map(expressFormulas, ExpressFormula::getId, ExpressFormula::getFormula);
Map<Long, String> customParameters = SalaryEntityUtil.convert2Map(salarySobItemPOS, SalarySobItemPO::getSalaryItemId, salarySobItemPO -> {
if (salarySobItemPO.getFormulaId() <= 0) {
return SalaryI18nUtil.getI18nLabel(92004, "输入/导入");
}
return expressFormulaMap.getOrDefault(salarySobItemPO.getFormulaId(), StringUtils.EMPTY);
});
// 查询薪资项目
Set<Long> salaryItemIds = SalaryEntityUtil.properties(salarySobItemPOS, SalarySobItemPO::getSalaryItemId);
List<SalaryItemPO> salaryItemPOS = getSalaryItemService(user).listByIds(salaryItemIds);
// 转换成聚合dto
SalarySobItemAggregateBO salarySobItemAggregateBO = new SalarySobItemAggregateBO(salarySobPO, salarySobEmpFieldPOS,
salarySobItemGroupPOS, salarySobItemPOS, expressFormulas, salaryItemPOS);
SalarySobItemAggregateDTO salarySobItemAggregateDTO = salarySobItemAggregateBO.convert2AggregateDTO();
// 薪资核算人员
List<SalaryAcctEmployeePO> salaryAcctEmployeePOS = getSalaryAcctEmployeeService(user).listByResultQueryParam(queryParam);
if (CollectionUtils.isEmpty(salaryAcctEmployeePOS)) {
// 构建薪资核算结果列表表头
2022-05-26 15:45:37 +08:00
List<Column> weaTableColumns = SalaryAcctResultBO.buildTableColumns4ComparisonResult(salarySobItemAggregateDTO, Collections.emptySet());
2022-04-13 14:18:00 +08:00
// 构建列表数据
// 返回结果
return new SalaryComparisonResultListDTO().setWeaTableColumns(weaTableColumns).setData(new PageInfo<>());
}
// 薪资核算结果
List<SalaryAcctResultPO> salaryAcctResultPOS;
// 线下导入结果
List<ExcelAcctResultPO> excelAcctResultPOS;
// 如果薪资核算人员太多利用薪资核算人员id查询薪资核算结果的效率就不太好改为直接用薪资核算记录id查询
if (salaryAcctEmployeePOS.size() > 1000) {
// 查询薪资核算结果
salaryAcctResultPOS = getSalaryAcctResultService(user).listBySalaryAcctRecordIds(Collections.singleton(queryParam.getSalaryAcctRecordId()));
// 查询线下导入结果
excelAcctResultPOS = listBySalaryAcctRecordId(queryParam.getSalaryAcctRecordId());
} else {
// 薪资核算人员id
Set<Long> salaryAcctEmployeeIds = SalaryEntityUtil.properties(salaryAcctEmployeePOS, SalaryAcctEmployeePO::getId);
// 查询薪资核算结果
salaryAcctResultPOS = getSalaryAcctResultService(user).listBySalaryAcctEmployeeIds(salaryAcctEmployeeIds);
// 查询线下导入结果
excelAcctResultPOS = listBySalaryAcctEmployeeIds(salaryAcctEmployeeIds);
}
// 查询个税扣缴义务人
Set<Long> taxAgentIds = SalaryEntityUtil.properties(salaryAcctEmployeePOS, SalaryAcctEmployeePO::getTaxAgentId);
2022-05-31 16:41:11 +08:00
List<TaxAgentPO> taxAgentPOS = getTaxAgentService(user).listByIds(taxAgentIds);
2022-04-13 14:18:00 +08:00
// 查询人员信息
List<Long> employeeIds = SalaryEntityUtil.properties(salaryAcctEmployeePOS, SalaryAcctEmployeePO::getEmployeeId, Collectors.toList());
List<DataCollectionEmployee> simpleEmployees = getSalaryEmployeeService(user).listByIds(employeeIds);
// 判断是否存在合并计税
Set<Long> salaryAcctEmployeeIds4ConsolidatedTax;
if (StringUtils.isEmpty(queryParam.getConsolidatedTaxation())) {
salaryAcctEmployeeIds4ConsolidatedTax = SalaryEntityUtil.properties(salaryAcctEmployeePOS, SalaryAcctEmployeePO::getId);
} else {
SalaryAcctEmployeeQueryParam accEmployeeQueryParam = SalaryAcctEmployeeQueryParam.builder()
.salaryAcctRecordId(queryParam.getSalaryAcctRecordId())
.ids(SalaryEntityUtil.properties(salaryAcctEmployeePOS, SalaryAcctEmployeePO::getId))
.build();
List<SalaryAcctEmployeePO> salaryAcctEmployeePOS4ConsolidatedTax = getSalaryAcctEmployeeService(user).listByParam4ConsolidatedTax(accEmployeeQueryParam);
salaryAcctEmployeeIds4ConsolidatedTax = SalaryEntityUtil.properties(salaryAcctEmployeePOS4ConsolidatedTax, SalaryAcctEmployeePO::getId);
}
// 系统值和线下值不一致的薪资项目id
Set<Long> includeSalaryItemIds = Sets.newHashSetWithExpectedSize(salaryItemPOS.size());
// 转换成薪资核算线下对比结果
List<Map<String, Object>> resultMapList = SalaryAcctResultBO.buildComparisonTableData(salaryItemPOS, salarySobEmpFieldPOS, simpleEmployees,
salaryAcctEmployeePOS, salaryAcctResultPOS, excelAcctResultPOS, taxAgentPOS, customParameters, salaryAcctEmployeeIds4ConsolidatedTax, includeSalaryItemIds);
// 系统值和线下值一致的人员
if (queryParam.isOnlyDiffEmployee()) {
// 过滤系统值和线下值一致的薪资核算人员
resultMapList = resultMapList.stream()
.filter(map -> BooleanUtils.toBoolean(String.valueOf(map.get("different"))))
.collect(Collectors.toList());
}
// 分页
PageInfo<Map<String, Object>> dtoPage = new PageInfo<>();
dtoPage.setTotal(resultMapList.size());
if (needPage) {
2022-05-25 13:10:03 +08:00
dtoPage.setList(SalaryPageUtil.subList(queryParam.getCurrent(), queryParam.getPageSize(), resultMapList));
2022-04-13 14:18:00 +08:00
} else {
dtoPage.setList(resultMapList);
}
Set<Long> excludeSalaryItemIds = Sets.newHashSet();
if (queryParam.isOnlyDiffSalaryItem()) {
// 过滤系统值和线下值一致的薪资项目
excludeSalaryItemIds = salaryItemPOS.stream()
.filter(salaryItemPO -> !includeSalaryItemIds.contains(salaryItemPO.getId()))
.map(SalaryItemPO::getId)
.collect(Collectors.toSet());
}
// 构建薪资核算结果列表表头
2022-05-26 15:45:37 +08:00
List<Column> weaTableColumns = SalaryAcctResultBO.buildTableColumns4ComparisonResult(salarySobItemAggregateDTO, excludeSalaryItemIds);
2022-04-13 14:18:00 +08:00
// 返回结果
return new SalaryComparisonResultListDTO().setWeaTableColumns(weaTableColumns).setData(dtoPage);
}
@Override
public void batchSave(Collection<ExcelAcctResultPO> excelAcctResultPOS) {
2022-05-31 16:02:41 +08:00
ExcelAcctResultPOEncrypt.encryptList(excelAcctResultPOS);
2022-07-18 09:38:12 +08:00
if (CollectionUtils.isEmpty(excelAcctResultPOS)) {
2022-05-26 13:41:58 +08:00
return;
}
List<List<ExcelAcctResultPO>> partition = Lists.partition((List) excelAcctResultPOS, 100);
partition.forEach(getExcelAcctResultMapper()::batchInsert);
2022-04-13 14:18:00 +08:00
}
@Override
public void deleteBySalaryAcctEmployeeIds(Collection<Long> salaryAcctEmployeeIds) {
getExcelAcctResultMapper().deleteBySalaryAcctEmployeeIds(salaryAcctEmployeeIds);
}
@Override
public void deleteBySalaryAcctRecordIds(Collection<Long> salaryAcctRecordIds) {
getExcelAcctResultMapper().deleteBySalaryAcctRecordIds(salaryAcctRecordIds);
}
2022-05-24 09:23:17 +08:00
private Collection<ExcelAcctResultPO> encryptCollection(Collection<ExcelAcctResultPO> collection) {
collection.forEach(item -> item.setResultValue(AESEncryptUtil.encrypt(item.getResultValue())));
return collection;
}
private Collection<ExcelAcctResultPO> decryptCollection(Collection<ExcelAcctResultPO> collection) {
collection.forEach(item -> item.setResultValue(AESEncryptUtil.decrypt(item.getResultValue())));
return collection;
}
2022-04-13 14:18:00 +08:00
}