CoopBatchReportDetailMapper.xml 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5. <mapper namespace="cn.vber.breeding.mapper.CoopBatchReportDetailMapper">
  6. <resultMap id="statisticResultVo" type="cn.vber.breeding.domain.vo.statistic.CoopBatchChickenStatisticResultVo">
  7. <id property="coopId" column="coop_id"/>
  8. <result property="batchNum" column="batch_num"/>
  9. <result property="chickenCount" column="chicken_count"/>
  10. </resultMap>
  11. <resultMap id="statisticEggResultVo" type="cn.vber.breeding.domain.vo.statistic.CoopBatchEggStatisticResultVo">
  12. <id property="coopId" column="coop_id"/>
  13. <result property="batchNum" column="batch_num"/>
  14. <result property="eggCount" column="egg_count"/>
  15. <result property="eggType" column="egg_type"/>
  16. </resultMap>
  17. <resultMap id="statisticDayResultVo" type="cn.vber.breeding.domain.vo.statistic.ChickenStatisticDayResultVo">
  18. <id property="coopId" column="coop_id"/>
  19. <result property="batchNum" column="batch_num"/>
  20. <result property="reportDate" column="report_date"/>
  21. <result property="reportCycle" column="report_cycle"/>
  22. </resultMap>
  23. <resultMap id="CoopBatchReportDetailView" type="cn.vber.breeding.domain.vo.report.CoopBatchReportDetailView">
  24. <result property="reportId" column="report_id"/>
  25. <result property="coopId" column="coop_id"/>
  26. <result property="batchNum" column="batch_num"/>
  27. <result property="lastSave0" column="last_save0"/>
  28. <result property="lastSave1" column="last_save1"/>
  29. <result property="qualifiedEgg" column="qualified_egg"/>
  30. <result property="deformedEgg" column="deformed_egg"/>
  31. <result property="breakEgg" column="break_egg"/>
  32. <result property="eggProductionRate" column="egg_production_rate"/>
  33. <result property="eggPassRate" column="egg_pass_rate"/>
  34. <result property="cullRate" column="cull_rate"/>
  35. <result property="lifeRate" column="life_rate"/>
  36. <result property="reportDate" column="report_date"/>
  37. <result property="reportCycle" column="report_cycle"/>
  38. <result property="batchName" column="batch_name"/>
  39. <result property="hatchDate" column="hatch_date"/>
  40. <result property="coopNum" column="coop_num"/>
  41. <result property="coopName" column="coop_name"/>
  42. <result property="coopType" column="coop_type"/>
  43. </resultMap>
  44. <select id="selectCullCount"
  45. resultMap="statisticResultVo">
  46. SELECT
  47. coop.id AS coop_id,
  48. fc.batch_num,
  49. fc.gender,
  50. count(fc.id) as chicken_count
  51. FROM
  52. f_chicken AS fc
  53. LEFT JOIN
  54. f_chicken_cage AS fcc
  55. ON
  56. fc.cage_id = fcc.id
  57. LEFT JOIN
  58. f_chicken_coop AS coop
  59. ON
  60. fcc.chicken_coop_id = coop.id
  61. WHERE
  62. fc.`status` = 1 and fc.cull_time between #{startDate} and #{endDate} and coop.coop_type = #{coopType}
  63. GROUP BY
  64. fc.batch_num,
  65. coop.id,
  66. fc.gender
  67. </select>
  68. <select id="selectChickenCount"
  69. resultMap="statisticResultVo">
  70. SELECT
  71. coop.id AS coop_id,
  72. fc.batch_num,
  73. fc.gender,
  74. count(fc.id) as chicken_count
  75. FROM
  76. f_chicken AS fc
  77. LEFT JOIN
  78. f_chicken_cage AS fcc
  79. ON
  80. fc.cage_id = fcc.id
  81. LEFT JOIN
  82. f_chicken_coop AS coop
  83. ON
  84. fcc.chicken_coop_id = coop.id
  85. WHERE
  86. fc.`status` = 0 and (fc.cage_id != NULL or fc.cage_id !='') and coop.coop_type = #{coopType}
  87. GROUP BY
  88. fc.batch_num,
  89. coop.id,
  90. fc.gender
  91. </select>
  92. <select id="selectChickenCountDay"
  93. resultMap="statisticDayResultVo">
  94. SELECT
  95. fcbre.coop_id,
  96. fcbre.batch_num,
  97. fcbre.save_0 as save0,
  98. fcbre.save_1 as save1,
  99. fcbre.chicken_0 as chicken0,
  100. fcbre.chicken_1 as chicken1,
  101. fcbre.report_date,
  102. fcbre.report_cycle
  103. FROM
  104. f_coop_batch_report_detail AS fcbre
  105. INNER JOIN
  106. f_chicken_coop AS coop
  107. ON
  108. fcbre.coop_id = coop.id
  109. WHERE
  110. fcbre.del_flag = 0 AND
  111. fcbre.report_cycle = 'D' AND
  112. fcbre.report_date BETWEEN #{startDate} AND #{endDate} and coop.coop_type = #{coopType}
  113. </select>
  114. <select id="selectChickenIn"
  115. resultMap="statisticResultVo">
  116. SELECT
  117. fc.batch_num AS batch_num,
  118. fc.gender AS gender,
  119. count(fcc.chicken_id) AS chicken_count,
  120. coop.id as coop_id
  121. FROM
  122. (SELECT f_cage_change.target_cage_id AS target_cage_id, f_cage_change.chicken_id AS chicken_id
  123. FROM f_cage_change WHERE f_cage_change.bind_time BETWEEN #{startDate} and #{endDate}
  124. and f_cage_change.status = 1 and f_cage_change.cross_coop = 1) as fcc
  125. LEFT JOIN f_chicken AS fc ON fcc.chicken_id = fc.id
  126. LEFT JOIN f_chicken_cage AS fca ON fcc.target_cage_id = fca.id
  127. LEFT JOIN f_chicken_coop AS coop ON fca.chicken_coop_id = coop.id
  128. where coop.coop_type = #{coopType}
  129. GROUP BY
  130. fc.batch_num,
  131. coop.id,
  132. fc.gender
  133. </select>
  134. <select id="selectChickenOut"
  135. resultMap="statisticResultVo">
  136. SELECT
  137. fc.batch_num AS batch_num,
  138. fc.gender AS gender,
  139. count(fcc.chicken_id) AS chicken_count,
  140. coop.id as coop_id
  141. FROM
  142. (SELECT f_cage_change.source_cage_id AS source_cage_id, f_cage_change.chicken_id AS chicken_id
  143. FROM f_cage_change WHERE f_cage_change.bind_time BETWEEN #{startDate} and #{endDate}
  144. and f_cage_change.status = 1 and f_cage_change.cross_coop=1
  145. and (source_cage_id != NULL or source_cage_id>0)) as fcc
  146. LEFT JOIN f_chicken AS fc ON fcc.chicken_id = fc.id
  147. LEFT JOIN f_chicken_cage AS fca ON fcc.source_cage_id = fca.id
  148. LEFT JOIN f_chicken_coop AS coop ON fca.chicken_coop_id = coop.id
  149. where coop.coop_type = #{coopType}
  150. GROUP BY
  151. fc.batch_num,
  152. coop.id,
  153. fc.gender
  154. </select>
  155. <select id="selectStatisticEgg" resultMap="statisticEggResultVo">
  156. SELECT
  157. cage.chicken_coop_id as coop_id,
  158. fc.batch_num,
  159. egg.egg_type,
  160. SUM(egg.egg_count) as egg_count
  161. FROM
  162. f_breeding_egg AS egg
  163. INNER JOIN
  164. f_chicken_cage AS cage
  165. ON
  166. egg.cage_id = cage.id
  167. INNER JOIN
  168. f_chicken AS fc
  169. ON
  170. egg.female_chicken_id = fc.id
  171. INNER JOIN
  172. f_chicken_coop AS coop
  173. ON
  174. cage.chicken_coop_id = coop.id
  175. WHERE
  176. egg.del_flag = '0' AND
  177. egg.lay_date BETWEEN #{startDate} AND #{endDate}
  178. and coop.coop_type = #{coopType}
  179. GROUP BY
  180. fc.batch_num,
  181. cage.chicken_coop_id,
  182. egg.egg_type
  183. </select>
  184. <select id="selectCoopBatchReportDetail" resultMap="CoopBatchReportDetailView">
  185. SELECT
  186. detail.id,
  187. detail.report_id,
  188. detail.coop_id,
  189. detail.batch_num,
  190. detail.last_save0,
  191. detail.last_save1,
  192. detail.save0,
  193. detail.save1,
  194. detail.cull0,
  195. detail.cull1,
  196. detail.in0,
  197. detail.in1,
  198. detail.out0,
  199. detail.out1,
  200. detail.qualified_egg,
  201. detail.deformed_egg,
  202. detail.break_egg,
  203. detail.egg_production_rate,
  204. detail.egg_pass_rate,
  205. detail.chicken0,
  206. detail.chicken1,
  207. detail.cull_rate,
  208. detail.life_rate,
  209. detail.report_date,
  210. detail.report_cycle,
  211. batch.batch_name,
  212. batch.hatch_date,
  213. coop.coop_num,
  214. coop.coop_name,
  215. coop.coop_type
  216. FROM
  217. f_coop_batch_report_detail AS detail
  218. LEFT JOIN
  219. f_batch AS batch
  220. ON
  221. detail.batch_num = batch.batch_num
  222. LEFT JOIN
  223. f_chicken_coop AS coop
  224. ON
  225. detail.coop_id = coop.id
  226. WHERE
  227. detail.del_flag = '0'
  228. AND detail.report_id = #{report_id}
  229. <if test="coop_type != null">
  230. and coop.coop_type = #{coop_type}
  231. </if>
  232. </select>
  233. </mapper>