GasTimer.java 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  1. package com.huimv.admin.timer;
  2. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  3. import com.huimv.admin.common.utils.NumberUtils;
  4. import com.huimv.admin.entity.GasData;
  5. import com.huimv.admin.entity.GasThreshold;
  6. import com.huimv.admin.entity.GasWarningInfo;
  7. import com.huimv.admin.mapper.GasDataMapper;
  8. import com.huimv.admin.mapper.GasThresholdMapper;
  9. import com.huimv.admin.mapper.GasWarningInfoMapper;
  10. import org.springframework.beans.factory.annotation.Autowired;
  11. import org.springframework.context.annotation.Configuration;
  12. import org.springframework.scheduling.annotation.EnableScheduling;
  13. import org.springframework.scheduling.annotation.Scheduled;
  14. import java.util.Date;
  15. @Configuration
  16. @EnableScheduling
  17. public class GasTimer {
  18. @Autowired
  19. private GasDataMapper gasDataMapper;
  20. @Autowired
  21. private GasWarningInfoMapper warningInfoMapper;
  22. @Autowired
  23. private GasThresholdMapper thresholdMapper;
  24. @Scheduled(cron = "0 0 */1 * * ? ")
  25. private void getShenChan() throws Exception {
  26. String type = NumberUtils.getNum(1, 5, 0);//loc_type
  27. for (int i = 1; i < 5; i++) {
  28. String nh3n = NumberUtils.getNumFloat(0.04, 0.051);//NH3N
  29. String jlm = NumberUtils.getNumFloat(0.05, 0.071);//jlm
  30. String elht = NumberUtils.getNumFloat(2.00, 2.501);//elht
  31. String ejel = NumberUtils.getNumFloat(0.04, 0.051);//ejel
  32. String h2s = NumberUtils.getNumFloat(0.04, 0.051);//h2s
  33. String byx = NumberUtils.getNumFloat(4.0, 4.501);//byx
  34. String ch3 = NumberUtils.getNumFloat(0.005, 0.0062);//ch3
  35. String sja = NumberUtils.getNumFloat(0.05, 0.071);//sja
  36. String cq = NumberUtils.getNumFloat(15.0, 18.01);//cq
  37. GasData gasData = new GasData();
  38. gasData.setLoctionType(i);
  39. gasData.setNh3N(nh3n);
  40. gasData.setJlm(jlm);
  41. gasData.setElht(elht);
  42. gasData.setEjel(ejel);
  43. gasData.setH2s(h2s);
  44. gasData.setByx(byx);
  45. gasData.setCh3sh(ch3);
  46. gasData.setSja(sja);
  47. gasData.setCq(cq);
  48. gasData.setFarmId(21);
  49. gasData.setCreateTime(new Date());
  50. gasDataMapper.insert(gasData);
  51. QueryWrapper<GasThreshold> queryWrapper = new QueryWrapper<>();
  52. GasWarningInfo warningInfo = new GasWarningInfo();
  53. if (i==1) {
  54. queryWrapper.eq("farm_id", 21).eq("gas_type", 1);
  55. GasThreshold gasThreshold = thresholdMapper.selectOne(queryWrapper);
  56. if (Double.parseDouble(nh3n) > Double.parseDouble(gasThreshold.getNh3N())) {
  57. warningInfo.setWarningContent("NH3N为"+nh3n + "超过阈值,系统预警提醒");
  58. warningInfo.setWarningType(0);
  59. warningInfo.setBuildLocation("屋顶");
  60. warningInfo.setDate(new Date());
  61. warningInfo.setFarmId(gasThreshold.getFarmId());
  62. warningInfo.setUserIds(gasThreshold.getUserIds());
  63. warningInfoMapper.insert(warningInfo);
  64. }
  65. if (Double.parseDouble(jlm) > Double.parseDouble(gasThreshold.getJlm())) {
  66. warningInfo.setWarningContent("甲硫醚为"+jlm + "超过阈值,系统预警提醒");
  67. warningInfo.setWarningType(1);
  68. warningInfo.setBuildLocation("屋顶");
  69. warningInfo.setDate(new Date());
  70. warningInfo.setFarmId(gasThreshold.getFarmId());
  71. warningInfo.setUserIds(gasThreshold.getUserIds());
  72. warningInfoMapper.insert(warningInfo);
  73. }
  74. if (Double.parseDouble(elht) > Double.parseDouble(gasThreshold.getElht())) {
  75. warningInfo.setWarningContent("二硫化碳为"+elht + "超过阈值,系统预警提醒");
  76. warningInfo.setWarningType(2);
  77. warningInfo.setBuildLocation("屋顶");
  78. warningInfo.setDate(new Date());
  79. warningInfo.setFarmId(gasThreshold.getFarmId());
  80. warningInfo.setUserIds(gasThreshold.getUserIds());
  81. warningInfoMapper.insert(warningInfo);
  82. }
  83. if (Double.parseDouble(ejel) > Double.parseDouble(gasThreshold.getEjel())) {
  84. warningInfo.setWarningContent("二甲二硫为"+ejel + "超过阈值,系统预警提醒");
  85. warningInfo.setWarningType(3);
  86. warningInfo.setBuildLocation("屋顶");
  87. warningInfo.setDate(new Date());
  88. warningInfo.setFarmId(gasThreshold.getFarmId());
  89. warningInfo.setUserIds(gasThreshold.getUserIds());
  90. warningInfoMapper.insert(warningInfo);
  91. }
  92. if (Double.parseDouble(h2s) > Double.parseDouble(gasThreshold.getH2s())) {
  93. warningInfo.setWarningContent("H2S为"+h2s + "超过阈值,系统预警提醒");
  94. warningInfo.setWarningType(4);
  95. warningInfo.setBuildLocation("屋顶");
  96. warningInfo.setDate(new Date());
  97. warningInfo.setFarmId(gasThreshold.getFarmId());
  98. warningInfo.setUserIds(gasThreshold.getUserIds());
  99. warningInfoMapper.insert(warningInfo);
  100. }
  101. if (Double.parseDouble(byx) > Double.parseDouble(gasThreshold.getByx())) {
  102. warningInfo.setWarningContent("苯乙烯为"+byx + "超过阈值,系统预警提醒");
  103. warningInfo.setWarningType(5);
  104. warningInfo.setBuildLocation("屋顶");
  105. warningInfo.setDate(new Date());
  106. warningInfo.setFarmId(gasThreshold.getFarmId());
  107. warningInfo.setUserIds(gasThreshold.getUserIds());
  108. warningInfoMapper.insert(warningInfo);
  109. }
  110. if (Double.parseDouble(ch3) > Double.parseDouble(gasThreshold.getCh3sh())) {
  111. warningInfo.setWarningContent("CH3SH为"+ch3 + "超过阈值,系统预警提醒");
  112. warningInfo.setWarningType(6);
  113. warningInfo.setBuildLocation("屋顶");
  114. warningInfo.setDate(new Date());
  115. warningInfo.setFarmId(gasThreshold.getFarmId());
  116. warningInfo.setUserIds(gasThreshold.getUserIds());
  117. warningInfoMapper.insert(warningInfo);
  118. }
  119. if (Double.parseDouble(sja) > Double.parseDouble(gasThreshold.getSja())) {
  120. warningInfo.setWarningContent("三甲胺为"+sja + "超过阈值,系统预警提醒");
  121. warningInfo.setWarningType(7);
  122. warningInfo.setBuildLocation("屋顶");
  123. warningInfo.setDate(new Date());
  124. warningInfo.setFarmId(gasThreshold.getFarmId());
  125. warningInfo.setUserIds(gasThreshold.getUserIds());
  126. warningInfoMapper.insert(warningInfo);
  127. }
  128. if (Double.parseDouble(cq) > Double.parseDouble(gasThreshold.getCq())) {
  129. warningInfo.setWarningContent("臭气为"+cq + "超过阈值,系统预警提醒");
  130. warningInfo.setWarningType(8);
  131. warningInfo.setBuildLocation("屋顶");
  132. warningInfo.setDate(new Date());
  133. warningInfo.setFarmId(gasThreshold.getFarmId());
  134. warningInfo.setUserIds(gasThreshold.getUserIds());
  135. warningInfoMapper.insert(warningInfo);
  136. }
  137. } else if (i==2) {
  138. queryWrapper.eq("farm_id", 21).eq("gas_type", 2);
  139. GasThreshold gasThreshold = thresholdMapper.selectOne(queryWrapper);
  140. if (Double.parseDouble(nh3n) > Double.parseDouble(gasThreshold.getNh3N())) {
  141. warningInfo.setWarningContent("NH3N为"+nh3n + "超过阈值,系统预警提醒");
  142. warningInfo.setWarningType(0);
  143. warningInfo.setBuildLocation("厂界上");
  144. warningInfo.setDate(new Date());
  145. warningInfo.setFarmId(gasThreshold.getFarmId());
  146. warningInfo.setUserIds(gasThreshold.getUserIds());
  147. warningInfoMapper.insert(warningInfo);
  148. }
  149. if (Double.parseDouble(jlm) > Double.parseDouble(gasThreshold.getJlm())) {
  150. warningInfo.setWarningContent("甲硫醚为"+jlm + "超过阈值,系统预警提醒");
  151. warningInfo.setWarningType(1);
  152. warningInfo.setBuildLocation("厂界上");
  153. warningInfo.setDate(new Date());
  154. warningInfo.setFarmId(gasThreshold.getFarmId());
  155. warningInfo.setUserIds(gasThreshold.getUserIds());
  156. warningInfoMapper.insert(warningInfo);
  157. }
  158. if (Double.parseDouble(elht) > Double.parseDouble(gasThreshold.getElht())) {
  159. warningInfo.setWarningContent("二硫化碳为"+elht + "超过阈值,系统预警提醒");
  160. warningInfo.setWarningType(2);
  161. warningInfo.setBuildLocation("厂界上");
  162. warningInfo.setDate(new Date());
  163. warningInfo.setFarmId(gasThreshold.getFarmId());
  164. warningInfo.setUserIds(gasThreshold.getUserIds());
  165. warningInfoMapper.insert(warningInfo);
  166. }
  167. if (Double.parseDouble(ejel) > Double.parseDouble(gasThreshold.getEjel())) {
  168. warningInfo.setWarningContent("二甲二硫为"+ejel + "超过阈值,系统预警提醒");
  169. warningInfo.setWarningType(3);
  170. warningInfo.setBuildLocation("厂界上");
  171. warningInfo.setDate(new Date());
  172. warningInfo.setFarmId(gasThreshold.getFarmId());
  173. warningInfo.setUserIds(gasThreshold.getUserIds());
  174. warningInfoMapper.insert(warningInfo);
  175. }
  176. if (Double.parseDouble(h2s) > Double.parseDouble(gasThreshold.getH2s())) {
  177. warningInfo.setWarningContent("H2S为"+h2s + "超过阈值,系统预警提醒");
  178. warningInfo.setWarningType(4);
  179. warningInfo.setBuildLocation("厂界上");
  180. warningInfo.setDate(new Date());
  181. warningInfo.setFarmId(gasThreshold.getFarmId());
  182. warningInfo.setUserIds(gasThreshold.getUserIds());
  183. warningInfoMapper.insert(warningInfo);
  184. }
  185. if (Double.parseDouble(byx) > Double.parseDouble(gasThreshold.getByx())) {
  186. warningInfo.setWarningContent("苯乙烯为"+byx + "超过阈值,系统预警提醒");
  187. warningInfo.setWarningType(5);
  188. warningInfo.setBuildLocation("厂界上");
  189. warningInfo.setDate(new Date());
  190. warningInfo.setFarmId(gasThreshold.getFarmId());
  191. warningInfo.setUserIds(gasThreshold.getUserIds());
  192. warningInfoMapper.insert(warningInfo);
  193. }
  194. if (Double.parseDouble(ch3) > Double.parseDouble(gasThreshold.getCh3sh())) {
  195. warningInfo.setWarningContent("CH3SH为"+ch3 + "超过阈值,系统预警提醒");
  196. warningInfo.setWarningType(6);
  197. warningInfo.setBuildLocation("厂界上");
  198. warningInfo.setDate(new Date());
  199. warningInfo.setFarmId(gasThreshold.getFarmId());
  200. warningInfo.setUserIds(gasThreshold.getUserIds());
  201. warningInfoMapper.insert(warningInfo);
  202. }
  203. if (Double.parseDouble(sja) > Double.parseDouble(gasThreshold.getSja())) {
  204. warningInfo.setWarningContent("三甲胺为"+sja + "超过阈值,系统预警提醒");
  205. warningInfo.setWarningType(7);
  206. warningInfo.setBuildLocation("厂界上");
  207. warningInfo.setDate(new Date());
  208. warningInfo.setFarmId(gasThreshold.getFarmId());
  209. warningInfo.setUserIds(gasThreshold.getUserIds());
  210. warningInfoMapper.insert(warningInfo);
  211. }
  212. if (Double.parseDouble(cq) > Double.parseDouble(gasThreshold.getCq())) {
  213. warningInfo.setWarningContent("臭气为"+cq + "超过阈值,系统预警提醒");
  214. warningInfo.setWarningType(8);
  215. warningInfo.setBuildLocation("厂界上");
  216. warningInfo.setDate(new Date());
  217. warningInfo.setFarmId(gasThreshold.getFarmId());
  218. warningInfo.setUserIds(gasThreshold.getUserIds());
  219. warningInfoMapper.insert(warningInfo);
  220. }
  221. } else if (i==3) {
  222. queryWrapper.eq("farm_id", 21).eq("gas_type", 3);
  223. GasThreshold gasThreshold = thresholdMapper.selectOne(queryWrapper);
  224. if (Double.parseDouble(nh3n) > Double.parseDouble(gasThreshold.getNh3N())) {
  225. warningInfo.setWarningContent("NH3N为"+nh3n + "超过阈值,系统预警提醒");
  226. warningInfo.setWarningType(0);
  227. warningInfo.setBuildLocation("厂界下");
  228. warningInfo.setDate(new Date());
  229. warningInfo.setFarmId(gasThreshold.getFarmId());
  230. warningInfo.setUserIds(gasThreshold.getUserIds());
  231. warningInfoMapper.insert(warningInfo);
  232. }
  233. if (Double.parseDouble(jlm) > Double.parseDouble(gasThreshold.getJlm())) {
  234. warningInfo.setWarningContent("甲硫醚为"+jlm + "超过阈值,系统预警提醒");
  235. warningInfo.setWarningType(1);
  236. warningInfo.setBuildLocation("厂界下");
  237. warningInfo.setDate(new Date());
  238. warningInfo.setFarmId(gasThreshold.getFarmId());
  239. warningInfo.setUserIds(gasThreshold.getUserIds());
  240. warningInfoMapper.insert(warningInfo);
  241. }
  242. if (Double.parseDouble(elht) > Double.parseDouble(gasThreshold.getElht())) {
  243. warningInfo.setWarningContent("二硫化碳为"+elht + "超过阈值,系统预警提醒");
  244. warningInfo.setWarningType(2);
  245. warningInfo.setBuildLocation("厂界下");
  246. warningInfo.setDate(new Date());
  247. warningInfo.setFarmId(gasThreshold.getFarmId());
  248. warningInfo.setUserIds(gasThreshold.getUserIds());
  249. warningInfoMapper.insert(warningInfo);
  250. }
  251. if (Double.parseDouble(ejel) > Double.parseDouble(gasThreshold.getEjel())) {
  252. warningInfo.setWarningContent("二甲二硫为"+ejel + "超过阈值,系统预警提醒");
  253. warningInfo.setWarningType(3);
  254. warningInfo.setBuildLocation("厂界下");
  255. warningInfo.setDate(new Date());
  256. warningInfo.setFarmId(gasThreshold.getFarmId());
  257. warningInfo.setUserIds(gasThreshold.getUserIds());
  258. warningInfoMapper.insert(warningInfo);
  259. }
  260. if (Double.parseDouble(h2s) > Double.parseDouble(gasThreshold.getH2s())) {
  261. warningInfo.setWarningContent("H2S为"+h2s + "超过阈值,系统预警提醒");
  262. warningInfo.setWarningType(4);
  263. warningInfo.setBuildLocation("厂界下");
  264. warningInfo.setDate(new Date());
  265. warningInfo.setFarmId(gasThreshold.getFarmId());
  266. warningInfo.setUserIds(gasThreshold.getUserIds());
  267. warningInfoMapper.insert(warningInfo);
  268. }
  269. if (Double.parseDouble(byx) > Double.parseDouble(gasThreshold.getByx())) {
  270. warningInfo.setWarningContent("苯乙烯为"+byx + "超过阈值,系统预警提醒");
  271. warningInfo.setWarningType(5);
  272. warningInfo.setBuildLocation("厂界下");
  273. warningInfo.setDate(new Date());
  274. warningInfo.setFarmId(gasThreshold.getFarmId());
  275. warningInfo.setUserIds(gasThreshold.getUserIds());
  276. warningInfoMapper.insert(warningInfo);
  277. }
  278. if (Double.parseDouble(ch3) > Double.parseDouble(gasThreshold.getCh3sh())) {
  279. warningInfo.setWarningContent("CH3SH为"+ch3 + "超过阈值,系统预警提醒");
  280. warningInfo.setWarningType(6);
  281. warningInfo.setBuildLocation("厂界下");
  282. warningInfo.setDate(new Date());
  283. warningInfo.setFarmId(gasThreshold.getFarmId());
  284. warningInfo.setUserIds(gasThreshold.getUserIds());
  285. warningInfoMapper.insert(warningInfo);
  286. }
  287. if (Double.parseDouble(sja) > Double.parseDouble(gasThreshold.getSja())) {
  288. warningInfo.setWarningContent("三甲胺为"+sja + "超过阈值,系统预警提醒");
  289. warningInfo.setWarningType(7);
  290. warningInfo.setBuildLocation("厂界下");
  291. warningInfo.setDate(new Date());
  292. warningInfo.setFarmId(gasThreshold.getFarmId());
  293. warningInfo.setUserIds(gasThreshold.getUserIds());
  294. warningInfoMapper.insert(warningInfo);
  295. }
  296. if (Double.parseDouble(cq) > Double.parseDouble(gasThreshold.getCq())) {
  297. warningInfo.setWarningContent("臭气为"+cq + "超过阈值,系统预警提醒");
  298. warningInfo.setWarningType(8);
  299. warningInfo.setBuildLocation("厂界下");
  300. warningInfo.setDate(new Date());
  301. warningInfo.setFarmId(gasThreshold.getFarmId());
  302. warningInfo.setUserIds(gasThreshold.getUserIds());
  303. warningInfoMapper.insert(warningInfo);
  304. }
  305. } else if (i==4) {
  306. queryWrapper.eq("farm_id", 21).eq("gas_type", 4);
  307. GasThreshold gasThreshold = thresholdMapper.selectOne(queryWrapper);
  308. if (Double.parseDouble(nh3n) > Double.parseDouble(gasThreshold.getNh3N())) {
  309. warningInfo.setWarningContent("NH3N为"+nh3n + "超过阈值,系统预警提醒");
  310. warningInfo.setWarningType(0);
  311. warningInfo.setBuildLocation("厂界居民");
  312. warningInfo.setDate(new Date());
  313. warningInfo.setFarmId(gasThreshold.getFarmId());
  314. warningInfo.setUserIds(gasThreshold.getUserIds());
  315. warningInfoMapper.insert(warningInfo);
  316. }
  317. if (Double.parseDouble(jlm) > Double.parseDouble(gasThreshold.getJlm())) {
  318. warningInfo.setWarningContent("甲硫醚为"+jlm + "超过阈值,系统预警提醒");
  319. warningInfo.setWarningType(1);
  320. warningInfo.setBuildLocation("厂界居民");
  321. warningInfo.setDate(new Date());
  322. warningInfo.setFarmId(gasThreshold.getFarmId());
  323. warningInfo.setUserIds(gasThreshold.getUserIds());
  324. warningInfoMapper.insert(warningInfo);
  325. }
  326. if (Double.parseDouble(elht) > Double.parseDouble(gasThreshold.getElht())) {
  327. warningInfo.setWarningContent("二硫化碳为"+elht + "超过阈值,系统预警提醒");
  328. warningInfo.setWarningType(2);
  329. warningInfo.setBuildLocation("厂界居民");
  330. warningInfo.setDate(new Date());
  331. warningInfo.setFarmId(gasThreshold.getFarmId());
  332. warningInfo.setUserIds(gasThreshold.getUserIds());
  333. warningInfoMapper.insert(warningInfo);
  334. }
  335. if (Double.parseDouble(ejel) > Double.parseDouble(gasThreshold.getEjel())) {
  336. warningInfo.setWarningContent("二甲二硫为"+ejel + "超过阈值,系统预警提醒");
  337. warningInfo.setWarningType(3);
  338. warningInfo.setBuildLocation("厂界居民");
  339. warningInfo.setDate(new Date());
  340. warningInfo.setFarmId(gasThreshold.getFarmId());
  341. warningInfo.setUserIds(gasThreshold.getUserIds());
  342. warningInfoMapper.insert(warningInfo);
  343. }
  344. if (Double.parseDouble(h2s) > Double.parseDouble(gasThreshold.getH2s())) {
  345. warningInfo.setWarningContent("H2S为"+h2s + "超过阈值,系统预警提醒");
  346. warningInfo.setWarningType(4);
  347. warningInfo.setBuildLocation("厂界居民");
  348. warningInfo.setDate(new Date());
  349. warningInfo.setFarmId(gasThreshold.getFarmId());
  350. warningInfo.setUserIds(gasThreshold.getUserIds());
  351. warningInfoMapper.insert(warningInfo);
  352. }
  353. if (Double.parseDouble(byx) > Double.parseDouble(gasThreshold.getByx())) {
  354. warningInfo.setWarningContent("苯乙烯为"+byx + "超过阈值,系统预警提醒");
  355. warningInfo.setWarningType(5);
  356. warningInfo.setBuildLocation("厂界居民");
  357. warningInfo.setDate(new Date());
  358. warningInfo.setFarmId(gasThreshold.getFarmId());
  359. warningInfo.setUserIds(gasThreshold.getUserIds());
  360. warningInfoMapper.insert(warningInfo);
  361. }
  362. if (Double.parseDouble(ch3) > Double.parseDouble(gasThreshold.getCh3sh())) {
  363. warningInfo.setWarningContent("CH3SH为"+ch3 + "超过阈值,系统预警提醒");
  364. warningInfo.setWarningType(6);
  365. warningInfo.setBuildLocation("厂界居民");
  366. warningInfo.setDate(new Date());
  367. warningInfo.setFarmId(gasThreshold.getFarmId());
  368. warningInfo.setUserIds(gasThreshold.getUserIds());
  369. warningInfoMapper.insert(warningInfo);
  370. }
  371. if (Double.parseDouble(sja) > Double.parseDouble(gasThreshold.getSja())) {
  372. warningInfo.setWarningContent("三甲胺为"+sja + "超过阈值,系统预警提醒");
  373. warningInfo.setWarningType(7);
  374. warningInfo.setBuildLocation("厂界居民");
  375. warningInfo.setDate(new Date());
  376. warningInfo.setFarmId(gasThreshold.getFarmId());
  377. warningInfo.setUserIds(gasThreshold.getUserIds());
  378. warningInfoMapper.insert(warningInfo);
  379. }
  380. if (Double.parseDouble(cq) > Double.parseDouble(gasThreshold.getCq())) {
  381. warningInfo.setWarningContent("臭气为"+cq + "超过阈值,系统预警提醒");
  382. warningInfo.setWarningType(8);
  383. warningInfo.setBuildLocation("厂界居民");
  384. warningInfo.setDate(new Date());
  385. warningInfo.setFarmId(gasThreshold.getFarmId());
  386. warningInfo.setUserIds(gasThreshold.getUserIds());
  387. warningInfoMapper.insert(warningInfo);
  388. }
  389. }
  390. }
  391. }
  392. }