|
@@ -1,15 +1,18 @@
|
|
|
package com.ruoyi.system.service.impl;
|
|
|
|
|
|
import cn.hutool.core.convert.Convert;
|
|
|
+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.core.redis.RedisCache;
|
|
|
import com.ruoyi.system.domain.vo.AisShipInfo;
|
|
|
import com.ruoyi.system.domain.vo.ShipEepReportRecInfo;
|
|
|
import com.ruoyi.system.service.IAisInfoService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
@@ -32,8 +35,9 @@ public class AisInfoServiceImpl implements IAisInfoService {
|
|
|
private String shipEepReportRecInfoUrl;
|
|
|
@Value("${third.shipBaseInfo}")
|
|
|
private String shipBaseInfo;
|
|
|
- @Value("${third.shipDynamicInfo}")
|
|
|
- private String shipDynamicInfo;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private RedisCache redisCache;
|
|
|
|
|
|
/**
|
|
|
* 获取船舶进出港记录
|
|
@@ -57,7 +61,7 @@ public class AisInfoServiceImpl implements IAisInfoService {
|
|
|
try {
|
|
|
String para = HttpUtil.toParams(params);
|
|
|
String getResult = HttpUtil.get(shipEepReportRecInfoUrl + "?" + para);
|
|
|
- log.info("入参:{},获取进出港数据:{}", para, getResult);
|
|
|
+ log.debug("入参:{},获取进出港数据:{}", para, getResult);
|
|
|
JSONObject jsonObject = JSON.parseObject(getResult);
|
|
|
if (jsonObject != null && 200 == jsonObject.getInteger("code")) {
|
|
|
JSONArray result = jsonObject.getJSONArray("result");
|
|
@@ -76,23 +80,30 @@ public class AisInfoServiceImpl implements IAisInfoService {
|
|
|
|
|
|
@Override
|
|
|
public AisShipInfo getShipInfo(String shipnameCn, String mmsi, String shipId, String shipNo) {
|
|
|
- log.info("当前环境:{}", profile);
|
|
|
+ log.debug("当前环境:{}", profile);
|
|
|
if ("prod".equals(profile) && StrUtil.isNotBlank(mmsi) && mmsi.length() == 9) {
|
|
|
+ // 先从缓存找
|
|
|
+ AisShipInfo baseInfo = redisCache.getCacheMapValue("ais:base", mmsi);
|
|
|
+ if (ObjectUtil.isNotEmpty(baseInfo)) {
|
|
|
+ return baseInfo;
|
|
|
+ }
|
|
|
+
|
|
|
Map<String, Object> params = new HashMap<>();
|
|
|
-// params.put("shipnameCn", shipnameCn);
|
|
|
params.put("mmsi", mmsi);
|
|
|
-// params.put("shipId", shipId);
|
|
|
-// params.put("shipNo", shipNo);
|
|
|
try {
|
|
|
String url = shipBaseInfo + "?" + HttpUtil.toParams(params);
|
|
|
String getResult = HttpUtil.get(url);
|
|
|
- log.info("调用地址:{}。获取船舶数据:{}", url, getResult);
|
|
|
+ log.debug("调用地址:{}。获取船舶数据:{}", url, getResult);
|
|
|
JSONObject jsonObject = JSON.parseObject(getResult);
|
|
|
if (jsonObject != null && 200 == jsonObject.getInteger("code")) {
|
|
|
JSONArray result = jsonObject.getJSONArray("data");
|
|
|
if (result != null && !result.isEmpty()) {
|
|
|
Map<String, String> stringStringMap = Convert.toMap(String.class, String.class, result.get(0));
|
|
|
- return AisShipInfo.builder().shipName(stringStringMap.get("shipnameCn")).shipRegionType(stringStringMap.get("shipRegionType")).build();
|
|
|
+ AisShipInfo build = AisShipInfo.builder().shipName(stringStringMap.get("shipnameCn")).shipRegionType(stringStringMap.get("shipRegionType")).build();
|
|
|
+ if (StrUtil.isNotBlank(stringStringMap.get("shipnameCn"))) {
|
|
|
+ redisCache.setCacheMapValue("ais:base", mmsi, build);
|
|
|
+ }
|
|
|
+ return build;
|
|
|
}
|
|
|
}
|
|
|
} catch (Exception e) {
|