|
@@ -1,5 +1,6 @@
|
|
|
package com.huimv.production.autoGetData.service.impl;
|
|
|
|
|
|
+import antlr.StringUtils;
|
|
|
import cn.hutool.core.date.DateTime;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
@@ -447,9 +448,9 @@ public class AutoGetErpDataImpl implements IAutoGetErpData {
|
|
|
paramsMap.put("accessToken", token);
|
|
|
|
|
|
Map<String, Integer> timeoutMap = new HashMap<String, Integer>();
|
|
|
- timeoutMap.put("connectTimeout", 120000);
|
|
|
- timeoutMap.put("requestTimeout", 120000);
|
|
|
- timeoutMap.put("socketTimeout", 120000);
|
|
|
+ timeoutMap.put("connectTimeout", Integer.parseInt(connectTimeout));
|
|
|
+ timeoutMap.put("requestTimeout", Integer.parseInt(requestTimeout));
|
|
|
+ timeoutMap.put("socketTimeout", Integer.parseInt(socketTimeout));
|
|
|
String url = apiIp + apiPort + serviceName + "/getManyFarmProduce";
|
|
|
log.info("多个牧场生产数据访问地址=" + url);
|
|
|
log.info("业务请求参数=" + paramsMap.toString());
|
|
@@ -466,8 +467,7 @@ public class AutoGetErpDataImpl implements IAutoGetErpData {
|
|
|
if (dataJa.size() > 0) {
|
|
|
//获取牧场所有名称数据
|
|
|
List<ProdFarmNameEntity> farmNameEntityList = prodFarmNameRepo.findAll();
|
|
|
-
|
|
|
- //删除旧数据
|
|
|
+ //-- 删除旧数据 --//
|
|
|
//删除产房成活率
|
|
|
ProdProduceEntity delEntity1 = new ProdProduceEntity();
|
|
|
delEntity1.setYear(Integer.parseInt(year));
|
|
@@ -753,9 +753,9 @@ public class AutoGetErpDataImpl implements IAutoGetErpData {
|
|
|
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);
|
|
|
+ timeoutMap.put("connectTimeout", Integer.parseInt(connectTimeout));
|
|
|
+ timeoutMap.put("requestTimeout", Integer.parseInt(connectTimeout));
|
|
|
+ timeoutMap.put("socketTimeout", Integer.parseInt(connectTimeout));
|
|
|
String url = apiIp + apiPort + serviceName + "/getManyFarmStock";
|
|
|
log.info("获取多个牧场的存栏数据请求地址=" + url);
|
|
|
log.info("业务请求参数=" + paramsMap.toString());
|
|
@@ -855,6 +855,13 @@ public class AutoGetErpDataImpl implements IAutoGetErpData {
|
|
|
// prodStockRepo.delete(prodStockRepo.findOne(example10).get());
|
|
|
prodStockRepo.deleteAll(prodStockRepo.findAll(example10));
|
|
|
// prodStockRepo.deleteByYearAndMonth(Integer.parseInt(year),Integer.parseInt(month));
|
|
|
+ //商品猪
|
|
|
+ ProdStockEntity delStockEntity11 = new ProdStockEntity();
|
|
|
+ delStockEntity11.setYear(Integer.parseInt(year));
|
|
|
+ delStockEntity11.setMonth(Integer.parseInt(month));
|
|
|
+ delStockEntity11.setStockType("business_stock");
|
|
|
+ Example<ProdStockEntity> example11 = Example.of(delStockEntity11);
|
|
|
+ prodStockRepo.deleteAll(prodStockRepo.findAll(example11));
|
|
|
|
|
|
// 添加入库
|
|
|
for (int a = 0; a < dataJa.size(); a++) {
|
|
@@ -963,6 +970,15 @@ public class AutoGetErpDataImpl implements IAutoGetErpData {
|
|
|
stockEntity10.setMonth(Integer.valueOf(month));
|
|
|
stockEntity10.setYear(Integer.parseInt(year));
|
|
|
prodStockRepo.saveAndFlush(stockEntity10);
|
|
|
+ //商品猪=仔猪+保育+育肥+后备
|
|
|
+ ProdStockEntity stockEntity11 = new ProdStockEntity();
|
|
|
+ stockEntity11.setFarmId(farmId);
|
|
|
+ stockEntity11.setStockType("business_stock");
|
|
|
+ stockEntity11.setStockName("商品猪");
|
|
|
+ stockEntity11.setStockQuantity(String.valueOf(dataJo.getInteger("zz")+dataJo.getInteger("by")+dataJo.getInteger("yf")+dataJo.getInteger("hb")));
|
|
|
+ stockEntity11.setMonth(Integer.valueOf(month));
|
|
|
+ stockEntity11.setYear(Integer.parseInt(year));
|
|
|
+ prodStockRepo.saveAndFlush(stockEntity11);
|
|
|
}
|
|
|
|
|
|
}
|
|
@@ -1004,6 +1020,7 @@ public class AutoGetErpDataImpl implements IAutoGetErpData {
|
|
|
paramsMap.put("accessToken", token);
|
|
|
// paramsMap.put("year", dateUtil.getThisYear());
|
|
|
// paramsMap.put("month", dateUtil.getThisMonth());
|
|
|
+ // test data
|
|
|
paramsMap.put("year", "2021");
|
|
|
paramsMap.put("month", "8");
|
|
|
//
|
|
@@ -1160,7 +1177,6 @@ public class AutoGetErpDataImpl implements IAutoGetErpData {
|
|
|
return farmId;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
@Override
|
|
|
public void getWorkPlan() throws IOException, ParseException {
|
|
|
//
|
|
@@ -1385,6 +1401,87 @@ public class AutoGetErpDataImpl implements IAutoGetErpData {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void getManyFarmPsy() throws IOException {
|
|
|
+ //
|
|
|
+ Map timeoutMap = httpClientUtil.setTimeout(connectTimeout, requestTimeout, socketTimeout);
|
|
|
+ //
|
|
|
+ String token = getRemoteToken();
|
|
|
+ String year = dateUtil.getThisYear();
|
|
|
+ String month = dateUtil.getThisMonth();
|
|
|
+
|
|
|
+ //查询所有记录
|
|
|
+ List<ProdFarmNameEntity> farmNameEntityList = prodFarmNameRepo.findAll();
|
|
|
+ JSONArray psyJa = new JSONArray();
|
|
|
+ for(ProdFarmNameEntity farmNameEntity:farmNameEntityList){
|
|
|
+ if(null != farmNameEntity.getErpFarmId()){
|
|
|
+ //
|
|
|
+ Map<String, String> paramsMap = new HashMap<String, String>();
|
|
|
+ paramsMap.put("accessToken", token);
|
|
|
+ paramsMap.put("farmID", farmNameEntity.getErpFarmId());
|
|
|
+ paramsMap.put("startDate", dateUtil.getStartDateInThisMonth());
|
|
|
+ paramsMap.put("endDate", dateUtil.getEndDateInThisMonth());
|
|
|
+
|
|
|
+ String url = apiIp + apiPort + serviceName + "/getPsy";
|
|
|
+ log.info("销售数据接口访问地址=" + url);
|
|
|
+ log.info("业务请求参数=" + paramsMap.toString());
|
|
|
+ log.info("开始取数=" + new Date(System.currentTimeMillis()));
|
|
|
+ //
|
|
|
+ JSONObject outJo = httpClientUtil.doGet(url, paramsMap);
|
|
|
+ log.info("返回结果>>" + outJo);
|
|
|
+ log.info("结束取数=" + new Date(System.currentTimeMillis()));
|
|
|
+ if (outJo.getBoolean("status")) {
|
|
|
+ JSONObject contentJo = outJo.getJSONObject("content");
|
|
|
+ if (contentJo.getBoolean("success")) {
|
|
|
+ String psyData = contentJo.getString("data");
|
|
|
+ if (null == psyData || psyData.trim().length()==0) {
|
|
|
+ log.info("未取到数据 。");
|
|
|
+ } else {
|
|
|
+ System.out.println("data="+psyData);
|
|
|
+ JSONObject psyJo = new JSONObject();
|
|
|
+ psyJa.add(psyJo);
|
|
|
+ psyJo.put("stock_type","psy");
|
|
|
+ psyJo.put("stock_name","PSY");
|
|
|
+ psyJo.put("stock_quantity",psyData);
|
|
|
+ psyJo.put("month",month);
|
|
|
+ psyJo.put("year",year);
|
|
|
+ psyJo.put("farm_id",farmNameEntity.getFarmId());
|
|
|
+ psyJo.put("farm_name",farmNameEntity.getFarmName());
|
|
|
+ //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //关闭http连接资源
|
|
|
+// httpClientUtil.closeHttpConn();
|
|
|
+ if(psyJa.size()>0){
|
|
|
+ //
|
|
|
+ ProdProduceEntity delEntity = new ProdProduceEntity();
|
|
|
+ delEntity.setYear(Integer.parseInt(year));
|
|
|
+ delEntity.setMonth(Integer.parseInt(month));
|
|
|
+ delEntity.setStockType("psy");
|
|
|
+ Example<ProdProduceEntity> delExample = Example.of(delEntity);
|
|
|
+ produceRepo.deleteAll(produceRepo.findAll(delExample));
|
|
|
+ //
|
|
|
+ for(int a=0;a<psyJa.size();a++){
|
|
|
+ JSONObject psyJo = psyJa.getJSONObject(a);
|
|
|
+ ProdProduceEntity addEntity1 = new ProdProduceEntity();
|
|
|
+ addEntity1.setFarmId(psyJo.getInteger("farm_id"));
|
|
|
+ addEntity1.setStockType("psy");
|
|
|
+ addEntity1.setStockName("PSY");
|
|
|
+ addEntity1.setStockQuantity(psyJo.getString("stock_quantity"));
|
|
|
+ addEntity1.setMonth(Integer.valueOf(month));
|
|
|
+ addEntity1.setYear(Integer.parseInt(year));
|
|
|
+ produceRepo.saveAndFlush(addEntity1);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/* public static void main(String[] args) {
|
|
|
RestTemplate restTemplate = new RestTemplate();
|
|
|
|