1 public void hazardAlertJob(){ 2 Map<String,Map<String,Object>> alertTranNoMaps=new HashMap<String,Map<String,Object>>(); 3 EmConfig config=emConfigMapper.select(); 4 Long startTranNo=0L; 5 if(config!=null&&config.getHazardDataTranNo()!=null){ 6 startTranNo=config.getHazardDataTranNo(); 7 } 8 Long maxTranNo=hazardMonitorDataMapper.selectMaxTranNo(); 9 if(maxTranNo==null||startTranNo>=maxTranNo){ 10 return; 11 } 12 List<Map<String,Object>> list=hazardMonitorDataMapper.selectAlertRecord(startTranNo, maxTranNo); 13 for(Map<String,Object> map:list){ 14 Long alertTranNo=null; 15 Boolean alertIsReported=null; 16 Date alertTime=null; 17 String deviceCode=(String)map.get("deviceCode"); 18 String deviceName=(String)map.get("deviceName"); 19 Long tranNo=((BigDecimal)map.get("tranNo")).longValue(); 20 Date timeCreated=(Date)map.get("timeCreated"); 21 Map<String,Object> res=alertTranNoMaps.get(deviceCode); 22 if(res!=null){//上一条已经触发阀值,取存储的值 23 alertTranNo=(Long)res.get("alertTranNo"); 24 alertIsReported=(Boolean)res.get("alertIsReported"); 25 alertTime=(Date)res.get("alertTime"); 26 }else{ 27 Object atn=map.get("alertTranNo"); 28 alertTranNo=atn==null?null:((BigDecimal)atn).longValue(); 29 Object air=map.get("alertIsReported"); 30 alertIsReported=air==null?null:(map.get("alertIsReported").equals("1")?true:false); 31 Object atc=map.get("alertTime"); 32 alertTime=atc==null?null:(Date)atc; 33 } 34 Map<String,Object> newMap=new HashMap<String,Object>(); 35 newMap.put("alertTranNo", tranNo); 36 newMap.put("alertTime", timeCreated); 37 38 boolean isContinuous =false; 39 if(alertTranNo!=null&&alertTime!=null){ 40 /* Calendar calendar=Calendar.getInstance(); 41 calendar.setTime(timeCreated); 42 calendar.add(Calendar.SECOND, -10); 43 Calendar alertCalendar=Calendar.getInstance(); 44 alertCalendar.setTime(alertTime); 45 //if(calendar.compareTo(alertCalendar)<=0&&tranNo-alertTranNo.longValue()==1){ 46 if(calendar.compareTo(alertCalendar)<=0){//10秒内计为连续批次,因数据采集的时间无规律,有5秒、10更新采集的 47 isContinuous=true; 48 }*/ 49 50 Map<String,Object> frontData=hazardMonitorDataMapper.selectFrontFirstData(deviceCode, timeCreated); 51 if(frontData!=null&&((Date)frontData.get("timeCreated")).compareTo(alertTime)==0){//前一个数据与设备表中的已经报警过的日期相等,则为连续记录 52 isContinuous=true; 53 } 54 } 55 56 newMap.put("alertIsReported", isContinuous); 57 alertTranNoMaps.put(deviceCode, newMap); 58 hazardMonitorDeviceMapper.updateAlertTranNo(deviceCode, tranNo, isContinuous,timeCreated); 59 if(!isContinuous){ 60 continue; 61 } 62 63 if(alertIsReported!=null&&alertIsReported==false){//连续的且上一次没有生成报警记录 64 AlertInfo info=new AlertInfo(); 65 info.setMonitoringPoint(deviceName); 66 info.setEquipmentType(String.valueOf(FinalStaticValues.WEIXIANYUAN)); 67 info.setAlertTime((Date)timeCreated); 68 BigDecimal dataValue=(BigDecimal)map.get("dataValue"); 69 BigDecimal hValue=(BigDecimal)map.get("hValue"); 70 BigDecimal hhValue=(BigDecimal)map.get("hhValue"); 71 BigDecimal lValue=(BigDecimal)map.get("lValue"); 72 BigDecimal llValue=(BigDecimal)map.get("llValue"); 73 String alertLevel=null; 74 String alertInfo="监测值:"+dataValue; 75 BigDecimal rate=null; 76 if(dataValue.compareTo(hhValue)>=0){ 77 alertLevel="HH"; 78 alertInfo+=",高二级报警(HH:"+hhValue+")"; 79 }else if(dataValue.compareTo(hValue)>=0){ 80 alertLevel="H"; 81 alertInfo+=",高一级报警(H:"+hValue+")"; 82 }else if(dataValue.compareTo(llValue)<=0){ 83 alertLevel="LL"; 84 alertInfo+=",低二级报警(LL:"+llValue+")"; 85 }else if(dataValue.compareTo(lValue)<=0){ 86 alertLevel="L"; 87 alertInfo+=",低一级报警(L:"+lValue+")"; 88 } 89 if(alertLevel.equals("HH")||alertLevel.equals("H")){ 90 if(hValue.doubleValue()==0){ 91 rate=dataValue; 92 }else{ 93 rate=dataValue.subtract(hValue).divide(hValue,3, BigDecimal.ROUND_HALF_UP); 94 } 95 }else if(alertLevel.equals("LL")||alertLevel.equals("L")){ 96 if(lValue.doubleValue()==0){ 97 rate=dataValue; 98 }else{ 99 rate=dataValue.subtract(lValue).divide(lValue).setScale(3, BigDecimal.ROUND_HALF_UP); 100 } 101 } 102 info.setAlertInfo(alertInfo); 103 info.setAlertLevel(alertLevel); 104 info.setEquipmentId(deviceCode); 105 info.setEntId((String)map.get("companyId")); 106 info.setCurrentValue(String.valueOf(dataValue)); 107 info.setRate(rate.doubleValue()==0?"0":rate.toString()); 108 info.setlValue(lValue.doubleValue()); 109 info.setLlValue(llValue.doubleValue()); 110 info.sethValue(hValue.doubleValue()); 111 info.setHhValue(hhValue.doubleValue()); 112 alertInfoMapper.insert2(info); 113 } 114 } 115 emConfigMapper.update("HAZARD_DATA_TRAN_NO",maxTranNo); 116 }