CanalScheduling.java 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  1. package com.ruoyi.web.job;
  2. import cn.hutool.core.bean.BeanUtil;
  3. import cn.hutool.core.bean.copier.CopyOptions;
  4. import cn.hutool.core.collection.CollUtil;
  5. import cn.hutool.core.convert.Convert;
  6. import cn.hutool.core.date.DateUtil;
  7. import cn.hutool.core.util.NumberUtil;
  8. import cn.hutool.core.util.ObjectUtil;
  9. import cn.hutool.core.util.StrUtil;
  10. import cn.hutool.http.HttpUtil;
  11. import com.alibaba.fastjson.JSON;
  12. import com.alibaba.fastjson.JSONArray;
  13. import com.alibaba.fastjson.JSONObject;
  14. import com.alibaba.otter.canal.client.CanalConnector;
  15. import com.alibaba.otter.canal.client.CanalConnectors;
  16. import com.alibaba.otter.canal.protocol.CanalEntry;
  17. import com.alibaba.otter.canal.protocol.Message;
  18. import com.google.protobuf.InvalidProtocolBufferException;
  19. import com.ruoyi.common.constant.CacheConstants;
  20. import com.ruoyi.common.constant.ElasticConstants;
  21. import com.ruoyi.common.core.redis.RedisCache;
  22. import com.ruoyi.common.utils.JdbcTypeUtil;
  23. import com.ruoyi.common.utils.uuid.IdUtils;
  24. import com.ruoyi.framework.config.ElasticSearchClient;
  25. import com.ruoyi.system.domain.IllegalShipData;
  26. import com.ruoyi.system.domain.vo.AisShipInfo;
  27. import com.ruoyi.system.domain.vo.ShipEepReportRecInfo;
  28. import com.ruoyi.system.service.IAisInfoService;
  29. import com.ruoyi.system.service.IIllegalShipDataService;
  30. import com.ruoyi.system.service.ISysConfigService;
  31. import com.ruoyi.web.core.config.CanalConfig;
  32. import lombok.SneakyThrows;
  33. import lombok.extern.slf4j.Slf4j;
  34. import org.springframework.beans.BeansException;
  35. import org.springframework.beans.factory.annotation.Autowired;
  36. import org.springframework.beans.factory.annotation.Value;
  37. import org.springframework.context.ApplicationContext;
  38. import org.springframework.context.ApplicationContextAware;
  39. import org.springframework.scheduling.annotation.Scheduled;
  40. import org.springframework.stereotype.Component;
  41. import org.springframework.util.LinkedCaseInsensitiveMap;
  42. import java.net.InetSocketAddress;
  43. import java.util.ArrayList;
  44. import java.util.Date;
  45. import java.util.HashMap;
  46. import java.util.List;
  47. import java.util.Map;
  48. /**
  49. * @Description: TODO
  50. * @Author: huangcheng
  51. * @Date: 2021/8/16
  52. * @Version V1.0
  53. */
  54. @Slf4j
  55. @Component
  56. public class CanalScheduling implements Runnable, ApplicationContextAware {
  57. private ApplicationContext applicationContext;
  58. @Autowired
  59. private ElasticSearchClient client;
  60. @Autowired
  61. private RedisCache redisCache;
  62. @Autowired
  63. private ISysConfigService configService;
  64. @Autowired
  65. private IAisInfoService aisInfoService;
  66. // @Resource
  67. // private CanalConnector canalConnector;
  68. @Value("${black.snapImgUrl}")
  69. private String blackImgUrl;
  70. @Autowired
  71. private IIllegalShipDataService illegalShipDataService;
  72. @Autowired
  73. private CanalConfig canalConfig;
  74. @Value("${spring.profiles.active}")
  75. private String env;
  76. public final static Map<String, String> orgMap = new HashMap<String, String>() {{
  77. put("南京三桥", "南京海事局");
  78. put("南京四桥", "南京海事局");
  79. put("润扬大桥", "扬州海事局");
  80. put("泰州大桥", "泰州海事局");
  81. put("江阴大桥", "江阴海事局");
  82. put("苏通大桥", "常熟海事局");
  83. }};
  84. public final static Map<String, String> heiyanDeviceMap = new HashMap<String, String>() {{
  85. put("南京三桥", "1106");
  86. put("润扬大桥", "2104");
  87. put("江阴大桥", "6106");
  88. put("苏通大桥", "9108");
  89. }};
  90. @Override
  91. @Scheduled(fixedDelay = 100) //每隔100秒执行
  92. public void run() {
  93. for (CanalConfig.Config config : canalConfig.getConfigs()) {
  94. // 创建链接
  95. CanalConnector canalConnector = CanalConnectors
  96. .newSingleConnector(new InetSocketAddress(config.getHostname(), config.getPort()), config.getDestination(), "", "");
  97. long batchId = -1;
  98. try {
  99. canalConnector.connect();
  100. canalConnector.subscribe();
  101. canalConnector.rollback();
  102. //每次拉取条数
  103. int batchSize = 1000;
  104. Message message = canalConnector.getWithoutAck(batchSize);
  105. //批次id
  106. batchId = message.getId();
  107. List<CanalEntry.Entry> entries = message.getEntries();
  108. if (batchId != -1 && entries.size() > 0) {
  109. entries.forEach(entry -> {
  110. //MySQL种my.cnf中配置的是binlog_format = ROW,这里只解析ROW类型
  111. if (entry.getEntryType() == CanalEntry.EntryType.ROWDATA) {
  112. //解析处理
  113. publishCanalEvent(entry);
  114. }
  115. });
  116. }
  117. canalConnector.ack(batchId);
  118. } catch (Exception e) {
  119. log.info("canal存在异常:{}", e.getMessage());
  120. e.printStackTrace();
  121. canalConnector.rollback(batchId);
  122. } finally {
  123. // 断开连接
  124. canalConnector.disconnect();
  125. }
  126. }
  127. }
  128. private void publishCanalEvent(CanalEntry.Entry entry) {
  129. //表名
  130. String tableName = entry.getHeader().getTableName();
  131. //数据库名
  132. String database = entry.getHeader().getSchemaName();
  133. // 操作类型
  134. CanalEntry.EventType eventType = entry.getHeader().getEventType();
  135. log.info(String.format("========> binlog[%s:%s] , name[%s,%s] , eventType[%s]",
  136. entry.getHeader().getLogfileName(), entry.getHeader().getLogfileOffset(),
  137. database, tableName,
  138. eventType));
  139. CanalEntry.RowChange rowChange;
  140. try {
  141. rowChange = CanalEntry.RowChange.parseFrom(entry.getStoreValue());
  142. } catch (InvalidProtocolBufferException e) {
  143. e.printStackTrace();
  144. return;
  145. }
  146. rowChange.getRowDatasList().forEach(rowData -> {
  147. //获取改变前的数据
  148. List<CanalEntry.Column> beforeColumnsList = rowData.getBeforeColumnsList();
  149. //获取改变后的数据
  150. List<CanalEntry.Column> afterColumnsList = rowData.getAfterColumnsList();
  151. Map<String, Object> beforeColumnsToMap = toCaseInsensitiveMap(parseColumnsToMap(beforeColumnsList, tableName));
  152. Map<String, Object> afterColumnsToMap = toCaseInsensitiveMap(parseColumnsToMap(afterColumnsList, tableName));
  153. //插入es
  154. indexES(beforeColumnsToMap, afterColumnsToMap, eventType, database, tableName);
  155. });
  156. }
  157. Map<String, Object> parseColumnsToMap(List<CanalEntry.Column> columns, String tableName) {
  158. Map<String, Object> map = new HashMap<>();
  159. columns.forEach(column -> {
  160. if (column == null) {
  161. return;
  162. }
  163. map.put(StrUtil.lowerFirst(StrUtil.toCamelCase(column.getName())), JdbcTypeUtil.typeConvert(tableName, column.getName(), column.getValue(), column.getSqlType(), column.getMysqlType()));
  164. });
  165. return map;
  166. }
  167. @SneakyThrows
  168. private void indexES(Map<String, Object> beforeDataMap, Map<String, Object> afterDataMap, CanalEntry.EventType eventType, String database, String table) {
  169. log.info("eventType:{},database:{},table:{}\nbeforeMap:{},\n afterMap:{}", eventType, database, table, beforeDataMap, afterDataMap);
  170. if (!StrUtil.equalsAnyIgnoreCase(database, "smoke_api", "ship", "ais_database")) {
  171. return;
  172. }
  173. //不是user表中的数据不处理
  174. if (!StrUtil.equalsAnyIgnoreCase(table,
  175. "ship_recognition",
  176. "ship_snap_address",
  177. "common_record",
  178. "monitor_point",
  179. "device",
  180. "illegal_ship",
  181. "sem_instrument")) {
  182. return;
  183. }
  184. String so2ThresholdVal = configService.selectConfigByKey("so2.so2");
  185. String blackThresholdVal = configService.selectConfigByKey("black.rcgSoot");
  186. // 根据不同类型处理相应的逻辑
  187. switch (eventType) {
  188. case INSERT:
  189. // 黑烟船舶数据入库
  190. if (StrUtil.equalsIgnoreCase(database, "smoke_api") && StrUtil.equalsIgnoreCase(table, "ship_recognition")) {
  191. afterDataMap.put("mmsi", afterDataMap.get("aisMmsi"));
  192. afterDataMap.put("illegalType", "heiyan");
  193. afterDataMap.put("createTime", afterDataMap.get("snapTimeFmt"));
  194. afterDataMap.put("monitorPointName", afterDataMap.get("snapPos"));
  195. if (ObjectUtil.isEmpty(afterDataMap.get("mmsi")) /*|| Convert.toStr(afterDataMap.get("mmsi")).length() != 9*/) {
  196. break;
  197. }
  198. // 判断数据状态
  199. if (ObjectUtil.isNotEmpty(afterDataMap.get("rcgSoot")) && NumberUtil.isGreaterOrEqual(Convert.toBigDecimal(afterDataMap.get("rcgSoot")),
  200. Convert.toBigDecimal(blackThresholdVal))) {
  201. // 查询黑烟图片
  202. if ("prod".equals(env)) {
  203. String imgUrl = HttpUtil.get(blackImgUrl + Convert.toStr(afterDataMap.get("id")));
  204. JSONObject response = JSON.parseObject(imgUrl);
  205. if (200 == response.getInteger("code")) {
  206. List<String> newImgList = new ArrayList<>();
  207. JSONArray imgUrlList = response.getJSONObject("data").getJSONArray("imgUrlList");
  208. String sootImgUrl = response.getJSONObject("data").getString("sootImgUrl");
  209. for (Object o : imgUrlList) {
  210. // 只保存细节、全貌开头的图片
  211. String s = Convert.toStr(o);
  212. // if (StrUtil.containsAny(s, "全貌", "细节")) {
  213. newImgList.add("http://" + s);
  214. // }
  215. }
  216. afterDataMap.put("sootImgUrl", StrUtil.isNotBlank(sootImgUrl) ? "http://" + sootImgUrl : "");
  217. afterDataMap.put("allImgUrl", newImgList);
  218. }
  219. }
  220. // 查询检测点和船舶信息、船舶进出港记录
  221. ShipEepReportRecInfo eepReportRecInfo = aisInfoService.getShipEepReportRecInfo(DateUtil.formatDate(DateUtil.offsetDay(new Date(), -20)), DateUtil.formatDate(DateUtil.tomorrow()), Convert.toStr(afterDataMap.get("mmsi")), "", "");
  222. if (eepReportRecInfo != null) {
  223. afterDataMap.put("destination", eepReportRecInfo.getNextPortName());
  224. afterDataMap.put("berthName", eepReportRecInfo.getBerthName());
  225. afterDataMap.put("expectTime", eepReportRecInfo.getExpectTime());
  226. }
  227. // 超过阈值后直接判定为违规船舶
  228. afterDataMap.put("illegalStatus", 3);
  229. afterDataMap.put("uploadFlag", 0);
  230. // TODO 上报行政检查系统
  231. } else {
  232. afterDataMap.put("uploadFlag", 0);
  233. afterDataMap.put("illegalStatus", 1);
  234. }
  235. // 查询检测点和船舶信息
  236. AisShipInfo shipInfo = aisInfoService.getShipInfo("", Convert.toStr(afterDataMap.get("mmsi")), "", "");
  237. if (shipInfo != null) {
  238. afterDataMap.put("shipName", shipInfo.getShipName());
  239. afterDataMap.put("shipRegionType", shipInfo.getShipRegionType());
  240. }
  241. // 对于没有从ais系统拿到船名的情况下,直接取rcgShipName
  242. if (ObjectUtil.isEmpty(afterDataMap.get("shipName"))) {
  243. afterDataMap.put("shipName", afterDataMap.get("rcgShipName"));
  244. }
  245. if (ObjectUtil.isNotEmpty(afterDataMap.get("snapPos"))) {
  246. afterDataMap.put("orgName", orgMap.get(Convert.toStr(afterDataMap.get("snapPos"))));
  247. afterDataMap.put("deviceId", heiyanDeviceMap.get(Convert.toStr(afterDataMap.get("snapPos"))));
  248. }
  249. // 保存数据
  250. saveIllegalData(afterDataMap, ElasticConstants.HEIYAN_SHIP_RECOGNITION);
  251. client.createDocument(ElasticConstants.HEIYAN_SHIP_RECOGNITION, Convert.toStr(afterDataMap.get("id")), afterDataMap);
  252. } else if (StrUtil.equalsIgnoreCase(database, "smoke_api") && StrUtil.equalsIgnoreCase(table, "ship_snap_address")) {
  253. // 删除设备和类型的统计缓存
  254. log.info("删除redis设备缓存");
  255. redisCache.deleteObject(CollUtil.set(false,
  256. CacheConstants.DEVICE_STATIC,
  257. CacheConstants.DEVICE_TYPE_STATIC,
  258. CacheConstants.DEVICE_LIST_STATIC));
  259. } else if (StrUtil.equalsIgnoreCase(database, "ship") && StrUtil.equalsIgnoreCase(table, "monitor_point")) {
  260. // 检测点信息
  261. client.createDocument(ElasticConstants.SO2_MONITOR_POINT, Convert.toStr(afterDataMap.get("id")), afterDataMap);
  262. redisCache.deleteObject(CacheConstants.DEVICE_STATIC);
  263. } else if (StrUtil.equalsIgnoreCase(database, "ship") && StrUtil.equalsIgnoreCase(table, "device")) {
  264. // 设备信息
  265. log.info("删除redis设备缓存");
  266. redisCache.deleteObject(CollUtil.set(false,
  267. CacheConstants.DEVICE_STATIC,
  268. CacheConstants.DEVICE_TYPE_STATIC,
  269. CacheConstants.DEVICE_LIST_STATIC));
  270. } else if (StrUtil.equalsIgnoreCase(database, "ais_database") && (StrUtil.equalsIgnoreCase(table, "sem_instrument"))) {
  271. // 嗅探系统-站点信息
  272. client.createDocument(ElasticConstants.AIS_SEM_INSTRUMENT, Convert.toStr(afterDataMap.get("id")), afterDataMap);
  273. log.info("删除redis设备缓存");
  274. redisCache.deleteObject(CollUtil.set(false,
  275. CacheConstants.DEVICE_STATIC,
  276. CacheConstants.DEVICE_TYPE_STATIC,
  277. CacheConstants.DEVICE_LIST_STATIC));
  278. } else if (StrUtil.equalsIgnoreCase(database, "ais_database") && StrUtil.equalsIgnoreCase(table, "illegal_ship")) {
  279. // 嗅探系统-违规船舶
  280. afterDataMap.put("mmsi", afterDataMap.get("shipMmsi"));
  281. afterDataMap.put("createTime", afterDataMap.get("peakTime"));
  282. afterDataMap.put("so2Percent", afterDataMap.get("sPercent"));
  283. if ("prod".equals(env)) {
  284. // 查询检测点和船舶信息、船舶进出港记录
  285. AisShipInfo shipInfo = aisInfoService.getShipInfo("", Convert.toStr(afterDataMap.get("mmsi")), "", "");
  286. if (shipInfo != null) {
  287. afterDataMap.put("shipName", shipInfo.getShipName());
  288. afterDataMap.put("shipRegionType", shipInfo.getShipRegionType());
  289. }
  290. }
  291. if (ObjectUtil.isNotEmpty(afterDataMap.get("sPercent")) && NumberUtil.isGreaterOrEqual(Convert.toBigDecimal(afterDataMap.get("sPercent")), Convert.toBigDecimal(so2ThresholdVal))) {
  292. // 查询检测点和船舶信息、船舶进出港记录
  293. ShipEepReportRecInfo eepReportRecInfo = aisInfoService.getShipEepReportRecInfo(DateUtil.formatDate(DateUtil.offsetDay(new Date(), -20)), DateUtil.formatDate(DateUtil.tomorrow()), Convert.toStr(afterDataMap.get("mmsi")), "",
  294. "");
  295. if (eepReportRecInfo != null) {
  296. afterDataMap.put("destination", eepReportRecInfo.getNextPortName());
  297. afterDataMap.put("berthName", eepReportRecInfo.getBerthName());
  298. afterDataMap.put("expectTime", eepReportRecInfo.getExpectTime());
  299. }
  300. // 嫌疑船舶
  301. afterDataMap.put("illegalStatus", 2);
  302. afterDataMap.put("uploadFlag", 0);
  303. // TODO 上报行政检查系统
  304. } else {
  305. afterDataMap.put("uploadFlag", 0);
  306. afterDataMap.put("illegalStatus", 1);
  307. }
  308. afterDataMap.put("deviceId", afterDataMap.get("semId"));
  309. // 查询站点信息
  310. Map<String, Object> sem = client.getDocById(ElasticConstants.AIS_SEM_INSTRUMENT, Convert.toStr(afterDataMap.get("semId")), "name,category");
  311. if (sem != null && ObjectUtil.equal(sem.get("code"), 200)) {
  312. Map<String, String> data = Convert.toMap(String.class, String.class, sem.get("data"));
  313. afterDataMap.put("semName", data.get("name"));
  314. afterDataMap.put("monitorPointName", data.get("category"));
  315. afterDataMap.put("orgName", orgMap.get(data.get("category")));
  316. }
  317. afterDataMap.put("illegalType", "xiutan");
  318. // 保存数据
  319. saveIllegalData(afterDataMap, ElasticConstants.AIS_ILLEGAL_SHIP);
  320. client.createDocument(ElasticConstants.AIS_ILLEGAL_SHIP, Convert.toStr(afterDataMap.get("id")), afterDataMap);
  321. }
  322. break;
  323. case UPDATE:
  324. if (StrUtil.equalsIgnoreCase(database, "smoke_api") && StrUtil.equalsIgnoreCase(table, "ship_snap_address")) {
  325. if (ObjectUtil.notEqual(beforeDataMap.get("deviceImgUrl"), afterDataMap.get("deviceImgUrl"))
  326. || ObjectUtil.notEqual(beforeDataMap.get("latitude"), afterDataMap.get("latitude"))
  327. || ObjectUtil.notEqual(beforeDataMap.get("longitude"), afterDataMap.get("longitude"))
  328. || ObjectUtil.notEqual(beforeDataMap.get("status"), afterDataMap.get("status"))) {
  329. log.info("删除redis设备缓存");
  330. redisCache.deleteObject(CollUtil.set(false,
  331. CacheConstants.DEVICE_STATIC,
  332. CacheConstants.DEVICE_TYPE_STATIC,
  333. CacheConstants.DEVICE_LIST_STATIC));
  334. }
  335. } else if (StrUtil.equalsIgnoreCase(database, "ship") && StrUtil.equalsIgnoreCase(table, "common_record")) {
  336. // 船舶记录
  337. if ("prod".equals(env)) {
  338. AisShipInfo shipInfo = aisInfoService.getShipInfo("", Convert.toStr(afterDataMap.get("mmsi")), "", "");
  339. if (shipInfo != null) {
  340. afterDataMap.put("shipName", shipInfo.getShipName());
  341. afterDataMap.put("shipRegionType", shipInfo.getShipRegionType());
  342. }
  343. }
  344. // 判断是否大于阈值
  345. if (ObjectUtil.isNotEmpty(afterDataMap.get("so2Percent")) && NumberUtil.isGreaterOrEqual(Convert.toBigDecimal(afterDataMap.get("so2Percent")), Convert.toBigDecimal(so2ThresholdVal))) {
  346. // 查询检测点和船舶信息、船舶进出港记录
  347. ShipEepReportRecInfo eepReportRecInfo = aisInfoService.getShipEepReportRecInfo(DateUtil.formatDate(DateUtil.offsetDay(new Date(), -20)), DateUtil.formatDate(DateUtil.tomorrow()), Convert.toStr(afterDataMap.get("mmsi")), "", "");
  348. if (eepReportRecInfo != null) {
  349. afterDataMap.put("destination", eepReportRecInfo.getNextPortName());
  350. afterDataMap.put("berthName", eepReportRecInfo.getBerthName());
  351. afterDataMap.put("expectTime", eepReportRecInfo.getExpectTime());
  352. }
  353. // 嫌疑船舶
  354. afterDataMap.put("illegalStatus", 2);
  355. afterDataMap.put("uploadFlag", 0);
  356. // TODO 上报行政检查系统
  357. } else {
  358. afterDataMap.put("uploadFlag", 0);
  359. afterDataMap.put("illegalStatus", 1);
  360. }
  361. Map<String, Object> monitor = client.getDocById(ElasticConstants.SO2_MONITOR_POINT, Convert.toStr(afterDataMap.get("monitorPointId")), "name");
  362. if (monitor != null && ObjectUtil.equal(monitor.get("code"), 200)) {
  363. Map<String, String> data = Convert.toMap(String.class, String.class, monitor.get("data"));
  364. afterDataMap.put("monitorPointName", data.get("name"));
  365. afterDataMap.put("orgName", orgMap.get(data.get("name")));
  366. }
  367. afterDataMap.put("illegalType", "guangpu");
  368. // 保存数据
  369. saveIllegalData(afterDataMap, ElasticConstants.SO2_ALERT);
  370. client.createDocument(ElasticConstants.SO2_ALERT, Convert.toStr(afterDataMap.get("id")), afterDataMap);
  371. } else if (StrUtil.equalsIgnoreCase(database, "ship") && StrUtil.equalsIgnoreCase(table, "monitor_point")) {
  372. // 检测点信息
  373. client.updateDocument(ElasticConstants.SO2_MONITOR_POINT, Convert.toStr(afterDataMap.get("id")), afterDataMap);
  374. redisCache.deleteObject(CacheConstants.DEVICE_STATIC);
  375. } else if (StrUtil.equalsIgnoreCase(database, "ship") && StrUtil.equalsIgnoreCase(table, "device")) {
  376. // 设备信息
  377. // 如果状态和经纬度变更才去删除redis
  378. if (ObjectUtil.notEqual(beforeDataMap.get("online_status"), afterDataMap.get("online_status")) || ObjectUtil.notEqual(beforeDataMap.get("longitude"), afterDataMap.get("longitude")) || ObjectUtil.notEqual(beforeDataMap.get(
  379. "latitude"), afterDataMap.get("latitude"))) {
  380. log.info("删除redis设备缓存");
  381. redisCache.deleteObject(CollUtil.set(false,
  382. CacheConstants.DEVICE_STATIC,
  383. CacheConstants.DEVICE_TYPE_STATIC,
  384. CacheConstants.DEVICE_LIST_STATIC));
  385. }
  386. } else if (StrUtil.equalsIgnoreCase(database, "ais_database") && (StrUtil.equalsIgnoreCase(table, "sem_instrument"))) {
  387. // 嗅探系统-站点信息
  388. client.updateDocument(ElasticConstants.AIS_SEM_INSTRUMENT, Convert.toStr(afterDataMap.get("id")), afterDataMap);
  389. if (ObjectUtil.notEqual(beforeDataMap.get("latitude"), afterDataMap.get("latitude")) || ObjectUtil.notEqual(beforeDataMap.get("longitude"), afterDataMap.get("longitude"))) {
  390. log.info("删除redis设备缓存");
  391. redisCache.deleteObject(CollUtil.set(false,
  392. CacheConstants.DEVICE_STATIC,
  393. CacheConstants.DEVICE_TYPE_STATIC,
  394. CacheConstants.DEVICE_LIST_STATIC));
  395. }
  396. }
  397. break;
  398. case DELETE:
  399. if (StrUtil.equalsIgnoreCase(database, "smoke_api") && StrUtil.equalsIgnoreCase(table, "ship_snap_address")) {
  400. log.info("删除redis设备缓存");
  401. redisCache.deleteObject(CollUtil.set(false,
  402. CacheConstants.DEVICE_STATIC,
  403. CacheConstants.DEVICE_TYPE_STATIC,
  404. CacheConstants.DEVICE_LIST_STATIC));
  405. } else if (StrUtil.equalsIgnoreCase(database, "ship") && StrUtil.equalsIgnoreCase(table, "monitor_point")) {
  406. // 检测点信息
  407. client.deleteDocument(ElasticConstants.SO2_MONITOR_POINT, Convert.toStr(afterDataMap.get("id")));
  408. redisCache.deleteObject(CacheConstants.DEVICE_STATIC);
  409. } else if (StrUtil.equalsIgnoreCase(database, "ship") && StrUtil.equalsIgnoreCase(table, "device")) {
  410. // 设备信息
  411. log.info("删除redis设备缓存");
  412. redisCache.deleteObject(CollUtil.set(false,
  413. CacheConstants.DEVICE_STATIC,
  414. CacheConstants.DEVICE_TYPE_STATIC,
  415. CacheConstants.DEVICE_LIST_STATIC));
  416. } else if (StrUtil.equalsIgnoreCase(database, "ais_database") && (StrUtil.equalsIgnoreCase(table, "sem_instrument"))) {
  417. // 嗅探系统-站点信息
  418. client.deleteDocument(ElasticConstants.AIS_SEM_INSTRUMENT, Convert.toStr(afterDataMap.get("id")));
  419. log.info("删除redis设备缓存");
  420. redisCache.deleteObject(CollUtil.set(false,
  421. CacheConstants.DEVICE_STATIC,
  422. CacheConstants.DEVICE_TYPE_STATIC,
  423. CacheConstants.DEVICE_LIST_STATIC));
  424. }
  425. break;
  426. default:
  427. break;
  428. }
  429. }
  430. private void saveIllegalData(Map<String, Object> afterDataMap, String indexName) {
  431. if (Convert.toInt(afterDataMap.get("illegalStatus")) != 1) {
  432. IllegalShipData illegalShipData = new IllegalShipData();
  433. BeanUtil.fillBeanWithMap(afterDataMap, illegalShipData, CopyOptions.create().setIgnoreProperties("id"));
  434. illegalShipData.setId(IdUtils.fastSimpleUUID());
  435. illegalShipData.setSystemId(Convert.toStr(afterDataMap.get("id")));
  436. illegalShipData.setSystemEsIndex(indexName);
  437. try {
  438. illegalShipDataService.insertIllegalShipData(illegalShipData);
  439. } catch (Exception ignored) {
  440. ignored.printStackTrace();
  441. }
  442. }
  443. }
  444. /**
  445. * 或缺数据库字段的大小写
  446. *
  447. * @param data
  448. * @param <V>
  449. * @return
  450. */
  451. private static <V> LinkedCaseInsensitiveMap<V> toCaseInsensitiveMap(Map<String, V> data) {
  452. LinkedCaseInsensitiveMap map = new LinkedCaseInsensitiveMap();
  453. map.putAll(data);
  454. return map;
  455. }
  456. @Override
  457. public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
  458. this.applicationContext = applicationContext;
  459. }
  460. }