|
@@ -2,14 +2,13 @@ package com.shkpr.service.warncore.bizhandler;
|
|
|
|
|
|
|
|
import com.global.base.log.LogLevelFlag;
|
|
import com.global.base.log.LogLevelFlag;
|
|
|
import com.global.base.log.LogPrintMgr;
|
|
import com.global.base.log.LogPrintMgr;
|
|
|
|
|
+import com.global.base.tools.CastUtil;
|
|
|
import com.global.base.tools.FastJsonUtil;
|
|
import com.global.base.tools.FastJsonUtil;
|
|
|
import com.shkpr.service.warncore.commtools.CommTool;
|
|
import com.shkpr.service.warncore.commtools.CommTool;
|
|
|
import com.shkpr.service.warncore.commtools.TimeTool;
|
|
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.constants.*;
|
|
|
import com.shkpr.service.warncore.dbdao.DBMgrProxy;
|
|
import com.shkpr.service.warncore.dbdao.DBMgrProxy;
|
|
|
|
|
+import com.shkpr.service.warncore.dbdao.services.intef.MixDataBizDBService;
|
|
|
import com.shkpr.service.warncore.dbdao.services.intef.OrdWarnPlanInfoDBService;
|
|
import com.shkpr.service.warncore.dbdao.services.intef.OrdWarnPlanInfoDBService;
|
|
|
import com.shkpr.service.warncore.dbdao.services.intef.OrdWarnPlanRulesDBService;
|
|
import com.shkpr.service.warncore.dbdao.services.intef.OrdWarnPlanRulesDBService;
|
|
|
import com.shkpr.service.warncore.dbdao.tables.OrdWarnEventInfoTable;
|
|
import com.shkpr.service.warncore.dbdao.tables.OrdWarnEventInfoTable;
|
|
@@ -19,6 +18,7 @@ import com.shkpr.service.warncore.dto.*;
|
|
|
import com.shkpr.service.warncore.jsonbean.JPOrdWarnEventInfo;
|
|
import com.shkpr.service.warncore.jsonbean.JPOrdWarnEventInfo;
|
|
|
import org.springframework.util.StringUtils;
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
|
|
|
|
+import java.sql.Timestamp;
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -37,6 +37,10 @@ public class ZoneDataWarnHandler {
|
|
|
return DBMgrProxy.getInstance().applyXXXApi(OrdWarnPlanRulesDBService.class);
|
|
return DBMgrProxy.getInstance().applyXXXApi(OrdWarnPlanRulesDBService.class);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private static MixDataBizDBService getMixDataDBService(){
|
|
|
|
|
+ return DBMgrProxy.getInstance().applyXXXApi(MixDataBizDBService.class);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public static ResponseCode handlerDataFun(OrdWarnPlanDetail planDetail, List<OrdWarnPlanRules> rules){
|
|
public static ResponseCode handlerDataFun(OrdWarnPlanDetail planDetail, List<OrdWarnPlanRules> rules){
|
|
|
ResponseCode code = ResponseCode.RESULT_NORMAL;
|
|
ResponseCode code = ResponseCode.RESULT_NORMAL;
|
|
|
switch (planDetail.getFrequencyUnit()){
|
|
switch (planDetail.getFrequencyUnit()){
|
|
@@ -188,6 +192,7 @@ public class ZoneDataWarnHandler {
|
|
|
return code;
|
|
return code;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ //当月只分析前一月的数据
|
|
|
private static ResponseCode pickWarnByMonth(OrdWarnPlanDetail planDetail, List<OrdWarnPlanRules> rules){
|
|
private static ResponseCode pickWarnByMonth(OrdWarnPlanDetail planDetail, List<OrdWarnPlanRules> rules){
|
|
|
ResponseCode code = ResponseCode.RESULT_NORMAL;
|
|
ResponseCode code = ResponseCode.RESULT_NORMAL;
|
|
|
String step = "Start to pre analysis.";
|
|
String step = "Start to pre analysis.";
|
|
@@ -205,7 +210,7 @@ public class ZoneDataWarnHandler {
|
|
|
final int preMonth = TimeTool.getMonthIndex(lastMonthThisTm);//月分析时,分析前一月
|
|
final int preMonth = TimeTool.getMonthIndex(lastMonthThisTm);//月分析时,分析前一月
|
|
|
final int preMonthInYear = TimeTool.getYearIndex(lastMonthThisTm);//月分析时,分析前一月所在的年份
|
|
final int preMonthInYear = TimeTool.getYearIndex(lastMonthThisTm);//月分析时,分析前一月所在的年份
|
|
|
long queryBeginUTC = 0L, conditionMinUTC = 0L;
|
|
long queryBeginUTC = 0L, conditionMinUTC = 0L;
|
|
|
- long queryEndUTC = TimeTool.getMonthBeginUTC(curUTCTm);
|
|
|
|
|
|
|
+ long queryEndUTC = TimeTool.getMonthBeginUTC(curUTCTm)-TimeTool.MS_ONE_SEC;
|
|
|
OrdWarnPlanTempStep thisStepTempRes = new OrdWarnPlanTempStep(planDetail);
|
|
OrdWarnPlanTempStep thisStepTempRes = new OrdWarnPlanTempStep(planDetail);
|
|
|
thisStepTempRes.setLastAnalyTime(curUTCTm);
|
|
thisStepTempRes.setLastAnalyTime(curUTCTm);
|
|
|
thisStepTempRes.setCompareTimes(planDetail.getCompareTimes()+1);
|
|
thisStepTempRes.setCompareTimes(planDetail.getCompareTimes()+1);
|
|
@@ -304,6 +309,7 @@ public class ZoneDataWarnHandler {
|
|
|
return code;
|
|
return code;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ //当日只分析前一日的数据
|
|
|
public static ResponseCode pickWarnByDay(OrdWarnPlanDetail planDetail, List<OrdWarnPlanRules> rules){
|
|
public static ResponseCode pickWarnByDay(OrdWarnPlanDetail planDetail, List<OrdWarnPlanRules> rules){
|
|
|
ResponseCode code = ResponseCode.RESULT_NORMAL;
|
|
ResponseCode code = ResponseCode.RESULT_NORMAL;
|
|
|
String step = "Start to pre analysis.";
|
|
String step = "Start to pre analysis.";
|
|
@@ -320,7 +326,7 @@ public class ZoneDataWarnHandler {
|
|
|
final int preDayInYear = TimeTool.getYearIndex(curUTCTm-TimeTool.MS_ONE_DAY);//日分析时,分析前一日所在的年份
|
|
final int preDayInYear = TimeTool.getYearIndex(curUTCTm-TimeTool.MS_ONE_DAY);//日分析时,分析前一日所在的年份
|
|
|
final int preDayInMonth = TimeTool.getMonthIndex(curUTCTm-TimeTool.MS_ONE_DAY);//日分析时,分析前一日所在的月份
|
|
final int preDayInMonth = TimeTool.getMonthIndex(curUTCTm-TimeTool.MS_ONE_DAY);//日分析时,分析前一日所在的月份
|
|
|
long queryBeginUTC = 0L, conditionMinUTC = 0L;
|
|
long queryBeginUTC = 0L, conditionMinUTC = 0L;
|
|
|
- long queryEndUTC = TimeTool.getTodayBeginUTC();
|
|
|
|
|
|
|
+ long queryEndUTC = TimeTool.getTodayBeginUTC()-TimeTool.MS_ONE_SEC;
|
|
|
OrdWarnPlanTempStep thisStepTempRes = new OrdWarnPlanTempStep(planDetail);
|
|
OrdWarnPlanTempStep thisStepTempRes = new OrdWarnPlanTempStep(planDetail);
|
|
|
thisStepTempRes.setLastAnalyTime(curUTCTm);
|
|
thisStepTempRes.setLastAnalyTime(curUTCTm);
|
|
|
thisStepTempRes.setCompareTimes(planDetail.getCompareTimes()+1);
|
|
thisStepTempRes.setCompareTimes(planDetail.getCompareTimes()+1);
|
|
@@ -438,15 +444,19 @@ public class ZoneDataWarnHandler {
|
|
|
|
|
|
|
|
do {
|
|
do {
|
|
|
final String doField = rules.get(0).getConditions().get(0).getFormat();
|
|
final String doField = rules.get(0).getConditions().get(0).getFormat();
|
|
|
|
|
+ final String metricId = rules.get(0).getConditions().get(0).getKey();
|
|
|
|
|
+ final String fieldUnit = rules.get(0).getConditions().get(0).getUnit();
|
|
|
String[] storeTagAndBackTag = doField.split("@");
|
|
String[] storeTagAndBackTag = doField.split("@");
|
|
|
if (storeTagAndBackTag == null || storeTagAndBackTag.length < 2){
|
|
if (storeTagAndBackTag == null || storeTagAndBackTag.length < 2){
|
|
|
step = String.format("Format param invalid in rules");
|
|
step = String.format("Format param invalid in rules");
|
|
|
code = ResponseCode.RESULT_BAD;
|
|
code = ResponseCode.RESULT_BAD;
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
- TRecordRes<DateKeyValue> sampleRes = getSampleDataFromDB(planDetail.getItemKey()
|
|
|
|
|
|
|
+ TRecordRes<DateKeyValue> sampleRes = getSampleDataFromDB(fieldUnit
|
|
|
|
|
+ , planDetail.getFrequencyUnit()
|
|
|
|
|
+ , planDetail.getItemKey()
|
|
|
, zoneId, thisTempStep.getQueryBeginUTC(), thisTempStep.getQueryEndUTC()
|
|
, zoneId, thisTempStep.getQueryBeginUTC(), thisTempStep.getQueryEndUTC()
|
|
|
- , planDetail.getDoDb(), doField, planDetail.getDoTime());
|
|
|
|
|
|
|
+ , metricId , planDetail.getDoDb(), doField, planDetail.getDoTime());
|
|
|
if (sampleRes != null && sampleRes.getCode() == ResponseCode.RESULT_NORMAL.toInt()){
|
|
if (sampleRes != null && sampleRes.getCode() == ResponseCode.RESULT_NORMAL.toInt()){
|
|
|
zoneStatsData = sampleRes.getData();
|
|
zoneStatsData = sampleRes.getData();
|
|
|
}
|
|
}
|
|
@@ -788,9 +798,88 @@ public class ZoneDataWarnHandler {
|
|
|
return code;
|
|
return code;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private static TRecordRes<DateKeyValue> getSampleDataFromDB(String itemKey, String objId, long beginTm, long endTm, String doDb, String doField, String doTime){
|
|
|
|
|
|
|
+ public static TRecordRes<DateKeyValue> getSampleDataFromDB(String fieldUnit, String frequencyUnit, String itemKey, String objId, long beginTm, long endTm, String metricId, String doDb, String doField, String doTime){
|
|
|
|
|
+ TRecordRes<DateKeyValue> oRes = new TRecordRes<>(ResponseCode.RESULT_BAD.toInt());
|
|
|
String[] storeDbAndTable = doDb.split("@");
|
|
String[] storeDbAndTable = doDb.split("@");
|
|
|
String[] storeFieldAndBackField = doField.split("@");
|
|
String[] storeFieldAndBackField = doField.split("@");
|
|
|
|
|
+ String doTimeFunction = doTime.replaceAll("\\(.*\\)", "");
|
|
|
|
|
+ String doTimeField = doTime.replaceAll("^.*\\(|\\)", "");
|
|
|
|
|
+
|
|
|
|
|
+ String orderBy = String.format(" %s asc", doTimeField);
|
|
|
|
|
+ String queryField = String.format("zone_id,'%s' as key,%s as date"
|
|
|
|
|
+ , storeFieldAndBackField[1]
|
|
|
|
|
+ , doTimeField);
|
|
|
|
|
+ if ("%".equals(fieldUnit)){
|
|
|
|
|
+ queryField += String.format(",COALESCE(%s, 0)*100 as value", storeFieldAndBackField[0]);
|
|
|
|
|
+ }else
|
|
|
|
|
+ queryField += String.format(",COALESCE(%s, 0) as value", storeFieldAndBackField[0]);
|
|
|
|
|
+
|
|
|
|
|
+ StringBuilder filterExtend = new StringBuilder("");
|
|
|
|
|
+ switch (itemKey){
|
|
|
|
|
+ case WarnItemType.ZONE_HWO:{//小时水量,存储的是累计流量:(n+1)点-(n)点=(n)点水量,故分区水量要将endTm += TimeTool.MS_ONE_HOUR;然后再查询
|
|
|
|
|
+ endTm = TimeTool.getNextRoundHourUTCTm(endTm);
|
|
|
|
|
+ filterExtend.append(String.format(" AND EXTRACT(MINUTE FROM %s) = 0 AND EXTRACT(SECOND FROM %s) = 0 ", doTimeField, doTimeField));
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ default:
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ switch (doTimeFunction){
|
|
|
|
|
+ case "timestamp":{
|
|
|
|
|
+ filterExtend.append(String.format(" AND %s >= to_timestamp(%d) AND %s <= to_timestamp(%d)"
|
|
|
|
|
+ , doTimeField, beginTm/1000
|
|
|
|
|
+ , doTimeField, endTm/1000));
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ case "date":{
|
|
|
|
|
+ filterExtend.append(String.format(" AND %s >= '%s' AND %s <= '%s'"
|
|
|
|
|
+ , doTimeField, TimeTool.convertUTC2DateStr(beginTm, TimeTool.YEAR_MONTH_DAY_FORMAT)
|
|
|
|
|
+ , doTimeField, TimeTool.convertUTC2DateStr(endTm, TimeTool.YEAR_MONTH_DAY_FORMAT)));
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ default:{
|
|
|
|
|
+ filterExtend.append(String.format(" AND %s >= '%s' AND %s <= '%s'"
|
|
|
|
|
+ , doTimeField, TimeTool.convertUTC2DateStr(beginTm, TimeTool.YEAR_MONTH_DAY_FORMAT)
|
|
|
|
|
+ , doTimeField, TimeTool.convertUTC2DateStr(endTm, TimeTool.YEAR_MONTH_DAY_FORMAT)));
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ List<Map<String, Object>> arrDbs = getMixDataDBService().batchQueryL2L3Data(storeDbAndTable[1]
|
|
|
|
|
+ , queryField
|
|
|
|
|
+ , new HashMap<String, Object>(){{
|
|
|
|
|
+ put("zone_id", objId);
|
|
|
|
|
+ put("metric_id", metricId);}}
|
|
|
|
|
+ , null, orderBy, filterExtend.toString());
|
|
|
|
|
+ if (arrDbs == null) {
|
|
|
|
|
+ oRes.setCode(ResponseCode.BUSINESS_DB_ERROR.toInt());
|
|
|
|
|
+ return oRes;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ List<DateKeyValue> arrRecordRes = null;
|
|
|
|
|
+ do {
|
|
|
|
|
+ if (arrDbs.size() <= 0)
|
|
|
|
|
+ break;
|
|
|
|
|
+
|
|
|
|
|
+ if (WarnItemType.ZONE_HWO.equals(itemKey)){
|
|
|
|
|
+ if (CommTool.listSize(arrDbs) < 2)
|
|
|
|
|
+ break;
|
|
|
|
|
+
|
|
|
|
|
+ arrRecordRes = new ArrayList<>();
|
|
|
|
|
+ for (int i=0;i<arrDbs.size()-1;i++){
|
|
|
|
|
+ long thisTm = ((Timestamp)(arrDbs.get(i).get("date"))).getTime();
|
|
|
|
|
+ long nextTm = ((Timestamp)(arrDbs.get(i+1).get("date"))).getTime();
|
|
|
|
|
+ double thisValue = CastUtil.castDouble(arrDbs.get(i).get("value"), 0.0);
|
|
|
|
|
+ double nextValue = CastUtil.castDouble(arrDbs.get(i+1).get("value"), 0.0);
|
|
|
|
|
+ if (thisTm == (nextTm-TimeTool.MS_ONE_HOUR)){
|
|
|
|
|
+ arrRecordRes.add(new DateKeyValue(storeFieldAndBackField[1], CommToolHandler.toShortStrData(nextValue-thisValue)
|
|
|
|
|
+ , TimeTool.convertUTC2DateStr(thisTm, TimeTool.TIMESTAMP_FORMAT)));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }else
|
|
|
|
|
+ arrRecordRes = FastJsonUtil.batchMap2Obj(arrDbs, DateKeyValue.class);
|
|
|
|
|
+ }while (false);
|
|
|
|
|
|
|
|
/**小时水量,存储的是累计流量:(n+1)点-(n)点=(n)点水量,故分区水量要将endTm += TimeTool.MS_ONE_HOUR;然后再查询
|
|
/**小时水量,存储的是累计流量:(n+1)点-(n)点=(n)点水量,故分区水量要将endTm += TimeTool.MS_ONE_HOUR;然后再查询
|
|
|
* SELECT
|
|
* SELECT
|
|
@@ -806,6 +895,10 @@ public class ZoneDataWarnHandler {
|
|
|
* AND EXTRACT(SECOND FROM ts) = 0
|
|
* AND EXTRACT(SECOND FROM ts) = 0
|
|
|
* ORDER BY zone_id, ts
|
|
* ORDER BY zone_id, ts
|
|
|
*/
|
|
*/
|
|
|
- return null;
|
|
|
|
|
|
|
+ arrDbs.clear();
|
|
|
|
|
+ oRes.setData(arrRecordRes);
|
|
|
|
|
+ oRes.setCode(ResponseCode.RESULT_NORMAL.toInt());
|
|
|
|
|
+ oRes.checkRes();
|
|
|
|
|
+ return oRes;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|