健康度指标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) @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.TEXT)
private String indicatorColor; private String indicatorColor;
@Transient // @Transient
@Column(name = "INDICATOR_VALUE")
@ApiParam(value = "指标测算值") @ApiParam(value = "指标测算值")
@DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.NUMBER) @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.NUMBER)
private Double indicatorCalcValue; private Double indicatorCalcValue;

@ -107,4 +107,10 @@ public class WmsHealthVariable extends BaseBean {
@ApiParam(value = "测算方式") @ApiParam(value = "测算方式")
@DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.TEXT) @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.TEXT)
private String calcWays; 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") @Column(name = "VARIABLE_VALUE")
@ApiParam(value = "变量测算值") @ApiParam(value = "变量测算值")
@DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.NUMBER) @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.NUMBER)
private Integer variableValue; private Double variableValue;
@Lob @Lob
@Column(name = "VARIABLE_DETAILS") @Column(name = "VARIABLE_DETAILS")

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

@ -1,5 +1,7 @@
package cn.estsh.i3plus.pojo.wms.bean.health; package cn.estsh.i3plus.pojo.wms.bean.health;
import lombok.Getter;
/** /**
* *
* @author link * @author link
@ -18,9 +20,20 @@ public enum WmsHealthIndexCalcWay {
*/ */
SCRIPT("30"); SCRIPT("30");
@Getter
private String value; private String value;
private WmsHealthIndexCalcWay(String value){ private WmsHealthIndexCalcWay(String value){
this.value = 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; package cn.estsh.i3plus.pojo.wms.bean.health;
import cn.estsh.i3plus.pojo.wms.bean.WmsHealthVariableResult;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; 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 WmsHealthIndexValue value;
/** /**
* * ()
*/ */
private Boolean refresh; private Boolean refresh;
public WmsHealthIndexEntity(final WmsHealthIndexId id, public WmsHealthIndexEntity(final WmsHealthIndexId id,
final WmsHealthIndexFormula formula){ final WmsHealthIndexFormula formula){
if(null==id){
throw new IllegalArgumentException("WmsHealthIndexId can't be null");
}
this.id = id; this.id = id;
this.formula = formula; this.formula = formula;
}; };
@ -50,7 +47,7 @@ public class WmsHealthIndexEntity {
final String indicatorCode, final String indicatorCode,
final String calcFormula){ final String calcFormula){
return new WmsHealthIndexEntity(WmsHealthIndexId.of(organizeCode,indicatorCode), 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(){ private WmsHealthIndexValue generateWmsHealthIndexValue(){
if(!formula.isEmpty()){ if(!formula.isResultEmpty()){
String result = null; String result = null;
int size = formula.getResults().size(); int size = formula.getResults().size();
if(size==1){ if(size==1){
WmsHealthIndexVariableValue varValue = formula.getSingleValue(); WmsHealthIndexVariableValue varValue = formula.getSingleValue();
if(null!=varValue)
result = String.valueOf(varValue.getDetail()); result = String.valueOf(varValue.getDetail());
}else{ }else{
result = String.valueOf(formula.getSpelResult()); result = String.valueOf(formula.getSpelResult());

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

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

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

@ -2,6 +2,11 @@ package cn.estsh.i3plus.pojo.wms.bean.health;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; 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 @Getter
public class WmsHealthIndexVariable { public class WmsHealthIndexVariable {
/** /**
* *
*/ */
private final WmsHealthIndexVariableId id; private final WmsHealthIndexVariableId id;
/** /**
* *
*/ */
@Setter @Setter
private String name; private String name;
/** // /**
* // * 计算周期
*/ // */
@Setter // @Setter
private IWmsHealthIndexCron cycleRange; // private IWmsHealthIndexCron cycleRange;
/** /**
* *
*/ */
@ -50,34 +52,59 @@ public class WmsHealthIndexVariable {
@Setter @Setter
private String applyPartGroup; private String applyPartGroup;
/**
*
*/
@Setter @Setter
private String sqlStatement; private String sqlStatement;
/**
* spring
*/
@Setter @Setter
private String className; private String className;
/**
*
*/
@Setter @Setter
private String functionName; private String functionName;
/**
*
*/
@Setter @Setter
private String scriptNo; private String scriptNo;
/** /**
* *
*/ */
@Setter @Setter
private Object value; private WmsHealthIndexVariableValue value;
/** /**
* CRON * CRON
*/ */
@Setter @Setter
private boolean refresh; 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){ public WmsHealthIndexVariable(WmsHealthIndexVariableId id){
if(null==id){
throw new IllegalArgumentException("WmsHealthIndexVariableId can't be null");
}
this.id = id; this.id = id;
} }
@ -92,17 +119,75 @@ public class WmsHealthIndexVariable {
return flag; return flag;
} }
public boolean checked(){
/**
*
* @return
*/
public boolean hasValue(){
return null!=value; return null!=value;
} }
/**
* CRON
* @param cron
*/
public void changeCalcFrequency(IWmsHealthIndexCron cron){ public void changeCalcFrequency(IWmsHealthIndexCron cron){
setCalcFrequency(cron); setCalcFrequency(cron);
setRefresh(true); 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; package cn.estsh.i3plus.pojo.wms.bean.health;
import lombok.Getter; import lombok.Getter;
import lombok.Value; import lombok.Setter;
/** /**
* *
*/ */
@Getter @Getter
@Value
public class WmsHealthIndexVariableId { public class WmsHealthIndexVariableId {
/**
* ID
*/
@Getter
@Setter
private Long pk;
/** /**
* *
*/ */
@ -20,4 +25,16 @@ public class WmsHealthIndexVariableId {
private final String variable; 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 @Getter
@Value
public class WmsHealthIndexVariableValue { public class WmsHealthIndexVariableValue {
/** /**
* *
*/ */
private final Integer value; private final Double value;
/** /**
* *
@ -21,7 +20,19 @@ public class WmsHealthIndexVariableValue {
private final Object detail; 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(){ public static WmsHealthIndexVariableValue empty(){
return new WmsHealthIndexVariableValue(-1,""); return new WmsHealthIndexVariableValue(-1.0,"");
} }
} }

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

Loading…
Cancel
Save