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

285 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;
import com.engine.salary.component.WeaTableColumnGroup;
import com.engine.salary.encrypt.EncryptUtil;
2022-04-13 14:18:00 +08:00
import com.engine.salary.entity.datacollection.DataCollectionEmployee;
2024-05-06 16:03:29 +08:00
import com.engine.salary.entity.salaryacct.bo.SalaryAcctConfig;
2022-04-13 14:18:00 +08:00
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;
2023-11-16 16:56:50 +08:00
import com.engine.salary.entity.salarysob.po.*;
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;
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 EncryptUtil encryptUtil = new EncryptUtil();
2022-04-13 14:18:00 +08:00
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
}
2023-11-16 16:56:50 +08:00
private SalarySobItemHideService getSalarySobItemHideService(User user) {
return ServiceUtil.getService(SalarySobItemHideServiceImpl.class, user);
}
2024-05-06 16:03:29 +08:00
private SalaryAcctSobConfigService getSalaryAcctSobConfigService(User user) {
return ServiceUtil.getService(SalaryAcctSobConfigServiceImpl.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());
return encryptUtil.decryptList(excelAcctResultPOS, ExcelAcctResultPO.class);
2022-04-13 14:18:00 +08:00
}
@Override
public List<ExcelAcctResultPO> listBySalaryAcctEmployeeIds(Collection<Long> salaryAcctEmployeeIds) {
if (CollectionUtils.isEmpty(salaryAcctEmployeeIds)) {
return Collections.emptyList();
}
2023-05-04 11:56:34 +08:00
List<ExcelAcctResultPO> excelAcctResultPOS = new ArrayList<>();
List<List<Long>> partition = Lists.partition((List<Long>) salaryAcctEmployeeIds, 2000);
partition.forEach(empIds -> {
excelAcctResultPOS.addAll(getExcelAcctResultMapper().listSome(ExcelAcctResultPO.builder().salaryAcctEmpIds(empIds).build()));
});
return encryptUtil.decryptList(excelAcctResultPOS, ExcelAcctResultPO.class);
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, "薪资核算记录不存在或已被删除"));
}
2024-05-06 16:03:29 +08:00
SalaryAcctConfig salaryAcctConfig = getSalaryAcctSobConfigService(user).getSalaryAcctConfig(queryParam.getSalaryAcctRecordId());
2022-04-13 14:18:00 +08:00
// 查询薪资核算所用薪资账套
SalarySobPO salarySobPO = getSalarySobService(user).getById(salaryAcctRecordPO.getSalarySobId());
// 查询薪资核算所用的薪资账套的员工信息字段
2024-05-06 16:03:29 +08:00
List<SalarySobEmpFieldPO> salarySobEmpFieldPOS = salaryAcctConfig.getSalarySobEmpFields();
2022-04-13 14:18:00 +08:00
// 查询薪资账套的薪资项目分类
2024-05-06 16:03:29 +08:00
List<SalarySobItemGroupPO> salarySobItemGroupPOS = salaryAcctConfig.getSalarySobItemGroups();
2022-04-13 14:18:00 +08:00
// 查询薪资核算所用薪资账套的薪资项目副本
2024-05-06 16:03:29 +08:00
List<SalarySobItemPO> salarySobItemPOS = salaryAcctConfig.getSalarySobItems();
2023-11-16 16:56:50 +08:00
// 过滤在账套中隐藏的薪资项目
2024-05-06 16:03:29 +08:00
salarySobItemPOS = salarySobItemPOS.stream().filter(po -> po.getItemHide()==null || po.getItemHide() == 0).collect(Collectors.toList());
2022-04-13 14:18:00 +08:00
// 查询公式详情
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,
2023-05-04 11:56:34 +08:00
salarySobItemGroupPOS, salarySobItemPOS, expressFormulas, salaryItemPOS, Collections.emptyList(), Collections.emptyList());
2022-04-13 14:18:00 +08:00
SalarySobItemAggregateDTO salarySobItemAggregateDTO = salarySobItemAggregateBO.convert2AggregateDTO();
// 薪资核算人员
List<SalaryAcctEmployeePO> salaryAcctEmployeePOS = getSalaryAcctEmployeeService(user).listByResultQueryParam(queryParam);
if (CollectionUtils.isEmpty(salaryAcctEmployeePOS)) {
// 构建薪资核算结果列表表头
List<WeaTableColumnGroup> weaTableColumns = SalaryAcctResultBO.buildTableColumns4ComparisonResultByGroup(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
2023-05-04 11:56:34 +08:00
List<Long> salaryAcctEmployeeIds = SalaryEntityUtil.properties(salaryAcctEmployeePOS, SalaryAcctEmployeePO::getId, Collectors.toList());
2022-04-13 14:18:00 +08:00
// 查询薪资核算结果
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());
2023-04-12 15:27:35 +08:00
List<DataCollectionEmployee> simpleEmployees = getSalaryEmployeeService(user).getEmployeeByIdsAll(employeeIds);
2022-04-13 14:18:00 +08:00
// 判断是否存在合并计税
Set<Long> salaryAcctEmployeeIds4ConsolidatedTax;
if (StringUtils.isEmpty(queryParam.getConsolidatedTaxation())) {
salaryAcctEmployeeIds4ConsolidatedTax = SalaryEntityUtil.properties(salaryAcctEmployeePOS, SalaryAcctEmployeePO::getId);
} else {
SalaryAcctEmployeeQueryParam accEmployeeQueryParam = SalaryAcctEmployeeQueryParam.builder()
.salaryAcctRecordId(queryParam.getSalaryAcctRecordId())
2024-01-30 10:26:44 +08:00
.ids(SalaryEntityUtil.properties(salaryAcctEmployeePOS, SalaryAcctEmployeePO::getId, Collectors.toList()))
2022-04-13 14:18:00 +08:00
.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-09-22 15:31:28 +08:00
dtoPage.setPageSize(queryParam.getPageSize());
dtoPage.setPageNum(queryParam.getCurrent());
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());
}
// 构建薪资核算结果列表表头
List<WeaTableColumnGroup> weaTableColumns = SalaryAcctResultBO.buildTableColumns4ComparisonResultByGroup(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-07-18 09:38:12 +08:00
if (CollectionUtils.isEmpty(excelAcctResultPOS)) {
2022-05-26 13:41:58 +08:00
return;
}
excelAcctResultPOS = encryptUtil.encryptList(new ArrayList<>(excelAcctResultPOS), ExcelAcctResultPO.class);
2022-05-26 13:41:58 +08:00
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);
}
}