ApiGoodsMapper.xml 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  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. mb.third_party_merch_code
  140. from mall_goods a left join mall_merch m on a.merch_sn = m.merch_sn
  141. left join third_merchant_biz mb on a.third_party_merch_code = mb.third_party_merch_code and mb.merch_sn=a.merch_sn
  142. LEFT JOIN mall_product_store_rela psr1 ON a.id = psr1.goods_id and a.merch_sn = psr1.merch_sn
  143. where a.id = #{id} and psr1.store_id = #{storeId}
  144. </select>
  145. <select id="queryList" resultMap="goodsMap">
  146. select
  147. <if test="fields != null and fields != ''">
  148. ${fields}
  149. </if>
  150. <if test="fields == null or fields == ''">
  151. a.*
  152. </if>
  153. ,psr1.stock_num,psr1.category_id,psr1.brand_id,psr1.attribute_category,a.third_party_merch_code
  154. ,a.goods_biz_type,a.goods_number,mb.is_stock_share isStockShare,psr1.store_id
  155. from mall_goods a
  156. LEFT JOIN mall_product_store_rela psr1 ON a.id = psr1.goods_id and a.merch_sn = psr1.merch_sn
  157. left join third_merchant_biz mb on a.third_party_merch_code = mb.third_party_merch_code and mb.merch_sn=a.merch_sn
  158. LEFT JOIN mall_product b ON b.id = psr1.product_id
  159. left join mall_category c on psr1.category_id = c.id
  160. where 1 = 1
  161. and a.is_delete != 1 and a.is_on_sale = 1
  162. <if test="is_new != null and is_new != ''">
  163. and a.is_new = #{is_new}
  164. </if>
  165. <if test="is_hot != null and is_hot != ''">
  166. and a.is_hot = #{is_hot}
  167. </if>
  168. <if test="brand_id != null and brand_id != ''">
  169. and psr1.brand_id = #{brand_id}
  170. </if>
  171. <if test="category_id != null and category_id != ''">
  172. and psr1.category_id = #{category_id}
  173. </if>
  174. <if test="keyword != null">
  175. and a.name like concat('%',#{keyword},'%')
  176. </if>
  177. <if test="is_delete != null">
  178. and a.is_delete = #{is_delete}
  179. </if>
  180. <if test="goodsBizType != null">
  181. and a.goods_biz_type = #{goodsBizType}
  182. </if>
  183. <if test="notGoodsBizType == true">
  184. and a.goods_biz_type in ('00','11')
  185. </if>
  186. <if test="categoryIds != null">
  187. and psr1.category_id in
  188. <foreach item="item" collection="categoryIds" open="(" separator="," close=")">
  189. #{item}
  190. </foreach>
  191. </if>
  192. <if test="category_parent_id != null and category_parent_id != null and category_parent_id != 0">
  193. and FIND_IN_SET(psr1.category_id, getCategoryChildLst(#{category_parent_id}))
  194. </if>
  195. <if test="category_parent_id != null and category_parent_id != null and category_parent_id == 0">
  196. and FIND_IN_SET(c.parent_id, getCategoryChildLst(#{category_parent_id}))
  197. </if>
  198. <if test="goods_ids != null">
  199. and a.id in
  200. <foreach item="item" collection="goods_ids" open="(" separator="," close=")">
  201. #{item}
  202. </foreach>
  203. </if>
  204. <if test="store_id != null and store_id != ''">
  205. and psr1.store_id = #{store_id}
  206. and c.store_id = #{store_id}
  207. </if>
  208. <choose>
  209. <when test="sidx != null and sidx.trim() != ''">
  210. order by ${sidx} ${order}
  211. </when>
  212. <otherwise>
  213. order by a.id desc
  214. </otherwise>
  215. </choose>
  216. <if test="offset != null and limit != null">
  217. limit #{offset}, #{limit}
  218. </if>
  219. </select>
  220. <select id="queryHotGoodsList" resultMap="goodsMap">
  221. select
  222. <if test="fields != null and fields != ''">
  223. ${fields}
  224. </if>
  225. <if test="fields == null or fields == ''">
  226. a.*,b.id as product_id,psr1.category_id,psr1.brand_id,psr1.attribute_category
  227. </if>
  228. ,a.goods_biz_type,
  229. a.goods_number,
  230. a.third_party_merch_code third_party_merch_code,
  231. mb.is_stock_share isStockShare,psr1.store_id
  232. from mall_goods a
  233. LEFT JOIN mall_product_store_rela psr1 ON a.id = psr1.goods_id and a.merch_sn = psr1.merch_sn
  234. left join third_merchant_biz mb on mb.third_party_merch_code = a.third_party_merch_code and mb.merch_sn=a.merch_sn
  235. LEFT JOIN mall_product b ON b.id = psr1.product_id
  236. left join mall_category c on psr1.category_id = c.id
  237. where 1 = 1
  238. <if test="isStockShare == 1">
  239. and (a.goods_number > 0 or psr1.stock_num > 0 )
  240. </if>
  241. <if test="isStockShare == 0">
  242. and psr1.stock_num > 0
  243. </if>
  244. and b.id is not null and a.is_delete != 1 and psr1.retail_price is not null and a.is_on_sale = 1
  245. <if test="is_new != null and is_new != ''">
  246. and a.is_new = #{is_new}
  247. </if>
  248. <if test="is_hot != null and is_hot != ''">
  249. and a.is_hot = #{is_hot}
  250. </if>
  251. <if test="brand_id != null and brand_id != ''">
  252. and psr1.brand_id = #{brand_id}
  253. </if>
  254. <if test="category_id != null and category_id != ''">
  255. and psr1.category_id = #{category_id}
  256. </if>
  257. <if test="keyword != null">
  258. and a.keywords like concat('%',#{keyword},'%')
  259. </if>
  260. <if test="categoryIds != null">
  261. and psr1.category_id in
  262. <foreach item="item" collection="categoryIds" open="(" separator="," close=")">
  263. #{item}
  264. </foreach>
  265. </if>
  266. <if test="category_parent_id != null and category_parent_id != null">
  267. and FIND_IN_SET(c.parent_id, getCategoryChildLst(#{category_parent_id}))
  268. </if>
  269. <if test="goods_ids != null">
  270. and a.id in
  271. <foreach item="item" collection="goods_ids" open="(" separator="," close=")">
  272. #{item}
  273. </foreach>
  274. </if>
  275. <if test="store_id != null and store_id != ''">
  276. and psr1.store_id = #{store_id}
  277. </if>
  278. <choose>
  279. <when test="sidx != null and sidx.trim() != ''">
  280. order by ${sidx} ${order}
  281. </when>
  282. <otherwise>
  283. order by a.id desc
  284. </otherwise>
  285. </choose>
  286. <if test="offset != null and limit != null">
  287. limit #{offset}, #{limit}
  288. </if>
  289. </select>
  290. <select id="queryCatalogProductList" resultMap="goodsMap">
  291. 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,
  292. psr1.stock_num,a.third_party_merch_code,a.goods_biz_type,a.goods_number,
  293. mb.is_stock_share isStockShare,psr1.store_id
  294. <if test="is_group != null and is_group == true">
  295. ,gg.id as group_id
  296. </if>
  297. FROM
  298. mall_goods a
  299. LEFT JOIN mall_product_store_rela psr1 ON a.id = psr1.goods_id and a.merch_sn = psr1.merch_sn
  300. left join third_merchant_biz mb on a.third_party_merch_code = mb.third_party_merch_code and mb.merch_sn=a.merch_sn
  301. LEFT JOIN mall_product b ON b.id = psr1.product_id
  302. <if test="is_group != null and is_group == true">
  303. left join mall_goods_group gg on gg.goods_id = a.id
  304. </if>
  305. WHERE
  306. 1 = 1 and b.id > 0 and a.is_delete != 1 and psr1.retail_price is not null and a.is_on_sale = 1
  307. <if test="is_new != null and is_new != ''">
  308. and a.is_new = #{is_new}
  309. </if>
  310. <if test="is_hot != null and is_hot != ''">
  311. and a.is_hot = #{is_hot}
  312. </if>
  313. <if test="brand_id != null and brand_id != ''">
  314. and psr1.brand_id = #{brand_id}
  315. </if>
  316. <if test="name != null and name != ''">
  317. and a.'name' like concat('%',#{keyword},'%')
  318. </if>
  319. <if test="category_id != null and category_id != ''">
  320. and psr1.category_id = #{category_id}
  321. </if>
  322. <if test="keyword != null">
  323. and a.keywords like concat('%',#{keyword},'%')
  324. </if>
  325. <if test="is_group != null and is_group == true">
  326. and gg.id is not null
  327. </if>
  328. <if test="categoryIds != null">
  329. and psr1.category_id in
  330. <foreach item="item" collection="categoryIds" open="(" separator="," close=")">
  331. #{item}
  332. </foreach>
  333. </if>
  334. <if test="category_parent_id != null and category_parent_id != null">
  335. and FIND_IN_SET(psr1.category_id, getCategoryChildLst(#{category_parent_id}))
  336. </if>
  337. <if test="goods_ids != null">
  338. and a.id in
  339. <foreach item="item" collection="goods_ids" open="(" separator="," close=")">
  340. #{item}
  341. </foreach>
  342. </if>
  343. <if test="store_id != null and store_id != ''">
  344. and psr1.store_id = #{store_id}
  345. </if>
  346. <if test="goodsBizType != null and goodsBizType != ''">
  347. and a.goods_biz_type = #{goodsBizType}
  348. </if>
  349. group by a.id, a.name, a.list_pic_url, psr1.market_price, psr1.retail_price, a.goods_brief, b.id
  350. <choose>
  351. <when test="sidx != null and sidx.trim() != ''">
  352. order by ${sidx} ${order}
  353. </when>
  354. <otherwise>
  355. order by a.id desc
  356. </otherwise>
  357. </choose>
  358. <if test="offset != null and limit != null">
  359. limit #{offset}, #{limit}
  360. </if>
  361. </select>
  362. <select id="queryTotal" resultType="int">
  363. select count(*)
  364. from mall_goods a
  365. left join mall_product_store_rela s on a.id = s.goods_id and a.merch_sn = s.merch_sn
  366. left join third_merchant_biz mb on a.third_party_merch_code = mb.third_party_merch_code and mb.merch_sn=a.merch_sn
  367. where 1 = 1 and a.is_on_sale = 1
  368. <if test="isStockShare == 1">
  369. and (a.goods_number > 0 or s.stock_num > 0 )
  370. </if>
  371. <if test="isStockShare == 0">
  372. and s.stock_num > 0
  373. </if>
  374. <if test="storeId != null and storeId != ''">
  375. and s.store_id = #{storeId}
  376. </if>
  377. <if test="is_new != null and is_new != ''">
  378. and a.is_new = #{is_new}
  379. </if>
  380. <if test="is_hot != null and is_hot != ''">
  381. and a.is_hot = #{is_hot}
  382. </if>
  383. <if test="brand_id != null and brand_id != ''">
  384. and s.brand_id = #{brand_id}
  385. </if>
  386. <if test="category_id != null and category_id != ''">
  387. and s.category_id = #{category_id}
  388. </if>
  389. <if test="keyword != null">
  390. and a.name like concat('%',#{keyword},'%')
  391. </if>
  392. <if test="is_delete != null">
  393. and a.is_delete = #{is_delete}
  394. </if>
  395. <if test="categoryIds != null">
  396. and s.category_id in
  397. <foreach item="item" collection="categoryIds" open="(" separator="," close=")">
  398. #{item}
  399. </foreach>
  400. </if>
  401. <if test="category_parent_id != null and category_parent_id != null">
  402. and FIND_IN_SET(s.category_id, getCategoryChildLst(#{category_parent_id}))
  403. </if>
  404. <if test="goods_ids != null">
  405. and a.id in
  406. <foreach item="item" collection="goods_ids" open="(" separator="," close=")">
  407. #{item}
  408. </foreach>
  409. </if>
  410. <if test="store_id != null and store_id != ''">
  411. and s.store_id = #{store_id}
  412. </if>
  413. <if test="goodsBizType != null and goodsBizType != ''">
  414. and a.goods_biz_type = #{goodsBizType}
  415. </if>
  416. <if test="notGoodsBizType == true">
  417. and a.goods_biz_type in ('00','11')
  418. </if>
  419. </select>
  420. <update id="updateGoodsStock" parameterType="com.kmall.api.entity.GoodsVo">
  421. update mall_goods a
  422. <set>
  423. <if test="goods_number != null">a.`goods_number` = #{goods_number},</if>
  424. <if test="sell_volume != null">a.`sell_volume` = #{sell_volume},</if>
  425. </set>
  426. where a.id = #{id}
  427. </update>
  428. </mapper>