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.

153 lines
5.5 KiB

  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.check.mapper.CountAdjustmentMapper">
  4. <!-- rqrq - 统计需要系统处理的异常结果数量 -->
  5. <select id="countSystemHandleRecords" resultType="int">
  6. SELECT COUNT(1)
  7. FROM count_result
  8. WHERE site = #{site}
  9. AND count_no = #{countNo}
  10. AND handle_flag = 'N'
  11. AND handle_type = 'SYSTEM'
  12. AND count_result != 'SURPLUS'
  13. AND count_result != 'OK'
  14. </select>
  15. <!-- rqrq - 查询待系统处理的标签明细(排除SURPLUS类型)-->
  16. <select id="querySystemHandleLabels" resultType="CountAdjustmentLabelItem">
  17. SELECT
  18. r.id AS countResultId,
  19. r.count_no AS countNo,
  20. r.count_result AS countResult,
  21. r.diff_qty AS diffQty,
  22. r.site AS site,
  23. r.unit_id AS unitId,
  24. r.pallet_id AS palletId,
  25. h.part_no AS partNo,
  26. h.qty AS qty,
  27. h.batch_no AS batchNo,
  28. h.location_id AS locationId,
  29. h.warehouse_id AS warehouseId,
  30. h.wdr AS wdr,
  31. h.expired_date AS expiredDate,
  32. h.eng_chg_level AS engChgLevel
  33. FROM count_result r
  34. LEFT JOIN handling_unit h ON r.site = h.site AND r.unit_id = h.unit_id
  35. WHERE r.site = #{site}
  36. AND r.count_no = #{countNo}
  37. AND r.handle_flag = 'N'
  38. AND r.handle_type = 'SYSTEM'
  39. AND r.count_result != 'SURPLUS'
  40. AND r.count_result != 'OK'
  41. ORDER BY r.id
  42. </select>
  43. <!-- rqrq - 插入事务明细 -->
  44. <insert id="insertTransDetail">
  45. INSERT INTO trans_detail (
  46. site, trans_no, item_no, part_no, trans_qty,
  47. batch_no, location_id, direction, wdr_no, eng_chg_level
  48. ) VALUES (
  49. #{site}, #{transNo}, #{itemNo}, #{partNo}, #{transQty},
  50. #{batchNo}, #{locationId}, #{direction}, #{wdrNo}, #{engChgLevel}
  51. )
  52. </insert>
  53. <!-- rqrq - 插入事务子明细(sub_no是标签号,seq_no是序号,direction是+/--->
  54. <insert id="insertTransDetailSub">
  55. INSERT INTO trans_detail_sub (
  56. site, trans_no, item_no, seq_no, sub_no, sub_qty, direction,
  57. part_no, batch_no, location_id, eng_chg_level, order_ref1, order_ref3, order_ref4
  58. ) VALUES (
  59. #{site}, #{transNo}, #{itemNo}, #{seqNo}, #{subNo}, #{subQty}, #{direction},
  60. #{partNo}, #{batchNo}, #{locationId}, #{engChgLevel}, #{orderRef1}, #{orderRef3}, #{orderRef4}
  61. )
  62. </insert>
  63. <!-- rqrq - 更新标签数量 -->
  64. <update id="updateHandlingUnitQty">
  65. UPDATE handling_unit
  66. SET qty = #{qty},
  67. in_stock_flag = #{inStockFlag},
  68. modified_by = #{username},
  69. modified_date = GETDATE()
  70. WHERE site = #{site}
  71. AND unit_id = #{unitId}
  72. </update>
  73. <!-- rqrq - 更新盘点结果处理标记 -->
  74. <update id="updateCountResultHandleFlag">
  75. UPDATE count_result
  76. SET handle_flag = 'Y'
  77. WHERE id = #{countResultId}
  78. </update>
  79. <!-- rqrq - 查询盘盈盘亏事务头和明细 -->
  80. <select id="queryAdjustmentTransList" resultType="CountAdjustmentTransData">
  81. SELECT
  82. h.site,
  83. h.trans_no AS transNo,
  84. h.trans_date AS transDate,
  85. h.trans_type_db AS transTypeDb,
  86. CASE h.trans_type_db
  87. WHEN 'PK' THEN '盘亏'
  88. WHEN 'PY' THEN '盘盈'
  89. ELSE h.trans_type_db
  90. END AS transTypeDesc,
  91. h.warehouse_id AS warehouseId,
  92. h.order_ref1 AS orderRef1,
  93. h.remark,
  94. h.user_name AS userName,
  95. d.item_no AS itemNo,
  96. d.part_no AS partNo,
  97. d.trans_qty AS transQty,
  98. d.batch_no AS batchNo,
  99. d.location_id AS locationId,
  100. d.direction,
  101. CASE d.direction
  102. WHEN '+' THEN '入库'
  103. WHEN '-' THEN '出库'
  104. ELSE d.direction
  105. END AS directionDesc,
  106. d.wdr_no AS wdrNo,
  107. d.eng_chg_level AS engChgLevel
  108. FROM trans_header h
  109. INNER JOIN trans_detail d ON h.site = d.site AND h.trans_no = d.trans_no
  110. WHERE h.site = #{site}
  111. AND h.order_ref1 = #{countNo}
  112. AND h.trans_type_db IN ('PK', 'PY')
  113. ORDER BY h.trans_no, d.item_no
  114. </select>
  115. <!-- rqrq - 查询事务子明细(sub_no就是标签号unit_id) -->
  116. <select id="queryAdjustmentTransSubList" resultType="CountAdjustmentTransSubData">
  117. SELECT
  118. site,
  119. trans_no AS transNo,
  120. item_no AS itemNo,
  121. seq_no AS seqNo,
  122. sub_no AS subNo,
  123. sub_qty AS subQty,
  124. direction,
  125. CASE direction
  126. WHEN '+' THEN '入库'
  127. WHEN '-' THEN '出库'
  128. ELSE direction
  129. END AS directionDesc,
  130. part_no AS partNo,
  131. batch_no AS batchNo,
  132. location_id AS locationId,
  133. eng_chg_level AS engChgLevel,
  134. order_ref1 AS palletId,
  135. order_ref3 AS wdr,
  136. order_ref4 AS warehouseId
  137. FROM trans_detail_sub
  138. WHERE site = #{site}
  139. AND trans_no = #{transNo}
  140. ORDER BY item_no, seq_no
  141. </select>
  142. </mapper>