GoodsSkuMapper.xml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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.mst.GoodsSkuMapper">
  4. <!-- 通用设置 -->
  5. <!-- 通用查询列 -->
  6. <sql id="Base_Column_List">
  7. sku_id, sku_code, sku_name, sku_model, brand_id, category_id, unit_id, sub_unit_id, conversion_factor
  8. , series_id, sku_spec, price_purchase, price_standard, price_wholesale, price_limited, price_other,sku_images
  9. , remarks, flg_valid, cp_id, op_create_time, op_create_user_id, op_update_time, op_update_user_id
  10. , op_app_code, op_timestamp, op_db_user
  11. </sql>
  12. <!-- 通用查询映射结果 -->
  13. <resultMap id="BaseResultMap" type="com.dk.mdm.model.pojo.mst.GoodsSku">
  14. <id column="sku_id" property="skuId"/>
  15. <result column="sku_code" property="skuCode"/>
  16. <result column="sku_name" property="skuName"/>
  17. <result column="sku_model" property="skuModel"/>
  18. <result column="brand_id" property="brandId" typeHandler="UuidTypeHandler"/>
  19. <result column="category_id" property="categoryId" typeHandler="UuidTypeHandler"/>
  20. <result column="unit_id" property="unitId" typeHandler="UuidTypeHandler"/>
  21. <result column="sub_unit_id" property="subUnitId" typeHandler="UuidTypeHandler"/>
  22. <result column="conversion_factor" property="conversionFactor"/>
  23. <result column="series_id" property="seriesId" typeHandler="UuidTypeHandler"/>
  24. <result column="sku_spec" property="skuSpec"/>
  25. <result column="price_purchase" property="pricePurchase"/>
  26. <result column="price_standard" property="priceStandard"/>
  27. <result column="price_wholesale" property="priceWholesale"/>
  28. <result column="price_limited" property="priceLimited"/>
  29. <result column="price_other" property="priceOther"/>
  30. <result column="sku_images" property="skuImages" typeHandler="JsonTypeHandler"/>
  31. <result column="remarks" property="remarks"/>
  32. <result column="flg_valid" property="flgValid"/>
  33. <result column="cp_id" property="cpId"/>
  34. <result column="op_create_time" property="opCreateTime" typeHandler="TimestampTypeHandler"/>
  35. <result column="op_create_user_id" property="opCreateUserId" typeHandler="UuidTypeHandler"/>
  36. <result column="op_update_time" property="opUpdateTime" typeHandler="TimestampTypeHandler"/>
  37. <result column="op_update_user_id" property="opUpdateUserId" typeHandler="UuidTypeHandler"/>
  38. <result column="op_app_code" property="opAppCode"/>
  39. <result column="op_timestamp" property="opTimestamp" typeHandler="TimestampTypeHandler"/>
  40. <result column="op_db_user" property="opDbUser"/>
  41. </resultMap>
  42. <sql id="Base_Column_List_JOIN">
  43. tmgs.price_other,tmgs.sku_id, tmgs.sku_code, tmgs.sku_name, tmgs.sku_model, tmgs.brand_id, tmgs.category_id, tmgs.unit_id, tmgs.sub_unit_id,
  44. tmgs.conversion_factor, tmgs.series_id, tmgs.sku_spec, tmgs.price_purchase, tmgs.price_standard,
  45. tmgs.pack_box, tmgs.price_wholesale, tmgs.price_limited, tmgs.price_other,tmgs.sku_images, tmgs.remarks, tmgs.flg_valid, tmgs.cp_id
  46. </sql>
  47. <resultMap id="BaseResultMapResponse" type="com.dk.mdm.model.response.mst.GoodsSkuResponse">
  48. <id column="sku_id" property="skuId"/>
  49. <result column="sku_code" property="skuCode"/>
  50. <result column="sku_name" property="skuName"/>
  51. <result column="sku_model" property="skuModel"/>
  52. <result column="brand_id" property="brandId" typeHandler="UuidTypeHandler"/>
  53. <result column="category_id" property="categoryId" typeHandler="UuidTypeHandler"/>
  54. <result column="unit_id" property="unitId" typeHandler="UuidTypeHandler"/>
  55. <result column="sub_unit_id" property="subUnitId" typeHandler="UuidTypeHandler"/>
  56. <result column="conversion_factor" property="conversionFactor"/>
  57. <result column="series_id" property="seriesId" typeHandler="UuidTypeHandler"/>
  58. <result column="sku_spec" property="skuSpec"/>
  59. <result column="price_purchase" property="pricePurchase"/>
  60. <result column="price_standard" property="priceStandard"/>
  61. <result column="price_wholesale" property="priceWholesale"/>
  62. <result column="price_other" property="priceOther"/>
  63. <result column="price_limited" property="priceLimited"/>
  64. <result column="price_other" property="priceOther"/>
  65. <result column="pack_box" property="packBox"/>
  66. <result column="sku_images" property="skuImages" typeHandler="JsonTypeHandler"/>
  67. <result column="remarks" property="remarks"/>
  68. <result column="flg_valid" property="flgValid"/>
  69. <result column="cp_id" property="cpId"/>
  70. </resultMap>
  71. <!-- 通用条件列 -->
  72. <sql id="Condition">
  73. <where>
  74. <if test="skuCode != null and skuCode != ''">
  75. AND tmgs.sku_code = #{skuCode}
  76. </if>
  77. <if test="skuName != null and skuName != ''">
  78. AND tmgs.sku_name = #{skuName}
  79. </if>
  80. <if test="skuModel != null and skuModel != ''">
  81. AND tmgs.sku_model = #{skuModel}
  82. </if>
  83. <if test="brandId != null and brandId != ''">
  84. AND tmgs.brand_id = #{brandId}
  85. </if>
  86. <if test="categoryId != null and categoryId != ''">
  87. AND tmgs.category_id = #{categoryId}::uuid
  88. </if>
  89. <if test="unitId != null and unitId != ''">
  90. AND tmgs.unit_id = #{unitId}
  91. </if>
  92. <if test="subUnitId != null and subUnitId != ''">
  93. AND tmgs.sub_unit_id = #{subUnitId}
  94. </if>
  95. <if test="conversionFactor != null">
  96. AND tmgs.conversion_factor = #{conversionFactor}
  97. </if>
  98. <if test="seriesId != null and seriesId != ''">
  99. AND tmgs.series_id = #{seriesId}::uuid
  100. </if>
  101. <if test="skuSpec != null and skuSpec != ''">
  102. AND tmgs.sku_spec = #{skuSpec}
  103. </if>
  104. <if test="pricePurchase != null">
  105. AND tmgs.price_purchase = #{pricePurchase}
  106. </if>
  107. <if test="priceStandard != null">
  108. AND tmgs.price_standard = #{priceStandard}
  109. </if>
  110. <if test="priceWholesale != null">
  111. AND tmgs.price_wholesale = #{priceWholesale}
  112. </if>
  113. <if test="priceLimited != null">
  114. AND tmgs.price_limited = #{priceLimited}
  115. </if>
  116. <if test="skuImages != null and skuImages != ''">
  117. AND tmgs.sku_images = #{skuImages}
  118. </if>
  119. <if test="remarks != null and remarks != ''">
  120. AND tmgs.remarks = #{remarks}
  121. </if>
  122. <if test="flgValid != null">
  123. AND tmgs.flg_valid = #{flgValid}
  124. </if>
  125. <if test="flgValidList != null and flgValidList.size>0">
  126. AND tmgs.flg_valid =any(#{flgValidList, typeHandler=BooleanListTypeHandler})
  127. </if>
  128. <if test="goodsBrandList != null and goodsBrandList.size>0">
  129. AND tmgs.brand_id =any(#{goodsBrandList, typeHandler=UuidListTypeHandler})
  130. </if>
  131. <if test="cpId != null">
  132. AND tmgs.cp_id = #{cpId}
  133. </if>
  134. <if test="brandIds != null">
  135. AND EXISTS (
  136. SELECT 1
  137. FROM unnest(string_to_array(#{brandIds}, ',')) AS brand_uuid
  138. WHERE brand_uuid::uuid = tmgs.brand_id
  139. )
  140. </if>
  141. <if test="searchText !=null">
  142. AND tmgs.sku_name LIKE concat('%', #{searchText}, '%')
  143. </if>
  144. </where>
  145. </sql>
  146. <sql id="idsForeach">
  147. <!-- 根据主键skuId批量操作 -->
  148. WHERE sku_id in
  149. <foreach collection="ids" index="index" item="item" separator="," open="(" close=")">
  150. #{item}
  151. </foreach>
  152. </sql>
  153. <!-- 查询表t_mst_goods_sku,(条件查询+分页)列表 -->
  154. <select id="selectByCond" resultMap="BaseResultMapResponse">
  155. SELECT
  156. <include refid="Base_Column_List_JOIN"/>
  157. ,tmgb.short_name AS "shortName"
  158. ,tmgb.brand_name AS "brandName",tmgsr.series_name AS "seriesName"
  159. ,COALESCE((SELECT sum(tpi.usable_qty) from dkic_b.t_psi_inventory tpi where tpi.sku_id = tmgs.sku_id and tpi.cp_id = #{cpId} ),0) AS "usableQty"
  160. FROM dkic_b.t_mst_goods_sku tmgs
  161. LEFT JOIN dkic_b.t_mst_goods_brand tmgb ON tmgb.brand_id = tmgs.brand_id
  162. LEFT JOIN dkic_b.t_mst_goods_series tmgsr ON tmgsr.series_id = tmgs.series_id
  163. <include refid="Condition"/>
  164. order by tmgs.op_create_time desc
  165. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  166. limit #{end} offset #{start}
  167. </if>
  168. </select>
  169. <!-- 查询表t_mst_goods_sku,(条件查询)个数 -->
  170. <select id="countByCond" resultType="Long">
  171. SELECT
  172. count(1)
  173. FROM dkic_b.t_mst_goods_sku tmgs
  174. <include refid="Condition"/>
  175. </select>
  176. <!-- 根据主键查询表t_mst_goods_sku的一行数据 -->
  177. <select id="selectById" resultMap="BaseResultMapResponse">
  178. SELECT
  179. <include refid="Base_Column_List_JOIN"/>
  180. ,tmgb.brand_name AS "brandName"
  181. ,tmgc.cat_name AS "catName"
  182. ,tmu.unit_name AS "unitName"
  183. ,subtmu.unit_name AS "subUnitName"
  184. ,tmgsr.series_name AS "seriesName"
  185. FROM dkic_b.t_mst_goods_sku tmgs
  186. LEFT JOIN dkic_b.t_mst_goods_brand tmgb ON tmgb.brand_id = tmgs.brand_id
  187. LEFT JOIN dkic_b.t_mst_goods_category tmgc ON tmgc.cat_id = tmgs.category_id
  188. LEFT JOIN dkic_b.t_mst_unit tmu ON tmu.unit_id = tmgs.unit_id
  189. LEFT JOIN dkic_b.t_mst_unit subtmu ON subtmu.unit_id = tmgs.sub_unit_id
  190. LEFT JOIN dkic_b.t_mst_goods_series tmgsr ON tmgsr.series_id = tmgs.series_id
  191. WHERE tmgs.sku_id = #{id}::uuid
  192. </select>
  193. <!-- 根据主键锁定表t_mst_goods_sku的一行数据 -->
  194. <select id="selectByIdForUpdate" resultMap="BaseResultMap">
  195. SELECT
  196. <include refid="Base_Column_List"/>
  197. FROM dkic_b.t_mst_goods_sku
  198. WHERE sku_id = #{skuId}
  199. for update
  200. </select>
  201. <!-- 根据主键锁定表t_mst_goods_sku的多行数据 -->
  202. <select id="selectByIdsForUpdate" resultMap="BaseResultMap">
  203. SELECT
  204. <include refid="Base_Column_List"/>
  205. FROM dkic_b.t_mst_goods_sku
  206. <include refid="idsForeach"/>
  207. for update
  208. </select>
  209. <insert id="insertBatch">
  210. insert into dkic_b.t_mst_goods_sku
  211. (
  212. <trim suffixOverrides=",">
  213. sku_code,
  214. sku_name,
  215. sku_model,
  216. brand_id,
  217. category_id,
  218. unit_id,
  219. sub_unit_id,
  220. conversion_factor,
  221. series_id,
  222. sku_spec,
  223. price_purchase,
  224. price_standard,
  225. price_wholesale,
  226. price_limited,
  227. sku_images,
  228. remarks,
  229. cp_id,
  230. op_app_code,
  231. </trim>
  232. )
  233. values
  234. <foreach collection="list" index="index" item="item" separator=",">
  235. (
  236. <trim suffixOverrides=",">
  237. #{item.skuCode},
  238. #{item.skuName},
  239. #{item.skuModel},
  240. #{item.brandId}::uuid,
  241. #{item.categoryId}::uuid,
  242. #{item.unitId}::uuid,
  243. #{item.subUnitId}::uuid,
  244. #{item.conversionFactor},
  245. #{item.seriesId}::uuid,
  246. #{item.skuSpec},
  247. #{item.pricePurchase},
  248. #{item.priceStandard},
  249. #{item.priceWholesale},
  250. #{item.priceLimited},
  251. #{item.skuImages},
  252. #{item.remarks},
  253. #{item.cpId},
  254. #{item.opAppCode},
  255. </trim>
  256. )
  257. </foreach>
  258. </insert>
  259. </mapper>