2022-04-11 20:17:47 +08:00
|
|
|
package com.engine.salary.service.impl;
|
|
|
|
|
|
|
|
|
|
import com.engine.common.util.ServiceUtil;
|
|
|
|
|
import com.engine.core.impl.Service;
|
|
|
|
|
import com.engine.salary.constant.SalaryDefaultTenantConstant;
|
|
|
|
|
import com.engine.salary.constant.SalaryFormulaFieldConstant;
|
|
|
|
|
import com.engine.salary.entity.datacollection.AddUpDeduction;
|
|
|
|
|
import com.engine.salary.entity.datacollection.AddUpSituation;
|
|
|
|
|
import com.engine.salary.entity.datacollection.DataCollectionEmployee;
|
|
|
|
|
import com.engine.salary.entity.datacollection.dto.AttendQuoteDataDTO;
|
|
|
|
|
import com.engine.salary.entity.datacollection.po.OtherDeductionPO;
|
|
|
|
|
import com.engine.salary.entity.salaryacct.bo.*;
|
|
|
|
|
import com.engine.salary.entity.salaryacct.po.SalaryAcctEmployeePO;
|
|
|
|
|
import com.engine.salary.entity.salaryacct.po.SalaryAcctRecordPO;
|
|
|
|
|
import com.engine.salary.entity.salaryacct.po.SalaryAcctResultPO;
|
|
|
|
|
import com.engine.salary.entity.salaryacct.po.SalaryAcctResultTempPO;
|
|
|
|
|
import com.engine.salary.entity.salaryarchive.dto.SalaryArchiveDataDTO;
|
2022-04-27 09:43:24 +08:00
|
|
|
import com.engine.salary.entity.salaryformula.ExpressFormula;
|
|
|
|
|
import com.engine.salary.entity.salaryformula.po.FormulaVar;
|
2022-04-11 20:17:47 +08:00
|
|
|
import com.engine.salary.entity.salaryitem.po.SalaryItemPO;
|
|
|
|
|
import com.engine.salary.entity.salarysob.dto.SalarySobCycleDTO;
|
|
|
|
|
import com.engine.salary.entity.salarysob.po.SalarySobItemPO;
|
|
|
|
|
import com.engine.salary.enums.SalaryFormulaReferenceEnum;
|
2022-04-26 16:39:41 +08:00
|
|
|
import com.engine.salary.enums.SalaryValueTypeEnum;
|
2022-04-11 20:17:47 +08:00
|
|
|
import com.engine.salary.service.*;
|
|
|
|
|
import com.engine.salary.util.SalaryEntityUtil;
|
2022-04-27 13:33:44 +08:00
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
|
|
import com.fasterxml.jackson.databind.JsonNode;
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
2022-04-11 20:17:47 +08:00
|
|
|
import com.google.common.collect.Lists;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.apache.commons.lang3.math.NumberUtils;
|
2022-04-27 09:43:24 +08:00
|
|
|
import weaver.conn.RecordSet;
|
2022-04-11 20:17:47 +08:00
|
|
|
import weaver.hrm.User;
|
|
|
|
|
|
|
|
|
|
import java.time.Month;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 薪资核算-核算
|
|
|
|
|
* <p>Copyright: Copyright (c) 2022</p>
|
|
|
|
|
* <p>Company: 泛微软件</p>
|
|
|
|
|
*
|
|
|
|
|
* @author qiantao
|
|
|
|
|
* @version 1.0
|
|
|
|
|
**/
|
|
|
|
|
@Slf4j
|
|
|
|
|
public class SalaryAcctCalculateServiceImpl extends Service implements SalaryAcctCalculateService {
|
|
|
|
|
|
2022-04-15 13:54:47 +08:00
|
|
|
|
2022-04-11 20:17:47 +08:00
|
|
|
private SalaryAcctResultService getSalaryAcctResultService(User user) {
|
|
|
|
|
return (SalaryAcctResultService) ServiceUtil.getService(SalaryAcctResultServiceImpl.class, user);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private SalaryEmployeeService getSalaryEmployeeService(User user) {
|
|
|
|
|
return (SalaryEmployeeService) ServiceUtil.getService(SalaryEmployeeServiceImpl.class, user);
|
|
|
|
|
}
|
2022-04-15 13:54:47 +08:00
|
|
|
|
2022-04-11 20:17:47 +08:00
|
|
|
|
|
|
|
|
private SalaryArchiveService getSalaryArchiveService(User user) {
|
|
|
|
|
return (SalaryArchiveService) ServiceUtil.getService(SalaryArchiveServiceImpl.class, user);
|
|
|
|
|
}
|
2022-04-15 13:54:47 +08:00
|
|
|
|
2022-04-11 20:17:47 +08:00
|
|
|
|
|
|
|
|
private AddUpSituationService getAddUpSituationService(User user) {
|
|
|
|
|
return (AddUpSituationService) ServiceUtil.getService(AddUpSituationServiceImpl.class, user);
|
|
|
|
|
}
|
2022-04-15 13:54:47 +08:00
|
|
|
|
2022-04-11 20:17:47 +08:00
|
|
|
|
|
|
|
|
private AddUpDeductionService getAddUpDeductionService(User user) {
|
|
|
|
|
return (AddUpDeductionService) ServiceUtil.getService(AddUpDeductionServiceImpl.class, user);
|
|
|
|
|
}
|
2022-04-15 13:54:47 +08:00
|
|
|
|
2022-04-11 20:17:47 +08:00
|
|
|
|
|
|
|
|
private OtherDeductionService getOtherDeductionService(User user) {
|
|
|
|
|
return (OtherDeductionService) ServiceUtil.getService(OtherDeductionServiceImpl.class, user);
|
|
|
|
|
}
|
2022-04-15 13:54:47 +08:00
|
|
|
|
2022-04-11 20:17:47 +08:00
|
|
|
// private SIAccountService siAccountService;
|
2022-04-15 13:54:47 +08:00
|
|
|
|
2022-04-11 20:17:47 +08:00
|
|
|
|
|
|
|
|
private AttendQuoteDataService getAttendQuoteDataService(User user) {
|
|
|
|
|
return (AttendQuoteDataService) ServiceUtil.getService(AttendQuoteDataServiceImpl.class, user);
|
|
|
|
|
}
|
2022-04-15 13:54:47 +08:00
|
|
|
|
|
|
|
|
private FormulaRunService getFormulaRunService(User user) {
|
|
|
|
|
return (FormulaRunService) ServiceUtil.getService(FormulaRunServiceImpl.class, user);
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-11 20:17:47 +08:00
|
|
|
|
|
|
|
|
private SalaryAcctResultTempService getSalaryAcctResultTempService(User user) {
|
|
|
|
|
return (SalaryAcctResultTempService) ServiceUtil.getService(SalaryAcctResultTempServiceImpl.class, user);
|
|
|
|
|
}
|
2022-04-15 13:54:47 +08:00
|
|
|
|
2022-04-11 20:17:47 +08:00
|
|
|
private SalaryAcctProgressService salaryAcctProgressService;
|
2022-04-15 13:54:47 +08:00
|
|
|
|
2022-04-12 19:25:19 +08:00
|
|
|
private SalaryAcctEmployeeService getSalaryAcctEmployeeService(User user) {
|
|
|
|
|
return (SalaryAcctEmployeeService) ServiceUtil.getService(SalaryAcctEmployeeServiceImpl.class, user);
|
|
|
|
|
}
|
2022-04-11 20:17:47 +08:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void calculate(SalaryAcctCalculateBO salaryAcctCalculateBO, DataCollectionEmployee simpleEmployee) {
|
|
|
|
|
Date now = new Date();
|
|
|
|
|
try {
|
|
|
|
|
// 数据库字段加密用
|
|
|
|
|
// 1、查询人员信息
|
|
|
|
|
List<Long> employeeIds = SalaryEntityUtil.properties(salaryAcctCalculateBO.getSalaryAcctEmployeePOS(), SalaryAcctEmployeePO::getEmployeeId, Collectors.toList());
|
|
|
|
|
List<DataCollectionEmployee> simpleEmployees = getSalaryEmployeeService(user).listByIds(employeeIds);
|
|
|
|
|
SalarySobCycleDTO salarySobCycleDTO = salaryAcctCalculateBO.getSalarySobCycleDTO();
|
|
|
|
|
// 2、查询薪资档案的数据
|
|
|
|
|
List<SalaryArchiveDataDTO> salaryArchiveData = getSalaryArchiveService(user).getSalaryArchiveData(salarySobCycleDTO.getSalaryCycle(), employeeIds);
|
|
|
|
|
// 3、查询往期累计情况(查询的是上个税款所属期的的累计情况)
|
|
|
|
|
List<AddUpSituation> addUpSituationPOS;
|
|
|
|
|
if (salarySobCycleDTO.getTaxCycle().getMonth() == Month.JANUARY) {
|
|
|
|
|
// 3.1、如果当前税款所属期是本年度第一个税款所属期,就不需要查询往期累计情况
|
|
|
|
|
addUpSituationPOS = Collections.emptyList();
|
|
|
|
|
} else {
|
|
|
|
|
addUpSituationPOS = getAddUpSituationService(user).getAddUpSituationList(salarySobCycleDTO.getTaxCycle().plusMonths(-1), employeeIds);
|
|
|
|
|
}
|
|
|
|
|
// 4、查询累计专项附加扣除
|
|
|
|
|
List<AddUpDeduction> addUpDeductionPOS = getAddUpDeductionService(user).getAddUpDeductionList(salarySobCycleDTO.getTaxCycle(), employeeIds);
|
|
|
|
|
// 5、查询其他免税扣除
|
|
|
|
|
List<OtherDeductionPO> otherDeductionPOS = getOtherDeductionService(user).getOtherDeductionList(salarySobCycleDTO.getTaxCycle(), employeeIds);
|
|
|
|
|
//todo 6、查询社保福利
|
2022-04-12 19:25:19 +08:00
|
|
|
List<Map<String, Object>> welfareData = Lists.newArrayList();//siAccountService.welfareData(salarySobCycleDTO.getSocialSecurityCycle().toString(), employeeIds);
|
2022-04-11 20:17:47 +08:00
|
|
|
// 7、查询考勤数据
|
|
|
|
|
List<AttendQuoteDataDTO> attendQuoteDataDTOS = getAttendQuoteDataService(user).getAttendQuoteData(salarySobCycleDTO.getSalaryMonth(), salarySobCycleDTO.getSalarySobId(), employeeIds);
|
|
|
|
|
// 8、查询薪资核算人员的薪资核算结果
|
|
|
|
|
Set<Long> salaryAcctEmployeeIds = SalaryEntityUtil.properties(salaryAcctCalculateBO.getSalaryAcctEmployeePOS(), SalaryAcctEmployeePO::getId);
|
|
|
|
|
List<SalaryAcctResultPO> salaryAcctResultPOS = getSalaryAcctResultService(user).listBySalaryAcctEmployeeIds(salaryAcctEmployeeIds);
|
|
|
|
|
// 9、查询相同税款所属期内涉及合并计税的其他薪资核算结果
|
|
|
|
|
Set<Long> otherSalaryAcctRecordIds = SalaryEntityUtil.properties(salaryAcctCalculateBO.getOtherSalaryAcctRecordPOS(), SalaryAcctRecordPO::getId);
|
|
|
|
|
List<SalaryAcctResultPO> otherSalaryAcctResultPOS = getSalaryAcctResultService(user).listBySalaryAcctRecordIdsAndEmployeeIds(otherSalaryAcctRecordIds, employeeIds);
|
|
|
|
|
Map<String, List<SalaryAcctResultPO>> otherSalaryAcctResultPOMap = SalaryEntityUtil.group2Map(otherSalaryAcctResultPOS, e -> e.getEmployeeId() + "_" + e.getTaxAgentId());
|
|
|
|
|
// 9.1、查询相同税款所属期内设计合并计税的其他薪资核算人员
|
2022-04-12 19:25:19 +08:00
|
|
|
List<SalaryAcctEmployeePO> otherSalaryAcctEmployeePOS = getSalaryAcctEmployeeService(user).listBySalaryAcctRecordIdsAndEmployeeIds(otherSalaryAcctRecordIds, employeeIds);
|
2022-04-11 20:17:47 +08:00
|
|
|
Map<String, List<SalaryAcctEmployeePO>> otherSalaryAcctEmployeePOMap = SalaryEntityUtil.group2Map(otherSalaryAcctEmployeePOS, salaryAcctEmployeePO -> salaryAcctEmployeePO.getEmployeeId() + "_" + salaryAcctEmployeePO.getTaxAgentId());
|
|
|
|
|
|
|
|
|
|
// 10、转换成公式编辑器中的变量
|
|
|
|
|
CalculateFormulaVarBO calculateFormulaVarBO = new CalculateFormulaVarBO(simpleEmployees, salaryArchiveData, addUpSituationPOS, addUpDeductionPOS, otherDeductionPOS,
|
|
|
|
|
welfareData, attendQuoteDataDTOS, salaryAcctResultPOS);
|
|
|
|
|
Map<String, List<CalculateFormulaVarBO.FormulaVarValue>> formulaVarMap = calculateFormulaVarBO.convert2FormulaVar(salaryAcctCalculateBO);
|
|
|
|
|
|
|
|
|
|
// 本次薪资核算所用的薪资账套下的薪资项目
|
|
|
|
|
Map<Long, SalarySobItemPO> salaryItemIdKeySalarySobItemPOMap = SalaryEntityUtil.convert2Map(salaryAcctCalculateBO.getSalarySobItemPOS(), SalarySobItemPO::getSalaryItemId);
|
|
|
|
|
// 本次薪资核算所用的公式
|
|
|
|
|
Map<Long, ExpressFormula> expressFormulaMap = SalaryEntityUtil.convert2Map(salaryAcctCalculateBO.getExpressFormulas(), ExpressFormula::getId);
|
|
|
|
|
// 系统内的薪资项目
|
|
|
|
|
Map<Long, SalaryItemPO> salaryItemMap = SalaryEntityUtil.convert2Map(salaryAcctCalculateBO.getSalaryItemPOS(), SalaryItemPO::getId);
|
|
|
|
|
|
|
|
|
|
List<SalaryAcctResultTempPO> salaryAcctResultTempPOS = Lists.newArrayList();
|
|
|
|
|
// 开始核算
|
|
|
|
|
for (SalaryAcctEmployeePO salaryAcctEmployeePO : salaryAcctCalculateBO.getSalaryAcctEmployeePOS()) {
|
|
|
|
|
// 获取当前薪资核算人员的公式中的变量的值
|
|
|
|
|
List<CalculateFormulaVarBO.FormulaVarValue> formulaVarValues = formulaVarMap.get(salaryAcctEmployeePO.getEmployeeId() + "_" + salaryAcctEmployeePO.getTaxAgentId());
|
|
|
|
|
Map<String, String> formulaVarValueMap = SalaryEntityUtil.convert2Map(formulaVarValues, CalculateFormulaVarBO.FormulaVarValue::getFieldId, CalculateFormulaVarBO.FormulaVarValue::getFieldValue);
|
|
|
|
|
// 按照计算好的优先级计算薪资项目的值
|
|
|
|
|
for (List<Long> salaryItemIds : salaryAcctCalculateBO.getSalaryItemIdWithPriorityList()) {
|
|
|
|
|
// 同一运算优先级下的薪资项目逐个独立运算
|
|
|
|
|
for (Long salaryItemId : salaryItemIds) {
|
|
|
|
|
String resultValue;
|
|
|
|
|
SalaryItemPO salaryItemPO = salaryItemMap.get(salaryItemId);
|
2022-04-26 16:39:41 +08:00
|
|
|
|
|
|
|
|
SalaryValueTypeEnum salaryValueTypeEnum = SalaryValueTypeEnum.parseByValue(salaryItemPO.getValueType());
|
|
|
|
|
|
|
|
|
|
|
2022-04-11 20:17:47 +08:00
|
|
|
ExpressFormula expressFormula;
|
|
|
|
|
// 如果薪资账套下重新定义了薪资项目的公式,则使用薪资账套下的公式,否则使用薪资项目本身的公式
|
|
|
|
|
if (salaryItemIdKeySalarySobItemPOMap.containsKey(salaryItemId)) {
|
|
|
|
|
SalarySobItemPO salarySobItemPO = salaryItemIdKeySalarySobItemPOMap.get(salaryItemId);
|
|
|
|
|
expressFormula = expressFormulaMap.get(salarySobItemPO.getFormulaId());
|
|
|
|
|
} else {
|
|
|
|
|
expressFormula = expressFormulaMap.get(salaryItemPO.getFormulaId());
|
|
|
|
|
}
|
2022-04-26 16:39:41 +08:00
|
|
|
if (salaryValueTypeEnum == SalaryValueTypeEnum.FORMULA && Objects.nonNull(expressFormula)) {
|
2022-04-11 20:17:47 +08:00
|
|
|
// 运行公式
|
|
|
|
|
resultValue = runExpressFormula(expressFormula, formulaVarValueMap, simpleEmployee);
|
2022-04-27 09:43:24 +08:00
|
|
|
} else if (salaryValueTypeEnum == SalaryValueTypeEnum.SQL && Objects.nonNull(expressFormula)) {
|
|
|
|
|
// 运行SQL
|
|
|
|
|
resultValue = runExpressSQL(expressFormula, formulaVarValueMap, simpleEmployee);
|
2022-04-11 20:17:47 +08:00
|
|
|
} else {
|
|
|
|
|
// 处理取值类型为“输入/导入”的薪资项目
|
|
|
|
|
String key = SalaryFormulaReferenceEnum.SALARY_ITEM.getValue()
|
|
|
|
|
+ SalaryFormulaFieldConstant.FIELD_ID_SEPARATOR
|
|
|
|
|
+ salaryItemPO.getCode();
|
|
|
|
|
resultValue = formulaVarValueMap.getOrDefault(key, StringUtils.EMPTY);
|
|
|
|
|
}
|
|
|
|
|
// 处理薪资档案
|
|
|
|
|
if (Objects.equals(salaryItemPO.getUseInEmployeeSalary(), NumberUtils.INTEGER_ONE)) {
|
|
|
|
|
String key = SalaryFormulaReferenceEnum.SALARY_ARCHIVES.getValue()
|
|
|
|
|
+ SalaryFormulaFieldConstant.FIELD_ID_SEPARATOR
|
|
|
|
|
+ salaryItemPO.getCode();
|
|
|
|
|
resultValue = formulaVarValueMap.getOrDefault(key, StringUtils.EMPTY);
|
|
|
|
|
}
|
|
|
|
|
// 处理合并计税
|
|
|
|
|
resultValue = handleConsolidatedTax(resultValue, salaryItemPO, salaryAcctCalculateBO,
|
|
|
|
|
otherSalaryAcctEmployeePOMap.get(salaryAcctEmployeePO.getEmployeeId() + "_" + salaryAcctEmployeePO.getTaxAgentId()),
|
|
|
|
|
otherSalaryAcctResultPOMap.get(salaryAcctEmployeePO.getEmployeeId() + "_" + salaryAcctEmployeePO.getTaxAgentId()));
|
|
|
|
|
// 处理小数点
|
|
|
|
|
resultValue = SalaryAcctFormulaBO.roundResultValue(resultValue, salaryItemPO);
|
|
|
|
|
// 将已经计算过的薪资项目的值转换成公式变量的值添加到集合中
|
|
|
|
|
String key = SalaryFormulaReferenceEnum.SALARY_ITEM.getValue()
|
|
|
|
|
+ SalaryFormulaFieldConstant.FIELD_ID_SEPARATOR
|
|
|
|
|
+ salaryItemPO.getCode();
|
|
|
|
|
formulaVarValueMap.put(key, resultValue);
|
|
|
|
|
|
|
|
|
|
// 值保存薪资账套下的薪资项目的核算结果
|
|
|
|
|
if (salaryItemIdKeySalarySobItemPOMap.containsKey(salaryItemId)) {
|
|
|
|
|
// 转换成薪资核算结果po
|
|
|
|
|
SalaryAcctResultTempPO salaryAcctResultTempPO = new SalaryAcctResultTempPO()
|
|
|
|
|
// .setId(IdGenerator.generate())
|
|
|
|
|
.setSalaryAcctRecordId(salaryAcctEmployeePO.getSalaryAcctRecordId())
|
|
|
|
|
.setSalaryAcctEmpId(salaryAcctEmployeePO.getId())
|
|
|
|
|
.setEmployeeId(salaryAcctEmployeePO.getEmployeeId())
|
|
|
|
|
.setTaxAgentId(salaryAcctEmployeePO.getTaxAgentId())
|
|
|
|
|
.setSalarySobId(salaryAcctEmployeePO.getSalarySobId())
|
|
|
|
|
.setSalaryItemId(salaryItemPO.getId())
|
|
|
|
|
.setResultValue(resultValue)
|
|
|
|
|
.setCalculateKey(salaryAcctCalculateBO.getCalculateKey())
|
2022-04-26 16:39:41 +08:00
|
|
|
.setCreator((long) user.getUID())
|
2022-04-11 20:17:47 +08:00
|
|
|
.setCreateTime(now)
|
|
|
|
|
.setUpdateTime(now)
|
|
|
|
|
.setTenantKey(SalaryDefaultTenantConstant.DEFAULT_TENANT_KEY)
|
|
|
|
|
.setDeleteType(0);
|
|
|
|
|
salaryAcctResultTempPOS.add(salaryAcctResultTempPO);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 保存新的薪资核算结果(临时存储)
|
|
|
|
|
getSalaryAcctResultTempService(user).batchSave(salaryAcctResultTempPOS);
|
|
|
|
|
// 更新薪资核算进度
|
2022-04-12 19:25:19 +08:00
|
|
|
// salaryAcctProgressService.getAndAddCalculatedQty("" + salaryAcctCalculateBO.getSalaryAcctRecordPO().getId(),
|
|
|
|
|
// salaryAcctCalculateBO.getSalaryAcctEmployeePOS().size());
|
2022-04-11 20:17:47 +08:00
|
|
|
// 记录子线程执行结果
|
|
|
|
|
salaryAcctCalculateBO.getResults().add(new SalaryAcctCalculateBO.Result(true, StringUtils.EMPTY));
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.info("薪资核算失败:{}", e.getMessage(), e);
|
|
|
|
|
salaryAcctCalculateBO.getResults().add(new SalaryAcctCalculateBO.Result(false, e.getMessage()));
|
|
|
|
|
} finally {
|
|
|
|
|
// 数据库字段加密用
|
|
|
|
|
// DSTenantKeyThreadVar.tenantKey.remove();
|
|
|
|
|
// 子线程执行完毕
|
|
|
|
|
salaryAcctCalculateBO.getChildMonitor().countDown();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 运行公式
|
|
|
|
|
*
|
|
|
|
|
* @param expressFormula
|
|
|
|
|
* @param formulaVarValueMap
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private String runExpressFormula(ExpressFormula expressFormula, Map<String, String> formulaVarValueMap, DataCollectionEmployee simpleEmployee) {
|
|
|
|
|
// 给公式中的变量填入值
|
|
|
|
|
List<FormulaVar> formulaVars = ExpressFormulaBO.buildFormulaVar4Accounting(expressFormula, formulaVarValueMap);
|
2022-04-15 13:54:47 +08:00
|
|
|
|
|
|
|
|
Object run = getFormulaRunService(user).run(expressFormula, formulaVars, simpleEmployee);
|
2022-04-11 20:17:47 +08:00
|
|
|
// if (excelResult.isStatus()) {
|
|
|
|
|
// return excelResult.getStringData();
|
|
|
|
|
// }
|
2022-04-15 13:54:47 +08:00
|
|
|
return run.toString();
|
|
|
|
|
// return StringUtils.EMPTY;
|
2022-04-11 20:17:47 +08:00
|
|
|
}
|
|
|
|
|
|
2022-04-27 13:33:44 +08:00
|
|
|
private static final ObjectMapper objectMapper = new ObjectMapper();
|
2022-04-27 09:43:24 +08:00
|
|
|
private String runExpressSQL(ExpressFormula expressFormula, Map<String, String> formulaVarValueMap, DataCollectionEmployee simpleEmployee) {
|
|
|
|
|
|
|
|
|
|
RecordSet rs = new RecordSet();
|
|
|
|
|
//select * from uf_test where epmid = {emp.id}
|
|
|
|
|
String formulaRunScript = expressFormula.getFormulaRunScript();
|
|
|
|
|
|
2022-04-27 13:33:44 +08:00
|
|
|
|
|
|
|
|
String extendParam = expressFormula.getExtendParam();
|
|
|
|
|
String sqlReturnKey ="";
|
|
|
|
|
try {
|
|
|
|
|
JsonNode jsonNode = objectMapper.readTree(extendParam);
|
|
|
|
|
JsonNode sqlReturnKeyNode = jsonNode.get("sqlReturnKey");
|
|
|
|
|
if (sqlReturnKeyNode != null){
|
|
|
|
|
sqlReturnKey = sqlReturnKeyNode.asText();
|
|
|
|
|
}
|
|
|
|
|
} catch (JsonProcessingException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2022-04-27 09:43:24 +08:00
|
|
|
// 给公式中的变量填入值
|
|
|
|
|
List<FormulaVar> formulaVars = ExpressFormulaBO.buildFormulaVar4Accounting(expressFormula, formulaVarValueMap);
|
|
|
|
|
String sql = formulaRunScript;
|
|
|
|
|
for (int i = 0; i < formulaVars.size(); i++) {
|
|
|
|
|
FormulaVar formulaVar = formulaVars.get(i);
|
2022-04-27 13:33:44 +08:00
|
|
|
sql = formulaRunScript.replaceAll(formulaVar.getFieldId(), "'"+formulaVar.getContent()+"'");
|
2022-04-27 09:43:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2022-04-27 13:33:44 +08:00
|
|
|
rs.execute(sql);
|
|
|
|
|
rs.next();
|
|
|
|
|
String string = rs.getString(sqlReturnKey);
|
|
|
|
|
return string;
|
2022-04-27 09:43:24 +08:00
|
|
|
// Object run = getFormulaRunService(user).run(expressFormula, formulaVars, simpleEmployee);
|
|
|
|
|
// return run.toString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2022-04-11 20:17:47 +08:00
|
|
|
/**
|
|
|
|
|
* 处理合并计税
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private String handleConsolidatedTax(String resultValue, SalaryItemPO salaryItemPO, SalaryAcctCalculateBO salaryAcctCalculateBO, List<SalaryAcctEmployeePO> otherSalaryAcctEmployeePOS, List<SalaryAcctResultPO> otherSalaryAcctResultPOS) {
|
|
|
|
|
// 如果相同税款所属期内没有其他薪资核算人员,就不存在合并计税
|
|
|
|
|
if (CollectionUtils.isEmpty(otherSalaryAcctEmployeePOS)) {
|
|
|
|
|
return resultValue;
|
|
|
|
|
}
|
|
|
|
|
// 相同税款所属期内其他薪资核算记录
|
|
|
|
|
Set<Long> otherSalaryAcctRecordIds = SalaryEntityUtil.properties(otherSalaryAcctEmployeePOS, SalaryAcctEmployeePO::getSalaryAcctRecordId);
|
|
|
|
|
List<SalaryAcctRecordPO> otherSalaryAcctRecordPOS = salaryAcctCalculateBO.getOtherSalaryAcctRecordPOS().stream()
|
|
|
|
|
.filter(e -> otherSalaryAcctRecordIds.contains(e.getId()))
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
// 相同税款所属期内,同一个个税扣缴义务人下的同一个人存在多次工资薪金类型的薪资核算记录,那么只有最早创建的薪资核算记录可以扣减如下数据:减除费用、专项扣除、专项附加扣除、其他扣除
|
|
|
|
|
// 根据薪资核算记录的创建时间判断是否需要做合并计税处理
|
|
|
|
|
boolean needConsolidatedTax = otherSalaryAcctRecordPOS.stream().anyMatch(salaryAcctRecordPO -> salaryAcctCalculateBO.getSalaryAcctRecordPO().getCreateTime().compareTo(salaryAcctRecordPO.getCreateTime()) > 0);
|
|
|
|
|
if (!needConsolidatedTax) {
|
|
|
|
|
return resultValue;
|
|
|
|
|
}
|
|
|
|
|
// 合并计税处理
|
|
|
|
|
return SalaryAcctConsolidatedTaxBO.handleConsolidatedTaxValue(resultValue, salaryItemPO, salaryAcctCalculateBO.getSalaryItemPOS(), otherSalaryAcctResultPOS);
|
|
|
|
|
}
|
|
|
|
|
}
|