EntranceBatchMapper.xml 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611
  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.EntranceBatchMapper">
  6. <resultMap type="EntranceBatch" id="EntranceBatchResult">
  7. <result property="id" column="id" />
  8. <result property="supplierId" column="supplier_id" />
  9. <result property="originPlace" column="origin_place" />
  10. <result property="entranceTime" column="entrance_time" />
  11. <result property="variety" column="variety" />
  12. <result property="transportVehicle" column="transport_vehicle" />
  13. <result property="weight" column="weight" />
  14. <result property="pigpens" column="pigpens" />
  15. <result property="animalCertNo" column="animal_cert_no" />
  16. <result property="animalCertPics" column="animal_cert_pics" />
  17. <result property="cargoOwner" column="cargo_owner" />
  18. <result property="companyNo" column="company_no" />
  19. <result property="cargoOwnerPhone" column="cargo_owner_phone" />
  20. <result property="animalCategory" column="animal_category" />
  21. <result property="amount" column="amount" />
  22. <result property="units" column="units" />
  23. <result property="useto" column="useto" />
  24. <result property="fromPlace" column="from_place" />
  25. <result property="toPlace" column="to_place" />
  26. <result property="carrier" column="carrier" />
  27. <result property="carrierPhone" column="carrier_phone" />
  28. <result property="animalEartags" column="animal_eartags" />
  29. <result property="remark" column="remark" />
  30. <result property="createTime" column="create_time" />
  31. <result property="createBy" column="create_by" />
  32. <result property="updateTime" column="update_time" />
  33. <result property="updateBy" column="update_by" />
  34. <result property="delFlag" column="del_flag" />
  35. <association property="harmlessTreatment" javaType="HarmlessTreatment" resultMap="HarmlessTreatmentResult" />
  36. <association property="supplier" javaType="Supplier" resultMap="SupplierResult" />
  37. </resultMap>
  38. <resultMap type="Supplier" id="SupplierResult">
  39. <result property="id" column="id" />
  40. <result property="supplierName" column="supplier_name" />
  41. <result property="phone" column="phone" />
  42. <result property="supplySpecies" column="supply_species" />
  43. <result property="businessPlace" column="business_place" />
  44. <result property="originPlace" column="origin_place" />
  45. <result property="region" column="region" />
  46. <result property="evaluate" column="evaluate" />
  47. <result property="remark" column="remark" />
  48. <result property="inBlacklist" column="in_blacklist" />
  49. <result property="createTime" column="create_time" />
  50. <result property="createBy" column="create_by" />
  51. <result property="updateTime" column="update_time" />
  52. <result property="updateBy" column="update_by" />
  53. <result property="delFlag" column="del_flag" />
  54. </resultMap>
  55. <resultMap type="HarmlessTreatment" id="HarmlessTreatmentResult">
  56. <result property="id" column="id" />
  57. <result property="entranceBatchId" column="entrance_batch_id" />
  58. <result property="illnessDeadAmount" column="illness_dead_amount" />
  59. <result property="illnessDiseaseAmount" column="illness_disease_amount" />
  60. <result property="snapKillAmount" column="snap_kill_amount" />
  61. <result property="unqualifiedWeight" column="unqualified_weight" />
  62. <result property="illnessPigsDetail" column="illness_pigs_detail" />
  63. <result property="dealReason" column="deal_reason" />
  64. <result property="dealWay" column="deal_way" />
  65. <result property="createTime" column="create_time" />
  66. <result property="createBy" column="create_by" />
  67. <result property="updateTime" column="update_time" />
  68. <result property="updateBy" column="update_by" />
  69. <result property="delFlag" column="del_flag" />
  70. </resultMap>
  71. <resultMap type="com.ruoyi.app.DTO.TimeAndNumberDTO" id="TimeAndNumberDTOResult">
  72. <result property="timeSpot" column="time_spot" />
  73. <result property="totalAmount" column="total_amount" />
  74. </resultMap>
  75. <resultMap id="productTraceResultMap" type="com.ruoyi.app.DTO.ProductTraceDTO">
  76. <result property="entranceBatchId" column="entrance_batch_id"/>
  77. <result property="animalCertNo" column="animal_cert_no"/>
  78. <result property="entranceTime" column="entrance_time"/>
  79. <result property="cargoOwner" column="cargo_owner"/>
  80. <result property="companyNo" column="company_no"/>
  81. <result property="animalCategory" column="animal_category"/>
  82. <result property="variety" column="variety"/>
  83. <result property="amount" column="amount"/>
  84. <result property="units" column="units"/>
  85. <result property="fromPlace" column="from_place"/>
  86. <result property="toPlace" column="to_place"/>
  87. <result property="carrier" column="carrier"/>
  88. <result property="cargoOwnerPhone" column="cargo_owner_phone"/>
  89. <result property="carrierPhone" column="carrier_phone"/>
  90. <result property="spirit" column="spirit"/>
  91. <result property="appearance" column="appearance"/>
  92. <result property="breathe" column="breathe"/>
  93. <result property="metabolite" column="metabolite"/>
  94. <result property="otherRemark" column="other_remark"/>
  95. <result property="inspectionDetail" column="inspection_detail"/>
  96. <result property="illnessDeadAmount" column="illness_dead_amount"/>
  97. <result property="illnessDiseaseAmount" column="illness_disease_amount"/>
  98. <result property="snapKillAmount" column="snap_kill_amount"/>
  99. <result property="unqualifiedWeight" column="unqualified_weight"/>
  100. <result property="dealWay" column="deal_way"/>
  101. <result property="totalSideWeight" column="total_side_weight"/>
  102. <result property="totalHeadWeight" column="total_head_weight"/>
  103. <result property="totalRedWeight" column="total_red_weight"/>
  104. <result property="totalWhiteWeight" column="total_white_weight"/>
  105. <!-- 处理 slaughterBatchDTO 集合 -->
  106. <collection property="slaughterBatchs" ofType="com.ruoyi.app.DTO.SlaughterBatchDTO">
  107. <!-- 主表 -->
  108. <id property="id" column="distribute_batch_id"/>
  109. <result property="slaughterTime" column="slaughter_time"/>
  110. <result property="salePlace" column="sale_place"/>
  111. <result property="meatCert" column="meat_cert"/>
  112. <result property="animalCert" column="animal_cert"/>
  113. <!-- 分销批次 -->
  114. <result property="slaughterCode" column="slaughter_code"/>
  115. <result property="amount" column="slaughter_amount"/>
  116. <result property="beforeWeight" column="before_weight"/>
  117. <!--肉商 -->
  118. <result property="purchaserName" column="purchaser_name"/>
  119. <!-- 供应商 -->
  120. <result property="supplierName" column="supplier_name"/>
  121. <!-- 入场批次 -->
  122. <result property="variety" column="variety"/>
  123. <result property="animalCertNo" column="animal_cert_no"/>
  124. <!-- 重量统计 -->
  125. <result property="sideWeight" column="side_weight"/>
  126. <result property="headWeight" column="head_weight"/>
  127. <result property="redWeight" column="red_weight"/>
  128. <result property="whiteWeight" column="white_weight"/>
  129. </collection>
  130. </resultMap>
  131. <resultMap id="entranceReportResultMap" type="com.ruoyi.app.DTO.EntranceReportDTO">
  132. <result property="entranceTime" column="entrance_time"/>
  133. <result property="animalCertNo" column="animal_cert_no"/>
  134. <result property="animalEartags" column="animal_eartags"/>
  135. <result property="amount" column="amount"/>
  136. <result property="weight" column="weight"/>
  137. <result property="pigpens" column="pigpens"/>
  138. <result property="supplierName" column="supplier_name"/>
  139. <result property="originPlace" column="origin_place"/>
  140. <result property="illnessDeadAmount" column="illness_dead_amount"/>
  141. <result property="illnessDiseaseAmount" column="illness_disease_amount"/>
  142. <result property="snapKillAmount" column="snap_kill_amount"/>
  143. <result property="unqualifiedWeight" column="unqualified_weight"/>
  144. <result property="illnessPigsDetail" column="illness_pigs_detail"/>
  145. <result property="dealWay" column="deal_way"/>
  146. <result property="inspectionDetail" column="inspection_detail"/>
  147. </resultMap>
  148. <resultMap type="com.ruoyi.app.DTO.DailyEntranceAmountDTO" id="DailyEntranceAmountResult">
  149. <result property="illnessDeadAmountSum" column="illness_dead_amount_sum" />
  150. <result property="illnessDiseaseAmountSum" column="illness_disease_amount_sum" />
  151. <result property="entranceAmountSum" column="entrance_amount_sum" />
  152. </resultMap>
  153. <sql id="selectEntranceBatchVo">
  154. select id, supplier_id,origin_place,entrance_time, variety, transport_vehicle, weight, pigpens, animal_cert_no,animal_cert_pics, cargo_owner, company_no, cargo_owner_phone, animal_category, amount, units, useto, from_place, to_place, carrier, carrier_phone, animal_eartags, remark, create_time,create_by, update_time, update_by, del_flag from entrance_batch
  155. </sql>
  156. <select id="selectEntranceBatchList" parameterType="EntranceBatch" resultMap="EntranceBatchResult">
  157. select a.id, a.entrance_time,a.animal_cert_no, a.cargo_owner,a.amount,a.supplier_id,a.variety,
  158. b.supplier_name,
  159. c.illness_dead_amount,c.illness_disease_amount,c.snap_kill_amount,c.unqualified_weight
  160. from entrance_batch as a
  161. left join supplier as b on b.id = a.supplier_id and b.del_flag = '0'
  162. left join harmless_treatment as c on c.entrance_batch_id = a.id and c.del_flag = '0'
  163. <where>
  164. a.del_flag = '0'
  165. <if test="supplierId != null "> and a.supplier_id = #{supplierId}</if>
  166. <if test="entranceTime != null "> and a.entrance_time >= #{entranceTime}</if>
  167. <if test="animalCertNo != null and animalCertNo != ''"> and a.animal_cert_no like concat('%', #{animalCertNo}, '%')</if>
  168. </where>
  169. order by a.entrance_time desc,a.id desc
  170. </select>
  171. <select id="selectEntranceBatchDetailById" parameterType="Long" resultMap="EntranceBatchResult">
  172. select a.*,b.phone,b.origin_place,b.region,b.business_place
  173. from entrance_batch as a
  174. left join supplier as b on b.id = a.supplier_id and b.del_flag = '0'
  175. where a.id = #{id} and a.del_flag = '0'
  176. </select>
  177. <select id="selectEntranceBatchById" parameterType="Long" resultMap="EntranceBatchResult">
  178. select a.id, a.entrance_time,a.animal_cert_no, a.cargo_owner,a.amount,a.supplier_id,a.variety,
  179. c.illness_dead_amount,c.illness_disease_amount,c.snap_kill_amount,c.unqualified_weight
  180. from entrance_batch as a
  181. left join harmless_treatment as c on c.entrance_batch_id = a.id and c.del_flag = '0'
  182. where a.id = #{id} and a.del_flag = '0'
  183. </select>
  184. <!--检查检疫证号是否存在-->
  185. <select id="checkAnimalCertNoUnique" parameterType="String" resultMap="EntranceBatchResult">
  186. select id, animal_cert_no from entrance_batch where animal_cert_no = #{animalCertNo} and del_flag = '0' limit 1
  187. </select>
  188. <insert id="insertEntranceBatch" parameterType="EntranceBatch" useGeneratedKeys="true" keyProperty="id">
  189. insert into entrance_batch
  190. <trim prefix="(" suffix=")" suffixOverrides=",">
  191. <if test="supplierId != null">supplier_id,</if>
  192. <if test="originPlace != null">origin_place,</if>
  193. <if test="entranceTime != null">entrance_time,</if>
  194. <if test="variety != null">variety,</if>
  195. <if test="transportVehicle != null">transport_vehicle,</if>
  196. <if test="weight != null">weight,</if>
  197. <if test="pigpens != null">pigpens,</if>
  198. <if test="animalCertNo != null">animal_cert_no,</if>
  199. <if test="animalCertPics != null">animal_cert_pics,</if>
  200. <if test="cargoOwner != null">cargo_owner,</if>
  201. <if test="companyNo != null">company_no,</if>
  202. <if test="cargoOwnerPhone != null">cargo_owner_phone,</if>
  203. <if test="animalCategory != null">animal_category,</if>
  204. <if test="amount != null">amount,</if>
  205. <if test="units != null">units,</if>
  206. <if test="useto != null">useto,</if>
  207. <if test="fromPlace != null">from_place,</if>
  208. <if test="toPlace != null">to_place,</if>
  209. <if test="carrier != null">carrier,</if>
  210. <if test="carrierPhone != null">carrier_phone,</if>
  211. <if test="animalEartags != null">animal_eartags,</if>
  212. <if test="remark != null">remark,</if>
  213. <if test="createTime != null">create_time,</if>
  214. <if test="createBy != null">create_by,</if>
  215. del_flag
  216. </trim>
  217. <trim prefix="values (" suffix=")" suffixOverrides=",">
  218. <if test="supplierId != null">#{supplierId},</if>
  219. <if test="originPlace != null">#{originPlace},</if>
  220. <if test="entranceTime != null">#{entranceTime},</if>
  221. <if test="variety != null">#{variety},</if>
  222. <if test="transportVehicle != null">#{transportVehicle},</if>
  223. <if test="weight != null">#{weight},</if>
  224. <if test="pigpens != null">#{pigpens},</if>
  225. <if test="animalCertNo != null">#{animalCertNo},</if>
  226. <if test="animalCertPics != null">#{animalCertPics},</if>
  227. <if test="cargoOwner != null">#{cargoOwner},</if>
  228. <if test="companyNo != null">#{companyNo},</if>
  229. <if test="cargoOwnerPhone != null">#{cargoOwnerPhone},</if>
  230. <if test="animalCategory != null">#{animalCategory},</if>
  231. <if test="amount != null">#{amount},</if>
  232. <if test="units != null">#{units},</if>
  233. <if test="useto != null">#{useto},</if>
  234. <if test="fromPlace != null">#{fromPlace},</if>
  235. <if test="toPlace != null">#{toPlace},</if>
  236. <if test="carrier != null">#{carrier},</if>
  237. <if test="carrierPhone != null">#{carrierPhone},</if>
  238. <if test="animalEartags != null">#{animalEartags},</if>
  239. <if test="remark != null">#{remark},</if>
  240. <if test="createTime != null">#{createTime},</if>
  241. <if test="createBy != null">#{createBy},</if>
  242. '0'
  243. </trim>
  244. </insert>
  245. <update id="updateEntranceBatch" parameterType="EntranceBatch">
  246. update entrance_batch
  247. <trim prefix="SET" suffixOverrides=",">
  248. <if test="supplierId != null">supplier_id = #{supplierId},</if>
  249. <if test="originPlace != null">origin_place = #{originPlace},</if>
  250. <if test="entranceTime != null">entrance_time = #{entranceTime},</if>
  251. <if test="variety != null">variety = #{variety},</if>
  252. <if test="transportVehicle != null">transport_vehicle = #{transportVehicle},</if>
  253. <if test="weight != null">weight = #{weight},</if>
  254. <if test="pigpens != null">pigpens = #{pigpens},</if>
  255. <if test="animalCertNo != null">animal_cert_no = #{animalCertNo},</if>
  256. <if test="animalCertPics != null">animal_cert_pics = #{animalCertPics},</if>
  257. <if test="cargoOwner != null">cargo_owner = #{cargoOwner},</if>
  258. <if test="companyNo != null">company_no = #{companyNo},</if>
  259. <if test="cargoOwnerPhone != null">cargo_owner_phone = #{cargoOwnerPhone},</if>
  260. <if test="animalCategory != null">animal_category = #{animalCategory},</if>
  261. <if test="amount != null">amount = #{amount},</if>
  262. <if test="units != null">units = #{units},</if>
  263. <if test="useto != null">useto = #{useto},</if>
  264. <if test="fromPlace != null">from_place = #{fromPlace},</if>
  265. <if test="toPlace != null">to_place = #{toPlace},</if>
  266. <if test="carrier != null">carrier = #{carrier},</if>
  267. <if test="carrierPhone != null">carrier_phone = #{carrierPhone},</if>
  268. <if test="animalEartags != null">animal_eartags = #{animalEartags},</if>
  269. <if test="remark != null">remark = #{remark},</if>
  270. <if test="updateTime != null">update_time = #{updateTime},</if>
  271. <if test="updateBy != null">update_by = #{updateBy},</if>
  272. </trim>
  273. where id = #{id}
  274. </update>
  275. <delete id="deleteEntranceBatchById" parameterType="Long">
  276. update entrance_batch set del_flag = '2' where id = #{id}
  277. </delete>
  278. <delete id="deleteEntranceBatchByIds" parameterType="String">
  279. update entrance_batch set del_flag = '2' where id in
  280. <foreach item="id" collection="array" open="(" separator="," close=")">
  281. #{id}
  282. </foreach>
  283. </delete>
  284. <!--获取最近的一条记录-->
  285. <select id="selectLatelyEntrance" resultMap="EntranceBatchResult">
  286. select * from entrance_batch
  287. <where>
  288. del_flag = '0'
  289. </where>
  290. order by entrance_time desc
  291. limit 1
  292. </select>
  293. <!--根据时间范围获取入场次数-->
  294. <select id="selectCountByTime" parameterType="com.ruoyi.app.domain.request.TimeRangeParam" resultType="Long">
  295. select count(1) from entrance_batch
  296. <where>
  297. del_flag = '0'
  298. <if test="startTime != null "> and entrance_time <![CDATA[ >= ]]> #{startTime}</if>
  299. <if test="endTime != null "> and entrance_time <![CDATA[ <= ]]> #{endTime}</if>
  300. </where>
  301. </select>
  302. <!--根据时间范围获取今日入场次数-->
  303. <select id="selectTodayCount" resultType="Long">
  304. select count(1) from entrance_batch
  305. <where>
  306. del_flag = '0'
  307. and entrance_time <![CDATA[ >= ]]> CURDATE()
  308. and entrance_time <![CDATA[ < ]]> DATE_ADD(CURDATE(), INTERVAL 1 DAY)
  309. </where>
  310. </select>
  311. <!--根据时间范围获取昨日入场次数-->
  312. <select id="selectYesterdayCount" resultType="Long">
  313. select count(1) from entrance_batch
  314. <where>
  315. del_flag = '0'
  316. and entrance_time <![CDATA[ >= ]]> DATE_SUB(CURDATE(), INTERVAL 1 DAY)
  317. and entrance_time <![CDATA[ < ]]> CURDATE()
  318. </where>
  319. </select>
  320. <!--根据时间范围获取累计计划屠宰-->
  321. <select id="selectAmountByTime" parameterType="com.ruoyi.app.domain.request.TimeRangeParam" resultType="Long">
  322. select IFNULL(sum(amount),0) from entrance_batch
  323. <where>
  324. del_flag = '0'
  325. <if test="startTime != null "> and entrance_time <![CDATA[ >= ]]> #{startTime}</if>
  326. <if test="endTime != null "> and entrance_time <![CDATA[ <= ]]> #{endTime}</if>
  327. </where>
  328. </select>
  329. <!--根据时间范围获取今日累计计划屠宰-->
  330. <select id="selectTodayAmount" resultMap="DailyEntranceAmountResult">
  331. select IFNULL(sum(b.amount),0) as entrance_amount_sum,IFNULL(sum(illness_dead_amount),0) as illness_dead_amount_sum,IFNULL(sum(illness_disease_amount),0) as illness_disease_amount_sum
  332. from harmless_treatment as a
  333. left join entrance_batch as b on b.id = a.entrance_batch_id
  334. <where>
  335. a.del_flag = '0' and b.del_flag = '0'
  336. and b.entrance_time <![CDATA[ >= ]]> CURDATE()
  337. and b.entrance_time <![CDATA[ < ]]> DATE_ADD(CURDATE(), INTERVAL 1 DAY)
  338. </where>
  339. </select>
  340. <!--根据时间范围获取昨日累计计划屠宰-->
  341. <select id="selectYesterdayAmount" resultMap="DailyEntranceAmountResult">
  342. select IFNULL(sum(b.amount),0) as entrance_amount_sum,IFNULL(sum(illness_dead_amount),0) as illness_dead_amount_sum,IFNULL(sum(illness_disease_amount),0) as illness_disease_amount_sum
  343. from harmless_treatment as a
  344. left join entrance_batch as b on b.id = a.entrance_batch_id
  345. <where>
  346. a.del_flag = '0' and b.del_flag = '0'
  347. and b.entrance_time <![CDATA[ >= ]]> DATE_SUB(CURDATE(), INTERVAL 1 DAY)
  348. and b.entrance_time <![CDATA[ < ]]> CURDATE()
  349. </where>
  350. </select>
  351. <!--统计按年全部数据-->
  352. <select id="selectAllYearAmountByTime" parameterType="com.ruoyi.app.domain.request.TimeRangeParam" resultMap="TimeAndNumberDTOResult">
  353. SELECT
  354. YEAR(entrance_time) AS time_spot,
  355. IFNULL(SUM(amount),0) AS total_amount
  356. FROM
  357. entrance_batch
  358. where del_flag = '0'
  359. GROUP BY
  360. YEAR(entrance_time)
  361. ORDER BY
  362. time_spot;
  363. </select>
  364. <!--根据获取近一年每月累计计划屠宰-->
  365. <select id="selectYearAmountByTime" parameterType="com.ruoyi.app.domain.request.TimeRangeParam" resultMap="TimeAndNumberDTOResult">
  366. SELECT
  367. months.month_period as time_spot,
  368. IFNULL(SUM(eb.amount), 0) AS total_amount
  369. FROM (
  370. SELECT
  371. DATE_FORMAT(DATE_SUB(DATE_FORMAT(NOW(), '%Y-%m-01'), INTERVAL seq MONTH), '%Y-%m') AS month_period,
  372. DATE_SUB(DATE_FORMAT(NOW(), '%Y-%m-01'), INTERVAL seq MONTH) AS month_start,
  373. LAST_DAY(DATE_SUB(DATE_FORMAT(NOW(), '%Y-%m-01'), INTERVAL seq MONTH)) AS month_end
  374. FROM (
  375. SELECT 0 AS seq UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL
  376. SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL
  377. SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL
  378. SELECT 9 UNION ALL SELECT 10 UNION ALL SELECT 11
  379. ) AS sequences
  380. ) AS months
  381. LEFT JOIN entrance_batch eb ON
  382. eb.entrance_time BETWEEN months.month_start AND months.month_end and eb.del_flag = '0'
  383. GROUP BY
  384. months.month_period, months.month_start, months.month_end
  385. ORDER BY
  386. months.month_start;
  387. </select>
  388. <!--根据获取近三十天的每日累计计划屠宰-->
  389. <select id="selectMonthAmountByTime" parameterType="com.ruoyi.app.domain.request.TimeRangeParam" resultMap="TimeAndNumberDTOResult">
  390. SELECT
  391. dates.date AS time_spot,
  392. IFNULL(SUM(eb.amount), 0) AS total_amount
  393. FROM (
  394. SELECT DATE_SUB(CURDATE(), INTERVAL seq DAY) AS date
  395. FROM (
  396. SELECT 0 AS seq UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL
  397. SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL
  398. SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL
  399. SELECT 9 UNION ALL SELECT 10 UNION ALL SELECT 11 UNION ALL
  400. SELECT 12 UNION ALL SELECT 13 UNION ALL SELECT 14 UNION ALL
  401. SELECT 15 UNION ALL SELECT 16 UNION ALL SELECT 17 UNION ALL
  402. SELECT 18 UNION ALL SELECT 19 UNION ALL SELECT 20 UNION ALL
  403. SELECT 21 UNION ALL SELECT 22 UNION ALL SELECT 23 UNION ALL
  404. SELECT 24 UNION ALL SELECT 25 UNION ALL SELECT 26 UNION ALL
  405. SELECT 27 UNION ALL SELECT 28 UNION ALL SELECT 29
  406. ) AS sequences
  407. ) AS dates
  408. LEFT JOIN entrance_batch eb ON
  409. DATE(eb.entrance_time) = dates.date and eb.del_flag = '0'
  410. GROUP BY
  411. dates.date
  412. ORDER BY
  413. dates.date;
  414. </select>
  415. <!--根据获取近七天的每日累计计划屠宰-->
  416. <select id="selectWeekAmountByTime" parameterType="com.ruoyi.app.domain.request.TimeRangeParam" resultMap="TimeAndNumberDTOResult">
  417. SELECT
  418. dates.date AS time_spot,
  419. IFNULL(SUM(eb.amount), 0) AS total_amount
  420. FROM (
  421. SELECT CURDATE() AS date UNION ALL
  422. SELECT DATE_SUB(CURDATE(), INTERVAL 1 DAY) UNION ALL
  423. SELECT DATE_SUB(CURDATE(), INTERVAL 2 DAY) UNION ALL
  424. SELECT DATE_SUB(CURDATE(), INTERVAL 3 DAY) UNION ALL
  425. SELECT DATE_SUB(CURDATE(), INTERVAL 4 DAY) UNION ALL
  426. SELECT DATE_SUB(CURDATE(), INTERVAL 5 DAY) UNION ALL
  427. SELECT DATE_SUB(CURDATE(), INTERVAL 6 DAY)
  428. ) AS dates
  429. LEFT JOIN entrance_batch eb ON
  430. DATE(eb.entrance_time) = dates.date and eb.del_flag = '0'
  431. GROUP BY
  432. dates.date
  433. ORDER BY
  434. dates.date;
  435. </select>
  436. <!--根据获取每小时累计计划屠宰-->
  437. <select id="selectTodayAmountByTime" parameterType="com.ruoyi.app.domain.request.TimeRangeParam" resultMap="TimeAndNumberDTOResult">
  438. SELECT
  439. hours.hour AS time_spot,
  440. IFNULL(SUM(eb.amount), 0) AS total_amount
  441. FROM (
  442. SELECT '00:00' AS hour UNION SELECT '01:00' UNION SELECT '02:00' UNION SELECT '03:00'
  443. UNION SELECT '04:00' UNION SELECT '05:00' UNION SELECT '06:00' UNION SELECT '07:00'
  444. UNION SELECT '08:00' UNION SELECT '09:00' UNION SELECT '10:00' UNION SELECT '11:00'
  445. UNION SELECT '12:00' UNION SELECT '13:00' UNION SELECT '14:00' UNION SELECT '15:00'
  446. UNION SELECT '16:00' UNION SELECT '17:00' UNION SELECT '18:00' UNION SELECT '19:00'
  447. UNION SELECT '20:00' UNION SELECT '21:00' UNION SELECT '22:00' UNION SELECT '23:00'
  448. ) AS hours
  449. LEFT JOIN entrance_batch eb ON
  450. DATE_FORMAT(eb.entrance_time, '%H:00') = hours.hour
  451. AND DATE(eb.entrance_time) = CURDATE() and eb.del_flag = '0'
  452. GROUP BY
  453. hours.hour
  454. ORDER BY
  455. hours.hour;
  456. </select>
  457. <!--根据获取指定时间范围内每日累计计划屠宰-->
  458. <select id="selectRangeAmountByTime" parameterType="com.ruoyi.app.domain.request.TimeRangeParam" resultMap="TimeAndNumberDTOResult">
  459. SELECT
  460. DATE_FORMAT(dates.date, '%Y-%m-%d') AS time_spot,
  461. IFNULL(SUM(eb.amount), 0) AS total_amount
  462. FROM (
  463. SELECT DATE_ADD(#{startTime}, INTERVAL seq DAY) AS date
  464. FROM (
  465. SELECT a.n + b.n*10 + c.n*100 AS seq
  466. FROM
  467. (SELECT 0 AS n UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4
  468. UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9) a,
  469. (SELECT 0 AS n UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4
  470. UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9) b,
  471. (SELECT 0 AS n UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4
  472. UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9) c
  473. WHERE a.n + b.n*10 + c.n*100 <![CDATA[ <= ]]> DATEDIFF(#{endTime}, #{startTime})
  474. ) AS sequences
  475. ) AS dates
  476. LEFT JOIN entrance_batch eb ON
  477. DATE(eb.entrance_time) = dates.date
  478. AND eb.del_flag = '0'
  479. GROUP BY
  480. dates.date
  481. ORDER BY
  482. dates.date
  483. </select>
  484. <!--根据获取近七天的每日入场订单-->
  485. <select id="selectWeekCountByTime" resultMap="TimeAndNumberDTOResult">
  486. SELECT
  487. dates.date AS time_spot,
  488. IFNULL(count(eb.id), 0) AS total_amount
  489. FROM (
  490. SELECT CURDATE() AS date UNION ALL
  491. SELECT DATE_SUB(CURDATE(), INTERVAL 1 DAY) UNION ALL
  492. SELECT DATE_SUB(CURDATE(), INTERVAL 2 DAY) UNION ALL
  493. SELECT DATE_SUB(CURDATE(), INTERVAL 3 DAY) UNION ALL
  494. SELECT DATE_SUB(CURDATE(), INTERVAL 4 DAY) UNION ALL
  495. SELECT DATE_SUB(CURDATE(), INTERVAL 5 DAY) UNION ALL
  496. SELECT DATE_SUB(CURDATE(), INTERVAL 6 DAY)
  497. ) AS dates
  498. LEFT JOIN entrance_batch eb ON
  499. DATE(eb.entrance_time) = dates.date and eb.del_flag = '0'
  500. GROUP BY
  501. dates.date
  502. ORDER BY
  503. dates.date;
  504. </select>
  505. <!--产品追溯-根据肉商名称,供应商名称,血码,检疫证号查询-->
  506. <select id="selectProductTrace" parameterType="com.ruoyi.app.domain.request.ProductTraceParam" resultMap="productTraceResultMap">
  507. select
  508. a.id as entrance_batch_id,
  509. a.animal_cert_no,a.entrance_time,a.cargo_owner,a.company_no,a.animal_category,a.variety,a.amount,a.units,a.from_place,a.to_place,a.carrier,a.cargo_owner_phone,a.carrier_phone,
  510. f.spirit,f.appearance,f.breathe,f.metabolite,f.other_remark,f.inspection_detail,
  511. IFNULL(g.illness_dead_amount,0) as illness_dead_amount,IFNULL(g.illness_disease_amount,0) as illness_disease_amount,
  512. IFNULL(g.snap_kill_amount,0) as snap_kill_amount,IFNULL(g.unqualified_weight,0) as unqualified_weight,g.deal_way,
  513. slaughter_distribute.id as distribute_batch_id,
  514. slaughter_distribute.slaughter_code,slaughter_distribute.amount as slaughter_amount,slaughter_distribute.before_weight,
  515. slaughter_distribute.side_weight,slaughter_distribute.head_weight,slaughter_distribute.red_weight,slaughter_distribute.white_weight,
  516. slaughter_distribute.supplier_name,slaughter_distribute.purchaser_name,slaughter_distribute.sale_place,
  517. slaughter_distribute.meat_cert,slaughter_distribute.animal_cert
  518. from entrance_batch as a
  519. left join (
  520. select
  521. distribute.entrance_batch_id,
  522. distribute.id,
  523. distribute.slaughter_code,distribute.amount,distribute.weight as before_weight,
  524. supplier.supplier_name,
  525. purchaser.purchaser_name,
  526. slaughter.sale_place,slaughter.meat_cert,slaughter.animal_cert,
  527. (select IFNULL(sum(final_weight),0) from pork_side_produce where distribute_batch_id = distribute.id and del_flag = '0') as side_weight,
  528. (select IFNULL(sum(final_weight),0) from pork_other_produce where distribute_batch_id = distribute.id and product_name='猪头' and del_flag = '0') as head_weight,
  529. (select IFNULL(sum(final_weight),0) from pork_other_produce where distribute_batch_id = distribute.id and product_name='红脏' and del_flag = '0') as red_weight,
  530. (select IFNULL(sum(final_weight),0) from pork_other_produce where distribute_batch_id = distribute.id and product_name='白脏' and del_flag = '0') as white_weight
  531. from distribute_batch as distribute
  532. left join supplier on supplier.id = distribute.supplier_id and supplier.del_flag = '0'
  533. left join purchaser on purchaser.id = distribute.purchaser_id and purchaser.del_flag = '0'
  534. left join slaughter_batch as slaughter on slaughter.distribute_batch_id = distribute.id and slaughter.del_flag = '0'
  535. where distribute.del_flag = '0'
  536. ) as slaughter_distribute on slaughter_distribute.entrance_batch_id = a.id
  537. left join entrance_inspection as f on f.entrance_batch_id = a.id and f.del_flag = '0'
  538. left join harmless_treatment as g on g.entrance_batch_id = a.id and g.del_flag = '0'
  539. <where>
  540. a.del_flag = '0'
  541. <if test="animalCertNo != null "> and a.animal_cert_no = #{animalCertNo}</if>
  542. <if test="slaughterCode != null "> and slaughter_distribute.slaughter_code = #{slaughterCode}</if>
  543. <if test="supplierName != null "> and slaughter_distribute.supplier_name = #{supplierName}</if>
  544. <if test="purchaserName != null "> and slaughter_distribute.purchaser_name = #{purchaserName}</if>
  545. </where>
  546. order by a.entrance_time desc
  547. </select>
  548. <!--入场统计报表-->
  549. <select id="selectEntranceReport" parameterType="com.ruoyi.app.domain.request.ReqEntranceReport" resultMap="entranceReportResultMap">
  550. select
  551. a.entrance_time,a.origin_place,a.animal_cert_no,a.animal_eartags,a.amount,a.weight,
  552. b.supplier_name,
  553. c.illness_dead_amount,c.illness_disease_amount,c.snap_kill_amount,c.unqualified_weight,c.deal_way,c.illness_pigs_detail,
  554. d.inspection_detail
  555. from entrance_batch as a
  556. left join supplier as b on b.id = a.supplier_id and b.del_flag = '0'
  557. left join harmless_treatment as c on c.entrance_batch_id = a.id and c.del_flag = '0'
  558. left join entrance_inspection as d on d.entrance_batch_id = a.id and d.del_flag = '0'
  559. <where>
  560. a.del_flag = '0'
  561. <if test="animalCertNo != null "> and a.animal_cert_no like concat('%', #{animalCertNo}, '%')</if>
  562. <if test="supplierName != null "> and b.supplier_name like concat('%', #{supplierName}, '%')</if>
  563. <if test="entranceTime != null "> and DATE(a.entrance_time) = DATE(#{entranceTime})</if>
  564. </where>
  565. order by a.entrance_time desc
  566. </select>
  567. <!--根据供应商ID统计入场批次数量-->
  568. <select id="countBatchBySupplier" parameterType="Long" resultType="Integer">
  569. select count(1) from entrance_batch
  570. where supplier_id = #{supplierId} and del_flag = '0'
  571. </select>
  572. <select id="selectByAnimalNo" parameterType="string" resultType="com.ruoyi.app.domain.EntranceBatch">
  573. select * from entrance_batch where animal_cert_no=#{anNo}
  574. </select>
  575. </mapper>