Pārlūkot izejas kodu

新建并完成查询返情率和配种分娩率2个功能。

zhuoning 4 gadi atpakaļ
vecāks
revīzija
3e20aabf7c

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

@@ -2,6 +2,7 @@ package com.huimv.production.datasource.controller;
 
 import com.huimv.production.datasource.service.IErpDataService;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.repository.query.Param;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RestController;
@@ -15,7 +16,7 @@ import org.springframework.web.bind.annotation.RestController;
  * @Create : 2020-12-25
  **/
 @RestController
-@RequestMapping(value = "/ErpData",method=RequestMethod.GET)
+@RequestMapping(value = "/erpData",method=RequestMethod.GET)
 public class ErpDataController {
 
     @Autowired
@@ -23,7 +24,7 @@ public class ErpDataController {
 
     /**
      * @Method      : getPsy
-     * @Description : 
+     * @Description : 取货Psy
      * @Params      : []
      * @Return      : java.lang.String
      * 
@@ -38,7 +39,7 @@ public class ErpDataController {
 
     /**
      * @Method      : getReEstrusRate
-     * @Description : 返情率
+     * @Description : 获取返情率
      * @Params      : []
      * @Return      : java.lang.String
      * 
@@ -46,10 +47,98 @@ public class ErpDataController {
      * @Date        : 2021/5/14       
      * @Time        : 21:14
      */
-    @RequestMapping("getReEstrusRate")
-    public String getReEstrusRate(){
-        return "";
+    @RequestMapping("/getReEstrusRate")
+    public String getReEstrusRate(@Param(value="startDate") String startDate,@Param(value="endDate") String endDate){
+        return erpDataService.getReEstrusRate(startDate,endDate);
     }
 
+    /**
+     * @Method      : getParturitionRate
+     * @Description : 获取分娩率
+     * @Params      : []
+     * @Return      : java.lang.String
+     * 
+     * @Author      : ZhuoNing
+     * @Date        : 2021/5/15       
+     * @Time        : 11:02
+     */
+    @RequestMapping("/getParturitionRate")
+    public String getParturitionRate(@Param(value="startDate") String startDate,@Param(value="endDate") String endDate){
+        return erpDataService.getParturitionRate(startDate,endDate);
+    }
+
+    /**
+     * @Method      : getStorage
+     * @Description : 获取各种存栏
+     * @Params      : []
+     * @Return      : java.lang.String
+     * 
+     * @Author      : ZhuoNing
+     * @Date        : 2021/5/15       
+     * @Time        : 11:16
+     */
+    @RequestMapping("/getStorage")
+    public String getStorage(){
+        return erpDataService.getStorage();
+    }
+
+    /**
+     * @Method      : getPigletInfo
+     * @Description : 获取均产仔数,仔猪存活率
+     * @Params      : []
+     * @Return      : java.lang.String
+     * 
+     * @Author      : ZhuoNing
+     * @Date        : 2021/5/15       
+     * @Time        : 11:18
+     */
+    @RequestMapping("/getPigletInfo")
+    public String getPigletInfo(){
+        return erpDataService.getPigletInfo();
+    }
 
+    /**
+     * @Method      : getMatingTimes
+     * @Description : 配种数量
+     * @Params      : []
+     * @Return      : java.lang.String
+     * 
+     * @Author      : ZhuoNing
+     * @Date        : 2021/5/15       
+     * @Time        : 11:35
+     */
+    @RequestMapping("/getMateQuantity")
+    public String getMateQuantity(){
+        return erpDataService.getMateQuantity();
+    }
+
+    /**
+     * @Method      : getConceptionRate
+     * @Description : 受胎率
+     * @Params      : []
+     * @Return      : java.lang.String
+     * 
+     * @Author      : ZhuoNing
+     * @Date        : 2021/5/15       
+     * @Time        : 11:38
+     */
+    @RequestMapping("/getConceptionRate")
+    public String getConceptionRate(){
+        return erpDataService.getConceptionRate();
+    }
+
+    /**
+     * @Method      : getAllStorage
+     * @Description : 总存栏,母猪存栏
+     * @Params      : []
+     * @Return      : java.lang.String
+     * 
+     * @Author      : ZhuoNing
+     * @Date        : 2021/5/15       
+     * @Time        : 11:39
+     */
+    @RequestMapping("/getAllStorage")
+    public String getAllStorage(){
+        return erpDataService.getAllStorage();
+    }
 }

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

@@ -8,6 +8,17 @@ import org.springframework.data.jpa.repository.Query;
 import java.util.List;
 
 public interface TDeliveryRepo extends JpaRepository<TDeliveryEntity, String>, JpaSpecificationExecutor<TDeliveryEntity> {
+   
+    /**
+     * @Method      : getPsy
+     * @Description : Psy
+     * @Params      : []
+     * @Return      : java.util.List<java.lang.Object[]>
+     * 
+     * @Author      : ZhuoNing
+     * @Date        : 2021/5/15       
+     * @Time        : 13:50
+     */
     @Query(nativeQuery = true,value = "select CAST(PJWCHZ*chl*NLYWS AS DEC(8,2)) AS 'PSY' from (select avg(TNewStru7743.FamountLiveInt*1.0) as 'PJWCHZ'" +
             " from TDelivery left join TNewStru7743 on TNewStru7743.FDeliveryMainStruID=TDelivery.FID " +
             " where TDelivery.FLogStatee in(3,4,6) and TDelivery.FDateDelivery between '2021-03-01' and '2021-03-09')PJWCHZ, " +
@@ -29,4 +40,60 @@ public interface TDeliveryRepo extends JpaRepository<TDeliveryEntity, String>, J
             " ) tmp_tbl " +
             " having avg(tjj)>0)ncws ")
     List<Object[]> getPsy();
+
+    /**
+     * @Method      : getReEstrusRate
+     * @Description : 返情率
+     * @Params      : []
+     * @Return      : java.util.List<java.lang.Object[]>
+     *
+     * @Author      : ZhuoNing
+     * @Date        : 2021/5/15
+     * @Time        : 13:50
+     */
+    @Query(nativeQuery = true,value =
+            "select TOrganizeCell.FSHORTNAME as 'farm', tmp_tblpz.FBreedD as 'variety'," +
+            "CAST(count(tmp_tblfm.SowStrID)*1.0/(case sum(tmp_tblpz.mate_times) when 0 then null else sum(tmp_tblpz.mate_times) end) as dec(8,5)) as 'reestrus_rate' " +
+            "from (select " +
+            "TBreeding.HogpendID,TNewStru8094.FBreedD,TNewStru8094.SowStrID,TNewStru8094.FParityInt,count(TNewStru8094.FID) as 'mate_times' " +
+            "from TBreeding left join TNewStru8094 on TNewStru8094.FBreedingMainStruID=TBreeding.FID " +
+            "where TBreeding.FLogStatee in(3,4,6)   and datediff(dd, ?1, FDateBreed)>=-121 and datediff(dd, ?2,FDateBreed) <=-121 " +
+            "group by TBreeding.HogpendID,TNewStru8094.FBreedD,TNewStru8094.SowStrID,TNewStru8094.FParityInt " +
+            ") tmp_tblpz " +
+            "left join (select TReturnEstrusewStru.SowStrID,TReturnEstrusewStru.FParityInt from TReturnEstrusewStru " +
+            "left join TReturnEstrus on TReturnEstrusewStru.FReturnEstrusMainStruID=TReturnEstrus.FID " +
+            "where TReturnEstrus.FLogStatee in(3,4,6)  and datediff(dd, ?1, TReturnEstrusewStru.FDateBreed)>=-121 and datediff(dd, ?2,TReturnEstrusewStru.FDateBreed) <=-121 " +
+            ") tmp_tblfm on tmp_tblpz.SowStrID=tmp_tblfm.SowStrID and tmp_tblpz.FParityInt=tmp_tblfm.FParityInt " +
+            "left join TOrganizeCell on tmp_tblpz.HogpendID=TOrganizeCell.FID " +
+            "where TOrganizeCell.FNAME is not null " +
+            "group by TOrganizeCell.FSHORTNAME,tmp_tblpz.FBreedD")
+    List<Object[]> getReEstrusRate(String startDate,String endDate);
+
+    /**
+     * @Method      : getParturitionRate
+     * @Description : 分娩率
+     * @Params      : [startDate, endDate]
+     * @Return      : java.util.List<java.lang.Object[]>
+     * 
+     * @Author      : ZhuoNing
+     * @Date        : 2021/5/15       
+     * @Time        : 14:43
+     */
+    @Query(nativeQuery = true,value ="select TOrganizeCell.FSHORTNAME as 'farm', tmp_tblpz.FBreedD as 'variety', " +
+            "CAST(count(tmp_tblfm.SowStrID)*1.0/(case sum(tmp_tblpz.mate_times) when 0 then null else sum(tmp_tblpz.mate_times) end) as dec(8,5)) as 'parturition_rate' " +
+            "from (select " +
+            "TBreeding.HogpendID,TNewStru8094.FBreedD,TNewStru8094.SowStrID,TNewStru8094.FParityInt,count(TNewStru8094.FID) as 'mate_times' " +
+            "from TBreeding left join TNewStru8094 on TNewStru8094.FBreedingMainStruID=TBreeding.FID " +
+            "where TBreeding.FLogStatee in(3,4,6) and datediff(dd, ?1, FDateBreed)>=-121 and datediff(dd, ?2,FDateBreed) <=-121 " +
+            "group by TBreeding.HogpendID,TNewStru8094.FBreedD,TNewStru8094.SowStrID,TNewStru8094.FParityInt " +
+            ") tmp_tblpz " +
+            "left join (select TNewStru7743.SowStrID,TNewStru7743.FParityInt from TNewStru7743 " +
+            "left join TDelivery on TNewStru7743.FDeliveryMainStruID=TDelivery.FID " +
+            "where TDelivery.FLogStatee in(3,4,6)  and datediff(dd, ?1, TNewStru7743.FDateBreed )>=-121 " +
+            "and datediff(dd, ?2,TNewStru7743.FDateBreed ) <=-121 " +
+            ") tmp_tblfm on tmp_tblpz.SowStrID=tmp_tblfm.SowStrID and tmp_tblpz.FParityInt=tmp_tblfm.FParityInt " +
+            "left join TOrganizeCell on tmp_tblpz.HogpendID=TOrganizeCell.FID " +
+            "where TOrganizeCell.FNAME is not null " +
+            "group by TOrganizeCell.FSHORTNAME,tmp_tblpz.FBreedD ")
+    List<Object[]> getParturitionRate(String startDate, String endDate);
 }

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

@@ -3,4 +3,18 @@ package com.huimv.production.datasource.service;
 public interface IErpDataService {
 
     String getPsy();
+
+    String getReEstrusRate(String startDate,String endDate);
+
+    String getParturitionRate(String startDate,String endDate);
+
+    String getStorage();
+
+    String getPigletInfo();
+
+    String getMateQuantity();
+
+    String getConceptionRate();
+
+    String getAllStorage();
 }

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

@@ -1,7 +1,10 @@
 package com.huimv.production.datasource.service.impl;
 
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
 import com.huimv.production.datasource.dao.repo.TDeliveryRepo;
 import com.huimv.production.datasource.service.IErpDataService;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -16,14 +19,24 @@ import java.util.List;
  * @Create : 2020-12-25
  **/
 @Service
+@Slf4j
 public class ErpDataServiceImpl implements IErpDataService {
 
     @Autowired
     private TDeliveryRepo tDeliveryRepo;
 
+    /**
+     * @Method      : getPsy
+     * @Description : Psy
+     * @Params      : []
+     * @Return      : java.lang.String
+     * 
+     * @Author      : ZhuoNing
+     * @Date        : 2021/5/15       
+     * @Time        : 11:40
+     */
     @Override
     public String getPsy() {
-
         List<Object[]> psyFieldList = tDeliveryRepo.getPsy();
 //        System.out.println("psyFieldList.size: "+psyFieldList.size());
         String psy = "";
@@ -33,4 +46,139 @@ public class ErpDataServiceImpl implements IErpDataService {
         }
         return psy;
     }
+
+    /**
+     * @Method      : getReEstrusRate
+     * @Description : 返情率
+     * @Params      : []
+     * @Return      : java.lang.String
+     * 
+     * @Author      : ZhuoNing
+     * @Date        : 2021/5/15       
+     * @Time        : 11:41
+     */
+    @Override
+    public String getReEstrusRate(String startDate,String endDate) {
+        log.info(" 开始日期(返情率) startDate:"+startDate);
+        log.info(" 结束日期(返情率) endDate:"+endDate);
+        List<Object[]> reEstrusRateFieldList = tDeliveryRepo.getReEstrusRate(startDate,endDate);
+        log.info(" 返情率查询数量:"+reEstrusRateFieldList.size());
+        JSONArray resultJa = new JSONArray();
+        for (Object[] fieldObj : reEstrusRateFieldList) {
+            String farmVal = fieldObj[0].toString();
+            String varietyVal = fieldObj[1].toString();
+            String reEstrusRateVal = fieldObj[2].toString();
+            JSONObject dataJo = new JSONObject();
+            dataJo.put("farm",farmVal);
+            dataJo.put("variety",varietyVal);
+            dataJo.put("reestrus_rate",reEstrusRateVal);
+            resultJa.add(dataJo);
+        }
+        return resultJa.toJSONString();
+    }
+
+    /**
+     * @Method      : getParturitionRate
+     * @Description : 分娩率
+     * @Params      : []
+     * @Return      : java.lang.String
+     * 
+     * @Author      : ZhuoNing
+     * @Date        : 2021/5/15       
+     * @Time        : 11:41
+     */
+    @Override
+    public String getParturitionRate(String startDate,String endDate) {
+        log.info(" 开始日期(分娩率) startDate:"+startDate);
+        log.info(" 结束日期(分娩率) endDate:"+endDate);
+        List<Object[]> reEstrusRateFieldList = tDeliveryRepo.getParturitionRate(startDate,endDate);
+        log.info(" 分娩率查询数量:"+reEstrusRateFieldList.size());
+        JSONArray resultJa = new JSONArray();
+        for (Object[] fieldObj : reEstrusRateFieldList) {
+            String farmVal = fieldObj[0].toString();
+            String varietyVal = fieldObj[1].toString();
+            String reEstrusRateVal = fieldObj[2].toString();
+            JSONObject dataJo = new JSONObject();
+            dataJo.put("farm",farmVal);
+            dataJo.put("variety",varietyVal);
+            dataJo.put("parturition_rate",reEstrusRateVal);
+            resultJa.add(dataJo);
+        }
+        return resultJa.toJSONString();
+    }
+
+    /**
+     * @Method      : getStorage
+     * @Description : 各种存栏
+     * @Params      : []
+     * @Return      : java.lang.String
+     * 
+     * @Author      : ZhuoNing
+     * @Date        : 2021/5/15       
+     * @Time        : 11:42
+     */
+    @Override
+    public String getStorage() {
+        return null;
+    }
+
+    /**
+     * @Method      : getPigletInfo
+     * @Description : 均产仔数,仔猪存活率
+     * @Params      : []
+     * @Return      : java.lang.String
+     * 
+     * @Author      : ZhuoNing
+     * @Date        : 2021/5/15       
+     * @Time        : 11:43
+     */
+    @Override
+    public String getPigletInfo() {
+        return null;
+    }
+
+    /**
+     * @Method      : getMateQuantity
+     * @Description : 配种数量
+     * @Params      : []
+     * @Return      : java.lang.String
+     * 
+     * @Author      : ZhuoNing
+     * @Date        : 2021/5/15       
+     * @Time        : 11:44
+     */
+    @Override
+    public String getMateQuantity() {
+        return null;
+    }
+
+    /**
+     * @Method      : getConceptionRate
+     * @Description : 受胎率
+     * @Params      : []
+     * @Return      : java.lang.String
+     * 
+     * @Author      : ZhuoNing
+     * @Date        : 2021/5/15       
+     * @Time        : 11:45
+     */
+    @Override
+    public String getConceptionRate() {
+        return null;
+    }
+
+    /**
+     * @Method      : getAllStorage
+     * @Description : 总存栏,母猪存栏
+     * @Params      : []
+     * @Return      : java.lang.String
+     * 
+     * @Author      : ZhuoNing
+     * @Date        : 2021/5/15       
+     * @Time        : 11:45
+     */
+    @Override
+    public String getAllStorage() {
+        return null;
+    }
 }