ApiGoodsMapper.xml 14 KB

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