|
|
@@ -1,14 +1,21 @@
|
|
|
package com.shkpr.service.warncore.bizhandler;
|
|
|
|
|
|
+import com.global.base.log.LogLevelFlag;
|
|
|
+import com.global.base.log.LogPrintMgr;
|
|
|
+import com.global.base.tools.FastJsonUtil;
|
|
|
import com.shkpr.service.warncore.commtools.CommTool;
|
|
|
import com.shkpr.service.warncore.commtools.TimeTool;
|
|
|
import com.shkpr.service.warncore.constants.CommFieldStatus;
|
|
|
+import com.shkpr.service.warncore.constants.EventAction;
|
|
|
import com.shkpr.service.warncore.constants.FrequencyUnit;
|
|
|
+import com.shkpr.service.warncore.constants.LogFlagBusiType;
|
|
|
import com.shkpr.service.warncore.dbdao.DBMgrProxy;
|
|
|
import com.shkpr.service.warncore.dbdao.services.intef.OrdWarnPlanInfoDBService;
|
|
|
import com.shkpr.service.warncore.dbdao.services.intef.OrdWarnPlanRulesDBService;
|
|
|
+import com.shkpr.service.warncore.dbdao.tables.OrdWarnEventInfoTable;
|
|
|
import com.shkpr.service.warncore.dbdao.tables.OrdWarnPlanInfoTable;
|
|
|
import com.shkpr.service.warncore.dto.*;
|
|
|
+import com.shkpr.service.warncore.jsonbean.JPOrdWarnEventInfo;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
import java.util.*;
|
|
|
@@ -17,6 +24,10 @@ import java.util.*;
|
|
|
* 分区分析统计数据处理
|
|
|
*/
|
|
|
public class ZoneDataWarnHandler {
|
|
|
+ private static int COMPARE_TURE = 1;
|
|
|
+ private static int COMPARE_FALSE = 0;
|
|
|
+ private final static String mBusinessType = LogFlagBusiType.BUSI_SITE_DATA_WARN_HANDLE.toStrValue();
|
|
|
+ private final static String mStrClassName = "ZoneDataWarnHandler";
|
|
|
private static OrdWarnPlanInfoDBService getWarnPlanInfoDBService(){
|
|
|
return DBMgrProxy.getInstance().applyXXXApi(OrdWarnPlanInfoDBService.class);
|
|
|
}
|
|
|
@@ -109,7 +120,7 @@ public class ZoneDataWarnHandler {
|
|
|
if (lastEventTmInYear == preMonthInYear){
|
|
|
if (planDetail.getCycleTriggerUpperTimes() > 0
|
|
|
&& thisStepTempRes.getCycleTriggerTimes() >= planDetail.getCycleTriggerUpperTimes()){//触发事件达到最大个数
|
|
|
- step = "Event arrive at max limit,stop analysis for today.";
|
|
|
+ step = "Event arrive at max limit,stop analysis for month.";
|
|
|
code = ResponseCode.RESULT_BAD;
|
|
|
break;
|
|
|
}
|
|
|
@@ -135,7 +146,21 @@ public class ZoneDataWarnHandler {
|
|
|
if (code == ResponseCode.RESULT_NORMAL){
|
|
|
code = analysisDataByDayOrMonth(planDetail, rules, thisStepTempRes);
|
|
|
}else {//单独更新预警方案的分析时间、次数、说明
|
|
|
+ thisStepTempRes.setLastAnalyExplain(step);
|
|
|
+ Map<String, Object> updatePlan = thisStepTempRes.genUpdatePlan();
|
|
|
+ updatePlan.put(OrdWarnPlanInfoTable.W_INFO.VERSION, planDetail.getVersion()+1);
|
|
|
+ updatePlan.put(OrdWarnPlanInfoTable.W_INFO.UPDATE_TIME, System.currentTimeMillis());
|
|
|
+ if (getWarnPlanInfoDBService().updatePlanForTrigger(new HashMap<String, Object>(){{
|
|
|
+ put(OrdWarnPlanInfoTable.W_INFO.UNIQUE_ID, planDetail.getUid());
|
|
|
+ put(OrdWarnPlanInfoTable.W_INFO.VERSION, planDetail.getVersion());
|
|
|
+ }}, updatePlan, null, null) <= 0){
|
|
|
+ step = "Update warn plan trigger result to db failed.";
|
|
|
+ code = ResponseCode.RESULT_BAD;
|
|
|
+ }
|
|
|
}
|
|
|
+ LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBusinessType, mStrClassName
|
|
|
+ , String.format("Pick Zone Data By Month:{planId=%s} {step=%s} {%s}...",
|
|
|
+ planDetail.getUid(), step, code.toString()));
|
|
|
return code;
|
|
|
}
|
|
|
|
|
|
@@ -234,7 +259,21 @@ public class ZoneDataWarnHandler {
|
|
|
if (code == ResponseCode.RESULT_NORMAL){
|
|
|
code = analysisDataByDayOrMonth(planDetail, rules, thisStepTempRes);
|
|
|
}else {//单独更新预警方案的分析时间、次数、说明
|
|
|
+ thisStepTempRes.setLastAnalyExplain(step);
|
|
|
+ Map<String, Object> updatePlan = thisStepTempRes.genUpdatePlan();
|
|
|
+ updatePlan.put(OrdWarnPlanInfoTable.W_INFO.VERSION, planDetail.getVersion()+1);
|
|
|
+ updatePlan.put(OrdWarnPlanInfoTable.W_INFO.UPDATE_TIME, System.currentTimeMillis());
|
|
|
+ if (getWarnPlanInfoDBService().updatePlanForTrigger(new HashMap<String, Object>(){{
|
|
|
+ put(OrdWarnPlanInfoTable.W_INFO.UNIQUE_ID, planDetail.getUid());
|
|
|
+ put(OrdWarnPlanInfoTable.W_INFO.VERSION, planDetail.getVersion());
|
|
|
+ }}, updatePlan, null, null) <= 0){
|
|
|
+ step = "Update warn plan trigger result to db failed.";
|
|
|
+ code = ResponseCode.RESULT_BAD;
|
|
|
+ }
|
|
|
}
|
|
|
+ LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBusinessType, mStrClassName
|
|
|
+ , String.format("Pick Zone Data By Day:{planId=%s} {step=%s} {%s}...",
|
|
|
+ planDetail.getUid(), step, code.toString()));
|
|
|
return code;
|
|
|
}
|
|
|
|
|
|
@@ -244,7 +283,9 @@ public class ZoneDataWarnHandler {
|
|
|
long curTime = TimeTool.getCurMsUTC();
|
|
|
final String zoneId = rules.get(0).getObjId();
|
|
|
List<DateKeyValue> zoneStatsData = null;//要求数据按date升序
|
|
|
- Map<String, Long> eventId2NewEndUTC = new HashMap<>();//需要更新预警事件的样本截止时间
|
|
|
+ Map<String, Long> oldEvent2EndUTC = new HashMap<>();//需要更新预警事件的样本截止时间
|
|
|
+ Map<String, JPOrdWarnEventInfo> newEvent2Gen = new HashMap<>();
|
|
|
+
|
|
|
do {
|
|
|
String[] storeTagAndBackTag = rules.get(0).getConditions().get(0).getFormat().split("@");
|
|
|
if (storeTagAndBackTag == null || storeTagAndBackTag.length < 2){
|
|
|
@@ -302,22 +343,28 @@ public class ZoneDataWarnHandler {
|
|
|
|
|
|
if (!matched){//本次没有匹配成功
|
|
|
thisTempStep.setLastCompareSampleTime(sampleRecordTm);
|
|
|
- thisTempStep.setLastCompareSampleResult(0);
|
|
|
+ thisTempStep.setLastCompareSampleResult(COMPARE_FALSE);
|
|
|
thisTempStep.setFirstMatchSampleTime(0L);
|
|
|
thisTempStep.setLastEventId("");
|
|
|
thisTempStep.setLastEventTime(0L);
|
|
|
+ thisTempStep.setLastCompareSampleExplain("This is not matched.");
|
|
|
continue;
|
|
|
}//本次匹配成功进入下一步
|
|
|
|
|
|
long triggerEventPeriodSwitch = planDetail.getFrequency()*planDetail.getThreshold();//触发预警事件的最小时长(单位:天/月)
|
|
|
- if (thisTempStep.getLastCompareSampleResult() <= 0){//上一次没有匹配成功
|
|
|
+ if (thisTempStep.getLastCompareSampleResult() <= COMPARE_FALSE){//上一次没有匹配成功
|
|
|
thisTempStep.setLastCompareSampleTime(sampleRecordTm);
|
|
|
- thisTempStep.setLastCompareSampleResult(1);
|
|
|
+ thisTempStep.setLastCompareSampleResult(COMPARE_TURE);
|
|
|
thisTempStep.setFirstMatchSampleTime(sampleRecordTm);
|
|
|
+ thisTempStep.setLastCompareSampleExplain("This is matched, but last is not matched.");
|
|
|
if (triggerEventPeriodSwitch <= 1){//触发事件
|
|
|
- thisTempStep.setLastEventId("新事件ID");
|
|
|
- thisTempStep.setLastEventTime(curTime);
|
|
|
- thisTempStep.setLastEventAction(1);
|
|
|
+ thisTempStep.setLastEventTime(TimeTool.getCurMsUTC());
|
|
|
+ thisTempStep.setLastCompareSampleExplain("This is matched and trigger short period, it will gen event.");
|
|
|
+
|
|
|
+ JPOrdWarnEventInfo newEvent = new JPOrdWarnEventInfo(planDetail, rules, thisTempStep, thisTempStep.getLastEventTime());
|
|
|
+ newEvent2Gen.put(newEvent.getUid(), newEvent);
|
|
|
+ thisTempStep.setLastEventId(newEvent.getUid());
|
|
|
+ thisTempStep.setLastEventAction(newEvent.getAction());
|
|
|
thisTempStep.setCycleTriggerTimes(thisTempStep.getCycleTriggerTimes()+1);
|
|
|
}
|
|
|
continue;
|
|
|
@@ -330,12 +377,17 @@ public class ZoneDataWarnHandler {
|
|
|
diffMatch = (sampleRecordTm-thisTempStep.getLastCompareSampleTime())/TimeTool.MS_ONE_DAY;//换算成天
|
|
|
if (diffMatch > triggerEventPeriodSwitch){//两个最近匹配样本间缺失的数据太多、或跨了天/月、或跨了时段,可认为重新计数
|
|
|
thisTempStep.setLastCompareSampleTime(sampleRecordTm);
|
|
|
- thisTempStep.setLastCompareSampleResult(1);
|
|
|
+ thisTempStep.setLastCompareSampleResult(COMPARE_TURE);
|
|
|
thisTempStep.setFirstMatchSampleTime(sampleRecordTm);
|
|
|
+ thisTempStep.setLastCompareSampleExplain("This is matched, but two matched sample is too distance.");
|
|
|
if (triggerEventPeriodSwitch <= 1){//触发事件
|
|
|
- thisTempStep.setLastEventId("新事件ID");
|
|
|
- thisTempStep.setLastEventTime(curTime);
|
|
|
- thisTempStep.setLastEventAction(1);
|
|
|
+ thisTempStep.setLastEventTime(TimeTool.getCurMsUTC());
|
|
|
+ thisTempStep.setLastCompareSampleExplain("This is matched and trigger short period, it will gen event.");
|
|
|
+
|
|
|
+ JPOrdWarnEventInfo newEvent = new JPOrdWarnEventInfo(planDetail, rules, thisTempStep, thisTempStep.getLastEventTime());
|
|
|
+ newEvent2Gen.put(newEvent.getUid(), newEvent);
|
|
|
+ thisTempStep.setLastEventId(newEvent.getUid());
|
|
|
+ thisTempStep.setLastEventAction(newEvent.getAction());
|
|
|
thisTempStep.setCycleTriggerTimes(thisTempStep.getCycleTriggerTimes()+1);
|
|
|
}else {
|
|
|
thisTempStep.setLastEventId("");
|
|
|
@@ -354,34 +406,48 @@ public class ZoneDataWarnHandler {
|
|
|
if (StringUtils.isEmpty(thisTempStep.getLastEventId())){//之前无预警事件
|
|
|
if (matchLen < triggerEventPeriodSwitch){//还得持续等待,达不到触发事件的累计时长
|
|
|
thisTempStep.setLastCompareSampleTime(sampleRecordTm);
|
|
|
- thisTempStep.setLastCompareSampleResult(1);
|
|
|
+ thisTempStep.setLastCompareSampleResult(COMPARE_TURE);
|
|
|
+ thisTempStep.setLastCompareSampleExplain("This is matched, but need wait the next matched.");
|
|
|
if (thisTempStep.getFirstMatchSampleTime() <= 0){
|
|
|
thisTempStep.setFirstMatchSampleTime(sampleRecordTm);
|
|
|
if (triggerEventPeriodSwitch <= 1){//补充触发事件
|
|
|
- thisTempStep.setLastEventId("新事件ID");
|
|
|
- thisTempStep.setLastEventTime(curTime);
|
|
|
- thisTempStep.setLastEventAction(1);
|
|
|
+ thisTempStep.setLastEventTime(TimeTool.getCurMsUTC());
|
|
|
+ thisTempStep.setLastCompareSampleExplain("This is matched and trigger short period, it will gen event.");
|
|
|
+
|
|
|
+ JPOrdWarnEventInfo newEvent = new JPOrdWarnEventInfo(planDetail, rules, thisTempStep, thisTempStep.getLastEventTime());
|
|
|
+ newEvent2Gen.put(newEvent.getUid(), newEvent);
|
|
|
+ thisTempStep.setLastEventId(newEvent.getUid());
|
|
|
+ thisTempStep.setLastEventAction(newEvent.getAction());
|
|
|
thisTempStep.setCycleTriggerTimes(thisTempStep.getCycleTriggerTimes()+1);
|
|
|
}
|
|
|
}
|
|
|
}else {//触发一个新的事件
|
|
|
thisTempStep.setLastCompareSampleTime(sampleRecordTm);
|
|
|
- thisTempStep.setLastCompareSampleResult(1);
|
|
|
- thisTempStep.setLastEventId("新事件ID");
|
|
|
- thisTempStep.setLastEventTime(curTime);
|
|
|
- thisTempStep.setLastEventAction(1);
|
|
|
+ thisTempStep.setLastCompareSampleResult(COMPARE_TURE);
|
|
|
+ thisTempStep.setLastEventTime(TimeTool.getCurMsUTC());
|
|
|
+ thisTempStep.setLastCompareSampleExplain("This is matched, and will gen event.");
|
|
|
+
|
|
|
+ JPOrdWarnEventInfo newEvent = new JPOrdWarnEventInfo(planDetail, rules, thisTempStep, thisTempStep.getLastEventTime());
|
|
|
+ newEvent2Gen.put(newEvent.getUid(), newEvent);
|
|
|
+ thisTempStep.setLastEventId(newEvent.getUid());
|
|
|
+ thisTempStep.setLastEventAction(newEvent.getAction());
|
|
|
thisTempStep.setCycleTriggerTimes(thisTempStep.getCycleTriggerTimes()+1);
|
|
|
//[!!!]do not change the FirstMatchSampleTime[!!!]
|
|
|
}
|
|
|
}else {//之前有预警事件
|
|
|
- if (planDetail.getMergeToEvent() == 0 || thisTempStep.getLastEventAction() >= 2){//之前的预警事件已处理,则可认为进行重新计数
|
|
|
+ if (planDetail.getMergeToEvent() == 0 || thisTempStep.getLastEventAction() >= EventAction.DONE){//之前的预警事件已处理,则可认为进行重新计数
|
|
|
thisTempStep.setLastCompareSampleTime(sampleRecordTm);
|
|
|
- thisTempStep.setLastCompareSampleResult(1);
|
|
|
+ thisTempStep.setLastCompareSampleResult(COMPARE_TURE);
|
|
|
thisTempStep.setFirstMatchSampleTime(sampleRecordTm);
|
|
|
+ thisTempStep.setLastCompareSampleExplain("This is matched, but need to wait the next matched.");
|
|
|
if (triggerEventPeriodSwitch <= 1){//触发事件
|
|
|
- thisTempStep.setLastEventId("新事件ID");
|
|
|
- thisTempStep.setLastEventTime(curTime);
|
|
|
- thisTempStep.setLastEventAction(1);
|
|
|
+ thisTempStep.setLastEventTime(TimeTool.getCurMsUTC());
|
|
|
+ thisTempStep.setLastCompareSampleExplain("This is matched and trigger short period, it will gen event.");
|
|
|
+
|
|
|
+ JPOrdWarnEventInfo newEvent = new JPOrdWarnEventInfo(planDetail, rules, thisTempStep, thisTempStep.getLastEventTime());
|
|
|
+ newEvent2Gen.put(newEvent.getUid(), newEvent);
|
|
|
+ thisTempStep.setLastEventId(newEvent.getUid());
|
|
|
+ thisTempStep.setLastEventAction(newEvent.getAction());
|
|
|
thisTempStep.setCycleTriggerTimes(thisTempStep.getCycleTriggerTimes()+1);
|
|
|
}else {
|
|
|
thisTempStep.setLastEventId("");
|
|
|
@@ -389,12 +455,48 @@ public class ZoneDataWarnHandler {
|
|
|
}
|
|
|
}else {//之前的预警事件未处理,则更新预警事件的样本截止时刻
|
|
|
thisTempStep.setLastCompareSampleTime(sampleRecordTm);
|
|
|
- thisTempStep.setLastCompareSampleResult(1);
|
|
|
- eventId2NewEndUTC.put(thisTempStep.getLastEventId(), sampleRecordTm);
|
|
|
+ thisTempStep.setLastCompareSampleResult(COMPARE_TURE);
|
|
|
+ if (newEvent2Gen.containsKey(thisTempStep.getLastEventId())){
|
|
|
+ newEvent2Gen.get(thisTempStep.getLastEventId()).setToTime(sampleRecordTm);
|
|
|
+ }else
|
|
|
+ oldEvent2EndUTC.put(thisTempStep.getLastEventId(), sampleRecordTm);
|
|
|
+ thisTempStep.setLastCompareSampleExplain("This is matched, but need to merge the last event.");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}while (false);
|
|
|
+
|
|
|
+ thisTempStep.setLastAnalyExplain(step);
|
|
|
+ Map<String, Object> updatePlan = thisTempStep.genUpdatePlan();
|
|
|
+ updatePlan.put(OrdWarnPlanInfoTable.W_INFO.VERSION, planDetail.getVersion()+1);
|
|
|
+ updatePlan.put(OrdWarnPlanInfoTable.W_INFO.UPDATE_TIME, System.currentTimeMillis());
|
|
|
+ List<Map<String, Object>> genNewEventObj = null;
|
|
|
+ if (CommTool.mapSize(newEvent2Gen) > 0){
|
|
|
+ genNewEventObj = new ArrayList<>();
|
|
|
+ for (Map.Entry<String, JPOrdWarnEventInfo> entry:newEvent2Gen.entrySet())
|
|
|
+ genNewEventObj.add(FastJsonUtil.obj2Map(entry.getValue(), true));
|
|
|
+ }
|
|
|
+ List<Map<String, Object>> genOldEventObj = null;
|
|
|
+ if (CommTool.mapSize(oldEvent2EndUTC) > 0){
|
|
|
+ genOldEventObj = new ArrayList<>();
|
|
|
+ for (Map.Entry<String, Long> entry:oldEvent2EndUTC.entrySet()){
|
|
|
+ genOldEventObj.add(new HashMap<String, Object>(){{
|
|
|
+ put(OrdWarnEventInfoTable.W_INFO.UNIQUE_ID, entry.getKey());
|
|
|
+ put(OrdWarnEventInfoTable.W_INFO.TO_TIME, entry.getValue());
|
|
|
+ put(OrdWarnEventInfoTable.W_INFO.UPDATE_TIME, TimeTool.getCurMsUTC());
|
|
|
+ }});
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (getWarnPlanInfoDBService().updatePlanForTrigger(new HashMap<String, Object>(){{
|
|
|
+ put(OrdWarnPlanInfoTable.W_INFO.UNIQUE_ID, planDetail.getUid());
|
|
|
+ put(OrdWarnPlanInfoTable.W_INFO.VERSION, planDetail.getVersion());
|
|
|
+ }}, updatePlan, genNewEventObj, genOldEventObj) <= 0){
|
|
|
+ step = "Update warn plan trigger result to db failed.";
|
|
|
+ code = ResponseCode.RESULT_BAD;
|
|
|
+ }
|
|
|
+ LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBusinessType, mStrClassName
|
|
|
+ , String.format("Analysis Data By Day Or Month:{planId=%s,zoneId=%s} {step=%s} {%s}...",
|
|
|
+ planDetail.getUid(), zoneId, step, code.toString()));
|
|
|
return code;
|
|
|
}
|
|
|
}
|