|
|
@@ -15,6 +15,7 @@ import com.shkpr.service.warncore.dbdao.tables.OrdWarnEventInfoTable;
|
|
|
import com.shkpr.service.warncore.dbdao.tables.OrdWarnPlanInfoTable;
|
|
|
import com.shkpr.service.warncore.dbdao.tables.OrdWarnTriggerSampleHisTable;
|
|
|
import com.shkpr.service.warncore.dto.*;
|
|
|
+import com.shkpr.service.warncore.jsonbean.JPMixComplexCondition;
|
|
|
import com.shkpr.service.warncore.jsonbean.JPOrdWarnEventInfo;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
@@ -466,6 +467,7 @@ public class ZoneDataWarnHandler {
|
|
|
Map<String, List<DateKeyValue>> ownerId2TriggerSample = new HashMap<>();//触发规则的样本数据
|
|
|
String eventIdAcceptPlanHisTriggerSam = "";//将预案的历史触发样本数据迁移到该事件
|
|
|
boolean clearPlanHisTriggerSam = false;//是否需要清空预案的历史触发样本数据
|
|
|
+ Map<String, String> mixComplexKey2Value = new HashMap<>();//复合公式下的{key->value}
|
|
|
|
|
|
do {
|
|
|
final String doField = rules.get(0).getConditions().get(0).getFormat();
|
|
|
@@ -525,7 +527,28 @@ public class ZoneDataWarnHandler {
|
|
|
if (backTag.equals(sampleItem.getKey()))
|
|
|
originValue = sampleItem.getValue();
|
|
|
|
|
|
- int pkRes = CommToolHandler.matchedToRuleItem(originValue, condition);
|
|
|
+ int pkRes = -1;
|
|
|
+ if (condition.getThreshold().contains("@")){
|
|
|
+ JPMixComplexCondition jp = CommToolHandler.parseConditions2TimeRange(condition.getThreshold(), sampleRecordTm, 0L);
|
|
|
+ if (jp != null){
|
|
|
+ jp.setDataType(condition.getType());
|
|
|
+ String mixKey = jp.genKey();
|
|
|
+ String matchedValue = mixComplexKey2Value.get(mixKey);
|
|
|
+ if (matchedValue == null){
|
|
|
+ matchedValue = getMixComplexDataFromDB(fieldUnit, planDetail.getFrequencyUnit(), planDetail.getItemKey()
|
|
|
+ , zoneId, metricId , threshold, planDetail.getDoDb(), doField, planDetail.getDoTime(), jp);
|
|
|
+ if (matchedValue != null)
|
|
|
+ mixComplexKey2Value.put(mixKey, matchedValue);
|
|
|
+ }
|
|
|
+ pkRes = CommToolHandler.matchedToRuleItemEx(originValue, matchedValue, jp.getPercent(), condition);
|
|
|
+ }else{
|
|
|
+ step = String.format("Mix complex condition invalid.");
|
|
|
+ code = ResponseCode.RESULT_BAD;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }else
|
|
|
+ pkRes = CommToolHandler.matchedToRuleItem(originValue, condition);
|
|
|
+
|
|
|
if (pkRes == -1){
|
|
|
step = String.format("Compare value exception error");
|
|
|
code = ResponseCode.RESULT_BAD;
|
|
|
@@ -1015,4 +1038,56 @@ public class ZoneDataWarnHandler {
|
|
|
oRes.checkRes();
|
|
|
return oRes;
|
|
|
}
|
|
|
+
|
|
|
+ private static String getMixComplexDataFromDB(String fieldUnit, String frequencyUnit, String itemKey, String objId, String metricId, String threshold, String doDb, String doField, String doTime, JPMixComplexCondition jp){
|
|
|
+ String value = null;
|
|
|
+ TRecordRes<DateKeyValue> recordRes = null;
|
|
|
+ do {
|
|
|
+ recordRes = getSampleDataFromDB(fieldUnit, frequencyUnit, itemKey, objId, jp.getBeginTime(), jp.getEndTime(), metricId, threshold, doDb, doField, doTime);
|
|
|
+ if (recordRes == null || recordRes.getCode() != ResponseCode.RESULT_NORMAL.toInt())
|
|
|
+ break;
|
|
|
+
|
|
|
+ int nSampleLines = CommTool.listSize(recordRes.getData());
|
|
|
+ if (nSampleLines <= 0)
|
|
|
+ break;
|
|
|
+
|
|
|
+ for (DateKeyValue item:recordRes.getData()){
|
|
|
+ if (StringUtils.isEmpty(value)){
|
|
|
+ value = item.getValue();
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ("int".equalsIgnoreCase(jp.getDataType())
|
|
|
+ || "integer".equalsIgnoreCase(jp.getDataType())
|
|
|
+ || "long".equalsIgnoreCase(jp.getDataType())){
|
|
|
+ if ("min".equals(jp.getMethod())){
|
|
|
+ value = String.valueOf(Math.min(CastUtil.castInt(value, 0), CastUtil.castInt(item.getValue(), 0)));
|
|
|
+ }else if ("max".equals(jp.getMethod())){
|
|
|
+ value = String.valueOf(Math.max(CastUtil.castInt(value, 0), CastUtil.castInt(item.getValue(), 0)));
|
|
|
+ }else {
|
|
|
+ value = String.valueOf(CastUtil.castInt(value, 0)+CastUtil.castInt(item.getValue(), 0));
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ if ("min".equals(jp.getMethod())){
|
|
|
+ value = String.valueOf(Math.min(CastUtil.castDouble(value, 0), CastUtil.castDouble(item.getValue(), 0)));
|
|
|
+ }else if ("max".equals(jp.getMethod())){
|
|
|
+ value = String.valueOf(Math.max(CastUtil.castDouble(value, 0), CastUtil.castDouble(item.getValue(), 0)));
|
|
|
+ }else {
|
|
|
+ value = String.valueOf(CastUtil.castDouble(value, 0)+CastUtil.castDouble(item.getValue(), 0));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!StringUtils.isEmpty(value) && "avg".equals(jp.getMethod())){
|
|
|
+ if ("int".equalsIgnoreCase(jp.getDataType())
|
|
|
+ || "integer".equalsIgnoreCase(jp.getDataType())
|
|
|
+ || "long".equalsIgnoreCase(jp.getDataType()))
|
|
|
+ value = String.valueOf(CastUtil.castInt(value, 0)/nSampleLines);
|
|
|
+ else
|
|
|
+ value = String.valueOf(CastUtil.castDouble(value, 0)/nSampleLines);
|
|
|
+ }
|
|
|
+ recordRes.clearData();
|
|
|
+ }while (false);
|
|
|
+ return value;
|
|
|
+ }
|
|
|
}
|