ApiGoodsMapper.xml 15 KB

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