RealTimeWarnJob.java 23.8 KB
package com.skua.modules.alarm.quartz;

import com.skua.core.context.SpringContextUtils;
import com.skua.core.service.IFactoryInfoService;
import com.skua.core.service.ISequenceService;
import com.skua.core.util.ConvertUtils;
import com.skua.core.util.DateUtils;
import com.skua.core.util.DoubleOperaUtils;
import lombok.extern.slf4j.Slf4j;

import org.apache.commons.lang.StringUtils;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * <pre>
 * 按照客户要求开发预警逻辑
 * </pre>
 * @author Li Yuanyuan
 * @version V0.1, 2021年3月22日 下午1:32:26
 */
@Slf4j
public class RealTimeWarnJob implements Job {
	@Autowired
    private IFactoryInfoService factoryInfoService;
	@Autowired
	private ISequenceService sequenceService;
    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
    	System.out.println("********预警监测定时服务开启********");
    	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date nowDate = new Date();
        String nowDay = DateUtils.getTodayOrMonthDate("day");
        Date afterDate = new Date(nowDate.getTime() - 600000);
        //昨天
        String yesterday = DateUtils.getYesterday();
        String yesterdayStart = yesterday+" 00:00:00";
        String yesterdayEnd = yesterday+" 23:59:59";
        //前天
        String qt = "";
        try {
			qt = DateUtils.formatAddTime(yesterday,"yyyy-MM-dd",Calendar.DATE,-1);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        String qtStart = qt+" 00:00:00";
        String qtEnd = qt+" 23:59:59";
        //大前天
        String dqt = "";
        try {
			dqt = DateUtils.formatAddTime(yesterday,"yyyy-MM-dd",Calendar.DATE,-2);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        String dqtStart = dqt+" 00:00:00";
        String dqtEnd = dqt+" 23:59:59";
        
    	JdbcTemplate masterDB = (JdbcTemplate) SpringContextUtils.getBean("master");
    	//获取预警规则配置表
    	List<Map<String,Object>> configList = masterDB.queryForList("select a.*,b.out_level,c.depart_name from alarm_warning_config a left join sys_factory_info b on  a.factory_id=b.factory_id inner join sys_depart c on a.factory_id=c.id  where use_flag='1'");
    	//出水阈值配置
    	Map<String,Object> outLevelMap = new HashMap<String,Object>();
    	outLevelMap.put("a_cod", "50");
    	outLevelMap.put("a_nh3_12s", "5");
    	outLevelMap.put("a_nh3_12x", "8");
    	outLevelMap.put("a_tn", "15");
    	outLevelMap.put("a_tp", "0.5");
    	outLevelMap.put("b_cod", "60");
    	outLevelMap.put("b_nh3_12s", "8");
    	outLevelMap.put("b_nh3_12x", "15");
    	outLevelMap.put("b_tn", "20");
    	outLevelMap.put("b_tp", "1");
    	//使用hashMap构造厂站规则对应关系
    	Map<String,Map<String,Object>> configMap = new HashMap<String,Map<String,Object>>();
    	for(Map<String,Object> map : configList) {
    		configMap.put(ConvertUtils.getString(map.get("factory_id")), map);
    	}
        //获取参加预警的个厂站真实指标
    	Map<String,Map<String,Object>> fieldMap = new HashMap<String,Map<String,Object>>();
    	List<Map<String,Object>> fieldList = masterDB.queryForList("select a.id,a.metric_uid_tag,a.metric_name,a.metric_unit,a.fac_code from sys_monitor_metric_info a inner join sys_metric_dict b on a.metric_uid_tag = b.id where b.id in('CSCOD','CSNH3N','CSTP','CSTN','CSSW') and a.fac_code in (select factory_id from alarm_warning_config where use_flag='1')");
    	//使用hashMap构造指标厂站对应关系
    	for(Map<String,Object> map : fieldList) {
    		String factory_id = ConvertUtils.getString(map.get("fac_code"));
    		Map<String, Object> factoryFieldMap = fieldMap.get(factory_id);
    		if(factoryFieldMap==null) {
    			factoryFieldMap = new HashMap<String,Object>();
    			fieldMap.put(factory_id, factoryFieldMap);
    		}
    		factoryFieldMap.put(ConvertUtils.getString(map.get("metric_uid_tag")), map);
    	}
    	//获取报警表未处理的报警记录
    	List<String> warnRecordTagList = new ArrayList<String>();
    	List<Map<String, Object>> warnRecords = masterDB.queryForList("select factory_id,alarm_param_code from alarm_warning_record_history where DATE_FORMAT(record_time,'%Y-%m-%d') ='"+nowDay+"' and handle_status='0'");
    	for(Map<String, Object> warnRecord : warnRecords) {
    		warnRecordTagList.add(ConvertUtils.getString(warnRecord.get("factory_id"))+ConvertUtils.getString(warnRecord.get("alarm_param_code")));
    	}
    	
    	Set<String> factroyIds = configMap.keySet();
    	for(String factoryId : factroyIds) {
    		//获取厂站下的所有未处理预警通知,如果通知未处理,则不进行再次预警
    		//根据厂站获取厂站报警规则
    		Map<String, Object> config = configMap.get(factoryId);
    		String out_level = ConvertUtils.getString(config.get("out_level"),"B").toLowerCase();
    		String factory_name = ConvertUtils.getString(config.get("depart_name"));
    		//获取厂站下的数据采集指标
    		Map<String, Object> map = fieldMap.get(factoryId);
    		if(map==null) {
    			continue;
    		}
    		Set<String> fieldSet=map.keySet();
    		String fields = "";
    		for(String key : fieldSet) {
    			fields = fields+","+((Map)map.get(key)).get("id");
    		}
    		if(!StringUtils.isEmpty(fields)) {
    			fields = fields.substring(1);
    			//获取厂站10分钟的数据,遍历数据,只要有一条预警了,后面数据均不参加预警计算
    			List<Map<String, Object>> dataList = factoryInfoService.queryFactoryInfos(factoryId, fields, sdf.format(afterDate), sdf.format(nowDate), "0");
    			List<Map<String, Object>> yesterdayHourList = factoryInfoService.queryFactoryInfos(factoryId, fields, yesterdayStart, yesterdayEnd, "1");
    			List<Map<String, Object>> yesterdayList = factoryInfoService.handleResult(yesterdayHourList, "d", fields);
    			List<Map<String, Object>> qtHourList = factoryInfoService.queryFactoryInfos(factoryId, fields, qtStart, qtEnd, "1");
    			List<Map<String, Object>> qtList = factoryInfoService.handleResult(qtHourList, "d", fields);
    			List<Map<String, Object>> dqtHourList = factoryInfoService.queryFactoryInfos(factoryId, fields, dqtStart, dqtEnd, "1");
    			List<Map<String, Object>> dqtList = factoryInfoService.handleResult(dqtHourList, "d", fields);
    			Map<String, Object> yesterdayMap = null;
    			if(yesterdayList!=null&&yesterdayList.size()>0) {
    				yesterdayMap = yesterdayList.get(0);
    			}
    			Map<String, Object> qtMap = null;
    			if(qtList!=null&&qtList.size()>0) {
    				qtMap = qtList.get(0);
    			}
    			Map<String, Object> dqtMap = null;
    			if(dqtList!=null&&dqtList.size()>0) {
    				dqtMap = dqtList.get(0);
    			}
    			//预警规则,获取采集频率时间段内的数据
    			for(Map<String,Object> dataMap : dataList) {
    				String time = DateUtils.formatDate(DateUtils.getDate(Long.valueOf(dataMap.get("time").toString()+"000")), "yyyy-MM-dd HH:mm:ss");
    				//处理实时数据
    				//温度
    				Map<String,Object> csswMap = (Map<String,Object>)map.get("CSSW");
    				if(csswMap!=null&&!warnRecordTagList.contains(factoryId+csswMap.get("id"))) {
    					double csswVal = ConvertUtils.getDouble(dataMap.get(csswMap.get("id")),-999);
    					double one_upper = ConvertUtils.getDouble(config.get("sw_one_s_wd"), 0.0);
    					double one_lower = ConvertUtils.getDouble(config.get("sw_one_x_wd"), 0.0);
    					if(csswVal>0&&csswVal<one_lower) {
    						StringBuffer csswWarnMessage = new StringBuffer(); 
    						csswWarnMessage.append(time+","+factory_name+"采集数据触发预警机制,");
    						csswWarnMessage.append("出水水温:瞬时值"+csswVal+ConvertUtils.getString(csswMap.get("metric_unit"))+"小于阈值"+one_lower+",");
    						csswWarnMessage.append("请尽快处理。");
    						executeSql(masterDB,warnRecordTagList,factoryId,csswWarnMessage.toString(),time,csswMap);
    					}
    					if((csswVal>one_upper&&csswVal<50)) {
    						StringBuffer csswWarnMessage = new StringBuffer(); 
    						csswWarnMessage.append(time+","+factory_name+"采集数据触发预警机制,");
    						csswWarnMessage.append("出水水温:瞬时值"+csswVal+ConvertUtils.getString(csswMap.get("metric_unit"))+"大于阈值"+one_upper+",");
    						csswWarnMessage.append("请尽快处理。");
    						executeSql(masterDB,warnRecordTagList,factoryId,csswWarnMessage.toString(),time,csswMap);
    					}
    					
    				}
    				//cod
    				//获取出水cod的实时值
    				Map<String,Object> codMap = (Map<String,Object>)map.get("CSCOD");
    				if(codMap!=null&&!warnRecordTagList.contains(factoryId+codMap.get("id"))) {
    					//如果预警存在未处理的情况则不进行预警插入
    					double codVal = ConvertUtils.getDouble(dataMap.get(codMap.get("id")),-999);
        				if(codVal == -999) {
        					log.info("cod数据采集断线");
        				}else {
        					StringBuffer codWarnMessage = new StringBuffer(); 
        					codWarnMessage.append(""+time+","+factory_name+"采集数据触发预警机制,");
        					boolean codWarnTag = false;
            				//判断规则1
            				double one_upper = ConvertUtils.getDouble(config.get("cod_one_"+out_level+"_ssz"), 0.0);
            				double one_alarm_upper = ConvertUtils.getDouble(outLevelMap.get(out_level+"_cod"), 0.0);
            				if(codVal>one_upper&&codVal<one_alarm_upper) {
            					codWarnTag = true;
            					codWarnMessage.append("出水COD:瞬时值"+codVal+ConvertUtils.getString(codMap.get("metric_unit"))+"大于阈值"+one_upper+",");
            				}
            				//判断规则2
            				double second_upper = ConvertUtils.getDouble(config.get("cod_second_ssz"), 0.0);
            				if(yesterdayMap!=null&&yesterdayMap.size()>0) {
            					double rjz = DoubleOperaUtils.bigDecimalRound(ConvertUtils.getDouble(yesterdayMap.get(codMap.get("id")), 0.0)/ConvertUtils.getDouble(yesterdayMap.get(codMap.get("id")+"_tag"), 1), 2);
            					double diffVal = codVal - rjz;
            					if(diffVal>second_upper) {
            						codWarnTag = true;
            						codWarnMessage.append("出水COD:瞬时值【"+codVal+"】-昨日日均值【"+rjz+"】="+diffVal+ConvertUtils.getString(codMap.get("metric_unit"))+"大于阈值"+second_upper+",");
            					}
            				}
            				//判断规则3
            				double three_rjz_upper = ConvertUtils.getDouble(config.get("cod_three_rjz"), 0.0);
            				double three_ssz_upper = ConvertUtils.getDouble(config.get("cod_three_"+out_level+"_ssz"), 0.0);
            				if(yesterdayMap!=null&&yesterdayMap.size()>0&&qtMap!=null&&qtMap.size()>0&&dqtMap!=null&&dqtMap.size()>0) {
            					double yesDiffVal = DoubleOperaUtils.bigDecimalRound(ConvertUtils.getDouble(yesterdayMap.get(codMap.get("id")), 0.0)/ConvertUtils.getDouble(yesterdayMap.get(codMap.get("id")+"_tag"), 1), 2);
            					double qtDiffVal = DoubleOperaUtils.bigDecimalRound(ConvertUtils.getDouble(qtMap.get(codMap.get("id")), 0.0)/ConvertUtils.getDouble(qtMap.get(codMap.get("id")+"_tag"), 1), 2);
            					double dqtDiffVal = DoubleOperaUtils.bigDecimalRound(ConvertUtils.getDouble(dqtMap.get(codMap.get("id")), 0.0)/ConvertUtils.getDouble(dqtMap.get(codMap.get("id")+"_tag"), 1), 2);
            					if(((yesDiffVal-qtDiffVal)/qtDiffVal*100)>three_rjz_upper&&((qtDiffVal-dqtDiffVal)/dqtDiffVal*100)>three_rjz_upper&&codVal>three_ssz_upper) {
            						codWarnTag = true;
            						codWarnMessage.append("出水COD:日均值连续两天上涨大于"+three_rjz_upper+"%,且瞬时值"+codVal+ConvertUtils.getString(codMap.get("metric_unit"))+"大于阈值"+three_ssz_upper+",");
            					}
            				}
            				//预警入库操作,判断条件,如果该指标未处理,则不进行数据插入
            				if(codWarnTag) {
            					codWarnMessage.append("请尽快处理。");
            					executeSql(masterDB,warnRecordTagList,factoryId,codWarnMessage.toString(),time,codMap);
            				}
        				}
    				}
    				
    				//获取出水氨氮的实时值
    				Map<String,Object> nh3Map = (Map<String,Object>)map.get("CSNH3N");
    				if(nh3Map!=null&&!warnRecordTagList.contains(factoryId+nh3Map.get("id"))) {
    					double nh3Val = ConvertUtils.getDouble(dataMap.get(nh3Map.get("id")),-999);
        				Map<String,Object> swMap = (Map<String,Object>)map.get("CSSW");
        				double swVal = 13;
        				if(swMap!=null&&swMap.size()>0) {
        					swVal = ConvertUtils.getDouble(dataMap.get(swMap.get("id")),13);
        				}
        				
        				//获取水温
        				if(nh3Val == -999) {
        					log.info("氨氮数据采集断线");
        				}else {
        					StringBuffer nh3WarnMessage = new StringBuffer();  
        					nh3WarnMessage.append(""+time+","+factory_name+"采集数据触发预警机制,");
        					boolean nh3WarnTag = false;
            				//判断规则1
        					double one_upper = 0;
        					double one_alarm_upper = 0;
        					if(swVal>12) {
        						one_upper = ConvertUtils.getDouble(config.get("nh3_one_"+out_level+"_12s_ssz"), 0.0);
        						one_alarm_upper = ConvertUtils.getDouble(outLevelMap.get(out_level+"_nh3_12s"), 0.0);
        					}else {
        						one_upper = ConvertUtils.getDouble(config.get("nh3_one_"+out_level+"_12x_ssz"), 0.0);
        						one_alarm_upper = ConvertUtils.getDouble(outLevelMap.get(out_level+"_nh3_12x"), 0.0);
        					}

            				if(nh3Val>one_upper&&nh3Val<one_alarm_upper) {
            					nh3WarnMessage.append("出水氨氮:瞬时值"+nh3Val+ConvertUtils.getString(nh3Map.get("metric_unit"))+"大于阈值"+one_upper+",");
            					nh3WarnTag = true;
            				}
            				//判断规则2
            				double second_upper = ConvertUtils.getDouble(config.get("nh3_second_"+out_level+"_ssz"), 0.0);
            				if(yesterdayMap!=null&&yesterdayMap.size()>0) {
            					double rjz = DoubleOperaUtils.bigDecimalRound(ConvertUtils.getDouble(yesterdayMap.get(nh3Map.get("id")), 0.0)/ConvertUtils.getDouble(yesterdayMap.get(nh3Map.get("id")+"_tag"), 1), 2);
            					double diffVal = nh3Val - rjz;
            					if(diffVal>second_upper) {
            						nh3WarnMessage.append("出水氨氮:瞬时值【"+nh3Val+"】-昨日日均值【"+rjz+"】="+diffVal+ConvertUtils.getString(nh3Map.get("metric_unit"))+"大于阈值"+second_upper+",");
            						nh3WarnTag = true;
            					}
            				}
            				//判断规则3
            				double three_rjz_upper = ConvertUtils.getDouble(config.get("nh3_three_rjz"), 0.0);
            				double three_ssz_upper = ConvertUtils.getDouble(config.get("nh3_three_"+out_level+"_ssz"), 0.0);
            				if(yesterdayMap!=null&&yesterdayMap.size()>0&&qtMap!=null&&qtMap.size()>0&&dqtMap!=null&&dqtMap.size()>0) {
            					double yesDiffVal = DoubleOperaUtils.bigDecimalRound(ConvertUtils.getDouble(yesterdayMap.get(nh3Map.get("id")), 0.0)/ConvertUtils.getDouble(yesterdayMap.get(nh3Map.get("id")+"_tag"), 1), 2);
            					double qtDiffVal = DoubleOperaUtils.bigDecimalRound(ConvertUtils.getDouble(qtMap.get(nh3Map.get("id")), 0.0)/ConvertUtils.getDouble(qtMap.get(nh3Map.get("id")+"_tag"), 1), 2);
            					double dqtDiffVal = DoubleOperaUtils.bigDecimalRound(ConvertUtils.getDouble(dqtMap.get(nh3Map.get("id")), 0.0)/ConvertUtils.getDouble(dqtMap.get(nh3Map.get("id")+"_tag"), 1), 2);
            					if(((yesDiffVal-qtDiffVal)/qtDiffVal*100)>three_rjz_upper&&((qtDiffVal-dqtDiffVal)/dqtDiffVal*100)>three_rjz_upper&&nh3Val>three_ssz_upper) {
            						nh3WarnMessage.append("出水氨氮:日均值连续两天上涨大于"+three_rjz_upper+"%,且瞬时值"+nh3Val+ConvertUtils.getString(nh3Map.get("metric_unit"))+"大于阈值"+three_ssz_upper+",");
            						nh3WarnTag = true;
            					}
            				}
            				//预警入库操作,判断条件,如果该指标未处理,则不进行数据插入
            				if(nh3WarnTag) {
            					nh3WarnMessage.append("请尽快处理。");
            					executeSql(masterDB,warnRecordTagList,factoryId,nh3WarnMessage.toString(),time,nh3Map);
            				}
        				}
    				}
    				//总磷
    				//获取出水总磷的实时值
    				Map<String,Object> tpMap = (Map<String,Object>)map.get("CSTP");
    				if(tpMap!=null&&!warnRecordTagList.contains(factoryId+tpMap.get("id"))) {
    					double tpVal = ConvertUtils.getDouble(dataMap.get(tpMap.get("id")),-999);
        				if(tpVal == -999) {
        					log.info("总磷数据采集断线");
        				}else {
        					StringBuffer tpWarnMessage = new StringBuffer();
        					tpWarnMessage.append(""+time+","+factory_name+"采集数据触发预警机制,");
        					boolean tpWarnTag = false;
            				//判断规则1
            				double one_upper = ConvertUtils.getDouble(config.get("tp_one_"+out_level+"_ssz"), 0.0);
            				double one_alarm_upper = ConvertUtils.getDouble(outLevelMap.get(out_level+"_tp"), 0.0);
            				if(tpVal>one_upper&&tpVal<one_alarm_upper) {
            					tpWarnMessage.append("出水总磷:瞬时值"+tpVal+ConvertUtils.getString(tpMap.get("metric_unit"))+"大于阈值"+one_upper+",");
            					tpWarnTag = true;
            				}
            				//判断规则3
            				double three_rjz_upper = ConvertUtils.getDouble(config.get("tp_three_rjz"), 0.0);
            				double three_ssz_upper = ConvertUtils.getDouble(config.get("tp_three_"+out_level+"_ssz"), 0.0);
            				if(yesterdayMap!=null&&yesterdayMap.size()>0&&qtMap!=null&&qtMap.size()>0&&dqtMap!=null&&dqtMap.size()>0) {
            					double yesDiffVal = DoubleOperaUtils.bigDecimalRound(ConvertUtils.getDouble(yesterdayMap.get(tpMap.get("id")), 0.0)/ConvertUtils.getDouble(yesterdayMap.get(tpMap.get("id")+"_tag"), 1), 2);
            					double qtDiffVal = DoubleOperaUtils.bigDecimalRound(ConvertUtils.getDouble(qtMap.get(tpMap.get("id")), 0.0)/ConvertUtils.getDouble(qtMap.get(tpMap.get("id")+"_tag"), 1), 2);
            					double dqtDiffVal = DoubleOperaUtils.bigDecimalRound(ConvertUtils.getDouble(dqtMap.get(tpMap.get("id")), 0.0)/ConvertUtils.getDouble(dqtMap.get(tpMap.get("id")+"_tag"), 1), 2);
            					if(((yesDiffVal-qtDiffVal)/qtDiffVal*100)>three_rjz_upper&&((qtDiffVal-dqtDiffVal)/dqtDiffVal*100)>three_rjz_upper&&tpVal>three_ssz_upper) {
            						tpWarnMessage.append("出水总磷:日均值连续两天上涨大于"+three_rjz_upper+"%,且瞬时值"+tpVal+ConvertUtils.getString(tpMap.get("metric_unit"))+"大于阈值"+three_ssz_upper+",");
            						tpWarnTag = true;
            					}
            				}
            				//预警入库操作,判断条件,如果该指标未处理,则不进行数据插入
            				if(tpWarnTag) {
            					tpWarnMessage.append("请尽快处理。");
            					executeSql(masterDB,warnRecordTagList,factoryId,tpWarnMessage.toString(),time,tpMap);
            				}
        				}
    				}
    				//总氮
    				//获取出水总氮的实时值
    				Map<String,Object> tnMap = (Map<String,Object>)map.get("CSTN");
    				if(tnMap!=null&&!warnRecordTagList.contains(factoryId+tnMap.get("id"))) {
    					double tnVal = ConvertUtils.getDouble(dataMap.get(tnMap.get("id")),-999);
        				if(tnVal == -999) {
        					log.info("总氮数据采集断线");
        				}else {
        					StringBuffer tnWarnMessage = new StringBuffer();  
        					tnWarnMessage.append(""+time+","+factory_name+"采集数据触发预警机制,");
        					boolean tnWarnTag = false;
            				//判断规则1
            				double one_upper = ConvertUtils.getDouble(config.get("tn_one_"+out_level+"_ssz"), 0.0);
            				double one_alarm_upper = ConvertUtils.getDouble(outLevelMap.get(out_level+"_tn"), 0.0);
            				if(tnVal>one_upper&&tnVal<one_alarm_upper) {
            					tnWarnMessage.append("出水总氮:瞬时值"+tnVal+ConvertUtils.getString(tnMap.get("metric_unit"))+"大于阈值"+one_upper+",");
            					tnWarnTag = true;
            				}
            				//判断规则2
            				double second_upper = ConvertUtils.getDouble(config.get("tn_second_"+out_level+"_ssz"), 0.0);
            				if(yesterdayMap!=null&&yesterdayMap.size()>0) {
            					double rjz = DoubleOperaUtils.bigDecimalRound(ConvertUtils.getDouble(yesterdayMap.get(tnMap.get("id")), 0.0)/ConvertUtils.getDouble(yesterdayMap.get(tnMap.get("id")+"_tag"), 1), 2);
            					double diffVal = tnVal - rjz;
            					if(diffVal>second_upper) {
            						tnWarnMessage.append("出水总氮:瞬时值【"+tnVal+"】-昨日日均值【"+rjz+"】="+diffVal+ConvertUtils.getString(tnMap.get("metric_unit"))+"大于阈值"+second_upper+",");
            						tnWarnTag = true;
            					}
            				}
            				//判断规则3
            				double three_rjz_upper = ConvertUtils.getDouble(config.get("tn_three_rjz"), 0.0);
            				double three_ssz_upper = ConvertUtils.getDouble(config.get("tn_three_"+out_level+"_ssz"), 0.0);
            				if(yesterdayMap!=null&&yesterdayMap.size()>0&&qtMap!=null&&qtMap.size()>0&&dqtMap!=null&&dqtMap.size()>0) {
            					double yesDiffVal = DoubleOperaUtils.bigDecimalRound(ConvertUtils.getDouble(yesterdayMap.get(tnMap.get("id")), 0.0)/ConvertUtils.getDouble(yesterdayMap.get(tnMap.get("id")+"_tag"), 1), 2);
            					double qtDiffVal = DoubleOperaUtils.bigDecimalRound(ConvertUtils.getDouble(qtMap.get(tnMap.get("id")), 0.0)/ConvertUtils.getDouble(qtMap.get(tnMap.get("id")+"_tag"), 1), 2);
            					double dqtDiffVal = DoubleOperaUtils.bigDecimalRound(ConvertUtils.getDouble(dqtMap.get(tnMap.get("id")), 0.0)/ConvertUtils.getDouble(dqtMap.get(tnMap.get("id")+"_tag"), 1), 2);
            					if(((yesDiffVal-qtDiffVal)/qtDiffVal*100)>three_rjz_upper&&((qtDiffVal-dqtDiffVal)/dqtDiffVal*100)>three_rjz_upper&&tnVal>three_ssz_upper) {
            						tnWarnMessage.append("出水总氮:日均值连续两天上涨大于"+three_rjz_upper+"%,且瞬时值"+tnVal+ConvertUtils.getString(tnMap.get("metric_unit"))+"大于阈值"+three_ssz_upper+",");
            						tnWarnTag = true;
            					}
            				}
            				//预警入库操作,判断条件,如果该指标未处理,则不进行数据插入
            				if(tnWarnTag) {
            					tnWarnMessage.append("请尽快处理。");
            					executeSql(masterDB,warnRecordTagList,factoryId,tnWarnMessage.toString(),time,tnMap);
            				}
        				}
    				}
    			}
    		}
    	}
        System.out.println("********预警监测定时服务结束********");
    }
    /**
     * <pre>
     * 预警插入逻辑
     * </pre>
     * @param masterDB
     * @param warnRecordTagList
     * @param factoryId
     * @param warnMessage
     * @param time
     * @param fieldMap
     * @author Li Yuanyuan, 2021年3月23日 下午3:31:17
     */
    public void executeSql(JdbcTemplate masterDB,List<String> warnRecordTagList,String factoryId,String warnMessage,String time,Map<String,Object> fieldMap) {
    	String sql="insert into alarm_warning_record_history(id,alarm_param_code,alarm_param_name,alarm_param_unit,factory_id,record_time,handle_status,alarm_content,create_time)VALUES('"+sequenceService.nextId()+"','"+fieldMap.get("id")+"','"+fieldMap.get("metric_name")+"','"+ConvertUtils.getString(fieldMap.get("metric_unit"))+"','"+factoryId+"','"+time+"','0','"+warnMessage+"','"+DateUtils.now()+"')";
		masterDB.execute(sql);
		warnRecordTagList.add(factoryId+fieldMap.get("id"));
    }
}