ApiGoodsMapper.xml 14 KB

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