You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

306 lines
11 KiB

1 year ago
​
​
​
​
​
​
1 year ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
11 months ago
​
​
​
1 year ago
​
​
​
​
​
​
​
​
​
​
​
​
​
1 year ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
1 year ago
​
11 months ago
​
​
​
​
1 year ago
​
1 month ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 weeks ago
1 month ago
​
​
​
1 year ago
11 months ago
1 year ago
1 year ago
​
​
​
​
​
​
​
​
​
​
11 months ago
1 year ago
​
​
​
​
11 months ago
1 year ago
1 year ago
​
​
​
​
​
​
​
​
​
​
​
11 months ago
1 year ago
​
​
​
​
​
​
​
​
​
​
​
​
​
11 months ago
1 year ago
1 year ago
​
​
​
​
​
​
​
​
​
​
​
11 months ago
1 year ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
1 year ago
1 year ago
​
1 year ago
​
​
​
​
​
​
​
​
2 months ago
​
​
​
​
​
​
1 month ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
1 month ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
1 year ago
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.gaotao.modules.handlingunit.dao.HandlingUnitMapper">
  4. <!-- 查询处理单元列表 -->
  5. <select id="selectHandlingUnitList" resultType="com.gaotao.modules.handlingunit.entity.dto.HandlingUnitDto">
  6. SELECT
  7. h.unit_id,
  8. h.site,
  9. h.parent_unit_id,
  10. h.unit_type,
  11. h.unit_type_db,
  12. h.part_no,
  13. h.part_desc,
  14. h.qty,
  15. h.batch_no,
  16. h.location_id,
  17. h.warehouse_id,
  18. h.wdr,
  19. h.availability_control_id,
  20. h.status,
  21. h.status_db,
  22. h.freeze_flag,
  23. h.merged_flag,
  24. h.in_stock_flag,
  25. h.created_date,
  26. h.created_by,
  27. h.remark,
  28. h.print_count,
  29. h.last_print_date,
  30. p.unit_id as parent_unit_info,
  31. (SELECT COUNT(1) FROM handling_unit c WITH (NOLOCK) WHERE c.site = h.site AND c.parent_unit_id = h.unit_id) as children_count,
  32. (SELECT COUNT(1) FROM handling_unit_detail d WITH (NOLOCK) WHERE d.site = h.site AND d.unit_id = h.unit_id) as detail_count
  33. FROM handling_unit h WITH (NOLOCK)
  34. LEFT JOIN handling_unit p WITH (NOLOCK) ON h.site = p.site AND h.parent_unit_id = p.unit_id
  35. WHERE h.site = #{dto.site}
  36. <if test="dto.unitIdLike != null and dto.unitIdLike != ''">
  37. AND h.unit_id LIKE CONCAT('%', #{dto.unitIdLike}, '%')
  38. </if>
  39. <if test="dto.partNoLike != null and dto.partNoLike != ''">
  40. AND h.part_no LIKE CONCAT('%', #{dto.partNoLike}, '%')
  41. </if>
  42. <if test="dto.batchNoLike != null and dto.batchNoLike != ''">
  43. AND h.batch_no LIKE CONCAT('%', #{dto.batchNoLike}, '%')
  44. </if>
  45. <if test="dto.locationIdLike != null and dto.locationIdLike != ''">
  46. AND h.location_id LIKE CONCAT('%', #{dto.locationIdLike}, '%')
  47. </if>
  48. <if test="dto.statusList != null and dto.statusList != ''">
  49. AND h.status_db IN
  50. <foreach collection="dto.statusList.split(',')" item="status" open="(" separator="," close=")">
  51. #{status}
  52. </foreach>
  53. </if>
  54. <if test="dto.createdDateFrom != null">
  55. AND h.created_date >= #{dto.createdDateFrom}
  56. </if>
  57. <if test="dto.createdDateTo != null">
  58. AND h.created_date &lt;= #{dto.createdDateTo}
  59. </if>
  60. ORDER BY h.created_date DESC
  61. LIMIT 100
  62. </select>
  63. <!-- 查询处理单元详情 -->
  64. <select id="selectHandlingUnitDetail" resultType="com.gaotao.modules.handlingunit.entity.dto.HandlingUnitDto">
  65. SELECT
  66. h.*,
  67. p.unit_id as parent_unit_info,
  68. (SELECT COUNT(1) FROM handling_unit c WITH (NOLOCK) WHERE c.site = h.site AND c.parent_unit_id = h.unit_id) as children_count,
  69. (SELECT COUNT(1) FROM handling_unit_detail d WITH (NOLOCK) WHERE d.site = h.site AND d.unit_id = h.unit_id) as detail_count
  70. FROM handling_unit h WITH (NOLOCK)
  71. LEFT JOIN handling_unit p WITH (NOLOCK) ON h.site = p.site AND h.parent_unit_id = p.unit_id
  72. WHERE h.unit_id = #{unitId}
  73. <if test="site != null and site != ''">
  74. AND h.site = #{site}
  75. </if>
  76. </select>
  77. <select id="selectByUnitIdNoLock" resultType="com.gaotao.modules.handlingunit.entity.HandlingUnit">
  78. SELECT unit_id,
  79. site,
  80. parent_unit_id,
  81. unit_type,
  82. unit_type_db,
  83. part_no,
  84. part_desc,
  85. qty,
  86. batch_no,
  87. location_id,
  88. warehouse_id,
  89. wdr,
  90. availability_control_id,
  91. status,
  92. status_db,
  93. freeze_flag,
  94. merged_flag,
  95. in_stock_flag,
  96. supplier_manufacture_date,
  97. supplier_batch_no,um_id
  98. FROM handling_unit WITH (NOLOCK)
  99. WHERE unit_id = #{unitId}
  100. </select>
  101. <!-- 查询子处理单元 -->
  102. <!-- 注意:不能用NOLOCK,结果用于装箱/拆箱后updateHandlingUnit,脏读可能导致数据不一致 - rqrq -->
  103. <select id="selectChildUnits" resultType="com.gaotao.modules.handlingunit.entity.dto.HandlingUnitDto">
  104. SELECT
  105. unit_id,
  106. site,
  107. unit_type,
  108. part_no,
  109. part_desc,
  110. qty,
  111. batch_no,
  112. location_id,
  113. status,
  114. status_db,
  115. created_date
  116. FROM handling_unit
  117. WHERE site = #{site} AND parent_unit_id = #{parentUnitId}
  118. ORDER BY created_date
  119. </select>
  120. <!-- 查询可装箱的单元 -->
  121. <!-- 优化:添加 WITH (NOLOCK) 避免死锁 - rqrq -->
  122. <select id="selectAvailableUnitsForPacking" resultType="com.gaotao.modules.handlingunit.entity.dto.HandlingUnitDto">
  123. SELECT
  124. unit_id,
  125. site,
  126. unit_type,
  127. part_no,
  128. part_desc,
  129. qty,
  130. batch_no,
  131. location_id,
  132. warehouse_id,
  133. status,
  134. status_db,
  135. created_date
  136. FROM handling_unit
  137. WHERE site = #{site}
  138. AND status_db = 'A'
  139. AND parent_unit_id IS NULL
  140. <if test="locationId != null and locationId != ''">
  141. AND location_id = #{locationId}
  142. </if>
  143. <if test="warehouseId != null and warehouseId != ''">
  144. AND warehouse_id = #{warehouseId}
  145. </if>
  146. ORDER BY created_date DESC
  147. LIMIT 50
  148. </select>
  149. <!-- 查询可合并的单元 -->
  150. <!-- 注意:不能用NOLOCK,结果用于合并后updateHandlingUnit,脏读可能导致重复合并 - rqrq -->
  151. <select id="selectAvailableUnitsForMerge" resultType="com.gaotao.modules.handlingunit.entity.dto.HandlingUnitDto">
  152. SELECT
  153. unit_id,
  154. site,
  155. unit_type,
  156. part_no,
  157. part_desc,
  158. qty,
  159. batch_no,
  160. location_id,
  161. warehouse_id,
  162. status,
  163. status_db,
  164. created_date
  165. FROM handling_unit
  166. WHERE site = #{site}
  167. AND status_db = 'A'
  168. AND parent_unit_id IS NULL
  169. <if test="partNo != null and partNo != ''">
  170. AND part_no = #{partNo}
  171. </if>
  172. <if test="batchNo != null and batchNo != ''">
  173. AND batch_no = #{batchNo}
  174. </if>
  175. <if test="locationId != null and locationId != ''">
  176. AND location_id = #{locationId}
  177. </if>
  178. ORDER BY created_date DESC
  179. LIMIT 50
  180. </select>
  181. <!-- 更新打印信息 -->
  182. <!-- rqrq - 移除ROWLOCK,由数据库自动管理锁粒度 -->
  183. <update id="updatePrintInfo">
  184. UPDATE handling_unit
  185. SET printer_name = #{printerName},
  186. print_count = #{printCount},
  187. last_print_date = GETDATE()
  188. WHERE site = #{site} AND unit_id = #{unitId}
  189. </update>
  190. <!-- 更新HandlingUnit打印信息(打印次数+1,更新最后打印时间和打印人) -->
  191. <!-- rqrq - 移除ROWLOCK,由数据库自动管理锁粒度 -->
  192. <update id="updateHandlingUnitPrintInfo">
  193. UPDATE handling_unit
  194. SET print_count = ISNULL(print_count, 0) + 1,
  195. last_print_date = GETDATE(),
  196. printer_name = #{printerName},
  197. modified_by = #{printedBy},
  198. modified_date = GETDATE()
  199. WHERE site = #{site} AND unit_id = #{unitId}
  200. </update>
  201. <!-- 取消WMS预定 - rqrq -->
  202. <!-- rqrq - 移除ROWLOCK,由数据库自动管理锁粒度 -->
  203. <update id="cancelReserve">
  204. UPDATE handling_unit
  205. SET reserve_flag = 'N',
  206. reserve_order_ref1 = NULL,
  207. reserve_order_ref2 = NULL,
  208. reserve_order_ref3 = NULL,
  209. modified_date = GETDATE()
  210. WHERE site = #{site} AND unit_id = #{unitId}
  211. </update>
  212. <!-- rqrq - 必须查出 expired_date、eng_chg_level,海安移库分组和JSON按这两个字段取值;NOLOCK 避免与上游更新锁等待 -->
  213. <select id="selectByUnitIds" resultType="com.gaotao.modules.handlingunit.entity.HandlingUnit">
  214. SELECT
  215. unit_id,
  216. site,
  217. parent_unit_id,
  218. unit_type,
  219. unit_type_db,
  220. part_no,
  221. part_desc,
  222. qty,
  223. batch_no,
  224. location_id,
  225. warehouse_id,
  226. wdr,
  227. availability_control_id,
  228. expired_date,
  229. eng_chg_level,
  230. status,
  231. status_db,
  232. freeze_flag,
  233. merged_flag,
  234. in_stock_flag,
  235. created_date,
  236. created_by,
  237. remark,
  238. print_count,
  239. last_print_date
  240. FROM handling_unit WITH (NOLOCK)
  241. WHERE site = #{site} AND unit_id IN
  242. <foreach collection="unitIds" item="unitId" open="(" separator="," close=")">
  243. #{unitId}
  244. </foreach>
  245. </select>
  246. <!-- 批量更新HandlingUnit的收货日期和失效日期 -->
  247. <!-- 单条 UPDATE + CASE WHEN,避免多语句被 Druid 拦截 -->
  248. <!-- rqrq - 移除ROWLOCK,由数据库自动管理锁粒度 -->
  249. <update id="updateExpiredDate">
  250. <if test="handlingUnits != null and handlingUnits.size() > 0">
  251. UPDATE handling_unit
  252. SET
  253. receive_date = CASE
  254. <foreach collection="handlingUnits" item="item">
  255. <if test="item.receiveDate != null">
  256. WHEN site = #{item.site} AND unit_id = #{item.unitId} THEN #{item.receiveDate}
  257. </if>
  258. </foreach>
  259. ELSE receive_date
  260. END,
  261. expired_date = CASE
  262. <foreach collection="handlingUnits" item="item">
  263. <if test="item.expiredDate != null">
  264. WHEN site = #{item.site} AND unit_id = #{item.unitId} THEN #{item.expiredDate}
  265. </if>
  266. </foreach>
  267. ELSE expired_date
  268. END,
  269. modified_date = GETDATE()
  270. WHERE
  271. <foreach collection="handlingUnits" item="item" separator=" OR ">
  272. (site = #{item.site} AND unit_id = #{item.unitId})
  273. </foreach>
  274. </if>
  275. </update>
  276. <!-- 跨site移库改标签:WHERE 卡来源site+在库,防止校验后被并发改出库;site/库位/仓库必须一次改完 -->
  277. <update id="updateSiteAndLocationForCrossSiteMove">
  278. UPDATE handling_unit WITH (ROWLOCK)
  279. SET site = #{destSite},
  280. location_id = #{targetLocationId},
  281. warehouse_id = #{warehouseId},
  282. modified_by = #{modifiedBy},
  283. modified_date = GETDATE(),
  284. in_stock_flag = 'Y'
  285. WHERE site = #{fromSite}
  286. AND in_stock_flag = 'Y'
  287. AND (reserve_flag = 'N' OR reserve_flag IS NULL)
  288. AND unit_id IN
  289. <foreach collection="unitIds" item="unitId" open="(" separator="," close=")">
  290. #{unitId}
  291. </foreach>
  292. </update>
  293. </mapper>