GasCommonController.java 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  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(), -3));
  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(3);
  277. for (IllegalInfo illegalInfo : pageList) {
  278. if (StrUtil.isNotBlank(illegalInfo.getMmsi())) {
  279. AisShip aisShip = aisShipMap.get(illegalInfo.getMmsi());
  280. if (aisShip != null) {
  281. illegalInfo.setLat(aisShip.getLat());
  282. illegalInfo.setLng(aisShip.getLng());
  283. illegalInfo.setReceive(aisShip.getReceive());
  284. illegalInfo.setHead(ObjectUtil.isEmpty(aisShip.getHead()) ? "-" : aisShip.getHead() + "");
  285. illegalInfo.setSpeed(ObjectUtil.isEmpty(aisShip.getSpeed()) ? "-" : aisShip.getSpeed() + "节");
  286. illegalInfo.setCourse(ObjectUtil.isEmpty(aisShip.getCourse()) ? "-" : aisShip.getCourse() + "");
  287. }
  288. }
  289. }
  290. pageList =
  291. pageList.stream().filter(ship -> ObjectUtil.isNotEmpty(ship.getLat())).collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(o -> o.getMmsi() + ";" + o.getIllegalType()))),
  292. ArrayList::new));
  293. return AjaxResult.success(pageList);
  294. }
  295. @GetMapping("/queryShipMonitorInfo")
  296. @ApiOperation("获取船舶监测数据")
  297. public AjaxResult queryShipMonitorInfo(@RequestParam String mmsi) {
  298. Map<String, Object> map = new HashMap<>(4);
  299. List<MonitorInfo> minor = new ArrayList<>();
  300. // 硫的监测数据(监测点、硫含量、监测时间、so2浓度、no2浓度、co2浓度、硫碳比)
  301. // 查询so2系统
  302. Map<String, Object> equalsCondition = new HashMap<>();
  303. equalsCondition.put("mmsi", mmsi);
  304. List<String> orderBy = new ArrayList<>();
  305. orderBy.add("-createTime");
  306. Map<String, Object> monitorMap = client.searchDocument(equalsCondition,
  307. null,
  308. orderBy,
  309. 1,
  310. 100,
  311. ElasticConstants.AIS_ILLEGAL_SHIP,
  312. ElasticConstants.SO2_ALERT,
  313. ElasticConstants.HEIYAN_SHIP_RECOGNITION);
  314. List<MonitorInfo> pageList = Convert.toList(MonitorInfo.class, monitorMap.get("pageList"));
  315. // 处理数据
  316. for (MonitorInfo monitorInfo : pageList) {
  317. if (StrUtil.isBlank(monitorInfo.getMonitorPointName()) && StrUtil.isNotBlank(monitorInfo.getSnapPos())) {
  318. monitorInfo.setMonitorPointName(monitorInfo.getSnapPos());
  319. }
  320. if (ObjectUtil.isNotEmpty(monitorInfo.getCo2Concentration())) {
  321. minor.add(monitorInfo);
  322. }
  323. }
  324. map.put("main", pageList);
  325. map.put("minor", minor);
  326. return AjaxResult.success(map);
  327. }
  328. public final static Map<String, String> orgMap = new HashMap<String, String>() {{
  329. put("南京三桥", "南京海事局");
  330. put("南京四桥", "南京海事局");
  331. put("润扬大桥", "扬州海事局");
  332. put("泰州大桥", "泰州海事局");
  333. put("江阴大桥", "江阴海事局");
  334. put("苏通大桥", "常熟海事局");
  335. }};
  336. public final static Map<String, String> heiyanDeviceMap = new HashMap<String, String>() {{
  337. put("南京三桥", "1106");
  338. put("润扬大桥", "2104");
  339. put("江阴大桥", "6106");
  340. put("苏通大桥", "9108");
  341. }};
  342. @GetMapping("/queryData")
  343. @ApiOperation("查询ES数据")
  344. public Object queryData(@RequestParam(required = false) String id, @RequestParam(required = false) Integer size, @RequestParam(required = false) String orderKey, @RequestParam String... index) {
  345. if (size == null) {
  346. size = 200;
  347. }
  348. Map<String, Object> equalsCondition = new HashMap<>();
  349. if (StrUtil.isNotBlank(id)) {
  350. equalsCondition.put("id", id);
  351. }
  352. List<String> orderBy = new ArrayList<>();
  353. if (StrUtil.isNotBlank(orderKey)) {
  354. orderBy.add("-" + orderKey);
  355. }
  356. Map<String, Object> map = client.searchDocument(equalsCondition,
  357. null,
  358. orderBy,
  359. 1,
  360. size,
  361. index);
  362. return map.get("pageList");
  363. }
  364. @DeleteMapping("/deleteIndexOneData")
  365. @ApiOperation("删除ES中某个数据")
  366. public void deleteIndexData(@RequestParam String index, @RequestParam String id) {
  367. client.deleteDocument(index, id);
  368. }
  369. @PostMapping("/sendSms")
  370. @ApiOperation("发送短信")
  371. public AjaxResult sendSms(@RequestBody JSONObject jsonObject) {
  372. String content = jsonObject.getString("content");
  373. String phone = jsonObject.getString("phone");
  374. if (StrUtil.hasBlank(content, phone)) {
  375. return AjaxResult.error("存在参数为空");
  376. }
  377. SMSUtil smsUtil = new SMSUtil();
  378. smsUtil.sendMessage(content, phone);
  379. return AjaxResult.success();
  380. }
  381. @SneakyThrows
  382. @PostMapping("/reSyncOneData")
  383. @ApiOperation("重新同步某一个数据")
  384. public void reSyncOneData(@RequestParam String index, @RequestParam String id) {
  385. client.deleteDocument(index, id);
  386. String so2ThresholdVal = configService.selectConfigByKey("so2.so2");
  387. String blackThresholdVal = configService.selectConfigByKey("black.rcgSoot");
  388. if (ElasticConstants.AIS_ILLEGAL_SHIP.equals(index)) {
  389. Map<String, Object> afterDataMap = aisDatabase.queryById(id);
  390. // 嗅探系统-违规船舶
  391. if ("prod".equals(env)) {
  392. // 查询检测点和船舶信息、船舶进出港记录
  393. AisShipInfo shipInfo = aisInfoService.getShipInfo("", Convert.toStr(afterDataMap.get("mmsi")), "", "");
  394. if (shipInfo != null) {
  395. afterDataMap.put("shipName", shipInfo.getShipName());
  396. afterDataMap.put("shipRegionType", shipInfo.getShipRegionType());
  397. }
  398. }
  399. if (ObjectUtil.isNotEmpty(afterDataMap.get("sPercent")) && NumberUtil.isGreaterOrEqual(Convert.toBigDecimal(afterDataMap.get("sPercent")), Convert.toBigDecimal(so2ThresholdVal))) {
  400. // 查询检测点和船舶信息、船舶进出港记录
  401. ShipEepReportRecInfo eepReportRecInfo = aisInfoService.getShipEepReportRecInfo(DateUtil.formatDate(DateUtil.offsetDay(new Date(), -20)), DateUtil.formatDate(DateUtil.tomorrow()), Convert.toStr(afterDataMap.get("mmsi")), "", "");
  402. if (eepReportRecInfo != null) {
  403. afterDataMap.put("destination", eepReportRecInfo.getNextPortName());
  404. afterDataMap.put("berthName", eepReportRecInfo.getBerthName());
  405. }
  406. afterDataMap.put("deviceId", afterDataMap.get("semId"));
  407. // 查询站点信息
  408. Map<String, Object> sem = client.getDocById(ElasticConstants.AIS_SEM_INSTRUMENT, Convert.toStr(afterDataMap.get("semId")), "name,category");
  409. if (sem != null && ObjectUtil.equal(sem.get("code"), 200)) {
  410. Map<String, String> data = Convert.toMap(String.class, String.class, sem.get("data"));
  411. afterDataMap.put("semName", data.get("name"));
  412. afterDataMap.put("monitorPointName", data.get("category"));
  413. afterDataMap.put("orgName", orgMap.get(data.get("category")));
  414. }
  415. // 嫌疑船舶
  416. afterDataMap.put("illegalStatus", 2);
  417. afterDataMap.put("uploadFlag", 0);
  418. // TODO 上报行政检查系统
  419. } else {
  420. afterDataMap.put("uploadFlag", 0);
  421. afterDataMap.put("illegalStatus", 1);
  422. }
  423. if (ObjectUtil.isNotEmpty(afterDataMap.get("mmsi"))) {
  424. aisInfoService.getDynamicShipInfo(Convert.toStr(afterDataMap.get("mmsi")));
  425. }
  426. afterDataMap.put("illegalType", "xiutan");
  427. // 保存数据
  428. saveIllegalData(afterDataMap, ElasticConstants.AIS_ILLEGAL_SHIP);
  429. client.createDocument(ElasticConstants.AIS_ILLEGAL_SHIP, Convert.toStr(afterDataMap.get("id")), afterDataMap);
  430. } else if (ElasticConstants.SO2_ALERT.equals(index)) {
  431. Map<String, Object> afterDataMap = so2Service.queryById(id);
  432. // 船舶记录
  433. if ("prod".equals(env)) {
  434. AisShipInfo shipInfo = aisInfoService.getShipInfo("", Convert.toStr(afterDataMap.get("mmsi")), "", "");
  435. if (shipInfo != null) {
  436. afterDataMap.put("shipName", shipInfo.getShipName());
  437. afterDataMap.put("shipRegionType", shipInfo.getShipRegionType());
  438. }
  439. }
  440. // 判断是否大于阈值
  441. if (ObjectUtil.isNotEmpty(afterDataMap.get("so2Percent")) && NumberUtil.isGreaterOrEqual(Convert.toBigDecimal(afterDataMap.get("so2Percent")), Convert.toBigDecimal(so2ThresholdVal))) {
  442. // 查询检测点和船舶信息、船舶进出港记录
  443. ShipEepReportRecInfo eepReportRecInfo = aisInfoService.getShipEepReportRecInfo(DateUtil.formatDate(DateUtil.offsetDay(new Date(), -20)), DateUtil.formatDate(DateUtil.tomorrow()), Convert.toStr(afterDataMap.get("mmsi")), "", "");
  444. if (eepReportRecInfo != null) {
  445. afterDataMap.put("destination", eepReportRecInfo.getNextPortName());
  446. afterDataMap.put("berthName", eepReportRecInfo.getBerthName());
  447. }
  448. // 嫌疑船舶
  449. afterDataMap.put("illegalStatus", 2);
  450. afterDataMap.put("uploadFlag", 0);
  451. // TODO 上报行政检查系统
  452. } else {
  453. afterDataMap.put("uploadFlag", 0);
  454. afterDataMap.put("illegalStatus", 1);
  455. }
  456. Map<String, Object> monitor = client.getDocById(ElasticConstants.SO2_MONITOR_POINT, Convert.toStr(afterDataMap.get("monitorPointId")), "name");
  457. if (monitor != null && ObjectUtil.equal(monitor.get("code"), 200)) {
  458. Map<String, String> data = Convert.toMap(String.class, String.class, monitor.get("data"));
  459. afterDataMap.put("monitorPointName", data.get("name"));
  460. afterDataMap.put("orgName", orgMap.get(data.get("name")));
  461. }
  462. if (ObjectUtil.isNotEmpty(afterDataMap.get("mmsi"))) {
  463. aisInfoService.getDynamicShipInfo(Convert.toStr(afterDataMap.get("mmsi")));
  464. }
  465. afterDataMap.put("illegalType", "guangpu");
  466. // 保存数据
  467. saveIllegalData(afterDataMap, ElasticConstants.SO2_ALERT);
  468. client.createDocument(ElasticConstants.SO2_ALERT, Convert.toStr(afterDataMap.get("id")), afterDataMap);
  469. } else if (ElasticConstants.HEIYAN_SHIP_RECOGNITION.equals(index)) {
  470. Map<String, Object> afterDataMap = heiYanService.queryById(id);
  471. if (ObjectUtil.isEmpty(afterDataMap.get("mmsi"))) {
  472. return;
  473. }
  474. // 判断数据状态
  475. if (ObjectUtil.isNotEmpty(afterDataMap.get("rcgSoot")) && NumberUtil.isGreaterOrEqual(Convert.toBigDecimal(afterDataMap.get("rcgSoot")),
  476. Convert.toBigDecimal(blackThresholdVal))) {
  477. // 查询黑烟图片
  478. if ("prod".equals(env)) {
  479. String imgUrl = HttpUtil.get(blackImgUrl + Convert.toStr(afterDataMap.get("id")));
  480. JSONObject response = JSON.parseObject(imgUrl);
  481. if (200 == response.getInteger("code")) {
  482. List<String> newImgList = new ArrayList<>();
  483. JSONArray imgUrlList = response.getJSONObject("data").getJSONArray("imgUrlList");
  484. String sootImgUrl = response.getJSONObject("data").getString("sootImgUrl");
  485. for (Object o : imgUrlList) {
  486. // 只保存细节、全貌开头的图片
  487. String s = Convert.toStr(o);
  488. if (StrUtil.containsAny(s, "全貌", "细节")) {
  489. newImgList.add("http://" + s);
  490. }
  491. }
  492. afterDataMap.put("sootImgUrl", StrUtil.isNotBlank(sootImgUrl) ? "http://" + sootImgUrl : "");
  493. afterDataMap.put("allImgUrl", newImgList);
  494. }
  495. }
  496. // 查询检测点和船舶信息、船舶进出港记录
  497. ShipEepReportRecInfo eepReportRecInfo = aisInfoService.getShipEepReportRecInfo(DateUtil.formatDate(DateUtil.offsetDay(new Date(), -20)), DateUtil.formatDate(DateUtil.tomorrow()), Convert.toStr(afterDataMap.get("mmsi")), "", "");
  498. if (eepReportRecInfo != null) {
  499. afterDataMap.put("destination", eepReportRecInfo.getNextPortName());
  500. afterDataMap.put("berthName", eepReportRecInfo.getBerthName());
  501. }
  502. // 超过阈值后直接判定为违规船舶
  503. afterDataMap.put("illegalStatus", 3);
  504. afterDataMap.put("uploadFlag", 0);
  505. // TODO 上报行政检查系统
  506. } else {
  507. afterDataMap.put("uploadFlag", 0);
  508. afterDataMap.put("illegalStatus", 1);
  509. }
  510. if (ObjectUtil.isNotEmpty(afterDataMap.get("mmsi")) && Convert.toStr(afterDataMap.get("mmsi")).length() == 9) {
  511. aisInfoService.getDynamicShipInfo(Convert.toStr(afterDataMap.get("mmsi")));
  512. }
  513. afterDataMap.put("illegalType", "heiyan");
  514. // 查询检测点和船舶信息
  515. if (ObjectUtil.isNotEmpty(afterDataMap.get("mmsi")) && !"0".equals(Convert.toStr(afterDataMap.get("mmsi")))) {
  516. AisShipInfo shipInfo = aisInfoService.getShipInfo("", Convert.toStr(afterDataMap.get("mmsi")), "", "");
  517. if (shipInfo != null) {
  518. afterDataMap.put("shipName", shipInfo.getShipName());
  519. afterDataMap.put("shipRegionType", shipInfo.getShipRegionType());
  520. }
  521. }
  522. // 对于没有从ais系统拿到船名的情况下,直接取rcgShipName
  523. if (ObjectUtil.isEmpty(afterDataMap.get("shipName"))) {
  524. afterDataMap.put("shipName", afterDataMap.get("rcgShipName"));
  525. }
  526. if (ObjectUtil.isNotEmpty(afterDataMap.get("snapPos"))) {
  527. afterDataMap.put("orgName", orgMap.get(Convert.toStr(afterDataMap.get("snapPos"))));
  528. afterDataMap.put("deviceId", heiyanDeviceMap.get(Convert.toStr(afterDataMap.get("snapPos"))));
  529. }
  530. // 保存数据
  531. saveIllegalData(afterDataMap, ElasticConstants.HEIYAN_SHIP_RECOGNITION);
  532. client.createDocument(ElasticConstants.HEIYAN_SHIP_RECOGNITION, Convert.toStr(afterDataMap.get("id")), afterDataMap);
  533. }
  534. }
  535. private void saveIllegalData(Map<String, Object> afterDataMap, String indexName) {
  536. if (Convert.toInt(afterDataMap.get("illegalStatus")) != 1) {
  537. IllegalShipData illegalShipData = new IllegalShipData();
  538. BeanUtil.fillBeanWithMap(afterDataMap, illegalShipData, CopyOptions.create().setIgnoreProperties("id"));
  539. illegalShipData.setId(IdUtils.fastSimpleUUID());
  540. illegalShipData.setSystemId(Convert.toStr(afterDataMap.get("id")));
  541. illegalShipData.setSystemEsIndex(indexName);
  542. try {
  543. illegalShipDataService.insertIllegalShipData(illegalShipData);
  544. } catch (Exception ignored) {
  545. ignored.printStackTrace();
  546. }
  547. }
  548. }
  549. }