OutboundItemCostMapper.xml 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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.OutboundItemCostMapper">
  4. <!-- 通用设置 -->
  5. <!-- 通用查询列 -->
  6. <sql id="Base_Column_List">
  7. batch_id, out_item_id, inv_id, sys.f_remove_zero(out_qty) as out_qty, cost_price, cost_amt,
  8. flg_valid, cp_id, op_create_time, op_create_user_id, op_update_time, op_update_user_id, op_app_code, op_timestamp, op_db_user
  9. </sql>
  10. <!-- 通用查询列Response -->
  11. <sql id="Base_Column_List_Response">
  12. tpoic.batch_id,tpoic.out_item_id, tpoic.inv_id, sys.f_remove_zero(tpoic.out_qty) as out_qty, tpoic.cost_price, tpoic.cost_amt,
  13. tpoic.flg_valid, tpoic.cp_id
  14. </sql>
  15. <!-- 通用查询映射结果 -->
  16. <resultMap id="BaseResultMap" type="com.dk.mdm.model.pojo.ivt.OutboundItemCost">
  17. <id column="batch_id" property="batchId"/>
  18. <result column="out_item_id" property="outItemId" typeHandler="UuidTypeHandler"/>
  19. <result column="inv_id" property="invId" typeHandler="UuidTypeHandler"/>
  20. <result column="out_qty" property="outQty"/>
  21. <result column="cost_price" property="costPrice"/>
  22. <result column="cost_amt" property="costAmt"/>
  23. <result column="flg_valid" property="flgValid"/>
  24. <result column="cp_id" property="cpId"/>
  25. <result column="op_create_time" property="opCreateTime" typeHandler="TimestampTypeHandler"/>
  26. <result column="op_create_user_id" property="opCreateUserId" typeHandler="UuidTypeHandler"/>
  27. <result column="op_update_time" property="opUpdateTime" typeHandler="TimestampTypeHandler"/>
  28. <result column="op_update_user_id" property="opUpdateUserId" typeHandler="UuidTypeHandler"/>
  29. <result column="op_app_code" property="opAppCode"/>
  30. <result column="op_timestamp" property="opTimestamp" typeHandler="TimestampTypeHandler"/>
  31. <result column="op_db_user" property="opDbUser"/>
  32. </resultMap>
  33. <!-- 通用查询映射结果 -->
  34. <resultMap id="BaseResultMapResponse" type="com.dk.mdm.model.response.ivt.OutboundItemCostResponse">
  35. <id column="batch_id" property="batchId"/>
  36. <result column="out_item_id" property="outItemId" typeHandler="UuidTypeHandler"/>
  37. <result column="inv_id" property="invId" typeHandler="UuidTypeHandler"/>
  38. <result column="out_qty" property="outQty"/>
  39. <result column="cost_price" property="costPrice"/>
  40. <result column="cost_amt" property="costAmt"/>
  41. <result column="flg_valid" property="flgValid"/>
  42. <result column="cp_id" property="cpId"/>
  43. </resultMap>
  44. <!-- 通用条件列 -->
  45. <sql id="Condition">
  46. <where>
  47. <if test="outItemId != null and outItemId != ''">
  48. AND tpoic.out_item_id = #{outItemId}::uuid
  49. </if>
  50. <if test="invId != null and invId != ''">
  51. AND tpoic.inv_id = #{invId}
  52. </if>
  53. <if test="outQty != null">
  54. AND tpoic.out_qty = #{outQty}
  55. </if>
  56. <if test="costPrice != null">
  57. AND tpoic.cost_price = #{costPrice}
  58. </if>
  59. <if test="costAmt != null">
  60. AND tpoic.cost_amt = #{costAmt}
  61. </if>
  62. <if test="flgValid != null">
  63. AND tpoic.flg_valid = #{flgValid}
  64. </if>
  65. <if test="cpId != null">
  66. AND tpoic.cp_id = #{cpId}
  67. </if>
  68. </where>
  69. </sql>
  70. <sql id="idsForeach">
  71. <!-- 根据主键batchId批量操作 -->
  72. WHERE batch_id in
  73. <foreach collection="ids" index="index" item="item" separator="," open="(" close=")">
  74. #{item}
  75. </foreach>
  76. </sql>
  77. <!-- 查询表dkic_b.t_psi_outbound_item_cost,(条件查询+分页)列表 -->
  78. <select id="selectByCond" resultMap="BaseResultMapResponse">
  79. SELECT
  80. <include refid="Base_Column_List_Response"/>
  81. FROM dkic_b.t_psi_outbound_item_cost tpoic
  82. <include refid="Condition"/>
  83. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  84. limit #{end} offset #{start}
  85. </if>
  86. </select>
  87. <!-- 查询表dkic_b.t_psi_outbound_item_cost,(条件查询)个数 -->
  88. <select id="countByCond" resultType="Long">
  89. SELECT
  90. count(1)
  91. FROM dkic_b.t_psi_outbound_item_cost tpoic
  92. <include refid="Condition"/>
  93. </select>
  94. <!-- 根据主键查询表dkic_b.t_psi_outbound_item_cost的一行数据 -->
  95. <select id="selectById" resultMap="BaseResultMapResponse">
  96. SELECT
  97. <include refid="Base_Column_List_Response"/>
  98. FROM dkic_b.t_psi_outbound_item_cost tpoic
  99. WHERE tpoic.batch_id = #{id}::uuid
  100. </select>
  101. <!-- 根据主键锁定表dkic_b.t_psi_outbound_item_cost的一行数据 -->
  102. <select id="selectByIdForUpdate" resultMap="BaseResultMap">
  103. SELECT
  104. <include refid="Base_Column_List"/>
  105. FROM dkic_b.t_psi_outbound_item_cost
  106. WHERE batch_id = #{batchId}
  107. for update
  108. </select>
  109. <!-- 根据主键锁定表dkic_b.t_psi_outbound_item_cost的多行数据 -->
  110. <select id="selectByIdsForUpdate" resultMap="BaseResultMap">
  111. SELECT
  112. <include refid="Base_Column_List"/>
  113. FROM dkic_b.t_psi_outbound_item_cost
  114. <include refid="idsForeach"/>
  115. for update
  116. </select>
  117. <insert id="insertBatch">
  118. insert into dkic_b.t_psi_outbound_item_cost
  119. (
  120. <trim suffixOverrides=",">
  121. out_item_id,
  122. inv_id,
  123. out_qty,
  124. cost_price,
  125. cost_amt,
  126. cp_id,
  127. op_app_code,
  128. </trim>
  129. )
  130. values
  131. <foreach collection="list" index="index" item="item" separator=",">
  132. (
  133. <trim suffixOverrides=",">
  134. #{item.outItemId}::uuid,
  135. #{item.invId}::uuid,
  136. #{item.outQty},
  137. #{item.costPrice},
  138. #{item.costAmt},
  139. #{item.cpId},
  140. #{item.opAppCode},
  141. </trim>
  142. )
  143. </foreach>
  144. </insert>
  145. <!--删除数据-->
  146. <delete id="deleteData" >
  147. DELETE
  148. FROM dkic_b.t_psi_outbound_item_cost
  149. where out_item_id = #{id,typeHandler=UuidTypeHandler}
  150. </delete>
  151. <!-- 入库成本核对查询出库成本 -->
  152. <select id="selectCostOutbound" resultMap="BaseResultMapResponse">
  153. SELECT
  154. <include refid="Base_Column_List_Response"/>
  155. FROM dkic_b.t_psi_outbound_item_cost tpoic
  156. where tpoic.batch_id = #{batchId}::uuid
  157. AND tpoic.flg_valid
  158. </select>
  159. <!-- 修改出库成本(入库成本核对)-->
  160. <update id="updateOutboundCost" parameterType="com.dk.mdm.model.pojo.ivt.OutboundItemCost">
  161. update dkic_b.t_psi_outbound_item_cost
  162. set cost_amt = #{costAmt,jdbcType=NUMERIC},
  163. cost_price = #{costPrice,jdbcType=NUMERIC}
  164. where batch_id = #{batchId,typeHandler=UuidTypeHandler}
  165. </update>
  166. <!-- 修改最后一条出库成本(入库成本核对)-->
  167. <update id="updateLastCost" parameterType="com.dk.mdm.model.pojo.ivt.OutboundItemCost">
  168. update dkic_b.t_psi_outbound_item_cost
  169. set cost_amt += #{costAmt,jdbcType=NUMERIC}
  170. where batch_id = #{batchId,typeHandler=UuidTypeHandler}
  171. </update>
  172. </mapper>