GoodsMapper.xml 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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 g.sort 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 x.*
  112. FROM (SELECT g.*,
  113. CASE
  114. WHEN @shopId != g.shop_id THEN @rownum := 1
  115. ELSE @rownum := @rownum + 1
  116. END AS rank,
  117. @shopId := g.shop_id AS shopId
  118. FROM goods g
  119. JOIN (SELECT @rownum := NULL, @shopId := '') r
  120. where g.status=0
  121. <if test="goodsName!=null and goodsName!=''">
  122. and g.goods_name like concat('%',#{goodsName},'%')
  123. </if>
  124. <if test="shopIdList.size()>0">
  125. and g.shop_id in
  126. <foreach collection="shopIdList" item="id" index="index" open="(" close=")" separator=",">
  127. #{id}
  128. </foreach>
  129. </if>
  130. ORDER BY g.shop_id,g.sort asc,g.sales_volume desc) x
  131. WHERE x.rank &lt;= 3
  132. </select>
  133. <select id="selectGoodsById" resultType="com.sqx.modules.goods.entity.Goods">
  134. select g.*, gsr.inventory as inventory, gsr.sales
  135. from goods g
  136. left join goods_shop_relevancy gsr on g.goods_id = gsr.goods_id
  137. where g.goods_id = #{goodsId}
  138. </select>
  139. </mapper>