DistributeBatchMapper.xml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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.DistributeBatchMapper">
  6. <resultMap type="DistributeBatch" id="DistributeBatchResult">
  7. <result property="id" column="id" />
  8. <result property="entranceBatchId" column="entrance_batch_id" />
  9. <result property="slaughterCode" column="slaughter_code" />
  10. <result property="supplierId" column="supplier_id" />
  11. <result property="purchaserId" column="purchaser_id" />
  12. <result property="amount" column="amount" />
  13. <result property="weight" column="weight" />
  14. <result property="pigpenName" column="pigpen_name" />
  15. <result property="createTime" column="create_time" />
  16. <result property="createBy" column="create_by" />
  17. <result property="updateTime" column="update_time" />
  18. <result property="updateBy" column="update_by" />
  19. <result property="delFlag" column="del_flag" />
  20. <association property="purchaser" javaType="Purchaser" resultMap="purchaserResult" />
  21. <association property="supplier" javaType="Supplier" resultMap="supplierResult" />
  22. </resultMap>
  23. <resultMap id="supplierResult" type="Supplier">
  24. <result property="id" column="id" />
  25. <result property="supplierName" column="supplier_name" />
  26. <result property="phone" column="phone" />
  27. <result property="supplySpecies" column="supply_species" />
  28. <result property="businessPlace" column="business_place" />
  29. <result property="originPlace" column="origin_place" />
  30. <result property="region" column="region" />
  31. <result property="evaluate" column="evaluate" />
  32. <result property="remark" column="remark" />
  33. <result property="inBlacklist" column="in_blacklist" />
  34. </resultMap>
  35. <resultMap id="purchaserResult" type="Purchaser" >
  36. <result property="id" column="id" />
  37. <result property="purchaserName" column="purchaser_name" />
  38. <result property="idNumber" column="id_number" />
  39. <result property="phone" column="phone" />
  40. <result property="businessPlace" column="business_place" />
  41. <result property="salePlace" column="sale_place" />
  42. <result property="region" column="region" />
  43. <result property="remark" column="remark" />
  44. </resultMap>
  45. <resultMap id="ValidDistributeListResult" type="com.ruoyi.app.DTO.ValidDistributeListDTO">
  46. <result property="id" column="id" />
  47. <result property="entranceBatchId" column="entrance_batch_id" />
  48. <result property="purchaserId" column="purchaser_id" />
  49. <result property="supplierId" column="supplier_id" />
  50. <result property="purchaserName" column="purchaser_name" />
  51. <result property="supplierName" column="supplier_name" />
  52. <result property="slaughterCode" column="slaughter_code" />
  53. <result property="animalCertNo" column="animal_cert_no" />
  54. </resultMap>
  55. <resultMap id="ValidSlaughterCodeResult" type="com.ruoyi.app.DTO.ValidSlaughterCodeDTO">
  56. <result property="purchaserNo" column="purchaser_no" />
  57. <result property="supplierNo" column="supplier_no" />
  58. <result property="purchaserName" column="purchaser_name" />
  59. <result property="supplierName" column="supplier_name" />
  60. <result property="slaughterCode" column="slaughter_code" />
  61. </resultMap>
  62. <resultMap type="com.ruoyi.app.DTO.TimeAndNumberDTO" id="TimeAndNumberDTOResult">
  63. <result property="timeSpot" column="time_spot" />
  64. <result property="totalAmount" column="total_amount" />
  65. </resultMap>
  66. <sql id="selectDistributeBatchVo">
  67. select id, entrance_batch_id, slaughter_code, supplier_id, purchaser_id, amount, weight, pigpen_name, create_time, create_by, update_time, update_by, del_flag from distribute_batch
  68. </sql>
  69. <select id="selectDistributeBatchList" parameterType="DistributeBatch" resultMap="DistributeBatchResult">
  70. select a.*,b.purchaser_name,c.supplier_name from distribute_batch as a
  71. left join purchaser as b on b.id = a.purchaser_id
  72. left join supplier as c on c.id = a.supplier_id
  73. <where>
  74. a.del_flag = '0'
  75. <if test="entranceBatchId != null and entranceBatchId != 0">
  76. and a.entrance_batch_id = #{entranceBatchId}
  77. </if>
  78. <if test="slaughterCode != null and slaughterCode != ''"> and a.slaughter_code like concat('%', #{slaughterCode}, '%')</if>
  79. <if test="supplierId != null "> and a.supplier_id = #{supplierId}</if>
  80. <if test="purchaserId != null "> and a.purchaser_id = #{purchaserId}</if>
  81. </where>
  82. order by a.id desc
  83. </select>
  84. <select id="selectDistributeBatchById" parameterType="Long" resultMap="DistributeBatchResult">
  85. <include refid="selectDistributeBatchVo"/>
  86. where id = #{id} and del_flag = '0'
  87. </select>
  88. <!--判断当前批次下下肉商是否已有分销-->
  89. <select id="checkPurchaserUnique" parameterType="DistributeBatch" resultMap="DistributeBatchResult">
  90. select a.id, a.purchaser_id,b.purchaser_name from distribute_batch as a
  91. left join purchaser as b on b.id = a.purchaser_id
  92. where a.purchaser_id = #{purchaserId} and a.entrance_batch_id = #{entranceBatchId} and a.del_flag = '0'
  93. limit 1
  94. </select>
  95. <!--获取指定入场批次下的全部分销总量 如果是修改则排除当前批次-->
  96. <select id="getTotalByEntranceBatch" parameterType="DistributeBatch" resultType="Long">
  97. select IFNULL(sum(amount),0) from distribute_batch
  98. <where>
  99. entrance_batch_id = #{entranceBatchId} and del_flag = '0'
  100. <if test="id != null "> and id != #{id}</if>
  101. </where>
  102. group by entrance_batch_id
  103. </select>
  104. <!--获取血码关联的未完成(24小时内)屠宰的分销批次-->
  105. <select id="selectValidDistribute" parameterType="String" resultMap="ValidDistributeListResult">
  106. select a.id,a.entrance_batch_id,a.purchaser_id,c.purchaser_name,a.supplier_id,d.supplier_name,a.slaughter_code,e.animal_cert_no
  107. from distribute_batch as a
  108. left join purchaser as c on c.id = a.purchaser_id and c.del_flag = '0'
  109. left join supplier as d on d.id = a.supplier_id and d.del_flag = '0'
  110. left join entrance_batch as e on e.id = a.entrance_batch_id and e.del_flag = '0'
  111. where
  112. a.slaughter_code = #{slaughterCode}
  113. and a.create_time >= DATE_SUB(NOW(), INTERVAL 24 HOUR)
  114. and a.del_flag = '0'
  115. </select>
  116. <insert id="insertDistributeBatch" parameterType="DistributeBatch" useGeneratedKeys="true" keyProperty="id">
  117. insert into distribute_batch
  118. <trim prefix="(" suffix=")" suffixOverrides=",">
  119. <if test="entranceBatchId != null">entrance_batch_id,</if>
  120. <if test="slaughterCode != null">slaughter_code,</if>
  121. <if test="supplierId != null">supplier_id,</if>
  122. <if test="purchaserId != null">purchaser_id,</if>
  123. <if test="amount != null">amount,</if>
  124. <if test="weight != null">weight,</if>
  125. <if test="pigpenName != null">pigpen_name,</if>
  126. <if test="createTime != null">create_time,</if>
  127. <if test="createBy != null">create_by,</if>
  128. del_flag
  129. </trim>
  130. <trim prefix="values (" suffix=")" suffixOverrides=",">
  131. <if test="entranceBatchId != null">#{entranceBatchId},</if>
  132. <if test="slaughterCode != null">#{slaughterCode},</if>
  133. <if test="supplierId != null">#{supplierId},</if>
  134. <if test="purchaserId != null">#{purchaserId},</if>
  135. <if test="amount != null">#{amount},</if>
  136. <if test="weight != null">#{weight},</if>
  137. <if test="pigpenName != null">#{pigpenName},</if>
  138. <if test="createTime != null">#{createTime},</if>
  139. <if test="createBy != null">#{createBy},</if>
  140. '0'
  141. </trim>
  142. </insert>
  143. <insert id="insertDistributeBatchByBatch" parameterType="list" >
  144. INSERT INTO distribute_batch (entrance_batch_id, slaughter_code, supplier_id, purchaser_id, amount, weight, pigpen_name, create_time, create_by,del_flag)
  145. VALUES
  146. <foreach collection="list" item="item" index="index" separator=",">
  147. (#{item.entranceBatchId}, #{item.slaughterCode}, #{item.supplierId}, #{item.purchaserId}, #{item.amount}, #{item.weight}, #{item.pigpenName}, #{item.createTime}, #{item.createBy},'0')
  148. </foreach>
  149. </insert>
  150. <update id="updateDistributeBatch" parameterType="DistributeBatch">
  151. update distribute_batch
  152. <trim prefix="SET" suffixOverrides=",">
  153. <if test="entranceBatchId != null">entrance_batch_id = #{entranceBatchId},</if>
  154. <if test="slaughterCode != null">slaughter_code = #{slaughterCode},</if>
  155. <if test="supplierId != null">supplier_id = #{supplierId},</if>
  156. <if test="purchaserId != null">purchaser_id = #{purchaserId},</if>
  157. <if test="amount != null">amount = #{amount},</if>
  158. <if test="weight != null">weight = #{weight},</if>
  159. <if test="pigpenName != null">pigpen_name = #{pigpenName},</if>
  160. <if test="updateTime != null">update_time = #{updateTime},</if>
  161. <if test="updateBy != null">update_by = #{updateBy},</if>
  162. </trim>
  163. where id = #{id}
  164. </update>
  165. <delete id="deleteDistributeBatchById" parameterType="Long">
  166. update distribute_batch set del_flag = '2' where id = #{id}
  167. </delete>
  168. <delete id="deleteDistributeBatchByIds" parameterType="String">
  169. update distribute_batch set del_flag = '2' where id in
  170. <foreach item="id" collection="array" open="(" separator="," close=")">
  171. #{id}
  172. </foreach>
  173. </delete>
  174. <!--根据时间范围获取分销次数-->
  175. <select id="selectCountByTime" parameterType="com.ruoyi.app.domain.request.TimeRangeParam" resultType="Long">
  176. select count(1) from distribute_batch
  177. <where>
  178. del_flag = '0'
  179. <if test="startTime != null "> and create_time <![CDATA[ >= ]]> #{startTime}</if>
  180. <if test="endTime != null "> and create_time <![CDATA[ <= ]]> #{endTime}</if>
  181. </where>
  182. </select>
  183. <!--根据时间范围获取累计屠宰-->
  184. <select id="selectAmountByTime" parameterType="com.ruoyi.app.domain.request.TimeRangeParam" resultType="Long">
  185. select IFNULL(sum(amount),0) from distribute_batch
  186. <where>
  187. del_flag = '0'
  188. <if test="startTime != null "> and create_time <![CDATA[ >= ]]> #{startTime}</if>
  189. <if test="endTime != null "> and create_time <![CDATA[ <= ]]> #{endTime}</if>
  190. </where>
  191. </select>
  192. <!--根据供应商ID统计分销批次数量-->
  193. <select id="countBatchBySupplier" parameterType="Long" resultType="Integer">
  194. select count(1) from distribute_batch
  195. where supplier_id = #{supplierId} and del_flag = '0'
  196. </select>
  197. <!--根据肉商ID统计分销批次数量-->
  198. <select id="countBatchByPurchaser" parameterType="Long" resultType="Integer">
  199. select count(1) from distribute_batch
  200. where purchaser_id = #{purchaserId} and del_flag = '0'
  201. </select>
  202. <!--根据血码统计分销批次数量-->
  203. <select id="countBatchBySlaughterCode" parameterType="String" resultType="Integer">
  204. select count(1) from distribute_batch
  205. where slaughter_code = #{slaughterCode} and del_flag = '0'
  206. </select>
  207. <!--根据入场批次统计分销批次数量-->
  208. <select id="countBatchByEntrance" parameterType="Long" resultType="Integer">
  209. select count(1) from distribute_batch
  210. where entrance_batch_id = #{entranceBatchId} and del_flag = '0'
  211. </select>
  212. <!--根据时间范围获取今日入场次数-->
  213. <select id="selectTodayCount" resultType="Long">
  214. select count(1) from distribute_batch
  215. <where>
  216. del_flag = '0'
  217. and create_time <![CDATA[ >= ]]> CURDATE()
  218. and create_time <![CDATA[ < ]]> DATE_ADD(CURDATE(), INTERVAL 1 DAY)
  219. </where>
  220. </select>
  221. <!--根据时间范围获取昨日入场次数-->
  222. <select id="selectYesterdayCount" resultType="Long">
  223. select count(1) from distribute_batch
  224. <where>
  225. del_flag = '0'
  226. and create_time <![CDATA[ >= ]]> DATE_SUB(CURDATE(), INTERVAL 1 DAY)
  227. and create_time <![CDATA[ < ]]> CURDATE()
  228. </where>
  229. </select>
  230. <!--根据获取近七天的每日入场订单-->
  231. <select id="selectWeekCountByTime" resultMap="TimeAndNumberDTOResult">
  232. SELECT
  233. dates.date AS time_spot,
  234. IFNULL(count(eb.id), 0) AS total_amount
  235. FROM (
  236. SELECT CURDATE() AS date UNION ALL
  237. SELECT DATE_SUB(CURDATE(), INTERVAL 1 DAY) UNION ALL
  238. SELECT DATE_SUB(CURDATE(), INTERVAL 2 DAY) UNION ALL
  239. SELECT DATE_SUB(CURDATE(), INTERVAL 3 DAY) UNION ALL
  240. SELECT DATE_SUB(CURDATE(), INTERVAL 4 DAY) UNION ALL
  241. SELECT DATE_SUB(CURDATE(), INTERVAL 5 DAY) UNION ALL
  242. SELECT DATE_SUB(CURDATE(), INTERVAL 6 DAY)
  243. ) AS dates
  244. LEFT JOIN distribute_batch eb ON
  245. DATE(eb.create_time) = dates.date and eb.del_flag = '0'
  246. GROUP BY
  247. dates.date
  248. ORDER BY
  249. dates.date;
  250. </select>
  251. <!--获取存在未完成(24小时内)的分销批次的血码-->
  252. <select id="selectValidCode" parameterType="Integer" resultMap="ValidSlaughterCodeResult">
  253. select a.slaughter_code,c.purchaser_no,c.purchaser_name,d.supplier_no,d.supplier_name
  254. from distribute_batch as a
  255. left join purchaser as c on c.id = a.purchaser_id and c.del_flag = '0'
  256. left join supplier as d on d.id = a.supplier_id and d.del_flag = '0'
  257. where
  258. a.del_flag = '0'
  259. and a.create_time >= DATE_SUB(NOW(), INTERVAL 24 HOUR)
  260. group by a.slaughter_code,c.purchaser_no,c.purchaser_name,d.supplier_no,d.supplier_name
  261. </select>
  262. </mapper>