ApiGoodsMapper.xml 14 KB

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