ソースを参照

增加获取多牧场生产数据,
增加获取多牧场存栏数据,
增加获取多牧场成本数据

zhuoning 3 年 前
コミット
b2dc551526

+ 13 - 1
huimv-hy-production/huimv.hy.autoGetData/pom.xml

@@ -11,6 +11,18 @@
 
     <artifactId>huimv.hy.autoGetData</artifactId>
 
-
+    <dependencies>
+        <!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient -->
+        <dependency>
+            <groupId>org.apache.httpcomponents</groupId>
+            <artifactId>httpclient</artifactId>
+            <version>4.5.5</version>
+        </dependency>
+        <dependency>
+            <groupId>com.alibaba</groupId>
+            <artifactId>fastjson</artifactId>
+            <version>1.2.28</version>
+        </dependency>
+    </dependencies>
 
 </project>

+ 27 - 8
huimv-hy-production/huimv.hy.autoGetData/src/main/java/com/huimv/production/autoGetData/config/SaticScheduleTask.java

@@ -10,6 +10,7 @@ import org.springframework.scheduling.annotation.SchedulingConfigurer;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.io.IOException;
 import java.time.LocalDateTime;
 import java.util.List;
 
@@ -38,7 +39,7 @@ public class SaticScheduleTask  {
 
 
 //    @Scheduled(cron = "0/5 * * * * ?")
-    @Scheduled(cron = "0 * * * * ? ")
+//    @Scheduled(cron = "0 * * * * ? ")
     private void getPsyTask(){
         System.err.println("执行 getPsyTask 执行静态定时任务时间: " + LocalDateTime.now());
         iAutoGetErpData.getPsy();
@@ -46,21 +47,21 @@ public class SaticScheduleTask  {
 
 
 //    @Scheduled(cron = "* 0/5 * * * ?")
-    @Scheduled(cron = "0 * * * * ? ")
+//    @Scheduled(cron = "0 * * * * ? ")
     private void getReEstrusRate(){
         System.err.println("执行 getReEstrusRate 执行静态定时任务时间: " + LocalDateTime.now());
         iAutoGetErpData.getReEstrusRate();
     }
 
 //    @Scheduled(cron = "* 0/5 * * * ?")
-    @Scheduled(cron = "0 * * * * ? ")
+//    @Scheduled(cron = "0 * * * * ? ")
     private void getParturitionRate(){
         System.err.println("执行 getParturitionRate 执行静态定时任务时间: " + LocalDateTime.now());
         iAutoGetErpData.getParturitionRate();
     }
 
 //    @Scheduled(cron = "* 0/5 * * * ?")
-@Scheduled(cron = "0 * * * * ? ")
+//@Scheduled(cron = "0 * * * * ? ")
     @RequestMapping("/getStorage")
     private List getStorage(){
         System.err.println("执行 getStorage 执行静态定时任务时间: " + LocalDateTime.now());
@@ -68,25 +69,25 @@ public class SaticScheduleTask  {
     }
 
 
-    @Scheduled(cron = "0 * * * * ? ")
+//    @Scheduled(cron = "0 * * * * ? ")
     private void getPigletInfo(){
         System.err.println("执行 getPigletInfo 执行静态定时任务时间: " + LocalDateTime.now());
         iAutoGetErpData.getPigletInfo();
     }
 
-    @Scheduled(cron = "0 * * * * ? ")
+//    @Scheduled(cron = "0 * * * * ? ")
     private void getMateQuantity(){
         System.err.println("执行 getMateQuantity 执行静态定时任务时间: " + LocalDateTime.now());
         iAutoGetErpData.getMateQuantity();
     }
 
-    @Scheduled(cron = "0 * * * * ? ")
+//    @Scheduled(cron = "0 * * * * ? ")
     private void getConceptionRate(){
         System.err.println("执行 getConceptionRate 执行静态定时任务时间: " + LocalDateTime.now());
         iAutoGetErpData.getConceptionRate();
     }
 
-    @Scheduled(cron = "0 * * * * ? ")
+//    @Scheduled(cron = "0 * * * * ? ")
     private void getAllStorage(){
         System.err.println("执行 getAllStorage 执行静态定时任务时间: " + LocalDateTime.now());
         iAutoGetErpData.getAllStorage();
@@ -100,4 +101,22 @@ public class SaticScheduleTask  {
         return iAutoGetErpData.findAll();
     }
 
+//    @Scheduled(cron = "60 * * * * ? ")
+    private void getManyFarmProduce() throws IOException {
+        //获取多牧场生产数
+        iAutoGetErpData.getManyFarmProduce();
+    }
+
+    //    @Scheduled(cron = "60 * * * * ? ")
+    private void getManyFarmStock() throws IOException {
+        //获取多牧场存栏
+        iAutoGetErpData.getManyFarmStock();
+    }
+
+    //    @Scheduled(cron = "60 * * * * ? ")
+    private void getCostWithManyFarm() throws IOException {
+        //获取多牧场生产成本
+        iAutoGetErpData.getCostWithManyFarm();
+    }
+
 }

+ 49 - 0
huimv-hy-production/huimv.hy.autoGetData/src/main/java/com/huimv/production/autoGetData/controller/DataControll.java

@@ -0,0 +1,49 @@
+package com.huimv.production.autoGetData.controller;
+
+import com.huimv.production.autoGetData.service.IAutoGetErpData;
+import com.huimv.production.autoGetData.service.impl.AutoGetErpDataImpl;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.io.IOException;
+
+/**
+ * @Project : huimv.shiwan
+ * @Package : com.huimv.biosafety.uface.controller
+ * @Description : TODO
+ * @Version : 1.0
+ * @Author : ZhuoNing
+ * @Create : 2020-12-25
+ **/
+@RestController
+@RequestMapping(value = "/data")
+public class DataControll {
+    @Autowired
+    private IAutoGetErpData autoGetErpData;
+
+    @RequestMapping(value = "/getToken",method = RequestMethod.GET)
+    public void getToken() throws IOException {
+        //
+        autoGetErpData.getRemoteToken();
+    }
+
+    @RequestMapping(value = "/getManyFarmProduce",method = RequestMethod.GET)
+    public void getManyFarmProduce() throws IOException {
+        //
+        autoGetErpData.getManyFarmProduce();
+    }
+
+    @RequestMapping(value = "/getManyFarmStock",method = RequestMethod.GET)
+    public void getManyFarmStock() throws IOException {
+        //
+        autoGetErpData.getManyFarmStock();
+    }
+
+    @RequestMapping(value = "/getCostWithManyFarm",method = RequestMethod.GET)
+    public void getCostWithManyFarm() throws IOException {
+        //
+        autoGetErpData.getCostWithManyFarm();
+    }
+}

+ 9 - 0
huimv-hy-production/huimv.hy.autoGetData/src/main/java/com/huimv/production/autoGetData/service/IAutoGetErpData.java

@@ -1,5 +1,6 @@
 package com.huimv.production.autoGetData.service;
 
+import java.io.IOException;
 import java.util.List;
 
 public interface IAutoGetErpData {
@@ -20,4 +21,12 @@ public interface IAutoGetErpData {
     void getAllStorage();
 
     List findAll();
+
+    void getManyFarmProduce() throws IOException;
+
+    String getRemoteToken() throws IOException;
+
+    void getManyFarmStock() throws IOException;
+
+    void getCostWithManyFarm() throws IOException;
 }

+ 155 - 1
huimv-hy-production/huimv.hy.autoGetData/src/main/java/com/huimv/production/autoGetData/service/impl/AutoGetErpDataImpl.java

@@ -3,17 +3,22 @@ package com.huimv.production.autoGetData.service.impl;
 import cn.hutool.core.date.DateTime;
 import cn.hutool.core.date.DateUtil;
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+//import com.huimv.common.date.DateUtil;
 import com.huimv.production.autoGetData.entity.IndexParameter;
 import com.huimv.production.autoGetData.entity.ProductionGroup;
 import com.huimv.production.autoGetData.repo.IndexParameterRepository;
 import com.huimv.production.autoGetData.repo.ProductionGroupRepo;
 import com.huimv.production.autoGetData.service.IAutoGetErpData;
+import com.huimv.production.autoGetData.utils.HttpClientUtil;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.web.client.RestTemplate;
 
+import java.io.IOException;
 import java.util.*;
 
 /**
@@ -25,6 +30,7 @@ import java.util.*;
  * @Create : 2020-12-25
  **/
 @Service
+@Slf4j
 public class AutoGetErpDataImpl implements IAutoGetErpData {
     // 查询开始日期
 //    @Value("${erp.datasource.startDate}")
@@ -38,13 +44,16 @@ public class AutoGetErpDataImpl implements IAutoGetErpData {
     private String apiPort;
     @Value("${erp.datasource.serviceName}")
     private String serviceName;
-
+    @Autowired
+    private HttpClientUtil httpClientUtil;
     @Autowired
     private RestTemplate template;
     @Autowired
     private IndexParameterRepository parameterRepository;
     @Autowired
     private ProductionGroupRepo productionGroupRepo;
+    @Autowired
+    private com.huimv.production.autoGetData.utils.DateUtil dateUtil;
 
     //PSY
     @Override
@@ -389,6 +398,56 @@ public class AutoGetErpDataImpl implements IAutoGetErpData {
         return list;
     }
 
+    @Override
+    public void getManyFarmProduce() throws IOException {
+        String startDate ;
+        String endDate;
+        DateTime date = DateUtil.date();
+        endDate = (date+"").substring(0,10);
+        startDate =  (DateUtil.beginOfMonth(date)+"").substring(0,10);
+        //
+        String token = getRemoteToken();
+//        JSONObject jsonObject = template.getForObject(apiIp + apiPort + serviceName +"/getManyFarmProduce?startDate="+startDate+"&endDate="+endDate+"&accessToken="+token
+//                ,JSONObject.class );
+//        String data = jsonObject.getString("data");
+//        if (data == null){
+//            return;
+//        }
+        Map<String, String> paramsMap = new HashMap<String, String>();
+        paramsMap.put("startDate", startDate);
+        paramsMap.put("endDate", endDate);
+        paramsMap.put("accessToken", token);
+
+        Map<String, Integer> timeoutMap = new HashMap<String, Integer>();
+        timeoutMap.put("connectTimeout", 120000);
+        timeoutMap.put("requestTimeout", 120000);
+        timeoutMap.put("socketTimeout", 120000);
+        String url = apiIp + apiPort + serviceName +"/getManyFarmProduce";
+        System.out.println("url="+url);
+        System.out.println("paramsMap="+paramsMap.toString());
+        System.out.println("timeoutMap="+timeoutMap.toString());
+        System.out.println("开始取数="+new Date(System.currentTimeMillis()));
+        //
+        JSONObject outJo = httpClientUtil.get(url,paramsMap,timeoutMap);
+        System.out.println("返回结果="+outJo);
+        System.out.println("完成取数="+new Date(System.currentTimeMillis()));
+        if(outJo.getBoolean("status")){
+            JSONObject contentJo = outJo.getJSONObject("content");
+            if(contentJo.getBoolean("success")){
+                JSONArray dataJa = contentJo.getJSONArray("data");
+                // 添加入库
+                for(int a=0;a<dataJa.size();a++){
+                    JSONObject dataJo = dataJa.getJSONObject(a);
+                    System.out.println((a+1)+" "+dataJo);
+                }
+            }else{
+                System.out.println("取数失败");
+            }
+        }else{
+            System.out.println("取数失败");
+        }
+    }
+
 
     private String getToken(){
         JSONObject token = template.getForObject("http://127.0.0.1:9100/token/getToken?userId=20210501&timestamp=45546546454&random=1156&sign=7fa431325504e01e9fa87ed0e274c40c",
@@ -397,7 +456,102 @@ public class AutoGetErpDataImpl implements IAutoGetErpData {
 
     }
 
+    @Override
+    public String getRemoteToken() throws IOException {
+//        JSONObject token = template.getForObject(apiIp + apiPort +"/token/getToken?userId=20210501&timestamp=45546546454&random=1156&sign=7fa431325504e01e9fa87ed0e274c40c",
+//                JSONObject.class);
+        Map<String, String> paramsMap = new HashMap<String, String>();
+        paramsMap.put("userId", "20210501");
+        paramsMap.put("timestamp", "45546546454");
+        paramsMap.put("random", "1156");
+        paramsMap.put("sign", "7fa431325504e01e9fa87ed0e274c40c");
+
+        Map<String, Integer> timeoutMap = new HashMap<String, Integer>();
+        timeoutMap.put("connectTimeout", 5000);
+        timeoutMap.put("requestTimeout", 5000);
+        timeoutMap.put("socketTimeout", 5000);
+        String url = apiIp + apiPort +"/token/getToken";
+        //
+        JSONObject outJo = httpClientUtil.get(url,paramsMap,timeoutMap);
+        if(outJo.getBoolean("status")){
+            return outJo.getJSONObject("content").getString("accessToken");
+        }else{
+            return outJo.getString("content");
+        }
+    }
+
+    @Override
+    public void getManyFarmStock() throws IOException {
+        //
+        String token = getRemoteToken();
+        Map<String, String> paramsMap = new HashMap<String, String>();
+        paramsMap.put("accessToken", token);
+        Map<String, Integer> timeoutMap = new HashMap<String, Integer>();
+        timeoutMap.put("connectTimeout", 120000);
+        timeoutMap.put("requestTimeout", 120000);
+        timeoutMap.put("socketTimeout", 120000);
+        String url = apiIp + apiPort + serviceName +"/getManyFarmStock";
+        log.info("获取多个牧场的存栏="+url);
+        log.info("开始取数="+new Date(System.currentTimeMillis()));
+        //
+        JSONObject outJo = httpClientUtil.get(url,paramsMap,timeoutMap);
+        log.info("返回结果="+outJo);
+        log.info("结束取数="+new Date(System.currentTimeMillis()));
+        if(outJo.getBoolean("status")){
+            JSONObject contentJo = outJo.getJSONObject("content");
+            if(contentJo.getBoolean("success")){
+                JSONArray dataJa = contentJo.getJSONArray("data");
+                // 添加入库
+                for(int a=0;a<dataJa.size();a++){
+                    JSONObject dataJo = dataJa.getJSONObject(a);
+                    System.out.println((a+1)+" "+dataJo);
+                }
+            }else{
+                log.info("取数失败");
+            }
+        }else{
+            log.info("取数失败");
+        }
+    }
 
+    @Override
+    public void getCostWithManyFarm() throws IOException {
+        //
+        String token = getRemoteToken();
+        Map<String, String> paramsMap = new HashMap<String, String>();
+        paramsMap.put("accessToken", token);
+        paramsMap.put("year", dateUtil.getThisYear());
+        paramsMap.put("month", dateUtil.getThisMonth());
+        Map<String, Integer> timeoutMap = new HashMap<String, Integer>();
+        timeoutMap.put("connectTimeout", 120000);
+        timeoutMap.put("requestTimeout", 120000);
+        timeoutMap.put("socketTimeout", 120000);
+        String url = apiIp + apiPort + serviceName +"/getCostWithManyFarm";
+        log.info("获取多个牧场的成本="+url);
+        log.info("开始取数="+new Date(System.currentTimeMillis()));
+        //
+        JSONObject outJo = httpClientUtil.get(url,paramsMap,timeoutMap);
+        log.info("返回结果="+outJo);
+        log.info("结束取数="+new Date(System.currentTimeMillis()));
+        if(outJo.getBoolean("status")){
+            JSONObject contentJo = outJo.getJSONObject("content");
+            if(contentJo.getBoolean("success")){
+                JSONArray dataJa = contentJo.getJSONArray("data");
+                if(dataJa.size()==0){
+                    log.info("未取到数据 。");
+                }
+                // 添加入库
+                for(int a=0;a<dataJa.size();a++){
+                    JSONObject dataJo = dataJa.getJSONObject(a);
+                    System.out.println((a+1)+" "+dataJo);
+                }
+            }else{
+                System.out.println("取数失败");
+            }
+        }else{
+            System.out.println("取数失败");
+        }
+    }
 
    /* public static void main(String[] args) {
         RestTemplate restTemplate = new RestTemplate();

+ 34 - 0
huimv-hy-production/huimv.hy.autoGetData/src/main/java/com/huimv/production/autoGetData/utils/DateUtil.java

@@ -0,0 +1,34 @@
+package com.huimv.production.autoGetData.utils;
+
+import org.springframework.stereotype.Component;
+
+import java.util.Calendar;
+
+/**
+ * @Project : huimv.shiwan
+ * @Package : com.huimv.biosafety.uface.controller
+ * @Description : TODO
+ * @Version : 1.0
+ * @Author : ZhuoNing
+ * @Create : 2020-12-25
+ **/
+@Component
+public class DateUtil {
+
+    public String getThisYear(){
+        Calendar cal = Calendar.getInstance();
+        int year = cal.get(Calendar.YEAR);
+        return String.valueOf(year);
+    }
+
+    public String getThisMonth(){
+        Calendar cal = Calendar.getInstance();
+        int month = cal.get(Calendar.MONTH) + 1;
+        if(String.valueOf(month).length()==1)
+        {
+            return "0"+String.valueOf(month);
+        }else{
+            return String.valueOf(month);
+        }
+    }
+}

+ 240 - 0
huimv-hy-production/huimv.hy.autoGetData/src/main/java/com/huimv/production/autoGetData/utils/HttpClientUtil.java

@@ -0,0 +1,240 @@
+package com.huimv.production.autoGetData.utils;
+
+import com.alibaba.fastjson.JSONObject;
+import org.apache.http.*;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.config.RequestConfig;
+import org.apache.http.client.entity.UrlEncodedFormEntity;
+import org.apache.http.client.methods.*;
+import org.apache.http.conn.routing.HttpRoute;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.impl.client.HttpClientBuilder;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
+import org.apache.http.message.BasicNameValuePair;
+import org.apache.http.util.EntityUtils;
+import org.springframework.stereotype.Component;
+
+import java.io.IOException;
+import java.util.*;
+
+/**
+ * @Project : huimv.shiwan
+ * @Package : com.huimv.biosafety.uface.controller
+ * @Description : TODO
+ * @Version : 1.0
+ * @Author : ZhuoNing
+ * @Create : 2020-12-25
+ **/
+@Component
+public class HttpClientUtil {
+    String httpIp = "http://121.40.221.149:9100";
+
+    public static void main(String[] args) throws Exception {
+        //
+        HttpClientUtil client = new HttpClientUtil();
+//        client.testGetRequest1();
+        client.testGetRequest2();
+    }
+
+    private void testGetRequest1() throws IOException {
+        Map<String, Integer> timeoutMap = new HashMap<String, Integer>();
+        timeoutMap.put("connectTimeout", 5000);
+        timeoutMap.put("requestTimeout", 5000);
+        timeoutMap.put("socketTimeout", 5000);
+        String url = httpIp + "/token/getToken?userId=20210501&timestamp=45546546454&random=1156&sign=7fa431325504e01e9fa87ed0e274c40c";
+        // test error
+        url = httpIp + "/token/getToken?userId=20210501&timestamp=45546546454&random=1156&sign=7fa431325504e01e9fa87ed0e274c40c&userId=20210501&timestamp=45546546454&random=1156&sign=7fa431325504e01e9fa87ed0e274c40c";
+        CloseableHttpClient httpClient = getHttpClientConnection();
+        CloseableHttpResponse response = httpClient.execute(getHttpRequest(url, timeoutMap));
+        // 打印响应状态
+        System.out.println("响应状态1 =" + response.getStatusLine());
+        try {
+            if (response.getStatusLine().getStatusCode() == 200) {
+                // 获取响应实体
+                HttpEntity entity = response.getEntity();
+                // 打印响应内容
+                String text = EntityUtils.toString(entity, "utf-8");
+                System.out.println("响应内容=" + text);
+
+                JSONObject resultJo = JSONObject.parseObject(text);
+                System.out.println("accessToken="+resultJo.getString("accessToken"));
+            } else {
+                System.out.println("请求失败");
+            }
+        } finally {
+            response.close();
+            httpClient.close();
+        }
+    }
+
+    private void testGetRequest2() throws IOException {
+        Map<String, String> paramsMap = new HashMap<String, String>();
+        paramsMap.put("userId", "20210501");
+        paramsMap.put("timestamp", "45546546454");
+        paramsMap.put("random", "1156");
+        paramsMap.put("sign", "7fa431325504e01e9fa87ed0e274c40c");
+
+        Map<String, Integer> timeoutMap = new HashMap<String, Integer>();
+        timeoutMap.put("connectTimeout", 5000);
+        timeoutMap.put("requestTimeout", 5000);
+        timeoutMap.put("socketTimeout", 5000);
+
+        String url = httpIp + "/token/getToken";
+        //        get(url, paramsMap, timeoutMap);
+        //
+        JSONObject resultJo = get(url,paramsMap,timeoutMap);
+        System.out.println("status="+resultJo.getBoolean("status"));
+        System.out.println("content="+resultJo.getJSONObject("content"));
+    }
+
+    /**
+     * @Method      : get
+     * @Description : 
+     * @Params      : [url, paramsMap, timeoutMap]
+     * @Return      : com.alibaba.fastjson.JSONObject
+     * 
+     * @Author      : ZhuoNing
+     * @Date        : 2021/11/18       
+     * @Time        : 17:39
+     */
+    public JSONObject get(String url, Map<String, String> paramsMap, Map<String, Integer> timeoutMap) throws IOException {
+        if(timeoutMap == null){
+            timeoutMap.put("connectTimeout", 5000);
+            timeoutMap.put("requestTimeout", 5000);
+            timeoutMap.put("socketTimeout", 5000);
+        }
+        //
+        CloseableHttpClient httpClient = getHttpClientConnection();
+        //
+        CloseableHttpResponse response = httpClient.execute(getHttpRequest(url, paramsMap, timeoutMap));
+        try {
+            // 打印响应状态
+            if (response.getStatusLine().getStatusCode() == 200) {
+                // 获取响应实体
+                HttpEntity entity = response.getEntity();
+                // 打印响应内容
+                String text = EntityUtils.toString(entity, "utf-8");
+                JSONObject resultJo = new JSONObject();
+                resultJo.put("status",true);
+                resultJo.put("content",text);
+                return resultJo;
+            } else {
+                JSONObject resultJo = new JSONObject();
+                resultJo.put("status",false);
+                resultJo.put("content","请求失败");
+                return resultJo;
+            }
+        } finally {
+            response.close();
+            httpClient.close();
+        }
+
+    }
+
+    private CloseableHttpClient getHttpClientConnection() {
+        CloseableHttpClient httpclient = HttpClients.createDefault();
+//        CloseableHttpClient httpClient = HttpClientBuilder.create().build();
+        return httpclient;
+    }
+
+    private HttpUriRequest getHttpRequest(String url, Map<String, String> map, Map<String, Integer> timeoutMap) {
+        int connectTimeout = timeoutMap.get("connectTimeout");
+        int requestTimeout = timeoutMap.get("requestTimeout");
+        int socketTimeout = timeoutMap.get("socketTimeout");
+
+        List<NameValuePair> params = new ArrayList<NameValuePair>();
+        Set<Map.Entry<String, String>> entrySet = map.entrySet();
+        for (Map.Entry<String, String> e : entrySet) {
+            String name = e.getKey();
+            String value = e.getValue();
+            NameValuePair pair = new BasicNameValuePair(name, value);
+            params.add(pair);
+        }
+        RequestConfig requestConfig = RequestConfig.custom()
+                .setConnectTimeout(connectTimeout).setConnectionRequestTimeout(requestTimeout)
+                .setSocketTimeout(socketTimeout).build();
+        HttpUriRequest httpGet = RequestBuilder.get().setUri(url)
+                .addParameters(params.toArray(new BasicNameValuePair[params.size()]))
+                .setConfig(requestConfig).build();
+        return httpGet;
+    }
+
+    private HttpGet getHttpRequest(String url, Map<String, Integer> timeoutMap) {
+        int connectTimeout = timeoutMap.get("connectTimeout");
+        int requestTimeout = timeoutMap.get("requestTimeout");
+        int socketTimeout = timeoutMap.get("socketTimeout");
+
+        HttpGet httpGet = new HttpGet(url);
+        //设置超时时间
+        RequestConfig requestConfig = RequestConfig.custom()
+                .setConnectTimeout(connectTimeout).setConnectionRequestTimeout(requestTimeout)
+                .setSocketTimeout(socketTimeout).build();
+        httpGet.setConfig(requestConfig);
+        return httpGet;
+    }
+
+    //test
+    public void get() {
+//        CloseableHttpClient httpclient = HttpClients.createDefault();
+//        try {
+//            // 创建httpget.
+//            HttpGet httpget = new HttpGet(httpIp + "/token/getToken?userId=20210501&timestamp=45546546454&random=1156&sign=7fa431325504e01e9fa87ed0e274c40c");
+//            System.out.println("executing request " + httpget.getURI());
+//            // 执行get请求.
+//            CloseableHttpResponse response = httpclient.execute(httpget);
+//            try {
+//                // 获取响应实体
+//                HttpEntity entity = response.getEntity();
+//                System.out.println("--------------------------------------");
+//                // 打印响应状态
+//                System.out.println(response.getStatusLine());
+//                if (entity != null) {
+//                    // 打印响应内容长度
+//                    System.out.println("Response content length: " + entity.getContentLength());
+//                    // 打印响应内容
+//                    System.out.println("Response content: " + EntityUtils.toString(entity));
+//                }
+//                System.out.println("------------------------------------");
+//            } finally {
+//                response.close();
+//            }
+//        } catch (ClientProtocolException e) {
+//            e.printStackTrace();
+//        } catch (ParseException e) {
+//            e.printStackTrace();
+//        } catch (IOException e) {
+//            e.printStackTrace();
+//        } finally {
+//            // 关闭连接,释放资源
+//            try {
+//                httpclient.close();
+//            } catch (IOException e) {
+//                e.printStackTrace();
+//            }
+//        }
+    }
+
+
+    private void getRequest() throws IOException {
+//        //1.打开浏览器
+//        CloseableHttpClient httpClient = HttpClients.createDefault();
+//        //2.声明get请求
+//        HttpGet httpGet = new HttpGet(httpIp + "/token/getToken?userId=20210501&timestamp=45546546454&random=1156&sign=7fa431325504e01e9fa87ed0e274c40c");
+//        //3.发送请求
+//        CloseableHttpResponse response = httpClient.execute(httpGet);
+//        System.out.println("StatusCode=" + response.getStatusLine().getStatusCode());
+//        //4.判断状态码
+//        if (response.getStatusLine().getStatusCode() == 200) {
+//            HttpEntity entity = response.getEntity();
+//            //使用工具类EntityUtils,从响应中取出实体表示的内容并转换成字符串
+//            String string = EntityUtils.toString(entity, "utf-8");
+//            System.out.println(string);
+//        }
+//        //5.关闭资源
+//        response.close();
+//        httpClient.close();
+    }
+}

+ 2 - 1
huimv-hy-production/huimv.hy.autoGetData/src/main/resources/application.properties

@@ -2,7 +2,8 @@ spring.profiles.active=dev
 
 erp.datasource.startDate=2020.1.1
 erp.datasource.endDate=2021.12.31
-erp.datasource.apiIp=http://127.0.0.1
+#erp.datasource.apiIp=http://127.0.0.1
+erp.datasource.apiIp=http://121.40.221.149
 erp.datasource.apiPort=:9100
 erp.datasource.serviceName=/erpData
 #erp.datasource.filterFarm=º£ÑÎ

+ 40 - 0
huimv-hy-production/huimv.hy.autoGetData/src/test/java/com/huimv/production/autoGetData/utils/DateTest.java

@@ -0,0 +1,40 @@
+package com.huimv.production.autoGetData.utils;
+
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+
+import java.util.Calendar;
+
+/**
+ * @Project : huimv.shiwan
+ * @Package : com.huimv.biosafety.uface.controller
+ * @Description : TODO
+ * @Version : 1.0
+ * @Author : ZhuoNing
+ * @Create : 2020-12-25
+ **/
+@SpringBootTest
+public class DateTest {
+
+    @Test
+    public void testDate(){
+        Calendar cal = Calendar.getInstance();
+        int month = cal.get(Calendar.MONTH) + 1;
+        int year = cal.get(Calendar.YEAR);
+
+
+        System.out.println("当期时间: " + cal.getTime());
+        System.out.println("月份: " + month);
+        System.out.println("年份: " + year);
+    }
+
+    @Autowired
+    private DateUtil dateUtil;
+    @Test
+    public void testDate2(){
+        System.out.println("year="+dateUtil.getThisYear());;
+        System.out.println("month="+dateUtil.getThisMonth());;
+    }
+
+}