GoodsMapper.xml 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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.sqx.modules.goods.dao.GoodsDao">
  4. <!--<select id="selectGoodsList" resultType="com.sqx.modules.goods.entity.Goods">
  5. select * from goods where 1 = 1
  6. <if test="classify!=null and classify!=''">
  7. and classify = #{classify}
  8. </if>
  9. <if test="goodsName!=null and goodsName!=''">
  10. and goods_name = #{goodsName}
  11. </if>
  12. <if test="putawayFlag!=null and putawayFlag!=''">
  13. and putaway_flag = #{putawayFlag}
  14. </if>
  15. order by create_time desc
  16. </select>-->
  17. <select id="selectGoodsClassifyList" resultType="com.sqx.modules.goods.entity.Goods">
  18. select DISTINCT g.classify_id
  19. from goods g
  20. left join goods_shop_relevancy gsr on gsr.goods_id = g.goods_id
  21. where 1 = 1
  22. and gsr.shop_id = #{shopId}
  23. order by g.classify_id asc
  24. </select>
  25. <select id="selectClassify" resultType="com.sqx.modules.goods.entity.GoodsClassify">
  26. select *
  27. from goods_classify
  28. where classify_id = #{classifyId}
  29. </select>
  30. <select id="selectShortShop" resultType="com.sqx.modules.goods.entity.GoodsShop">
  31. select shop_id, shop_name, shop_lat, shop_lng, open_time, close_time, detailed_address, shop_banner,
  32. (st_distance (point (shop_lat, shop_lng), point(#{lat},#{lng}) ) *111195) AS distancess
  33. from goods_shop where 1 = 1
  34. and status=1 and putaway_flag=0 and banned_flag=0
  35. <if test="shopName!=null and shopName!=''">
  36. and shop_name like concat('%',#{shopName},'%')
  37. </if>
  38. <if test="shopId!=null">
  39. and shop_id = #{shopId}
  40. </if>
  41. order by is_recommend desc,distancess asc
  42. </select>
  43. <select id="selectAllClassify" resultType="com.sqx.modules.goods.entity.GoodsClassify">
  44. select gc.*, gs.shop_name as shopName from goods_classify gc left join goods_shop gs on gc.shop_id = gs.shop_id
  45. where 1 = 1
  46. <if test="shopName!=null and shopName!=''">
  47. and gs.shop_name like concat('%',#{shopName},'%')
  48. </if>
  49. <if test="shopId!=null">
  50. and gc.shop_id = #{shopId}
  51. </if>
  52. order by gc.sort asc
  53. </select>
  54. <select id="selectAllClassifyList" resultType="com.sqx.modules.goods.entity.GoodsClassify">
  55. select gc.*, gs.shop_name as shopName from goods_classify gc left join goods_shop gs on gc.shop_id = gs.shop_id
  56. where 1 = 1
  57. <if test="shopName!=null and shopName!=''">
  58. and gs.shop_name like concat('%',#{shopName},'%')
  59. </if>
  60. <if test="shopId!=null">
  61. and gc.shop_id = #{shopId}
  62. </if>
  63. order by gc.sort asc
  64. </select>
  65. <insert id="shopAddGoods">
  66. insert into goods_shop_relevancy (shop_id, goods_id) values
  67. <foreach collection="goodsIdList" item="item" open="(" close=")" separator=",">
  68. (#{shopId}, #{item})
  69. </foreach>
  70. </insert>
  71. <select id="selectGoodsByClassify" resultType="com.sqx.modules.goods.entity.Goods">
  72. select g.*, gsr.sales as sales, gsr.inventory as inventory, ga.activityList
  73. from goods_shop_relevancy gsr
  74. left join goods g on gsr.goods_id = g.goods_id
  75. left join (
  76. select
  77. tmp.goods_id, group_concat(a.title) as activityList
  78. from
  79. (
  80. select t.activity_shop_id, substring_index(substring_index(t.goods_ids, ',', n.n), ',', -1) goods_id
  81. from
  82. (select 1 as n union select 2 union select 3 union select 4) n
  83. inner join activity_goods t on char_length(t.goods_ids)-char_length(replace(t.goods_ids, ',', ''))>=n.n-1
  84. order by n.n
  85. ) tmp
  86. left join activity_shop ach on ach.id = tmp.activity_shop_id
  87. left join activity a on ach.activity_id = a.id
  88. where a.del_flag = '0'
  89. group by tmp.goods_id
  90. ) ga on ga.goods_id = g.goods_id
  91. where gsr.shop_id = #{shopId}
  92. and g.classify_id = #{classifyId}
  93. and g.status = 0
  94. order by LPAD(g.sort, 10, '0') ASC
  95. </select>
  96. <select id="selectGoodsBySales" resultType="com.sqx.modules.goods.entity.Goods">
  97. select *
  98. from goods
  99. where shop_id = #{shopId}
  100. and status = 0
  101. order by sort asc, sales_volume desc limit 3
  102. </select>
  103. <select id="selectGoodsBySalesAndGoodsName" resultType="com.sqx.modules.goods.entity.Goods">
  104. select * from goods where shop_id = #{shopId}
  105. <if test="goodsName!=null and goodsName!=''">
  106. and goods_name like concat('%',#{goodsName},'%')
  107. </if>
  108. and status=0 order by sort asc,sales_volume desc limit 3
  109. </select>
  110. <select id="selectGoodsBySalesAndGoodsNameAndShopIds" resultType="com.sqx.modules.goods.entity.Goods">
  111. SELECT
  112. x.*
  113. FROM (
  114. SELECT
  115. g.*,
  116. ROW_NUMBER() OVER (PARTITION BY g.shop_id ORDER BY g.sort asc, g.sales_volume desc) AS rank
  117. FROM
  118. goods g
  119. WHERE g.status=0
  120. <if test="goodsName!=null and goodsName!=''">
  121. and g.goods_name like concat('%',#{goodsName},'%')
  122. </if>
  123. <if test="shopIdList.size()>0">
  124. and g.shop_id in
  125. <foreach collection="shopIdList" item="id" index="index" open="(" close=")" separator=",">
  126. #{id}
  127. </foreach>
  128. </if>
  129. ) x
  130. WHERE x.rank &lt;= 3
  131. </select>
  132. <select id="selectGoodsById" resultType="com.sqx.modules.goods.entity.Goods">
  133. select g.*, gsr.inventory as inventory, gsr.sales
  134. from goods g
  135. left join goods_shop_relevancy gsr on g.goods_id = gsr.goods_id
  136. where g.goods_id = #{goodsId}
  137. </select>
  138. <select id="getByAllGoodsIdByShopId" resultType="java.lang.Long">
  139. select goods_id from goods where shop_id = #{shopId}
  140. </select>
  141. <select id="goodsCoverList" resultType="com.sqx.modules.goods.entity.Goods">
  142. SELECT
  143. ( @i := @i + 1 ) AS id,
  144. goods_name,
  145. goods_cover
  146. FROM
  147. goods,
  148. ( SELECT @i := #{total} ) AS itable
  149. WHERE
  150. goods_name LIKE concat('%',#{name},'%')
  151. GROUP BY goods_cover
  152. </select>
  153. <select id="goodsPictureList" resultType="com.sqx.modules.goods.entity.Goods">
  154. SELECT a.* FROM (
  155. SELECT
  156. ( @i := @i + 1 ) AS id,
  157. goods_name,
  158. SUBSTRING_INDEX( SUBSTRING_INDEX( goods_picture, ',', n ), ',', - 1 ) AS goods_picture
  159. FROM
  160. goods,
  161. ( SELECT @rownum := @rownum + 1 AS n FROM ( SELECT @rownum := 0 ) r, goods ) x,
  162. ( SELECT @i := #{total} ) AS itable
  163. WHERE
  164. goods_name LIKE concat('%',#{name},'%')
  165. AND ( LENGTH( goods_picture ) - LENGTH( REPLACE ( goods_picture, ',', '' ) ) + 1 ) >= n
  166. ) a
  167. GROUP BY a.goods_picture
  168. </select>
  169. <select id="goodsParticularsPictureList" resultType="com.sqx.modules.goods.entity.Goods">
  170. SELECT a.* FROM (
  171. SELECT
  172. ( @i := @i + 1 ) AS id,
  173. goods_name,
  174. SUBSTRING_INDEX( SUBSTRING_INDEX( goods_particulars_picture, ',', n ), ',', - 1 ) AS goods_particulars_picture
  175. FROM
  176. goods,
  177. ( SELECT @rownum := @rownum + 1 AS n FROM ( SELECT @rownum := 0 ) r, goods ) x,
  178. ( SELECT @i := #{total} ) AS itable
  179. WHERE
  180. goods_name LIKE concat('%',#{name},'%')
  181. AND ( LENGTH( goods_particulars_picture ) - LENGTH( REPLACE ( goods_particulars_picture, ',', '' ) ) + 1 ) >= n
  182. ) a
  183. GROUP BY a.goods_particulars_picture
  184. </select>
  185. <select id="selectGoodsVoByClassify" resultType="com.sqx.modules.goods.vo.GoodsListVo">
  186. select g.goods_id as goodsId,
  187. g.goods_cover as goodsCover,
  188. g.goods_name as goodsName,
  189. g.goods_describe as goodsDescribe,
  190. g.goods_money as goodsMoney,
  191. gsr.sales as sales
  192. from goods_shop_relevancy gsr
  193. left join goods g on gsr.goods_id = g.goods_id
  194. where gsr.shop_id = #{shopId}
  195. and g.classify_id = #{classifyId}
  196. and g.status = 0
  197. order by LPAD(g.sort, 10, '0') ASC
  198. </select>
  199. <select id="selectSupermarketGoodsList" resultType="com.sqx.modules.goods.entity.Goods">
  200. select g.*, gsr.sales as sales, gsr.inventory as inventory, ga.activityList
  201. from goods_shop_relevancy gsr
  202. left join goods g on gsr.goods_id = g.goods_id
  203. left join (
  204. select
  205. tmp.goods_id, group_concat(a.title) as activityList
  206. from
  207. (
  208. select t.activity_shop_id, substring_index(substring_index(t.goods_ids, ',', n.n), ',', -1) goods_id
  209. from
  210. (select 1 as n union select 2 union select 3 union select 4) n
  211. inner join activity_goods t on char_length(t.goods_ids)-char_length(replace(t.goods_ids, ',', ''))>=n.n-1
  212. order by n.n
  213. ) tmp
  214. left join activity_shop ach on ach.id = tmp.activity_shop_id
  215. left join activity a on ach.activity_id = a.id
  216. where a.del_flag = '0'
  217. group by tmp.goods_id
  218. ) ga on ga.goods_id = g.goods_id
  219. where gsr.shop_id = #{shopId}
  220. and g.classify_id = #{classifyId}
  221. and g.status = 0
  222. order by LPAD(g.sort, 10, '0') ASC
  223. </select>
  224. </mapper>