健康度指标DP修改

yun-zuoyi
link 3 years ago
parent 924339025e
commit 741193be82

@ -66,7 +66,8 @@ public class WmsHealthIndicator extends BaseBean {
@DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.TEXT)
private String indicatorColor;
@Transient
// @Transient
@Column(name = "INDICATOR_VALUE")
@ApiParam(value = "指标测算值")
@DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.NUMBER)
private Double indicatorCalcValue;

@ -107,4 +107,10 @@ public class WmsHealthVariable extends BaseBean {
@ApiParam(value = "测算方式")
@DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.TEXT)
private String calcWays;
@Column(name = "VARIABLE_VALUE")
@ApiParam(value = "上次计算的值")
@DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.TEXT)
private Double varibleValue;
}

@ -49,7 +49,7 @@ public class WmsHealthVariableResult extends BaseBean {
@Column(name = "VARIABLE_VALUE")
@ApiParam(value = "变量测算值")
@DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.NUMBER)
private Integer variableValue;
private Double variableValue;
@Lob
@Column(name = "VARIABLE_DETAILS")

@ -26,4 +26,11 @@ public interface IWmsHealthIndexCron {
*
*/
Date getNextDate();
/**
*
* CRON5300000
*/
public long getDifference();
}

@ -1,5 +1,7 @@
package cn.estsh.i3plus.pojo.wms.bean.health;
import lombok.Getter;
/**
*
* @author link
@ -18,9 +20,20 @@ public enum WmsHealthIndexCalcWay {
*/
SCRIPT("30");
@Getter
private String value;
private WmsHealthIndexCalcWay(String value){
this.value = value;
}
public static WmsHealthIndexCalcWay value(String value) {
WmsHealthIndexCalcWay[] values = WmsHealthIndexCalcWay.values();
for(WmsHealthIndexCalcWay target:values) {
if(target.getValue().equals(value)) {
return target;
}
}
return null;
}
}

@ -1,13 +1,7 @@
package cn.estsh.i3plus.pojo.wms.bean.health;
import cn.estsh.i3plus.pojo.wms.bean.WmsHealthVariableResult;
import lombok.Getter;
import lombok.Setter;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.expression.spel.support.StandardEvaluationContext;
import java.util.Set;
/**
*
@ -36,12 +30,15 @@ public class WmsHealthIndexEntity {
*/
private WmsHealthIndexValue value;
/**
*
* ()
*/
private Boolean refresh;
public WmsHealthIndexEntity(final WmsHealthIndexId id,
final WmsHealthIndexFormula formula){
if(null==id){
throw new IllegalArgumentException("WmsHealthIndexId can't be null");
}
this.id = id;
this.formula = formula;
};
@ -50,7 +47,7 @@ public class WmsHealthIndexEntity {
final String indicatorCode,
final String calcFormula){
return new WmsHealthIndexEntity(WmsHealthIndexId.of(organizeCode,indicatorCode),
WmsHealthIndexFormula.of(organizeCode,indicatorCode));
WmsHealthIndexFormula.of(organizeCode,calcFormula));
}
@ -67,13 +64,17 @@ public class WmsHealthIndexEntity {
}
}
public boolean hashValue(){
return null != this.value;
}
private WmsHealthIndexValue generateWmsHealthIndexValue(){
if(!formula.isEmpty()){
if(!formula.isResultEmpty()){
String result = null;
int size = formula.getResults().size();
if(size==1){
WmsHealthIndexVariableValue varValue = formula.getSingleValue();
if(null!=varValue)
result = String.valueOf(varValue.getDetail());
}else{
result = String.valueOf(formula.getSpelResult());

@ -9,6 +9,7 @@ import java.util.*;
/**
*
* (#VAR202201070002/#VAR456)/(#VAR123/#VAR456)*100
*/
@Getter
public class WmsHealthIndexFormula {
@ -17,7 +18,7 @@ public class WmsHealthIndexFormula {
*/
private final String organizeCode;
/**
* (#VAR202201070002/#VAR456)/(#VAR123/#VAR456)*100%
* (#VAR202201070002/#VAR456)/(#VAR123/#VAR456) * 100
*/
private final String calcFormula;
/**
@ -32,6 +33,12 @@ public class WmsHealthIndexFormula {
public WmsHealthIndexFormula(final String organizeCode,final String calcFormula){
if(null==organizeCode){
throw new IllegalArgumentException("organizeCode can't be null");
}
if(null==calcFormula){
throw new IllegalArgumentException("calcFormula can't be null");
}
this.calcFormula = calcFormula;
this.organizeCode = organizeCode;
checkCode();
@ -62,12 +69,15 @@ public class WmsHealthIndexFormula {
}
public void addResult(WmsHealthIndexVariable key, WmsHealthIndexVariableValue result){
if(null!=result) {
this.results.put(key, result);
if(null!=result && null!=key) {
if(key.isRefresh()) {
key.changeValue(result);
}
results.put(key, result);
}
}
public boolean isEmpty(){
public boolean isResultEmpty(){
return results.isEmpty();
}
@ -83,7 +93,7 @@ public class WmsHealthIndexFormula {
*
*/
public WmsHealthIndexVariableValue getSingleValue(){
if(!isEmpty()) {
if(!isResultEmpty()) {
WmsHealthIndexVariableValue variableValue = com.google.common.collect.Lists
.newArrayList(results.values()).get(0);
return variableValue;
@ -95,11 +105,11 @@ public class WmsHealthIndexFormula {
* calcFormulaSPEL
* @return
*/
public Integer getSpelResult(){
public Double getSpelResult(){
if(results.isEmpty()) {
return -1;
return -1.0;
}
Integer calcResult = 0;
Double calcResult = 0.0;
int resultSize = results.size();
StandardEvaluationContext ctx = new StandardEvaluationContext();
ExpressionParser parser = new SpelExpressionParser();
@ -111,15 +121,15 @@ public class WmsHealthIndexFormula {
for (WmsHealthIndexVariable varKey : varKeys) {
// 取出该变量名称对应的计算结果
WmsHealthIndexVariableValue variableValue = results.get(varKey);
Integer value = variableValue.getValue();
Double value = variableValue.getValue();
ctx.setVariable(varKey.getId().getVariable(), value);
}
// 存在多个变量则按照SPEL进行运算最后取值
try {
calcResult = (Integer) parser.parseExpression(calcFormula)
calcResult = (Double) parser.parseExpression(calcFormula)
.getValue(ctx);
} catch (Exception e) {
calcResult = -1;
calcResult = -1.0;
}
}
return calcResult;

@ -1,6 +1,7 @@
package cn.estsh.i3plus.pojo.wms.bean.health;
import lombok.Getter;
import lombok.Setter;
/**
*
@ -16,6 +17,11 @@ public class WmsHealthIndexId{
*
*/
private final String indicatorCode;
/**
* ID(OPTION)
*/
@Setter
private Long pk;
public WmsHealthIndexId(final String organizeCode,final String indicatorCode){
if(null==indicatorCode){
@ -25,7 +31,7 @@ public class WmsHealthIndexId{
throw new IllegalArgumentException("organizeCode can't be null");
}
this.indicatorCode = indicatorCode;
this.organizeCode = indicatorCode;
this.organizeCode = organizeCode;
}
public static WmsHealthIndexId of(String organizeCode,String indicatorCode){

@ -13,6 +13,9 @@ public class WmsHealthIndexValue{
*
*/
private final String result;
/**
*
*/
@Setter
private Long time;

@ -2,6 +2,11 @@ package cn.estsh.i3plus.pojo.wms.bean.health;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.time.DateUtils;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.util.Date;
/**
@ -9,23 +14,20 @@ import lombok.Setter;
*/
@Getter
public class WmsHealthIndexVariable {
/**
*
*/
private final WmsHealthIndexVariableId id;
/**
*
*/
@Setter
private String name;
/**
*
*/
@Setter
private IWmsHealthIndexCron cycleRange;
// /**
// * 计算周期
// */
// @Setter
// private IWmsHealthIndexCron cycleRange;
/**
*
*/
@ -50,34 +52,59 @@ public class WmsHealthIndexVariable {
@Setter
private String applyPartGroup;
/**
*
*/
@Setter
private String sqlStatement;
/**
* spring
*/
@Setter
private String className;
/**
*
*/
@Setter
private String functionName;
/**
*
*/
@Setter
private String scriptNo;
/**
*
*/
@Setter
private Object value;
private WmsHealthIndexVariableValue value;
/**
* CRON
*/
@Setter
private boolean refresh;
/**
*
*/
@Setter
private Instant lastCalcTime;
/**
*
*/
@Setter
private Instant nextCalcTime;
public WmsHealthIndexVariable(String organizeCode,String variable){
this(new WmsHealthIndexVariableId(organizeCode,variable));
public WmsHealthIndexVariable(final String organizeCode,final String variable){
this(new WmsHealthIndexVariableId(organizeCode, variable));
}
public WmsHealthIndexVariable(WmsHealthIndexVariableId id){
if(null==id){
throw new IllegalArgumentException("WmsHealthIndexVariableId can't be null");
}
this.id = id;
}
@ -92,17 +119,75 @@ public class WmsHealthIndexVariable {
return flag;
}
public boolean checked(){
/**
*
* @return
*/
public boolean hasValue(){
return null!=value;
}
/**
* CRON
* @param cron
*/
public void changeCalcFrequency(IWmsHealthIndexCron cron){
setCalcFrequency(cron);
setRefresh(true);
}
public void changeCycleRange(IWmsHealthIndexCron cron){
setCycleRange(cron);
setRefresh(true);
/**
*
* @param formartTime yyyy-MM-dd HH:mm:ss 2022-01-13 10:45:43
*/
public boolean setLastCalcTimeFormat(String formartTime){
if(null==formartTime||formartTime.trim().isEmpty()){
return false;
}
try{
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
long time = sdf.parse(formartTime).getTime();
this.lastCalcTime = (Instant.ofEpochMilli(time));
}catch (Exception e){
return false;
}
return null!=lastCalcTime;
}
public String formatToDateTime(Long time) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return sdf.format(new Date(time));
}
/**
*
* @return
*/
public String getLastCalcTimeFormat() {
return null!=this.lastCalcTime ? formatToDateTime(this.lastCalcTime.toEpochMilli()):"";
}
/**
*
* @return
*/
public String getNextCalcTimeFormat() {
return formatToDateTime(calcFrequency.getNextDate().getTime());
}
/**
*
* @param value
*/
public void changeValue(WmsHealthIndexVariableValue value){
if(null!=value) {
this.setValue(value);
this.setRefresh(true);
this.setLastCalcTime(Instant.now());
}
}
}

@ -1,15 +1,20 @@
package cn.estsh.i3plus.pojo.wms.bean.health;
import lombok.Getter;
import lombok.Value;
import lombok.Setter;
/**
*
*/
@Getter
@Value
public class WmsHealthIndexVariableId {
/**
* ID
*/
@Getter
@Setter
private Long pk;
/**
*
*/
@ -20,4 +25,16 @@ public class WmsHealthIndexVariableId {
private final String variable;
public WmsHealthIndexVariableId(final String organizeCode,final String variable){
if(null == organizeCode){
throw new IllegalArgumentException("organizeCode can't be null");
}
if(null == variable){
throw new IllegalArgumentException("variable can't be null");
}
this.organizeCode = organizeCode;
this.variable = variable;
}
}

@ -7,13 +7,12 @@ import lombok.Value;
*
*/
@Getter
@Value
public class WmsHealthIndexVariableValue {
/**
*
*/
private final Integer value;
private final Double value;
/**
*
@ -21,7 +20,19 @@ public class WmsHealthIndexVariableValue {
private final Object detail;
public WmsHealthIndexVariableValue(final Double value,final Object detail){
if(null==value){
throw new IllegalArgumentException("value can't be null");
}
if(null==detail){
throw new IllegalArgumentException("detail can't be null");
}
this.value = value;
this.detail = detail;
}
public static WmsHealthIndexVariableValue empty(){
return new WmsHealthIndexVariableValue(-1,"");
return new WmsHealthIndexVariableValue(-1.0,"");
}
}

@ -17,7 +17,7 @@ public interface IWmsHealthIndexRepository {
* @param id
* @return
*/
WmsHealthIndexEntity findAndInit(WmsHealthIndexId id);
WmsHealthIndexEntity findAndInit(final WmsHealthIndexId id);
/**
*
@ -31,7 +31,7 @@ public interface IWmsHealthIndexRepository {
* @param wmsHealthIndexEntity
* @param source
*/
void save(final WmsHealthIndexEntity wmsHealthIndexEntity,String source);
void save(final WmsHealthIndexEntity wmsHealthIndexEntity,final String source);
/**

Loading…
Cancel
Save