|
|
@@ -17,10 +17,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.JPGetRegionData;
|
|
|
-import com.shkpr.service.warncore.jsonbean.JPGetRegionReport;
|
|
|
-import com.shkpr.service.warncore.jsonbean.JPGetRegionReportItem;
|
|
|
-import com.shkpr.service.warncore.jsonbean.JPOrdWarnEventInfo;
|
|
|
+import com.shkpr.service.warncore.jsonbean.*;
|
|
|
import com.shkpr.service.warncore.services.ServiceMgrProxy;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
@@ -391,6 +388,7 @@ public class SiteDataWarnHandler {
|
|
|
Map<String, List<SiteSampleGroupItem>> ownerId2TriggerSample = new HashMap<>();//触发规则的样本数据
|
|
|
String eventIdAcceptPlanHisTriggerSam = "";//将预案的历史触发样本数据迁移到该事件
|
|
|
boolean clearPlanHisTriggerSam = false;//是否需要清空预案的历史触发样本数据
|
|
|
+ Map<String, String> mixComplexKey2Value = new HashMap<>();//复合公式下的{key->value}
|
|
|
do {
|
|
|
JPGetRegionData jpParam = new JPGetRegionData();
|
|
|
jpParam.setTotal(1);
|
|
|
@@ -447,14 +445,35 @@ public class SiteDataWarnHandler {
|
|
|
continue;
|
|
|
for (OrdWarnRuleCondition condition:findRule.getConditions()){
|
|
|
String originValue = "";
|
|
|
- String backTag = condition.getFormat().substring(condition.getFormat().lastIndexOf("@")+1);
|
|
|
+ String[] storeTagAndBackTag = condition.getFormat().split("@");
|
|
|
+ String storeTag = storeTagAndBackTag[0];
|
|
|
+ String backTag = storeTagAndBackTag[1];
|
|
|
for (KeyValue kv:sampleItem.getFields()){
|
|
|
if (backTag.equals(kv.getKey())){
|
|
|
originValue = kv.getValue();
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
- int pkRes = CommToolHandler.matchedToRuleItem(originValue, condition);
|
|
|
+ int pkRes = -1;
|
|
|
+ if (condition.getThreshold().contains("@")){
|
|
|
+ JPMixComplexCondition jp = CommToolHandler.parseConditions2TimeRange(condition.getThreshold(), sampleRecordTm, 0L);
|
|
|
+ if (jp != null){
|
|
|
+ String mixKey = jp.genKey();
|
|
|
+ String matchedValue = mixComplexKey2Value.get(mixKey);
|
|
|
+ if (matchedValue == null){
|
|
|
+ matchedValue = getMixComplexDataRealBySet(siteId, storeTag, 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;
|
|
|
@@ -651,6 +670,7 @@ public class SiteDataWarnHandler {
|
|
|
Map<String, List<SiteStatsDataItem>> ownerId2TriggerSample = new HashMap<>();//触发规则的样本数据
|
|
|
String eventIdAcceptPlanHisTriggerSam = "";//将预案的历史触发样本数据迁移到该事件
|
|
|
boolean clearPlanHisTriggerSam = false;//是否需要清空预案的历史触发样本数据
|
|
|
+ Map<String, String> mixComplexKey2Value = new HashMap<>();//复合公式下的{key->value}
|
|
|
|
|
|
List<Long> tagTime = new ArrayList<>();//每个整点时刻,用于查询站点的统计数据
|
|
|
long tmpStepToStep = thisTempStep.getQueryBeginUTC();
|
|
|
@@ -728,6 +748,7 @@ public class SiteDataWarnHandler {
|
|
|
|
|
|
for (OrdWarnRuleCondition condition:findRule.getConditions()){
|
|
|
String originValue = "";
|
|
|
+ String storeTag = storeTagAndBackTag[0];
|
|
|
String backTag = storeTagAndBackTag[1];
|
|
|
for (KeyValue kv:sampleItem.getReport()){
|
|
|
if (backTag.equals(kv.getKey())){
|
|
|
@@ -735,7 +756,26 @@ public class SiteDataWarnHandler {
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
- int pkRes = CommToolHandler.matchedToRuleItem(originValue, condition);
|
|
|
+ int pkRes = -1;
|
|
|
+ if (condition.getThreshold().contains("@")){
|
|
|
+ JPMixComplexCondition jp = CommToolHandler.parseConditions2TimeRange(condition.getThreshold(), sampleRecordTm, 0L);
|
|
|
+ if (jp != null){
|
|
|
+ String mixKey = jp.genKey();
|
|
|
+ String matchedValue = mixComplexKey2Value.get(mixKey);
|
|
|
+ if (matchedValue == null){
|
|
|
+ matchedValue = getMixComplexDataForHWO(siteId, storeTag, 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;
|
|
|
@@ -1034,6 +1074,7 @@ public class SiteDataWarnHandler {
|
|
|
Map<String, List<SiteStatsDataItem>> ownerId2TriggerSample = new HashMap<>();//触发规则的样本数据
|
|
|
String eventIdAcceptPlanHisTriggerSam = "";//将预案的历史触发样本数据迁移到该事件
|
|
|
boolean clearPlanHisTriggerSam = false;//是否需要清空预案的历史触发样本数据
|
|
|
+ Map<String, String> mixComplexKey2Value = new HashMap<>();//复合公式下的{key->value}
|
|
|
|
|
|
List<Long> tagTime = new ArrayList<>();//每天整点时刻,用于查询站点的统计数据
|
|
|
long tmpStepToStep = thisTempStep.getQueryBeginUTC();
|
|
|
@@ -1106,6 +1147,7 @@ public class SiteDataWarnHandler {
|
|
|
|
|
|
for (OrdWarnRuleCondition condition:findRule.getConditions()){
|
|
|
String originValue = "";
|
|
|
+ String storeTag = storeTagAndBackTag[0];
|
|
|
String backTag = storeTagAndBackTag[1];
|
|
|
for (KeyValue kv:sampleItem.getReport()){
|
|
|
if (backTag.equals(kv.getKey())){
|
|
|
@@ -1114,12 +1156,32 @@ public class SiteDataWarnHandler {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- int needLines = (int)(TimeTool.SEC_ONE_DAY/findRule.getDevCycle());//理论采集条数
|
|
|
- int offsetLines = (int)Math.ceil(needLines*0.01);//容错率为1%对应的条数
|
|
|
- int realLines = CastUtil.castInt(originValue, 0);//实际采集条数
|
|
|
- int diffLines = needLines-realLines;//缺失条数(实际条数比理论条数大时为负)
|
|
|
- double diffRate = diffLines<=offsetLines?0.0:(diffLines*100)/needLines;
|
|
|
- int pkRes = CommToolHandler.matchedToRuleItem(String.valueOf(diffRate), condition);
|
|
|
+ int pkRes = -1;
|
|
|
+ if (condition.getThreshold().contains("@")){
|
|
|
+ JPMixComplexCondition jp = CommToolHandler.parseConditions2TimeRange(condition.getThreshold(), sampleRecordTm, 0L);
|
|
|
+ if (jp != null){
|
|
|
+ String mixKey = jp.genKey();
|
|
|
+ String matchedValue = mixComplexKey2Value.get(mixKey);
|
|
|
+ if (matchedValue == null){
|
|
|
+ matchedValue = getMixComplexDataForLoss(siteId, storeTag, findRule.getDevCycle(), 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 {
|
|
|
+ int needLines = (int)(TimeTool.SEC_ONE_DAY/findRule.getDevCycle());//理论采集条数
|
|
|
+ int offsetLines = (int)Math.ceil(needLines*0.01);//容错率为1%对应的条数
|
|
|
+ int realLines = CastUtil.castInt(originValue, 0);//实际采集条数
|
|
|
+ int diffLines = needLines-realLines;//缺失条数(实际条数比理论条数大时为负)
|
|
|
+ double diffRate = diffLines<=offsetLines?0.0:(diffLines*100)/needLines;
|
|
|
+ pkRes = CommToolHandler.matchedToRuleItem(String.valueOf(diffRate), condition);
|
|
|
+ }
|
|
|
+
|
|
|
if (pkRes == -1){
|
|
|
step = String.format("Compare value exception error");
|
|
|
code = ResponseCode.RESULT_BAD;
|
|
|
@@ -1376,4 +1438,136 @@ public class SiteDataWarnHandler {
|
|
|
planDetail.getUid(), siteId, step, clearPlanHisTriggerSam, eventIdAcceptPlanHisTriggerSam, code.toString()));
|
|
|
return code;
|
|
|
}
|
|
|
+
|
|
|
+ private static String getMixComplexDataRealBySet(String objId, String field, JPMixComplexCondition jp){
|
|
|
+ String value = null;
|
|
|
+ SiteStatsDataResult siteStatsData = null;
|
|
|
+ do {
|
|
|
+ final JPGetRegionReportItem item = new JPGetRegionReportItem();
|
|
|
+ item.setUid(objId);
|
|
|
+ item.setField(field);
|
|
|
+ item.setTag("");
|
|
|
+ item.setBeginTime(jp.getBeginTime());
|
|
|
+ item.setEndTime(jp.getEndTime()+1L);
|
|
|
+
|
|
|
+ JPGetRegionReport queryJP = new JPGetRegionReport();
|
|
|
+ queryJP.setData(new ArrayList<JPGetRegionReportItem>(){{add(item);}});
|
|
|
+ queryJP.setTotal(CommTool.listSize(queryJP.getData()));
|
|
|
+
|
|
|
+ try {
|
|
|
+ ResponseRes<String> resHttp = ServiceMgrProxy.getInstance().applyDataQeServiceApi().siteRegionReport(queryJP);
|
|
|
+ if (ResponseCode.RESULT_NORMAL.toStrCode().equals(resHttp.getRescode()))
|
|
|
+ siteStatsData = FastJsonUtil.fromJSONByGson(resHttp.getResdata(), SiteStatsDataResult.class);
|
|
|
+ }catch (Exception e){}
|
|
|
+
|
|
|
+ if (siteStatsData == null || CommTool.listSize(siteStatsData.getData()) <= 0)
|
|
|
+ break;
|
|
|
+
|
|
|
+ String key = String.format("%s_f", jp.getMethod());
|
|
|
+ if (CommTool.listSize(siteStatsData.getData().get(0).getReport()) > 0){
|
|
|
+ for (KeyValue tmp:siteStatsData.getData().get(0).getReport()){
|
|
|
+ if (key.equals(tmp.getKey())){
|
|
|
+ value = tmp.getValue();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }while (false);
|
|
|
+ return value;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static String getMixComplexDataForHWO(String objId, String field, JPMixComplexCondition jp){
|
|
|
+ String value = null;
|
|
|
+ WaterXYReportRes reportRes = null;
|
|
|
+ do {
|
|
|
+ JPGetRegionXY tmpQuery = new JPGetRegionXY();
|
|
|
+ tmpQuery.setBeginDate(TimeTool.convertUTC2DateStr(jp.getBeginTime(), TimeTool.TIMESTAMP_FORMAT));
|
|
|
+ tmpQuery.setEndDate(TimeTool.convertUTC2DateStr(jp.getEndTime(), TimeTool.TIMESTAMP_FORMAT));
|
|
|
+ tmpQuery.setByTime(0);
|
|
|
+ tmpQuery.setIds(new ArrayList<String>(){{add(objId);}});
|
|
|
+
|
|
|
+ try {
|
|
|
+ ResponseRes<String> resHttp = ServiceMgrProxy.getInstance().applyDataQeServiceApi().siteRegionWaterXY(tmpQuery);
|
|
|
+ if (ResponseCode.RESULT_NORMAL.toStrCode().equals(resHttp.getRescode()))
|
|
|
+ reportRes = FastJsonUtil.fromJSONByGson(resHttp.getResdata(), WaterXYReportRes.class);
|
|
|
+ }catch (Exception e){}
|
|
|
+
|
|
|
+ if (reportRes == null || CommTool.listSize(reportRes.getData()) <= 0)
|
|
|
+ break;
|
|
|
+
|
|
|
+ int nSampleLines = CommTool.listSize(reportRes.getData().get(0).getReport());
|
|
|
+ if (nSampleLines <= 0)
|
|
|
+ break;
|
|
|
+
|
|
|
+ for (CommDVBean tmpItem:reportRes.getData().get(0).getReport()){
|
|
|
+ if (StringUtils.isEmpty(tmpItem.getValue()))
|
|
|
+ continue;
|
|
|
+ if (StringUtils.isEmpty(value)){
|
|
|
+ value = tmpItem.getValue();
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if ("min".equals(jp.getMethod())){
|
|
|
+ value = String.valueOf(Math.min(CastUtil.castDouble(value), CastUtil.castDouble(tmpItem.getValue())));
|
|
|
+ }else if ("max".equals(jp.getMethod())){
|
|
|
+ value = String.valueOf(Math.max(CastUtil.castDouble(value), CastUtil.castDouble(tmpItem.getValue())));
|
|
|
+ }else {
|
|
|
+ value = String.valueOf(CastUtil.castDouble(value)+CastUtil.castDouble(tmpItem.getValue()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!StringUtils.isEmpty(value) && "avg".equals(jp.getMethod()))
|
|
|
+ value = String.valueOf(CastUtil.castDouble(value)/nSampleLines);
|
|
|
+ }while (false);
|
|
|
+ return value;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static String getMixComplexDataForLoss(String objId, String field, int devCycle, JPMixComplexCondition jp){
|
|
|
+ String value = null;
|
|
|
+ LinesXYReportRes reportRes = null;
|
|
|
+ do {
|
|
|
+ JPGetRegionXY tmpQuery = new JPGetRegionXY();
|
|
|
+ tmpQuery.setBeginDate(TimeTool.convertUTC2DateStr(jp.getBeginTime(), TimeTool.TIMESTAMP_FORMAT));
|
|
|
+ tmpQuery.setEndDate(TimeTool.convertUTC2DateStr(jp.getEndTime(), TimeTool.TIMESTAMP_FORMAT));
|
|
|
+ tmpQuery.setByTime(1);
|
|
|
+ tmpQuery.setIds(new ArrayList<String>(){{add(objId);}});
|
|
|
+
|
|
|
+ try {
|
|
|
+ ResponseRes<String> resHttp = ServiceMgrProxy.getInstance().applyDataQeServiceApi().siteRegionLinesXY(tmpQuery);
|
|
|
+ if (ResponseCode.RESULT_NORMAL.toStrCode().equals(resHttp.getRescode()))
|
|
|
+ reportRes = FastJsonUtil.fromJSONByGson(resHttp.getResdata(), LinesXYReportRes.class);
|
|
|
+ }catch (Exception e){}
|
|
|
+
|
|
|
+ if (reportRes == null || CommTool.listSize(reportRes.getData()) <= 0)
|
|
|
+ break;
|
|
|
+
|
|
|
+ int nSampleLines = CommTool.listSize(reportRes.getData().get(0).getReport());
|
|
|
+ if (nSampleLines <= 0)
|
|
|
+ break;
|
|
|
+
|
|
|
+ for (CommDLBean tmpItem:reportRes.getData().get(0).getReport()){
|
|
|
+ if (StringUtils.isEmpty(value)){
|
|
|
+ value = String.valueOf(tmpItem.getLines());
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if ("min".equals(jp.getMethod())){
|
|
|
+ value = String.valueOf(Math.min(CastUtil.castInt(value), tmpItem.getLines()));
|
|
|
+ }else if ("max".equals(jp.getMethod())){
|
|
|
+ value = String.valueOf(Math.max(CastUtil.castInt(value), tmpItem.getLines()));
|
|
|
+ }else {
|
|
|
+ value = String.valueOf(CastUtil.castDouble(value)+tmpItem.getLines());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!StringUtils.isEmpty(value) && "avg".equals(jp.getMethod()))
|
|
|
+ value = String.valueOf(CastUtil.castDouble(value)/nSampleLines);
|
|
|
+
|
|
|
+ int needLines = (int)(TimeTool.SEC_ONE_DAY/devCycle);//理论采集条数
|
|
|
+ int offsetLines = (int)Math.ceil(needLines*0.01);//容错率为1%对应的条数
|
|
|
+ int realLines = CastUtil.castInt(value, 0);//实际采集条数
|
|
|
+ int diffLines = needLines-realLines;//缺失条数(实际条数比理论条数大时为负)
|
|
|
+ double diffRate = diffLines<=offsetLines?0.0:(diffLines*100)/needLines;
|
|
|
+ value = String.valueOf(diffRate);
|
|
|
+ }while (false);
|
|
|
+ return value;
|
|
|
+ }
|
|
|
}
|