zhuoning пре 3 година
родитељ
комит
3fb2ee61d4

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

@@ -200,12 +200,12 @@ public class ErpDataController {
      * @Time        : 13:27
      */
     @RequestMapping("/getPigletSurvivalRate")
-    public Result getPigletSurvivalRate(@Param(value="startDate") String startDate,@Param(value="endDate") String endDate,@RequestParam(value = "accessToken",required = true) String accessToken,@RequestParam(value = "farmName",required = true) String farmName){
+    public Result getPigletSurvivalRate(@Param(value="startDate") String startDate,@Param(value="endDate") String endDate,@RequestParam(value = "accessToken",required = true) String accessToken,@RequestParam(value = "farmID",required = true) String farmID){
         // 验证token
         Result result = tokenUtil.verifyToken(accessToken);
         if(!result.isSuccess()){
             return result;
         }
-        return new Result(ResultCode.SUCCESS,erpDataService.getPigletSurvivalRate(startDate,endDate,farmName));
+        return new Result(ResultCode.SUCCESS,erpDataService.getPigletSurvivalRate(startDate,endDate,farmID));
     }
 }

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

@@ -764,155 +764,63 @@ public interface TDeliveryRepo extends JpaRepository<TDeliveryEntity, String>, J
      * @Date        : 2021/6/30       
      * @Time        : 13:31
      */
-    @Query(nativeQuery = true,value ="SELECT  " +
-            "TOrganizeCell.FSHORTNAME AS 猪场, " +
-            "CAST " +
-            "(( " +
-            "CASE " +
-            "WHEN isnull( zrjcl.RJAmount, 0 ) > 0 THEN " +
-            "1- ( " +
-            "isnull( die.教槽, 0 ) + isnull( lose.教槽, 0 )) / isnull( zrjcl.RJAmount, 0 ) ELSE 0  " +
-            "END  " +
-            ") * 100 AS DEC ( 10, 2 )) 产房存活率 " +
-            "FROM " +
-            "TOrganizeCell " +
-            "LEFT JOIN ( " +
-            "SELECT " +
-            "tmpScbd.zsmc AS 'ZCID', " +
-            "( " +
-            "SUM ( tmpScbd.zzsl ) / ( DATEDIFF( dd,?1 ,?2 ) + 1 )) AS 'RJAmount'  " +
-            "FROM " +
-            "tmpScbd  " +
-            "GROUP BY " +
-            "tmpScbd.zsmc  " +
-            ") zrjcl ON zrjcl.ZCID= TOrganizeCell.FID " +
-            "LEFT JOIN ( " +
-            "SELECT " +
-            "tmpby.zsmc AS 'ZCID', " +
-            "( " +
-            "SUM ( tmpby.zzsl ) / ( DATEDIFF( dd,?1 ,?2 ) + 1 )) AS 'RJAmount'  " +
-            "FROM " +
-            "tmpby  " +
-            "GROUP BY " +
-            "tmpby.zsmc  " +
-            ") byrjcl ON byrjcl.ZCID= TOrganizeCell.FID " +
-            "LEFT JOIN ( " +
-            "SELECT " +
-            "tmpyf.zsmc AS 'ZCID', " +
-            "( " +
-            "SUM ( tmpyf.zzsl ) / ( DATEDIFF( dd,?1 ,?2 ) + 1 )) AS 'RJAmount'  " +
-            "FROM " +
-            "tmpyf  " +
-            "GROUP BY " +
-            "tmpyf.zsmc  " +
-            ") yfrjcl ON yfrjcl.ZCID= TOrganizeCell.FID " +
-            "LEFT JOIN ( " +
-            "SELECT " +
-            "temp.PigHouseID, " +
-            "SUM ( " +
-            "isnull( temp.育肥, 0 )) AS 育肥, " +
-            "SUM ( " +
-            "isnull( temp.教槽, 0 )) AS 教槽, " +
-            "SUM ( " +
-            "isnull( temp.保育, 0 )) AS 保育  " +
-            "FROM " +
-            "( " +
-            "SELECT " +
-            "TPigDie.PigHouseID  , " +
-            "CASE " +
-            "WHEN TPigDieChild.FPigState IN ( 1, 21, 22, 16 )  " +
-            "AND TPigDieChild.FPigSex IN ( 1, 2, 3 ) THEN " +
-            "SUM ( TPigDieChild.FweakpigdieCount ) + SUM ( TPigDieChild.Fpigdiecount )  " +
-            "END '育肥', " +
-            "CASE " +
-            "WHEN TPigDieChild.FPigState IN ( 15 )  " +
-            "AND TPigDieChild.FPigSex IN ( 1, 2, 3 ) THEN " +
-            "SUM ( TPigDieChild.FweakpigdieCount ) + SUM ( TPigDieChild.Fpigdiecount )  " +
-            "END '教槽', " +
-            "CASE " +
-            "WHEN TPigDieChild.FPigState IN ( 14 )  " +
-            "AND TPigDieChild.FPigSex IN ( 1, 2, 3 ) THEN " +
-            "SUM ( TPigDieChild.FweakpigdieCount ) + SUM ( TPigDieChild.Fpigdiecount )  " +
-            "END '保育', " +
-            "CASE " +
-            "WHEN TPigDieChild.FPigState IN ( 11 )  " +
-            "AND TPigDieChild.FPigSex= 3 THEN " +
-            "SUM ( TPigDieChild.FweakpigdieCount ) + SUM ( TPigDieChild.Fpigdiecount )  " +
-            "END '后备'  " +
-            "FROM " +
-            "TPigDie " +
-            "LEFT JOIN TPigDieChild ON TPigDieChild.FPigDieMainStruID= TPigDie.FID  " +
-            "WHERE " +
-            "TPigDie.FBillState IN ( 3, 4, 6 )  " +
-            "AND TPigDieChild.FPigSex IN ( 1, 2, 3 )  " +
-            "AND FPIGSTATE IN ( 14, 15, 1, 21, 22, 11, 16 )  " +
-            "AND datediff( dd,?1 , TPigDie.FDieDate ) >= 0  " +
-            "AND datediff( dd,  ?2, TPigDie.FDieDate ) <= 0  " +
-            "GROUP BY " +
-            "TPigDieChild.FPigState, " +
-            "TPigDieChild.FPigSex , " +
-            "TPigDie.PigHouseID  " +
-            ") temp  " +
-            "GROUP BY " +
-            "temp.PigHouseID  " +
-            ") die ON die.PigHouseID= TOrganizeCell.FID " +
-            "LEFT JOIN ( " +
-            "SELECT " +
-            "temp.PigHouseID, " +
-            "SUM ( " +
-            "isnull( temp.育肥, 0 )) AS 育肥, " +
-            "SUM ( " +
-            "isnull( temp.教槽, 0 )) AS 教槽, " +
-            "SUM ( " +
-            "isnull( temp.保育, 0 )) AS 保育  " +
-            "FROM " +
-            "( " +
-            "SELECT " +
-            "TPigLose.PigHouseID  , " +
-            "CASE " +
-            "WHEN TPigLoseChild.FPigState IN ( 1, 21, 22, 16 )  " +
-            "AND TPigLoseChild.FSEX IN ( 1, 2, 3 ) THEN " +
-            "SUM ( TPigLoseChild.FpigLoseCount ) + SUM ( TPigLoseChild.FweakPigLoseCount )  " +
-            "END '育肥', " +
-            "CASE " +
-            "WHEN TPigLoseChild.FPigState IN ( 15 )  " +
-            "AND TPigLoseChild.FSEX IN ( 1, 2, 3 ) THEN " +
-            "SUM ( TPigLoseChild.FpigLoseCount ) + SUM ( TPigLoseChild.FweakPigLoseCount )  " +
-            "END '教槽', " +
-            "CASE " +
-            "WHEN TPigLoseChild.FPigState IN ( 14 )  " +
-            "AND TPigLoseChild.FSEX IN ( 1, 2, 3 ) THEN " +
-            "SUM ( TPigLoseChild.FpigLoseCount ) + SUM ( TPigLoseChild.FweakPigLoseCount )  " +
-            "END '保育', " +
-            "CASE " +
-            "WHEN TPigLoseChild.FPigState IN ( 11 )  " +
-            "AND TPigLoseChild.FSEX= 3 THEN " +
-            "SUM ( TPigLoseChild.FpigLoseCount ) + SUM ( TPigLoseChild.FweakPigLoseCount )  " +
-            "END '后备'  " +
-            "FROM " +
-            "TPigLose " +
-            "LEFT JOIN TPigLoseChild ON TPigLoseChild.FPigLoseMainStruID= TPigLose.FID  " +
-            "WHERE " +
-            "TPigLose.FBillState IN ( 3, 4, 6 )  " +
-            "AND TPigLoseChild.FSEX IN ( 1, 2, 3 )  " +
-            "AND FPIGSTATE IN ( 14, 15, 1, 21, 22, 11, 16 )  " +
-            "AND datediff( dd,?1 , TPigLose.Fpiglosedate ) >= 0  " +
-            "AND datediff( dd,  ?2, TPigLose.Fpiglosedate ) <= 0  " +
-            "GROUP BY " +
-            "TPigLoseChild.FPigState, " +
-            "TPigLoseChild.FSEX , " +
-            "TPigLose.PigHouseID  " +
-            ") temp  " +
-            "GROUP BY " +
-            "temp.PigHouseID  " +
-            ") lose ON lose.PigHouseID= TOrganizeCell.FID  " +
-            "WHERE " +
-            "FOrganizeType = 2  " +
-            "AND ( TOrganizeCell.FNAME in(?3) )  " +
-            "AND ( " +
-            "isnull( zrjcl.RJAmount, 0 ) != 0  " +
-            "OR isnull( byrjcl.RJAmount, 0 ) != 0  " +
-            "OR isnull( yfrjcl.RJAmount, 0 ) != 0  " +
-            ")")
-    List<Object[]> getPigletSurvivalRate(String startDate, String endDate, String farmName);
+    @Query(nativeQuery = true,value = "select \n" +
+            " (SELECT  CASE WHEN DATEDIFF ( dd , '2021-02-01' , '2021-03-09' ) >=31  THEN \n" +
+            " case when ISNULL(cszrjcl.ZCZS,0)!=0 then 1-(isnull(die.教槽,0)+isnull(lose.教槽,0))/cszrjcl.ZCZS else 0 end ELSE \n" +
+            " case when ISNULL(zrjcl.RJAmount,0)!=0 then 1-(isnull(die.教槽,0)+isnull(lose.教槽,0))/zrjcl.RJAmount else 0 end END )AS '仔猪存活率',\n" +
+            " TOrganizeCell.FName 'ZCNAME'\n" +
+            "from(select tmp_tblcl.ZCID as 'ZCID',sum(tmp_tblcl.ZCL) as 'ZCL',sum(tmp_tblcl.JCMZ) as 'JCMZ',sum(tmp_tblcl.HBMZ) as 'HBMZ',sum(tmp_tblcl.GZ) as 'GZ',sum(tmp_tblcl.HBGZ) as 'HBGZ',sum(tmp_tblcl.BRZZ) as 'BRZZ',sum(tmp_tblcl.BYZ) as 'BYZ',sum(tmp_tblcl.YFZ) as 'YFZ',sum(tmp_tblcl.HBSPZ) as 'HBSPZ' \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<='2021-03-09' and TStockHistory.FPigClassE in(1,2,3) \n" +
+            "  and (TStockHistory.hogpenDID in('31025DA4-F9E1-46B8-BF38-5F2FA25E9C07'))\n" +
+            "  group by TStockHistory.hogpenDID,TStockHistory.FPigStatee,TStockHistory.FPigClassE ) tmp_tblcl group by tmp_tblcl.ZCID\n" +
+            "  ) tmp_tblcl \n" +
+            "left join ( select temp.PigHouseID,sum(isnull(temp.教槽,0)) as 教槽\n" +
+            "  from\n" +
+            "  (select TPigDie.PigHouseID  ,\n" +
+            "    case when TPigDieChild.FPigState in(15) and TPigDieChild.FPigSex IN(1,2,3) then sum(TPigDieChild.FweakpigdieCount)+sum(TPigDieChild.Fpigdiecount)  end'教槽' \n" +
+            "   from TPigDie \n" +
+            "    left join TPigDieChild on TPigDieChild.FPigDieMainStruID=TPigDie.FID \n" +
+            "   where TPigDie.FBillState in(3,4,6) and TPigDieChild.FPigSex in(1,2,3) and FPIGSTATE in (14,15,1,21,22,11,2,3,7,12,13,5,6,16)\n" +
+            "      and TPigDie.PigHouseID in('31025DA4-F9E1-46B8-BF38-5F2FA25E9C07') \n" +
+            "   and ( datediff(dd,'2021-02-01', TPigDie.FDieDate)>=0 and datediff(dd,'2021-03-09',TPigDie.FDieDate) <=0) \n" +
+            "   group by TPigDieChild.FPigState,TPigDieChild.FPigSex ,TPigDie.PigHouseID  )temp\n" +
+            "   group by temp.PigHouseID\n" +
+            "   ) die on die.PigHouseID=tmp_tblcl.ZCID \n" +
+            "left join (   select temp.PigHouseID,sum(isnull(temp.教槽,0)) as 教槽\n" +
+            "  from\n" +
+            "  (select TPigLose.PigHouseID,\n" +
+            "    case when TPigLoseChild.FPigState in(15) and TPigLoseChild.FSEX IN(1,2,3) then sum(TPigLoseChild.FpigLoseCount)+sum(TPigLoseChild.FweakPigLoseCount)  end'教槽'\n" +
+            "   from TPigLose left join TPigLoseChild on TPigLoseChild.FPigLoseMainStruID=TPigLose.FID \n" +
+            "   where TPigLose.FBillState in(3,4,6) and TPigLoseChild.FSEX in(1,2,3) and FPIGSTATE in (14,15,1,21,22,11,2,3,7,12,13,5,6,16)\n" +
+            "   and TPigLose.PigHouseID in('31025DA4-F9E1-46B8-BF38-5F2FA25E9C07') \n" +
+            "    and (datediff(dd,'2021-02-01', TPigLose.Fpiglosedate )>=0 and datediff(dd,'2021-03-09',TPigLose.Fpiglosedate ) <=0) \n" +
+            "   group by TPigLoseChild.FPigState,TPigLoseChild.FSEX ,TPigLose.PigHouseID  )temp\n" +
+            "   group by temp.PigHouseID\n" +
+            "   ) lose on lose.PigHouseID=tmp_tblcl.ZCID \n" +
+            "left join (select tmp_zzchl.ZCID as 'ZCID',SUM(tmp_zzchl.zczc ) as 'ZCZS' from \n" +
+            "          (select TBorn.HOGPENDID as 'ZCID',count(TBornNewStru.FWAREPIGNOSTR) as 'zczc'\n" +
+            "           from TBorn left join TBornNewStru on TBornNewStru.FBornMainStruID = TBorn.FID \n" +
+            "                      left join TPigArchives on TPigArchives.FID = TBornNewStru.PIGFIDID\n" +
+            "           where TBorn.FLOGSTATEE in (3,4,6) \n" +
+            "             and TBorn.HOGPENDID in ('31025DA4-F9E1-46B8-BF38-5F2FA25E9C07') and  datediff(dd,'2021-02-01',TBorn.FDATEBORN)>=0 and datediff(dd,'2021-03-09',TBorn.FDATEBORN) <=0\n" +
+            "             group by TBorn.HOGPENDID\n" +
+            "             ) tmp_zzchl group by tmp_zzchl.ZCID )cszrjcl on cszrjcl.ZCID=tmp_tblcl.ZCID\n" +
+            "left join (select tmp_tbl.ZCID, AVG(tmp_tbl.FAmount) 'RJAmount'\n" +
+            " from (select tppa.HogpendID 'ZCID',tppa.FDay 'FDate',SUM(tppa.FAmount) 'FAmount' from TPigStateAmountForGoods tppa where 1=1 \n" +
+            "        and tppa.FDay>='2021-02-01'\n" +
+            "           and tppa.FDay<='2021-03-09' and FPigState=15\n" +
+            "              and tppa.HogpendID in ('31025DA4-F9E1-46B8-BF38-5F2FA25E9C07')\n" +
+            "           group by tppa.HogpendID,tppa.FDay) tmp_tbl group by tmp_tbl.ZCID )zrjcl on zrjcl.ZCID=tmp_tblcl.ZCID\n" +
+            " left join TOrganizeCell on tmp_tblcl.ZCID=TOrganizeCell.FID\n" +
+            " ")
+    List<Object[]> getPigletSurvivalRate(String startDate, String endDate, String farmID);
 }

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

@@ -18,5 +18,5 @@ public interface IErpDataService {
 
     String getAllStorage(String farmName);
 
-    Object getPigletSurvivalRate(String startDate, String endDate, String farmName);
+    Object getPigletSurvivalRate(String startDate, String endDate, String farmID);
 }

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

@@ -297,11 +297,11 @@ public class ErpDataServiceImpl implements IErpDataService {
      * @Time        : 13:28
      */
     @Override
-    public Object getPigletSurvivalRate(String startDate, String endDate, String farmName) {
+    public Object getPigletSurvivalRate(String startDate, String endDate, String farmID) {
         log.info(" 开始日期(仔猪存活率) startDate:"+startDate);
         log.info(" 结束日期(仔猪存活率) endDate:"+endDate);
-        log.info(" 牧场名称(仔猪存活率) farmName:"+farmName);
-        List<Object[]> fieldList = tDeliveryRepo.getPigletSurvivalRate(startDate,endDate,farmName);
+        log.info(" 牧场名称(仔猪存活率) farmID:"+farmID);
+        List<Object[]> fieldList = tDeliveryRepo.getPigletSurvivalRate(startDate,endDate,farmID);
         log.info(" 仔猪存活率查询数量:"+fieldList.size());
         JSONArray resultJa = new JSONArray();
         for (Object[] fieldObj : fieldList) {