Explorar el Código

增加多牧场配种分娩率取数和数据入库。

zhuoning hace 3 años
padre
commit
f86ebe8a64

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

@@ -48,4 +48,6 @@ public interface IAutoGetErpData {
 
     //获取多牧场PSY
     void getManyFarmPsy() throws IOException;
+
+    void getManyFarmParturitionRate() throws IOException;
 }

+ 84 - 2
huimv-hy-production/huimv.hy.autoGetData/src/main/java/com/huimv/production/autoGetData/service/impl/AutoGetErpDataImpl.java

@@ -1447,7 +1447,6 @@ public class AutoGetErpDataImpl implements IAutoGetErpData {
                             psyJo.put("year",year);
                             psyJo.put("farm_id",farmNameEntity.getFarmId());
                             psyJo.put("farm_name",farmNameEntity.getFarmName());
-                            //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
                         }
                     }
                 }
@@ -1475,10 +1474,93 @@ public class AutoGetErpDataImpl implements IAutoGetErpData {
                 addEntity1.setYear(Integer.parseInt(year));
                 produceRepo.saveAndFlush(addEntity1);
             }
+        }
+    }
+
+    @Override
+    public void getManyFarmParturitionRate() 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 newJa = new JSONArray();
+        for(ProdFarmNameEntity farmNameEntity:farmNameEntityList){
+            if(null != farmNameEntity.getErpFarmId()){
+                //
+                Map<String, String> paramsMap = new HashMap<String, String>();
+                paramsMap.put("accessToken", token);
+                paramsMap.put("farmName", farmNameEntity.getErpFarmName());
+                paramsMap.put("startDate", dateUtil.getStartDateInThisMonth());
+                paramsMap.put("endDate", dateUtil.getEndDateInThisMonth());
 
+                String url = apiIp + apiPort + serviceName + "/getParturitionRate";
+                log.info("销售数据接口访问地址=" + url);
+                log.info("业务请求参数=" + paramsMap.toString());
+                log.info("开始取数=" + new Date(System.currentTimeMillis()));
+                //
+                JSONObject outJo = httpClientUtil.doGetBatch(url, paramsMap);
+//                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");
+                        System.out.println(""+dataJa);
+                        if (null == dataJa || dataJa.size()==0) {
+                            log.info("未取到数据 。");
+                        } else {
+                            JSONObject dataJo = dataJa.getJSONObject(0);
+                            JSONObject newJo = new JSONObject();
+                            newJa.add(newJo);
+                            newJo.put("stock_type","breed_rate");
+                            newJo.put("stock_name","配种分娩率");
+                            newJo.put("stock_quantity",dataJo.getString("parturition_rate"));
+                            newJo.put("month",month);
+                            newJo.put("year",year);
+                            newJo.put("farm_id",farmNameEntity.getFarmId());
+                            newJo.put("farm_name",farmNameEntity.getFarmName());
+                        }
+                    }
+                }
+            }
         }
+        //关闭http连接资源
+        httpClientUtil.closeHttpConn();
+
+//        for(int a=0;a<newJa.size();a++){
+//            JSONObject newJo = newJa.getJSONObject(a);
+//            System.out.println(""+newJo+" __ "+mathUtil.countRate(Float.parseFloat(newJo.getString("stock_quantity")),1));
+//        }
+        System.out.println("newJa.size="+newJa.size());
+
+        if(newJa.size()>0){
+            //
+            ProdProduceEntity delEntity = new ProdProduceEntity();
+            delEntity.setYear(Integer.parseInt(year));
+            delEntity.setMonth(Integer.parseInt(month));
+            delEntity.setStockType("breed_rate");
+            Example<ProdProduceEntity> delExample = Example.of(delEntity);
+            produceRepo.deleteAll(produceRepo.findAll(delExample));
+            //
+            for(int a=0;a<newJa.size();a++){
+                JSONObject newJo = newJa.getJSONObject(a);
+                ProdProduceEntity addEntity1 = new ProdProduceEntity();
+                addEntity1.setFarmId(newJo.getInteger("farm_id"));
+                addEntity1.setStockType("breed_rate");
+                addEntity1.setStockName("配种分娩率");
+                addEntity1.setStockQuantity(mathUtil.countRate(Float.parseFloat(newJo.getString("stock_quantity")),1));
+                addEntity1.setMonth(Integer.valueOf(month));
+                addEntity1.setYear(Integer.parseInt(year));
+                produceRepo.saveAndFlush(addEntity1);
+            }
+        }
+        //++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
 
-        //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     }
 
 

+ 9 - 0
huimv-hy-production/huimv.hy.autoGetData/src/test/java/com/huimv/production/autoGetData/utils/AutoGetDataTEst.java

@@ -91,4 +91,13 @@ public class AutoGetDataTEst {
         autoGetErpData.getManyFarmPsy();
     }
 
+    //多牧场分娩率
+    @Test
+    public void testManyFarmGetParturitionRate() throws IOException {
+        //
+        autoGetErpData.getManyFarmParturitionRate();
+    }
+
+
+
 }