Explorar el Código

修改查询每月数据接口

523096025 hace 2 años
padre
commit
dd75af73e5

+ 16 - 3
huimv-hy-production/huimv.hy.autoGetData/src/main/java/com/huimv/production/autoGetData/config/SaticScheduleTask.java

@@ -1,3 +1,4 @@
+/*
 package com.huimv.production.autoGetData.config;
 
 import com.huimv.production.autoGetData.service.IAutoGetErpData;
@@ -7,6 +8,7 @@ import org.springframework.context.annotation.Configuration;
 import org.springframework.scheduling.annotation.EnableScheduling;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.scheduling.annotation.SchedulingConfigurer;
+import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RestController;
@@ -16,6 +18,7 @@ import java.text.ParseException;
 import java.time.LocalDateTime;
 import java.util.List;
 
+*/
 /**
  * @Project : huimv.shiwan
  * @Package : com.huimv.biosafety.uface.controller
@@ -23,7 +26,8 @@ import java.util.List;
  * @Version : 1.0
  * @Author : ZhuoNing
  * @Create : 2020-12-25
- **/
+ **//*
+
 @Configuration      //1.主要用于标记配置类,兼备Component的效果。
 @EnableScheduling   // 2.开启定时任务
 @RestController
@@ -42,7 +46,8 @@ public class SaticScheduleTask  {
 
 //    @Scheduled(cron = "0/5 * * * * ?")
 //    @Scheduled(cron = "0 * * * * ? ")
-  /*  private void getPsyTask(){
+  */
+/*  private void getPsyTask(){
         System.err.println("执行 getPsyTask 执行静态定时任务时间: " + LocalDateTime.now());
         iAutoGetErpData.getPsy();
     }
@@ -101,7 +106,8 @@ public class SaticScheduleTask  {
     private List findAll(){
 
         return iAutoGetErpData.findAll();
-    }*/
+    }*//*
+
 
     //ok
     //
@@ -179,4 +185,11 @@ public class SaticScheduleTask  {
         //读取多个牧场的配种分娩率
         iAutoGetErpData.getManyFarmParturitionRate();
     }
+
+    @Scheduled(cron = "12 12 6,12,18 * * ? ")
+    public void getManyFarmStock2() throws IOException, ParseException {
+        //
+        iAutoGetErpData.getManyFarmStock2();
+    }
 }
+*/

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

@@ -54,4 +54,11 @@ public class DataControll {
         autoGetErpData.getPlay();
     }
 
+    @GetMapping(value = "/getManyFarmStock2")
+    public void getManyFarmStock2() throws IOException, ParseException {
+        //
+        autoGetErpData.getManyFarmStock2();
+    }
+
+
 }

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

@@ -56,4 +56,6 @@ public interface IAutoGetErpData {
     void getSalesMoney() throws ParseException, IOException;
 
     void getPlay() throws ParseException, IOException;
+
+    void getManyFarmStock2() throws IOException;
 }

+ 326 - 70
huimv-hy-production/huimv.hy.autoGetData/src/main/java/com/huimv/production/autoGetData/service/impl/AutoGetErpDataImpl.java

@@ -3,6 +3,8 @@ package com.huimv.production.autoGetData.service.impl;
 import antlr.StringUtils;
 import cn.hutool.core.date.DateTime;
 import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.io.unit.DataUnit;
+import cn.hutool.core.util.ObjectUtil;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
@@ -969,6 +971,276 @@ public class AutoGetErpDataImpl implements IAutoGetErpData {
     }
 
     @Override
+    public void getManyFarmStock2() throws IOException {
+
+        for (int i = 9; i>=0 ;i--) {
+            String format = DateUtil.format( DateUtil.endOfMonth(DateUtil.offsetMonth(new Date(),-i)), "yyyy-MM-dd");
+            //
+            Map<String, String> paramsMap = new HashMap<String, String>();
+            paramsMap.put("endTime", format);
+            Map<String, Integer> timeoutMap = new HashMap<String, Integer>();
+            timeoutMap.put("connectTimeout", Integer.parseInt(connectTimeout));
+            timeoutMap.put("requestTimeout", Integer.parseInt(connectTimeout));
+            timeoutMap.put("socketTimeout", Integer.parseInt(connectTimeout));
+            String url = apiIp + apiPort + serviceName + "/getManyFarmStock2";
+            //
+            JSONObject outJo = httpClientUtil.doGet(url, paramsMap, timeoutMap);
+            System.out.println(outJo);
+            log.info("返回结果=" + outJo);
+            log.info("结束取数=" + new Date(System.currentTimeMillis()));
+            if (outJo.getBoolean("status")) {
+                JSONObject contentJo = outJo.getJSONObject("content");
+                if (contentJo.getBoolean("success")) {
+                    JSONArray dataJa =(JSONArray) contentJo.get("data");
+                    for(int a=0;a<dataJa.size();a++) {
+                        List<Object> dataList = (List<Object>)dataJa.get(a);
+
+                        //牧场id
+                        ProdFarmNameEntity farmNameEntity = new ProdFarmNameEntity();
+                        farmNameEntity.setErpFarmId( (String) dataList.get(0));
+                        Example<ProdFarmNameEntity> example = Example.of(farmNameEntity);
+
+                        Optional<ProdFarmNameEntity> one = prodFarmNameRepo.findOne(example);
+                       if (one.isPresent()){
+                           ProdFarmNameEntity  prodFarmNameEntity=one.get();
+                           //拿到当月数据
+                           ProdStockEntity prodStockEntity = new ProdStockEntity();
+                           prodStockEntity.setMonth(Integer.parseInt(format.substring(5,7)));
+                           prodStockEntity.setYear(Integer.parseInt(format.substring(0,4)));
+                           prodStockEntity.setFarmId(prodFarmNameEntity.getFarmId());
+                           Example<ProdStockEntity> exampleStock = Example.of(prodStockEntity);
+                           List<ProdStockEntity> all = prodStockRepo.findAll(exampleStock);
+                           if (ObjectUtil.isEmpty(all)|| all.size() == 0){
+                               ProdStockEntity prodStockEntity1 = new ProdStockEntity();
+                               prodStockEntity1.setYear(Integer.parseInt(format.substring(0,4)));
+                               prodStockEntity1.setFarmId(prodFarmNameEntity.getFarmId());
+                               prodStockEntity1.setMonth(Integer.parseInt(format.substring(5,7)));
+                               prodStockEntity1.setStockQuantity(dataList.get(2)+"");
+                               prodStockEntity1.setStockName("母猪存栏");
+                               prodStockEntity1.setStockType("sow_stock");
+                               prodStockRepo.save(prodStockEntity1);
+
+                               ProdStockEntity  prodStockEntity2 = new ProdStockEntity();
+                                prodStockEntity2.setYear(Integer.parseInt(format.substring(0,4)));
+                                prodStockEntity2.setFarmId(prodFarmNameEntity.getFarmId());
+                                prodStockEntity2.setMonth(Integer.parseInt(format.substring(5,7)));
+                                prodStockEntity2.setStockQuantity(dataList.get(4)+"");
+                                prodStockEntity2.setStockName("公猪存栏");
+                                prodStockEntity2.setStockType("boar_stock");
+                               prodStockRepo.save( prodStockEntity2);
+
+                               ProdStockEntity   prodStockEntity3 = new ProdStockEntity();
+                                prodStockEntity3.setYear(Integer.parseInt(format.substring(0,4)));
+                                prodStockEntity3.setFarmId(prodFarmNameEntity.getFarmId());
+                                prodStockEntity3.setMonth(Integer.parseInt(format.substring(5,7)));
+                                prodStockEntity3.setStockQuantity(dataList.get(6)+"");
+                                prodStockEntity3.setStockName("哺乳猪存栏");
+                                prodStockEntity3.setStockType("grice_stock");
+                               prodStockRepo.save(  prodStockEntity3);
+
+                               ProdStockEntity    prodStockEntity4 = new ProdStockEntity();
+                                prodStockEntity4.setYear(Integer.parseInt(format.substring(0,4)));
+                                prodStockEntity4.setFarmId(prodFarmNameEntity.getFarmId());
+                                prodStockEntity4.setMonth(Integer.parseInt(format.substring(5,7)));
+                                prodStockEntity4.setStockQuantity(dataList.get(7)+"");
+                                prodStockEntity4.setStockName("保育猪存栏");
+                                prodStockEntity4.setStockType("piglet_stock");
+                               prodStockRepo.save(   prodStockEntity4);
+
+                               ProdStockEntity     prodStockEntity5 = new ProdStockEntity();
+                                prodStockEntity5.setYear(Integer.parseInt(format.substring(0,4)));
+                                prodStockEntity5.setFarmId(prodFarmNameEntity.getFarmId());
+                                prodStockEntity5.setMonth(Integer.parseInt(format.substring(5,7)));
+                               Object o = dataList.get(8);
+                               if (ObjectUtil.isEmpty(o)){
+                                   prodStockEntity5.setStockQuantity( "0");
+                               }else {
+                                   prodStockEntity5.setStockQuantity(  dataList.get(8)+"");
+                               }
+                                prodStockEntity5.setStockName("育肥猪存栏");
+                                prodStockEntity5.setStockType("fatpig_stock");
+                               prodStockRepo.save( prodStockEntity5);
+
+                               ProdStockEntity      prodStockEntity6 = new ProdStockEntity();
+                                prodStockEntity6.setYear(Integer.parseInt(format.substring(0,4)));
+                                prodStockEntity6.setFarmId(prodFarmNameEntity.getFarmId());
+                                prodStockEntity6.setMonth(Integer.parseInt(format.substring(5,7)));
+                               Object data = dataList.get(1);
+                               if (ObjectUtil.isEmpty(data)){
+                                   prodStockEntity6.setStockQuantity( "0");
+                               }else {
+                                   prodStockEntity6.setStockQuantity(  dataList.get(1)+"");
+                               }
+
+                                prodStockEntity6.setStockName("总存栏");
+                                prodStockEntity6.setStockType("total_stock");
+                               prodStockRepo.save(     prodStockEntity6);
+
+                               ProdStockEntity      prodStockEntity7 = new ProdStockEntity();
+                               prodStockEntity7.setYear(Integer.parseInt(format.substring(0,4)));
+                               prodStockEntity7.setFarmId(prodFarmNameEntity.getFarmId());
+                               prodStockEntity7.setMonth(Integer.parseInt(format.substring(5,7)));
+                               Integer muZhu = (Integer)dataList.get(3);
+                               Integer gongZhu = (Integer)dataList.get(5);
+                               int count1 = 0 ;
+                               if (muZhu != null ){
+                                   count1 +=muZhu;
+                               }
+                               if (gongZhu != null ){
+                                   count1 +=gongZhu;
+                               }
+                               prodStockEntity7.setStockQuantity(count1+"");
+                               prodStockEntity7.setStockName("后备猪存栏");
+                               prodStockEntity7.setStockType("sow_stock_5");
+                               prodStockRepo.save(     prodStockEntity7);
+
+                               ProdStockEntity      prodStockEntity8 = new ProdStockEntity();
+                               prodStockEntity8.setYear(Integer.parseInt(format.substring(0,4)));
+                               prodStockEntity8.setFarmId(prodFarmNameEntity.getFarmId());
+                               prodStockEntity8.setMonth(Integer.parseInt(format.substring(5,7)));
+                               Integer zaiZhu = (Integer)dataList.get(6);
+                               Integer baoYv = (Integer)dataList.get(7);
+                               Integer yvFei = (Integer)dataList.get(8);
+                               int count = 0 ;
+                               if (zaiZhu != null ){
+                                   count +=zaiZhu;
+                               }
+                               if (baoYv != null ){
+                                   count +=baoYv;
+                               }
+                               if (yvFei != null ){
+                                   count +=yvFei;
+                               }
+                               prodStockEntity8.setStockQuantity(count+"");
+                               prodStockEntity8.setStockName("商品猪");
+                               prodStockEntity8.setStockType("business_stock");
+                               prodStockRepo.save(     prodStockEntity8);
+
+                               ProdStockEntity prodStockEntity9 = new ProdStockEntity();
+                               prodStockEntity9.setYear(Integer.parseInt(format.substring(0,4)));
+                               prodStockEntity9.setFarmId(prodFarmNameEntity.getFarmId());
+                               prodStockEntity9.setMonth(Integer.parseInt(format.substring(5,7)));
+                               prodStockEntity9.setStockQuantity("0");
+                               prodStockEntity9.setStockName("妊娠");
+                               prodStockEntity9.setStockType("sow_stock_1");
+                               prodStockRepo.save(prodStockEntity9);
+
+                               ProdStockEntity prodStockEntity10 = new ProdStockEntity();
+                               prodStockEntity10.setYear(Integer.parseInt(format.substring(0,4)));
+                               prodStockEntity10.setFarmId(prodFarmNameEntity.getFarmId());
+                               prodStockEntity10.setMonth(Integer.parseInt(format.substring(5,7)));
+                               prodStockEntity10.setStockQuantity("0");
+                               prodStockEntity10.setStockName("哺乳");
+                               prodStockEntity10.setStockType("sow_stock_2");
+                               prodStockRepo.save(prodStockEntity10);
+
+                               ProdStockEntity prodStockEntity11 = new ProdStockEntity();
+                               prodStockEntity11.setYear(Integer.parseInt(format.substring(0,4)));
+                               prodStockEntity11.setFarmId(prodFarmNameEntity.getFarmId());
+                               prodStockEntity11.setMonth(Integer.parseInt(format.substring(5,7)));
+                               prodStockEntity11.setStockQuantity("0");
+                               prodStockEntity11.setStockName("空怀");
+                               prodStockEntity11.setStockType("sow_stock_3");
+                               prodStockRepo.save(prodStockEntity11);
+                           }else {
+                               for (ProdStockEntity stockEntity : all) {
+                                   switch (stockEntity.getStockType()){
+                                       case "sow_stock":
+                                           //母猪存栏
+                                           stockEntity.setStockQuantity( dataList.get(2)+"");
+                                           prodStockRepo.save(stockEntity);
+                                           break;
+                                       case "boar_stock":
+                                           //公猪存栏
+                                           stockEntity.setStockQuantity( dataList.get(4)+"");
+                                           prodStockRepo.save(stockEntity);
+                                           break;
+                                       case "grice_stock":
+                                           //哺乳猪存栏
+                                           stockEntity.setStockQuantity( dataList.get(6)+"");
+                                           prodStockRepo.save(stockEntity);
+                                           break;
+                                       case "piglet_stock":
+                                           //保育猪存栏
+                                           stockEntity.setStockQuantity(  dataList.get(7)+"");
+                                           prodStockRepo.save(stockEntity);
+                                           break;
+                                       case "fatpig_stock":
+                                           //育肥猪存栏
+                                           Object o = dataList.get(8);
+                                           if (ObjectUtil.isEmpty(o)){
+                                               stockEntity.setStockQuantity( "0");
+                                           }else {
+                                               stockEntity.setStockQuantity(  dataList.get(8)+"");
+                                           }
+                                           prodStockRepo.save(stockEntity);
+                                           break;
+                                       case "total_stock":
+                                           //总存栏
+                                           Object data = dataList.get(1);
+                                           if (ObjectUtil.isEmpty(data)){
+                                               stockEntity.setStockQuantity( "0");
+                                           }else {
+                                               stockEntity.setStockQuantity(  dataList.get(1)+"");
+                                           }
+
+                                           prodStockRepo.save(stockEntity);
+                                           break;
+                                       case "sow_stock_5":
+                                           //后备猪存栏
+                                           Integer muZhu = (Integer)dataList.get(3);
+                                           Integer gongZhu = (Integer)dataList.get(5);
+                                           int count1 = 0 ;
+                                           if (muZhu != null ){
+                                               count1 +=muZhu;
+                                           }
+                                           if (gongZhu != null ){
+                                               count1 +=gongZhu;
+                                           }
+
+                                           stockEntity.setStockQuantity( count1+"");
+                                           prodStockRepo.save(stockEntity);
+                                           break;
+                                       case "business_stock":
+                                           //商品猪
+                                           Integer zaiZhu = (Integer)dataList.get(6);
+                                           Integer baoYv = (Integer)dataList.get(7);
+                                           Integer yvFei = (Integer)dataList.get(8);
+                                           int count = 0 ;
+                                           if (zaiZhu != null ){
+                                               count +=zaiZhu;
+                                           }
+                                           if (baoYv != null ){
+                                               count +=baoYv;
+                                           }
+                                           if (yvFei != null ){
+                                               count +=yvFei;
+                                           }
+
+                                           stockEntity.setStockQuantity(count+"");
+                                           prodStockRepo.save(stockEntity);
+                                           break;
+
+                                   }
+
+                               }
+                           }
+
+                       }
+                    }
+                }
+            }
+
+
+
+        }
+
+
+    }
+
+
+
+    @Override
     public void getManyFarmStock() throws IOException {
         String year = dateUtil.getThisYear();
         String month = dateUtil.getThisMonth();
@@ -1988,8 +2260,7 @@ public class AutoGetErpDataImpl implements IAutoGetErpData {
 
     @Override
     public void getPlay() throws IOException, ParseException {
-        String todayText = "2022-08-01";/*dateUtil.getTodayDateText();*/
-        System.out.println(todayText);
+
         List<ProdFarmNameEntity> farmNameEntityList = prodFarmNameRepo.findAll();
         Map<String, String> paramsMap = new HashMap<String, String>();
         for (ProdFarmNameEntity farmNameEntity : farmNameEntityList) {
@@ -2014,83 +2285,69 @@ public class AutoGetErpDataImpl implements IAutoGetErpData {
                         if (dataJo.size() == 0) {
                             log.info("未取到数据 。");
                         } else {
-                            BigDecimal totalBg = new BigDecimal(0);
-                            BigDecimal totalMoneyBg = new BigDecimal(0);
+                            for(int a=0;a<dataJo.size();a++) {
+                                List<Object> dataList1 = (List<Object>)dataJo.get(a);
+                                String todayText  = (String) dataList1.get(2);
+                                BigDecimal totalBg = new BigDecimal(0);
+                                BigDecimal totalMoneyBg = new BigDecimal(0);
+
+                                BigDecimal totalBg1 = new BigDecimal(0);
+                                BigDecimal totalMoneyBg1 = new BigDecimal(0);
+
+                                String todayTotal1 ="0";
+                                String  todaySaleMoney1="0";
+                                for(int b=0;b<dataJo.size();b++) {
+                                    List<Object> dataList = (List<Object>)dataJo.get(b);
+
+                                    if (todayText.equals(dataList.get(2))){
+                                        if(  dataList.get(7) != null) {
+                                            todayTotal1 =dataList.get(7)+"";
+                                        }
+                                        if(   dataList.get(9) != null) {
+                                            todaySaleMoney1 =  dataList.get(9)+"";
+                                        }
+                                        totalMoneyBg1 = totalMoneyBg1.add(new BigDecimal(todaySaleMoney1));
+                                        totalBg1 = totalBg1.add(new BigDecimal(todayTotal1));
+                                    }
 
-                            BigDecimal totalBg1 = new BigDecimal(0);
-                            BigDecimal totalMoneyBg1 = new BigDecimal(0);
 
-                            String todayTotal1 ="0";
-                            String  todaySaleMoney1="0";
-                            for(int b=0;b<dataJo.size();b++) {
-                                List<Object> dataList = (List<Object>)dataJo.get(b);
-                                System.out.println(dataList);
-                                if (todayText.equals(dataList.get(2))){
+                                    String todayTotal ="0";
+                                    String  todaySaleMoney ="0";
                                     if(  dataList.get(7) != null) {
-                                        todayTotal1 =dataList.get(7)+"";
+                                        todayTotal =dataList.get(7)+"";
                                     }
                                     if(   dataList.get(9) != null) {
-                                        todaySaleMoney1 =  dataList.get(9)+"";
+                                        todaySaleMoney =  dataList.get(9)+"";
                                     }
-                                    totalMoneyBg1 = totalMoneyBg1.add(new BigDecimal(todaySaleMoney1));
-                                    totalBg1 = totalBg1.add(new BigDecimal(todayTotal1));
-                                }
 
-
-                                String todayTotal ="0";
-                                String  todaySaleMoney ="0";
-                                if(  dataList.get(7) != null) {
-                                    todayTotal =dataList.get(7)+"";
-                                }
-                                if(   dataList.get(9) != null) {
-                                    todaySaleMoney =  dataList.get(9)+"";
+                                    totalMoneyBg = totalMoneyBg.add(new BigDecimal(todaySaleMoney));
+                                    totalBg = totalBg.add(new BigDecimal(todayTotal));
                                 }
 
-                                totalMoneyBg = totalMoneyBg.add(new BigDecimal(todaySaleMoney));
-                                totalBg = totalBg.add(new BigDecimal(todayTotal));
-                            }
-
-                            ProdSalesEntity salesEntity = new ProdSalesEntity();
-                            salesEntity.setAddDate(DateUtil.parse(todayText, "yyyy-MM-dd"));
-                            salesEntity.setFarmId(farmNameEntity.getFarmId());
-                            Example<ProdSalesEntity> example = Example.of(salesEntity);
-                            Optional<ProdSalesEntity> optional = salesRepo.findOne(example);
-                            if(optional.isPresent()){
-                                ProdSalesEntity prodSalesEntity = optional.get();
-                                prodSalesEntity.setTodayQuantity(totalBg1+"");
-                                prodSalesEntity.setTodayMoney(totalMoneyBg1+"");
-
-
-                                salesRepo.save(prodSalesEntity);
-                            }else {
-                                ProdSalesEntity prodSalesEntity = new ProdSalesEntity();
-                                prodSalesEntity.setTodayQuantity(totalBg1+"");
-                                prodSalesEntity.setTodayMoney(totalMoneyBg1+"");
-                                prodSalesEntity.setFarmId(farmNameEntity.getFarmId());
-                                prodSalesEntity.setFarmName(farmNameEntity.getFarmName());
-                                prodSalesEntity.setAddDate(DateUtil.parse(todayText, "yyyy-MM-dd"));
-                                salesRepo.save(prodSalesEntity);
-                            }
-
+                                ProdSalesEntity salesEntity = new ProdSalesEntity();
+                                salesEntity.setAddDate(DateUtil.parse(todayText, "yyyy-MM-dd"));
+                                salesEntity.setFarmId(farmNameEntity.getFarmId());
+                                Example<ProdSalesEntity> example = Example.of(salesEntity);
+                                Optional<ProdSalesEntity> optional = salesRepo.findOne(example);
+                                if(optional.isPresent()){
+                                    ProdSalesEntity prodSalesEntity = optional.get();
+                                    prodSalesEntity.setTodayQuantity(totalBg1+"");
+                                    prodSalesEntity.setTodayMoney(totalMoneyBg1+"");
+                                    prodSalesEntity.setMonthMoney(totalMoneyBg+"");
+                                    prodSalesEntity.setMonthQuantity(totalBg+"");
+                                    salesRepo.save(prodSalesEntity);
+                                }else {
+                                    ProdSalesEntity prodSalesEntity = new ProdSalesEntity();
+                                    prodSalesEntity.setTodayQuantity(totalBg1+"");
+                                    prodSalesEntity.setTodayMoney(totalMoneyBg1+"");
+                                    prodSalesEntity.setMonthMoney(totalMoneyBg+"");
+                                    prodSalesEntity.setMonthQuantity(totalBg+"");
+                                    prodSalesEntity.setFarmName(farmNameEntity.getFarmName());
+                                    prodSalesEntity.setFarmId(farmNameEntity.getFarmId());
+                                    prodSalesEntity.setAddDate(DateUtil.parse(todayText,"yyyy-MM-dd"));
+                                    salesRepo.save(prodSalesEntity);
+                                }
 
-                            ProdSalesEntity salesEntity1 = new ProdSalesEntity();
-                            salesEntity1.setAddDate(DateUtil.parse(todayText, "yyyy-MM-dd"));
-                            salesEntity1.setFarmId(farmNameEntity.getFarmId());
-                            Example<ProdSalesEntity> example1 = Example.of(salesEntity1);
-                            Optional<ProdSalesEntity> optional1 = salesRepo.findOne(example1);
-                            if(optional1.isPresent()){
-                                ProdSalesEntity prodSalesEntity = optional1.get();
-                                prodSalesEntity.setMonthMoney(totalMoneyBg+"");
-                                prodSalesEntity.setMonthQuantity(totalBg+"");
-                                salesRepo.save(prodSalesEntity);
-                            }else {
-                                ProdSalesEntity prodSalesEntity = new ProdSalesEntity();
-                                prodSalesEntity.setMonthMoney(totalMoneyBg+"");
-                                prodSalesEntity.setMonthQuantity(totalBg+"");
-                                prodSalesEntity.setFarmId(farmNameEntity.getFarmId());
-                                prodSalesEntity.setFarmName(farmNameEntity.getFarmName());
-                                prodSalesEntity.setAddDate(DateUtil.parse(todayText, "yyyy-MM-dd"));
-                                salesRepo.save(prodSalesEntity);
                             }
 
                         }
@@ -2381,7 +2638,6 @@ public class AutoGetErpDataImpl implements IAutoGetErpData {
                             newJo.put("year", year);
                             newJo.put("farm_id", farmNameEntity.getFarmId());
                             newJo.put("farm_name", farmNameEntity.getFarmName());
-                            System.out.println("farmName="+farmNameEntity.getFarmName()+","+dataJo.getString("parturition_rate"));
                         }
                     }
                 }

+ 6 - 0
huimv-hy-production/huimv.hy.erp.datasource/src/main/java/com/huimv/production/datasource/controller/ErpDataController.java

@@ -271,6 +271,12 @@ public class ErpDataController {
         return erpDataService.getManyFarmStock();
     }
 
+    @RequestMapping(value = "/getManyFarmStock2",method = RequestMethod.GET)
+    public  Result getManyFarmStock2(@RequestParam(value = "endTime",required = true) String endTime){
+
+        return erpDataService.getManyFarmStock2(endTime);
+    }
+
     /**
      * @Method      : getManyFarmProduce
      * @Description : 获取多个牧场的生产数据

+ 18 - 0
huimv-hy-production/huimv.hy.erp.datasource/src/main/java/com/huimv/production/datasource/dao/repo/TDeliveryRepo.java

@@ -995,6 +995,22 @@ public interface TDeliveryRepo extends JpaRepository<TDeliveryEntity, String>, J
             "group by pig.猪场id,TOrganizeCell.FSHORTNAME order by  TOrganizeCell.FSHORTNAME")
     List<Object[]> getManyFarmStock();
 
+    @Query(nativeQuery = true,value ="select tmp_tblcl.ZCID as 'ZCID',sum(tmp_tblcl.ZCL) as '总存栏',sum(tmp_tblcl.JCMZ) as '基础母猪',sum(tmp_tblcl.HBMZ) as '后备母猪'\n" +
+            ",sum(tmp_tblcl.GZ) as '公猪',sum(tmp_tblcl.HBGZ) as '后备公猪',sum(tmp_tblcl.BRZZ) as '仔猪',sum(tmp_tblcl.BYZ) as '保育猪'\n" +
+            ",sum(tmp_tblcl.YFZ) as '育肥',sum(tmp_tblcl.HBSPZ) as '后备商品猪' \n" +
+            "from(select TStockHistory.hogpenDID as 'ZCID', sum(TStockHistory.FAmountChangeInt) as 'ZCL', \n" +
+            "case when TStockHistory.FPigStatee in(3,4,5,6,7,10,12,13) and TStockHistory.FPigClassE=2 then sum(TStockHistory.FAmountChangeInt) end as 'JCMZ', \n" +
+            "case when TStockHistory.FPigStatee in(11) and TStockHistory.FPigClassE=2 then sum(TStockHistory.FAmountChangeInt) end as 'HBMZ', \n" +
+            "case when TStockHistory.FPigStatee in(2) and TStockHistory.FPigClassE=1 then sum(TStockHistory.FAmountChangeInt) end as 'GZ', \n" +
+            "case when TStockHistory.FPigStatee in(11) and TStockHistory.FPigClassE=1 then sum(TStockHistory.FAmountChangeInt) end as 'HBGZ', \n" +
+            "case when TStockHistory.FPigStatee in(15) and TStockHistory.FPigClassE in (1,2,3) then sum(TStockHistory.FAmountChangeInt) end as 'BRZZ', \n" +
+            "case when TStockHistory.FPigStatee in(14) and TStockHistory.FPigClassE in (1,2,3) then sum(TStockHistory.FAmountChangeInt) end as 'BYZ', \n" +
+            "case when (TStockHistory.FPigStatee in(1,22,21,16) or TStockHistory.FPigStatee is null) and TStockHistory.FPigClassE in (1,2,3) then sum(TStockHistory.FAmountChangeInt) end as 'YFZ', \n" +
+            "case when  TStockHistory.FPigStatee in(11) and TStockHistory.FPigClassE=3 then sum(TStockHistory.FAmountChangeInt) end as 'HBSPZ' \n" +
+            "from TStockHistory where TStockHistory.FdateChange<=?1 and TStockHistory.FPigClassE in(1,2,3) \n" +
+            "group by TStockHistory.hogpenDID,TStockHistory.FPigStatee,TStockHistory.FPigClassE ) tmp_tblcl group by tmp_tblcl.ZCID")
+    List<Object[]> getManyFarmStock2(String endTime);
+
     /**
      * @Method      : getManyFarmProduce
      * @Description : 
@@ -1531,4 +1547,6 @@ public interface TDeliveryRepo extends JpaRepository<TDeliveryEntity, String>, J
             ")tw group by tw.销售类型,tw.销售日期,tw.杀算时间,tw.销售类别,tw.客户,tw.销售金额,tw.毛色,tw.基础重,tw.基础单价,tw.品种,tw.关联,tw.金额,tw.备注,tw.FSHORTNAME" +
             " ORDER BY pig_number")
     List<Object[]> getSales2(String farmCode);
+
+
 }

+ 2 - 0
huimv-hy-production/huimv.hy.erp.datasource/src/main/java/com/huimv/production/datasource/service/IErpDataService.java

@@ -47,4 +47,6 @@ public interface IErpDataService {
     Result getSales();
 
     Result getSales2(String farmCode);
+
+    Result getManyFarmStock2(String endTime);
 }

+ 9 - 0
huimv-hy-production/huimv.hy.erp.datasource/src/main/java/com/huimv/production/datasource/service/impl/ErpDataServiceImpl.java

@@ -448,6 +448,13 @@ public class ErpDataServiceImpl implements IErpDataService {
         return new Result(ResultCode.SUCCESS,stockJa);
     }
 
+    @Override
+    public Result getManyFarmStock2(String endTime) {
+        List<Object[]> stockList = tDeliveryRepo.getManyFarmStock2( endTime);
+        return new Result(ResultCode.SUCCESS,stockList);
+    }
+
+
     @Autowired
     private DateUtils dateUtils;
 
@@ -745,4 +752,6 @@ public class ErpDataServiceImpl implements IErpDataService {
         return new Result(ResultCode.SUCCESS,payableList);
     }
 
+
+
 }