|
@@ -1,27 +1,42 @@
|
|
|
package com.ruoyi.web.controller.gas;
|
|
|
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.bean.copier.CopyOptions;
|
|
|
import cn.hutool.core.convert.Convert;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
+import cn.hutool.core.util.NumberUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
+import cn.hutool.http.HttpUtil;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.ruoyi.common.constant.ElasticConstants;
|
|
|
import com.ruoyi.common.core.domain.AjaxResult;
|
|
|
+import com.ruoyi.common.utils.uuid.IdUtils;
|
|
|
import com.ruoyi.framework.config.ElasticSearchClient;
|
|
|
import com.ruoyi.system.domain.AisShip;
|
|
|
import com.ruoyi.system.domain.DeviceBo;
|
|
|
import com.ruoyi.system.domain.IllegalInfo;
|
|
|
+import com.ruoyi.system.domain.IllegalShipData;
|
|
|
import com.ruoyi.system.domain.MonitorInfo;
|
|
|
import com.ruoyi.system.domain.SyncPost;
|
|
|
+import com.ruoyi.system.domain.vo.AisShipInfo;
|
|
|
+import com.ruoyi.system.domain.vo.ShipEepReportRecInfo;
|
|
|
import com.ruoyi.system.service.IAisDatabase;
|
|
|
+import com.ruoyi.system.service.IAisInfoService;
|
|
|
import com.ruoyi.system.service.IAisShipService;
|
|
|
import com.ruoyi.system.service.IHeiYanService;
|
|
|
+import com.ruoyi.system.service.IIllegalShipDataService;
|
|
|
import com.ruoyi.system.service.ISo2Service;
|
|
|
+import com.ruoyi.system.service.ISysConfigService;
|
|
|
import com.ruoyi.web.controller.tool.SMSUtil;
|
|
|
import com.ruoyi.web.service.IGasCommonService;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
+import lombok.SneakyThrows;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
@@ -63,6 +78,16 @@ public class GasCommonController {
|
|
|
private IHeiYanService heiYanService;
|
|
|
@Autowired
|
|
|
private IAisShipService aisShipService;
|
|
|
+ @Value("${spring.profiles.active}")
|
|
|
+ private String env;
|
|
|
+ @Autowired
|
|
|
+ private IAisInfoService aisInfoService;
|
|
|
+ @Autowired
|
|
|
+ private IIllegalShipDataService illegalShipDataService;
|
|
|
+ @Autowired
|
|
|
+ private ISysConfigService configService;
|
|
|
+ @Value("${black.snapImgUrl}")
|
|
|
+ private String blackImgUrl;
|
|
|
|
|
|
@PreAuthorize("@ss.hasPermi('system:gas:sync')")
|
|
|
@PostMapping("/sync")
|
|
@@ -318,4 +343,180 @@ public class GasCommonController {
|
|
|
return AjaxResult.success();
|
|
|
}
|
|
|
|
|
|
+ @SneakyThrows
|
|
|
+ @PostMapping("/reSyncOneData")
|
|
|
+ @ApiOperation("重新同步某一个数据")
|
|
|
+ public void reSyncOneData(@RequestParam String index, @RequestParam String id) {
|
|
|
+ client.deleteDocument(index, id);
|
|
|
+ String so2ThresholdVal = configService.selectConfigByKey("so2.so2");
|
|
|
+ String blackThresholdVal = configService.selectConfigByKey("black.rcgSoot");
|
|
|
+ if (ElasticConstants.AIS_ILLEGAL_SHIP.equals(index)) {
|
|
|
+ Map<String, Object> afterDataMap = aisDatabase.queryById(id);
|
|
|
+ // 嗅探系统-违规船舶
|
|
|
+ if ("prod".equals(env)) {
|
|
|
+ // 查询检测点和船舶信息、船舶进出港记录
|
|
|
+ if (ObjectUtil.isNotEmpty(afterDataMap.get("shipMmsi"))) {
|
|
|
+ AisShipInfo shipInfo = aisInfoService.getShipInfo("", Convert.toStr(afterDataMap.get("shipMmsi")), "", "");
|
|
|
+ if (shipInfo != null) {
|
|
|
+ afterDataMap.put("shipName", shipInfo.getShipName());
|
|
|
+ afterDataMap.put("shipRegionType", shipInfo.getShipRegionType());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (ObjectUtil.isNotEmpty(afterDataMap.get("sPercent")) && NumberUtil.isGreaterOrEqual(Convert.toBigDecimal(afterDataMap.get("sPercent")), Convert.toBigDecimal(so2ThresholdVal))) {
|
|
|
+ // 查询检测点和船舶信息、船舶进出港记录
|
|
|
+ if (ObjectUtil.isNotEmpty(afterDataMap.get("mmsi"))) {
|
|
|
+ ShipEepReportRecInfo eepReportRecInfo = aisInfoService.getShipEepReportRecInfo(DateUtil.formatDate(DateUtil.lastWeek()), DateUtil.formatDate(DateUtil.tomorrow()), Convert.toStr(afterDataMap.get("mmsi")), "", "");
|
|
|
+ if (eepReportRecInfo != null) {
|
|
|
+ afterDataMap.put("destination", eepReportRecInfo.getNextPortName());
|
|
|
+ afterDataMap.put("berthName", eepReportRecInfo.getBerthName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 查询站点信息
|
|
|
+ Map<String, Object> sem = client.getDocById(ElasticConstants.AIS_SEM_INSTRUMENT, Convert.toStr(afterDataMap.get("semId")), "name,category");
|
|
|
+ if (sem != null && ObjectUtil.equal(sem.get("code"), 200)) {
|
|
|
+ Map<String, String> data = Convert.toMap(String.class, String.class, sem.get("data"));
|
|
|
+ afterDataMap.put("semName", data.get("name"));
|
|
|
+ afterDataMap.put("monitorPointName", data.get("category"));
|
|
|
+ afterDataMap.put("orgName", orgMap.get(data.get("category")));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 嫌疑船舶
|
|
|
+ afterDataMap.put("illegalStatus", 2);
|
|
|
+ afterDataMap.put("uploadFlag", 0);
|
|
|
+ // TODO 上报行政检查系统
|
|
|
+
|
|
|
+ } else {
|
|
|
+ afterDataMap.put("uploadFlag", 0);
|
|
|
+ afterDataMap.put("illegalStatus", 1);
|
|
|
+ }
|
|
|
+ if (ObjectUtil.isNotEmpty(afterDataMap.get("mmsi"))) {
|
|
|
+ aisInfoService.getDynamicShipInfo(Convert.toStr(afterDataMap.get("mmsi")));
|
|
|
+ }
|
|
|
+ afterDataMap.put("illegalType", "xiutan");
|
|
|
+ // 保存数据
|
|
|
+ saveIllegalData(afterDataMap, ElasticConstants.AIS_ILLEGAL_SHIP);
|
|
|
+ client.createDocument(ElasticConstants.AIS_ILLEGAL_SHIP, Convert.toStr(afterDataMap.get("id")), afterDataMap);
|
|
|
+
|
|
|
+ } else if (ElasticConstants.SO2_ALERT.equals(index)) {
|
|
|
+ Map<String, Object> afterDataMap = so2Service.queryById(id);
|
|
|
+
|
|
|
+ // 船舶记录
|
|
|
+ if ("prod".equals(env)) {
|
|
|
+ if (ObjectUtil.isNotEmpty(afterDataMap.get("mmsi"))) {
|
|
|
+ AisShipInfo shipInfo = aisInfoService.getShipInfo("", Convert.toStr(afterDataMap.get("mmsi")), "", "");
|
|
|
+ if (shipInfo != null) {
|
|
|
+ afterDataMap.put("shipName", shipInfo.getShipName());
|
|
|
+ afterDataMap.put("shipRegionType", shipInfo.getShipRegionType());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 判断是否大于阈值
|
|
|
+ if (ObjectUtil.isNotEmpty(afterDataMap.get("so2Percent")) && NumberUtil.isGreaterOrEqual(Convert.toBigDecimal(afterDataMap.get("so2Percent")), Convert.toBigDecimal(so2ThresholdVal))) {
|
|
|
+ // 查询检测点和船舶信息、船舶进出港记录
|
|
|
+ if (ObjectUtil.isNotEmpty(afterDataMap.get("mmsi"))) {
|
|
|
+ ShipEepReportRecInfo eepReportRecInfo = aisInfoService.getShipEepReportRecInfo(DateUtil.formatDate(DateUtil.lastWeek()), DateUtil.formatDate(DateUtil.tomorrow()), Convert.toStr(afterDataMap.get("mmsi")), "", "");
|
|
|
+ if (eepReportRecInfo != null) {
|
|
|
+ afterDataMap.put("destination", eepReportRecInfo.getNextPortName());
|
|
|
+ afterDataMap.put("berthName", eepReportRecInfo.getBerthName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Map<String, Object> monitor = client.getDocById(ElasticConstants.SO2_MONITOR_POINT, Convert.toStr(afterDataMap.get("monitorPointId")), "name");
|
|
|
+ if (monitor != null && ObjectUtil.equal(monitor.get("code"), 200)) {
|
|
|
+ Map<String, String> data = Convert.toMap(String.class, String.class, monitor.get("data"));
|
|
|
+ afterDataMap.put("monitorPointName", data.get("name"));
|
|
|
+ afterDataMap.put("orgName", orgMap.get(data.get("name")));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 嫌疑船舶
|
|
|
+ afterDataMap.put("illegalStatus", 2);
|
|
|
+ afterDataMap.put("uploadFlag", 0);
|
|
|
+ // TODO 上报行政检查系统
|
|
|
+
|
|
|
+ } else {
|
|
|
+ afterDataMap.put("uploadFlag", 0);
|
|
|
+ afterDataMap.put("illegalStatus", 1);
|
|
|
+ }
|
|
|
+ if (ObjectUtil.isNotEmpty(afterDataMap.get("mmsi"))) {
|
|
|
+ aisInfoService.getDynamicShipInfo(Convert.toStr(afterDataMap.get("mmsi")));
|
|
|
+ }
|
|
|
+ afterDataMap.put("illegalType", "guangpu");
|
|
|
+ // 保存数据
|
|
|
+ saveIllegalData(afterDataMap, ElasticConstants.SO2_ALERT);
|
|
|
+ client.createDocument(ElasticConstants.SO2_ALERT, Convert.toStr(afterDataMap.get("id")), afterDataMap);
|
|
|
+
|
|
|
+ } else if (ElasticConstants.HEIYAN_SHIP_RECOGNITION.equals(index)) {
|
|
|
+ Map<String, Object> afterDataMap = heiYanService.queryById(id);
|
|
|
+
|
|
|
+ if (ObjectUtil.isEmpty(afterDataMap.get("aisMmsi")) /*|| Convert.toStr(afterDataMap.get("aisMmsi")).length() != 9*/) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 判断数据状态
|
|
|
+ if (ObjectUtil.isNotEmpty(afterDataMap.get("rcgSoot")) && NumberUtil.isGreaterOrEqual(Convert.toBigDecimal(afterDataMap.get("rcgSoot")),
|
|
|
+ Convert.toBigDecimal(blackThresholdVal))) {
|
|
|
+ // 查询黑烟图片
|
|
|
+ if ("prod".equals(env)) {
|
|
|
+ String imgUrl = HttpUtil.get(blackImgUrl + Convert.toStr(afterDataMap.get("id")));
|
|
|
+ JSONObject response = JSON.parseObject(imgUrl);
|
|
|
+ if (200 == response.getInteger("code")) {
|
|
|
+ List<String> newImgList = new ArrayList<>();
|
|
|
+ JSONArray imgUrlList = response.getJSONObject("data").getJSONArray("imgUrlList");
|
|
|
+ String sootImgUrl = response.getJSONObject("data").getString("sootImgUrl");
|
|
|
+ for (Object o : imgUrlList) {
|
|
|
+ // 只保存细节、全貌开头的图片
|
|
|
+ String s = Convert.toStr(o);
|
|
|
+ if (StrUtil.containsAny(s, "全貌", "细节")) {
|
|
|
+ newImgList.add("http://" + s);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ afterDataMap.put("sootImgUrl", StrUtil.isNotBlank(sootImgUrl) ? "http://" + sootImgUrl : "");
|
|
|
+ afterDataMap.put("allImgUrl", newImgList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 超过阈值后直接判定为违规船舶
|
|
|
+ afterDataMap.put("illegalStatus", 3);
|
|
|
+ afterDataMap.put("uploadFlag", 0);
|
|
|
+ // TODO 上报行政检查系统
|
|
|
+
|
|
|
+ } else {
|
|
|
+ afterDataMap.put("uploadFlag", 0);
|
|
|
+ afterDataMap.put("illegalStatus", 1);
|
|
|
+ }
|
|
|
+ if (ObjectUtil.isNotEmpty(afterDataMap.get("aisMmsi")) && Convert.toStr(afterDataMap.get("aisMmsi")).length() == 9) {
|
|
|
+ aisInfoService.getDynamicShipInfo(Convert.toStr(afterDataMap.get("aisMmsi")));
|
|
|
+ }
|
|
|
+ afterDataMap.put("illegalType", "heiyan");
|
|
|
+ // 查询检测点和船舶信息
|
|
|
+ if (ObjectUtil.isNotEmpty(afterDataMap.get("aisMmsi")) && !"0".equals(Convert.toStr(afterDataMap.get("aisMmsi")))) {
|
|
|
+ AisShipInfo shipInfo = aisInfoService.getShipInfo("", Convert.toStr(afterDataMap.get("aisMmsi")), "", "");
|
|
|
+ if (shipInfo != null) {
|
|
|
+ afterDataMap.put("shipName", shipInfo.getShipName());
|
|
|
+ afterDataMap.put("shipRegionType", shipInfo.getShipRegionType());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (ObjectUtil.isNotEmpty(afterDataMap.get("snapPos"))) {
|
|
|
+ afterDataMap.put("orgName", orgMap.get(Convert.toStr(afterDataMap.get("snapPos"))));
|
|
|
+ }
|
|
|
+ // 保存数据
|
|
|
+ saveIllegalData(afterDataMap, ElasticConstants.HEIYAN_SHIP_RECOGNITION);
|
|
|
+ client.createDocument(ElasticConstants.HEIYAN_SHIP_RECOGNITION, Convert.toStr(afterDataMap.get("id")), afterDataMap);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void saveIllegalData(Map<String, Object> afterDataMap, String indexName) {
|
|
|
+ if (Convert.toInt(afterDataMap.get("illegalStatus")) != 1) {
|
|
|
+ IllegalShipData illegalShipData = new IllegalShipData();
|
|
|
+ BeanUtil.fillBeanWithMap(afterDataMap, illegalShipData, CopyOptions.create().setIgnoreProperties("id"));
|
|
|
+ illegalShipData.setId(IdUtils.fastSimpleUUID());
|
|
|
+ illegalShipData.setSystemId(Convert.toStr(afterDataMap.get("id")));
|
|
|
+ illegalShipData.setSystemEsIndex(indexName);
|
|
|
+ try {
|
|
|
+ illegalShipDataService.insertIllegalShipData(illegalShipData);
|
|
|
+ } catch (Exception ignored) {
|
|
|
+ ignored.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|