有向无环拓扑排序

This commit is contained in:
钱涛 2023-09-07 15:15:59 +08:00
parent 464bb9d623
commit 02100c2ee3
10 changed files with 232 additions and 215 deletions

View File

@ -68,7 +68,7 @@ public class SalaryAcctCalculateBO {
/** /**
* 本次运算的薪资项目已排好运算优先级 * 本次运算的薪资项目已排好运算优先级
*/ */
private List<List<Long>> salaryItemIdWithPriorityList; private List<Long> salaryItemIdWithPriorityList;
/** /**
* 本次运算涉及的所有公式 * 本次运算涉及的所有公式

View File

@ -1,6 +1,5 @@
package com.engine.salary.entity.salaryacct.bo; package com.engine.salary.entity.salaryacct.bo;
import com.engine.salary.constant.SalaryFormulaFieldConstant;
import com.engine.salary.entity.salaryformula.ExpressFormula; import com.engine.salary.entity.salaryformula.ExpressFormula;
import com.engine.salary.entity.salaryformula.po.FormulaVar; import com.engine.salary.entity.salaryformula.po.FormulaVar;
import com.engine.salary.entity.salaryitem.po.SalaryItemPO; import com.engine.salary.entity.salaryitem.po.SalaryItemPO;
@ -21,9 +20,10 @@ import org.apache.commons.lang3.StringUtils;
import java.util.*; import java.util.*;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static com.engine.salary.constant.SalaryFormulaFieldConstant.SALARY_PATTERN;
/** /**
* 薪资核算-薪资项目运算优先级 * 薪资核算-薪资项目运算优先级
* <p>Copyright: Copyright (c) 2022</p> * <p>Copyright: Copyright (c) 2022</p>
@ -34,16 +34,6 @@ import java.util.stream.Collectors;
**/ **/
public class SalaryAcctCalculatePriorityBO { public class SalaryAcctCalculatePriorityBO {
/**
* 公式中变量的fieldId的正则表达式
*/
private static final String SALARY_REGEX = "(\\w+)" + SalaryFormulaFieldConstant.FIELD_ID_SEPARATOR + "(\\w+)";
/**
* 解析公式中变量的fieldId的正则表达式
*/
private static final Pattern SALARY_PATTERN = Pattern.compile(SALARY_REGEX);
/** /**
* 计算优先级 * 计算优先级
* *

View File

@ -3,15 +3,18 @@ package com.engine.salary.entity.salaryacct.bo;
import com.engine.salary.entity.salaryformula.ExpressFormula; import com.engine.salary.entity.salaryformula.ExpressFormula;
import com.engine.salary.enums.SalaryRoundingModeEnum; import com.engine.salary.enums.SalaryRoundingModeEnum;
import com.engine.salary.enums.salaryitem.SalaryDataTypeEnum; import com.engine.salary.enums.salaryitem.SalaryDataTypeEnum;
import lombok.Data;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
/** /**
* @description: 薪资核算涉及的薪资项目 * 薪资核算涉及的薪资项目
* @author: xiajun * <p>Copyright: Copyright (c) 2023</p>
* @modified By: xiajun * <p>Company: 泛微软件</p>
* @date: Created in 2023/5/19 16:00 *
* @version:v1.0 * @author qiantao
*/ * @version 1.0
**/
@Data
@Accessors(chain = true) @Accessors(chain = true)
public class SalaryCalcItem { public class SalaryCalcItem {
@ -53,81 +56,4 @@ public class SalaryCalcItem {
private ExpressFormula expressFormula; private ExpressFormula expressFormula;
public Long getSalaryItemId() {
return salaryItemId;
}
public void setSalaryItemId(Long salaryItemId) {
this.salaryItemId = salaryItemId;
}
public String getSalaryItemCode() {
return salaryItemCode;
}
public void setSalaryItemCode(String salaryItemCode) {
this.salaryItemCode = salaryItemCode;
}
public String getIncomeCategory() {
return incomeCategory;
}
public void setIncomeCategory(String incomeCategory) {
this.incomeCategory = incomeCategory;
}
public Integer getUseInEmployeeSalary() {
return useInEmployeeSalary;
}
public void setUseInEmployeeSalary(Integer useInEmployeeSalary) {
this.useInEmployeeSalary = useInEmployeeSalary;
}
public String getDataType() {
return dataType;
}
public void setDataType(String dataType) {
this.dataType = dataType;
}
public Integer getRoundingMode() {
return roundingMode;
}
public void setRoundingMode(Integer roundingMode) {
this.roundingMode = roundingMode;
}
public Integer getPattern() {
return pattern;
}
public void setPattern(Integer pattern) {
this.pattern = pattern;
}
public ExpressFormula getExpressFormula() {
return expressFormula;
}
public void setExpressFormula(ExpressFormula expressFormula) {
this.expressFormula = expressFormula;
}
@Override
public String toString() {
return "SalaryCalcItem{" +
"salaryItemId=" + salaryItemId +
", salaryItemCode='" + salaryItemCode + '\'' +
", incomeCategory='" + incomeCategory + '\'' +
", useInEmployeeSalary=" + useInEmployeeSalary +
", dataType='" + dataType + '\'' +
", roundingMode=" + roundingMode +
", pattern=" + pattern +
", expressFormula=" + expressFormula +
'}';
}
} }

View File

@ -2,7 +2,9 @@ package com.engine.salary.entity.salaryacct.bo;
import com.engine.salary.entity.salaryformula.ExpressFormula; import com.engine.salary.entity.salaryformula.ExpressFormula;
import com.engine.salary.entity.salaryformula.po.FormulaVar; import com.engine.salary.entity.salaryformula.po.FormulaVar;
import com.engine.salary.entity.salaryitem.po.SalaryItemPO;
import com.engine.salary.entity.salarysob.po.SalarySobItemPO; import com.engine.salary.entity.salarysob.po.SalarySobItemPO;
import com.engine.salary.enums.salaryformula.SalaryFormulaReferenceEnum;
import com.engine.salary.report.common.constant.SalaryConstant; import com.engine.salary.report.common.constant.SalaryConstant;
import com.engine.salary.util.SalaryEntityUtil; import com.engine.salary.util.SalaryEntityUtil;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
@ -13,12 +15,13 @@ import java.util.*;
import java.util.concurrent.LinkedTransferQueue; import java.util.concurrent.LinkedTransferQueue;
/** /**
* @description: 对薪资核算时涉及的薪资项目进行排序 * 对薪资核算时涉及的薪资项目进行排序
* @author: xiajun * <p>Copyright: Copyright (c) 2023</p>
* @modified By: xiajun * <p>Company: 泛微软件</p>
* @date: Created in 2023/5/19 16:01 *
* @version:v1.0 * @author qiantao
*/ * @version 1.0
**/
public class SalaryCalcItemGraph { public class SalaryCalcItemGraph {
private List<SalaryCalcItemGraphNode> nodes; private List<SalaryCalcItemGraphNode> nodes;
@ -29,8 +32,9 @@ public class SalaryCalcItemGraph {
* @param salarySobItems 薪资账套的薪资项目 * @param salarySobItems 薪资账套的薪资项目
* @param expressFormulas 公式详情 * @param expressFormulas 公式详情
*/ */
public SalaryCalcItemGraph(List<SalarySobItemPO> salarySobItems, List<ExpressFormula> expressFormulas) { public SalaryCalcItemGraph(List<SalarySobItemPO> salarySobItems, List<SalaryItemPO> salaryItemPOS, List<ExpressFormula> expressFormulas) {
Map<String, SalarySobItemPO> salaryItemMap = SalaryEntityUtil.convert2Map(salarySobItems, SalarySobItemPO::getSalaryItemCode); Map<String, SalarySobItemPO> salarySobItemMap = SalaryEntityUtil.convert2Map(salarySobItems, SalarySobItemPO::getSalaryItemCode);
Map<String, SalaryItemPO> salaryItemMap = SalaryEntityUtil.convert2Map(salaryItemPOS, SalaryItemPO::getCode);
Map<Long, ExpressFormula> expressFormulaMap = SalaryEntityUtil.convert2Map(expressFormulas, ExpressFormula::getId); Map<Long, ExpressFormula> expressFormulaMap = SalaryEntityUtil.convert2Map(expressFormulas, ExpressFormula::getId);
Map<Long, List<FormulaVar>> formulaVarMap = ExpressFormulaBO.buildFormulaVar(expressFormulas); Map<Long, List<FormulaVar>> formulaVarMap = ExpressFormulaBO.buildFormulaVar(expressFormulas);
@ -40,14 +44,20 @@ public class SalaryCalcItemGraph {
SalaryCalcItemGraphNode node = nodeMap.computeIfAbsent(salarySobItem.getSalaryItemId(), key -> new SalaryCalcItemGraphNode(salarySobItem, expressFormula)); SalaryCalcItemGraphNode node = nodeMap.computeIfAbsent(salarySobItem.getSalaryItemId(), key -> new SalaryCalcItemGraphNode(salarySobItem, expressFormula));
List<FormulaVar> formulaVars = expressFormula == null ? Collections.emptyList() : formulaVarMap.getOrDefault(expressFormula.getId(), Collections.emptyList()); List<FormulaVar> formulaVars = expressFormula == null ? Collections.emptyList() : formulaVarMap.getOrDefault(expressFormula.getId(), Collections.emptyList());
for (FormulaVar formulaVar : formulaVars) { for (FormulaVar formulaVar : formulaVars) {
if (StringUtils.isNotEmpty(formulaVar.getFieldId())) { if (StringUtils.isNotEmpty(formulaVar.getFieldId()) && StringUtils.startsWith(formulaVar.getFieldId(), SalaryFormulaReferenceEnum.SALARY_ITEM.getValue() + SalaryConstant.FORMULA_VAR_SEPARATOR)) {
String salaryItemCode = formulaVar.getFieldId().split(SalaryConstant.FORMULA_VAR_SEPARATOR)[1]; String salaryItemCode = formulaVar.getFieldId().split(SalaryConstant.FORMULA_VAR_SEPARATOR)[1];
SalarySobItemPO subSalarySobItem = salaryItemMap.get(salaryItemCode); SalarySobItemPO subSalarySobItem = salarySobItemMap.get(salaryItemCode);
if (subSalarySobItem == null) { if (subSalarySobItem == null) {
continue; SalaryItemPO salaryItemPO = salaryItemMap.get(salaryItemCode);
if (salaryItemPO == null) {
continue;
}else {
subSalarySobItem = SalarySobItemPO.builder().salaryItemId(salaryItemPO.getId()).salaryItemCode(salaryItemPO.getCode()).build();
}
} }
ExpressFormula subExpressFormula = expressFormulaMap.get(subSalarySobItem.getFormulaId()); ExpressFormula subExpressFormula = expressFormulaMap.get(subSalarySobItem.getFormulaId());
SalaryCalcItemGraphNode destNode = nodeMap.computeIfAbsent(subSalarySobItem.getSalaryItemId(), key -> new SalaryCalcItemGraphNode(subSalarySobItem, subExpressFormula)); SalarySobItemPO finalSubSalarySobItem = subSalarySobItem;
SalaryCalcItemGraphNode destNode = nodeMap.computeIfAbsent(subSalarySobItem.getSalaryItemId(), key -> new SalaryCalcItemGraphNode(finalSubSalarySobItem, subExpressFormula));
node.getDestNodes().add(destNode); node.getDestNodes().add(destNode);
} }
} }

View File

@ -94,7 +94,7 @@ public class TaxDeclarationValueList {
dataMap.put("username", employeeDeclare.getEmployeeName()); dataMap.put("username", employeeDeclare.getEmployeeName());
dataMap.put("cardType", SalaryI18nUtil.getI18nLabel(CardTypeEnum.RESIDENT_IDENTITY_CARDS.getLabelId(), CardTypeEnum.RESIDENT_IDENTITY_CARDS.getDefaultLabel())); dataMap.put("cardType", SalaryI18nUtil.getI18nLabel(CardTypeEnum.RESIDENT_IDENTITY_CARDS.getLabelId(), CardTypeEnum.RESIDENT_IDENTITY_CARDS.getDefaultLabel()));
dataMap.put("cardNum", employeeDeclare.getCardNum()); dataMap.put("cardNum", employeeDeclare.getCardNum());
} else if (Objects.equals(taxDeclarationValue.getEmployeeType(), EmployeeTypeEnum.ORGANIZATION.getValue())) { } else if (taxDeclarationValue.getEmployeeType() == null || Objects.equals(taxDeclarationValue.getEmployeeType(), EmployeeTypeEnum.ORGANIZATION.getValue())) {
DataCollectionEmployee simpleEmployee = simpleEmployeeMap.get(taxDeclarationValue.getEmployeeId()); DataCollectionEmployee simpleEmployee = simpleEmployeeMap.get(taxDeclarationValue.getEmployeeId());
DataCollectionEmployee simpleUserInfo = simpleUserInfoMap.get(taxDeclarationValue.getEmployeeId()); DataCollectionEmployee simpleUserInfo = simpleUserInfoMap.get(taxDeclarationValue.getEmployeeId());
dataMap.put("jobNum", simpleEmployee.getWorkcode()); dataMap.put("jobNum", simpleEmployee.getWorkcode());

View File

@ -4,20 +4,23 @@ import com.engine.common.util.ServiceUtil;
import com.engine.core.impl.Service; import com.engine.core.impl.Service;
import com.engine.salary.entity.datacollection.DataCollectionEmployee; import com.engine.salary.entity.datacollection.DataCollectionEmployee;
import com.engine.salary.entity.datacollection.dto.AttendQuoteFieldListDTO; import com.engine.salary.entity.datacollection.dto.AttendQuoteFieldListDTO;
import com.engine.salary.entity.salaryacct.bo.SalaryAcctCalculateBO;
import com.engine.salary.entity.salaryacct.bo.SalaryAcctCalculatePriorityBO;
import com.engine.salary.entity.progress.ProgressDTO; import com.engine.salary.entity.progress.ProgressDTO;
import com.engine.salary.entity.salaryacct.bo.SalaryAcctCalculateBO;
import com.engine.salary.entity.salaryacct.bo.SalaryCalcItem;
import com.engine.salary.entity.salaryacct.bo.SalaryCalcItemGraph;
import com.engine.salary.entity.salaryacct.po.SalaryAcctEmployeePO; import com.engine.salary.entity.salaryacct.po.SalaryAcctEmployeePO;
import com.engine.salary.entity.salaryacct.po.SalaryAcctRecordPO; import com.engine.salary.entity.salaryacct.po.SalaryAcctRecordPO;
import com.engine.salary.entity.salaryacct.po.SalaryAcctResultPO; import com.engine.salary.entity.salaryacct.po.SalaryAcctResultPO;
import com.engine.salary.entity.salaryacct.po.SalaryAcctResultTempPO; import com.engine.salary.entity.salaryacct.po.SalaryAcctResultTempPO;
import com.engine.salary.entity.salaryformula.ExpressFormula; import com.engine.salary.entity.salaryformula.ExpressFormula;
import com.engine.salary.entity.salaryformula.po.FormulaVar;
import com.engine.salary.entity.salaryitem.po.SalaryItemPO; import com.engine.salary.entity.salaryitem.po.SalaryItemPO;
import com.engine.salary.entity.salarysob.dto.SalarySobCycleDTO; import com.engine.salary.entity.salarysob.dto.SalarySobCycleDTO;
import com.engine.salary.entity.salarysob.po.SalarySobAdjustRulePO; import com.engine.salary.entity.salarysob.po.SalarySobAdjustRulePO;
import com.engine.salary.entity.salarysob.po.SalarySobBackItemPO; import com.engine.salary.entity.salarysob.po.SalarySobBackItemPO;
import com.engine.salary.entity.salarysob.po.SalarySobItemPO; import com.engine.salary.entity.salarysob.po.SalarySobItemPO;
import com.engine.salary.entity.salarysob.po.SalarySobPO; import com.engine.salary.entity.salarysob.po.SalarySobPO;
import com.engine.salary.enums.salaryformula.SalaryFormulaReferenceEnum;
import com.engine.salary.exception.SalaryRunTimeException; import com.engine.salary.exception.SalaryRunTimeException;
import com.engine.salary.mapper.salaryacct.SalaryAcctResultMapper; import com.engine.salary.mapper.salaryacct.SalaryAcctResultMapper;
import com.engine.salary.service.*; import com.engine.salary.service.*;
@ -38,6 +41,7 @@ import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils; import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang.math.NumberUtils; import org.apache.commons.lang.math.NumberUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.jdbc.datasource.DataSourceTransactionManager; import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import weaver.hrm.User; import weaver.hrm.User;
@ -47,8 +51,11 @@ import java.util.*;
import java.util.concurrent.BlockingDeque; import java.util.concurrent.BlockingDeque;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.LinkedBlockingDeque; import java.util.concurrent.LinkedBlockingDeque;
import java.util.regex.Matcher;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static com.engine.salary.constant.SalaryFormulaFieldConstant.SALARY_PATTERN;
/** /**
* 薪资核算维护类 * 薪资核算维护类
* <p>Copyright: Copyright (c) 2022</p> * <p>Copyright: Copyright (c) 2022</p>
@ -294,9 +301,10 @@ public class SalaryAcctManager extends Service {
formulaIds.addAll(SalaryEntityUtil.properties(salarySobBackItems, SalarySobBackItemPO::getFormulaId)); formulaIds.addAll(SalaryEntityUtil.properties(salarySobBackItems, SalarySobBackItemPO::getFormulaId));
List<ExpressFormula> expressFormulas = getSalaryFormulaService(user).listExpressFormula(formulaIds); List<ExpressFormula> expressFormulas = getSalaryFormulaService(user).listExpressFormula(formulaIds);
// 本次运算的回算薪资项目所涉及的变量 // 本次运算的回算薪资项目所涉及的变量
Set<String> issuedFieldIds = new HashSet<>(); Set<String> issuedFieldIds = getIssuedFieldIds(salarySobBackItems);
// 9计算薪资项目的运算优先级 // 9计算薪资项目的运算优先级
List<List<Long>> salarySobItemsWithPriority = SalaryAcctCalculatePriorityBO.calculatePriority(salarySobItemPOS, salaryItemPOS, expressFormulas, salarySobBackItems, issuedFieldIds); // List<List<Long>> salarySobItemsWithPriority = SalaryAcctCalculatePriorityBO.calculatePriority(salarySobItemPOS, salaryItemPOS, expressFormulas, salarySobBackItems, issuedFieldIds);
List<Long> salarySobItemsWithPriority = sortItems(salarySobItemPOS, salarySobBackItems, salaryItemPOS, expressFormulas);
// 10根据id查询其他合并计税的薪资核算记录 // 10根据id查询其他合并计税的薪资核算记录
List<SalaryAcctRecordPO> otherSalaryAcctRecordPOS = getSalaryAcctRecordService(user).listById4OtherConsolidatedTax(salaryAcctRecordPO.getId()); List<SalaryAcctRecordPO> otherSalaryAcctRecordPOS = getSalaryAcctRecordService(user).listById4OtherConsolidatedTax(salaryAcctRecordPO.getId());
// 11查询本次核算人员 // 11查询本次核算人员
@ -396,5 +404,43 @@ public class SalaryAcctManager extends Service {
getSalaryAcctResultTempService(user).deleteByCalculateKey(calculateKey); getSalaryAcctResultTempService(user).deleteByCalculateKey(calculateKey);
} }
@NotNull
private List<Long> sortItems(List<SalarySobItemPO> salarySobItemPOS, List<SalarySobBackItemPO> salarySobBackItems, List<SalaryItemPO> salaryItemPOS, List<ExpressFormula> expressFormulas) {
List<SalarySobItemPO> temp = salarySobBackItems.stream()
.map(e -> {
SalarySobItemPO salarySobItem = new SalarySobItemPO();
BeanUtils.copyProperties(e, salarySobItem);
return salarySobItem;
}).collect(Collectors.toList());
salarySobItemPOS.addAll(temp);
SalaryCalcItemGraph salaryCalcItemGraph = new SalaryCalcItemGraph(salarySobItemPOS, salaryItemPOS, expressFormulas);
List<SalaryCalcItem> salaryCalcItems = salaryCalcItemGraph.sort();
return SalaryEntityUtil.properties(salaryCalcItems, SalaryCalcItem::getSalaryItemId, Collectors.toList());
}
/**
* 获取回算变量
*
* @param salarySobBackItems
* @return
*/
@NotNull
private Set<String> getIssuedFieldIds(List<SalarySobBackItemPO> salarySobBackItems) {
Set<String> issuedFieldIds;
Set<Long> issuedFormulaIds = SalaryEntityUtil.properties(salarySobBackItems, SalarySobBackItemPO::getFormulaId);
List<ExpressFormula> expressFormulas1 = getSalaryFormulaService(user).listExpressFormula(issuedFormulaIds);
List<FormulaVar> issuedFormulaVars = new ArrayList<>();
expressFormulas1.forEach(f -> issuedFormulaVars.addAll(f.getParameters()));
issuedFieldIds = issuedFormulaVars.stream()
.map(FormulaVar::getFieldId)
.filter(StringUtils::isNotBlank)
.filter(v -> v.startsWith(SalaryFormulaReferenceEnum.ISSUED.getValue() + "_"))
.map(SALARY_PATTERN::matcher)
.filter(Matcher::find)
.map(m -> m.group(2))
.collect(Collectors.toSet());
return issuedFieldIds;
}
} }

View File

@ -183,82 +183,80 @@ public class SalaryAcctCalculateServiceImpl extends Service implements SalaryAcc
formulaVarValues.addAll(empInfo); formulaVarValues.addAll(empInfo);
Map<String, String> formulaVarValueMap = SalaryEntityUtil.convert2Map(formulaVarValues, CalculateFormulaVarBO.FormulaVarValue::getFieldId, CalculateFormulaVarBO.FormulaVarValue::getFieldValue); Map<String, String> formulaVarValueMap = SalaryEntityUtil.convert2Map(formulaVarValues, CalculateFormulaVarBO.FormulaVarValue::getFieldId, CalculateFormulaVarBO.FormulaVarValue::getFieldValue);
// 按照计算好的优先级计算薪资项目的值 // 按照计算好的优先级计算薪资项目的值
for (List<Long> salaryItemIds : salaryAcctCalculateBO.getSalaryItemIdWithPriorityList()) { for (Long salaryItemId : salaryAcctCalculateBO.getSalaryItemIdWithPriorityList()) {
// 同一运算优先级下的薪资项目逐个独立运算 // 同一运算优先级下的薪资项目逐个独立运算
for (Long salaryItemId : salaryItemIds) { String resultValue;
String resultValue; SalaryItemPO salaryItemPO = salaryItemMap.get(salaryItemId);
SalaryItemPO salaryItemPO = salaryItemMap.get(salaryItemId); ExpressFormula expressFormula;
ExpressFormula expressFormula; if (salarySobBackItemMap.containsKey(salaryItemId)) {
if (salarySobBackItemMap.containsKey(salaryItemId)) { // 如果薪资账套的回算项目中重新定义了回算项目公式则使用薪资账套下的公式
// 如果薪资账套的回算项目中重新定义了回算项目公式则使用薪资账套下的公式 SalarySobBackItemPO salarySobBackItemPO = salarySobBackItemMap.get(salaryItemId);
SalarySobBackItemPO salarySobBackItemPO = salarySobBackItemMap.get(salaryItemId); expressFormula = expressFormulaMap.get(salarySobBackItemPO.getFormulaId());
expressFormula = expressFormulaMap.get(salarySobBackItemPO.getFormulaId()); } else if (salaryItemIdKeySalarySobItemPOMap.containsKey(salaryItemId)) {
} else if (salaryItemIdKeySalarySobItemPOMap.containsKey(salaryItemId)) { // 如果薪资账套下重新定义了薪资项目的公式则使用薪资账套下的公式否则使用薪资项目本身的公式
// 如果薪资账套下重新定义了薪资项目的公式则使用薪资账套下的公式否则使用薪资项目本身的公式 SalarySobItemPO salarySobItemPO = salaryItemIdKeySalarySobItemPOMap.get(salaryItemId);
SalarySobItemPO salarySobItemPO = salaryItemIdKeySalarySobItemPOMap.get(salaryItemId); expressFormula = expressFormulaMap.get(salarySobItemPO.getFormulaId());
expressFormula = expressFormulaMap.get(salarySobItemPO.getFormulaId()); } else {
} else { expressFormula = expressFormulaMap.get(salaryItemPO.getFormulaId());
expressFormula = expressFormulaMap.get(salaryItemPO.getFormulaId()); }
if (Objects.nonNull(expressFormula)) {
// 运行公式
ExcelResult result = runExpressFormula(expressFormula, formulaVarValueMap, simpleEmployee);
resultValue = Utils.null2String(result.getData());
//公式异常信息
if (!result.isStatus()) {
String username = empInfo.stream().filter(emp -> StringUtils.equals("employeeInfo_username", emp.getFieldId())).findFirst().map(CalculateFormulaVarBO.FormulaVarValue::getFieldValue).orElse("");
String errorMsg = String.format("%s的%s核算异常原因%s \r\n", username, salaryItemPO.getName(), result.getErrorMsg());
noticeMsg.append(errorMsg);
} }
if (Objects.nonNull(expressFormula)) { //提醒运行超时
// 运行公式 if (StringUtils.isNotBlank(formulaRunOvertimeThreshold) && result.getRunTime() > Long.parseLong(formulaRunOvertimeThreshold)) {
ExcelResult result = runExpressFormula(expressFormula, formulaVarValueMap, simpleEmployee); String username = empInfo.stream().filter(emp -> StringUtils.equals("employeeInfo_username", emp.getFieldId())).findFirst().map(CalculateFormulaVarBO.FormulaVarValue::getFieldValue).orElse("");
resultValue = Utils.null2String(result.getData()); String errorMsg = String.format("%s的%s核算超时耗时%s毫秒 \r\n", username, salaryItemPO.getName(), result.getRunTime());
//公式异常信息 noticeMsg.append(errorMsg);
if (!result.isStatus()) {
String username = empInfo.stream().filter(emp -> StringUtils.equals("employeeInfo_username", emp.getFieldId())).findFirst().map(CalculateFormulaVarBO.FormulaVarValue::getFieldValue).orElse("");
String errorMsg = String.format("%s的%s核算异常原因%s \r\n", username, salaryItemPO.getName(), result.getErrorMsg());
noticeMsg.append(errorMsg);
}
//提醒运行超时
if (StringUtils.isNotBlank(formulaRunOvertimeThreshold) && result.getRunTime() > Long.parseLong(formulaRunOvertimeThreshold)) {
String username = empInfo.stream().filter(emp -> StringUtils.equals("employeeInfo_username", emp.getFieldId())).findFirst().map(CalculateFormulaVarBO.FormulaVarValue::getFieldValue).orElse("");
String errorMsg = String.format("%s的%s核算超时耗时%s毫秒 \r\n", username, salaryItemPO.getName(), result.getRunTime());
noticeMsg.append(errorMsg);
}
} else {
// 处理取值类型为输入/导入的薪资项目
String key = SalaryFormulaReferenceEnum.SALARY_ITEM.getValue() + SalaryFormulaFieldConstant.FIELD_ID_SEPARATOR + salaryItemPO.getCode();
resultValue = formulaVarValueMap.getOrDefault(key, StringUtils.EMPTY);
} }
// 处理薪资档案 } else {
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, salarySobBackItems, salarySobBackItemMap, salaryItemIdKeySalarySobItemPOMap);
//是否锁定
if (lockSalaryItemIds.contains(salaryItemId) && salaryAcctLockResultPOS.get(salaryItemId + "_" + salaryAcctEmployeePOId) != null) {
resultValue = salaryAcctLockResultPOS.get(salaryItemId + "_" + salaryAcctEmployeePOId).getResultValue();
}
// 将已经计算过的薪资项目的值转换成公式变量的值添加到集合中
String key = SalaryFormulaReferenceEnum.SALARY_ITEM.getValue() + SalaryFormulaFieldConstant.FIELD_ID_SEPARATOR + salaryItemPO.getCode(); String key = SalaryFormulaReferenceEnum.SALARY_ITEM.getValue() + SalaryFormulaFieldConstant.FIELD_ID_SEPARATOR + salaryItemPO.getCode();
formulaVarValueMap.put(key, resultValue); resultValue = formulaVarValueMap.getOrDefault(key, StringUtils.EMPTY);
// 值保存薪资账套下的薪资项目的核算结果 }
if (salaryItemIdKeySalarySobItemPOMap.containsKey(salaryItemId) || salarySobBackItemIds.contains(salaryItemId)) { // 处理薪资档案
// 转换成薪资核算结果po if (Objects.equals(salaryItemPO.getUseInEmployeeSalary(), NumberUtils.INTEGER_ONE)) {
SalaryAcctResultTempPO salaryAcctResultTempPO = new SalaryAcctResultTempPO() String key = SalaryFormulaReferenceEnum.SALARY_ARCHIVES.getValue() + SalaryFormulaFieldConstant.FIELD_ID_SEPARATOR + salaryItemPO.getCode();
.setSalaryAcctRecordId(salaryAcctEmployeePO.getSalaryAcctRecordId()) resultValue = formulaVarValueMap.getOrDefault(key, StringUtils.EMPTY);
.setSalaryAcctEmpId(salaryAcctEmployeePOId) }
.setEmployeeId(salaryAcctEmployeePO.getEmployeeId()) // 处理合并计税
.setTaxAgentId(salaryAcctEmployeePO.getTaxAgentId()) resultValue = handleConsolidatedTax(resultValue, salaryItemPO, salaryAcctCalculateBO, otherSalaryAcctEmployeePOMap.get(salaryAcctEmployeePO.getEmployeeId() + "_" + salaryAcctEmployeePO.getTaxAgentId()), otherSalaryAcctResultPOMap.get(salaryAcctEmployeePO.getEmployeeId() + "_" + salaryAcctEmployeePO.getTaxAgentId()));
.setSalarySobId(salaryAcctEmployeePO.getSalarySobId())
.setSalaryItemId(salaryItemPO.getId()) // 处理小数点
.setResultValue(resultValue) resultValue = SalaryAcctFormulaBO.roundResultValue(resultValue, salaryItemPO, salarySobBackItems, salarySobBackItemMap, salaryItemIdKeySalarySobItemPOMap);
.setOriginResultValue(salaryAcctResultPOMap.get(salaryAcctEmployeePO.getEmployeeId() + "-" + salaryAcctEmployeePO.getTaxAgentId() + "-" + salaryItemId) == null //是否锁定
? StringUtils.EMPTY : salaryAcctResultPOMap.get(salaryAcctEmployeePO.getEmployeeId() + "-" + salaryAcctEmployeePO.getTaxAgentId() + "-" + salaryItemId)) if (lockSalaryItemIds.contains(salaryItemId) && salaryAcctLockResultPOS.get(salaryItemId + "_" + salaryAcctEmployeePOId) != null) {
.setCalculateKey(salaryAcctCalculateBO.getCalculateKey()) resultValue = salaryAcctLockResultPOS.get(salaryItemId + "_" + salaryAcctEmployeePOId).getResultValue();
.setCreator((long) user.getUID()) }
.setCreateTime(now) // 将已经计算过的薪资项目的值转换成公式变量的值添加到集合中
.setUpdateTime(now) String key = SalaryFormulaReferenceEnum.SALARY_ITEM.getValue() + SalaryFormulaFieldConstant.FIELD_ID_SEPARATOR + salaryItemPO.getCode();
.setTenantKey(SalaryDefaultTenantConstant.DEFAULT_TENANT_KEY) formulaVarValueMap.put(key, resultValue);
.setDeleteType(0); // 值保存薪资账套下的薪资项目的核算结果
salaryAcctResultTempPOS.add(salaryAcctResultTempPO); if (salaryItemIdKeySalarySobItemPOMap.containsKey(salaryItemId) || salarySobBackItemIds.contains(salaryItemId)) {
} // 转换成薪资核算结果po
SalaryAcctResultTempPO salaryAcctResultTempPO = new SalaryAcctResultTempPO()
.setSalaryAcctRecordId(salaryAcctEmployeePO.getSalaryAcctRecordId())
.setSalaryAcctEmpId(salaryAcctEmployeePOId)
.setEmployeeId(salaryAcctEmployeePO.getEmployeeId())
.setTaxAgentId(salaryAcctEmployeePO.getTaxAgentId())
.setSalarySobId(salaryAcctEmployeePO.getSalarySobId())
.setSalaryItemId(salaryItemPO.getId())
.setResultValue(resultValue)
.setOriginResultValue(salaryAcctResultPOMap.get(salaryAcctEmployeePO.getEmployeeId() + "-" + salaryAcctEmployeePO.getTaxAgentId() + "-" + salaryItemId) == null
? StringUtils.EMPTY : salaryAcctResultPOMap.get(salaryAcctEmployeePO.getEmployeeId() + "-" + salaryAcctEmployeePO.getTaxAgentId() + "-" + salaryItemId))
.setCalculateKey(salaryAcctCalculateBO.getCalculateKey())
.setCreator((long) user.getUID())
.setCreateTime(now)
.setUpdateTime(now)
.setTenantKey(SalaryDefaultTenantConstant.DEFAULT_TENANT_KEY)
.setDeleteType(0);
salaryAcctResultTempPOS.add(salaryAcctResultTempPO);
} }
} }
} }

View File

@ -17,6 +17,7 @@ import com.engine.salary.entity.salaryacct.dto.SalaryAcctResultListColumnDTO;
import com.engine.salary.entity.salaryacct.param.*; import com.engine.salary.entity.salaryacct.param.*;
import com.engine.salary.entity.salaryacct.po.*; import com.engine.salary.entity.salaryacct.po.*;
import com.engine.salary.entity.salaryformula.ExpressFormula; import com.engine.salary.entity.salaryformula.ExpressFormula;
import com.engine.salary.entity.salaryformula.po.FormulaVar;
import com.engine.salary.entity.salaryitem.po.SalaryItemPO; import com.engine.salary.entity.salaryitem.po.SalaryItemPO;
import com.engine.salary.entity.salarysob.dto.*; import com.engine.salary.entity.salarysob.dto.*;
import com.engine.salary.entity.salarysob.po.*; import com.engine.salary.entity.salarysob.po.*;
@ -26,6 +27,7 @@ import com.engine.salary.enums.SalaryValueTypeEnum;
import com.engine.salary.enums.salaryaccounting.LockStatusEnum; import com.engine.salary.enums.salaryaccounting.LockStatusEnum;
import com.engine.salary.enums.salaryaccounting.SalaryAcctRecordStatusEnum; import com.engine.salary.enums.salaryaccounting.SalaryAcctRecordStatusEnum;
import com.engine.salary.enums.salaryaccounting.SalaryAcctResultDataSourceEnum; import com.engine.salary.enums.salaryaccounting.SalaryAcctResultDataSourceEnum;
import com.engine.salary.enums.salaryformula.SalaryFormulaReferenceEnum;
import com.engine.salary.enums.salaryitem.SalaryDataTypeEnum; import com.engine.salary.enums.salaryitem.SalaryDataTypeEnum;
import com.engine.salary.enums.salarysob.IncomeCategoryEnum; import com.engine.salary.enums.salarysob.IncomeCategoryEnum;
import com.engine.salary.exception.SalaryRunTimeException; import com.engine.salary.exception.SalaryRunTimeException;
@ -54,6 +56,8 @@ import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils; import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils; import org.apache.commons.lang3.math.NumberUtils;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.BeanUtils;
import org.springframework.jdbc.datasource.DataSourceTransactionManager; import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import weaver.hrm.User; import weaver.hrm.User;
@ -62,8 +66,11 @@ import java.util.*;
import java.util.concurrent.BlockingDeque; import java.util.concurrent.BlockingDeque;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.LinkedBlockingDeque; import java.util.concurrent.LinkedBlockingDeque;
import java.util.regex.Matcher;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static com.engine.salary.constant.SalaryFormulaFieldConstant.SALARY_PATTERN;
/** /**
* 薪资核算结果 * 薪资核算结果
* <p>Copyright: Copyright (c) 2022</p> * <p>Copyright: Copyright (c) 2022</p>
@ -331,7 +338,7 @@ public class SalaryAcctResultServiceImpl extends Service implements SalaryAcctRe
List<SalarySobItemPO> salarySobItemPOS = getSalarySobItemService(user).listBySalarySobId(salaryAcctRecordPO.getSalarySobId()); List<SalarySobItemPO> salarySobItemPOS = getSalarySobItemService(user).listBySalarySobId(salaryAcctRecordPO.getSalarySobId());
Map<Long, SalarySobItemPO> salaryItemIdKeySalarySobItemPOMap = SalaryEntityUtil.convert2Map(salarySobItemPOS, SalarySobItemPO::getSalaryItemId); Map<Long, SalarySobItemPO> salaryItemIdKeySalarySobItemPOMap = SalaryEntityUtil.convert2Map(salarySobItemPOS, SalarySobItemPO::getSalaryItemId);
Set<Long> salaryItemIds = SalaryEntityUtil.properties(salarySobItemPOS, SalarySobItemPO::getSalaryItemId); Set<Long> salaryItemIds = SalaryEntityUtil.properties(salarySobItemPOS, SalarySobItemPO::getSalaryItemId);
if(Objects.equals(salaryAcctRecordPO.getBackCalcStatus(), NumberUtils.INTEGER_ONE)){ if (Objects.equals(salaryAcctRecordPO.getBackCalcStatus(), NumberUtils.INTEGER_ONE)) {
// 是回算获取回算项 // 是回算获取回算项
List<SalarySobBackItemPO> salarySobBackItemPOS = getSalarySobBackItemService(user).listBySalarySobId(salaryAcctRecordPO.getSalarySobId()); List<SalarySobBackItemPO> salarySobBackItemPOS = getSalarySobBackItemService(user).listBySalarySobId(salaryAcctRecordPO.getSalarySobId());
salaryItemIds.addAll(salarySobBackItemPOS.stream().map(SalarySobBackItemPO::getSalaryItemId).collect(Collectors.toList())); salaryItemIds.addAll(salarySobBackItemPOS.stream().map(SalarySobBackItemPO::getSalaryItemId).collect(Collectors.toList()));
@ -339,7 +346,7 @@ public class SalaryAcctResultServiceImpl extends Service implements SalaryAcctRe
List<SalaryItemPO> salaryItemPOS = getSalaryItemService(user).listByIds(salaryItemIds); List<SalaryItemPO> salaryItemPOS = getSalaryItemService(user).listByIds(salaryItemIds);
// 查询薪资核算结果 // 查询薪资核算结果
List<Long> salaryAcctEmployeeIds = SalaryEntityUtil.properties(salaryAcctEmployeePOS, SalaryAcctEmployeePO::getId,Collectors.toList()); List<Long> salaryAcctEmployeeIds = SalaryEntityUtil.properties(salaryAcctEmployeePOS, SalaryAcctEmployeePO::getId, Collectors.toList());
List<SalaryAcctResultPO> salaryAcctResultPOS = listBySalaryAcctEmployeeIds(salaryAcctEmployeeIds); List<SalaryAcctResultPO> salaryAcctResultPOS = listBySalaryAcctEmployeeIds(salaryAcctEmployeeIds);
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
@ -396,7 +403,7 @@ public class SalaryAcctResultServiceImpl extends Service implements SalaryAcctRe
} }
List<SalaryItemPO> salaryItemPOS = getSalaryItemService(user).listByIds(salaryItemIds); List<SalaryItemPO> salaryItemPOS = getSalaryItemService(user).listByIds(salaryItemIds);
// 查询薪资核算结果 // 查询薪资核算结果
List<Long> salaryAcctEmployeeIds = SalaryEntityUtil.properties(salaryAcctEmployeePOS, SalaryAcctEmployeePO::getId,Collectors.toList()); List<Long> salaryAcctEmployeeIds = SalaryEntityUtil.properties(salaryAcctEmployeePOS, SalaryAcctEmployeePO::getId, Collectors.toList());
List<SalaryAcctResultPO> salaryAcctResultPOS = listBySalaryAcctEmployeeIds(salaryAcctEmployeeIds); List<SalaryAcctResultPO> salaryAcctResultPOS = listBySalaryAcctEmployeeIds(salaryAcctEmployeeIds);
// 查询人员信息 // 查询人员信息
List<Long> employeeIds = SalaryEntityUtil.properties(salaryAcctEmployeePOS, SalaryAcctEmployeePO::getEmployeeId, Collectors.toList()); List<Long> employeeIds = SalaryEntityUtil.properties(salaryAcctEmployeePOS, SalaryAcctEmployeePO::getEmployeeId, Collectors.toList());
@ -477,7 +484,7 @@ public class SalaryAcctResultServiceImpl extends Service implements SalaryAcctRe
salaryAcctEmployeePOS = getSalaryAcctEmployeeService(user).listByRecordIdsAndEmpIdAndTaxAgentId(salaryAcctRecordIds, salaryAcctEmployeePO.getEmployeeId(), salaryAcctEmployeePO.getTaxAgentId()); salaryAcctEmployeePOS = getSalaryAcctEmployeeService(user).listByRecordIdsAndEmpIdAndTaxAgentId(salaryAcctRecordIds, salaryAcctEmployeePO.getEmployeeId(), salaryAcctEmployeePO.getTaxAgentId());
} }
// 查询薪资核算人员的薪资核算结果 // 查询薪资核算人员的薪资核算结果
List<Long> salaryAcctEmployeeIds = SalaryEntityUtil.properties(salaryAcctEmployeePOS, SalaryAcctEmployeePO::getId,Collectors.toList()); List<Long> salaryAcctEmployeeIds = SalaryEntityUtil.properties(salaryAcctEmployeePOS, SalaryAcctEmployeePO::getId, Collectors.toList());
List<SalaryAcctResultPO> salaryAcctResultPOS = listBySalaryAcctEmployeeIds(salaryAcctEmployeeIds); List<SalaryAcctResultPO> salaryAcctResultPOS = listBySalaryAcctEmployeeIds(salaryAcctEmployeeIds);
// 查询薪资核算人员所有合并计税的薪资核算记录所用的账套 // 查询薪资核算人员所有合并计税的薪资核算记录所用的账套
Set<Long> salarySobIds = SalaryEntityUtil.properties(salaryAcctEmployeePOS, SalaryAcctEmployeePO::getSalarySobId); Set<Long> salarySobIds = SalaryEntityUtil.properties(salaryAcctEmployeePOS, SalaryAcctEmployeePO::getSalarySobId);
@ -555,13 +562,13 @@ public class SalaryAcctResultServiceImpl extends Service implements SalaryAcctRe
// 保存参数转换成薪资核算结果po // 保存参数转换成薪资核算结果po
List<SalaryAcctResultPO> salaryAcctResultPOS = SalaryAcctResultBO.convert2PO(salaryAcctResultPOSOld, saveParam, salaryAcctEmployeePO, (long) user.getUID()); List<SalaryAcctResultPO> salaryAcctResultPOS = SalaryAcctResultBO.convert2PO(salaryAcctResultPOSOld, saveParam, salaryAcctEmployeePO, (long) user.getUID());
SalarySysConfPO autoLock = getSalarySysConfService(user).getOneByCode(SalarySysConstant.EDIT_IMPORT_AUTO_LOCK); SalarySysConfPO autoLock = getSalarySysConfService(user).getOneByCode(SalarySysConstant.EDIT_IMPORT_AUTO_LOCK);
if(autoLock != null && StringUtils.equals(autoLock.getConfValue(),"1")){ if (autoLock != null && StringUtils.equals(autoLock.getConfValue(), "1")) {
// 对比核算结果提取修改了哪些薪资项目 // 对比核算结果提取修改了哪些薪资项目
Set<Long> needLockItems = new HashSet<>(); Set<Long> needLockItems = new HashSet<>();
Map<Long, SalaryAcctResultPO> oldResutMap = SalaryEntityUtil.convert2Map(salaryAcctResultPOSOld, SalaryAcctResultPO::getSalaryItemId); Map<Long, SalaryAcctResultPO> oldResutMap = SalaryEntityUtil.convert2Map(salaryAcctResultPOSOld, SalaryAcctResultPO::getSalaryItemId);
salaryAcctResultPOS.stream().forEach(PO -> { salaryAcctResultPOS.stream().forEach(PO -> {
String oldValue = Optional.ofNullable(oldResutMap.get(PO.getSalaryItemId())).map(SalaryAcctResultPO::getResultValue).orElse(""); String oldValue = Optional.ofNullable(oldResutMap.get(PO.getSalaryItemId())).map(SalaryAcctResultPO::getResultValue).orElse("");
if(!StringUtils.equals(oldValue,PO.getResultValue())){ if (!StringUtils.equals(oldValue, PO.getResultValue())) {
needLockItems.add(PO.getSalaryItemId()); needLockItems.add(PO.getSalaryItemId());
} }
}); });
@ -601,7 +608,7 @@ public class SalaryAcctResultServiceImpl extends Service implements SalaryAcctRe
// 存储薪资核算结果数据来源日志 // 存储薪资核算结果数据来源日志
salaryAcctResultPOS = getSalaryAcctRecordService(user).listBySalaryAcctEmpId(saveParam.getSalaryAcctEmpId()); salaryAcctResultPOS = getSalaryAcctRecordService(user).listBySalaryAcctEmpId(saveParam.getSalaryAcctEmpId());
saveSalaryAcctResultLog(salaryAcctResultPOSOld,salaryAcctResultPOS); saveSalaryAcctResultLog(salaryAcctResultPOSOld, salaryAcctResultPOS);
// 查询操作日志的targetName // 查询操作日志的targetName
// String targetName = getSalaryAcctRecordService(user).getLogTargetNameById(salaryAcctEmployeePO.getSalaryAcctRecordId()); // String targetName = getSalaryAcctRecordService(user).getLogTargetNameById(salaryAcctEmployeePO.getSalaryAcctRecordId());
@ -623,6 +630,7 @@ public class SalaryAcctResultServiceImpl extends Service implements SalaryAcctRe
/** /**
* 存储薪资核算结果数据来源日志 * 存储薪资核算结果数据来源日志
*
* @param salaryAcctResultPOSOld * @param salaryAcctResultPOSOld
* @param salaryAcctResultPOS * @param salaryAcctResultPOS
*/ */
@ -631,11 +639,11 @@ public class SalaryAcctResultServiceImpl extends Service implements SalaryAcctRe
List<SalaryAcctResultPO> editItems = new ArrayList<>(); List<SalaryAcctResultPO> editItems = new ArrayList<>();
Map<Long, SalaryAcctResultPO> oldResutMap = SalaryEntityUtil.convert2Map(salaryAcctResultPOSOld, SalaryAcctResultPO::getSalaryItemId); Map<Long, SalaryAcctResultPO> oldResutMap = SalaryEntityUtil.convert2Map(salaryAcctResultPOSOld, SalaryAcctResultPO::getSalaryItemId);
salaryAcctResultPOS.stream().forEach(PO -> { salaryAcctResultPOS.stream().forEach(PO -> {
if(oldResutMap.get(PO.getSalaryItemId()) == null){ if (oldResutMap.get(PO.getSalaryItemId()) == null) {
editItems.add(PO); editItems.add(PO);
}else{ } else {
String oldValue = oldResutMap.get(PO.getSalaryItemId()).getResultValue(); String oldValue = oldResutMap.get(PO.getSalaryItemId()).getResultValue();
if(!StringUtils.equals(oldValue,PO.getResultValue())){ if (!StringUtils.equals(oldValue, PO.getResultValue())) {
editItems.add(PO); editItems.add(PO);
} }
} }
@ -731,14 +739,10 @@ public class SalaryAcctResultServiceImpl extends Service implements SalaryAcctRe
formulaIds.addAll(SalaryEntityUtil.properties(salarySobBackItems, SalarySobBackItemPO::getFormulaId)); formulaIds.addAll(SalaryEntityUtil.properties(salarySobBackItems, SalarySobBackItemPO::getFormulaId));
List<ExpressFormula> expressFormulas = getSalaryFormulaService(user).listExpressFormula(formulaIds); List<ExpressFormula> expressFormulas = getSalaryFormulaService(user).listExpressFormula(formulaIds);
// 本次运算的回算薪资项目所涉及的变量 // 本次运算的回算薪资项目所涉及的变量
Set<String> issuedFieldIds = new HashSet<>(); Set<String> issuedFieldIds = getIssuedFieldIds(salarySobBackItems);
// 9计算薪资项目的运算优先级 // 9计算薪资项目的运算优先级
List<List<Long>> salarySobItemsWithPriority = SalaryAcctCalculatePriorityBO.calculatePriority(salarySobItemPOS, salaryItemPOS, expressFormulas, salarySobBackItems, issuedFieldIds); // List<List<Long>> salarySobItemsWithPriority = SalaryAcctCalculatePriorityBO.calculatePriority(salarySobItemPOS, salaryItemPOS, expressFormulas, salarySobBackItems, issuedFieldIds);
// List<List<Long>> salarySobItemsWithPriority = new ArrayList<>(); List<Long> salarySobItemsWithPriority = sortItems(salarySobItemPOS, salarySobBackItems, salaryItemPOS, expressFormulas);
SalaryCalcItemGraph salaryCalcItemGraph = new SalaryCalcItemGraph(salarySobItemPOS, expressFormulas);
List<SalaryCalcItem> salaryCalcItems = salaryCalcItemGraph.sort();
List<Long> properties = SalaryEntityUtil.properties(salaryCalcItems, SalaryCalcItem::getSalaryItemId, Collectors.toList());
// salarySobItemsWithPriority.add(properties);
// 10根据id查询其他合并计税的薪资核算记录 // 10根据id查询其他合并计税的薪资核算记录
List<SalaryAcctRecordPO> otherSalaryAcctRecordPOS = getSalaryAcctRecordService(user).listById4OtherConsolidatedTax(salaryAcctRecordPO.getId()); List<SalaryAcctRecordPO> otherSalaryAcctRecordPOS = getSalaryAcctRecordService(user).listById4OtherConsolidatedTax(salaryAcctRecordPO.getId());
@ -825,8 +829,8 @@ public class SalaryAcctResultServiceImpl extends Service implements SalaryAcctRe
List<Long> salaryAcctEmployeeIds = salaryAcctEmployeePOS.stream().map(SalaryAcctEmployeePO::getId).collect(Collectors.toList()); List<Long> salaryAcctEmployeeIds = salaryAcctEmployeePOS.stream().map(SalaryAcctEmployeePO::getId).collect(Collectors.toList());
exceptItemIds.addAll(lockSalaryItemIds); exceptItemIds.addAll(lockSalaryItemIds);
exceptItemIds.addAll(salaryItemPOS.stream().filter(PO -> Objects.equals(PO.getValueType(), NumberUtils.INTEGER_ONE) && exceptItemIds.addAll(salaryItemPOS.stream().filter(PO -> Objects.equals(PO.getValueType(), NumberUtils.INTEGER_ONE) &&
Objects.equals(PO.getUseInEmployeeSalary(),0)) Objects.equals(PO.getUseInEmployeeSalary(), 0))
.map(SalaryItemPO::getId).collect(Collectors.toList()) ); .map(SalaryItemPO::getId).collect(Collectors.toList()));
getSalaryAcctResultLogService(user).deleteBySalaryAcctEmpIdExceptItemIds(salaryAcctEmployeeIds, exceptItemIds); getSalaryAcctResultLogService(user).deleteBySalaryAcctEmpIdExceptItemIds(salaryAcctEmployeeIds, exceptItemIds);
} }
}.start(); }.start();
@ -849,6 +853,46 @@ public class SalaryAcctResultServiceImpl extends Service implements SalaryAcctRe
} }
} }
@NotNull
private List<Long> sortItems(List<SalarySobItemPO> salarySobItemPOS, List<SalarySobBackItemPO> salarySobBackItems, List<SalaryItemPO> salaryItemPOS, List<ExpressFormula> expressFormulas) {
List<SalarySobItemPO> temp = salarySobBackItems.stream()
.map(e -> {
SalarySobItemPO salarySobItem = new SalarySobItemPO();
BeanUtils.copyProperties(e, salarySobItem);
return salarySobItem;
}).collect(Collectors.toList());
salarySobItemPOS.addAll(temp);
SalaryCalcItemGraph salaryCalcItemGraph = new SalaryCalcItemGraph(salarySobItemPOS, salaryItemPOS, expressFormulas);
List<SalaryCalcItem> salaryCalcItems = salaryCalcItemGraph.sort();
return SalaryEntityUtil.properties(salaryCalcItems, SalaryCalcItem::getSalaryItemId, Collectors.toList());
}
/**
* 获取回算变量
*
* @param salarySobBackItems
* @return
*/
@NotNull
private Set<String> getIssuedFieldIds(List<SalarySobBackItemPO> salarySobBackItems) {
Set<String> issuedFieldIds;
Set<Long> issuedFormulaIds = SalaryEntityUtil.properties(salarySobBackItems, SalarySobBackItemPO::getFormulaId);
List<ExpressFormula> expressFormulas1 = getSalaryFormulaService(user).listExpressFormula(issuedFormulaIds);
List<FormulaVar> issuedFormulaVars = new ArrayList<>();
expressFormulas1.forEach(f -> issuedFormulaVars.addAll(f.getParameters()));
issuedFieldIds = issuedFormulaVars.stream()
.map(FormulaVar::getFieldId)
.filter(StringUtils::isNotBlank)
.filter(v -> v.startsWith(SalaryFormulaReferenceEnum.ISSUED.getValue() + "_"))
.map(SALARY_PATTERN::matcher)
.filter(Matcher::find)
.map(m -> m.group(2))
.collect(Collectors.toSet());
return issuedFieldIds;
}
/** /**
* 处理薪资核算临时存储表中的数据 * 处理薪资核算临时存储表中的数据
* *
@ -946,9 +990,9 @@ public class SalaryAcctResultServiceImpl extends Service implements SalaryAcctRe
// } // }
Set<Long> salaryItemIds; Set<Long> salaryItemIds;
if(CollectionUtils.isNotEmpty(updateParam.getSalaryItemIds())){ if (CollectionUtils.isNotEmpty(updateParam.getSalaryItemIds())) {
salaryItemIds = updateParam.getSalaryItemIds(); salaryItemIds = updateParam.getSalaryItemIds();
}else{ } else {
salaryItemIds = Collections.singleton(updateParam.getSalaryItemId()); salaryItemIds = Collections.singleton(updateParam.getSalaryItemId());
} }
if (updateParam.getLockStatus() == LockStatusEnum.LOCK) { if (updateParam.getLockStatus() == LockStatusEnum.LOCK) {
@ -987,10 +1031,10 @@ public class SalaryAcctResultServiceImpl extends Service implements SalaryAcctRe
@Override @Override
public List<SalaryAcctResultPO> listByAcctEmployeeIdsAndSalaryItemIds(List<Long> salaryAcctEmployeeIds, Collection<Long> salaryItemIds) { public List<SalaryAcctResultPO> listByAcctEmployeeIdsAndSalaryItemIds(List<Long> salaryAcctEmployeeIds, Collection<Long> salaryItemIds) {
if(CollectionUtils.isEmpty(salaryAcctEmployeeIds)){ if (CollectionUtils.isEmpty(salaryAcctEmployeeIds)) {
return Collections.emptyList(); return Collections.emptyList();
} }
List<List<Long>> partition = Lists.partition((List<Long>)salaryAcctEmployeeIds, 200); List<List<Long>> partition = Lists.partition((List<Long>) salaryAcctEmployeeIds, 200);
List<SalaryAcctResultPO> result = new ArrayList<>(); List<SalaryAcctResultPO> result = new ArrayList<>();
partition.forEach(empIds -> { partition.forEach(empIds -> {
SalaryAcctResultPO build = SalaryAcctResultPO.builder().salaryAcctEmpIds(empIds).salaryItemIds(salaryItemIds).build(); SalaryAcctResultPO build = SalaryAcctResultPO.builder().salaryAcctEmpIds(empIds).salaryItemIds(salaryItemIds).build();
@ -1013,10 +1057,10 @@ public class SalaryAcctResultServiceImpl extends Service implements SalaryAcctRe
@Override @Override
public List<Long> listAcctEmpIdByAcctEmpId(List<Long> salaryAcctEmployeeIds) { public List<Long> listAcctEmpIdByAcctEmpId(List<Long> salaryAcctEmployeeIds) {
if(CollectionUtils.isEmpty(salaryAcctEmployeeIds)){ if (CollectionUtils.isEmpty(salaryAcctEmployeeIds)) {
return Collections.emptyList(); return Collections.emptyList();
} }
List<List<Long>> partition = Lists.partition((List<Long>)salaryAcctEmployeeIds, 1000); List<List<Long>> partition = Lists.partition((List<Long>) salaryAcctEmployeeIds, 1000);
List<Long> result = new ArrayList<>(); List<Long> result = new ArrayList<>();
partition.forEach(empIds -> { partition.forEach(empIds -> {
result.addAll(getSalaryAcctResultMapper().getAcctEmpIsExist(empIds)); result.addAll(getSalaryAcctResultMapper().getAcctEmpIsExist(empIds));
@ -1053,15 +1097,15 @@ public class SalaryAcctResultServiceImpl extends Service implements SalaryAcctRe
public Boolean checkAuth(Long salaryAcctRecordId) { public Boolean checkAuth(Long salaryAcctRecordId) {
// 获取该核算记录的个税扣缴义务 // 获取该核算记录的个税扣缴义务
SalaryAcctRecordPO recordPO = getSalaryAcctRecordService(user).getById(salaryAcctRecordId); SalaryAcctRecordPO recordPO = getSalaryAcctRecordService(user).getById(salaryAcctRecordId);
if(Objects.isNull(recordPO)) { if (Objects.isNull(recordPO)) {
return false; return false;
} }
SalarySobPO salarySobPO = getSalarySobService(user).getById(recordPO.getSalarySobId()); SalarySobPO salarySobPO = getSalarySobService(user).getById(recordPO.getSalarySobId());
Long taxAgentId = salarySobPO.getTaxAgentId(); Long taxAgentId = salarySobPO.getTaxAgentId();
List<TaxAgentAdminPO> adminTaxAgentList = getTaxAgentAdminService(user).listByEmployeeId(Long.valueOf(user.getUID())); List<TaxAgentAdminPO> adminTaxAgentList = getTaxAgentAdminService(user).listByEmployeeId(Long.valueOf(user.getUID()));
Optional<TaxAgentAdminPO> canOperate = adminTaxAgentList.stream().filter(po -> NumberUtils.compare(taxAgentId, po.getTaxAgentId()) == 0).findFirst(); Optional<TaxAgentAdminPO> canOperate = adminTaxAgentList.stream().filter(po -> NumberUtils.compare(taxAgentId, po.getTaxAgentId()) == 0).findFirst();
if(!canOperate.isPresent()){ if (!canOperate.isPresent()) {
return false; return false;
} }
return true; return true;
} }

View File

@ -32,7 +32,7 @@ import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
* 个税申报表 * 个税申报表
* <p>Copyright: Copyright (c) 2023</p> * <p>Copyright: Copyright (c) 2023</p>
* <p>Company: 泛微软件</p> * <p>Company: 泛微软件</p>
* *
@ -92,7 +92,7 @@ public class TaxDeclarationValueServiceImpl extends Service implements TaxDeclar
List<EmployeeDeclarePO> employeeDeclares = getEmployeeDeclareService(user).listByTaxCycleAndTaxAgentIdAndEmployeeIds(taxDeclaration.getTaxCycle(), taxDeclaration.getTaxAgentId(), employeeIds); List<EmployeeDeclarePO> employeeDeclares = getEmployeeDeclareService(user).listByTaxCycleAndTaxAgentIdAndEmployeeIds(taxDeclaration.getTaxCycle(), taxDeclaration.getTaxAgentId(), employeeIds);
// 查询人员信息 // 查询人员信息
List<Long> simpleEmployeeIds = taxDeclarationValues.stream() List<Long> simpleEmployeeIds = taxDeclarationValues.stream()
.filter(taxDeclarationValue -> Objects.equals(taxDeclarationValue.getEmployeeType(), EmployeeTypeEnum.ORGANIZATION.getValue())) .filter(taxDeclarationValue -> taxDeclarationValue.getEmployeeType() == null || Objects.equals(taxDeclarationValue.getEmployeeType(), EmployeeTypeEnum.ORGANIZATION.getValue()))
.map(TaxDeclarationValuePO::getEmployeeId) .map(TaxDeclarationValuePO::getEmployeeId)
.distinct() .distinct()
.collect(Collectors.toList()); .collect(Collectors.toList());

View File

@ -368,6 +368,9 @@ public class TaxDeclareRecordServiceImpl extends Service implements TaxDeclareRe
getAddUpSituationService(user).batchSave(entry.getValue()); getAddUpSituationService(user).batchSave(entry.getValue());
} }
} }
//更新核算记录状态
getSalaryAcctRecordService(user).updateStatusByIds(salaryAcctRecordIds, SalaryAcctRecordStatusEnum.DECLARED);
} }
private TaxDeclarationResult generateReportPerRecord(TaxDeclareRecordPO taxDeclareRecord, List<SalaryAcctEmployeePO> salaryAcctEmployees) { private TaxDeclarationResult generateReportPerRecord(TaxDeclareRecordPO taxDeclareRecord, List<SalaryAcctEmployeePO> salaryAcctEmployees) {