SecondGoodsMapper.xml 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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="shop.alien.mapper.second.SecondGoodsMapper">
  4. <resultMap id="BaseResultMap" type="shop.alien.entity.second.SecondGoods">
  5. <!--@mbggenerated-->
  6. <id column="id" property="id" jdbcType="INTEGER"/>
  7. <result column="user_id" property="userId" jdbcType="INTEGER"/>
  8. <result column="title" property="title" jdbcType="VARCHAR"/>
  9. <result column="describe" property="describe" jdbcType="VARCHAR"/>
  10. <result column="price" property="price" jdbcType="DECIMAL"/>
  11. <result column="position" property="position" jdbcType="VARCHAR"/>
  12. <result column="like_count" property="likeCount" jdbcType="INTEGER"/>
  13. <result column="collect_count" property="collectCount" jdbcType="INTEGER"/>
  14. <result column="category_one_id" property="categoryOneId" jdbcType="INTEGER"/>
  15. <result column="category_two_id" property="categoryTwoId" jdbcType="INTEGER"/>
  16. <result column="label" property="label" jdbcType="VARCHAR"/>
  17. <result column="topic" property="topic" jdbcType="VARCHAR"/>
  18. <result column="trade_id" property="tradeId" jdbcType="INTEGER"/>
  19. <result column="goods_status" property="goodsStatus" jdbcType="INTEGER"/>
  20. <result column="failed_reason" property="failedReason" jdbcType="VARCHAR"/>
  21. <result column="delete_flag" property="deleteFlag" jdbcType="INTEGER"/>
  22. <result column="created_time" property="createdTime" jdbcType="TIMESTAMP"/>
  23. <result column="created_user_id" property="createdUserId" jdbcType="INTEGER"/>
  24. <result column="updated_time" property="updatedTime" jdbcType="TIMESTAMP"/>
  25. <result column="updated_user_id" property="updatedUserId" jdbcType="INTEGER"/>
  26. <result column="release_time" property="releaseTime" jdbcType="TIMESTAMP"/>
  27. </resultMap>
  28. <!-- 自定义分页查询 -->
  29. <select id="getSecondGoodsByPage" resultType="shop.alien.entity.second.SecondGoods">
  30. SELECT *
  31. FROM second_goods
  32. WHERE delete_flag = 0
  33. </select>
  34. <!-- 自定义分页查询并按距离排序 Haversine公式 d=rarccos(cos(ϕ1)cos(ϕ2)cos(Δλ)+sin(ϕ1)sin(ϕ2)) -->
  35. <select id="getSecondGoodsByPageAndDistance" resultType="shop.alien.entity.second.SecondGoods">
  36. SELECT *,
  37. (6371 * acos(cos(radians(#{currentLatitude})) * cos(radians(SUBSTRING_INDEX(position, ',', 1))) * cos(radians(SUBSTRING_INDEX(position, ',', -1)) - radians(#{currentLongitude})) + sin(radians(#{currentLatitude})) * sin(radians(SUBSTRING_INDEX(position, ',', 1))))) AS distance
  38. FROM second_goods
  39. WHERE delete_flag = 0
  40. ORDER BY distance ASC
  41. </select>
  42. <!-- 查询商品热卖排行榜 -->
  43. <select id="getHotSellingRanking" resultType="shop.alien.entity.second.SecondGoods">
  44. SELECT *
  45. FROM second_goods
  46. WHERE delete_flag = 0
  47. ORDER BY like_count DESC
  48. </select>
  49. <!-- 查询商品热卖排行榜(前10名),按标签聚合计算总点赞量 -->
  50. <select id="getHotSellingRankingTop10" resultType="shop.alien.entity.second.SecondGoods">
  51. SELECT label, SUM(like_count) AS like_count
  52. FROM second_goods
  53. WHERE delete_flag = 0
  54. GROUP BY label
  55. ORDER BY like_count DESC
  56. LIMIT 10
  57. </select>
  58. <!-- 获取商品收藏排行榜(前10名),按标签聚合计算总收藏量 -->
  59. <select id="getCollectTop10" resultType="shop.alien.entity.second.SecondGoods">
  60. SELECT label, SUM(collect_count) AS collect_count
  61. FROM second_goods
  62. WHERE delete_flag = 0
  63. GROUP BY label
  64. ORDER BY collect_count DESC
  65. LIMIT 10
  66. </select>
  67. <!-- 带图片信息的商品查询 支持分类和状态筛选 -->
  68. <select id="selectGoodsWithImages" resultType="shop.alien.entity.second.SecondGoods">
  69. SELECT *
  70. FROM second_goods
  71. <where>
  72. <if test="categoryId != null">
  73. AND category_one_id = #{categoryId}
  74. </if>
  75. <if test="status != null">
  76. AND goods_status = #{status}
  77. </if>
  78. </where>
  79. </select>
  80. <!-- 查询用户屏蔽的商品列表 -->
  81. <select id="getShieldedGoodsListByType" resultType="shop.alien.entity.second.SecondGoods">
  82. SELECT sg.*
  83. FROM second_goods sg
  84. INNER JOIN second_shield ss ON
  85. (sg.id = ss.shield_id AND ss.shield_type = 1) OR
  86. (sg.user_id = ss.shield_id AND ss.shield_type = 2)
  87. WHERE ss.user_id = #{userId} AND ss.delete_flag = 0 AND sg.delete_flag = 0
  88. AND ss.shield_type = #{shieldType}
  89. </select>
  90. <!-- 搜索商品列表(包含商品信息、图片、用户信息),按距离和创建时间倒序 -->
  91. <select id="searchGoodsList" resultType="shop.alien.entity.second.SecondGoods">
  92. SELECT
  93. sg.*,
  94. (6371 * acos(cos(radians(#{currentLatitude})) * cos(radians(SUBSTRING_INDEX(sg.position, ',', 1))) * cos(radians(SUBSTRING_INDEX(sg.position, ',', -1)) - radians(#{currentLongitude})) + sin(radians(#{currentLatitude})) * sin(radians(SUBSTRING_INDEX(sg.position, ',', 1))))) AS distance
  95. FROM second_goods sg
  96. WHERE sg.delete_flag = 0
  97. ORDER BY distance ASC, sg.created_time DESC
  98. </select>
  99. </mapper>