|
@@ -7,9 +7,12 @@ 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.HistoryGpsData;
|
|
|
import com.songhua.system.domain.dto.ShipSaveDTO;
|
|
|
+import com.songhua.system.service.IBasicCruiseShipService;
|
|
|
import com.songhua.system.service.ICruiseShipMappingService;
|
|
|
import com.songhua.system.service.ISysConfigService;
|
|
|
+import com.songhua.system.service.impl.BasicCruiseShipServiceImpl;
|
|
|
import com.songhua.web.controller.utils.MD5Encryptor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -39,6 +42,8 @@ public class gpsJob {
|
|
|
@Autowired
|
|
|
private ISysConfigService configService;
|
|
|
@Autowired
|
|
|
+ private IBasicCruiseShipService basicCruiseShipService;
|
|
|
+ @Autowired
|
|
|
private RedisCache redisCache;
|
|
|
private final List<String> keys = Arrays.asList("gps_address", "app_key", "app_secret", "account", "password");
|
|
|
|
|
@@ -106,7 +111,7 @@ public class gpsJob {
|
|
|
* 获取单个设备或多个设备的信息
|
|
|
*/
|
|
|
@Scheduled(cron = "0 0/2 * * * ?")
|
|
|
- public AjaxResult getEquipment() {
|
|
|
+ public void getEquipment() {
|
|
|
log.info("获取单个设备或多个设备的信息开始");
|
|
|
AjaxResult result;
|
|
|
Object obj;
|
|
@@ -181,7 +186,6 @@ public class gpsJob {
|
|
|
cruiseShipMappingService.saveCruiseShipMapping(saveList);
|
|
|
}
|
|
|
log.info("获取单个设备或多个设备的信息结束");
|
|
|
- return AjaxResult.success();
|
|
|
} else {
|
|
|
log.error("获取单个设备或多个设备的信息返回错误代码:{}", responseCode);
|
|
|
}
|
|
@@ -191,9 +195,92 @@ public class gpsJob {
|
|
|
log.error("获取单个设备或多个设备的信息接口失败:{}", e);
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
- return error("获取单个设备或多个设备的信息接口失败");
|
|
|
+ log.error("获取单个设备或多个设备的信息接口失败");
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取设备历史定位数据信息
|
|
|
+ */
|
|
|
+ @Scheduled(cron = "0 0/1 * * * ?")
|
|
|
+ public void getShipLocation() {
|
|
|
+ log.info("获取设备历史定位数据信息开始");
|
|
|
+ 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");
|
|
|
+ List<Long> didList = basicCruiseShipService.selectDidList();
|
|
|
+ for (Long var : didList){
|
|
|
+ log.info("获取" + var + "设备历史定位数据信息开始");
|
|
|
+ String sign = MD5Encryptor.md5EncryptToUppercase(configMap.get("app_secret") +
|
|
|
+ "access_token" + obj +
|
|
|
+ "app_key" + configMap.get("app_key") +
|
|
|
+ "dev_key59346d400236ab95e95193f35f3df6a4" +
|
|
|
+ "did" + var +
|
|
|
+ "fieldsdid,lon,lat,speed,direct,gpsTime,rcvTimeformatjsonlimit-1mapBAIDUmethodwicare.gpsdata.listpagedidpage_no1sign_methodmd5sortsdid" +
|
|
|
+ "timestamp" + dateStr +
|
|
|
+ "v2.0" +
|
|
|
+ configMap.get("app_secret"));
|
|
|
+ String apiUrl = configMap.get("gps_address") +
|
|
|
+ "timestamp=" + dateStr +
|
|
|
+ "&format=json&" +
|
|
|
+ "app_key=" + configMap.get("app_key") +
|
|
|
+ "&v=2.0&sign_method=md5&method=wicare.gpsdata.list&dev_key=59346d400236ab95e95193f35f3df6a4&" +
|
|
|
+ "access_token=" + obj +
|
|
|
+ "&map=BAIDU&fields=did,lon,lat,speed,direct,gpsTime,rcvTime&sorts=did&page=did&page_no=1&limit=-1&" +
|
|
|
+ "sign=" + sign +
|
|
|
+ "&did=" + var;
|
|
|
+ try {
|
|
|
+ // 创建 URL 对象
|
|
|
+ URL url = new URL(apiUrl);
|
|
|
+ // 打开连接
|
|
|
+ HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
|
|
+ // 设置请求方法
|
|
|
+ connection.setRequestMethod("GET");
|
|
|
+ // 获取响应状态码
|
|
|
+ int responseCode = connection.getResponseCode();
|
|
|
+ if (responseCode == HttpURLConnection.HTTP_OK) {
|
|
|
+ // 读取响应内容
|
|
|
+ BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
|
|
+ String line;
|
|
|
+ StringBuilder response1 = new StringBuilder();
|
|
|
+ while ((line = reader.readLine()) != null) {
|
|
|
+ response1.append(line);
|
|
|
+ }
|
|
|
+ reader.close();
|
|
|
+ List<HistoryGpsData> objectList = JSONArray.parseArray(JSONObject.parseObject(response1.toString()).getString("data").toString(), HistoryGpsData.class);
|
|
|
+ if (!CollectionUtils.isEmpty(objectList)) {
|
|
|
+ int totalCount = objectList.size();
|
|
|
+ int batchSize = 500; // 每次批量操作的数量
|
|
|
+ int roundCount = (totalCount + batchSize - 1) / batchSize;
|
|
|
+
|
|
|
+ for (int i = 0; i < roundCount; i++) {
|
|
|
+ int startIndex = i * batchSize;
|
|
|
+ int endIndex = Math.min((i + 1) * batchSize, totalCount);
|
|
|
+ List<HistoryGpsData> batchUserList = objectList.subList(startIndex, endIndex);
|
|
|
+ cruiseShipMappingService.saveEquipmentHistoryLocation(batchUserList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ log.info("获取设备历史定位数据信息结束");
|
|
|
+ } else {
|
|
|
+ log.error("获取设备历史定位数据信息返回错误代码:{}", responseCode);
|
|
|
+ }
|
|
|
+ // 关闭连接
|
|
|
+ connection.disconnect();
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("获取设备历史定位数据信息接口失败:{}", e);
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ log.error("获取设备历史定位数据信息接口失败");
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 根据参数编号获取详细信息
|