公式更换jar
This commit is contained in:
parent
50d502632f
commit
bbcb5916ce
Binary file not shown.
|
|
@ -1,5 +1,7 @@
|
|||
package com.engine.salary.constant;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* 薪酬管理公式编辑器的常量
|
||||
* <p>Copyright: Copyright (c) 2022</p>
|
||||
|
|
@ -15,4 +17,14 @@ public class SalaryFormulaFieldConstant {
|
|||
|
||||
// 公式中变量的fieldId的分隔符
|
||||
public static final String FIELD_ID_SEPARATOR = "_";
|
||||
|
||||
/**
|
||||
* 公式中变量的fieldId的正则表达式
|
||||
*/
|
||||
public static final String SALARY_REGEX = "(\\w+)" + SalaryFormulaFieldConstant.FIELD_ID_SEPARATOR + "(\\w+)";
|
||||
|
||||
/**
|
||||
* 解析公式中变量的fieldId的正则表达式
|
||||
*/
|
||||
public static final Pattern SALARY_PATTERN = Pattern.compile(SALARY_REGEX);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,6 +48,12 @@ public class ExpressFormula {
|
|||
* 公式内容
|
||||
*/
|
||||
private String formula;
|
||||
|
||||
/**
|
||||
* 公式实际运行脚本
|
||||
*/
|
||||
private String formulaRunScript;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ public class SalaryFormulaSaveParam {
|
|||
/**
|
||||
* 名称
|
||||
*/
|
||||
@DataCheck(require = true,message = "名称为空")
|
||||
private String name;
|
||||
/**
|
||||
* 备注
|
||||
|
|
@ -31,6 +32,7 @@ public class SalaryFormulaSaveParam {
|
|||
/**
|
||||
* 模块
|
||||
*/
|
||||
@DataCheck(require = true,message = "模块为空")
|
||||
private String module;
|
||||
/**
|
||||
* 用途
|
||||
|
|
@ -43,10 +45,12 @@ public class SalaryFormulaSaveParam {
|
|||
/**
|
||||
* 返回类型
|
||||
*/
|
||||
@DataCheck(require = true,message = "返回类型为空")
|
||||
private String returnType;
|
||||
/**
|
||||
* 校验类型
|
||||
*/
|
||||
@DataCheck(require = true,message = "校验类型为空")
|
||||
private String validateType;
|
||||
/**
|
||||
* 扩展参数
|
||||
|
|
@ -55,6 +59,7 @@ public class SalaryFormulaSaveParam {
|
|||
/**
|
||||
* 公式内容
|
||||
*/
|
||||
@DataCheck(require = true,message = "公式内容为空")
|
||||
private String formula;
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -53,6 +53,12 @@ public class FormulaPO {
|
|||
* 公式内容
|
||||
*/
|
||||
private String formula;
|
||||
|
||||
/**
|
||||
* 公式实际运行脚本
|
||||
*/
|
||||
private String formulaRunScript;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ public class SalarySobItemSaveParam {
|
|||
//"薪资账套薪资项目保存参数-员工基本信息字段")
|
||||
public static class SalarySobEmpFieldParam {
|
||||
|
||||
//主键id")
|
||||
//主键id
|
||||
private Long id;
|
||||
|
||||
//员工基本信息字段")
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@
|
|||
<result column="validate_type" property="validateType"/>
|
||||
<result column="extend_param" property="extendParam"/>
|
||||
<result column="formula" property="formula"/>
|
||||
<result column="formulaRunScript" property="formulaRunScript"/>
|
||||
<result column="creator" property="creator"/>
|
||||
<result column="delete_type" property="deleteType"/>
|
||||
<result column="create_time" property="createTime"/>
|
||||
|
|
@ -32,6 +33,7 @@
|
|||
, t.validate_type
|
||||
, t.extend_param
|
||||
, t.formula
|
||||
, t.formulaRunScript
|
||||
, t.creator
|
||||
, t.delete_type
|
||||
, t.create_time
|
||||
|
|
|
|||
|
|
@ -5,33 +5,29 @@ import com.engine.salary.entity.datacollection.DataCollectionEmployee;
|
|||
import com.engine.salary.entity.salaryformula.ExpressFormula;
|
||||
import com.engine.salary.entity.salaryformula.po.FormulaVar;
|
||||
import com.engine.salary.service.FormulaRunService;
|
||||
import org.apache.commons.jexl3.*;
|
||||
import com.ql.util.express.DefaultContext;
|
||||
import com.ql.util.express.ExpressRunner;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
public class FormulaRunServiceImpl extends Service implements FormulaRunService {
|
||||
@Override
|
||||
public Object run(ExpressFormula expressFormula, List<FormulaVar> formulaVars, DataCollectionEmployee simpleEmployee) {
|
||||
|
||||
/*
|
||||
公式内容以如下显示方式存储
|
||||
{薪资项目.输入项1}+{薪资项目.输入项2}
|
||||
*/
|
||||
String formula = expressFormula.getFormula();
|
||||
|
||||
|
||||
JexlBuilder jexlBuilder = new JexlBuilder();
|
||||
// 创建Jexl表达式引擎
|
||||
JexlEngine jexlEngine = jexlBuilder.create();
|
||||
// 创建Jexl表达式解析器
|
||||
JexlScript jexlScript = jexlEngine.createScript(formula);
|
||||
// 创建Jexl表达式变量上下文
|
||||
JexlContext jexlContext = new MapContext();
|
||||
ExpressRunner runner = new ExpressRunner(true, false);
|
||||
DefaultContext<String, Object> context = new DefaultContext<String, Object>();
|
||||
formulaVars.forEach(v -> {
|
||||
jexlContext.set(v.getFieldId(), v.getContent());
|
||||
context.put(v.getFieldId(), v.getContent());
|
||||
});
|
||||
// 执行Jexl表达式,得到结果
|
||||
Object execute = jexlScript.execute(jexlContext);
|
||||
Object execute = null;
|
||||
try {
|
||||
execute = runner.execute(formula, context, null, true, false);
|
||||
} catch (Exception e) {
|
||||
log.error("公式执行异常", e);
|
||||
}
|
||||
return execute;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package com.engine.salary.service.impl;
|
||||
|
||||
import com.engine.core.impl.Service;
|
||||
import com.engine.salary.constant.SalaryFormulaFieldConstant;
|
||||
import com.engine.salary.entity.salaryformula.ExpressFormula;
|
||||
import com.engine.salary.entity.salaryformula.param.SalaryFormulaSaveParam;
|
||||
import com.engine.salary.entity.salaryformula.po.FormulaPO;
|
||||
|
|
@ -19,6 +20,8 @@ import org.apache.commons.lang3.math.NumberUtils;
|
|||
import org.springframework.beans.BeanUtils;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
|
|
@ -90,11 +93,19 @@ public class SalaryFormulaServiceImpl extends Service implements SalaryFormulaSe
|
|||
|
||||
@Override
|
||||
public FormulaPO save(SalaryFormulaSaveParam param) {
|
||||
ValidUtil.doValidator(param);
|
||||
|
||||
//公式参数与公式内容是否相符
|
||||
String paramFormula = param.getFormula();
|
||||
Pattern salaryPattern = SalaryFormulaFieldConstant.SALARY_PATTERN;
|
||||
Matcher matcher = salaryPattern.matcher(paramFormula);
|
||||
int end = matcher.end();
|
||||
if(!Objects.equals(end,param.getParameters())){
|
||||
throw new SalaryRunTimeException("参数不匹配");
|
||||
}
|
||||
|
||||
FormulaPO formulaPO = new FormulaPO();
|
||||
|
||||
String formula = param.getFormula();
|
||||
|
||||
formulaPO.setName(param.getName());
|
||||
formulaPO.setDescription(param.getDescription());
|
||||
formulaPO.setModule(param.getModule());
|
||||
|
|
@ -110,23 +121,28 @@ public class SalaryFormulaServiceImpl extends Service implements SalaryFormulaSe
|
|||
formulaPO.setCreateTime(now);
|
||||
formulaPO.setUpdateTime(now);
|
||||
formulaPO.setCreator((long) user.getUID());
|
||||
|
||||
/*
|
||||
公式内容以如下显示方式存储
|
||||
{薪资项目.输入项1}+{薪资项目.输入项2}
|
||||
转换为实际的运行脚本
|
||||
*/
|
||||
String formulaRunScript = formula;
|
||||
List<FormulaVar> parameters = param.getParameters();
|
||||
for (FormulaVar po : parameters) {
|
||||
formulaRunScript = formulaRunScript.replace(po.getFieldName(), po.getFieldId());
|
||||
}
|
||||
formulaPO.setFormulaRunScript(formulaRunScript);
|
||||
getFormulaMapper().insertIgnoreNull(formulaPO);
|
||||
|
||||
List<FormulaVar> parameters = param.getParameters();
|
||||
parameters.forEach(po -> {
|
||||
|
||||
formula.replace(po.getFieldName(), po.getFieldId());
|
||||
|
||||
|
||||
for (FormulaVar po : parameters) {
|
||||
po.setFormulaId(formulaPO.getId());
|
||||
po.setDeleteType(NumberUtils.INTEGER_ZERO);
|
||||
po.setCreator((long) user.getUID());
|
||||
po.setCreateTime(now);
|
||||
po.setUpdateTime(now);
|
||||
getFormulaVarMapper().insertIgnoreNull(po);
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
return formulaPO;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ import com.engine.salary.exception.SalaryRunTimeException;
|
|||
import com.engine.salary.service.*;
|
||||
import com.engine.salary.util.SalaryEntityUtil;
|
||||
import com.engine.salary.util.SalaryI18nUtil;
|
||||
import com.engine.salary.util.valid.ValidUtil;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.math.NumberUtils;
|
||||
|
|
@ -49,7 +50,9 @@ public class SalarySobItemServiceImpl extends Service implements SalarySobItemSe
|
|||
return (SalarySobItemGroupService) ServiceUtil.getService(SalarySobItemGroupServiceImpl.class, user);
|
||||
}
|
||||
|
||||
private SalaryFormulaService salaryFormulaService;
|
||||
private SalaryFormulaService getSalaryFormulaService(User user) {
|
||||
return (SalaryFormulaService) ServiceUtil.getService(SalaryFormulaServiceImpl.class, user);
|
||||
}
|
||||
|
||||
private SalaryItemService getSalaryItemService(User user) {
|
||||
return (SalaryItemService) ServiceUtil.getService(SalaryItemServiceImpl.class, user);
|
||||
|
|
@ -111,9 +114,8 @@ public class SalarySobItemServiceImpl extends Service implements SalarySobItemSe
|
|||
List<SalarySobItemPO> salarySobItemPOS = listBySalarySobId(salarySobId);
|
||||
// 薪资账套的薪资项目副本所用的公式id
|
||||
Set<Long> formulaIds = SalaryEntityUtil.properties(salarySobItemPOS, SalarySobItemPO::getFormulaId);
|
||||
// 查询公式详情 todo
|
||||
// List<ExpressFormula> expressFormulas = salaryFormulaService.listExpressFormula(formulaIds);
|
||||
List<ExpressFormula> expressFormulas = new ArrayList<>();
|
||||
// 查询公式详情
|
||||
List<ExpressFormula> expressFormulas = getSalaryFormulaService(user).listExpressFormula(formulaIds);
|
||||
// 查询薪资账套的薪资项目副本所关联的薪资项目
|
||||
Set<Long> salaryItemIds = SalaryEntityUtil.properties(salarySobItemPOS, SalarySobItemPO::getSalaryItemId);
|
||||
List<SalaryItemPO> salaryItemPOS = getSalaryItemService(user).listByIds(salaryItemIds);
|
||||
|
|
@ -129,7 +131,7 @@ public class SalarySobItemServiceImpl extends Service implements SalarySobItemSe
|
|||
Long salarySobId = saveParam.getSalarySobId();
|
||||
|
||||
// 校验
|
||||
validSaveParam(salarySobId);
|
||||
validSaveParam(saveParam);
|
||||
|
||||
//fixme 事务
|
||||
|
||||
|
|
@ -151,10 +153,13 @@ public class SalarySobItemServiceImpl extends Service implements SalarySobItemSe
|
|||
|
||||
/**
|
||||
* 校验
|
||||
* @param salarySobId
|
||||
*/
|
||||
private void validSaveParam(Long salarySobId) {
|
||||
private void validSaveParam(SalarySobItemSaveParam saveParam) {
|
||||
|
||||
ValidUtil.doValidator(saveParam);
|
||||
|
||||
//1、账套存在
|
||||
Long salarySobId = saveParam.getSalarySobId();
|
||||
SalarySobPO salarySobPO = salarySobBiz.getById(salarySobId);
|
||||
if (Objects.isNull(salarySobPO)) {
|
||||
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98379, "参数错误,薪资账套不存在或者已被删除"));
|
||||
|
|
@ -168,7 +173,6 @@ public class SalarySobItemServiceImpl extends Service implements SalarySobItemSe
|
|||
* @param salarySobId
|
||||
*/
|
||||
private void cleanOldData(Long salarySobId) {
|
||||
//todo
|
||||
// 删除薪资账套的员工信息字段
|
||||
getSalarySobEmpFieldService(user).deleteBySalarySobIds(Collections.singleton(salarySobId));
|
||||
// 删除薪资账套的薪资项目副本
|
||||
|
|
|
|||
Loading…
Reference in New Issue