ApiGoodsMapper.xml 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  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.kmall.api.dao.ApiGoodsMapper">
  4. <!-- 可根据自己的需求,是否要使用 -->
  5. <resultMap type="com.kmall.api.entity.GoodsVo" id="goodsMap">
  6. <result property="id" column="id"/>
  7. <result property="category_id" column="category_id"/>
  8. <result property="goods_sn" column="goods_sn"/>
  9. <result property="name" column="name"/>
  10. <result property="brand_id" column="brand_id"/>
  11. <result property="goods_number" column="goods_number"/>
  12. <result property="keywords" column="keywords"/>
  13. <result property="goods_brief" column="goods_brief"/>
  14. <result property="goods_desc" column="goods_desc"/>
  15. <result property="is_on_sale" column="is_on_sale"/>
  16. <result property="add_time" column="add_time"/>
  17. <result property="sort_order" column="sort_order"/>
  18. <result property="is_delete" column="is_delete"/>
  19. <result property="attribute_category" column="attribute_category"/>
  20. <result property="counter_price" column="counter_price"/>
  21. <result property="extra_price" column="extra_price"/>
  22. <result property="is_new" column="is_new"/>
  23. <result property="goods_unit" column="goods_unit"/>
  24. <result property="primary_pic_url" column="primary_pic_url"/>
  25. <result property="list_pic_url" column="list_pic_url"/>
  26. <result property="retail_price" column="retail_price"/>
  27. <result property="market_price" column="market_price"/>
  28. <result property="sell_volume" column="sell_volume"/>
  29. <result property="primary_product_id" column="primary_product_id"/>
  30. <result property="unit_price" column="unit_price"/>
  31. <result property="promotion_desc" column="promotion_desc"/>
  32. <result property="promotion_tag" column="promotion_tag"/>
  33. <result property="app_exclusive_price" column="app_exclusive_price"/>
  34. <result property="is_app_exclusive" column="is_app_exclusive"/>
  35. <result property="is_limited" column="is_limited"/>
  36. <result property="is_hot" column="is_hot"/>
  37. <result property="product_id" column="product_id"/>
  38. <result property="sku" column="sku"/>
  39. <result property="goodsBizType" column="goods_biz_type"/>
  40. <result column="creater_sn" property="createrSn" jdbcType="VARCHAR" />
  41. <result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
  42. <result column="moder_sn" property="moderSn" jdbcType="VARCHAR" />
  43. <result column="mod_time" property="modTime" jdbcType="TIMESTAMP" />
  44. <result column="tstm" property="tstm" jdbcType="TIMESTAMP" />
  45. <result property="goodsRate" column="goods_rate"/>
  46. <result property="stockNum" column="stock_num"/>
  47. <result property="storeId" column="store_id"/>
  48. <result property="merchSn" column="merch_sn"/>
  49. <result property="merchName" column="merch_name"/>
  50. <result column="third_party_merch_code" property="thirdPartyMerchCode" />
  51. <result column="isStockShare" property="isStockShare" />
  52. <result property="goods_sell_volume" column="goods_sell_volume"/>
  53. </resultMap>
  54. <sql id="Base_Column_List" >
  55. id, goods_sn, sku, goods_biz_type, name, goods_number, keywords,
  56. goods_brief, is_on_sale, add_time, sort_order, is_delete, counter_price,
  57. extra_price, is_new, goods_unit, primary_pic_url, list_pic_url, retail_price, sell_volume,
  58. primary_product_id, unit_price, promotion_desc, promotion_tag, app_exclusive_price,
  59. is_app_exclusive, is_limited, is_hot, market_price, creater_sn, create_time, moder_sn,
  60. mod_time, tstm,goods_desc,goods_rate,third_party_merch_code
  61. </sql>
  62. <select id="queryObject" resultMap="goodsMap">
  63. select a.id,
  64. psr1.category_id,
  65. a.goods_sn,
  66. a.name,
  67. psr1.brand_id,
  68. a.goods_number,
  69. a.keywords,
  70. a.goods_brief,
  71. a.is_on_sale,
  72. a.add_time,
  73. a.sort_order,
  74. a.is_delete,
  75. psr1.attribute_category,
  76. a.counter_price,
  77. a.extra_price,
  78. a.is_new,
  79. a.goods_unit,
  80. a.primary_pic_url,
  81. a.list_pic_url,
  82. psr1.retail_price,
  83. a.sell_volume,
  84. a.primary_product_id,
  85. a.unit_price,
  86. a.promotion_desc,
  87. a.promotion_tag,
  88. a.app_exclusive_price,
  89. a.is_app_exclusive,
  90. a.is_limited,
  91. a.is_hot,
  92. a.merch_sn,
  93. psr1.store_id,
  94. psr1.market_price,
  95. psr1.stock_num,
  96. a.goods_desc,a.goods_biz_type,a.goods_rate,a.third_party_merch_code,mb.is_stock_share isStockShare
  97. from mall_goods a LEFT JOIN mall_product_store_rela psr1 ON a.id = psr1.goods_id and a.merch_sn = psr1.merch_sn
  98. left join third_merchant_biz mb on a.third_party_merch_code = mb.third_party_merch_code and mb.merch_sn=a.merch_sn
  99. where a.id = #{value}
  100. </select>
  101. <select id="queryObjectByStoreId" resultMap="goodsMap">
  102. select
  103. a.sku,
  104. a.id,
  105. psr1.category_id,
  106. a.goods_sn,
  107. a.name,
  108. psr1.brand_id,
  109. a.goods_number,
  110. a.keywords,
  111. a.goods_brief,
  112. a.is_on_sale,
  113. a.add_time,
  114. a.sort_order,
  115. a.is_delete,
  116. psr1.attribute_category,
  117. a.counter_price,
  118. a.extra_price,
  119. a.is_new,
  120. a.goods_unit,
  121. a.primary_pic_url,
  122. a.list_pic_url,
  123. psr1.retail_price,
  124. psr1.sell_volume,
  125. a.primary_product_id,
  126. a.unit_price,
  127. a.promotion_desc,
  128. a.promotion_tag,
  129. a.app_exclusive_price,
  130. a.is_app_exclusive,
  131. a.is_limited,
  132. a.is_hot,
  133. a.merch_sn,
  134. m.merch_name,
  135. psr1.store_id,
  136. psr1.market_price,
  137. psr1.stock_num,
  138. a.goods_desc,a.goods_biz_type,a.goods_rate,a.third_party_merch_code,mb.is_stock_share isStockShare,a.sell_volume goods_sell_volume
  139. from mall_goods a left join mall_merch m on a.merch_sn = m.merch_sn
  140. left join third_merchant_biz mb on a.third_party_merch_code = mb.third_party_merch_code and mb.merch_sn=a.merch_sn
  141. LEFT JOIN mall_product_store_rela psr1 ON a.id = psr1.goods_id and a.merch_sn = psr1.merch_sn
  142. where a.id = #{id} and psr1.store_id = #{storeId}
  143. </select>
  144. <select id="queryList" resultMap="goodsMap">
  145. select
  146. <if test="fields != null and fields != ''">
  147. ${fields}
  148. </if>
  149. <if test="fields == null or fields == ''">
  150. a.*
  151. </if>
  152. ,psr1.stock_num,psr1.category_id,psr1.brand_id,psr1.attribute_category,a.third_party_merch_code
  153. ,a.goods_biz_type,a.goods_number,mb.is_stock_share isStockShare
  154. from mall_goods a
  155. LEFT JOIN mall_product_store_rela psr1 ON a.id = psr1.goods_id and a.merch_sn = psr1.merch_sn
  156. left join third_merchant_biz mb on a.third_party_merch_code = mb.third_party_merch_code and mb.merch_sn=a.merch_sn
  157. LEFT JOIN mall_product b ON b.id = psr1.product_id
  158. left join mall_category c on psr1.category_id = c.id
  159. where 1 = 1
  160. and a.is_delete != 1 and a.is_on_sale = 1
  161. <if test="is_new != null and is_new != ''">
  162. and a.is_new = #{is_new}
  163. </if>
  164. <if test="is_hot != null and is_hot != ''">
  165. and a.is_hot = #{is_hot}
  166. </if>
  167. <if test="brand_id != null and brand_id != ''">
  168. and psr1.brand_id = #{brand_id}
  169. </if>
  170. <if test="category_id != null and category_id != ''">
  171. and psr1.category_id = #{category_id}
  172. </if>
  173. <if test="keyword != null">
  174. and a.name like concat('%',#{keyword},'%')
  175. </if>
  176. <if test="is_delete != null">
  177. and a.is_delete = #{is_delete}
  178. </if>
  179. <if test="goodsBizType != null">
  180. and a.goods_biz_type = #{goodsBizType}
  181. </if>
  182. <if test="notGoodsBizType == true">
  183. and a.goods_biz_type in ('00','11')
  184. </if>
  185. <if test="categoryIds != null">
  186. and psr1.category_id in
  187. <foreach item="item" collection="categoryIds" open="(" separator="," close=")">
  188. #{item}
  189. </foreach>
  190. </if>
  191. <if test="category_parent_id != null and category_parent_id != null">
  192. and FIND_IN_SET(psr1.category_id, getCategoryChildLst(#{category_parent_id}))
  193. </if>
  194. <if test="goods_ids != null">
  195. and a.id in
  196. <foreach item="item" collection="goods_ids" open="(" separator="," close=")">
  197. #{item}
  198. </foreach>
  199. </if>
  200. <if test="store_id != null and store_id != ''">
  201. and psr1.store_id = #{store_id}
  202. and c.store_id = #{store_id}
  203. </if>
  204. <choose>
  205. <when test="sidx != null and sidx.trim() != ''">
  206. order by ${sidx} ${order}
  207. </when>
  208. <otherwise>
  209. order by a.id desc
  210. </otherwise>
  211. </choose>
  212. <if test="offset != null and limit != null">
  213. limit #{offset}, #{limit}
  214. </if>
  215. </select>
  216. <select id="queryHotGoodsList" resultMap="goodsMap">
  217. select
  218. <if test="fields != null and fields != ''">
  219. ${fields}
  220. </if>
  221. <if test="fields == null or fields == ''">
  222. a.*,b.id as product_id,psr1.category_id,psr1.brand_id,psr1.attribute_category
  223. </if>
  224. ,a.goods_biz_type,
  225. a.goods_number,
  226. a.third_party_merch_code third_party_merch_code,
  227. mb.is_stock_share isStockShare
  228. from mall_goods a
  229. LEFT JOIN mall_product_store_rela psr1 ON a.id = psr1.goods_id and a.merch_sn = psr1.merch_sn
  230. left join third_merchant_biz mb on mb.third_party_merch_code = a.third_party_merch_code and mb.merch_sn=a.merch_sn
  231. LEFT JOIN mall_product b ON b.id = psr1.product_id
  232. where 1 = 1
  233. <if test="isStockShare == 1">
  234. and (a.goods_number > 0 or psr1.stock_num > 0 )
  235. </if>
  236. <if test="isStockShare == 0">
  237. and psr1.stock_num > 0
  238. </if>
  239. and b.id is not null and a.is_delete != 1 and psr1.retail_price is not null and a.is_on_sale = 1
  240. <if test="is_new != null and is_new != ''">
  241. and a.is_new = #{is_new}
  242. </if>
  243. <if test="is_hot != null and is_hot != ''">
  244. and a.is_hot = #{is_hot}
  245. </if>
  246. <if test="brand_id != null and brand_id != ''">
  247. and psr1.brand_id = #{brand_id}
  248. </if>
  249. <if test="category_id != null and category_id != ''">
  250. and psr1.category_id = #{category_id}
  251. </if>
  252. <if test="keyword != null">
  253. and a.keywords like concat('%',#{keyword},'%')
  254. </if>
  255. <if test="categoryIds != null">
  256. and psr1.category_id in
  257. <foreach item="item" collection="categoryIds" open="(" separator="," close=")">
  258. #{item}
  259. </foreach>
  260. </if>
  261. <if test="category_parent_id != null and category_parent_id != null">
  262. and FIND_IN_SET(psr1.category_id, getCategoryChildLst(#{category_parent_id}))
  263. </if>
  264. <if test="goods_ids != null">
  265. and a.id in
  266. <foreach item="item" collection="goods_ids" open="(" separator="," close=")">
  267. #{item}
  268. </foreach>
  269. </if>
  270. <if test="store_id != null and store_id != ''">
  271. and psr1.store_id = #{store_id}
  272. </if>
  273. <choose>
  274. <when test="sidx != null and sidx.trim() != ''">
  275. order by ${sidx} ${order}
  276. </when>
  277. <otherwise>
  278. order by a.id desc
  279. </otherwise>
  280. </choose>
  281. <if test="offset != null and limit != null">
  282. limit #{offset}, #{limit}
  283. </if>
  284. </select>
  285. <select id="queryCatalogProductList" resultMap="goodsMap">
  286. select a.id, a.name, a.list_pic_url,psr1.category_id,psr1.brand_id,psr1.attribute_category , psr1.market_price, psr1.retail_price, a.goods_brief, b.id AS product_id,
  287. psr1.stock_num,a.third_party_merch_code,a.goods_biz_type,a.goods_number,
  288. mb.is_stock_share isStockShare
  289. <if test="is_group != null and is_group == true">
  290. ,gg.id as group_id
  291. </if>
  292. FROM
  293. mall_goods a
  294. LEFT JOIN mall_product_store_rela psr1 ON a.id = psr1.goods_id and a.merch_sn = psr1.merch_sn
  295. left join third_merchant_biz mb on a.third_party_merch_code = mb.third_party_merch_code and mb.merch_sn=a.merch_sn
  296. LEFT JOIN mall_product b ON b.id = psr1.product_id
  297. <if test="is_group != null and is_group == true">
  298. left join mall_goods_group gg on gg.goods_id = a.id
  299. </if>
  300. WHERE
  301. 1 = 1 and b.id > 0 and a.is_delete != 1 and psr1.retail_price is not null and a.is_on_sale = 1
  302. <if test="is_new != null and is_new != ''">
  303. and a.is_new = #{is_new}
  304. </if>
  305. <if test="is_hot != null and is_hot != ''">
  306. and a.is_hot = #{is_hot}
  307. </if>
  308. <if test="brand_id != null and brand_id != ''">
  309. and psr1.brand_id = #{brand_id}
  310. </if>
  311. <if test="name != null and name != ''">
  312. and a.'name' like concat('%',#{keyword},'%')
  313. </if>
  314. <if test="category_id != null and category_id != ''">
  315. and psr1.category_id = #{category_id}
  316. </if>
  317. <if test="keyword != null">
  318. and a.keywords like concat('%',#{keyword},'%')
  319. </if>
  320. <if test="is_group != null and is_group == true">
  321. and gg.id is not null
  322. </if>
  323. <if test="categoryIds != null">
  324. and psr1.category_id in
  325. <foreach item="item" collection="categoryIds" open="(" separator="," close=")">
  326. #{item}
  327. </foreach>
  328. </if>
  329. <if test="category_parent_id != null and category_parent_id != null">
  330. and FIND_IN_SET(psr1.category_id, getCategoryChildLst(#{category_parent_id}))
  331. </if>
  332. <if test="goods_ids != null">
  333. and a.id in
  334. <foreach item="item" collection="goods_ids" open="(" separator="," close=")">
  335. #{item}
  336. </foreach>
  337. </if>
  338. <if test="store_id != null and store_id != ''">
  339. and psr1.store_id = #{store_id}
  340. </if>
  341. <if test="goodsBizType != null and goodsBizType != ''">
  342. and a.goods_biz_type = #{goodsBizType}
  343. </if>
  344. group by a.id, a.name, a.list_pic_url, psr1.market_price, psr1.retail_price, a.goods_brief, b.id
  345. <choose>
  346. <when test="sidx != null and sidx.trim() != ''">
  347. order by ${sidx} ${order}
  348. </when>
  349. <otherwise>
  350. order by a.id desc
  351. </otherwise>
  352. </choose>
  353. <if test="offset != null and limit != null">
  354. limit #{offset}, #{limit}
  355. </if>
  356. </select>
  357. <select id="queryTotal" resultType="int">
  358. select count(*)
  359. from mall_goods a
  360. left join mall_product_store_rela s on a.id = s.goods_id and a.merch_sn = s.merch_sn
  361. left join third_merchant_biz mb on a.third_party_merch_code = mb.third_party_merch_code and mb.merch_sn=a.merch_sn
  362. where 1 = 1 and a.is_on_sale = 1
  363. <if test="isStockShare == 1">
  364. and (a.goods_number > 0 or s.stock_num > 0 )
  365. </if>
  366. <if test="isStockShare == 0">
  367. and s.stock_num > 0
  368. </if>
  369. <if test="storeId != null and storeId != ''">
  370. and s.store_id = #{storeId}
  371. </if>
  372. <if test="is_new != null and is_new != ''">
  373. and a.is_new = #{is_new}
  374. </if>
  375. <if test="is_hot != null and is_hot != ''">
  376. and a.is_hot = #{is_hot}
  377. </if>
  378. <if test="brand_id != null and brand_id != ''">
  379. and s.brand_id = #{brand_id}
  380. </if>
  381. <if test="category_id != null and category_id != ''">
  382. and s.category_id = #{category_id}
  383. </if>
  384. <if test="keyword != null">
  385. and a.name like concat('%',#{keyword},'%')
  386. </if>
  387. <if test="is_delete != null">
  388. and a.is_delete = #{is_delete}
  389. </if>
  390. <if test="categoryIds != null">
  391. and s.category_id in
  392. <foreach item="item" collection="categoryIds" open="(" separator="," close=")">
  393. #{item}
  394. </foreach>
  395. </if>
  396. <if test="category_parent_id != null and category_parent_id != null">
  397. and FIND_IN_SET(s.category_id, getCategoryChildLst(#{category_parent_id}))
  398. </if>
  399. <if test="goods_ids != null">
  400. and a.id in
  401. <foreach item="item" collection="goods_ids" open="(" separator="," close=")">
  402. #{item}
  403. </foreach>
  404. </if>
  405. <if test="store_id != null and store_id != ''">
  406. and s.store_id = #{store_id}
  407. </if>
  408. <if test="goodsBizType != null and goodsBizType != ''">
  409. and a.goods_biz_type = #{goodsBizType}
  410. </if>
  411. <if test="notGoodsBizType == true">
  412. and a.goods_biz_type in ('00','11')
  413. </if>
  414. </select>
  415. <update id="updateGoodsStock" parameterType="com.kmall.api.entity.GoodsVo">
  416. update mall_goods a
  417. <set>
  418. <if test="goods_number != null">a.`goods_number` = #{goods_number},</if>
  419. <if test="sell_volume != null">a.`sell_volume` = #{sell_volume},</if>
  420. </set>
  421. where a.id = #{id}
  422. </update>
  423. </mapper>