|
@@ -0,0 +1,89 @@
|
|
|
+package com.sooka.sponest.dataexchange.sendChange.quartz;
|
|
|
+
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.ruoyi.common.core.domain.R;
|
|
|
+import com.sooka.sponest.dataexchange.remoteapi.service.center.data.RemoteDataBaseService;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.scheduling.annotation.Scheduled;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.io.BufferedReader;
|
|
|
+import java.io.InputStreamReader;
|
|
|
+import java.net.HttpURLConnection;
|
|
|
+import java.net.URL;
|
|
|
+import java.net.URLEncoder;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.Calendar;
|
|
|
+import java.util.Date;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@Component
|
|
|
+public class EquipDataJob {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private RemoteDataBaseService remoteDataBaseService;
|
|
|
+
|
|
|
+ @Value("${equioData.accessKey}")
|
|
|
+ private String accessKey;
|
|
|
+
|
|
|
+ @Value("${equioData.ip}")
|
|
|
+ private String ip;
|
|
|
+
|
|
|
+ @Scheduled(cron = "0 0/10 * * * ?")
|
|
|
+ public void getEquipJobRecords() throws Exception {
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ Date now = new Date();
|
|
|
+ String endTime = URLEncoder.encode(sdf.format(now), "UTF-8");
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ //设置入参开始时间
|
|
|
+ calendar.setTime(now);
|
|
|
+ // 获取当前时间前10分钟的日期
|
|
|
+ calendar.add(Calendar.MINUTE, -10);
|
|
|
+ String startTime = URLEncoder.encode(sdf.format(calendar.getTime()), "UTF-8");
|
|
|
+// String accessKey = "d99f0830813a4d82921aefa002ddfb22";
|
|
|
+ Integer page = 1;
|
|
|
+ for (int i = 1; i <= page; i++) {
|
|
|
+ String urlString = ip + "/dev-api/outData/getJobRecords?page=" + page + "&size=10&createStartTime=" + startTime + "&createEndTime=" + endTime;
|
|
|
+// String urlString = "http://36.135.7.83:81/dev-api/outData/getJobRecords?page=1&size=10&createStartTime=2024-05-20%2010:50:33&createEndTime=2024-11-20%2010:50:33";
|
|
|
+ try {
|
|
|
+ URL url = new URL(urlString);
|
|
|
+ HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
|
|
+ connection.setRequestMethod("GET");
|
|
|
+ connection.setRequestProperty("access-key", accessKey);
|
|
|
+ int responseCode = connection.getResponseCode();
|
|
|
+ if (responseCode == HttpURLConnection.HTTP_OK) {
|
|
|
+ BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
|
|
+ String inputLine;
|
|
|
+ StringBuilder response = new StringBuilder();
|
|
|
+ while ((inputLine = in.readLine()) != null) {
|
|
|
+ response.append(inputLine);
|
|
|
+ }
|
|
|
+ in.close();
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(response.toString());
|
|
|
+ page = (Integer) JSONObject.parseObject(jsonObject.get("data").toString()).get("pages");
|
|
|
+ JSONArray jsonArray = JSONObject.parseArray(JSONObject.parseObject(jsonObject.get("data").toString()).get("records").toString());
|
|
|
+ R<?> result = remoteDataBaseService.insertEnforceLawInfoByList(jsonArray);
|
|
|
+ if (result.getCode() == 200) {
|
|
|
+ log.info("推送成功");
|
|
|
+ } else {
|
|
|
+ log.error("推送失败");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ log.error("调用接口返回code代码:{}", responseCode);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("调用接口报错");
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|