|
@@ -1,10 +1,12 @@
|
|
|
package com.huimv.production.datasource.dao.repo;
|
|
|
|
|
|
import com.huimv.production.datasource.dao.entity.TDeliveryEntity;
|
|
|
+import org.joda.time.DateTime;
|
|
|
import org.springframework.data.jpa.repository.JpaRepository;
|
|
|
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
|
|
import org.springframework.data.jpa.repository.Query;
|
|
|
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
|
|
|
public interface TDeliveryRepo extends JpaRepository<TDeliveryEntity, String>, JpaSpecificationExecutor<TDeliveryEntity> {
|
|
@@ -869,10 +871,10 @@ public interface TDeliveryRepo extends JpaRepository<TDeliveryEntity, String>, J
|
|
|
" and (TStockHistory.hogpenDID in( ?3) )\n" +
|
|
|
" group by TStockHistory.hogpenDID,qj.time ) tmp_tblcl\n" +
|
|
|
" group by tmp_tblcl.ZCID)clbd on clqc.ZCID =clbd.ZCID\n" +
|
|
|
- "left join (\tselect temp.PigHouseID,sum(isnull(temp.教槽,0)) as 教槽\n" +
|
|
|
+ "left join ( select temp.PigHouseID,sum(isnull(temp.教槽,0)) as 教槽\n" +
|
|
|
" from\n" +
|
|
|
" (select TPigDie.PigHouseID ,\n" +
|
|
|
- " case\twhen TPigDieChild.FPigState in(15) and TPigDieChild.FPigSex IN(1,2,3) then sum(TPigDieChild.FweakpigdieCount)+sum(TPigDieChild.Fpigdiecount) end'教槽' \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" +
|
|
@@ -881,10 +883,10 @@ public interface TDeliveryRepo extends JpaRepository<TDeliveryEntity, String>, J
|
|
|
" group by TPigDieChild.FPigState,TPigDieChild.FPigSex ,TPigDie.PigHouseID )temp\n" +
|
|
|
" group by temp.PigHouseID\n" +
|
|
|
" ) die on die.PigHouseID=clqc.ZCID \n" +
|
|
|
- "left join ( \tselect temp.PigHouseID,sum(isnull(temp.教槽,0)) as 教槽\n" +
|
|
|
+ "left join ( select temp.PigHouseID,sum(isnull(temp.教槽,0)) as 教槽\n" +
|
|
|
" from\n" +
|
|
|
" (select TPigLose.PigHouseID , \n" +
|
|
|
- " case\twhen TPigLoseChild.FPigState in(15) and TPigLoseChild.FSEX IN(1,2,3) then sum(TPigLoseChild.FpigLoseCount)+sum(TPigLoseChild.FweakPigLoseCount) end'教槽' \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( ?3) \n" +
|
|
@@ -902,4 +904,297 @@ public interface TDeliveryRepo extends JpaRepository<TDeliveryEntity, String>, J
|
|
|
" ) tmp_zzchl group by tmp_zzchl.ZCID )cszrjcl on cszrjcl.ZCID=clqc.ZCID\n" +
|
|
|
"left join TOrganizeCell on clqc.ZCID=TOrganizeCell.FID")
|
|
|
List<Object[]> getPigletSurvivalRate2(String startDate, String endDate, String farmID);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @Method : getCostWithManyFarm
|
|
|
+ * @Description :
|
|
|
+ * @Params : [month]
|
|
|
+ * @Return : java.util.List<java.lang.Object[]>
|
|
|
+ *
|
|
|
+ * @Author : ZhuoNing
|
|
|
+ * @Date : 2021/11/13
|
|
|
+ * @Time : 17:56
|
|
|
+ */
|
|
|
+ @Query(nativeQuery = true,value = "select TOrganizeCell.FSHORTNAME,FBASISPIGBATCH as '基础猪群',FCAREPIGBATCH as '保育猪群',FFATTENBOAR as '育肥',FFATTENWARE as '后备',FCOMMONCOSTS as '共同费用',TMonthCostDetailChild.FACCOUNT as '合计',TPublicCostProject.FPROJECTNAME from TMonthCostDetailChild,TPublicCostProject \n" +
|
|
|
+ ",TMonthCostDetail,TOrganizeCell where PUBPROJECTID=TPublicCostProject.FID \n" +
|
|
|
+ "and TMonthCostDetail.FID=TMonthCostDetailChild.FMonthCostDetailMainStruID \n" +
|
|
|
+ "and TMonthCostDetail.CREATEORGID=TOrganizeCell.FID \n" +
|
|
|
+ "and TMonthCostDetail.FBILLSTATE=3 \n" +
|
|
|
+ "and FPROJECTNAME in('存栏','饲料费','防疫消毒','兽药','公摊费用项目') \n" +
|
|
|
+ "and TMonthCostDetail.ACCOUNTPERIODID in (select FID from TAccountingPeriodData where FNAME=?1) \n" +
|
|
|
+ "order by TOrganizeCell.FSHORTNAME,FITEM,TOrganizeCell.fid")
|
|
|
+ List<Object[]> getCostWithManyFarm(String month);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @Method : getManyFarmStock
|
|
|
+ * @Description :
|
|
|
+ * @Params : []
|
|
|
+ * @Return : java.util.List<java.lang.Object[]>
|
|
|
+ *
|
|
|
+ * @Author : ZhuoNing
|
|
|
+ * @Date : 2021/11/13
|
|
|
+ * @Time : 18:44
|
|
|
+ */
|
|
|
+ @Query(nativeQuery = true,value =
|
|
|
+ "select TOrganizeCell.FSHORTNAME as 猪场\n" +
|
|
|
+ ",ISNULL(sum(pig.母猪后备),0)+ISNULL(sum(pig.空怀),0)+ISNULL(sum(pig.妊娠),0)+ISNULL(sum(pig.哺乳),0) AS 母猪\n" +
|
|
|
+ ",ISNULL(sum(pig.公猪后备),0) +ISNULL(sum(pig.成年),0) AS 公猪,ISNULL(sum(pig.教槽),0) AS 仔猪,\n" +
|
|
|
+ "ISNULL(sum(pig.保育),0) AS 保育 ,ISNULL(sum(pig.育成),0) +ISNULL(sum(pig.育肥),0) AS 育肥,ISNULL(sum(pig.后备),0) AS 后备\n" +
|
|
|
+ ",ISNULL(sum(pig.妊娠),0) AS 妊娠,ISNULL(sum(pig.哺乳),0) AS 哺乳,ISNULL(sum(pig.空怀),0) AS 空怀\n" +
|
|
|
+ "from\n" +
|
|
|
+ "(select \n" +
|
|
|
+ " tbl_tmp.猪场id,\n" +
|
|
|
+ " SUM(CASE WHEN tbl_tmp.状态 = '公猪后备' THEN tbl_tmp.数量 ELSE 0 END) AS 公猪后备,\n" +
|
|
|
+ " SUM(CASE WHEN tbl_tmp.状态 = '成年' THEN tbl_tmp.数量 ELSE 0 END) AS 成年, \n" +
|
|
|
+ " SUM(CASE WHEN tbl_tmp.状态 = '母猪后备' THEN tbl_tmp.数量 ELSE 0 END) AS 母猪后备,\n" +
|
|
|
+ " SUM(CASE WHEN tbl_tmp.状态 = '空怀' THEN tbl_tmp.数量 ELSE 0 END) AS 空怀,\n" +
|
|
|
+ " SUM(CASE WHEN tbl_tmp.状态 = '妊娠' THEN tbl_tmp.数量 ELSE 0 END) AS 妊娠, \n" +
|
|
|
+ " SUM(CASE WHEN tbl_tmp.状态 = '哺乳' THEN tbl_tmp.数量 ELSE 0 END) AS 哺乳, \n" +
|
|
|
+ " SUM(CASE WHEN tbl_tmp.状态 = '教槽' THEN tbl_tmp.数量 ELSE 0 END) AS 教槽,\n" +
|
|
|
+ " SUM(CASE WHEN tbl_tmp.状态 = '保育' THEN tbl_tmp.数量 ELSE 0 END) AS 保育, \n" +
|
|
|
+ " SUM(CASE WHEN tbl_tmp.状态 = '育成' THEN tbl_tmp.数量 ELSE 0 END) AS 育成, \n" +
|
|
|
+ " SUM(CASE WHEN tbl_tmp.状态 = '育肥' THEN tbl_tmp.数量 ELSE 0 END) AS 育肥,\n" +
|
|
|
+ " SUM(CASE WHEN tbl_tmp.状态 = '后备' THEN tbl_tmp.数量 ELSE 0 END) AS 后备\n" +
|
|
|
+ " from\n" +
|
|
|
+ "(select \n" +
|
|
|
+ "case when TPigArchives.FPigStatee=2 and TPigArchives.FPigClassEnum =1 then '成年' \n" +
|
|
|
+ " when TPigArchives.FPigStatee=11 and TPigArchives.FPigClassEnum =1 then '公猪后备' \n" +
|
|
|
+ " when TPigArchives.FPigStatee=14 and TPigArchives.FPigClassEnum in(1,2) then '保育' \n" +
|
|
|
+ " when TPigArchives.FPigStatee=15 and TPigArchives.FPigClassEnum in(1,2) then '教槽' \n" +
|
|
|
+ " when TPigArchives.FPigStatee=1 and TPigArchives.FPigClassEnum in(1,2) then '育肥' \n" +
|
|
|
+ " when TPigArchives.FPigStatee in (4,5) and TPigArchives.FPigClassEnum =2 then '妊娠' \n" +
|
|
|
+ " when TPigArchives.FPigStatee=6 and TPigArchives.FPigClassEnum =2 then '哺乳' \n" +
|
|
|
+ " when TPigArchives.FPigStatee=11 and TPigArchives.FPigClassEnum =2 then '母猪后备' \n" +
|
|
|
+ " when TPigArchives.FPigStatee in(3,7,10,12,13)and TPigArchives.FPigClassEnum =2 then '空怀' end as '状态',\n" +
|
|
|
+ "count(TPigArchives.FID) as '数量',\n" +
|
|
|
+ "TPigArchives.HOGPENWHEREDID as 猪场id\n" +
|
|
|
+ "from TPigArchives \n" +
|
|
|
+ "where TPigArchives.FPigClassEnum in(1,2) and TPigArchives.FPigStatee in(3,7,10,12,13,2,11,14,15,1,4,5,6) \n" +
|
|
|
+ "and HOGPENWHEREDID is not null \n" +
|
|
|
+ "group by TPigArchives.FPigStatee,TPigArchives.FPigClassEnum ,TPigArchives.HOGPENWHEREDID\n" +
|
|
|
+ "union all\n" +
|
|
|
+ " select \n" +
|
|
|
+ " case when TPigArchives.FPigStatee=14 then '保育' \n" +
|
|
|
+ " when TPigArchives.FPigStatee=15 then '教槽' \n" +
|
|
|
+ " when TPigArchives.FPigStatee=16 then '育成' \n" +
|
|
|
+ " when TPigArchives.FPigStatee=1 then '育肥' \n" +
|
|
|
+ " when TPigArchives.FPigStatee=11 then '后备' end as '状态',\n" +
|
|
|
+ " isnull(sum(TPigArchivesChild.FpigAmountOfPigsty),0) as '数量' ,TPigArchives.hogpenwheredID \n" +
|
|
|
+ "from TPigArchives \n" +
|
|
|
+ "left join TPigArchivesChild on TPigArchivesChild.FPigArchivesMainStruID=TPigArchives.FID \n" +
|
|
|
+ "left join TFeedStage on TPigArchives.feedingStageEID=TFeedStage.FID \n" +
|
|
|
+ "where TPigArchives.FPigClassEnum in(3) \n" +
|
|
|
+ "and TFeedStage.fstagename is not null \n" +
|
|
|
+ "and FBatchState=0 \n" +
|
|
|
+ "and TPigArchives.FPigStatee not in(8,9,17,18) \n" +
|
|
|
+ "group by TPigArchives.FPigStatee ,TPigArchives.hogpenwheredID \n" +
|
|
|
+ ") as tbl_tmp \n" +
|
|
|
+ " group by tbl_tmp.状态,tbl_tmp.猪场id)pig\n" +
|
|
|
+ " left join TOrganizeCell on pig.猪场id=TOrganizeCell.FID \n" +
|
|
|
+ "group by pig.猪场id,TOrganizeCell.FSHORTNAME order by TOrganizeCell.FSHORTNAME")
|
|
|
+ List<Object[]> getManyFarmStock();
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @Method : getManyFarmProduce
|
|
|
+ * @Description :
|
|
|
+ * @Params : [startDate, endDate]
|
|
|
+ * @Return : java.util.List<java.lang.Object[]>
|
|
|
+ *
|
|
|
+ * @Author : ZhuoNing
|
|
|
+ * @Date : 2021/11/16
|
|
|
+ * @Time : 18:37
|
|
|
+ */
|
|
|
+ @Query(nativeQuery = true,value ="select TOrganizeCell.FNAME, (SELECT CASE WHEN DATEDIFF ( dd , ?1 , ?2 ) >=31 THEN \n" +
|
|
|
+ "case when ISNULL(cszrjcl.出生合格仔,0)!=0 then 1-(isnull(die.教槽,0)+isnull(lose.教槽,0))/cszrjcl.出生合格仔 else 0 end ELSE \n" +
|
|
|
+ "case when isnull(clqc.仔猪日均存栏,0)+isnull(clbd.仔猪日均存栏,0) !=0\n" +
|
|
|
+ "then 1-(isnull(die.教槽,0)+isnull(lose.教槽,0))/(isnull(clqc.仔猪日均存栏,0)+isnull(clbd.仔猪日均存栏,0) ) else 0 end END )AS '产房成活率',\n" +
|
|
|
+ " (SELECT CASE WHEN DATEDIFF ( dd , ?1 , ?2 ) >=31 THEN \n" +
|
|
|
+ "case when isnull(spzyz.商品猪引种保育头数,0)+isnull(tmp_tblzz.仔猪断奶头数,0)>0 then 1-(isnull(die.保育,0)+isnull(lose.保育,0))/(isnull(spzyz.商品猪引种保育头数,0)+isnull(tmp_tblzz.仔猪断奶头数,0)) else 0 end ELSE \n" +
|
|
|
+ "case when isnull(clqc.保育日均存栏,0)+isnull(clbd.保育日均存栏,0) !=0\n" +
|
|
|
+ "then 1-(isnull(die.保育,0)+isnull(lose.保育,0))/(isnull(clqc.保育日均存栏,0)+isnull(clbd.保育日均存栏,0))else 0 end END )AS '保育成活率',\n" +
|
|
|
+ " (SELECT CASE WHEN DATEDIFF ( dd , ?1 , ?2 ) >=31 THEN \n" +
|
|
|
+ "case when isnull(spzyz.商品猪引种育肥头数,0)+isnull(tmp_tblbyz.ZYFZTS,0)>0 then 1-(isnull(die.育肥,0)+isnull(lose.育肥,0))/(isnull(spzyz.商品猪引种育肥头数,0)+isnull(tmp_tblbyz.ZYFZTS,0)) else 0 end ELSE \n" +
|
|
|
+ "case when isnull(clqc.育肥日均存栏,0)+isnull(clbd.育肥日均存栏,0) !=0\n" +
|
|
|
+ "then 1-( isnull(die.育肥,0)+isnull(lose.育肥,0))/( isnull(clqc.育肥日均存栏,0)+isnull(clbd.育肥日均存栏,0))else 0 end END )AS '肥猪成活率'\n" +
|
|
|
+ " ,isnull(tmp_tblfm.PJWCZZ,0) as '平均窝产仔猪', isnull(tmp_tblfm.PJWCHZ,0) as '平均窝产活仔数', isnull(tmp_tblfm.PJWCZC,0) as '平均窝产正常仔数',isnull(tmp_tbldn.PJWDNTS,0) as '窝断奶仔猪数'\n" +
|
|
|
+ " ,isnull(tmp_tbldn.PJDNWZ,0) as '平均断奶窝重',isnull(dn3.DPL,0) as '7日断配率',NCWS.NLYWS as '年产窝数'\n" +
|
|
|
+ "from \n" +
|
|
|
+ " ( \n" +
|
|
|
+ " select TStockHistory.hogpenDID as 'ZCID', sum(TStockHistory.FAmountChangeInt) as 'ZCL', \n" +
|
|
|
+ " sum(case when TStockHistory.FPigStatee in(3,4,5,6,7,12,13) and TStockHistory.FPigClassE=2 then isnull(TStockHistory.FAmountChangeInt,0)end) as '母猪日均存栏', \n" +
|
|
|
+ " sum(case when TStockHistory.FPigStatee in(3,7,12,13,5,6,2,11) and TStockHistory.FPigClassE in(1,2,3) then isnull(TStockHistory.FAmountChangeInt,0)end) as '种猪日均存栏', \n" +
|
|
|
+ " sum(case when TStockHistory.FPigStatee in(11) and TStockHistory.FPigClassE in (1,2,3) then isnull(TStockHistory.FAmountChangeInt,0)end) as '后备日均存栏', \n" +
|
|
|
+ " sum(case when TStockHistory.FPigStatee in(15) and TStockHistory.FPigClassE in (1,2,3) then isnull(TStockHistory.FAmountChangeInt,0)end) as '仔猪日均存栏', \n" +
|
|
|
+ " sum(case when TStockHistory.FPigStatee in(14) and TStockHistory.FPigClassE in (1,2,3) then isnull(TStockHistory.FAmountChangeInt,0)end) as '保育日均存栏', \n" +
|
|
|
+ " sum(case when (TStockHistory.FPigStatee in(1,22,21,16) or TStockHistory.FPigStatee is null) and TStockHistory.FPigClassE in (1,2,3) then isnull(TStockHistory.FAmountChangeInt,0)end) as '育肥日均存栏', \n" +
|
|
|
+ " sum(case when TStockHistory.FPigStatee in(11) and TStockHistory.FPigClassE=3 then isnull(TStockHistory.FAmountChangeInt,0)end) as '后备商日均存栏' \n" +
|
|
|
+ " from TStockHistory \n" +
|
|
|
+ " where datediff(dd, ?1, TStockHistory.FdateChange)<0 \n" +
|
|
|
+ " and TStockHistory.FPigClassE in(1,2,3) \n" +
|
|
|
+ " group by TStockHistory.hogpenDID)clqc \n" +
|
|
|
+ " left join (select tmp_tblcl.ZCID as 'ZCID',round(avg(isnull(tmp_tblcl.ZCL,0)*1.00000),0) as 'ZCL',round(avg(isnull(tmp_tblcl.母猪日均存栏,0)*1.00000),0) as '母猪日均存栏'\n" +
|
|
|
+ " ,round(avg(isnull(tmp_tblcl.种猪日均存栏,0)*1.00000),0) as '种猪日均存栏'\n" +
|
|
|
+ " ,round(avg(isnull(tmp_tblcl.后备日均存栏,0)*1.00000),0) as '后备日均存栏',round(avg(isnull(tmp_tblcl.仔猪日均存栏,0)*1.00000),0) as '仔猪日均存栏'\n" +
|
|
|
+ " ,round(avg(isnull(tmp_tblcl.保育日均存栏,0)*1.00000),0) as '保育日均存栏',round(avg(isnull(tmp_tblcl.育肥日均存栏,0)*1.00000),0) as '育肥日均存栏'\n" +
|
|
|
+ " ,round(avg(isnull(tmp_tblcl.后备商品猪日均存栏,0)*1.00000),0) as '后备商日均存栏'\n" +
|
|
|
+ " from( \n" +
|
|
|
+ " select TStockHistory.hogpenDID as 'ZCID', sum(TStockHistory.FAmountChangeInt) as 'ZCL', \n" +
|
|
|
+ " sum(case when TStockHistory.FPigStatee in(3,4,5,6,7,12,13) and TStockHistory.FPigClassE=2 then isnull(TStockHistory.FAmountChangeInt,0)end) as '母猪日均存栏', \n" +
|
|
|
+ " sum(case when TStockHistory.FPigStatee in(3,7,12,13,5,6,2,11) and TStockHistory.FPigClassE in(1,2,3) then isnull(TStockHistory.FAmountChangeInt,0)end) as '种猪日均存栏', \n" +
|
|
|
+ " sum(case when TStockHistory.FPigStatee in(11) and TStockHistory.FPigClassE in (1,2,3) then isnull(TStockHistory.FAmountChangeInt,0)end) as '后备日均存栏', \n" +
|
|
|
+ " sum(case when TStockHistory.FPigStatee in(15) and TStockHistory.FPigClassE in (1,2,3) then isnull(TStockHistory.FAmountChangeInt,0)end) as '仔猪日均存栏', \n" +
|
|
|
+ " sum(case when TStockHistory.FPigStatee in(14) and TStockHistory.FPigClassE in (1,2,3) then isnull(TStockHistory.FAmountChangeInt,0)end) as '保育日均存栏', \n" +
|
|
|
+ " sum(case when (TStockHistory.FPigStatee in(1,22,21,16) or TStockHistory.FPigStatee is null) and TStockHistory.FPigClassE in (1,2,3) then isnull(TStockHistory.FAmountChangeInt,0)end) as '育肥日均存栏', \n" +
|
|
|
+ " sum(case when TStockHistory.FPigStatee in(11) and TStockHistory.FPigClassE=3 then isnull(TStockHistory.FAmountChangeInt,0)end) as '后备商品猪日均存栏' \n" +
|
|
|
+ " ,qj.time as billdate\n" +
|
|
|
+ " from TStockHistory \n" +
|
|
|
+ " left join ( select CONVERT(varchar(10), CONVERT(datetime, ?1)+d,120) as [time] \n" +
|
|
|
+ " from\n" +
|
|
|
+ " (\n" +
|
|
|
+ " select top (datediff(day, ?1, ?2)+1) row_number() \n" +
|
|
|
+ " over(order by getdate())-1 d from sys.objects\n" +
|
|
|
+ " ) as a) qj on 1=1\n" +
|
|
|
+ " where TStockHistory.FdateChange<=qj.time\n" +
|
|
|
+ " and datediff(dd, ?1, TStockHistory.FdateChange)>=0 \n" +
|
|
|
+ " and TStockHistory.FPigClassE in(1,2,3) \n" +
|
|
|
+ " group by TStockHistory.hogpenDID,qj.time ) tmp_tblcl\n" +
|
|
|
+ " group by tmp_tblcl.ZCID)clbd on clqc.ZCID =clbd.ZCID\n" +
|
|
|
+ "left join ( select temp.PigHouseID,sum(isnull(temp.育肥,0)) as 育肥,sum(isnull(temp.教槽,0)) as 教槽,sum(isnull(temp.保育,0)) as 保育,\n" +
|
|
|
+ " sum(isnull(temp.基础母,0)) as 基础母,sum(isnull(temp.基础公,0)) as 基础公,sum(isnull(temp.后备公,0))as 后备公\n" +
|
|
|
+ " ,sum(isnull(temp.后备母,0))as 后备母,sum(isnull(temp.后备,0)) as 后备商\n" +
|
|
|
+ " from\n" +
|
|
|
+ " (select TPigDie.PigHouseID ,\n" +
|
|
|
+ " case when TPigDieChild.FPigState in(1,21,22,16) and TPigDieChild.FPigSex IN(1,2,3) then sum(TPigDieChild.FweakpigdieCount)+sum(TPigDieChild.Fpigdiecount) end '育肥' ,\n" +
|
|
|
+ " case when TPigDieChild.FPigState in(15) and TPigDieChild.FPigSex IN(1,2,3) then sum(TPigDieChild.FweakpigdieCount)+sum(TPigDieChild.Fpigdiecount) end'教槽' ,\n" +
|
|
|
+ " case when TPigDieChild.FPigState in(14) and TPigDieChild.FPigSex IN(1,2,3) then sum(TPigDieChild.FweakpigdieCount)+sum(TPigDieChild.Fpigdiecount)end '保育' ,\n" +
|
|
|
+ " case when TPigDieChild.FPigState in(11) and TPigDieChild.FPigSex=3 then sum(TPigDieChild.FweakpigdieCount)+sum(TPigDieChild.Fpigdiecount) end '后备'\n" +
|
|
|
+ " , case when TPigDieChild.FPigState in(3,7,12,13,5,6) and TPigDieChild.FPigSex=2 \n" +
|
|
|
+ " then count(TPigDieChild.FID) end'基础母' \n" +
|
|
|
+ " , case when TPigDieChild.FPigState in(2) and TPigDieChild.FPigSex=1\n" +
|
|
|
+ " then count(TPigDieChild.FID) end'基础公' \n" +
|
|
|
+ " , case when TPigDieChild.FPigState =11 and TPigDieChild.FPigSex=1\n" +
|
|
|
+ " then count(TPigDieChild.FID) end'后备公' \n" +
|
|
|
+ " , case when TPigDieChild.FPIGSTATE=11 and TPigDieChild.FPigSex=2\n" +
|
|
|
+ " then count(TPigDieChild.FID) 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 ( datediff(dd, ?1, TPigDie.FDieDate)>=0 and datediff(dd, ?2,TPigDie.FDieDate) <=0) \n" +
|
|
|
+ " group by TPigDieChild.FPigState,TPigDieChild.FPigSex ,TPigDie.PigHouseID )temp\n" +
|
|
|
+ " group by temp.PigHouseID\n" +
|
|
|
+ " ) die on die.PigHouseID=clqc.ZCID \n" +
|
|
|
+ " \n" +
|
|
|
+ "left join ( select temp.PigHouseID,sum(isnull(temp.淘汰商,0)) as 淘汰商,sum(isnull(temp.淘汰母,0)) as 淘汰母,sum(isnull(temp.淘汰公,0)) as 淘汰公\n" +
|
|
|
+ ",sum(isnull(temp.淘汰后备,0)) as 淘汰后备,sum(isnull(temp.育肥,0)) as 育肥,sum(isnull(temp.教槽,0)) as 教槽,sum(isnull(temp.保育,0)) as 保育 \n" +
|
|
|
+ " from\n" +
|
|
|
+ " (select TPigLose.PigHouseID ,\n" +
|
|
|
+ " case when TPigLoseChild.FSEX=3 and FPIGSTATE!=11\n" +
|
|
|
+ " then sum(TPigLoseChild.FpigLoseCount)+sum(TPigLoseChild.FweakPigLoseCount) end '淘汰商'\n" +
|
|
|
+ " , case when TPigLoseChild.FSEX=2 and FPIGSTATE!=11 then count(TPigLoseChild.FID) end '淘汰母' \n" +
|
|
|
+ " , case when TPigLoseChild.FSEX=1 and FPIGSTATE!=11 then count(TPigLoseChild.FID) end '淘汰公' \n" +
|
|
|
+ " , case when TPigLoseChild.FSEX in(1,2,3) and FPIGSTATE=11 then count(TPigLoseChild.FID) end '淘汰后备' \n" +
|
|
|
+ " ,case when TPigLoseChild.FPigState in(1,21,22,16) and TPigLoseChild.FSEX IN(1,2,3) then \n" +
|
|
|
+ " sum(TPigLoseChild.FpigLoseCount)+sum(TPigLoseChild.FweakPigLoseCount) end '育肥' ,\n" +
|
|
|
+ " case when TPigLoseChild.FPigState in(15) and TPigLoseChild.FSEX IN(1,2,3) then sum(TPigLoseChild.FpigLoseCount)+sum(TPigLoseChild.FweakPigLoseCount) end'教槽' ,\n" +
|
|
|
+ " case when TPigLoseChild.FPigState in(14) 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 (datediff(dd, ?1, TPigLose.Fpiglosedate )>=0 and datediff(dd, ?2,TPigLose.Fpiglosedate ) <=0) \n" +
|
|
|
+ " group by TPigLoseChild.FPigState,TPigLoseChild.FSEX ,TPigLose.PigHouseID )temp\n" +
|
|
|
+ " group by temp.PigHouseID\n" +
|
|
|
+ " ) lose on lose.PigHouseID=clqc.ZCID \n" +
|
|
|
+ "left join \n" +
|
|
|
+ " (select TBorn.HOGPENDID as 'ZCID',count(TBornNewStru.FID) as '出生合格仔',SUM(TBornNewStru.FWEIGHTINT) as '出生重'\n" +
|
|
|
+ " from TBorn left join TBornNewStru on TBornNewStru.FBornMainStruID = TBorn.FID \n" +
|
|
|
+ " \n" +
|
|
|
+ " where TBorn.FLOGSTATEE in (3,4,6) \n" +
|
|
|
+ " and datediff(dd, ?1,TBorn.FDATEBORN)>=0 and datediff(dd, ?2,TBorn.FDATEBORN) <=0\n" +
|
|
|
+ " group by TBorn.HOGPENDID\n" +
|
|
|
+ " )cszrjcl on cszrjcl.ZCID=clqc.ZCID \n" +
|
|
|
+ " \n" +
|
|
|
+ " left join (select zz.ZCID as 'ZCID',SUM(zz.商品猪引种保育头数) as '商品猪引种保育头数',SUM(zz.商品猪引种育肥头数) as '商品猪引种育肥头数'\n" +
|
|
|
+ " ,SUM(zz.保育引种重量) as '保育引种重量',SUM(zz.育肥引种重量) as '育肥引种重量',SUM(zz.后备引种重量) as '后备引种重量',SUM(zz.brbyyf引种重量) as 'brbyyf引种重量' from\n" +
|
|
|
+ "(select TBoarStock.STOCKORGID as 'ZCID',\n" +
|
|
|
+ " case when TBoarStockChild.FPIGSTATE = 14 then SUM(FNORMALAMOUNT)+SUM (FWEAKAMOUNT) end as '商品猪引种保育头数',\n" +
|
|
|
+ " case when TBoarStockChild.FPIGSTATE = 1 then SUM(FNORMALAMOUNT)+SUM (FWEAKAMOUNT) end as '商品猪引种育肥头数',\n" +
|
|
|
+ " case when TBoarStockChild.FPIGSTATE = 14 then SUM(FALLWEIGHT) end AS '保育引种重量', \n" +
|
|
|
+ " case when TBoarStockChild.FPIGSTATE = 1 then SUM(FALLWEIGHT) end AS '育肥引种重量',\n" +
|
|
|
+ " case when TBoarStockChild.FPIGSTATE = 11 then SUM(FALLWEIGHT) end AS '后备引种重量',\n" +
|
|
|
+ " case when TBoarStockChild.FPIGSTATE IN(15,14,1) then SUM(FALLWEIGHT) end AS 'brbyyf引种重量'\n" +
|
|
|
+ " from TBoarStockChild left join TBoarStock on TBoarStockChild.FBoarStockMainStruID = TBoarStock.FID \n" +
|
|
|
+ " where TBoarStock.FBILLSTATE in (3,4,6,12) and TBoarStock.FINTRODUCTIONCLASS =3 \n" +
|
|
|
+ " and datediff(dd, ?1, TBoarStock.FINHOGPENDATE)>=0 and datediff(dd, ?2,TBoarStock.FINHOGPENDATE) <=0\n" +
|
|
|
+ " group by TBoarStock.STOCKORGID,TBoarStockChild.FPIGSTATE) zz group by zz.ZCID\n" +
|
|
|
+ " )spzyz on spzyz.ZCID = clqc.ZCID \n" +
|
|
|
+ " left join (select TWeaningPiglets.hogpenDID as 'ZCID', \n" +
|
|
|
+ " sum(TWeaningPigletsNewStru.FweightSum)*1.0/(case sum(TWeaningPigletsNewStru.FAmountHead) when 0 then null else sum(TWeaningPigletsNewStru.FAmountHead) end) as 'ZZPJDNTZ', \n" +
|
|
|
+ " sum(TWeaningPigletsNewStru.FAmountHead) as '仔猪断奶头数',sum(TWeaningPigletsNewStru.FweightSum) as '断奶总重'\n" +
|
|
|
+ " from TWeaningPiglets left join TWeaningPigletsNewStru on TWeaningPigletsNewStru.FWeaningPigletsMainStruID=TWeaningPiglets.FID \n" +
|
|
|
+ " \n" +
|
|
|
+ " where TWeaningPiglets.FlogStateE in(3,4,6,12) and datediff(dd, ?1, TWeaningPiglets.FdateWeaning)>=0 and datediff(dd, ?2,TWeaningPiglets.FdateWeaning) <=0 \n" +
|
|
|
+ " group by TWeaningPiglets.hogpenDID)tmp_tblzz on tmp_tblzz.ZCID=clqc.ZCID \n" +
|
|
|
+ " left join (select tmp_tblzs.ZCID as 'ZCID', sum(tmp_tblzs.ZYFPJTZ*tmp_tblzs.ZYFZTS)/(case sum(tmp_tblzs.ZYFZTS) when 0 then null else sum(tmp_tblzs.ZYFZTS) end) as 'ZYFPJTZ', \n" +
|
|
|
+ " \n" +
|
|
|
+ " SUM(tmp_tblzs.ZYFZTS) as 'ZYFZTS' ,sum(tmp_tblzs.ZYFPJTZ*tmp_tblzs.ZYFZTS) as '保育转育肥重量'\n" +
|
|
|
+ " from(select TPiginout.inpighogpenID as 'ZCID', TPiginoutChild.Favgweight as 'ZYFPJTZ', TPiginoutChild.FToHomeSfew as 'ZYFZTS'\n" +
|
|
|
+ " \n" +
|
|
|
+ " from TPiginout left join TPiginoutChild on TPiginoutChild.FPiginoutMainStruID=TPiginout.FID\n" +
|
|
|
+ " \n" +
|
|
|
+ " where TPiginout.FBillFormState in(3,4,6,12) and TPiginoutChild.FPigCalss=3 and TPiginout.FpigpPhase=1 and datediff(dd, ?1, TPiginout.Finouthousedata)>=0 and datediff(dd, ?2,TPiginout.Finouthousedata) <=0 \n" +
|
|
|
+ " )tmp_tblzs group by tmp_tblzs.ZCID )tmp_tblbyz on tmp_tblbyz.ZCID=clqc.ZCID \n" +
|
|
|
+ " \n" +
|
|
|
+ " left join (select TDelivery.HogpendID as 'ZCID',count(TNewStru7743.FID) as 'CZWS',avg(TNewStru7743.FamountLiveInt*1.0) as 'PJWCHZ' \n" +
|
|
|
+ " ,avg(TNewStru7743.FAMOUNTKITTENINT*1.0) as 'PJWCZZ' ,avg(TNewStru7743.FAMOUNTRIGHTINT*1.0) as 'PJWCZC' ,sum(TNewStru7743.FAMOUNTRIGHTINT*1.0+TNewStru7743.FAMOUNTPUNINESSINT) as 'WCHZ' \n" +
|
|
|
+ " ,sum(TNewStru7743.FAMOUNTKITTENINT*1.0) as 'WCZZ' \n" +
|
|
|
+ " from TDelivery left join TNewStru7743 on TNewStru7743.FDeliveryMainStruID=TDelivery.FID \n" +
|
|
|
+ " where TDelivery.FLogStatee in(3,4,6) and datediff(dd, ?1, TDelivery.FDateDelivery)>=0 and datediff(dd, ?2,TDelivery.FDateDelivery) <=0 \n" +
|
|
|
+ " group by TDelivery.HogpendID )tmp_tblfm on tmp_tblfm.ZCID=clqc.ZCID \n" +
|
|
|
+ " left join (select TWeaning.HogpendID as 'ZCID', count(TWeaningNewStru.FID)'DNMZS',sum(TWeaningNewStru.FAmountWeanInt)'DNZZS', \n" +
|
|
|
+ " sum(TWeaningNewStru.FweightInt)*1.0/count(TWeaningNewStru.FID) as 'PJDNWZ', \n" +
|
|
|
+ " sum(TWeaningNewStru.FAmountWeanInt)*1.0/count(TWeaningNewStru.FID) as 'PJWDNTS'\n" +
|
|
|
+ " from TWeaning left join TWeaningNewStru on TWeaningNewStru.FWeaningMainStruID=TWeaning.FID\n" +
|
|
|
+ " where TWeaning.FLogStatee in(3,4,6) and datediff(dd, ?1, TWeaning.FdateWeaning)>=0 and datediff(dd, ?2,TWeaning.FdateWeaning) <=0 \n" +
|
|
|
+ " group by TWeaning.HogpendID )tmp_tbldn on tmp_tbldn.ZCID=clqc.ZCID \n" +
|
|
|
+ " left join \n" +
|
|
|
+ "(select tmp_tbl.HOGPENDID, CAST(count(tmp_tbl.发情ID)*1.0/case(count(tmp_tbl.断奶ID) -COUNT(tmp_tbl.stid)) when 0 then null else (count(tmp_tbl.断奶ID) -COUNT(tmp_tbl.stid)) end as dec(8,5))as 'DPL'\n" +
|
|
|
+ " from (select TWeaningNewStru.FBreedD as '品种',TWeaning.HOGPENDID, \n" +
|
|
|
+ " subString(convert(varchar(7),TWeaning.FDateWeaning,120),1,4)+'年'+subString(convert(varchar(7),\n" +
|
|
|
+ " TWeaning.FDateWeaning,120),6,2)+'月份' as '月', TWeaningNewStru.FID as '断奶ID', tmp_tblfq.SowStrID as '发情ID' ,\n" +
|
|
|
+ "st.NUMBERID as stid \n" +
|
|
|
+ " from TWeaning left join TWeaningNewStru on TWeaningNewStru.FWeaningMainStruID=TWeaning.FID \n" +
|
|
|
+ " left join ( select SowStrID,FParityInt,FDATEBREED from TBreeding left join TNewStru8094 \n" +
|
|
|
+ " on TNewStru8094.FBreedingMainStruID=TBreeding.FID where TBreeding.FLogStatee in(3,4,6)) tmp_tblfq \n" +
|
|
|
+ " on tmp_tblfq.SowStrID=TWeaningNewStru.SowStrID and tmp_tblfq.FParityInt=TWeaningNewStru.FParityInt \n" +
|
|
|
+ " and tmp_tblfq.FDATEBREED<=TWeaning.FDateWeaning+7 and tmp_tblfq.FDATEBREED>=TWeaning.FDateWeaning\n" +
|
|
|
+ "left join(select NUMBERID,FDIEDATE as stdate from TPigDie \n" +
|
|
|
+ " left join TPigDieChild on TPigDieChild.FPigDieMainStruID=TPigDie.FID where TPigDie.FBillState in(3,4,6)\n" +
|
|
|
+ " and TPigDieChild.FPIGSTATE!=5\n" +
|
|
|
+ " union all\n" +
|
|
|
+ " select NUMBERID,FPIGLOSEDATE as stdate from TPigLose \n" +
|
|
|
+ " left join TPigLoseChild on TPigLoseChild.FPigLoseMainStruID=TPigLose.FID \n" +
|
|
|
+ " and TPigLoseChild.FPIGSTATE!=5\n" +
|
|
|
+ " where TPigLose.FBillState in(3,4,6) \n" +
|
|
|
+ " ) st \n" +
|
|
|
+ " on st.NUMBERID=TWeaningNewStru.SowStrID \n" +
|
|
|
+ " and st.stdate<=TWeaning.FDateWeaning+7 and st.stdate>=TWeaning.FDateWeaning \n" +
|
|
|
+ " where TWeaning.FLogStatee in(3,4,6)\n" +
|
|
|
+ " and datediff(dd, ?1, TWeaning.FdateWeaning)>=-7 and datediff(dd, ?2,TWeaning.FdateWeaning) <=-7 \n" +
|
|
|
+ " ) tmp_tbl \n" +
|
|
|
+ " group by tmp_tbl.HOGPENDID)dn3 on dn3.HogpendID=clqc.ZCID \n" +
|
|
|
+ " left join (select CAST(365*1.0/avg(tjj) as dec(7,4)) as 'NLYWS' ,ZCID\n" +
|
|
|
+ " from\n" +
|
|
|
+ " (SELECT \n" +
|
|
|
+ " case when isnull(TNewStru7743.FtyreDistance,0)!=0 then TNewStru7743.FtyreDistance else DATEDIFF(dd,TPigArchives.FDATEOFBIRTH,TDelivery.FDATEDELIVERY)-250 end as 'tjj' \n" +
|
|
|
+ " ,TDelivery.HOGPENDID as ZCID\n" +
|
|
|
+ " FROM TDelivery \n" +
|
|
|
+ " LEFT JOIN TNewStru7743 on TNewStru7743.FDeliveryMainStruID = TDelivery.FID \n" +
|
|
|
+ " left join TPigArchives on TNewStru7743.SOWSTRID = TPigArchives.FID\n" +
|
|
|
+ " WHERE TDelivery.FlogStateE in(3,4,6)\n" +
|
|
|
+ " And ( datediff(dd, ?1,TDelivery.FDATEDELIVERY)>=0 or ?1 is null) \n" +
|
|
|
+ " And (datediff(dd, ?2,TDelivery.FDATEDELIVERY)<=0 or ?2 is null) \n" +
|
|
|
+ " ) tmp_tbl \n" +
|
|
|
+ " group by tmp_tbl.ZCID\n" +
|
|
|
+ " having avg(tjj)>0)NCWS on clqc.ZCID=NCWS.ZCID\n" +
|
|
|
+ " left join TOrganizeCell on clqc.ZCID=TOrganizeCell.FID where FNAME is not null")
|
|
|
+ List<Object[]> getManyFarmProduce(Date startDate, Date endDate);
|
|
|
}
|