1
0

ApiGoodsMapper.xml 21 KB

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