|
@@ -0,0 +1,183 @@
|
|
|
+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.ProtData;
|
|
|
+import com.huimv.admin.entity.ProtThreshold;
|
|
|
+import com.huimv.admin.entity.ProtWarningInfo;
|
|
|
+import com.huimv.admin.mapper.ProtDataMapper;
|
|
|
+import com.huimv.admin.mapper.ProtThresholdMapper;
|
|
|
+import com.huimv.admin.mapper.ProtWarningInfoMapper;
|
|
|
+import com.huimv.admin.service.IProtDataService;
|
|
|
+import com.huimv.admin.service.IProtThresholdService;
|
|
|
+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.text.NumberFormat;
|
|
|
+import java.util.Date;
|
|
|
+
|
|
|
+@Configuration
|
|
|
+@EnableScheduling
|
|
|
+public class ProtTimer {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ProtThresholdMapper protThresholdMapper;
|
|
|
+ @Autowired
|
|
|
+ private ProtDataMapper protDataMapper;
|
|
|
+ @Autowired
|
|
|
+ private ProtWarningInfoMapper warningInfoMapper;
|
|
|
+
|
|
|
+ // 环保数据
|
|
|
+ @Scheduled(cron = "0 * * * * ? ")
|
|
|
+ private void getShenChan() throws Exception {
|
|
|
+
|
|
|
+ //假设已经拿到了数据
|
|
|
+ String num = NumberUtils.getNum(1, 14, 1);//ph
|
|
|
+ String num1 = NumberUtils.getNum(30, 60, 1);//cod
|
|
|
+ String num2 = NumberUtils.getNum(15, 35, 1);//nh3n
|
|
|
+ String num3 = NumberUtils.getNum(65, 85, 1);//tp
|
|
|
+ String num4 = NumberUtils.getNum(65, 85, 1);//tn
|
|
|
+ String num5 = NumberUtils.getNum(90, 210, 0);//flow
|
|
|
+ String num6 = NumberUtils.getNum(1, 3, 0);//loc_type
|
|
|
+
|
|
|
+ ProtWarningInfo protWarningInfo = new ProtWarningInfo();
|
|
|
+
|
|
|
+ ProtData protData = new ProtData();
|
|
|
+ protData.setLoctionType(Integer.parseInt(num6));
|
|
|
+ protData.setCreateDate(new Date());
|
|
|
+ protData.setFarmId(21);
|
|
|
+ protData.setCod(num1);
|
|
|
+ protData.setPh(num);
|
|
|
+ protData.setNh3n(num2);
|
|
|
+ protData.setTp(num3);
|
|
|
+ protData.setTn(num4);
|
|
|
+ protData.setFlow(num5);
|
|
|
+ protDataMapper.insert(protData);
|
|
|
+
|
|
|
+ QueryWrapper<ProtThreshold> queryWrapper = new QueryWrapper<>();
|
|
|
+ if ("1".equals(num6)) {
|
|
|
+ queryWrapper.eq("farm_id", 21).eq("prot_type", 1);
|
|
|
+ ProtThreshold protThreshold = protThresholdMapper.selectOne(queryWrapper);//进污口
|
|
|
+ if (Double.parseDouble(num) > Double.parseDouble(protThreshold.getPh2())) {
|
|
|
+ protWarningInfo.setWarningContent("进污口ph值为" + num + "达到红色预警");
|
|
|
+ } else if (Double.parseDouble(num) > Double.parseDouble(protThreshold.getPh1())) {
|
|
|
+ protWarningInfo.setWarningContent("进污口ph值为" + num + "达到橙色预警");
|
|
|
+ }
|
|
|
+ if (Double.parseDouble(num1) > Double.parseDouble(protThreshold.getCod2())) {
|
|
|
+ protWarningInfo.setWarningContent("进污口cod值为" + num1 + "达到红色预警");
|
|
|
+ } else if (Double.parseDouble(num1) > Double.parseDouble(protThreshold.getCod1())) {
|
|
|
+ protWarningInfo.setWarningContent("进污口cod值为" + num1 + "达到橙色预警");
|
|
|
+ }
|
|
|
+ if (Double.parseDouble(num2) > Double.parseDouble(protThreshold.getNh3n2())) {
|
|
|
+ protWarningInfo.setWarningContent("进污口NH3N值为" + num2 + "达到红色预警");
|
|
|
+ } else if (Double.parseDouble(num2) > Double.parseDouble(protThreshold.getNh3n1())) {
|
|
|
+ protWarningInfo.setWarningContent("进污口NH3N值为" + num2 + "达到橙色预警");
|
|
|
+ }
|
|
|
+ if (Double.parseDouble(num3) > Double.parseDouble(protThreshold.getTp2())) {
|
|
|
+ protWarningInfo.setWarningContent("进污口TP值为" + num3 + "达到红色预警");
|
|
|
+ } else if (Double.parseDouble(num3) > Double.parseDouble(protThreshold.getTp1())) {
|
|
|
+ protWarningInfo.setWarningContent("进污口TP值为" + num3 + "达到橙色预警");
|
|
|
+ }
|
|
|
+ if (Double.parseDouble(num4) > Double.parseDouble(protThreshold.getTn2())) {
|
|
|
+ protWarningInfo.setWarningContent("进污口TN值为" + num4 + "达到红色预警");
|
|
|
+ } else if (Double.parseDouble(num4) > Double.parseDouble(protThreshold.getTn1())) {
|
|
|
+ protWarningInfo.setWarningContent("进污口TN值为" + num4+ "达到橙色预警");
|
|
|
+ }
|
|
|
+ if (Double.parseDouble(num5) > Double.parseDouble(protThreshold.getFlow2())) {
|
|
|
+ protWarningInfo.setWarningContent("进污口累计流量值为" + num5 + "达到红色预警");
|
|
|
+ } else if (Double.parseDouble(num5) > Double.parseDouble(protThreshold.getFlow1())) {
|
|
|
+ protWarningInfo.setWarningContent("进污口累计流量值为" + num5 + "达到橙色预警");
|
|
|
+ }
|
|
|
+ protWarningInfo.setFarmId(21);
|
|
|
+ protWarningInfo.setWarningType(Integer.parseInt(num6));
|
|
|
+ protWarningInfo.setDate(new Date());
|
|
|
+ protWarningInfo.setUserIds("1,2");
|
|
|
+ protWarningInfo.setDeviceId(Integer.parseInt(num6));
|
|
|
+ protWarningInfo.setBuildLocation("进污口");
|
|
|
+ warningInfoMapper.insert(protWarningInfo);
|
|
|
+ } else if ("2".equals(num6)) {
|
|
|
+ queryWrapper.eq("farm_id", 21).eq("prot_type", 2);
|
|
|
+ ProtThreshold protThreshold = protThresholdMapper.selectOne(queryWrapper);//污口
|
|
|
+ if (Double.parseDouble(num) > Double.parseDouble(protThreshold.getPh2())) {
|
|
|
+ protWarningInfo.setWarningContent("处理口ph值为" + num + "达到红色预警");
|
|
|
+ } else if (Double.parseDouble(num) > Double.parseDouble(protThreshold.getPh1())) {
|
|
|
+ protWarningInfo.setWarningContent("处理口ph值为" + num + "达到橙色预警");
|
|
|
+ }
|
|
|
+ if (Double.parseDouble(num1) > Double.parseDouble(protThreshold.getCod2())) {
|
|
|
+ protWarningInfo.setWarningContent("处理口cod值为" + num1 + "达到红色预警");
|
|
|
+ } else if (Double.parseDouble(num1) > Double.parseDouble(protThreshold.getCod1())) {
|
|
|
+ protWarningInfo.setWarningContent("处理口cod值为" + num1 + "达到橙色预警");
|
|
|
+ }
|
|
|
+ if (Double.parseDouble(num2) > Double.parseDouble(protThreshold.getNh3n2())) {
|
|
|
+ protWarningInfo.setWarningContent("处理口NH3N值为" + num2 + "达到红色预警");
|
|
|
+ } else if (Double.parseDouble(num2) > Double.parseDouble(protThreshold.getNh3n1())) {
|
|
|
+ protWarningInfo.setWarningContent("处理口NH3N值为" + num2 + "达到橙色预警");
|
|
|
+ }
|
|
|
+ if (Double.parseDouble(num3) > Double.parseDouble(protThreshold.getTp2())) {
|
|
|
+ protWarningInfo.setWarningContent("处理口TP值为" + num3 + "达到红色预警");
|
|
|
+ } else if (Double.parseDouble(num3) > Double.parseDouble(protThreshold.getTp1())) {
|
|
|
+ protWarningInfo.setWarningContent("处理口TP值为" + num3 + "达到橙色预警");
|
|
|
+ }
|
|
|
+ if (Double.parseDouble(num4) > Double.parseDouble(protThreshold.getTn2())) {
|
|
|
+ protWarningInfo.setWarningContent("处理口TN值为" + num4 + "达到红色预警");
|
|
|
+ } else if (Double.parseDouble(num4) > Double.parseDouble(protThreshold.getTn1())) {
|
|
|
+ protWarningInfo.setWarningContent("处理口TN值为" + num4+ "达到橙色预警");
|
|
|
+ }
|
|
|
+ if (Double.parseDouble(num5) > Double.parseDouble(protThreshold.getFlow2())) {
|
|
|
+ protWarningInfo.setWarningContent("处理口累计流量值为" + num5 + "达到红色预警");
|
|
|
+ } else if (Double.parseDouble(num5) > Double.parseDouble(protThreshold.getFlow1())) {
|
|
|
+ protWarningInfo.setWarningContent("处理口累计流量值为" + num5 + "达到橙色预警");
|
|
|
+ }
|
|
|
+ protWarningInfo.setFarmId(21);
|
|
|
+ protWarningInfo.setWarningType(Integer.parseInt(num6));
|
|
|
+ protWarningInfo.setDate(new Date());
|
|
|
+ protWarningInfo.setUserIds("1,2");
|
|
|
+ protWarningInfo.setDeviceId(Integer.parseInt(num6));
|
|
|
+ protWarningInfo.setBuildLocation("处理口");
|
|
|
+ warningInfoMapper.insert(protWarningInfo);
|
|
|
+ } else if ("3".equals(num6)) {
|
|
|
+ queryWrapper.eq("farm_id", 21).eq("prot_type", 3);
|
|
|
+ ProtThreshold protThreshold = protThresholdMapper.selectOne(queryWrapper);//进污口
|
|
|
+ if (Double.parseDouble(num) > Double.parseDouble(protThreshold.getPh2())) {
|
|
|
+ protWarningInfo.setWarningContent("排污口ph值为" + num + "达到红色预警");
|
|
|
+ } else if (Double.parseDouble(num) > Double.parseDouble(protThreshold.getPh1())) {
|
|
|
+ protWarningInfo.setWarningContent("排污口ph值为" + num + "达到橙色预警");
|
|
|
+ }
|
|
|
+ if (Double.parseDouble(num1) > Double.parseDouble(protThreshold.getCod2())) {
|
|
|
+ protWarningInfo.setWarningContent("排污口cod值为" + num1 + "达到红色预警");
|
|
|
+ } else if (Double.parseDouble(num1) > Double.parseDouble(protThreshold.getCod1())) {
|
|
|
+ protWarningInfo.setWarningContent("排污口cod值为" + num1 + "达到橙色预警");
|
|
|
+ }
|
|
|
+ if (Double.parseDouble(num2) > Double.parseDouble(protThreshold.getNh3n2())) {
|
|
|
+ protWarningInfo.setWarningContent("排污口NH3N值为" + num2 + "达到红色预警");
|
|
|
+ } else if (Double.parseDouble(num2) > Double.parseDouble(protThreshold.getNh3n1())) {
|
|
|
+ protWarningInfo.setWarningContent("排污口NH3N值为" + num2 + "达到橙色预警");
|
|
|
+ }
|
|
|
+ if (Double.parseDouble(num3) > Double.parseDouble(protThreshold.getTp2())) {
|
|
|
+ protWarningInfo.setWarningContent("排污口TP值为" + num3 + "达到红色预警");
|
|
|
+ } else if (Double.parseDouble(num3) > Double.parseDouble(protThreshold.getTp1())) {
|
|
|
+ protWarningInfo.setWarningContent("排污口TP值为" + num3 + "达到橙色预警");
|
|
|
+ }
|
|
|
+ if (Double.parseDouble(num4) > Double.parseDouble(protThreshold.getTn2())) {
|
|
|
+ protWarningInfo.setWarningContent("排污口TN值为" + num4 + "达到红色预警");
|
|
|
+ } else if (Double.parseDouble(num4) > Double.parseDouble(protThreshold.getTn1())) {
|
|
|
+ protWarningInfo.setWarningContent("排污口TN值为" + num4+ "达到橙色预警");
|
|
|
+ }
|
|
|
+ if (Double.parseDouble(num5) > Double.parseDouble(protThreshold.getFlow2())) {
|
|
|
+ protWarningInfo.setWarningContent("排污口累计流量值为" + num5 + "达到红色预警");
|
|
|
+ } else if (Double.parseDouble(num5) > Double.parseDouble(protThreshold.getFlow1())) {
|
|
|
+ protWarningInfo.setWarningContent("排污口累计流量值为" + num5 + "达到橙色预警");
|
|
|
+ }
|
|
|
+ protWarningInfo.setFarmId(21);
|
|
|
+ protWarningInfo.setWarningType(Integer.parseInt(num6));
|
|
|
+ protWarningInfo.setDate(new Date());
|
|
|
+ protWarningInfo.setUserIds("1,2");
|
|
|
+ protWarningInfo.setDeviceId(Integer.parseInt(num6));
|
|
|
+ protWarningInfo.setBuildLocation("排污口");
|
|
|
+ warningInfoMapper.insert(protWarningInfo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|