Explorar el Código

修改对接gps

bihuisong hace 1 año
padre
commit
a31efa0592

+ 2 - 0
songhua-admin/src/main/java/com/songhua/SongHuaApplication.java

@@ -3,6 +3,7 @@ package com.songhua;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
+import org.springframework.scheduling.annotation.EnableScheduling;
 
 /**
  * 启动程序
@@ -10,6 +11,7 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
  * @author ruoyi
  */
 @SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
+@EnableScheduling
 public class SongHuaApplication {
     public static void main(String[] args) {
         // System.setProperty("spring.devtools.restart.enabled", "false");

+ 19 - 8
songhua-admin/src/main/java/com/songhua/web/quzrtz/gpsJob.java

@@ -3,7 +3,9 @@ package com.songhua.web.quzrtz;
 
 import com.alibaba.fastjson2.JSONArray;
 import com.alibaba.fastjson2.JSONObject;
+import com.songhua.common.constant.Constants;
 import com.songhua.common.core.domain.AjaxResult;
+import com.songhua.common.core.redis.RedisCache;
 import com.songhua.system.domain.GPSEquipment;
 import com.songhua.system.domain.dto.ShipSaveDTO;
 import com.songhua.system.service.ICruiseShipMappingService;
@@ -20,6 +22,7 @@ import java.net.HttpURLConnection;
 import java.net.URL;
 import java.text.SimpleDateFormat;
 import java.util.*;
+import java.util.concurrent.TimeUnit;
 import java.util.stream.Collectors;
 
 import static com.songhua.common.core.domain.AjaxResult.error;
@@ -34,8 +37,10 @@ public class gpsJob {
     private ICruiseShipMappingService cruiseShipMappingService;
     @Autowired
     private ISysConfigService configService;
+    @Autowired
+    private RedisCache redisCache;
+    private final List<String> keys = Arrays.asList("gps_address", "app_key", "app_secret", "account", "password");
 
-    private final List<String> keys = Arrays.asList("gps_address", "app_key", "app_secret","account","password");
     /**
      * 获取访问令牌
      */
@@ -81,8 +86,8 @@ public class gpsJob {
                     response.append(line);
                 }
                 reader.close();
-                // 打印响应内容
-                System.out.println(JSONObject.parseObject(response.toString()));
+                // 存入redis中
+                redisCache.setCacheObject("access_token", JSONObject.parseObject(response.toString()).get("access_token"), Constants.GPS_ACCESS_TOKEN_EXPIRATION, TimeUnit.MINUTES);
                 return success(JSONObject.parseObject(response.toString()).get("access_token"));
             } else {
                 log.error("获取访问令牌接口返回错误代码:{}", responseCode);
@@ -96,20 +101,26 @@ public class gpsJob {
         return error("获取访问令牌接口失败");
     }
 
-
     /**
      * 获取单个设备或多个设备的信息
      */
     @Scheduled(cron = "0 0/2 * * * ?")
     public AjaxResult getEquipment() {
         log.info("获取单个设备或多个设备的信息开始");
-        AjaxResult result = getToken();
+        AjaxResult result;
+        Object obj;
+        if (!redisCache.hasKey("access_token")) {
+            result = getToken();
+            obj = result.get("data");
+        } else {
+            obj = redisCache.getCacheObject("access_token");
+        }
         Date date = new Date();
         String format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date);
         Map<String, String> configMap = getStringStringMap();
         String dateStr = format.replace(" ", "%20");
         String sign = MD5Encryptor.md5EncryptToUppercase(configMap.get("app_secret") +
-                "access_token" + result.get("data") +
+                "access_token" + obj +
                 "app_key" + configMap.get("app_key") +
                 "dev_key59346d400236ab95e95193f35f3df6a4" +
                 "fieldsdid,activeGpsDataformatjsonlimit-1mapBAIDU" +
@@ -122,7 +133,7 @@ public class gpsJob {
                 "&format=json&" +
                 "app_key=" +
                 configMap.get("app_key") +
-                "&v=2.0&sign_method=md5&method=wicare.device.list&dev_key=59346d400236ab95e95193f35f3df6a4&access_token=" + result.get("data")+
+                "&v=2.0&sign_method=md5&method=wicare.device.list&dev_key=59346d400236ab95e95193f35f3df6a4&access_token=" + obj +
                 "&map=BAIDU&fields=did,activeGpsData&sorts=did&page=did&page_no=1&limit=-1&sign=" +
                 sign;
         try {
@@ -183,9 +194,9 @@ public class gpsJob {
     }
 
 
-
     /**
      * 根据参数编号获取详细信息
+     *
      * @return
      */
     private Map<String, String> getStringStringMap() {

+ 5 - 0
songhua-common/src/main/java/com/songhua/common/constant/Constants.java

@@ -96,6 +96,11 @@ public class Constants
     public static final Integer CAPTCHA_EXPIRATION = 2;
 
     /**
+     * GPS获取令牌间隔时间(分钟)
+     */
+    public static final Integer GPS_ACCESS_TOKEN_EXPIRATION = 240;
+
+    /**
      * 令牌
      */
     public static final String TOKEN = "token";

+ 39 - 17
songhua-system/src/main/java/com/songhua/system/domain/CruiseShipMapping.java

@@ -2,59 +2,81 @@ package com.songhua.system.domain;
 
 import com.fasterxml.jackson.annotation.JsonFormat;
 import com.songhua.common.annotation.Excel;
-import com.songhua.common.annotation.Log;
 import com.songhua.common.core.domain.BaseEntity;
 import lombok.Data;
 
 import java.util.Date;
 
 @Data
-public  class CruiseShipMapping extends BaseEntity {
+public class CruiseShipMapping extends BaseEntity {
 
     private static final long serialVersionUID = 1L;
 
-    /** 主键ID */
+    /**
+     * 主键ID
+     */
     private Long id;
-    /** 游船id */
+    /**
+     * 游船id
+     */
     private String shipId;
-    /** 经度 */
+    /**
+     * 经度
+     */
     private String longitude;
-    /** 纬度 */
+    /**
+     * 纬度
+     */
     private String latitude;
-    /** 游船时间 */
+    /**
+     * 游船时间
+     */
     @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     private Date shipTime;
+
     private String shipName;
-    /** 船型 */
+    /**
+     * 船型
+     */
     @Excel(name = "船型")
     private String shipType;
 
-    /** 船长 */
+    /**
+     * 船长
+     */
     @Excel(name = "船长")
     private String lengthOverall;
 
 
-    /** 船舶注册号 */
+    /**
+     * 船舶注册号
+     */
     @Excel(name = "船舶注册号")
-    private String registrationNumber;
+    private Long registrationNumber;
 
-    /** 船舱数量 */
+    /**
+     * 船舱数量
+     */
     @Excel(name = "船舱数量")
     private String quantity;
 
 
-
-    /** 船舱数量 */
+    /**
+     * 船舱数量
+     */
     @Excel(name = "驱动类型")
     private String propulsion;
 
-    /** 乘客容量 */
+    /**
+     * 乘客容量
+     */
     @Excel(name = "乘客容量")
     private String passengerCapacity;
 
 
-
-    /** 乘客容量 */
+    /**
+     * 乘客容量
+     */
     @Excel(name = "安全设备")
     private String safetyEquipment;