|
@@ -6,7 +6,9 @@ import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.alibaba.fastjson.serializer.SerializerFeature;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.google.common.collect.Maps;
|
|
|
+import com.shanghaigeography.Util.DateUtils;
|
|
|
import com.shanghaigeography.entity.ResultMsg;
|
|
|
import com.shanghaigeography.eum.ResultState;
|
|
|
import com.shcd.entity.ShorePowerBerthInfo;
|
|
@@ -22,22 +24,22 @@ import com.shcd.entity.ShorePowerPortInfo;
|
|
|
import com.shcd.entity.ShorePowerPortInfoNew;
|
|
|
import com.shcd.enums.GhjgPortThreeUrl;
|
|
|
import com.shcd.service.*;
|
|
|
+import com.shcd.utils.PrintLogUtils;
|
|
|
import com.shcd.utils.secret.Encodes;
|
|
|
import com.xxl.job.core.biz.model.ReturnT;
|
|
|
import com.xxl.job.core.handler.annotation.XxlJob;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Optional;
|
|
|
+import java.util.*;
|
|
|
+import java.util.concurrent.ExecutionException;
|
|
|
import java.util.concurrent.ExecutorService;
|
|
|
import java.util.concurrent.Executors;
|
|
|
import javax.annotation.Resource;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.junit.jupiter.api.parallel.Execution;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
@@ -81,6 +83,12 @@ public class ShorePowerScheduler {
|
|
|
@Resource
|
|
|
IShorePowerConnectorInfoService shorePowerConnectorInfoService;
|
|
|
|
|
|
+ @Value("${queryConnRecordInfo}")
|
|
|
+ String queryConnRecordInfo;
|
|
|
+
|
|
|
+ @Value("${shorePower}")
|
|
|
+ String shorePower;
|
|
|
+
|
|
|
ExecutorService service = Executors.newFixedThreadPool(2);
|
|
|
|
|
|
@Scheduled(cron = "0 0 0/1 * * ? ")
|
|
@@ -106,11 +114,11 @@ public class ShorePowerScheduler {
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
jsonObject.put("Sig", "59962D299728C732F772AD9CDE6A9456");
|
|
|
jsonObject.put("PlatformID", "425009768");
|
|
|
- jsonObject.put("Data",
|
|
|
- "/J9njgV+VvzgibMjaU4c0HH+Zbr9n5DRkJkfxLy0Z8agH7kzqKIbtm97MilBq0XaMbHfhxW+Vwd/JqfFVnvSbA==");
|
|
|
+ jsonObject.put("Data","/J9njgV+VvzgibMjaU4c0HH+Zbr9n5DRkJkfxLy0Z8agH7kzqKIbtm97MilBq0XaMbHfhxW+Vwd/JqfFVnvSbA==");
|
|
|
jsonObject.put("TimeStamp", "16880151424323");
|
|
|
jsonObject.put("Seq", "0001");
|
|
|
result = HttpUtil.createPost(GhjgPortThreeUrl.PROXY_SHORE_POWER.getUrl())
|
|
|
+
|
|
|
.setConnectionTimeout(3600000)
|
|
|
.setReadTimeout(3600000)
|
|
|
.header("Content-Type", "application/json")
|
|
@@ -590,31 +598,81 @@ public class ShorePowerScheduler {
|
|
|
String berthId = "";
|
|
|
String page = "1";
|
|
|
String limit = "500";
|
|
|
- String result = executeConnRecordInfoUrl(portId, deviceId, berthId, page, limit);
|
|
|
+ String startTime = "";
|
|
|
+ String endTime = "";
|
|
|
+
|
|
|
+ startTime = connRecordInfoService.getMaxModifyTime();
|
|
|
+ endTime = DateUtils.dateToString(new Date(),DateUtils.DATE_FORMAT_19);
|
|
|
+
|
|
|
+ String result = executeConnRecordInfoUrl(portId, deviceId, berthId, page, limit, startTime, endTime);
|
|
|
log.info("连船记录信息查询查询接口调用成功! ===>返回结果:{}",
|
|
|
JSONObject.toJSONString(result));
|
|
|
+ Integer total = getTotal(result);
|
|
|
+
|
|
|
+ if(total > Integer.parseInt(limit) * Integer.parseInt(page)){
|
|
|
+ while (total > Integer.parseInt(limit) * Integer.parseInt(page)){
|
|
|
+ page = String.valueOf(Integer.parseInt(page) + 1);
|
|
|
+ String res = executeConnRecordInfoUrl(portId, deviceId, berthId, page, limit, startTime, endTime);
|
|
|
+ saveConnRecordInfos(res);
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ saveConnRecordInfos(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 获取总条数
|
|
|
+ * @param result
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Integer getTotal(String result) {
|
|
|
+ Integer total = 0;
|
|
|
+ try{
|
|
|
JSONObject jsonObject = JSONObject.parseObject(result);
|
|
|
if (0 == ((int) jsonObject.get("Ret"))) {
|
|
|
String lightData = (String) jsonObject.get("Data");
|
|
|
String data = new String(Encodes.aesDecrypt(
|
|
|
- Encodes.decodeBase64(lightData),
|
|
|
- GhjgPortThreeUrl.TOKEN_KEY.getUrl().getBytes(),
|
|
|
- GhjgPortThreeUrl.TOKEN_KEY.getUrl().getBytes()), StandardCharsets.UTF_8);
|
|
|
+ Encodes.decodeBase64(lightData),
|
|
|
+ GhjgPortThreeUrl.TOKEN_KEY.getUrl().getBytes(),
|
|
|
+ GhjgPortThreeUrl.TOKEN_KEY.getUrl().getBytes()), StandardCharsets.UTF_8);
|
|
|
+ JSONObject dataJsonObject = (JSONObject) JSONObject.parse(data.toLowerCase());
|
|
|
+ total = (Integer) dataJsonObject.get("total");
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ PrintLogUtils.printErrorLogInfo(e,"getTotal异常:");
|
|
|
+ }
|
|
|
+ return total;
|
|
|
+ }
|
|
|
+
|
|
|
+ public boolean saveConnRecordInfos(String result){
|
|
|
+ boolean flag = false;
|
|
|
+ try{
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(result);
|
|
|
+ if (0 == ((int) jsonObject.get("Ret"))) {
|
|
|
+ String lightData = (String) jsonObject.get("Data");
|
|
|
+ String data = new String(Encodes.aesDecrypt(
|
|
|
+ Encodes.decodeBase64(lightData),
|
|
|
+ GhjgPortThreeUrl.TOKEN_KEY.getUrl().getBytes(),
|
|
|
+ GhjgPortThreeUrl.TOKEN_KEY.getUrl().getBytes()), StandardCharsets.UTF_8);
|
|
|
log.info("==============> 业务数据:{}", JSONObject.toJSONString(data));
|
|
|
JSONObject dataJsonObject = (JSONObject) JSONObject.parse(data.toLowerCase());
|
|
|
JSONArray records = (JSONArray) dataJsonObject.get("records");
|
|
|
log.info("records ====>{}", records);
|
|
|
String arrayJSON = JSONObject.toJSONString(records, SerializerFeature.WriteClassName);
|
|
|
List<JSONObject> JSONObjectList = JSONObject.parseArray(arrayJSON,
|
|
|
- JSONObject.class);
|
|
|
+ JSONObject.class);
|
|
|
List<ShorePowerConnRecordInfo> connRecordInfos = new ArrayList<>();
|
|
|
JSONObjectList.forEach(x -> {
|
|
|
ShorePowerConnRecordInfo connRecordInfo = JSONObject.parseObject(JSON.toJSONString(x),
|
|
|
- ShorePowerConnRecordInfo.class);
|
|
|
+ ShorePowerConnRecordInfo.class);
|
|
|
connRecordInfos.add(connRecordInfo);
|
|
|
});
|
|
|
log.info("==============> 业务转换为港航数据:{}",
|
|
|
- JSONObject.toJSONString(connRecordInfos));
|
|
|
+ JSONObject.toJSONString(connRecordInfos));
|
|
|
|
|
|
|
|
|
for (ShorePowerConnRecordInfo connRecordInfo : connRecordInfos) {
|
|
@@ -622,10 +680,12 @@ public class ShorePowerScheduler {
|
|
|
}
|
|
|
log.info("操作完成,共有{}条数据", connRecordInfos.size());
|
|
|
|
|
|
+ flag = true;
|
|
|
}
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
+ }catch (Exception e){
|
|
|
+ PrintLogUtils.printErrorLogInfo(e,"saveConnRecordInfos异常:");
|
|
|
}
|
|
|
+ return flag;
|
|
|
}
|
|
|
|
|
|
@Scheduled(cron = "0 0/1 * * * ?")
|
|
@@ -839,7 +899,7 @@ public class ShorePowerScheduler {
|
|
|
JSONObject berthInfo = new JSONObject();
|
|
|
LocalDateTime now = LocalDateTime.now();
|
|
|
LocalDateTime oneHourAgo = now.minusHours(24);
|
|
|
- DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd hh:mm:ss");
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
berthInfo.put("startTime", formatter.format(oneHourAgo));
|
|
|
berthInfo.put("endTime", formatter.format(now));
|
|
|
berthInfo.put("portId", portId);
|
|
@@ -879,7 +939,7 @@ public class ShorePowerScheduler {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private String executeConnRecordInfoUrl(String portId, String deviceId, String berthId,
|
|
|
+ public String executeConnRecordInfoUrl(String portId, String deviceId, String berthId,
|
|
|
String page, String limit, String startTime, String endTime) {
|
|
|
try {
|
|
|
JSONObject tokenJsonObject = JSONObject.parseObject(getToken());
|
|
@@ -888,9 +948,6 @@ public class ShorePowerScheduler {
|
|
|
String platformID = (String) tokenData.get("PlatformID");
|
|
|
JSONObject data = new JSONObject();
|
|
|
JSONObject berthInfo = new JSONObject();
|
|
|
- LocalDateTime now = LocalDateTime.now();
|
|
|
- LocalDateTime oneHourAgo = now.minusHours(24);
|
|
|
- DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd hh:mm:ss");
|
|
|
berthInfo.put("startTime", startTime);
|
|
|
berthInfo.put("endTime", endTime);
|
|
|
berthInfo.put("portId", portId);
|
|
@@ -918,7 +975,9 @@ public class ShorePowerScheduler {
|
|
|
String reqSign = Encodes.sign(param, GhjgPortThreeUrl.TOKEN_KEY.getUrl());
|
|
|
param.put("Sig", reqSign);
|
|
|
log.info("=====> 入参:{}", JSONObject.toJSONString(param));
|
|
|
+
|
|
|
HttpRequest post = HttpUtil.createPost(GhjgPortThreeUrl.PROXY_QUERY_CONNRECORD_INFO.getUrl());
|
|
|
+
|
|
|
Map<String, String> headers = new HashMap<>();
|
|
|
headers.put("Authorization", "Bearer" + " " + accessToken);
|
|
|
headers.put("Content-Type", "application/json;charset=utf-8");
|