|
@@ -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() {
|