ApiGoodsMapper.xml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  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="sku" column="sku"/>
  38. <result property="goodsBizType" column="goods_biz_type"/>
  39. <result column="creater_sn" property="createrSn" jdbcType="VARCHAR" />
  40. <result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
  41. <result column="moder_sn" property="moderSn" jdbcType="VARCHAR" />
  42. <result column="mod_time" property="modTime" jdbcType="TIMESTAMP" />
  43. <result column="tstm" property="tstm" jdbcType="TIMESTAMP" />
  44. </resultMap>
  45. <sql id="Base_Column_List" >
  46. id, category_id, goods_sn, sku, goods_biz_type, name, brand_id, goods_number, keywords,
  47. goods_brief, is_on_sale, add_time, sort_order, is_delete, attribute_category, counter_price,
  48. extra_price, is_new, goods_unit, primary_pic_url, list_pic_url, retail_price, sell_volume,
  49. primary_product_id, unit_price, promotion_desc, promotion_tag, app_exclusive_price,
  50. is_app_exclusive, is_limited, is_hot, market_price, creater_sn, create_time, moder_sn,
  51. mod_time, tstm,goods_desc
  52. </sql>
  53. <select id="queryObject" resultMap="goodsMap">
  54. select <include refid="Base_Column_List" />
  55. from mall_goods
  56. where id = #{value}
  57. </select>
  58. <select id="queryObjectByStoreId" resultMap="goodsMap">
  59. select
  60. a.id,
  61. a.category_id,
  62. a.goods_sn,
  63. a.name,
  64. a.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. a.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. psr1.market_price,
  90. psr1.stock_num,
  91. a.goods_desc,a.goods_biz_type
  92. from mall_goods a
  93. LEFT JOIN mall_product_store_rela psr1 ON a.id = psr1.goods_id AND a.primary_product_id = psr1.product_id
  94. where a.id = #{id} and psr1.store_id = #{storeId}
  95. </select>
  96. <select id="queryList" resultMap="goodsMap">
  97. select
  98. <if test="fields != null and fields != ''">
  99. ${fields}
  100. </if>
  101. <if test="fields == null or fields == ''">
  102. a.*
  103. </if>
  104. from mall_goods a
  105. LEFT JOIN mall_product_store_rela psr1 ON a.id = psr1.goods_id AND a.primary_product_id = psr1.product_id
  106. LEFT JOIN mall_product b ON b.id = psr1.product_id
  107. where 1 = 1 and a.is_delete != 1 and psr1.stock_num > 0 and a.is_on_sale = 1
  108. <if test="is_new != null and is_new != ''">
  109. and a.is_new = #{is_new}
  110. </if>
  111. <if test="is_hot != null and is_hot != ''">
  112. and a.is_hot = #{is_hot}
  113. </if>
  114. <if test="brand_id != null and brand_id != ''">
  115. and a.brand_id = #{brand_id}
  116. </if>
  117. <if test="category_id != null and category_id != ''">
  118. and a.category_id = #{category_id}
  119. </if>
  120. <if test="keyword != null">
  121. and a.name like concat('%',#{keyword},'%')
  122. </if>
  123. <if test="is_delete != null">
  124. and a.is_delete = #{is_delete}
  125. </if>
  126. <if test="categoryIds != null">
  127. and a.category_id in
  128. <foreach item="item" collection="categoryIds" open="(" separator="," close=")">
  129. #{item}
  130. </foreach>
  131. </if>
  132. <if test="category_parent_id != null and category_parent_id != null">
  133. and FIND_IN_SET(a.category_id, getCategoryChildLst(#{category_parent_id}))
  134. </if>
  135. <if test="goods_ids != null">
  136. and a.id in
  137. <foreach item="item" collection="goods_ids" open="(" separator="," close=")">
  138. #{item}
  139. </foreach>
  140. </if>
  141. <if test="store_id != null and store_id != ''">
  142. and psr1.store_id = #{store_id}
  143. </if>
  144. <choose>
  145. <when test="sidx != null and sidx.trim() != ''">
  146. order by ${sidx} ${order}
  147. </when>
  148. <otherwise>
  149. order by a.id desc
  150. </otherwise>
  151. </choose>
  152. <if test="offset != null and limit != null">
  153. limit #{offset}, #{limit}
  154. </if>
  155. </select>
  156. <select id="queryHotGoodsList" resultMap="goodsMap">
  157. select
  158. <if test="fields != null and fields != ''">
  159. ${fields}
  160. </if>
  161. <if test="fields == null or fields == ''">
  162. a.*,b.id as product_id
  163. </if>
  164. from mall_goods a
  165. LEFT JOIN mall_product_store_rela psr1 ON a.id = psr1.goods_id AND a.primary_product_id = psr1.product_id
  166. LEFT JOIN mall_product b ON b.id = psr1.product_id
  167. 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
  168. <if test="is_new != null and is_new != ''">
  169. and a.is_new = #{is_new}
  170. </if>
  171. <if test="is_hot != null and is_hot != ''">
  172. and a.is_hot = #{is_hot}
  173. </if>
  174. <if test="brand_id != null and brand_id != ''">
  175. and a.brand_id = #{brand_id}
  176. </if>
  177. <if test="category_id != null and category_id != ''">
  178. and a.category_id = #{category_id}
  179. </if>
  180. <if test="keyword != null">
  181. and a.keywords like concat('%',#{keyword},'%')
  182. </if>
  183. <if test="categoryIds != null">
  184. and a.category_id in
  185. <foreach item="item" collection="categoryIds" open="(" separator="," close=")">
  186. #{item}
  187. </foreach>
  188. </if>
  189. <if test="category_parent_id != null and category_parent_id != null">
  190. and FIND_IN_SET(a.category_id, getCategoryChildLst(#{category_parent_id}))
  191. </if>
  192. <if test="goods_ids != null">
  193. and a.id in
  194. <foreach item="item" collection="goods_ids" open="(" separator="," close=")">
  195. #{item}
  196. </foreach>
  197. </if>
  198. <if test="store_id != null and store_id != ''">
  199. and psr1.store_id = #{store_id}
  200. </if>
  201. <choose>
  202. <when test="sidx != null and sidx.trim() != ''">
  203. order by ${sidx} ${order}
  204. </when>
  205. <otherwise>
  206. order by a.id desc
  207. </otherwise>
  208. </choose>
  209. <if test="offset != null and limit != null">
  210. limit #{offset}, #{limit}
  211. </if>
  212. </select>
  213. <select id="queryCatalogProductList" resultMap="goodsMap">
  214. select a.id, a.name, a.list_pic_url, psr1.market_price, psr1.retail_price, a.goods_brief, b.id AS product_id
  215. <if test="is_group != null and is_group == true">
  216. ,gg.id as group_id
  217. </if>
  218. FROM
  219. mall_goods a
  220. LEFT JOIN mall_product_store_rela psr1 ON a.id = psr1.goods_id AND a.primary_product_id = psr1.product_id
  221. LEFT JOIN mall_product b ON b.id = psr1.product_id
  222. <if test="is_group != null and is_group == true">
  223. left join mall_goods_group gg on gg.goods_id = a.id
  224. </if>
  225. WHERE
  226. 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
  227. <if test="is_new != null and is_new != ''">
  228. and a.is_new = #{is_new}
  229. </if>
  230. <if test="is_hot != null and is_hot != ''">
  231. and a.is_hot = #{is_hot}
  232. </if>
  233. <if test="brand_id != null and brand_id != ''">
  234. and a.brand_id = #{brand_id}
  235. </if>
  236. <if test="name != null and name != ''">
  237. and a.'name' like concat('%',#{keyword},'%')
  238. </if>
  239. <if test="category_id != null and category_id != ''">
  240. and a.category_id = #{category_id}
  241. </if>
  242. <if test="keyword != null">
  243. and a.keywords like concat('%',#{keyword},'%')
  244. </if>
  245. <if test="is_group != null and is_group == true">
  246. and gg.id is not null
  247. </if>
  248. <if test="categoryIds != null">
  249. and a.category_id in
  250. <foreach item="item" collection="categoryIds" open="(" separator="," close=")">
  251. #{item}
  252. </foreach>
  253. </if>
  254. <if test="category_parent_id != null and category_parent_id != null">
  255. and FIND_IN_SET(a.category_id, getCategoryChildLst(#{category_parent_id}))
  256. </if>
  257. <if test="goods_ids != null">
  258. and a.id in
  259. <foreach item="item" collection="goods_ids" open="(" separator="," close=")">
  260. #{item}
  261. </foreach>
  262. </if>
  263. <if test="store_id != null and store_id != ''">
  264. and psr1.store_id = #{store_id}
  265. </if>
  266. group by a.id, a.name, a.list_pic_url, psr1.market_price, psr1.retail_price, a.goods_brief, b.id
  267. <choose>
  268. <when test="sidx != null and sidx.trim() != ''">
  269. order by ${sidx} ${order}
  270. </when>
  271. <otherwise>
  272. order by a.id desc
  273. </otherwise>
  274. </choose>
  275. <if test="offset != null and limit != null">
  276. limit #{offset}, #{limit}
  277. </if>
  278. </select>
  279. <select id="queryTotal" resultType="int">
  280. select count(*)
  281. from mall_goods a
  282. left join mall_product_store_rela s on a.id = s.goods_id
  283. where 1 = 1 and a.is_on_sale = 1 AND s.stock_num > 0
  284. <if test="is_new != null and is_new != ''">
  285. and a.is_new = #{is_new}
  286. </if>
  287. <if test="is_hot != null and is_hot != ''">
  288. and a.is_hot = #{is_hot}
  289. </if>
  290. <if test="brand_id != null and brand_id != ''">
  291. and a.brand_id = #{brand_id}
  292. </if>
  293. <if test="category_id != null and category_id != ''">
  294. and a.category_id = #{category_id}
  295. </if>
  296. <if test="keyword != null">
  297. and a.name like concat('%',#{keyword},'%')
  298. </if>
  299. <if test="is_delete != null">
  300. and a.is_delete = #{is_delete}
  301. </if>
  302. <if test="categoryIds != null">
  303. and a.category_id in
  304. <foreach item="item" collection="categoryIds" open="(" separator="," close=")">
  305. #{item}
  306. </foreach>
  307. </if>
  308. <if test="category_parent_id != null and category_parent_id != null">
  309. and FIND_IN_SET(a.category_id, getCategoryChildLst(#{category_parent_id}))
  310. </if>
  311. <if test="goods_ids != null">
  312. and a.id in
  313. <foreach item="item" collection="goods_ids" open="(" separator="," close=")">
  314. #{item}
  315. </foreach>
  316. </if>
  317. <if test="store_id != null and store_id != ''">
  318. and s.store_id = #{store_id}
  319. </if>
  320. </select>
  321. </mapper>