SlaughterBatchMapper.xml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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="com.ruoyi.app.mapper.SlaughterBatchMapper">
  6. <resultMap type="SlaughterBatch" id="SlaughterBatchResult">
  7. <result property="id" column="id" />
  8. <result property="slaughterTime" column="slaughter_time" />
  9. <result property="distributeBatchId" column="distribute_batch_id" />
  10. <result property="entranceBatchId" column="entrance_batch_id" />
  11. <result property="salePlace" column="sale_place" />
  12. <result property="meatCert" column="meat_cert" />
  13. <result property="animalCert" column="animal_cert" />
  14. <result property="createTime" column="create_time" />
  15. <result property="createBy" column="create_by" />
  16. <result property="updateTime" column="update_time" />
  17. <result property="updateBy" column="update_by" />
  18. <result property="delFlag" column="del_flag" />
  19. </resultMap>
  20. <resultMap id="slaughterBatchDTOResultMap" type="com.ruoyi.app.DTO.SlaughterBatchDTO">
  21. <!-- 主表 -->
  22. <id property="id" column="id"/>
  23. <result property="slaughterTime" column="slaughter_time"/>
  24. <result property="salePlace" column="sale_place"/>
  25. <result property="meatCert" column="meat_cert"/>
  26. <result property="animalCert" column="animal_cert"/>
  27. <!-- 分销批次 -->
  28. <result property="slaughterCode" column="slaughter_code"/>
  29. <result property="amount" column="amount"/>
  30. <result property="beforeWeight" column="before_weight"/>
  31. <!--肉商 -->
  32. <result property="purchaserName" column="purchaser_name"/>
  33. <!-- 供应商 -->
  34. <result property="supplierName" column="supplier_name"/>
  35. <!-- 入场批次 -->
  36. <result property="variety" column="variety"/>
  37. <result property="animalCertNo" column="animal_cert_no"/>
  38. <!-- 重量统计 -->
  39. <result property="sideWeight" column="side_weight"/>
  40. <result property="headWeight" column="head_weight"/>
  41. <result property="redWeight" column="red_weight"/>
  42. <result property="whiteWeight" column="white_weight"/>
  43. </resultMap>
  44. <resultMap id="SlaughterReportResultMap" type="com.ruoyi.app.DTO.SlaughterReportDTO">
  45. <!-- 主表 -->
  46. <id property="id" column="id"/>
  47. <result property="slaughterTime" column="slaughter_time"/>
  48. <result property="salePlace" column="sale_place"/>
  49. <result property="meatCert" column="meat_cert"/>
  50. <result property="animalCert" column="animal_cert"/>
  51. <!-- 分销批次 -->
  52. <result property="slaughterCode" column="slaughter_code"/>
  53. <result property="amount" column="amount"/>
  54. <result property="beforeWeight" column="before_weight"/>
  55. <!--肉商 -->
  56. <result property="purchaserName" column="purchaser_name"/>
  57. <!-- 供应商 -->
  58. <result property="supplierName" column="supplier_name"/>
  59. <!-- 入场批次 -->
  60. <result property="variety" column="variety"/>
  61. <result property="animalCertNo" column="animal_cert_no"/>
  62. <!-- 重量统计 -->
  63. <result property="sideWeight" column="side_weight"/>
  64. <result property="headWeight" column="head_weight"/>
  65. <result property="redWeight" column="red_weight"/>
  66. <result property="whiteWeight" column="white_weight"/>
  67. </resultMap>
  68. <resultMap type="com.ruoyi.app.DTO.PorkProduceDTO" id="PorkProduceResult">
  69. <result property="productName" column="product_name" />
  70. <result property="produceTime" column="produce_time" />
  71. <result property="hookNo" column="hook_no" />
  72. <result property="slaughterCode" column="slaughter_code" />
  73. <result property="finalWeight" column="final_weight" />
  74. </resultMap>
  75. <sql id="selectSlaughterBatchVo">
  76. select id, slaughter_time, distribute_batch_id, entrance_batch_id, sale_place, meat_cert, animal_cert, create_time, create_by, update_time, update_by, del_flag from slaughter_batch
  77. </sql>
  78. <select id="selectSlaughterBatchList" parameterType="com.ruoyi.app.domain.request.ReqSlaughterBatch" resultMap="slaughterBatchDTOResultMap">
  79. select a.id,a.slaughter_time,a.sale_place,a.meat_cert,a.animal_cert,
  80. b.slaughter_code,b.amount,b.weight as before_weight,
  81. c.purchaser_name,
  82. d.supplier_name,
  83. e.variety,e.animal_cert_no,
  84. (select sum(final_weight) from pork_side_produce where distribute_batch_id = a.distribute_batch_id and del_flag = '0') as side_weight,
  85. (select sum(final_weight) from pork_other_produce where distribute_batch_id = a.distribute_batch_id and product_name='猪头' and del_flag = '0') as head_weight,
  86. (select sum(final_weight) from pork_other_produce where distribute_batch_id = a.distribute_batch_id and product_name='红脏' and del_flag = '0') as red_weight,
  87. (select sum(final_weight) from pork_other_produce where distribute_batch_id = a.distribute_batch_id and product_name='白脏' and del_flag = '0') as white_weight
  88. from slaughter_batch as a
  89. left join distribute_batch as b on b.id = a.distribute_batch_id and b.del_flag = '0'
  90. left join purchaser as c on c.id = b.purchaser_id and c.del_flag = '0'
  91. left join supplier as d on d.id = b.supplier_id and d.del_flag = '0'
  92. left join entrance_batch as e on e.id = a.entrance_batch_id and e.del_flag = '0'
  93. <where>
  94. a.del_flag = '0'
  95. <if test="slaughterTime != null "> and DATE(a.slaughter_time) = DATE(#{slaughterTime})</if>
  96. <if test="animalCertNo != null and animalCertNo != ''"> and e.animal_cert_no like concat('%', #{animalCertNo}, '%')</if>
  97. <if test="slaughterCode != null and slaughterCode != ''"> and b.slaughter_code like concat('%', #{slaughterCode}, '%')</if>
  98. </where>
  99. order by a.slaughter_time desc
  100. </select>
  101. <select id="selectSlaughterBatchById" parameterType="Long" resultMap="slaughterBatchDTOResultMap">
  102. select a.id,a.slaughter_time,a.sale_place,a.meat_cert,animal_cert,
  103. b.slaughter_code,b.amount,b.weight as before_weight,
  104. c.purchaser_name,
  105. d.supplier_name,
  106. e.variety,e.animal_cert_no,
  107. (select sum(final_weight) from pork_side_produce where distribute_batch_id = a.distribute_batch_id and del_flag = '0') as side_weight,
  108. (select sum(final_weight) from pork_other_produce where distribute_batch_id = a.distribute_batch_id and product_name='猪头' and del_flag = '0') as head_weight,
  109. (select sum(final_weight) from pork_other_produce where distribute_batch_id = a.distribute_batch_id and product_name='红脏' and del_flag = '0') as red_weight,
  110. (select sum(final_weight) from pork_other_produce where distribute_batch_id = a.distribute_batch_id and product_name='白脏' and del_flag = '0') as white_weight
  111. from slaughter_batch as a
  112. left join distribute_batch as b on b.id = a.distribute_batch_id and b.del_flag = '0'
  113. left join purchaser as c on c.id = b.purchaser_id and c.del_flag = '0'
  114. left join supplier as d on d.id = b.supplier_id and d.del_flag = '0'
  115. left join entrance_batch as e on e.id = a.entrance_batch_id and e.del_flag = '0'
  116. where a.id = #{id} and a.del_flag = '0'
  117. </select>
  118. <insert id="insertSlaughterBatch" parameterType="SlaughterBatch" useGeneratedKeys="true" keyProperty="id">
  119. insert into slaughter_batch
  120. <trim prefix="(" suffix=")" suffixOverrides=",">
  121. <if test="slaughterTime != null">slaughter_time,</if>
  122. <if test="distributeBatchId != null">distribute_batch_id,</if>
  123. <if test="entranceBatchId != null">entrance_batch_id,</if>
  124. <if test="salePlace != null">sale_place,</if>
  125. <if test="meatCert != null">meat_cert,</if>
  126. <if test="animalCert != null">animal_cert,</if>
  127. <if test="createTime != null">create_time,</if>
  128. <if test="createBy != null">create_by,</if>
  129. del_flag
  130. </trim>
  131. <trim prefix="values (" suffix=")" suffixOverrides=",">
  132. <if test="slaughterTime != null">#{slaughterTime},</if>
  133. <if test="distributeBatchId != null">#{distributeBatchId},</if>
  134. <if test="entranceBatchId != null">#{entranceBatchId},</if>
  135. <if test="salePlace != null">#{salePlace},</if>
  136. <if test="meatCert != null">#{meatCert},</if>
  137. <if test="animalCert != null">#{animalCert},</if>
  138. <if test="createTime != null">#{createTime},</if>
  139. <if test="createBy != null">#{createBy},</if>
  140. '0'
  141. </trim>
  142. </insert>
  143. <update id="updateSlaughterBatch" parameterType="SlaughterBatch">
  144. update slaughter_batch
  145. <trim prefix="SET" suffixOverrides=",">
  146. <if test="slaughterTime != null">slaughter_time = #{slaughterTime},</if>
  147. <if test="distributeBatchId != null">distribute_batch_id = #{distributeBatchId},</if>
  148. <if test="entranceBatchId != null">entrance_batch_id = #{entranceBatchId},</if>
  149. <if test="salePlace != null">sale_place = #{salePlace},</if>
  150. <if test="meatCert != null">meat_cert = #{meatCert},</if>
  151. <if test="animalCert != null">animal_cert = #{animalCert},</if>
  152. <if test="updateTime != null">update_time = #{updateTime},</if>
  153. <if test="updateBy != null">update_by = #{updateBy},</if>
  154. </trim>
  155. where id = #{id}
  156. </update>
  157. <delete id="deleteSlaughterBatchById" parameterType="Long">
  158. update slaughter_batch set del_flag = '2' where id = #{id}
  159. </delete>
  160. <!--根据分销批次删除屠宰批次-->
  161. <delete id="deleteSlaughterBatchByDistributeId" parameterType="Long">
  162. update slaughter_batch set del_flag = '2' where distribute_batch_id = #{id}
  163. </delete>
  164. <delete id="deleteSlaughterBatchByIds" parameterType="String">
  165. update slaughter_batch set del_flag = '2' where id in
  166. <foreach item="id" collection="array" open="(" separator="," close=")">
  167. #{id}
  168. </foreach>
  169. </delete>
  170. <!--根据分销批次批量删除屠宰批次-->
  171. <delete id="deleteSlaughterBatchByDistributeIds" parameterType="String">
  172. update slaughter_batch set del_flag = '2' where distribute_batch_id in
  173. <foreach item="id" collection="array" open="(" separator="," close=")">
  174. #{id}
  175. </foreach>
  176. </delete>
  177. <!--根据入场批次和分销批次ID获取各部位称重记录-->
  178. <select id="selectPorkProduceByBatch" parameterType="com.ruoyi.app.domain.request.ReqEntranceAndDistribute" resultMap="PorkProduceResult">
  179. (
  180. select product_name,produce_time,hook_no,slaughter_code,final_weight
  181. from pork_side_produce
  182. <where>
  183. del_flag = '0'
  184. <if test="entranceBatchId != null "> and entrance_batch_id = #{entranceBatchId}</if>
  185. <if test="distributeBatchId != null "> and distribute_batch_id = #{distributeBatchId}</if>
  186. </where>
  187. )
  188. union all
  189. (
  190. select product_name,produce_time,'-' as hook_no,slaughter_code,final_weight
  191. from pork_other_produce
  192. <where>
  193. del_flag = '0'
  194. <if test="entranceBatchId != null "> and entrance_batch_id = #{entranceBatchId}</if>
  195. <if test="distributeBatchId != null "> and distribute_batch_id = #{distributeBatchId}</if>
  196. </where>
  197. )
  198. order by produce_time desc
  199. </select>
  200. <!--生产情况报表-->
  201. <select id="selectSlaughterReport" parameterType="com.ruoyi.app.domain.request.ReqSlaughterReport" resultMap="SlaughterReportResultMap">
  202. select a.id,a.slaughter_time,a.sale_place,a.meat_cert,a.animal_cert,
  203. b.slaughter_code,b.amount,b.weight as before_weight,
  204. c.purchaser_name,
  205. d.supplier_name,
  206. (select sum(final_weight) from pork_side_produce where distribute_batch_id = a.distribute_batch_id and del_flag = '0') as side_weight,
  207. (select sum(final_weight) from pork_other_produce where distribute_batch_id = a.distribute_batch_id and product_name='猪头' and del_flag = '0') as head_weight,
  208. (select sum(final_weight) from pork_other_produce where distribute_batch_id = a.distribute_batch_id and product_name='红脏' and del_flag = '0') as red_weight,
  209. (select sum(final_weight) from pork_other_produce where distribute_batch_id = a.distribute_batch_id and product_name='白脏' and del_flag = '0') as white_weight
  210. from slaughter_batch as a
  211. left join distribute_batch as b on b.id = a.distribute_batch_id and b.del_flag = '0'
  212. left join purchaser as c on c.id = b.purchaser_id and c.del_flag = '0'
  213. left join supplier as d on d.id = b.supplier_id and d.del_flag = '0'
  214. left join entrance_batch as e on e.id = a.entrance_batch_id and e.del_flag = '0'
  215. <where>
  216. a.del_flag = '0'
  217. <if test="slaughterTime != null "> and DATE(a.slaughter_time) = DATE(#{slaughterTime})</if>
  218. <if test="purchaserName != null and purchaserName != ''"> and c.purchaser_name like concat('%', #{purchaserName}, '%')</if>
  219. <if test="supplierName != null and supplierName != ''"> and d.supplier_name like concat('%', #{supplierName}, '%')</if>
  220. </where>
  221. order by a.slaughter_time desc
  222. </select>
  223. <select id="getAllList" resultType="com.ruoyi.app.DTO.ProductionVo">
  224. select b.productName produceName,a.afterWeight weight,b.unit unit,a.amount amount FROM
  225. (select produce_name produceName,SUM(after_weight) afterWeight,SUM(amount) amount FROM js_distribution where purchaser_name=#{purchaserName}
  226. <if test="animalCertNo != null "> and animal_cert_no = #{animalCertNo}</if>
  227. GROUP BY produce_name)
  228. as a right JOIN
  229. (select product_name productName,unit unit FROM product_category WHERE del_flag='0') AS b
  230. on a.produceName=b.productName
  231. </select>
  232. </mapper>