GasCommonController.java 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583
  1. package com.ruoyi.web.controller.gas;
  2. import cn.hutool.core.bean.BeanUtil;
  3. import cn.hutool.core.bean.copier.CopyOptions;
  4. import cn.hutool.core.convert.Convert;
  5. import cn.hutool.core.date.DateUtil;
  6. import cn.hutool.core.util.NumberUtil;
  7. import cn.hutool.core.util.ObjectUtil;
  8. import cn.hutool.core.util.StrUtil;
  9. import cn.hutool.http.HttpUtil;
  10. import com.alibaba.fastjson.JSON;
  11. import com.alibaba.fastjson.JSONArray;
  12. import com.alibaba.fastjson.JSONObject;
  13. import com.ruoyi.common.constant.CacheConstants;
  14. import com.ruoyi.common.constant.ElasticConstants;
  15. import com.ruoyi.common.core.domain.AjaxResult;
  16. import com.ruoyi.common.core.redis.RedisCache;
  17. import com.ruoyi.common.utils.uuid.IdUtils;
  18. import com.ruoyi.framework.config.ElasticSearchClient;
  19. import com.ruoyi.system.domain.AisShip;
  20. import com.ruoyi.system.domain.DeviceBo;
  21. import com.ruoyi.system.domain.IllegalInfo;
  22. import com.ruoyi.system.domain.IllegalShipData;
  23. import com.ruoyi.system.domain.MonitorInfo;
  24. import com.ruoyi.system.domain.SyncPost;
  25. import com.ruoyi.system.domain.vo.AisShipInfo;
  26. import com.ruoyi.system.domain.vo.ShipEepReportRecInfo;
  27. import com.ruoyi.system.service.IAisDatabase;
  28. import com.ruoyi.system.service.IAisInfoService;
  29. import com.ruoyi.system.service.IAisShipService;
  30. import com.ruoyi.system.service.IHeiYanService;
  31. import com.ruoyi.system.service.IIllegalShipDataService;
  32. import com.ruoyi.system.service.ISo2Service;
  33. import com.ruoyi.system.service.ISysConfigService;
  34. import com.ruoyi.web.controller.tool.SMSUtil;
  35. import com.ruoyi.web.service.IGasCommonService;
  36. import io.swagger.annotations.Api;
  37. import io.swagger.annotations.ApiOperation;
  38. import lombok.SneakyThrows;
  39. import org.springframework.beans.factory.annotation.Autowired;
  40. import org.springframework.beans.factory.annotation.Value;
  41. import org.springframework.security.access.prepost.PreAuthorize;
  42. import org.springframework.web.bind.annotation.DeleteMapping;
  43. import org.springframework.web.bind.annotation.GetMapping;
  44. import org.springframework.web.bind.annotation.PostMapping;
  45. import org.springframework.web.bind.annotation.RequestBody;
  46. import org.springframework.web.bind.annotation.RequestMapping;
  47. import org.springframework.web.bind.annotation.RequestParam;
  48. import org.springframework.web.bind.annotation.RestController;
  49. import java.util.ArrayList;
  50. import java.util.Comparator;
  51. import java.util.Date;
  52. import java.util.HashMap;
  53. import java.util.List;
  54. import java.util.Map;
  55. import java.util.TreeSet;
  56. import java.util.stream.Collectors;
  57. /**
  58. * @Description: 公共提出接口
  59. * @Author: huangcheng
  60. * @Date: 2021/8/30
  61. * @Version V1.0
  62. */
  63. @RestController
  64. @RequestMapping("/gas/common")
  65. @Api(tags = "公共接口")
  66. public class GasCommonController {
  67. @Autowired
  68. private IGasCommonService gasCommonService;
  69. @Autowired
  70. private ElasticSearchClient client;
  71. @Autowired
  72. private ISo2Service so2Service;
  73. @Autowired
  74. private IAisDatabase aisDatabase;
  75. @Autowired
  76. private IHeiYanService heiYanService;
  77. @Autowired
  78. private IAisShipService aisShipService;
  79. @Value("${spring.profiles.active}")
  80. private String env;
  81. @Autowired
  82. private IAisInfoService aisInfoService;
  83. @Autowired
  84. private IIllegalShipDataService illegalShipDataService;
  85. @Autowired
  86. private ISysConfigService configService;
  87. @Value("${black.snapImgUrl}")
  88. private String blackImgUrl;
  89. @Autowired
  90. private RedisCache redisCache;
  91. @PreAuthorize("@ss.hasPermi('system:gas:sync')")
  92. @PostMapping("/sync")
  93. @ApiOperation("第三方表数据同步ES")
  94. public AjaxResult sync(@RequestBody SyncPost syncPost) {
  95. gasCommonService.sync(syncPost);
  96. return AjaxResult.success("同步中...");
  97. }
  98. @GetMapping("/illegalShipStatic")
  99. @ApiOperation("获取硫、黑烟超标数量统计")
  100. public AjaxResult illegalShipStatic() {
  101. // Map<String, Object> params = baseEntity.getParams();
  102. // if (ObjectUtil.isNotEmpty(params.get("beginTime"))) {
  103. // params.put("beginTime", params.get("beginTime") + " 00:00:00");
  104. // }
  105. // if (ObjectUtil.isNotEmpty(params.get("endTime"))) {
  106. // params.put("endTime", params.get("endTime") + " 23:59:59");
  107. // }
  108. // Map<String, Object> so2RangeCondition = new HashMap<>();
  109. // so2RangeCondition.put("createTime", StrUtil.concat(true, "[", Convert.toStr(params.get("beginTime")), ",", Convert.toStr(params.get("endTime")), "]"));
  110. // so2RangeCondition.put("peakTime", StrUtil.concat(true, "[", Convert.toStr(params.get("beginTime")), ",", Convert.toStr(params.get("endTime")), "]"));
  111. Map<String, Object> equalsCondition = new HashMap<>();
  112. equalsCondition.put("illegalStatus", 2);
  113. long so2Count = client.count(equalsCondition, null, ElasticConstants.SO2_ALERT, ElasticConstants.AIS_ILLEGAL_SHIP);
  114. equalsCondition.put("illegalStatus", 3);
  115. long blackCount = client.count(equalsCondition, null, ElasticConstants.HEIYAN_SHIP_RECOGNITION);
  116. Map<String, Object> result = new HashMap<>();
  117. result.put("so2Count", so2Count);
  118. result.put("blackCount", blackCount);
  119. return AjaxResult.success(result);
  120. }
  121. @GetMapping("/queryIllegalInfoList")
  122. @ApiOperation("获取嫌疑或违规船舶信息")
  123. public AjaxResult queryIllegalInfoList(@RequestParam String illegalStatus, @RequestParam(required = false, defaultValue = "20") Integer size) {
  124. Map<String, Object> equalsCondition = new HashMap<>();
  125. equalsCondition.put("illegalStatus", illegalStatus);
  126. List<String> orderBy = new ArrayList<>();
  127. orderBy.add("-createTime");
  128. Map<String, Object> stringObjectMap = client.searchDocument(equalsCondition,
  129. null,
  130. orderBy,
  131. 1,
  132. size,
  133. ElasticConstants.AIS_ILLEGAL_SHIP,
  134. ElasticConstants.SO2_ALERT,
  135. ElasticConstants.HEIYAN_SHIP_RECOGNITION);
  136. return AjaxResult.success(Convert.toList(IllegalInfo.class, stringObjectMap.get("pageList")));
  137. }
  138. @GetMapping("/queryDeviceList")
  139. @ApiOperation("获取所有设备数据")
  140. public AjaxResult queryDeviceList(@RequestParam(required = false) String monitor) {
  141. if (redisCache.hasKey(CacheConstants.DEVICE_LIST_STATIC)) {
  142. return AjaxResult.success(redisCache.getCacheMap(CacheConstants.DEVICE_LIST_STATIC));
  143. }
  144. List<DeviceBo> njsanq = new ArrayList<>();
  145. List<DeviceBo> njsiq = new ArrayList<>();
  146. List<DeviceBo> ry = new ArrayList<>();
  147. List<DeviceBo> tz = new ArrayList<>();
  148. List<DeviceBo> jy = new ArrayList<>();
  149. List<DeviceBo> st = new ArrayList<>();
  150. Map<String, Object> data = new HashMap<>();
  151. List<DeviceBo> so2 = so2Service.queryDeviceList(monitor);
  152. List<DeviceBo> ais = aisDatabase.queryDeviceList(monitor);
  153. List<DeviceBo> heiyan = heiYanService.queryDeviceList(monitor);
  154. for (DeviceBo deviceBo : so2) {
  155. deviceBo.setOrgName(orgMap.get(deviceBo.getMonitorName()));
  156. switch (deviceBo.getMonitorName()) {
  157. case "南京三桥":
  158. njsanq.add(deviceBo);
  159. break;
  160. case "南京四桥":
  161. njsiq.add(deviceBo);
  162. break;
  163. case "润扬大桥":
  164. ry.add(deviceBo);
  165. break;
  166. case "泰州大桥":
  167. tz.add(deviceBo);
  168. break;
  169. case "江阴大桥":
  170. jy.add(deviceBo);
  171. break;
  172. case "苏通大桥":
  173. st.add(deviceBo);
  174. break;
  175. }
  176. }
  177. for (DeviceBo deviceBo : ais) {
  178. deviceBo.setOrgName(orgMap.get(deviceBo.getMonitorName()));
  179. switch (deviceBo.getMonitorName()) {
  180. case "南京三桥":
  181. njsanq.add(deviceBo);
  182. break;
  183. case "南京四桥":
  184. njsiq.add(deviceBo);
  185. break;
  186. case "润扬大桥":
  187. ry.add(deviceBo);
  188. break;
  189. case "泰州大桥":
  190. tz.add(deviceBo);
  191. break;
  192. case "江阴大桥":
  193. jy.add(deviceBo);
  194. break;
  195. case "苏通大桥":
  196. st.add(deviceBo);
  197. break;
  198. }
  199. }
  200. for (DeviceBo deviceBo : heiyan) {
  201. switch (deviceBo.getMonitorName()) {
  202. case "南京三桥":
  203. njsanq.add(deviceBo);
  204. break;
  205. case "南京四桥":
  206. njsiq.add(deviceBo);
  207. break;
  208. case "润扬大桥":
  209. ry.add(deviceBo);
  210. break;
  211. case "泰州大桥":
  212. tz.add(deviceBo);
  213. break;
  214. case "江阴大桥":
  215. jy.add(deviceBo);
  216. break;
  217. case "苏通大桥":
  218. st.add(deviceBo);
  219. break;
  220. }
  221. }
  222. data.put("南京三桥", njsanq);
  223. data.put("南京四桥", njsiq);
  224. data.put("润扬大桥", ry);
  225. data.put("泰州大桥", tz);
  226. data.put("江阴大桥", jy);
  227. data.put("苏通大桥", st);
  228. redisCache.setCacheMap(CacheConstants.DEVICE_LIST_STATIC, data);
  229. return AjaxResult.success(data);
  230. }
  231. @GetMapping("/queryShipByDeviceId")
  232. @ApiOperation("根据设备id获取设备的嫌疑或违规船舶数据")
  233. public AjaxResult queryShipByDeviceId(@RequestParam String deviceId, @RequestParam String illegalStatus, @RequestParam(required = false) Integer size, @RequestParam String... index) {
  234. Map<String, Object> equalsCondition = new HashMap<>();
  235. equalsCondition.put("illegalStatus", illegalStatus);
  236. equalsCondition.put("deviceId", deviceId);
  237. List<String> orderBy = new ArrayList<>();
  238. orderBy.add("-createTime");
  239. if (ObjectUtil.isEmpty(size)) {
  240. size = 20;
  241. }
  242. Map<String, Object> stringObjectMap = client.searchDocument(equalsCondition,
  243. null,
  244. orderBy,
  245. 1,
  246. size,
  247. index);
  248. return AjaxResult.success(Convert.toList(IllegalInfo.class, stringObjectMap.get("pageList")));
  249. }
  250. @GetMapping("/queryShipList")
  251. @ApiOperation("获取所有船舶数据-用于地图展示船舶")
  252. public AjaxResult queryShipList(@RequestParam(required = false) String monitor, @RequestParam(required = false) String startTime) {
  253. Map<String, Object> equalsCondition = new HashMap<>();
  254. if (StrUtil.isNotBlank(monitor)) {
  255. equalsCondition.put("monitorPointName", monitor);
  256. equalsCondition.put("snapPos", monitor);
  257. }
  258. equalsCondition.put("mmsi", "!0");
  259. Map<String, Object> rangeCondition = new HashMap<>();
  260. if (StrUtil.isBlank(startTime)) {
  261. startTime = DateUtil.formatDateTime(DateUtil.offsetDay(new Date(), -1));
  262. }
  263. rangeCondition.put("createTime", StrUtil.concat(true, "[", startTime, ",", DateUtil.now(), "]"));
  264. List<String> orderBy = new ArrayList<>();
  265. orderBy.add("-createTime");
  266. Map<String, Object> stringObjectMap = client.searchDocument(equalsCondition,
  267. rangeCondition,
  268. orderBy,
  269. 1,
  270. 10000,
  271. ElasticConstants.AIS_ILLEGAL_SHIP,
  272. ElasticConstants.SO2_ALERT,
  273. ElasticConstants.HEIYAN_SHIP_RECOGNITION);
  274. List<IllegalInfo> pageList = Convert.toList(IllegalInfo.class, stringObjectMap.get("pageList"));
  275. // 查询船舶的实时经纬度
  276. Map<String, AisShip> aisShipMap = aisShipService.queryDynamicShip(1);
  277. List<AisShip> aisShipAddressList = aisShipService.queryShipAddressList(1);
  278. // 组装一段时间内的经纬度数据
  279. Map<String, List<String>> collect = aisShipAddressList.stream().collect(Collectors.groupingBy(AisShip::getMmsi, Collectors.mapping(a -> a.getLng() + "," + a.getLat(), Collectors.toList())));
  280. for (IllegalInfo illegalInfo : pageList) {
  281. if (StrUtil.isNotBlank(illegalInfo.getMmsi())) {
  282. AisShip aisShip = aisShipMap.get(illegalInfo.getMmsi());
  283. if (aisShip != null) {
  284. illegalInfo.setLat(aisShip.getLat());
  285. illegalInfo.setLng(aisShip.getLng());
  286. illegalInfo.setReceive(aisShip.getReceive());
  287. illegalInfo.setHead(ObjectUtil.isEmpty(aisShip.getHead()) ? "-" : aisShip.getHead() + "");
  288. illegalInfo.setSpeed(ObjectUtil.isEmpty(aisShip.getSpeed()) ? "-" : aisShip.getSpeed() + "节");
  289. illegalInfo.setCourse(ObjectUtil.isEmpty(aisShip.getCourse()) ? "-" : aisShip.getCourse() + "");
  290. }
  291. illegalInfo.setLnglat(collect.get(illegalInfo.getMmsi()));
  292. }
  293. }
  294. pageList =
  295. pageList.stream().filter(ship -> ObjectUtil.isNotEmpty(ship.getLat())).collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(o -> o.getMmsi() + ";" + o.getIllegalType()))),
  296. ArrayList::new));
  297. return AjaxResult.success(pageList);
  298. }
  299. @GetMapping("/queryShipMonitorInfo")
  300. @ApiOperation("获取船舶监测数据")
  301. public AjaxResult queryShipMonitorInfo(@RequestParam String mmsi) {
  302. Map<String, Object> map = new HashMap<>(4);
  303. List<MonitorInfo> minor = new ArrayList<>();
  304. // 硫的监测数据(监测点、硫含量、监测时间、so2浓度、no2浓度、co2浓度、硫碳比)
  305. // 查询so2系统
  306. Map<String, Object> equalsCondition = new HashMap<>();
  307. equalsCondition.put("mmsi", mmsi);
  308. List<String> orderBy = new ArrayList<>();
  309. orderBy.add("-createTime");
  310. Map<String, Object> monitorMap = client.searchDocument(equalsCondition,
  311. null,
  312. orderBy,
  313. 1,
  314. 100,
  315. ElasticConstants.AIS_ILLEGAL_SHIP,
  316. ElasticConstants.SO2_ALERT,
  317. ElasticConstants.HEIYAN_SHIP_RECOGNITION);
  318. List<MonitorInfo> pageList = Convert.toList(MonitorInfo.class, monitorMap.get("pageList"));
  319. // 处理数据
  320. for (MonitorInfo monitorInfo : pageList) {
  321. if (StrUtil.isBlank(monitorInfo.getMonitorPointName()) && StrUtil.isNotBlank(monitorInfo.getSnapPos())) {
  322. monitorInfo.setMonitorPointName(monitorInfo.getSnapPos());
  323. }
  324. if (ObjectUtil.isNotEmpty(monitorInfo.getCo2Concentration())) {
  325. minor.add(monitorInfo);
  326. }
  327. }
  328. map.put("main", pageList);
  329. map.put("minor", minor);
  330. return AjaxResult.success(map);
  331. }
  332. public final static Map<String, String> orgMap = new HashMap<String, String>() {{
  333. put("南京三桥", "南京海事局");
  334. put("南京四桥", "南京海事局");
  335. put("润扬大桥", "扬州海事局");
  336. put("泰州大桥", "泰州海事局");
  337. put("江阴大桥", "江阴海事局");
  338. put("苏通大桥", "常熟海事局");
  339. }};
  340. public final static Map<String, String> heiyanDeviceMap = new HashMap<String, String>() {{
  341. put("南京三桥", "1106");
  342. put("润扬大桥", "2104");
  343. put("江阴大桥", "6106");
  344. put("苏通大桥", "9108");
  345. }};
  346. @GetMapping("/queryData")
  347. @ApiOperation("查询ES数据")
  348. public Object queryData(@RequestParam(required = false) String id, @RequestParam(required = false) Integer size, @RequestParam(required = false) String orderKey, @RequestParam String... index) {
  349. if (size == null) {
  350. size = 200;
  351. }
  352. Map<String, Object> equalsCondition = new HashMap<>();
  353. if (StrUtil.isNotBlank(id)) {
  354. equalsCondition.put("id", id);
  355. }
  356. List<String> orderBy = new ArrayList<>();
  357. if (StrUtil.isNotBlank(orderKey)) {
  358. orderBy.add("-" + orderKey);
  359. }
  360. Map<String, Object> map = client.searchDocument(equalsCondition,
  361. null,
  362. orderBy,
  363. 1,
  364. size,
  365. index);
  366. return map.get("pageList");
  367. }
  368. @DeleteMapping("/deleteIndexOneData")
  369. @ApiOperation("删除ES中某个数据")
  370. public void deleteIndexData(@RequestParam String index, @RequestParam String id) {
  371. client.deleteDocument(index, id);
  372. }
  373. @PostMapping("/sendSms")
  374. @ApiOperation("发送短信")
  375. public AjaxResult sendSms(@RequestBody JSONObject jsonObject) {
  376. String content = jsonObject.getString("content");
  377. String phone = jsonObject.getString("phone");
  378. if (StrUtil.hasBlank(content, phone)) {
  379. return AjaxResult.error("存在参数为空");
  380. }
  381. SMSUtil smsUtil = new SMSUtil();
  382. smsUtil.sendMessage(content, phone);
  383. return AjaxResult.success();
  384. }
  385. @SneakyThrows
  386. @PostMapping("/reSyncOneData")
  387. @ApiOperation("重新同步某一个数据")
  388. public void reSyncOneData(@RequestParam String index, @RequestParam String id) {
  389. client.deleteDocument(index, id);
  390. String so2ThresholdVal = configService.selectConfigByKey("so2.so2");
  391. String blackThresholdVal = configService.selectConfigByKey("black.rcgSoot");
  392. if (ElasticConstants.AIS_ILLEGAL_SHIP.equals(index)) {
  393. Map<String, Object> afterDataMap = aisDatabase.queryById(id);
  394. // 嗅探系统-违规船舶
  395. if ("prod".equals(env)) {
  396. // 查询检测点和船舶信息、船舶进出港记录
  397. AisShipInfo shipInfo = aisInfoService.getShipInfo("", Convert.toStr(afterDataMap.get("mmsi")), "", "");
  398. if (shipInfo != null) {
  399. afterDataMap.put("shipName", shipInfo.getShipName());
  400. afterDataMap.put("shipRegionType", shipInfo.getShipRegionType());
  401. }
  402. }
  403. if (ObjectUtil.isNotEmpty(afterDataMap.get("sPercent")) && NumberUtil.isGreaterOrEqual(Convert.toBigDecimal(afterDataMap.get("sPercent")), Convert.toBigDecimal(so2ThresholdVal))) {
  404. // 查询检测点和船舶信息、船舶进出港记录
  405. ShipEepReportRecInfo eepReportRecInfo = aisInfoService.getShipEepReportRecInfo(DateUtil.formatDate(DateUtil.offsetDay(new Date(), -20)), DateUtil.formatDate(DateUtil.tomorrow()), Convert.toStr(afterDataMap.get("mmsi")), "", "");
  406. if (eepReportRecInfo != null) {
  407. afterDataMap.put("destination", eepReportRecInfo.getNextPortName());
  408. afterDataMap.put("berthName", eepReportRecInfo.getBerthName());
  409. }
  410. afterDataMap.put("deviceId", afterDataMap.get("semId"));
  411. // 查询站点信息
  412. Map<String, Object> sem = client.getDocById(ElasticConstants.AIS_SEM_INSTRUMENT, Convert.toStr(afterDataMap.get("semId")), "name,category");
  413. if (sem != null && ObjectUtil.equal(sem.get("code"), 200)) {
  414. Map<String, String> data = Convert.toMap(String.class, String.class, sem.get("data"));
  415. afterDataMap.put("semName", data.get("name"));
  416. afterDataMap.put("monitorPointName", data.get("category"));
  417. afterDataMap.put("orgName", orgMap.get(data.get("category")));
  418. }
  419. // 嫌疑船舶
  420. afterDataMap.put("illegalStatus", 2);
  421. afterDataMap.put("uploadFlag", 0);
  422. // TODO 上报行政检查系统
  423. } else {
  424. afterDataMap.put("uploadFlag", 0);
  425. afterDataMap.put("illegalStatus", 1);
  426. }
  427. if (ObjectUtil.isNotEmpty(afterDataMap.get("mmsi"))) {
  428. aisInfoService.getDynamicShipInfo(Convert.toStr(afterDataMap.get("mmsi")));
  429. }
  430. afterDataMap.put("illegalType", "xiutan");
  431. // 保存数据
  432. saveIllegalData(afterDataMap, ElasticConstants.AIS_ILLEGAL_SHIP);
  433. client.createDocument(ElasticConstants.AIS_ILLEGAL_SHIP, Convert.toStr(afterDataMap.get("id")), afterDataMap);
  434. } else if (ElasticConstants.SO2_ALERT.equals(index)) {
  435. Map<String, Object> afterDataMap = so2Service.queryById(id);
  436. // 船舶记录
  437. if ("prod".equals(env)) {
  438. AisShipInfo shipInfo = aisInfoService.getShipInfo("", Convert.toStr(afterDataMap.get("mmsi")), "", "");
  439. if (shipInfo != null) {
  440. afterDataMap.put("shipName", shipInfo.getShipName());
  441. afterDataMap.put("shipRegionType", shipInfo.getShipRegionType());
  442. }
  443. }
  444. // 判断是否大于阈值
  445. if (ObjectUtil.isNotEmpty(afterDataMap.get("so2Percent")) && NumberUtil.isGreaterOrEqual(Convert.toBigDecimal(afterDataMap.get("so2Percent")), Convert.toBigDecimal(so2ThresholdVal))) {
  446. // 查询检测点和船舶信息、船舶进出港记录
  447. ShipEepReportRecInfo eepReportRecInfo = aisInfoService.getShipEepReportRecInfo(DateUtil.formatDate(DateUtil.offsetDay(new Date(), -20)), DateUtil.formatDate(DateUtil.tomorrow()), Convert.toStr(afterDataMap.get("mmsi")), "", "");
  448. if (eepReportRecInfo != null) {
  449. afterDataMap.put("destination", eepReportRecInfo.getNextPortName());
  450. afterDataMap.put("berthName", eepReportRecInfo.getBerthName());
  451. }
  452. // 嫌疑船舶
  453. afterDataMap.put("illegalStatus", 2);
  454. afterDataMap.put("uploadFlag", 0);
  455. // TODO 上报行政检查系统
  456. } else {
  457. afterDataMap.put("uploadFlag", 0);
  458. afterDataMap.put("illegalStatus", 1);
  459. }
  460. Map<String, Object> monitor = client.getDocById(ElasticConstants.SO2_MONITOR_POINT, Convert.toStr(afterDataMap.get("monitorPointId")), "name");
  461. if (monitor != null && ObjectUtil.equal(monitor.get("code"), 200)) {
  462. Map<String, String> data = Convert.toMap(String.class, String.class, monitor.get("data"));
  463. afterDataMap.put("monitorPointName", data.get("name"));
  464. afterDataMap.put("orgName", orgMap.get(data.get("name")));
  465. }
  466. if (ObjectUtil.isNotEmpty(afterDataMap.get("mmsi"))) {
  467. aisInfoService.getDynamicShipInfo(Convert.toStr(afterDataMap.get("mmsi")));
  468. }
  469. afterDataMap.put("illegalType", "guangpu");
  470. // 保存数据
  471. saveIllegalData(afterDataMap, ElasticConstants.SO2_ALERT);
  472. client.createDocument(ElasticConstants.SO2_ALERT, Convert.toStr(afterDataMap.get("id")), afterDataMap);
  473. } else if (ElasticConstants.HEIYAN_SHIP_RECOGNITION.equals(index)) {
  474. Map<String, Object> afterDataMap = heiYanService.queryById(id);
  475. if (ObjectUtil.isEmpty(afterDataMap.get("mmsi"))) {
  476. return;
  477. }
  478. // 判断数据状态
  479. if (ObjectUtil.isNotEmpty(afterDataMap.get("rcgSoot")) && NumberUtil.isGreaterOrEqual(Convert.toBigDecimal(afterDataMap.get("rcgSoot")),
  480. Convert.toBigDecimal(blackThresholdVal))) {
  481. // 查询黑烟图片
  482. if ("prod".equals(env)) {
  483. String imgUrl = HttpUtil.get(blackImgUrl + Convert.toStr(afterDataMap.get("id")));
  484. JSONObject response = JSON.parseObject(imgUrl);
  485. if (200 == response.getInteger("code")) {
  486. List<String> newImgList = new ArrayList<>();
  487. JSONArray imgUrlList = response.getJSONObject("data").getJSONArray("imgUrlList");
  488. String sootImgUrl = response.getJSONObject("data").getString("sootImgUrl");
  489. for (Object o : imgUrlList) {
  490. // 只保存细节、全貌开头的图片
  491. String s = Convert.toStr(o);
  492. // if (StrUtil.containsAny(s, "全貌", "细节")) {
  493. newImgList.add("http://" + s);
  494. // }
  495. }
  496. afterDataMap.put("sootImgUrl", StrUtil.isNotBlank(sootImgUrl) ? "http://" + sootImgUrl : "");
  497. afterDataMap.put("allImgUrl", newImgList);
  498. }
  499. }
  500. // 查询检测点和船舶信息、船舶进出港记录
  501. ShipEepReportRecInfo eepReportRecInfo = aisInfoService.getShipEepReportRecInfo(DateUtil.formatDate(DateUtil.offsetDay(new Date(), -20)), DateUtil.formatDate(DateUtil.tomorrow()), Convert.toStr(afterDataMap.get("mmsi")), "", "");
  502. if (eepReportRecInfo != null) {
  503. afterDataMap.put("destination", eepReportRecInfo.getNextPortName());
  504. afterDataMap.put("berthName", eepReportRecInfo.getBerthName());
  505. }
  506. // 超过阈值后直接判定为违规船舶
  507. afterDataMap.put("illegalStatus", 3);
  508. afterDataMap.put("uploadFlag", 0);
  509. // TODO 上报行政检查系统
  510. } else {
  511. afterDataMap.put("uploadFlag", 0);
  512. afterDataMap.put("illegalStatus", 1);
  513. }
  514. if (ObjectUtil.isNotEmpty(afterDataMap.get("mmsi")) && Convert.toStr(afterDataMap.get("mmsi")).length() == 9) {
  515. aisInfoService.getDynamicShipInfo(Convert.toStr(afterDataMap.get("mmsi")));
  516. }
  517. afterDataMap.put("illegalType", "heiyan");
  518. // 查询检测点和船舶信息
  519. if (ObjectUtil.isNotEmpty(afterDataMap.get("mmsi")) && !"0".equals(Convert.toStr(afterDataMap.get("mmsi")))) {
  520. AisShipInfo shipInfo = aisInfoService.getShipInfo("", Convert.toStr(afterDataMap.get("mmsi")), "", "");
  521. if (shipInfo != null) {
  522. afterDataMap.put("shipName", shipInfo.getShipName());
  523. afterDataMap.put("shipRegionType", shipInfo.getShipRegionType());
  524. }
  525. }
  526. // 对于没有从ais系统拿到船名的情况下,直接取rcgShipName
  527. if (ObjectUtil.isEmpty(afterDataMap.get("shipName"))) {
  528. afterDataMap.put("shipName", afterDataMap.get("rcgShipName"));
  529. }
  530. if (ObjectUtil.isNotEmpty(afterDataMap.get("snapPos"))) {
  531. afterDataMap.put("orgName", orgMap.get(Convert.toStr(afterDataMap.get("snapPos"))));
  532. afterDataMap.put("deviceId", heiyanDeviceMap.get(Convert.toStr(afterDataMap.get("snapPos"))));
  533. }
  534. // 保存数据
  535. saveIllegalData(afterDataMap, ElasticConstants.HEIYAN_SHIP_RECOGNITION);
  536. client.createDocument(ElasticConstants.HEIYAN_SHIP_RECOGNITION, Convert.toStr(afterDataMap.get("id")), afterDataMap);
  537. }
  538. }
  539. private void saveIllegalData(Map<String, Object> afterDataMap, String indexName) {
  540. if (Convert.toInt(afterDataMap.get("illegalStatus")) != 1) {
  541. IllegalShipData illegalShipData = new IllegalShipData();
  542. BeanUtil.fillBeanWithMap(afterDataMap, illegalShipData, CopyOptions.create().setIgnoreProperties("id"));
  543. illegalShipData.setId(IdUtils.fastSimpleUUID());
  544. illegalShipData.setSystemId(Convert.toStr(afterDataMap.get("id")));
  545. illegalShipData.setSystemEsIndex(indexName);
  546. try {
  547. illegalShipDataService.insertIllegalShipData(illegalShipData);
  548. } catch (Exception ignored) {
  549. ignored.printStackTrace();
  550. }
  551. }
  552. }
  553. }