ApiGoodsMapper.xml 17 KB

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