parent
1e0d464534
commit
8edffdb2dc
4 changed files with 70 additions and 5 deletions
@ -0,0 +1,42 @@ |
|||||||
|
package org.springblade.lims.utils; |
||||||
|
|
||||||
|
import com.ql.util.express.DefaultContext; |
||||||
|
import com.ql.util.express.ExpressRunner; |
||||||
|
|
||||||
|
import java.util.Arrays; |
||||||
|
import java.util.List; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
/** |
||||||
|
* 数学公式相关方法 |
||||||
|
* @author ytl |
||||||
|
* @since 2022-09-14 17:01 |
||||||
|
*/ |
||||||
|
public class FormulaTool { |
||||||
|
private static ExpressRunner runner; |
||||||
|
|
||||||
|
static{ |
||||||
|
runner = new ExpressRunner(true,false); |
||||||
|
} |
||||||
|
|
||||||
|
//返回公式中参数的列表
|
||||||
|
public static List<String> paraList(String regx) throws Exception{ |
||||||
|
String[] paras = runner.getOutVarNames(regx); |
||||||
|
List<String> strings = Arrays.asList(paras); |
||||||
|
return strings; |
||||||
|
} |
||||||
|
|
||||||
|
//返回公式的计算结果
|
||||||
|
public static String getResult(String regx, Map<String,Object> params) throws Exception{ |
||||||
|
DefaultContext<String, Object> context = new DefaultContext<>(); |
||||||
|
//给参数赋值
|
||||||
|
params.forEach((k,v)->{ |
||||||
|
context.put(k,Double.valueOf(v.toString())); |
||||||
|
}); |
||||||
|
|
||||||
|
//计算
|
||||||
|
Object result = runner.execute(regx, context, null, true, false); |
||||||
|
|
||||||
|
return result.toString(); |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue