132 lines
5.7 KiB
Java
132 lines
5.7 KiB
Java
//package com.engine.salary.entity.salaryacct.bo;
|
||
//
|
||
//import com.alibaba.fastjson.JSON;
|
||
//import com.alibaba.fastjson.JSONArray;
|
||
//import com.alibaba.fastjson.JSONObject;
|
||
//import com.weaver.excel.formula.api.entity.ExpressFormula;
|
||
//import com.weaver.excel.formula.api.entity.FormulaVar;
|
||
//import com.weaver.hrm.salary.constant.SalaryFormulaFieldConstant;
|
||
//import com.weaver.hrm.salary.entity.salaryacct.po.SalaryAcctResultPO;
|
||
//import com.weaver.hrm.salary.entity.salaryitem.po.SalaryItemPO;
|
||
//import com.weaver.hrm.salary.enums.SalaryFormulaReferenceEnum;
|
||
//import com.weaver.hrm.salary.util.SalaryEntityUtil;
|
||
//import org.apache.commons.collections4.CollectionUtils;
|
||
//import org.apache.commons.lang3.StringUtils;
|
||
//import org.apache.curator.shaded.com.google.common.collect.Maps;
|
||
//
|
||
//import java.math.BigDecimal;
|
||
//import java.util.Collections;
|
||
//import java.util.List;
|
||
//import java.util.Map;
|
||
//import java.util.Objects;
|
||
//import java.util.regex.Matcher;
|
||
//import java.util.regex.Pattern;
|
||
//
|
||
///**
|
||
// * @description: 薪资核算公式
|
||
// * @author: xiajun
|
||
// * @modified By: xiajun
|
||
// * @date: Created in 6/2/22 10:33 PM
|
||
// * @version:v1.0
|
||
// */
|
||
//public class ExpressFormulaBO {
|
||
//
|
||
// /**
|
||
// * 公式中变量的fieldId的正则表达式
|
||
// */
|
||
// private static final String SALARY_REGEX = "(\\w+)" + SalaryFormulaFieldConstant.FIELD_ID_SEPARATOR + "(\\w+)";
|
||
//
|
||
// /**
|
||
// * 解析公式中变量的fieldId的正则表达式
|
||
// */
|
||
// private static final Pattern SALARY_PATTERN = Pattern.compile(SALARY_REGEX);
|
||
//
|
||
// /**
|
||
// * 解析公式中的变量
|
||
// *
|
||
// * @param expressFormulas 公式详情
|
||
// * @return
|
||
// */
|
||
// public static Map<Long, List<FormulaVar>> buildFormulaVar(List<ExpressFormula> expressFormulas) {
|
||
// if (CollectionUtils.isEmpty(expressFormulas)) {
|
||
// return Collections.emptyMap();
|
||
// }
|
||
// Map<Long, List<FormulaVar>> resultMap = Maps.newHashMapWithExpectedSize(expressFormulas.size());
|
||
// for (ExpressFormula expressFormula : expressFormulas) {
|
||
// if (StringUtils.isEmpty(expressFormula.getParameter())) {
|
||
// continue;
|
||
// }
|
||
// JSONObject paramJson = JSON.parseObject(expressFormula.getParameter());
|
||
// if (paramJson != null) {
|
||
// JSONArray paramArray = paramJson.getJSONArray("formulavars");
|
||
// if (paramArray != null) {
|
||
// List<FormulaVar> formulaVars = paramArray.toJavaList(FormulaVar.class);
|
||
// resultMap.put(expressFormula.getId(), formulaVars);
|
||
// }
|
||
// }
|
||
// }
|
||
// return resultMap;
|
||
// }
|
||
//
|
||
// /**
|
||
// * 给公式中的变量填入值
|
||
// *
|
||
// * @param expressFormulas
|
||
// * @param salaryItems
|
||
// * @param acctResults
|
||
// * @return
|
||
// */
|
||
// public static Map<Long, List<FormulaVar>> buildFormulaVar4Check(List<ExpressFormula> expressFormulas, List<SalaryItemPO> salaryItems, List<SalaryAcctResultPO> acctResults) {
|
||
// if (CollectionUtils.isEmpty(expressFormulas)) {
|
||
// return Collections.emptyMap();
|
||
// }
|
||
// Map<Long, String> salaryItemCodeMap = SalaryEntityUtil.convert2Map(salaryItems, SalaryItemPO::getId, SalaryItemPO::getCode);
|
||
// Map<String, String> acctResultMap = SalaryEntityUtil.convert2Map(acctResults, e -> salaryItemCodeMap.getOrDefault(e.getSalaryItemId(), ""), SalaryAcctResultPO::getResultValue);
|
||
// Map<Long, List<FormulaVar>> formulaVarMap = buildFormulaVar(expressFormulas);
|
||
// formulaVarMap.forEach((k, v) -> {
|
||
// for (FormulaVar formulaVar : v) {
|
||
// Matcher matcher = SALARY_PATTERN.matcher(formulaVar.getFieldId());
|
||
// if (matcher.find()) {
|
||
// SalaryFormulaReferenceEnum referenceEnum = SalaryFormulaReferenceEnum.parseByValue(matcher.group(1));
|
||
// if (referenceEnum == SalaryFormulaReferenceEnum.SALARY_ITEM) {
|
||
// formulaVar.setContent(acctResultMap.getOrDefault(matcher.group(2), ""));
|
||
// }
|
||
// }
|
||
// }
|
||
// });
|
||
// return formulaVarMap;
|
||
// }
|
||
//
|
||
// /**
|
||
// * 给公式中的变量填入值
|
||
// *
|
||
// * @param expressFormula 公式
|
||
// * @param formulaVarValueMap 公式变量的值
|
||
// * @return
|
||
// */
|
||
// public static List<FormulaVar> buildFormulaVar4Accounting(ExpressFormula expressFormula, Map<String, String> formulaVarValueMap) {
|
||
// List<FormulaVar> formulaVars = Collections.emptyList();
|
||
// // 公式异常
|
||
// if (Objects.isNull(expressFormula) || StringUtils.isEmpty(expressFormula.getParameter())) {
|
||
// return Collections.emptyList();
|
||
// }
|
||
// JSONObject paramJson = JSON.parseObject(expressFormula.getParameter());
|
||
// if (paramJson != null) {
|
||
// JSONArray paramArray = paramJson.getJSONArray("formulavars");
|
||
// if (paramArray != null) {
|
||
// formulaVars = paramArray.toJavaList(FormulaVar.class);
|
||
// for (FormulaVar formulaVar : formulaVars) {
|
||
// // 公式变量的值
|
||
// String formulaVarValue = formulaVarValueMap.getOrDefault(formulaVar.getFieldId(), StringUtils.EMPTY);
|
||
// // 如果公式的返回值类型为number,公式中的变量的值如果为空,公式运行的时候会报错,所以需要替换成0
|
||
// if (StringUtils.isEmpty(formulaVarValue) && "number".equals(expressFormula.getReturnType())) {
|
||
// formulaVarValue = BigDecimal.ZERO.toPlainString();
|
||
// }
|
||
// formulaVar.setContent(formulaVarValue);
|
||
// }
|
||
// }
|
||
// }
|
||
// return formulaVars;
|
||
// }
|
||
//}
|