Commit d2d857a9 authored by maoying's avatar maoying

添加指标偏移量

parent e6e32733
...@@ -213,4 +213,8 @@ public class EquipmentSpecificIndex extends BaseEntity { ...@@ -213,4 +213,8 @@ public class EquipmentSpecificIndex extends BaseEntity {
@ApiModelProperty(value = "是否遥测") @ApiModelProperty(value = "是否遥测")
@TableField(value = "is_trend") @TableField(value = "is_trend")
private Boolean isTrend; private Boolean isTrend;
@ApiModelProperty(value = "计算公式")
@TableField(value = "formula")
private String formula ;
} }
package com.yeejoin.equipmanage.utils;
import java.math.BigDecimal;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import javax.script.Compilable;
import javax.script.CompiledScript;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import javax.script.SimpleBindings;
public class FormulaCalculator {
private static final ScriptEngine engine =
new ScriptEngineManager().getEngineByName("js");
private static final Map<String, CompiledScript> compiledCache =
new ConcurrentHashMap<>();
public static synchronized Object calculate(String formula,
Map<String, Object> variables) throws ScriptException {
try {
// 类型安全转换
variables.replaceAll((k, v) ->
v instanceof String ? new BigDecimal((String)v) : v);
CompiledScript script = compiledCache.computeIfAbsent(
formula, f -> {
try {
return ((Compilable)engine).compile(f);
} catch (ScriptException e) {
e.printStackTrace();
// TODO Auto-generated catch block
throw new IllegalArgumentException("输入值格式错误");
}
}
);
return script.eval(new SimpleBindings(variables));
} catch (ClassCastException e) {
throw new IllegalArgumentException("输入值格式错误");
}
}
}
...@@ -1231,4 +1231,18 @@ ...@@ -1231,4 +1231,18 @@
alter table `f_equipment` add column `drain_duration` double DEFAULT NULL COMMENT '排空时长(分钟)'; alter table `f_equipment` add column `drain_duration` double DEFAULT NULL COMMENT '排空时长(分钟)';
</sql> </sql>
</changeSet> </changeSet>
<changeSet author="my" id="17491871450000">
<preConditions onFail="MARK_RAN">
<not>
<columnExists tableName="wl_equipment_specific_index" columnName="formula"/>
</not>
</preConditions>
<comment>wl_equipment_specific_index add column formula</comment>
<sql>
ALTER TABLE `wl_equipment_specific_index`
ADD COLUMN `formula` varchar(255) NULL DEFAULT '' COMMENT '计算公式';
</sql>
</changeSet>
</databaseChangeLog> </databaseChangeLog>
\ No newline at end of file
...@@ -68,7 +68,8 @@ ...@@ -68,7 +68,8 @@
sd.warehouse_structure_id AS buildId, sd.warehouse_structure_id AS buildId,
wes.biz_org_name AS bizOrgName, wes.biz_org_name AS bizOrgName,
wes.biz_org_code AS bizOrgCode, wes.biz_org_code AS bizOrgCode,
wesi.alarm_rule AS alarmRule wesi.alarm_rule AS alarmRule,
wesi.formula
FROM FROM
wl_equipment_specific_index AS wesi wl_equipment_specific_index AS wesi
LEFT JOIN wl_equipment_specific AS wes LEFT JOIN wl_equipment_specific AS wes
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment