package com.huimv.admin.timer; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.huimv.admin.common.utils.NumberUtils; import com.huimv.admin.entity.GasData; import com.huimv.admin.entity.GasThreshold; import com.huimv.admin.entity.GasWarningInfo; import com.huimv.admin.mapper.GasDataMapper; import com.huimv.admin.mapper.GasThresholdMapper; import com.huimv.admin.mapper.GasWarningInfoMapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.Scheduled; import java.util.Date; @Configuration @EnableScheduling public class GasTimer { @Autowired private GasDataMapper gasDataMapper; @Autowired private GasWarningInfoMapper warningInfoMapper; @Autowired private GasThresholdMapper thresholdMapper; @Scheduled(cron = "0 0 */1 * * ? ") private void getShenChan() throws Exception { String type = NumberUtils.getNum(1, 5, 0);//loc_type for (int i = 1; i < 5; i++) { String nh3n = NumberUtils.getNumFloat(0.0, 10.5);//NH3N String jlm = NumberUtils.getNumFloat(0.0, 10.5);//jlm String elht = NumberUtils.getNumFloat(0.0, 10.5);//elht String ejel = NumberUtils.getNumFloat(0.0, 10.5);//ejel String h2s = NumberUtils.getNumFloat(0.0, 10.5);//h2s String byx = NumberUtils.getNumFloat(0.0, 20.5);//byx String ch3 = NumberUtils.getNumFloat(0.0, 10.5);//ch3 String sja = NumberUtils.getNumFloat(0.0,10.5);//sja GasData gasData = new GasData(); gasData.setLoctionType(i); gasData.setNh3N(nh3n); gasData.setJlm(jlm); gasData.setElht(elht); gasData.setEjel(ejel); gasData.setH2s(h2s); gasData.setByx(byx); gasData.setCh3sh(ch3); gasData.setSja(sja); gasData.setFarmId(21); gasData.setCreateTime(new Date()); QueryWrapper queryWrapper = new QueryWrapper<>(); GasWarningInfo warningInfo = new GasWarningInfo(); if (i==1) { String cq = NumberUtils.getNumFloat(0.0, 1000.5);//cq gasData.setCq(cq); queryWrapper.eq("farm_id", 21).eq("gas_type", 1); GasThreshold gasThreshold = thresholdMapper.selectOne(queryWrapper); if (Double.parseDouble(nh3n) > Double.parseDouble(gasThreshold.getNh3N())) { warningInfo.setWarningContent("NH3N为"+nh3n + "超过阈值,系统预警提醒"); warningInfo.setWarningType(0); warningInfo.setBuildLocation("屋顶"); warningInfo.setDate(new Date()); warningInfo.setFarmId(gasThreshold.getFarmId()); warningInfo.setUserIds(gasThreshold.getUserIds()); warningInfoMapper.insert(warningInfo); } if (Double.parseDouble(jlm) > Double.parseDouble(gasThreshold.getJlm())) { warningInfo.setWarningContent("甲硫醚为"+jlm + "超过阈值,系统预警提醒"); warningInfo.setWarningType(1); warningInfo.setBuildLocation("屋顶"); warningInfo.setDate(new Date()); warningInfo.setFarmId(gasThreshold.getFarmId()); warningInfo.setUserIds(gasThreshold.getUserIds()); warningInfoMapper.insert(warningInfo); } if (Double.parseDouble(elht) > Double.parseDouble(gasThreshold.getElht())) { warningInfo.setWarningContent("二硫化碳为"+elht + "超过阈值,系统预警提醒"); warningInfo.setWarningType(2); warningInfo.setBuildLocation("屋顶"); warningInfo.setDate(new Date()); warningInfo.setFarmId(gasThreshold.getFarmId()); warningInfo.setUserIds(gasThreshold.getUserIds()); warningInfoMapper.insert(warningInfo); } if (Double.parseDouble(ejel) > Double.parseDouble(gasThreshold.getEjel())) { warningInfo.setWarningContent("二甲二硫为"+ejel + "超过阈值,系统预警提醒"); warningInfo.setWarningType(3); warningInfo.setBuildLocation("屋顶"); warningInfo.setDate(new Date()); warningInfo.setFarmId(gasThreshold.getFarmId()); warningInfo.setUserIds(gasThreshold.getUserIds()); warningInfoMapper.insert(warningInfo); } if (Double.parseDouble(h2s) > Double.parseDouble(gasThreshold.getH2s())) { warningInfo.setWarningContent("H2S为"+h2s + "超过阈值,系统预警提醒"); warningInfo.setWarningType(4); warningInfo.setBuildLocation("屋顶"); warningInfo.setDate(new Date()); warningInfo.setFarmId(gasThreshold.getFarmId()); warningInfo.setUserIds(gasThreshold.getUserIds()); warningInfoMapper.insert(warningInfo); } if (Double.parseDouble(byx) > Double.parseDouble(gasThreshold.getByx())) { warningInfo.setWarningContent("苯乙烯为"+byx + "超过阈值,系统预警提醒"); warningInfo.setWarningType(5); warningInfo.setBuildLocation("屋顶"); warningInfo.setDate(new Date()); warningInfo.setFarmId(gasThreshold.getFarmId()); warningInfo.setUserIds(gasThreshold.getUserIds()); warningInfoMapper.insert(warningInfo); } if (Double.parseDouble(ch3) > Double.parseDouble(gasThreshold.getCh3sh())) { warningInfo.setWarningContent("CH3SH为"+ch3 + "超过阈值,系统预警提醒"); warningInfo.setWarningType(6); warningInfo.setBuildLocation("屋顶"); warningInfo.setDate(new Date()); warningInfo.setFarmId(gasThreshold.getFarmId()); warningInfo.setUserIds(gasThreshold.getUserIds()); warningInfoMapper.insert(warningInfo); } if (Double.parseDouble(sja) > Double.parseDouble(gasThreshold.getSja())) { warningInfo.setWarningContent("三甲胺为"+sja + "超过阈值,系统预警提醒"); warningInfo.setWarningType(7); warningInfo.setBuildLocation("屋顶"); warningInfo.setDate(new Date()); warningInfo.setFarmId(gasThreshold.getFarmId()); warningInfo.setUserIds(gasThreshold.getUserIds()); warningInfoMapper.insert(warningInfo); } if (Double.parseDouble(cq) > Double.parseDouble(gasThreshold.getCq())) { warningInfo.setWarningContent("臭气为"+cq + "超过阈值,系统预警提醒"); warningInfo.setWarningType(8); warningInfo.setBuildLocation("屋顶"); warningInfo.setDate(new Date()); warningInfo.setFarmId(gasThreshold.getFarmId()); warningInfo.setUserIds(gasThreshold.getUserIds()); warningInfoMapper.insert(warningInfo); } } else if (i==2) { String cq = NumberUtils.getNumFloat(0.0, 5000.5);//cq gasData.setCq(cq); queryWrapper.eq("farm_id", 21).eq("gas_type", 2); GasThreshold gasThreshold = thresholdMapper.selectOne(queryWrapper); if (Double.parseDouble(nh3n) > Double.parseDouble(gasThreshold.getNh3N())) { warningInfo.setWarningContent("NH3N为"+nh3n + "超过阈值,系统预警提醒"); warningInfo.setWarningType(0); warningInfo.setBuildLocation("厂界上"); warningInfo.setDate(new Date()); warningInfo.setFarmId(gasThreshold.getFarmId()); warningInfo.setUserIds(gasThreshold.getUserIds()); warningInfoMapper.insert(warningInfo); } if (Double.parseDouble(jlm) > Double.parseDouble(gasThreshold.getJlm())) { warningInfo.setWarningContent("甲硫醚为"+jlm + "超过阈值,系统预警提醒"); warningInfo.setWarningType(1); warningInfo.setBuildLocation("厂界上"); warningInfo.setDate(new Date()); warningInfo.setFarmId(gasThreshold.getFarmId()); warningInfo.setUserIds(gasThreshold.getUserIds()); warningInfoMapper.insert(warningInfo); } if (Double.parseDouble(elht) > Double.parseDouble(gasThreshold.getElht())) { warningInfo.setWarningContent("二硫化碳为"+elht + "超过阈值,系统预警提醒"); warningInfo.setWarningType(2); warningInfo.setBuildLocation("厂界上"); warningInfo.setDate(new Date()); warningInfo.setFarmId(gasThreshold.getFarmId()); warningInfo.setUserIds(gasThreshold.getUserIds()); warningInfoMapper.insert(warningInfo); } if (Double.parseDouble(ejel) > Double.parseDouble(gasThreshold.getEjel())) { warningInfo.setWarningContent("二甲二硫为"+ejel + "超过阈值,系统预警提醒"); warningInfo.setWarningType(3); warningInfo.setBuildLocation("厂界上"); warningInfo.setDate(new Date()); warningInfo.setFarmId(gasThreshold.getFarmId()); warningInfo.setUserIds(gasThreshold.getUserIds()); warningInfoMapper.insert(warningInfo); } if (Double.parseDouble(h2s) > Double.parseDouble(gasThreshold.getH2s())) { warningInfo.setWarningContent("H2S为"+h2s + "超过阈值,系统预警提醒"); warningInfo.setWarningType(4); warningInfo.setBuildLocation("厂界上"); warningInfo.setDate(new Date()); warningInfo.setFarmId(gasThreshold.getFarmId()); warningInfo.setUserIds(gasThreshold.getUserIds()); warningInfoMapper.insert(warningInfo); } if (Double.parseDouble(byx) > Double.parseDouble(gasThreshold.getByx())) { warningInfo.setWarningContent("苯乙烯为"+byx + "超过阈值,系统预警提醒"); warningInfo.setWarningType(5); warningInfo.setBuildLocation("厂界上"); warningInfo.setDate(new Date()); warningInfo.setFarmId(gasThreshold.getFarmId()); warningInfo.setUserIds(gasThreshold.getUserIds()); warningInfoMapper.insert(warningInfo); } if (Double.parseDouble(ch3) > Double.parseDouble(gasThreshold.getCh3sh())) { warningInfo.setWarningContent("CH3SH为"+ch3 + "超过阈值,系统预警提醒"); warningInfo.setWarningType(6); warningInfo.setBuildLocation("厂界上"); warningInfo.setDate(new Date()); warningInfo.setFarmId(gasThreshold.getFarmId()); warningInfo.setUserIds(gasThreshold.getUserIds()); warningInfoMapper.insert(warningInfo); } if (Double.parseDouble(sja) > Double.parseDouble(gasThreshold.getSja())) { warningInfo.setWarningContent("三甲胺为"+sja + "超过阈值,系统预警提醒"); warningInfo.setWarningType(7); warningInfo.setBuildLocation("厂界上"); warningInfo.setDate(new Date()); warningInfo.setFarmId(gasThreshold.getFarmId()); warningInfo.setUserIds(gasThreshold.getUserIds()); warningInfoMapper.insert(warningInfo); } if (Double.parseDouble(cq) > Double.parseDouble(gasThreshold.getCq())) { warningInfo.setWarningContent("臭气为"+cq + "超过阈值,系统预警提醒"); warningInfo.setWarningType(8); warningInfo.setBuildLocation("厂界上"); warningInfo.setDate(new Date()); warningInfo.setFarmId(gasThreshold.getFarmId()); warningInfo.setUserIds(gasThreshold.getUserIds()); warningInfoMapper.insert(warningInfo); } } else if (i==3) { String cq = NumberUtils.getNumFloat(0.0, 1000.5);//cq gasData.setCq(cq); queryWrapper.eq("farm_id", 21).eq("gas_type", 3); GasThreshold gasThreshold = thresholdMapper.selectOne(queryWrapper); if (Double.parseDouble(nh3n) > Double.parseDouble(gasThreshold.getNh3N())) { warningInfo.setWarningContent("NH3N为"+nh3n + "超过阈值,系统预警提醒"); warningInfo.setWarningType(0); warningInfo.setBuildLocation("厂界下"); warningInfo.setDate(new Date()); warningInfo.setFarmId(gasThreshold.getFarmId()); warningInfo.setUserIds(gasThreshold.getUserIds()); warningInfoMapper.insert(warningInfo); } if (Double.parseDouble(jlm) > Double.parseDouble(gasThreshold.getJlm())) { warningInfo.setWarningContent("甲硫醚为"+jlm + "超过阈值,系统预警提醒"); warningInfo.setWarningType(1); warningInfo.setBuildLocation("厂界下"); warningInfo.setDate(new Date()); warningInfo.setFarmId(gasThreshold.getFarmId()); warningInfo.setUserIds(gasThreshold.getUserIds()); warningInfoMapper.insert(warningInfo); } if (Double.parseDouble(elht) > Double.parseDouble(gasThreshold.getElht())) { warningInfo.setWarningContent("二硫化碳为"+elht + "超过阈值,系统预警提醒"); warningInfo.setWarningType(2); warningInfo.setBuildLocation("厂界下"); warningInfo.setDate(new Date()); warningInfo.setFarmId(gasThreshold.getFarmId()); warningInfo.setUserIds(gasThreshold.getUserIds()); warningInfoMapper.insert(warningInfo); } if (Double.parseDouble(ejel) > Double.parseDouble(gasThreshold.getEjel())) { warningInfo.setWarningContent("二甲二硫为"+ejel + "超过阈值,系统预警提醒"); warningInfo.setWarningType(3); warningInfo.setBuildLocation("厂界下"); warningInfo.setDate(new Date()); warningInfo.setFarmId(gasThreshold.getFarmId()); warningInfo.setUserIds(gasThreshold.getUserIds()); warningInfoMapper.insert(warningInfo); } if (Double.parseDouble(h2s) > Double.parseDouble(gasThreshold.getH2s())) { warningInfo.setWarningContent("H2S为"+h2s + "超过阈值,系统预警提醒"); warningInfo.setWarningType(4); warningInfo.setBuildLocation("厂界下"); warningInfo.setDate(new Date()); warningInfo.setFarmId(gasThreshold.getFarmId()); warningInfo.setUserIds(gasThreshold.getUserIds()); warningInfoMapper.insert(warningInfo); } if (Double.parseDouble(byx) > Double.parseDouble(gasThreshold.getByx())) { warningInfo.setWarningContent("苯乙烯为"+byx + "超过阈值,系统预警提醒"); warningInfo.setWarningType(5); warningInfo.setBuildLocation("厂界下"); warningInfo.setDate(new Date()); warningInfo.setFarmId(gasThreshold.getFarmId()); warningInfo.setUserIds(gasThreshold.getUserIds()); warningInfoMapper.insert(warningInfo); } if (Double.parseDouble(ch3) > Double.parseDouble(gasThreshold.getCh3sh())) { warningInfo.setWarningContent("CH3SH为"+ch3 + "超过阈值,系统预警提醒"); warningInfo.setWarningType(6); warningInfo.setBuildLocation("厂界下"); warningInfo.setDate(new Date()); warningInfo.setFarmId(gasThreshold.getFarmId()); warningInfo.setUserIds(gasThreshold.getUserIds()); warningInfoMapper.insert(warningInfo); } if (Double.parseDouble(sja) > Double.parseDouble(gasThreshold.getSja())) { warningInfo.setWarningContent("三甲胺为"+sja + "超过阈值,系统预警提醒"); warningInfo.setWarningType(7); warningInfo.setBuildLocation("厂界下"); warningInfo.setDate(new Date()); warningInfo.setFarmId(gasThreshold.getFarmId()); warningInfo.setUserIds(gasThreshold.getUserIds()); warningInfoMapper.insert(warningInfo); } if (Double.parseDouble(cq) > Double.parseDouble(gasThreshold.getCq())) { warningInfo.setWarningContent("臭气为"+cq + "超过阈值,系统预警提醒"); warningInfo.setWarningType(8); warningInfo.setBuildLocation("厂界下"); warningInfo.setDate(new Date()); warningInfo.setFarmId(gasThreshold.getFarmId()); warningInfo.setUserIds(gasThreshold.getUserIds()); warningInfoMapper.insert(warningInfo); } } else if (i==4) { String cq = NumberUtils.getNumFloat(0.0, 10000.5);//cq gasData.setCq(cq); queryWrapper.eq("farm_id", 21).eq("gas_type", 4); GasThreshold gasThreshold = thresholdMapper.selectOne(queryWrapper); if (Double.parseDouble(nh3n) > Double.parseDouble(gasThreshold.getNh3N())) { warningInfo.setWarningContent("NH3N为"+nh3n + "超过阈值,系统预警提醒"); warningInfo.setWarningType(0); warningInfo.setBuildLocation("厂界居民"); warningInfo.setDate(new Date()); warningInfo.setFarmId(gasThreshold.getFarmId()); warningInfo.setUserIds(gasThreshold.getUserIds()); warningInfoMapper.insert(warningInfo); } if (Double.parseDouble(jlm) > Double.parseDouble(gasThreshold.getJlm())) { warningInfo.setWarningContent("甲硫醚为"+jlm + "超过阈值,系统预警提醒"); warningInfo.setWarningType(1); warningInfo.setBuildLocation("厂界居民"); warningInfo.setDate(new Date()); warningInfo.setFarmId(gasThreshold.getFarmId()); warningInfo.setUserIds(gasThreshold.getUserIds()); warningInfoMapper.insert(warningInfo); } if (Double.parseDouble(elht) > Double.parseDouble(gasThreshold.getElht())) { warningInfo.setWarningContent("二硫化碳为"+elht + "超过阈值,系统预警提醒"); warningInfo.setWarningType(2); warningInfo.setBuildLocation("厂界居民"); warningInfo.setDate(new Date()); warningInfo.setFarmId(gasThreshold.getFarmId()); warningInfo.setUserIds(gasThreshold.getUserIds()); warningInfoMapper.insert(warningInfo); } if (Double.parseDouble(ejel) > Double.parseDouble(gasThreshold.getEjel())) { warningInfo.setWarningContent("二甲二硫为"+ejel + "超过阈值,系统预警提醒"); warningInfo.setWarningType(3); warningInfo.setBuildLocation("厂界居民"); warningInfo.setDate(new Date()); warningInfo.setFarmId(gasThreshold.getFarmId()); warningInfo.setUserIds(gasThreshold.getUserIds()); warningInfoMapper.insert(warningInfo); } if (Double.parseDouble(h2s) > Double.parseDouble(gasThreshold.getH2s())) { warningInfo.setWarningContent("H2S为"+h2s + "超过阈值,系统预警提醒"); warningInfo.setWarningType(4); warningInfo.setBuildLocation("厂界居民"); warningInfo.setDate(new Date()); warningInfo.setFarmId(gasThreshold.getFarmId()); warningInfo.setUserIds(gasThreshold.getUserIds()); warningInfoMapper.insert(warningInfo); } if (Double.parseDouble(byx) > Double.parseDouble(gasThreshold.getByx())) { warningInfo.setWarningContent("苯乙烯为"+byx + "超过阈值,系统预警提醒"); warningInfo.setWarningType(5); warningInfo.setBuildLocation("厂界居民"); warningInfo.setDate(new Date()); warningInfo.setFarmId(gasThreshold.getFarmId()); warningInfo.setUserIds(gasThreshold.getUserIds()); warningInfoMapper.insert(warningInfo); } if (Double.parseDouble(ch3) > Double.parseDouble(gasThreshold.getCh3sh())) { warningInfo.setWarningContent("CH3SH为"+ch3 + "超过阈值,系统预警提醒"); warningInfo.setWarningType(6); warningInfo.setBuildLocation("厂界居民"); warningInfo.setDate(new Date()); warningInfo.setFarmId(gasThreshold.getFarmId()); warningInfo.setUserIds(gasThreshold.getUserIds()); warningInfoMapper.insert(warningInfo); } if (Double.parseDouble(sja) > Double.parseDouble(gasThreshold.getSja())) { warningInfo.setWarningContent("三甲胺为"+sja + "超过阈值,系统预警提醒"); warningInfo.setWarningType(7); warningInfo.setBuildLocation("厂界居民"); warningInfo.setDate(new Date()); warningInfo.setFarmId(gasThreshold.getFarmId()); warningInfo.setUserIds(gasThreshold.getUserIds()); warningInfoMapper.insert(warningInfo); } if (Double.parseDouble(cq) > Double.parseDouble(gasThreshold.getCq())) { warningInfo.setWarningContent("臭气为"+cq + "超过阈值,系统预警提醒"); warningInfo.setWarningType(8); warningInfo.setBuildLocation("厂界居民"); warningInfo.setDate(new Date()); warningInfo.setFarmId(gasThreshold.getFarmId()); warningInfo.setUserIds(gasThreshold.getUserIds()); warningInfoMapper.insert(warningInfo); } } gasDataMapper.insert(gasData); } } }