CheckItemMapper.xml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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.dk.mdm.mapper.ivt.CheckItemMapper">
  4. <!-- 通用设置 -->
  5. <!-- 通用查询列 -->
  6. <sql id="Base_Column_List">
  7. item_id, check_id, item_index, sku_id, inv_id, sys.f_remove_zero(inv_qty) as inv_qty, sub_unit_id, unit_id,pack_box,box, piece,
  8. sys.f_remove_zero(check_qty) as check_qty, sys.f_remove_zero(balance_qty) as balance_qty, staff_id, loss_reason, check_date, remarks,
  9. flg_valid, cp_id,
  10. op_create_time, op_create_user_id, op_update_time, op_update_user_id, op_app_code, op_timestamp, op_db_user, sys.f_remove_zero(o_inv_qty) as o_inv_qty
  11. </sql>
  12. <!-- 盘点一览通用查询列 -->
  13. <sql id="Base_Column_List_Response">
  14. item.item_id,item.check_id,item.inv_id
  15. ,sys.f_remove_zero(item.inv_qty) as inv_qty,sys.f_remove_zero(item.o_inv_qty) as o_inv_qty,item.box,item.piece,item.sub_unit_id,item.unit_id,item.pack_box
  16. ,sys.f_remove_zero(item.check_qty) as check_qty,sys.f_remove_zero(item.balance_qty) as balance_qty,item.staff_id
  17. ,item.loss_reason,item.check_date,item.remarks,item.flg_valid,item.cp_id
  18. ,sku.sku_code,sku.sku_name,sku.sku_model,brand.short_name,wh.wh_name
  19. ,dd.data_value AS "lossReasonName",staff.staff_name AS "dutyStaff"
  20. ,item.sku_id,inv.wh_id,inv.non_std_code,item.item_id AS "fromItemId"
  21. ,item.check_id AS "fromId",item.item_index,item.balance_qty AS "intoingQty"
  22. ,abs(item.balance_qty) AS "outingQty",item.price_into,item.intoing_amt
  23. ,0 AS "priceOut",dkic_b.f_box_piece(u2.unit_name,ul.unit_name,item.box,item.piece) AS "boxPiece"
  24. </sql>
  25. <!-- 通用查询映射结果 -->
  26. <resultMap id="BaseResultMap" type="com.dk.mdm.model.pojo.ivt.CheckItem">
  27. <id column="item_id" property="itemId"/>
  28. <result column="check_id" property="checkId" typeHandler="UuidTypeHandler"/>
  29. <result column="item_index" property="itemIndex"/>
  30. <result column="sku_id" property="skuId" typeHandler="UuidTypeHandler"/>
  31. <result column="inv_id" property="invId" typeHandler="UuidTypeHandler"/>
  32. <result column="unit_id" property="unitId" typeHandler="UuidTypeHandler"/>
  33. <result column="sub_unit_id" property="subUnitId" typeHandler="UuidTypeHandler"/>
  34. <result column="pack_box" property="packBox"/>
  35. <result column="inv_qty" property="invQty"/>
  36. <result column="box" property="box"/>
  37. <result column="piece" property="piece"/>
  38. <result column="check_qty" property="checkQty"/>
  39. <result column="balance_qty" property="balanceQty"/>
  40. <result column="price_into" property="priceInto"/>
  41. <result column="intoing_amt" property="intoingAmt"/>
  42. <result column="staff_id" property="staffId" typeHandler="UuidTypeHandler"/>
  43. <result column="loss_reason" property="lossReason" typeHandler="UuidTypeHandler"/>
  44. <result column="check_date" property="checkDate" typeHandler="TimestampTypeHandler"/>
  45. <result column="remarks" property="remarks"/>
  46. <result column="flg_valid" property="flgValid"/>
  47. <result column="cp_id" property="cpId"/>
  48. <result column="op_create_time" property="opCreateTime" typeHandler="TimestampTypeHandler"/>
  49. <result column="op_create_user_id" property="opCreateUserId" typeHandler="UuidTypeHandler"/>
  50. <result column="op_update_time" property="opUpdateTime" typeHandler="TimestampTypeHandler"/>
  51. <result column="op_update_user_id" property="opUpdateUserId" typeHandler="UuidTypeHandler"/>
  52. <result column="op_app_code" property="opAppCode"/>
  53. <result column="op_timestamp" property="opTimestamp" typeHandler="TimestampTypeHandler"/>
  54. <result column="op_db_user" property="opDbUser"/>
  55. <result column="o_inv_qty" property="oInvQty"/>
  56. <result column="decimalPlaces" property="decimalPlaces"/>
  57. </resultMap>
  58. <!-- 盘点一览查询映射结果 -->
  59. <resultMap id="BaseResultMapResponse" type="com.dk.mdm.model.response.ivt.CheckItemResponse">
  60. <id column="item_id" property="itemId"/>
  61. <result column="check_id" property="checkId" typeHandler="UuidTypeHandler"/>
  62. <result column="item_index" property="itemIndex"/>
  63. <result column="sku_id" property="skuId" typeHandler="UuidTypeHandler"/>
  64. <result column="inv_id" property="invId" typeHandler="UuidTypeHandler"/>
  65. <result column="unit_id" property="unitId" typeHandler="UuidTypeHandler"/>
  66. <result column="sub_unit_id" property="subUnitId" typeHandler="UuidTypeHandler"/>
  67. <result column="pack_box" property="packBox"/>
  68. <result column="inv_qty" property="invQty"/>
  69. <result column="box" property="box"/>
  70. <result column="piece" property="piece"/>
  71. <result column="check_qty" property="checkQty"/>
  72. <result column="balance_qty" property="balanceQty"/>
  73. <result column="price_into" property="priceInto"/>
  74. <result column="intoing_amt" property="intoingAmt"/>
  75. <result column="staff_id" property="staffId" typeHandler="UuidTypeHandler"/>
  76. <result column="loss_reason" property="lossReason" typeHandler="UuidTypeHandler"/>
  77. <result column="check_date" property="checkDate" typeHandler="TimestampTypeHandler"/>
  78. <result column="remarks" property="remarks"/>
  79. <result column="flg_valid" property="flgValid"/>
  80. <result column="cp_id" property="cpId"/>
  81. <result column="op_create_time" property="opCreateTime" typeHandler="TimestampTypeHandler"/>
  82. <result column="op_create_user_id" property="opCreateUserId" typeHandler="UuidTypeHandler"/>
  83. <result column="op_update_time" property="opUpdateTime" typeHandler="TimestampTypeHandler"/>
  84. <result column="op_update_user_id" property="opUpdateUserId" typeHandler="UuidTypeHandler"/>
  85. <result column="op_app_code" property="opAppCode"/>
  86. <result column="sku_images" property="skuImages" typeHandler="JsonTypeHandler"/>
  87. <result column="op_timestamp" property="opTimestamp" typeHandler="TimestampTypeHandler"/>
  88. <result column="op_db_user" property="opDbUser"/>
  89. <result column="o_inv_qty" property="oInvQty"/>
  90. <result column="decimalPlaces" property="decimalPlaces"/>
  91. </resultMap>
  92. <!-- 通用条件列 -->
  93. <sql id="Condition">
  94. <where>
  95. <if test="checkId != null and checkId != ''">
  96. AND check_id = #{checkId}::uuid
  97. </if>
  98. <if test="itemIndex != null">
  99. AND item_index = #{itemIndex}
  100. </if>
  101. <if test="skuId != null and skuId != ''">
  102. AND sku_id = #{skuId}
  103. </if>
  104. <if test="invId != null and invId != ''">
  105. AND inv_id = #{invId}
  106. </if>
  107. <if test="invQty != null">
  108. AND inv_qty = #{invQty}
  109. </if>
  110. <if test="checkQty != null">
  111. AND check_qty = #{checkQty}
  112. </if>
  113. <if test="balanceQty != null">
  114. AND balance_qty = #{balanceQty}
  115. </if>
  116. <if test="staffId != null and staffId != ''">
  117. AND staff_id = #{staffId}
  118. </if>
  119. <if test="lossReason != null and lossReason != ''">
  120. AND loss_reason = #{lossReason}
  121. </if>
  122. <if test="checkDate != null">
  123. AND check_date = #{checkDate}
  124. </if>
  125. <if test="remarks != null and remarks != ''">
  126. AND remarks = #{remarks}
  127. </if>
  128. <if test="flgValid != null">
  129. AND flg_valid = #{flgValid}
  130. </if>
  131. <if test="cpId != null">
  132. AND cp_id = #{cpId}
  133. </if>
  134. <if test="opCreateTime != null">
  135. AND op_create_time = #{opCreateTime}
  136. </if>
  137. <if test="opCreateUserId != null and opCreateUserId != ''">
  138. AND op_create_user_id = #{opCreateUserId}
  139. </if>
  140. <if test="opUpdateTime != null">
  141. AND op_update_time = #{opUpdateTime}
  142. </if>
  143. <if test="opUpdateUserId != null and opUpdateUserId != ''">
  144. AND op_update_user_id = #{opUpdateUserId}
  145. </if>
  146. <if test="opAppCode != null and opAppCode != ''">
  147. AND op_app_code = #{opAppCode}
  148. </if>
  149. <if test="opTimestamp != null">
  150. AND op_timestamp = #{opTimestamp}
  151. </if>
  152. <if test="opDbUser != null and opDbUser != ''">
  153. AND op_db_user = #{opDbUser}
  154. </if>
  155. <if test="oInvQty != null">
  156. AND o_inv_qty = #{oInvQty}
  157. </if>
  158. </where>
  159. </sql>
  160. <!-- 盘点一览条件列 -->
  161. <sql id="Condition_Response">
  162. <where>
  163. <if test="checkId != null and checkId != ''">
  164. AND item.check_id = #{checkId}::uuid
  165. </if>
  166. </where>
  167. </sql>
  168. <sql id="idsForeach">
  169. <!-- 根据主键itemId批量操作 -->
  170. WHERE item_id in
  171. <foreach collection="ids" index="index" item="item" separator="," open="(" close=")">
  172. #{item}
  173. </foreach>
  174. </sql>
  175. <!-- 查询表t_psi_check_item,(条件查询+分页)列表 -->
  176. <select id="selectByCond" resultMap="BaseResultMapResponse">
  177. SELECT
  178. <include refid="Base_Column_List_Response"/>
  179. ,sku.sku_images
  180. ,ul.decimal_places as "decimalPlaces"
  181. FROM dkic_b.t_psi_check_item AS item
  182. LEFT JOIN dkic_b.t_mst_goods_sku AS sku ON item.sku_id=sku.sku_id
  183. LEFT JOIN dkic_b.t_mst_unit AS ul ON item.unit_id = ul.unit_id
  184. LEFT JOIN dkic_b.t_mst_unit AS u2 ON item.sub_unit_id = u2.unit_id
  185. LEFT JOIN dkic_b.t_psi_inventory AS inv ON inv.inv_id=item.inv_id
  186. LEFT JOIN dkic_b.t_mst_warehouse AS wh ON wh.wh_id=inv.wh_id
  187. LEFT JOIN dkic_b.t_mst_goods_brand AS brand ON brand.brand_id=sku.brand_id
  188. LEFT JOIN dkic_b.t_mst_staff AS staff ON staff.staff_id=item.staff_id
  189. left join dkic_b.t_mst_dictionary_data AS dd ON dd.data_id=item.loss_reason
  190. <include refid="Condition_Response"/>
  191. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  192. limit #{end} offset #{start}
  193. </if>
  194. </select>
  195. <!-- 查询表t_psi_check_item,(条件查询)个数 -->
  196. <select id="countByCond" resultType="Long">
  197. SELECT
  198. count(1)
  199. FROM dkic_b.t_psi_check_item
  200. <include refid="Condition"/>
  201. </select>
  202. <!-- 根据主键查询表t_psi_check_item的一行数据 -->
  203. <select id="selectById" resultMap="BaseResultMap">
  204. SELECT
  205. <include refid="Base_Column_List"/>
  206. ,(select ul.decimal_places from dkic_b.t_mst_unit ul where dkic_b.t_psi_check_item.unit_id = ul.unit_id) as "decimalPlaces"
  207. FROM dkic_b.t_psi_check_item
  208. WHERE item_id = #{id}::uuid
  209. </select>
  210. <!-- 根据主键锁定表t_psi_check_item的一行数据 -->
  211. <select id="selectByIdForUpdate" resultMap="BaseResultMap">
  212. SELECT
  213. <include refid="Base_Column_List"/>
  214. FROM dkic_b.t_psi_check_item
  215. ,(select ul.decimal_places from dkic_b.t_mst_unit ul where dkic_b.t_psi_check_item.unit_id = ul.unit_id) as "decimalPlaces"
  216. WHERE item_id = #{itemId}
  217. for update
  218. </select>
  219. <!-- 根据主键锁定表t_psi_check_item的多行数据 -->
  220. <select id="selectByIdsForUpdate" resultMap="BaseResultMap">
  221. SELECT
  222. <include refid="Base_Column_List"/>
  223. FROM dkic_b.t_psi_check_item
  224. ,(select ul.decimal_places from dkic_b.t_mst_unit ul where dkic_b.t_psi_check_item.unit_id = ul.unit_id) as "decimalPlaces"
  225. <include refid="idsForeach"/>
  226. for update
  227. </select>
  228. <insert id="insertBatch">
  229. insert into t_psi_check_item
  230. (
  231. <trim suffixOverrides=",">
  232. check_id,
  233. item_index,
  234. sku_id,
  235. inv_id,
  236. inv_qty,
  237. check_qty,
  238. balance_qty,
  239. staff_id,
  240. loss_reason,
  241. check_date,
  242. remarks,
  243. cp_id,
  244. op_app_code,
  245. o_inv_qty,
  246. </trim>
  247. )
  248. values
  249. <foreach collection="list" index="index" item="item" separator=",">
  250. (
  251. <trim suffixOverrides=",">
  252. #{item.checkId}::uuid,
  253. #{item.itemIndex},
  254. #{item.skuId}::uuid,
  255. #{item.invId}::uuid,
  256. #{item.invQty},
  257. #{item.checkQty},
  258. #{item.balanceQty},
  259. #{item.staffId}::uuid,
  260. #{item.lossReason}::uuid,
  261. #{item.checkDate},
  262. #{item.remarks},
  263. #{item.cpId},
  264. #{item.opAppCode},
  265. #{item.oInvQty},
  266. </trim>
  267. )
  268. </foreach>
  269. </insert>
  270. </mapper>