1
0

ApiGoodsMapper.xml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  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. </resultMap>
  51. <sql id="Base_Column_List" >
  52. id, goods_sn, sku, goods_biz_type, name, goods_number, keywords,
  53. goods_brief, is_on_sale, add_time, sort_order, is_delete, counter_price,
  54. extra_price, is_new, goods_unit, primary_pic_url, list_pic_url, retail_price, sell_volume,
  55. primary_product_id, unit_price, promotion_desc, promotion_tag, app_exclusive_price,
  56. is_app_exclusive, is_limited, is_hot, market_price, creater_sn, create_time, moder_sn,
  57. mod_time, tstm,goods_desc,goods_rate
  58. </sql>
  59. <select id="queryObject" resultMap="goodsMap">
  60. select a.id,
  61. psr1.category_id,
  62. a.goods_sn,
  63. a.name,
  64. psr1.brand_id,
  65. a.goods_number,
  66. a.keywords,
  67. a.goods_brief,
  68. a.is_on_sale,
  69. a.add_time,
  70. a.sort_order,
  71. a.is_delete,
  72. psr1.attribute_category,
  73. a.counter_price,
  74. a.extra_price,
  75. a.is_new,
  76. a.goods_unit,
  77. a.primary_pic_url,
  78. a.list_pic_url,
  79. psr1.retail_price,
  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. psr1.store_id,
  91. psr1.market_price,
  92. psr1.stock_num,
  93. a.goods_desc,a.goods_biz_type,a.goods_rate
  94. from mall_goods a LEFT JOIN mall_product_store_rela psr1 ON a.id = psr1.goods_id and a.merch_sn = psr1.merch_sn
  95. where a.id = #{value}
  96. </select>
  97. <select id="queryObjectByStoreId" resultMap="goodsMap">
  98. select
  99. a.sku,
  100. a.id,
  101. psr1.category_id,
  102. a.goods_sn,
  103. a.name,
  104. psr1.brand_id,
  105. a.goods_number,
  106. a.keywords,
  107. a.goods_brief,
  108. a.is_on_sale,
  109. a.add_time,
  110. a.sort_order,
  111. a.is_delete,
  112. psr1.attribute_category,
  113. a.counter_price,
  114. a.extra_price,
  115. a.is_new,
  116. a.goods_unit,
  117. a.primary_pic_url,
  118. a.list_pic_url,
  119. psr1.retail_price,
  120. a.sell_volume,
  121. a.primary_product_id,
  122. a.unit_price,
  123. a.promotion_desc,
  124. a.promotion_tag,
  125. a.app_exclusive_price,
  126. a.is_app_exclusive,
  127. a.is_limited,
  128. a.is_hot,
  129. a.merch_sn,
  130. m.merch_name,
  131. psr1.store_id,
  132. psr1.market_price,
  133. psr1.stock_num,
  134. a.goods_desc,a.goods_biz_type,a.goods_rate
  135. from mall_goods a left join mall_merch m on a.merch_sn = m.merch_sn
  136. LEFT JOIN mall_product_store_rela psr1 ON a.id = psr1.goods_id and a.merch_sn = psr1.merch_sn
  137. where a.id = #{id} and psr1.store_id = #{storeId}
  138. </select>
  139. <select id="queryList" resultMap="goodsMap">
  140. select
  141. <if test="fields != null and fields != ''">
  142. ${fields}
  143. </if>
  144. <if test="fields == null or fields == ''">
  145. a.*
  146. </if>
  147. ,psr1.stock_num,psr1.category_id,psr1.brand_id,psr1.attribute_category
  148. from mall_goods a
  149. LEFT JOIN mall_product_store_rela psr1 ON a.id = psr1.goods_id and a.merch_sn = psr1.merch_sn
  150. LEFT JOIN mall_product b ON b.id = psr1.product_id
  151. left join mall_category c on psr1.category_id = c.id
  152. where 1 = 1 and a.is_delete != 1 and psr1.stock_num > 0 and a.is_on_sale = 1
  153. <if test="is_new != null and is_new != ''">
  154. and a.is_new = #{is_new}
  155. </if>
  156. <if test="is_hot != null and is_hot != ''">
  157. and a.is_hot = #{is_hot}
  158. </if>
  159. <if test="brand_id != null and brand_id != ''">
  160. and psr1.brand_id = #{brand_id}
  161. </if>
  162. <if test="category_id != null and category_id != ''">
  163. and psr1.category_id = #{category_id}
  164. </if>
  165. <if test="keyword != null">
  166. and a.name like concat('%',#{keyword},'%')
  167. </if>
  168. <if test="is_delete != null">
  169. and a.is_delete = #{is_delete}
  170. </if>
  171. <if test="goodsBizType != null">
  172. and a.goods_biz_type = #{goodsBizType}
  173. </if>
  174. <if test="notGoodsBizType == true">
  175. and a.goods_biz_type in ('00','11')
  176. </if>
  177. <if test="categoryIds != null">
  178. and psr1.category_id in
  179. <foreach item="item" collection="categoryIds" open="(" separator="," close=")">
  180. #{item}
  181. </foreach>
  182. </if>
  183. <if test="category_parent_id != null and category_parent_id != null">
  184. and FIND_IN_SET(psr1.category_id, getCategoryChildLst(#{category_parent_id}))
  185. </if>
  186. <if test="goods_ids != null">
  187. and a.id in
  188. <foreach item="item" collection="goods_ids" open="(" separator="," close=")">
  189. #{item}
  190. </foreach>
  191. </if>
  192. <if test="store_id != null and store_id != ''">
  193. and psr1.store_id = #{store_id}
  194. and c.store_id = #{store_id}
  195. </if>
  196. <choose>
  197. <when test="sidx != null and sidx.trim() != ''">
  198. order by ${sidx} ${order}
  199. </when>
  200. <otherwise>
  201. order by a.id desc
  202. </otherwise>
  203. </choose>
  204. <if test="offset != null and limit != null">
  205. limit #{offset}, #{limit}
  206. </if>
  207. </select>
  208. <select id="queryHotGoodsList" resultMap="goodsMap">
  209. select
  210. <if test="fields != null and fields != ''">
  211. ${fields}
  212. </if>
  213. <if test="fields == null or fields == ''">
  214. a.*,b.id as product_id,psr1.category_id,psr1.brand_id,psr1.attribute_category
  215. </if>
  216. from mall_goods a
  217. LEFT JOIN mall_product_store_rela psr1 ON a.id = psr1.goods_id and a.merch_sn = psr1.merch_sn
  218. LEFT JOIN mall_product b ON b.id = psr1.product_id
  219. where 1 = 1 and b.id is not null and psr1.stock_num > 0 and a.is_delete != 1 and psr1.retail_price is not null and a.is_on_sale = 1
  220. <if test="is_new != null and is_new != ''">
  221. and a.is_new = #{is_new}
  222. </if>
  223. <if test="is_hot != null and is_hot != ''">
  224. and a.is_hot = #{is_hot}
  225. </if>
  226. <if test="brand_id != null and brand_id != ''">
  227. and psr1.brand_id = #{brand_id}
  228. </if>
  229. <if test="category_id != null and category_id != ''">
  230. and psr1.category_id = #{category_id}
  231. </if>
  232. <if test="keyword != null">
  233. and a.keywords like concat('%',#{keyword},'%')
  234. </if>
  235. <if test="categoryIds != null">
  236. and psr1.category_id in
  237. <foreach item="item" collection="categoryIds" open="(" separator="," close=")">
  238. #{item}
  239. </foreach>
  240. </if>
  241. <if test="category_parent_id != null and category_parent_id != null">
  242. and FIND_IN_SET(psr1.category_id, getCategoryChildLst(#{category_parent_id}))
  243. </if>
  244. <if test="goods_ids != null">
  245. and a.id in
  246. <foreach item="item" collection="goods_ids" open="(" separator="," close=")">
  247. #{item}
  248. </foreach>
  249. </if>
  250. <if test="store_id != null and store_id != ''">
  251. and psr1.store_id = #{store_id}
  252. </if>
  253. <choose>
  254. <when test="sidx != null and sidx.trim() != ''">
  255. order by ${sidx} ${order}
  256. </when>
  257. <otherwise>
  258. order by a.id desc
  259. </otherwise>
  260. </choose>
  261. <if test="offset != null and limit != null">
  262. limit #{offset}, #{limit}
  263. </if>
  264. </select>
  265. <select id="queryCatalogProductList" resultMap="goodsMap">
  266. 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,psr1.stock_num
  267. <if test="is_group != null and is_group == true">
  268. ,gg.id as group_id
  269. </if>
  270. FROM
  271. mall_goods a
  272. LEFT JOIN mall_product_store_rela psr1 ON a.id = psr1.goods_id and a.merch_sn = psr1.merch_sn
  273. LEFT JOIN mall_product b ON b.id = psr1.product_id
  274. <if test="is_group != null and is_group == true">
  275. left join mall_goods_group gg on gg.goods_id = a.id
  276. </if>
  277. WHERE
  278. 1 = 1 AND psr1.stock_num > 0 and b.id > 0 and a.is_delete != 1 and psr1.retail_price is not null and a.is_on_sale = 1
  279. <if test="is_new != null and is_new != ''">
  280. and a.is_new = #{is_new}
  281. </if>
  282. <if test="is_hot != null and is_hot != ''">
  283. and a.is_hot = #{is_hot}
  284. </if>
  285. <if test="brand_id != null and brand_id != ''">
  286. and psr1.brand_id = #{brand_id}
  287. </if>
  288. <if test="name != null and name != ''">
  289. and a.'name' like concat('%',#{keyword},'%')
  290. </if>
  291. <if test="category_id != null and category_id != ''">
  292. and psr1.category_id = #{category_id}
  293. </if>
  294. <if test="keyword != null">
  295. and a.keywords like concat('%',#{keyword},'%')
  296. </if>
  297. <if test="is_group != null and is_group == true">
  298. and gg.id is not null
  299. </if>
  300. <if test="categoryIds != null">
  301. and psr1.category_id in
  302. <foreach item="item" collection="categoryIds" open="(" separator="," close=")">
  303. #{item}
  304. </foreach>
  305. </if>
  306. <if test="category_parent_id != null and category_parent_id != null">
  307. and FIND_IN_SET(psr1.category_id, getCategoryChildLst(#{category_parent_id}))
  308. </if>
  309. <if test="goods_ids != null">
  310. and a.id in
  311. <foreach item="item" collection="goods_ids" open="(" separator="," close=")">
  312. #{item}
  313. </foreach>
  314. </if>
  315. <if test="store_id != null and store_id != ''">
  316. and psr1.store_id = #{store_id}
  317. </if>
  318. <if test="goodsBizType != null and goodsBizType != ''">
  319. and a.goods_biz_type = #{goodsBizType}
  320. </if>
  321. group by a.id, a.name, a.list_pic_url, psr1.market_price, psr1.retail_price, a.goods_brief, b.id
  322. <choose>
  323. <when test="sidx != null and sidx.trim() != ''">
  324. order by ${sidx} ${order}
  325. </when>
  326. <otherwise>
  327. order by a.id desc
  328. </otherwise>
  329. </choose>
  330. <if test="offset != null and limit != null">
  331. limit #{offset}, #{limit}
  332. </if>
  333. </select>
  334. <select id="queryTotal" resultType="int">
  335. select count(*)
  336. from mall_goods a
  337. left join mall_product_store_rela s on a.id = s.goods_id and a.merch_sn = s.merch_sn
  338. where 1 = 1 and a.is_on_sale = 1 AND s.stock_num > 0
  339. <if test="storeId != null and storeId != ''">
  340. and s.store_id = #{storeId}
  341. </if>
  342. <if test="is_new != null and is_new != ''">
  343. and a.is_new = #{is_new}
  344. </if>
  345. <if test="is_hot != null and is_hot != ''">
  346. and a.is_hot = #{is_hot}
  347. </if>
  348. <if test="brand_id != null and brand_id != ''">
  349. and s.brand_id = #{brand_id}
  350. </if>
  351. <if test="category_id != null and category_id != ''">
  352. and s.category_id = #{category_id}
  353. </if>
  354. <if test="keyword != null">
  355. and a.name like concat('%',#{keyword},'%')
  356. </if>
  357. <if test="is_delete != null">
  358. and a.is_delete = #{is_delete}
  359. </if>
  360. <if test="categoryIds != null">
  361. and s.category_id in
  362. <foreach item="item" collection="categoryIds" open="(" separator="," close=")">
  363. #{item}
  364. </foreach>
  365. </if>
  366. <if test="category_parent_id != null and category_parent_id != null">
  367. and FIND_IN_SET(s.category_id, getCategoryChildLst(#{category_parent_id}))
  368. </if>
  369. <if test="goods_ids != null">
  370. and a.id in
  371. <foreach item="item" collection="goods_ids" open="(" separator="," close=")">
  372. #{item}
  373. </foreach>
  374. </if>
  375. <if test="store_id != null and store_id != ''">
  376. and s.store_id = #{store_id}
  377. </if>
  378. <if test="goodsBizType != null and goodsBizType != ''">
  379. and a.goods_biz_type = #{goodsBizType}
  380. </if>
  381. <if test="notGoodsBizType == true">
  382. and a.goods_biz_type in ('00','11')
  383. </if>
  384. </select>
  385. </mapper>