|
@@ -3,17 +3,22 @@ package com.huimv.production.autoGetData.service.impl;
|
|
import cn.hutool.core.date.DateTime;
|
|
import cn.hutool.core.date.DateTime;
|
|
import cn.hutool.core.date.DateUtil;
|
|
import cn.hutool.core.date.DateUtil;
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
+//import com.huimv.common.date.DateUtil;
|
|
import com.huimv.production.autoGetData.entity.IndexParameter;
|
|
import com.huimv.production.autoGetData.entity.IndexParameter;
|
|
import com.huimv.production.autoGetData.entity.ProductionGroup;
|
|
import com.huimv.production.autoGetData.entity.ProductionGroup;
|
|
import com.huimv.production.autoGetData.repo.IndexParameterRepository;
|
|
import com.huimv.production.autoGetData.repo.IndexParameterRepository;
|
|
import com.huimv.production.autoGetData.repo.ProductionGroupRepo;
|
|
import com.huimv.production.autoGetData.repo.ProductionGroupRepo;
|
|
import com.huimv.production.autoGetData.service.IAutoGetErpData;
|
|
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.Autowired;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.web.client.RestTemplate;
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
|
|
+import java.io.IOException;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -25,6 +30,7 @@ import java.util.*;
|
|
* @Create : 2020-12-25
|
|
* @Create : 2020-12-25
|
|
**/
|
|
**/
|
|
@Service
|
|
@Service
|
|
|
|
+@Slf4j
|
|
public class AutoGetErpDataImpl implements IAutoGetErpData {
|
|
public class AutoGetErpDataImpl implements IAutoGetErpData {
|
|
// 查询开始日期
|
|
// 查询开始日期
|
|
// @Value("${erp.datasource.startDate}")
|
|
// @Value("${erp.datasource.startDate}")
|
|
@@ -38,13 +44,16 @@ public class AutoGetErpDataImpl implements IAutoGetErpData {
|
|
private String apiPort;
|
|
private String apiPort;
|
|
@Value("${erp.datasource.serviceName}")
|
|
@Value("${erp.datasource.serviceName}")
|
|
private String serviceName;
|
|
private String serviceName;
|
|
-
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private HttpClientUtil httpClientUtil;
|
|
@Autowired
|
|
@Autowired
|
|
private RestTemplate template;
|
|
private RestTemplate template;
|
|
@Autowired
|
|
@Autowired
|
|
private IndexParameterRepository parameterRepository;
|
|
private IndexParameterRepository parameterRepository;
|
|
@Autowired
|
|
@Autowired
|
|
private ProductionGroupRepo productionGroupRepo;
|
|
private ProductionGroupRepo productionGroupRepo;
|
|
|
|
+ @Autowired
|
|
|
|
+ private com.huimv.production.autoGetData.utils.DateUtil dateUtil;
|
|
|
|
|
|
//PSY
|
|
//PSY
|
|
@Override
|
|
@Override
|
|
@@ -389,6 +398,56 @@ public class AutoGetErpDataImpl implements IAutoGetErpData {
|
|
return list;
|
|
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(){
|
|
private String getToken(){
|
|
JSONObject token = template.getForObject("http://127.0.0.1:9100/token/getToken?userId=20210501×tamp=45546546454&random=1156&sign=7fa431325504e01e9fa87ed0e274c40c",
|
|
JSONObject token = template.getForObject("http://127.0.0.1:9100/token/getToken?userId=20210501×tamp=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×tamp=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) {
|
|
/* public static void main(String[] args) {
|
|
RestTemplate restTemplate = new RestTemplate();
|
|
RestTemplate restTemplate = new RestTemplate();
|