ApiGoodsMapper.xml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  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="notGoodsBizType == true">
  132. and a.goods_biz_type in ('00','11')
  133. </if>
  134. <if test="categoryIds != null">
  135. and a.category_id in
  136. <foreach item="item" collection="categoryIds" open="(" separator="," close=")">
  137. #{item}
  138. </foreach>
  139. </if>
  140. <if test="category_parent_id != null and category_parent_id != null">
  141. and FIND_IN_SET(a.category_id, getCategoryChildLst(#{category_parent_id}))
  142. </if>
  143. <if test="goods_ids != null">
  144. and a.id in
  145. <foreach item="item" collection="goods_ids" open="(" separator="," close=")">
  146. #{item}
  147. </foreach>
  148. </if>
  149. <if test="store_id != null and store_id != ''">
  150. and psr1.store_id = #{store_id}
  151. </if>
  152. <choose>
  153. <when test="sidx != null and sidx.trim() != ''">
  154. order by ${sidx} ${order}
  155. </when>
  156. <otherwise>
  157. order by a.id desc
  158. </otherwise>
  159. </choose>
  160. <if test="offset != null and limit != null">
  161. limit #{offset}, #{limit}
  162. </if>
  163. </select>
  164. <select id="queryHotGoodsList" resultMap="goodsMap">
  165. select
  166. <if test="fields != null and fields != ''">
  167. ${fields}
  168. </if>
  169. <if test="fields == null or fields == ''">
  170. a.*,b.id as product_id
  171. </if>
  172. from mall_goods a
  173. LEFT JOIN mall_product_store_rela psr1 ON a.id = psr1.goods_id AND a.primary_product_id = psr1.product_id
  174. LEFT JOIN mall_product b ON b.id = psr1.product_id
  175. 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
  176. <if test="is_new != null and is_new != ''">
  177. and a.is_new = #{is_new}
  178. </if>
  179. <if test="is_hot != null and is_hot != ''">
  180. and a.is_hot = #{is_hot}
  181. </if>
  182. <if test="brand_id != null and brand_id != ''">
  183. and a.brand_id = #{brand_id}
  184. </if>
  185. <if test="category_id != null and category_id != ''">
  186. and a.category_id = #{category_id}
  187. </if>
  188. <if test="keyword != null">
  189. and a.keywords like concat('%',#{keyword},'%')
  190. </if>
  191. <if test="categoryIds != null">
  192. and a.category_id in
  193. <foreach item="item" collection="categoryIds" open="(" separator="," close=")">
  194. #{item}
  195. </foreach>
  196. </if>
  197. <if test="category_parent_id != null and category_parent_id != null">
  198. and FIND_IN_SET(a.category_id, getCategoryChildLst(#{category_parent_id}))
  199. </if>
  200. <if test="goods_ids != null">
  201. and a.id in
  202. <foreach item="item" collection="goods_ids" open="(" separator="," close=")">
  203. #{item}
  204. </foreach>
  205. </if>
  206. <if test="store_id != null and store_id != ''">
  207. and psr1.store_id = #{store_id}
  208. </if>
  209. <choose>
  210. <when test="sidx != null and sidx.trim() != ''">
  211. order by ${sidx} ${order}
  212. </when>
  213. <otherwise>
  214. order by a.id desc
  215. </otherwise>
  216. </choose>
  217. <if test="offset != null and limit != null">
  218. limit #{offset}, #{limit}
  219. </if>
  220. </select>
  221. <select id="queryCatalogProductList" resultMap="goodsMap">
  222. select a.id, a.name, a.list_pic_url, psr1.market_price, psr1.retail_price, a.goods_brief, b.id AS product_id
  223. <if test="is_group != null and is_group == true">
  224. ,gg.id as group_id
  225. </if>
  226. FROM
  227. mall_goods a
  228. LEFT JOIN mall_product_store_rela psr1 ON a.id = psr1.goods_id AND a.primary_product_id = psr1.product_id
  229. LEFT JOIN mall_product b ON b.id = psr1.product_id
  230. <if test="is_group != null and is_group == true">
  231. left join mall_goods_group gg on gg.goods_id = a.id
  232. </if>
  233. WHERE
  234. 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
  235. <if test="is_new != null and is_new != ''">
  236. and a.is_new = #{is_new}
  237. </if>
  238. <if test="is_hot != null and is_hot != ''">
  239. and a.is_hot = #{is_hot}
  240. </if>
  241. <if test="brand_id != null and brand_id != ''">
  242. and a.brand_id = #{brand_id}
  243. </if>
  244. <if test="name != null and name != ''">
  245. and a.'name' like concat('%',#{keyword},'%')
  246. </if>
  247. <if test="category_id != null and category_id != ''">
  248. and a.category_id = #{category_id}
  249. </if>
  250. <if test="keyword != null">
  251. and a.keywords like concat('%',#{keyword},'%')
  252. </if>
  253. <if test="is_group != null and is_group == true">
  254. and gg.id is not null
  255. </if>
  256. <if test="categoryIds != null">
  257. and a.category_id in
  258. <foreach item="item" collection="categoryIds" open="(" separator="," close=")">
  259. #{item}
  260. </foreach>
  261. </if>
  262. <if test="category_parent_id != null and category_parent_id != null">
  263. and FIND_IN_SET(a.category_id, getCategoryChildLst(#{category_parent_id}))
  264. </if>
  265. <if test="goods_ids != null">
  266. and a.id in
  267. <foreach item="item" collection="goods_ids" open="(" separator="," close=")">
  268. #{item}
  269. </foreach>
  270. </if>
  271. <if test="store_id != null and store_id != ''">
  272. and psr1.store_id = #{store_id}
  273. </if>
  274. <if test="goodsBizType != null and goodsBizType != ''">
  275. and a.goods_biz_type = #{goodsBizType}
  276. </if>
  277. group by a.id, a.name, a.list_pic_url, psr1.market_price, psr1.retail_price, a.goods_brief, b.id
  278. <choose>
  279. <when test="sidx != null and sidx.trim() != ''">
  280. order by ${sidx} ${order}
  281. </when>
  282. <otherwise>
  283. order by a.id desc
  284. </otherwise>
  285. </choose>
  286. <if test="offset != null and limit != null">
  287. limit #{offset}, #{limit}
  288. </if>
  289. </select>
  290. <select id="queryTotal" resultType="int">
  291. select count(*)
  292. from mall_goods a
  293. left join mall_product_store_rela s on a.id = s.goods_id
  294. where 1 = 1 and a.is_on_sale = 1 AND s.stock_num > 0
  295. <if test="is_new != null and is_new != ''">
  296. and a.is_new = #{is_new}
  297. </if>
  298. <if test="is_hot != null and is_hot != ''">
  299. and a.is_hot = #{is_hot}
  300. </if>
  301. <if test="brand_id != null and brand_id != ''">
  302. and a.brand_id = #{brand_id}
  303. </if>
  304. <if test="category_id != null and category_id != ''">
  305. and a.category_id = #{category_id}
  306. </if>
  307. <if test="keyword != null">
  308. and a.name like concat('%',#{keyword},'%')
  309. </if>
  310. <if test="is_delete != null">
  311. and a.is_delete = #{is_delete}
  312. </if>
  313. <if test="categoryIds != null">
  314. and a.category_id in
  315. <foreach item="item" collection="categoryIds" open="(" separator="," close=")">
  316. #{item}
  317. </foreach>
  318. </if>
  319. <if test="category_parent_id != null and category_parent_id != null">
  320. and FIND_IN_SET(a.category_id, getCategoryChildLst(#{category_parent_id}))
  321. </if>
  322. <if test="goods_ids != null">
  323. and a.id in
  324. <foreach item="item" collection="goods_ids" open="(" separator="," close=")">
  325. #{item}
  326. </foreach>
  327. </if>
  328. <if test="store_id != null and store_id != ''">
  329. and s.store_id = #{store_id}
  330. </if>
  331. <if test="goodsBizType != null and goodsBizType != ''">
  332. and a.goods_biz_type = #{goodsBizType}
  333. </if>
  334. </select>
  335. </mapper>