|
@@ -0,0 +1,163 @@
|
|
|
+package com.huimv.transmission.task;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.huimv.transmission.entity.form.PigStockForm;
|
|
|
+import com.huimv.transmission.result.R;
|
|
|
+import com.huimv.transmission.service.DataPushService;
|
|
|
+import com.huimv.transmission.service.EartagDataService;
|
|
|
+import com.huimv.transmission.utils.PageUtils;
|
|
|
+import org.apache.http.client.methods.HttpPost;
|
|
|
+import org.apache.http.entity.StringEntity;
|
|
|
+import org.apache.http.impl.client.CloseableHttpClient;
|
|
|
+import org.apache.http.impl.client.HttpClients;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.context.annotation.Configuration;
|
|
|
+import org.springframework.scheduling.annotation.Async;
|
|
|
+import org.springframework.scheduling.annotation.EnableAsync;
|
|
|
+import org.springframework.scheduling.annotation.Scheduled;
|
|
|
+
|
|
|
+import java.io.IOException;
|
|
|
+import java.nio.charset.Charset;
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ *
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author yinhao
|
|
|
+ * @date 2021/7/27 8:39
|
|
|
+ */
|
|
|
+@EnableAsync
|
|
|
+@Configuration
|
|
|
+public class DataProcessingTask {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private DataPushService dataPushService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private EartagDataService eartagDataService;
|
|
|
+
|
|
|
+
|
|
|
+ @Async
|
|
|
+ @Scheduled(cron = "0 0 0 * * ?")
|
|
|
+ public void getNewEartagList() {
|
|
|
+
|
|
|
+ CloseableHttpClient httpClient = null;
|
|
|
+ try {
|
|
|
+ HttpPost httpPost = new HttpPost("http://127.0.0.1:8220/pig/recive");
|
|
|
+ httpPost.addHeader("Content-Type", "application/json");
|
|
|
+ httpClient = HttpClients.createDefault();
|
|
|
+
|
|
|
+ eartagDataService.handleNewAndOffLineEartag();
|
|
|
+
|
|
|
+ PageUtils page = dataPushService.getNewPigStock(1, 1000);
|
|
|
+ handleDataAndPush(page, httpPost, httpClient, 1);
|
|
|
+
|
|
|
+ int pageSize = page.getPageSize();
|
|
|
+ int totalPage = page.getTotalPage();
|
|
|
+ for (int i = 2; i <= totalPage; i++) {
|
|
|
+ PageUtils pigStock = dataPushService.getNewPigStock(i, pageSize);
|
|
|
+ handleDataAndPush(pigStock, httpPost, httpClient, 1);
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } finally {
|
|
|
+ try {
|
|
|
+ if (httpClient != null) {
|
|
|
+ httpClient.close();
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Async
|
|
|
+ @Scheduled(cron = "0 0 0 * * ?")
|
|
|
+ public void getOffLineEartagList() {
|
|
|
+ CloseableHttpClient httpClient = null;
|
|
|
+ try {
|
|
|
+ HttpPost httpPost = new HttpPost("http://127.0.0.1:8220/pig/recive");
|
|
|
+ httpPost.addHeader("Content-Type", "application/json");
|
|
|
+ httpClient = HttpClients.createDefault();
|
|
|
+
|
|
|
+ eartagDataService.handleNewAndOffLineEartag();
|
|
|
+
|
|
|
+ PageUtils page = dataPushService.getOffLinePigStock(1, 1000);
|
|
|
+ handleDataAndPush(page, httpPost, httpClient, 2);
|
|
|
+
|
|
|
+ int pageSize = page.getPageSize();
|
|
|
+ int totalPage = page.getTotalPage();
|
|
|
+ for (int i = 2; i <= totalPage; i++) {
|
|
|
+ PageUtils pigStock = dataPushService.getOffLinePigStock(i, pageSize);
|
|
|
+ handleDataAndPush(pigStock, httpPost, httpClient, 2);
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } finally {
|
|
|
+ try {
|
|
|
+ if (httpClient != null) {
|
|
|
+ httpClient.close();
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void handleDataAndPush(PageUtils page, HttpPost httpPost, CloseableHttpClient httpClient, Integer type) throws IOException {
|
|
|
+ R resultData = R.ok().put("resultData", page);
|
|
|
+ String string = null;
|
|
|
+ if (type == 2) {
|
|
|
+ string = JSONObject.toJSONString(resultData).replace("new", "eliminate");
|
|
|
+ } else {
|
|
|
+ string = JSONObject.toJSONString(resultData);
|
|
|
+ }
|
|
|
+ System.out.println(string);
|
|
|
+ httpPost.setEntity(new StringEntity(string, Charset.defaultCharset()));
|
|
|
+ httpClient.execute(httpPost);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Async
|
|
|
+ @Scheduled(cron = "0 0 0 * * ?")
|
|
|
+ public void pushPigStock() {
|
|
|
+
|
|
|
+ CloseableHttpClient httpClient = null;
|
|
|
+ try {
|
|
|
+ HttpPost httpPost = new HttpPost("http://127.0.0.1:8220/dataPush/recive");
|
|
|
+ httpPost.addHeader("Content-Type", "application/json");
|
|
|
+ httpClient = HttpClients.createDefault();
|
|
|
+
|
|
|
+ PigStockForm pigStockForm = new PigStockForm(1,1000);
|
|
|
+ PageUtils page = dataPushService.getPigStock(pigStockForm);
|
|
|
+ R resultData = R.ok().put("resultData", page);
|
|
|
+ String string = JSONObject.toJSONString(resultData).replace("newCount", "new");
|
|
|
+ System.out.println(string);
|
|
|
+
|
|
|
+ httpPost.setEntity(new StringEntity(string, Charset.defaultCharset()));
|
|
|
+ httpClient.execute(httpPost);
|
|
|
+
|
|
|
+ int totalPage = page.getTotalPage();
|
|
|
+ for (int i = 2; i <= totalPage; i++) {
|
|
|
+ pigStockForm.setPageNo(i);
|
|
|
+ PageUtils pigStock = dataPushService.getPigStock(pigStockForm);
|
|
|
+ R result = R.ok().put("resultData", pigStock);
|
|
|
+ String jsonData = JSONObject.toJSONString(result).replace("newCount", "new");
|
|
|
+ httpPost.setEntity(new StringEntity(jsonData, Charset.defaultCharset()));
|
|
|
+ httpClient.execute(httpPost);
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } finally {
|
|
|
+ try {
|
|
|
+ if (httpClient != null) {
|
|
|
+ httpClient.close();
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|