ApiGoodsMapper.xml 21 KB

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