GasCommonController.java 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558
  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. case "南京四桥":
  160. njsiq.add(deviceBo);
  161. case "润扬大桥":
  162. ry.add(deviceBo);
  163. case "泰州大桥":
  164. tz.add(deviceBo);
  165. case "江阴大桥":
  166. jy.add(deviceBo);
  167. case "苏通大桥":
  168. st.add(deviceBo);
  169. }
  170. }
  171. for (DeviceBo deviceBo : ais) {
  172. deviceBo.setOrgName(orgMap.get(deviceBo.getMonitorName()));
  173. switch (deviceBo.getMonitorName()) {
  174. case "南京三桥":
  175. njsanq.add(deviceBo);
  176. case "南京四桥":
  177. njsiq.add(deviceBo);
  178. case "润扬大桥":
  179. ry.add(deviceBo);
  180. case "泰州大桥":
  181. tz.add(deviceBo);
  182. case "江阴大桥":
  183. jy.add(deviceBo);
  184. case "苏通大桥":
  185. st.add(deviceBo);
  186. }
  187. }
  188. for (DeviceBo deviceBo : heiyan) {
  189. switch (deviceBo.getMonitorName()) {
  190. case "南京三桥":
  191. njsanq.add(deviceBo);
  192. case "南京四桥":
  193. njsiq.add(deviceBo);
  194. case "润扬大桥":
  195. ry.add(deviceBo);
  196. case "泰州大桥":
  197. tz.add(deviceBo);
  198. case "江阴大桥":
  199. jy.add(deviceBo);
  200. case "苏通大桥":
  201. st.add(deviceBo);
  202. }
  203. }
  204. data.put("南京三桥", njsanq);
  205. data.put("南京四桥", njsiq);
  206. data.put("润扬大桥", ry);
  207. data.put("泰州大桥", tz);
  208. data.put("江阴大桥", jy);
  209. data.put("苏通大桥", st);
  210. redisCache.setCacheMap(CacheConstants.DEVICE_LIST_STATIC, data);
  211. return AjaxResult.success(data);
  212. }
  213. @GetMapping("/queryShipByDeviceId")
  214. @ApiOperation("根据设备id获取设备的嫌疑或违规船舶数据")
  215. public AjaxResult queryShipByDeviceId(@RequestParam String deviceId, @RequestParam String illegalStatus, @RequestParam(required = false) Integer size, @RequestParam String... index) {
  216. Map<String, Object> equalsCondition = new HashMap<>();
  217. equalsCondition.put("illegalStatus", illegalStatus);
  218. equalsCondition.put("deviceId", deviceId);
  219. List<String> orderBy = new ArrayList<>();
  220. orderBy.add("-createTime");
  221. if (ObjectUtil.isEmpty(size)) {
  222. size = 20;
  223. }
  224. Map<String, Object> stringObjectMap = client.searchDocument(equalsCondition,
  225. null,
  226. orderBy,
  227. 1,
  228. size,
  229. index);
  230. return AjaxResult.success(Convert.toList(IllegalInfo.class, stringObjectMap.get("pageList")));
  231. }
  232. @GetMapping("/queryShipList")
  233. @ApiOperation("获取所有船舶数据-用于地图展示船舶")
  234. public AjaxResult queryShipList(@RequestParam(required = false) String monitor, @RequestParam(required = false) String startTime) {
  235. Map<String, Object> equalsCondition = new HashMap<>();
  236. if (StrUtil.isNotBlank(monitor)) {
  237. equalsCondition.put("monitorPointName", monitor);
  238. equalsCondition.put("snapPos", monitor);
  239. }
  240. Map<String, Object> rangeCondition = new HashMap<>();
  241. if (StrUtil.isBlank(startTime)) {
  242. startTime = DateUtil.formatDateTime(DateUtil.offsetDay(new Date(), -3));
  243. }
  244. rangeCondition.put("createTime", StrUtil.concat(true, "[", startTime, ",", DateUtil.now(), "]"));
  245. List<String> orderBy = new ArrayList<>();
  246. orderBy.add("-createTime");
  247. Map<String, Object> stringObjectMap = client.searchDocument(equalsCondition,
  248. rangeCondition,
  249. orderBy,
  250. 1,
  251. 10000,
  252. ElasticConstants.AIS_ILLEGAL_SHIP,
  253. ElasticConstants.SO2_ALERT,
  254. ElasticConstants.HEIYAN_SHIP_RECOGNITION);
  255. List<IllegalInfo> pageList = Convert.toList(IllegalInfo.class, stringObjectMap.get("pageList"));
  256. // 查询船舶的实时经纬度
  257. Map<String, AisShip> aisShipMap = aisShipService.queryDynamicShip(3);
  258. for (IllegalInfo illegalInfo : pageList) {
  259. if (StrUtil.isNotBlank(illegalInfo.getMmsi())) {
  260. AisShip aisShip = aisShipMap.get(illegalInfo.getMmsi());
  261. if (aisShip != null) {
  262. illegalInfo.setLat(aisShip.getLat());
  263. illegalInfo.setLng(aisShip.getLng());
  264. illegalInfo.setReceive(aisShip.getReceive());
  265. illegalInfo.setHead(aisShip.getHead());
  266. illegalInfo.setSpeed(aisShip.getSpeed());
  267. illegalInfo.setCourse(aisShip.getCourse());
  268. }
  269. }
  270. }
  271. pageList =
  272. pageList.stream().filter(ship -> ObjectUtil.isNotEmpty(ship.getLat())).collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(o -> o.getMmsi() + ";" + o.getIllegalType()))),
  273. ArrayList::new));
  274. return AjaxResult.success(pageList);
  275. }
  276. @GetMapping("/queryShipMonitorInfo")
  277. @ApiOperation("获取船舶监测数据")
  278. public AjaxResult queryShipMonitorInfo(@RequestParam String mmsi) {
  279. Map<String, Object> map = new HashMap<>(4);
  280. List<MonitorInfo> minor = new ArrayList<>();
  281. // 硫的监测数据(监测点、硫含量、监测时间、so2浓度、no2浓度、co2浓度、硫碳比)
  282. // 查询so2系统
  283. Map<String, Object> equalsCondition = new HashMap<>();
  284. equalsCondition.put("mmsi", mmsi);
  285. List<String> orderBy = new ArrayList<>();
  286. orderBy.add("-createTime");
  287. Map<String, Object> monitorMap = client.searchDocument(equalsCondition,
  288. null,
  289. orderBy,
  290. 1,
  291. 100,
  292. ElasticConstants.AIS_ILLEGAL_SHIP,
  293. ElasticConstants.SO2_ALERT,
  294. ElasticConstants.HEIYAN_SHIP_RECOGNITION);
  295. List<MonitorInfo> pageList = Convert.toList(MonitorInfo.class, monitorMap.get("pageList"));
  296. // 处理数据
  297. for (MonitorInfo monitorInfo : pageList) {
  298. if (StrUtil.isBlank(monitorInfo.getMonitorPointName()) && StrUtil.isNotBlank(monitorInfo.getSnapPos())) {
  299. monitorInfo.setMonitorPointName(monitorInfo.getSnapPos());
  300. }
  301. if (ObjectUtil.isNotEmpty(monitorInfo.getCo2Concentration())) {
  302. minor.add(monitorInfo);
  303. }
  304. }
  305. map.put("main", pageList);
  306. map.put("minor", minor);
  307. return AjaxResult.success(map);
  308. }
  309. public final static Map<String, String> orgMap = new HashMap<String, String>() {{
  310. put("南京三桥", "南京海事局");
  311. put("南京四桥", "南京海事局");
  312. put("润扬大桥", "扬州海事局");
  313. put("泰州大桥", "泰州海事局");
  314. put("江阴大桥", "江阴海事局");
  315. put("苏通大桥", "常熟海事局");
  316. }};
  317. public final static Map<String, String> heiyanDeviceMap = new HashMap<String, String>() {{
  318. put("南京三桥", "65");
  319. put("润扬大桥", "66");
  320. put("江阴大桥", "67");
  321. put("苏通大桥", "68");
  322. }};
  323. @GetMapping("/queryData")
  324. @ApiOperation("查询ES数据")
  325. public Object queryData(@RequestParam(required = false) String id, @RequestParam(required = false) Integer size, @RequestParam(required = false) String orderKey, @RequestParam String... index) {
  326. if (size == null) {
  327. size = 200;
  328. }
  329. Map<String, Object> equalsCondition = new HashMap<>();
  330. if (StrUtil.isNotBlank(id)) {
  331. equalsCondition.put("id", id);
  332. }
  333. List<String> orderBy = new ArrayList<>();
  334. if (StrUtil.isNotBlank(orderKey)) {
  335. orderBy.add("-" + orderKey);
  336. }
  337. Map<String, Object> map = client.searchDocument(equalsCondition,
  338. null,
  339. orderBy,
  340. 1,
  341. size,
  342. index);
  343. return map.get("pageList");
  344. }
  345. @DeleteMapping("/deleteIndexOneData")
  346. @ApiOperation("删除ES中某个数据")
  347. public void deleteIndexData(@RequestParam String index, @RequestParam String id) {
  348. client.deleteDocument(index, id);
  349. }
  350. @PostMapping("/sendSms")
  351. @ApiOperation("发送短信")
  352. public AjaxResult sendSms(@RequestBody JSONObject jsonObject) {
  353. String content = jsonObject.getString("content");
  354. String phone = jsonObject.getString("phone");
  355. if (StrUtil.hasBlank(content, phone)) {
  356. return AjaxResult.error("存在参数为空");
  357. }
  358. SMSUtil smsUtil = new SMSUtil();
  359. smsUtil.sendMessage(content, phone);
  360. return AjaxResult.success();
  361. }
  362. @SneakyThrows
  363. @PostMapping("/reSyncOneData")
  364. @ApiOperation("重新同步某一个数据")
  365. public void reSyncOneData(@RequestParam String index, @RequestParam String id) {
  366. client.deleteDocument(index, id);
  367. String so2ThresholdVal = configService.selectConfigByKey("so2.so2");
  368. String blackThresholdVal = configService.selectConfigByKey("black.rcgSoot");
  369. if (ElasticConstants.AIS_ILLEGAL_SHIP.equals(index)) {
  370. Map<String, Object> afterDataMap = aisDatabase.queryById(id);
  371. // 嗅探系统-违规船舶
  372. if ("prod".equals(env)) {
  373. // 查询检测点和船舶信息、船舶进出港记录
  374. if (ObjectUtil.isNotEmpty(afterDataMap.get("shipMmsi"))) {
  375. AisShipInfo shipInfo = aisInfoService.getShipInfo("", Convert.toStr(afterDataMap.get("shipMmsi")), "", "");
  376. if (shipInfo != null) {
  377. afterDataMap.put("shipName", shipInfo.getShipName());
  378. afterDataMap.put("shipRegionType", shipInfo.getShipRegionType());
  379. }
  380. }
  381. }
  382. if (ObjectUtil.isNotEmpty(afterDataMap.get("sPercent")) && NumberUtil.isGreaterOrEqual(Convert.toBigDecimal(afterDataMap.get("sPercent")), Convert.toBigDecimal(so2ThresholdVal))) {
  383. // 查询检测点和船舶信息、船舶进出港记录
  384. if (ObjectUtil.isNotEmpty(afterDataMap.get("mmsi"))) {
  385. ShipEepReportRecInfo eepReportRecInfo = aisInfoService.getShipEepReportRecInfo(DateUtil.formatDate(DateUtil.lastWeek()), DateUtil.formatDate(DateUtil.tomorrow()), Convert.toStr(afterDataMap.get("mmsi")), "", "");
  386. if (eepReportRecInfo != null) {
  387. afterDataMap.put("destination", eepReportRecInfo.getNextPortName());
  388. afterDataMap.put("berthName", eepReportRecInfo.getBerthName());
  389. }
  390. }
  391. afterDataMap.put("deviceId", afterDataMap.get("semId"));
  392. // 查询站点信息
  393. Map<String, Object> sem = client.getDocById(ElasticConstants.AIS_SEM_INSTRUMENT, Convert.toStr(afterDataMap.get("semId")), "name,category");
  394. if (sem != null && ObjectUtil.equal(sem.get("code"), 200)) {
  395. Map<String, String> data = Convert.toMap(String.class, String.class, sem.get("data"));
  396. afterDataMap.put("semName", data.get("name"));
  397. afterDataMap.put("monitorPointName", data.get("category"));
  398. afterDataMap.put("orgName", orgMap.get(data.get("category")));
  399. }
  400. // 嫌疑船舶
  401. afterDataMap.put("illegalStatus", 2);
  402. afterDataMap.put("uploadFlag", 0);
  403. // TODO 上报行政检查系统
  404. } else {
  405. afterDataMap.put("uploadFlag", 0);
  406. afterDataMap.put("illegalStatus", 1);
  407. }
  408. if (ObjectUtil.isNotEmpty(afterDataMap.get("mmsi"))) {
  409. aisInfoService.getDynamicShipInfo(Convert.toStr(afterDataMap.get("mmsi")));
  410. }
  411. afterDataMap.put("illegalType", "xiutan");
  412. // 保存数据
  413. saveIllegalData(afterDataMap, ElasticConstants.AIS_ILLEGAL_SHIP);
  414. client.createDocument(ElasticConstants.AIS_ILLEGAL_SHIP, Convert.toStr(afterDataMap.get("id")), afterDataMap);
  415. } else if (ElasticConstants.SO2_ALERT.equals(index)) {
  416. Map<String, Object> afterDataMap = so2Service.queryById(id);
  417. // 船舶记录
  418. if ("prod".equals(env)) {
  419. if (ObjectUtil.isNotEmpty(afterDataMap.get("mmsi"))) {
  420. AisShipInfo shipInfo = aisInfoService.getShipInfo("", Convert.toStr(afterDataMap.get("mmsi")), "", "");
  421. if (shipInfo != null) {
  422. afterDataMap.put("shipName", shipInfo.getShipName());
  423. afterDataMap.put("shipRegionType", shipInfo.getShipRegionType());
  424. }
  425. }
  426. }
  427. // 判断是否大于阈值
  428. if (ObjectUtil.isNotEmpty(afterDataMap.get("so2Percent")) && NumberUtil.isGreaterOrEqual(Convert.toBigDecimal(afterDataMap.get("so2Percent")), Convert.toBigDecimal(so2ThresholdVal))) {
  429. // 查询检测点和船舶信息、船舶进出港记录
  430. if (ObjectUtil.isNotEmpty(afterDataMap.get("mmsi"))) {
  431. ShipEepReportRecInfo eepReportRecInfo = aisInfoService.getShipEepReportRecInfo(DateUtil.formatDate(DateUtil.lastWeek()), DateUtil.formatDate(DateUtil.tomorrow()), Convert.toStr(afterDataMap.get("mmsi")), "", "");
  432. if (eepReportRecInfo != null) {
  433. afterDataMap.put("destination", eepReportRecInfo.getNextPortName());
  434. afterDataMap.put("berthName", eepReportRecInfo.getBerthName());
  435. }
  436. }
  437. Map<String, Object> monitor = client.getDocById(ElasticConstants.SO2_MONITOR_POINT, Convert.toStr(afterDataMap.get("monitorPointId")), "name");
  438. if (monitor != null && ObjectUtil.equal(monitor.get("code"), 200)) {
  439. Map<String, String> data = Convert.toMap(String.class, String.class, monitor.get("data"));
  440. afterDataMap.put("monitorPointName", data.get("name"));
  441. afterDataMap.put("orgName", orgMap.get(data.get("name")));
  442. }
  443. // 嫌疑船舶
  444. afterDataMap.put("illegalStatus", 2);
  445. afterDataMap.put("uploadFlag", 0);
  446. // TODO 上报行政检查系统
  447. } else {
  448. afterDataMap.put("uploadFlag", 0);
  449. afterDataMap.put("illegalStatus", 1);
  450. }
  451. if (ObjectUtil.isNotEmpty(afterDataMap.get("mmsi"))) {
  452. aisInfoService.getDynamicShipInfo(Convert.toStr(afterDataMap.get("mmsi")));
  453. }
  454. afterDataMap.put("illegalType", "guangpu");
  455. // 保存数据
  456. saveIllegalData(afterDataMap, ElasticConstants.SO2_ALERT);
  457. client.createDocument(ElasticConstants.SO2_ALERT, Convert.toStr(afterDataMap.get("id")), afterDataMap);
  458. } else if (ElasticConstants.HEIYAN_SHIP_RECOGNITION.equals(index)) {
  459. Map<String, Object> afterDataMap = heiYanService.queryById(id);
  460. if (ObjectUtil.isEmpty(afterDataMap.get("aisMmsi")) /*|| Convert.toStr(afterDataMap.get("aisMmsi")).length() != 9*/) {
  461. return;
  462. }
  463. // 判断数据状态
  464. if (ObjectUtil.isNotEmpty(afterDataMap.get("rcgSoot")) && NumberUtil.isGreaterOrEqual(Convert.toBigDecimal(afterDataMap.get("rcgSoot")),
  465. Convert.toBigDecimal(blackThresholdVal))) {
  466. // 查询黑烟图片
  467. if ("prod".equals(env)) {
  468. String imgUrl = HttpUtil.get(blackImgUrl + Convert.toStr(afterDataMap.get("id")));
  469. JSONObject response = JSON.parseObject(imgUrl);
  470. if (200 == response.getInteger("code")) {
  471. List<String> newImgList = new ArrayList<>();
  472. JSONArray imgUrlList = response.getJSONObject("data").getJSONArray("imgUrlList");
  473. String sootImgUrl = response.getJSONObject("data").getString("sootImgUrl");
  474. for (Object o : imgUrlList) {
  475. // 只保存细节、全貌开头的图片
  476. String s = Convert.toStr(o);
  477. if (StrUtil.containsAny(s, "全貌", "细节")) {
  478. newImgList.add("http://" + s);
  479. }
  480. }
  481. afterDataMap.put("sootImgUrl", StrUtil.isNotBlank(sootImgUrl) ? "http://" + sootImgUrl : "");
  482. afterDataMap.put("allImgUrl", newImgList);
  483. }
  484. }
  485. // 超过阈值后直接判定为违规船舶
  486. afterDataMap.put("illegalStatus", 3);
  487. afterDataMap.put("uploadFlag", 0);
  488. // TODO 上报行政检查系统
  489. } else {
  490. afterDataMap.put("uploadFlag", 0);
  491. afterDataMap.put("illegalStatus", 1);
  492. }
  493. if (ObjectUtil.isNotEmpty(afterDataMap.get("aisMmsi")) && Convert.toStr(afterDataMap.get("aisMmsi")).length() == 9) {
  494. aisInfoService.getDynamicShipInfo(Convert.toStr(afterDataMap.get("aisMmsi")));
  495. }
  496. afterDataMap.put("illegalType", "heiyan");
  497. // 查询检测点和船舶信息
  498. if (ObjectUtil.isNotEmpty(afterDataMap.get("aisMmsi")) && !"0".equals(Convert.toStr(afterDataMap.get("aisMmsi")))) {
  499. AisShipInfo shipInfo = aisInfoService.getShipInfo("", Convert.toStr(afterDataMap.get("aisMmsi")), "", "");
  500. if (shipInfo != null) {
  501. afterDataMap.put("shipName", shipInfo.getShipName());
  502. afterDataMap.put("shipRegionType", shipInfo.getShipRegionType());
  503. }
  504. }
  505. if (ObjectUtil.isNotEmpty(afterDataMap.get("snapPos"))) {
  506. afterDataMap.put("orgName", orgMap.get(Convert.toStr(afterDataMap.get("snapPos"))));
  507. afterDataMap.put("deviceId", heiyanDeviceMap.get(Convert.toStr(afterDataMap.get("snapPos"))));
  508. }
  509. // 保存数据
  510. saveIllegalData(afterDataMap, ElasticConstants.HEIYAN_SHIP_RECOGNITION);
  511. client.createDocument(ElasticConstants.HEIYAN_SHIP_RECOGNITION, Convert.toStr(afterDataMap.get("id")), afterDataMap);
  512. }
  513. }
  514. private void saveIllegalData(Map<String, Object> afterDataMap, String indexName) {
  515. if (Convert.toInt(afterDataMap.get("illegalStatus")) != 1) {
  516. IllegalShipData illegalShipData = new IllegalShipData();
  517. BeanUtil.fillBeanWithMap(afterDataMap, illegalShipData, CopyOptions.create().setIgnoreProperties("id"));
  518. illegalShipData.setId(IdUtils.fastSimpleUUID());
  519. illegalShipData.setSystemId(Convert.toStr(afterDataMap.get("id")));
  520. illegalShipData.setSystemEsIndex(indexName);
  521. try {
  522. illegalShipDataService.insertIllegalShipData(illegalShipData);
  523. } catch (Exception ignored) {
  524. ignored.printStackTrace();
  525. }
  526. }
  527. }
  528. }