GasCommonController.java 27 KB

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