瀏覽代碼

APP城市与城市半径提交

zjy 4 周之前
父節點
當前提交
5f7dfbf36d

+ 2 - 2
alien-entity/src/main/java/shop/alien/mapper/second/SecondRecommendMapper.java

@@ -17,11 +17,11 @@ public interface SecondRecommendMapper extends BaseMapper<SecondGoodsRecommendVo
     /**
      * 自定义分页查询
      */
-    IPage<SecondGoodsRecommendVo> getSecondRecommendByPage(IPage<SecondGoodsRecommendVo> page, @Param("userId") Integer userId, @Param("position") String position, @Param("typeId") Integer typeId, @Param("phoneId") String phoneId);
+    IPage<SecondGoodsRecommendVo> getSecondRecommendByPage(IPage<SecondGoodsRecommendVo> page, @Param("userId") Integer userId, @Param("position") String position, @Param("typeId") Integer typeId, @Param("phoneId") String phoneId, @Param("radiusKm") String radiusKm);
 
     IPage<SecondGoodsRecommendVo> querySecondConcernByPage(IPage<SecondGoodsRecommendVo> page, @Param("userId") Integer userId, @Param("phoneId") String phoneId, @Param("position") String position);
 
-    IPage<SecondGoodsRecommendVo> querySecondNewGoodsByPage(IPage<SecondGoodsRecommendVo> page,@Param("userId") String userId, @Param("phoneId") String phoneId, @Param("position") String position);
+    IPage<SecondGoodsRecommendVo> querySecondNewGoodsByPage(IPage<SecondGoodsRecommendVo> page,@Param("userId") String userId, @Param("phoneId") String phoneId, @Param("position") String position, @Param("radiusKm") String radiusKm);
 
     List<SecondCommentVo> querySecondCommentInfo(@Param("ids") List<Integer> ids);
 

+ 88 - 84
alien-entity/src/main/resources/mapper/second/SecondGoodsInfoMapper.xml

@@ -42,47 +42,49 @@
             where lb.delete_flag = 0 and lb.blocker_type = 2 and lb.blocked_type = 2
                 and lb.blocker_id = #{userId}
         )
-        SELECT
-            g.id,
-            g.user_id,
-            g.title,
-            g.description,
-            g.price,
-            g.price as amount,
-            g.position,
-            g.like_count,
-            g.collect_count,
-            g.category_one_id,
-            g.category_two_id,
-            g.label,
-            g.topic,
-            g.trade_id,
-            g.created_time,
-            g.created_user_id,
-            g.updated_time,
-            g.updated_user_id,
-            u.user_name,
-            u.user_image,
-            g.goods_status,
-            g.delete_flag,
-            g.release_time,
-            g.video_first_frame,
-            ROUND(ST_Distance_Sphere(ST_GeomFromText(CONCAT('POINT(', REPLACE(#{position}, ',', ' '), ')' )), ST_GeomFromText(CONCAT('POINT(', REPLACE(g.position, ',', ' '), ')' ))) / 1000, 2) AS dist,
-            case when llr.id is null then '0' else '1' end likeStatus,
-            g.home_image,
-            CONCAT('user_', u.user_phone) as user_phone
-        FROM
-            second_goods g inner join life_user u on u.id =  g.user_id and u.delete_flag = 0
-            left join life_like_record llr on llr.dianzan_id = #{phoneId} and llr.huifu_id = g.id and llr.type = 6 and llr.delete_flag = 0
-        where g.delete_flag = 0
-            <if test="typeId != null and typeId != '' ">
-                and (g.category_one_id = #{typeId} or g.category_two_id =#{typeId} )
-            </if>
-            and not exists (select 1 from shieldUser s where s.id = g.id)
-            and not exists (select 1 from second_shield s where s.user_id = #{userId} and s.shield_type = 1 and s.shield_id = g.id and s.delete_flag = 0)
-            and g.goods_status = 3
-            and g.position != '' and g.position is not null
-        order by dist, like_count desc, release_time desc
+        SELECT * FROM (
+            SELECT
+                g.id,
+                g.user_id,
+                g.title,
+                g.description,
+                g.price,
+                g.price as amount,
+                g.position,
+                g.like_count,
+                g.collect_count,
+                g.category_one_id,
+                g.category_two_id,
+                g.label,
+                g.topic,
+                g.trade_id,
+                g.created_time,
+                g.created_user_id,
+                g.updated_time,
+                g.updated_user_id,
+                u.user_name,
+                u.user_image,
+                g.goods_status,
+                g.delete_flag,
+                g.release_time,
+                g.video_first_frame,
+                ROUND(ST_Distance_Sphere(ST_GeomFromText(CONCAT('POINT(', REPLACE(#{position}, ',', ' '), ')' )), ST_GeomFromText(CONCAT('POINT(', REPLACE(g.position, ',', ' '), ')' ))) / 1000, 2) AS dist,
+                case when llr.id is null then '0' else '1' end likeStatus,
+                g.home_image,
+                CONCAT('user_', u.user_phone) as user_phone
+            FROM
+                second_goods g inner join life_user u on u.id =  g.user_id and u.delete_flag = 0
+                left join life_like_record llr on llr.dianzan_id = #{phoneId} and llr.huifu_id = g.id and llr.type = 6 and llr.delete_flag = 0
+            where g.delete_flag = 0
+                <if test="typeId != null and typeId != '' ">
+                    and (g.category_one_id = #{typeId} or g.category_two_id =#{typeId} )
+                </if>
+                and not exists (select 1 from shieldUser s where s.id = g.id)
+                and not exists (select 1 from second_shield s where s.user_id = #{userId} and s.shield_type = 1 and s.shield_id = g.id and s.delete_flag = 0)
+                and g.goods_status = 3
+                and g.position != '' and g.position is not null
+            order by dist, like_count desc, release_time desc
+        ) a where a.dist &lt; #{radiusKm}
     </select>
 
     <!-- 分页查询关注数据concern -->
@@ -173,49 +175,51 @@
             where lb.delete_flag = 0 and lb.blocker_type = 2 and lb.blocked_type = 2
                 and lb.blocker_id = #{userId}
         )
-        SELECT
-            g.id,
-            g.user_id,
-            g.title,
-            g.description,
-            g.price,
-            g.price as amount,
-            g.position,
-            g.like_count,
-            g.collect_count,
-            g.category_one_id,
-            g.category_two_id,
-            g.label,
-            g.topic,
-            g.trade_id,
-            g.created_time,
-            g.created_user_id,
-            g.updated_time,
-            g.updated_user_id,
-            g.release_time,
-            u.user_name,
-            u.user_image,
-            CONCAT('user_', u.user_phone) as user_phone,
-            g.goods_status,
-            g.delete_flag,
-            ROUND(ST_Distance_Sphere(ST_GeomFromText(CONCAT('POINT(', REPLACE(#{position}, ',', ' '), ')' )), ST_GeomFromText(CONCAT('POINT(', REPLACE(g.position, ',', ' '), ')' ))) / 1000, 2) AS dist,
-            g.home_image,
-            g.video_first_frame,
-            case when llr.id is null then '0' else '1' end likeStatus,
-            case when lc.id is null then '0' else '1' end collectStatus,
-            (select count(1) from (SELECT id FROM store_comment c where c.business_id = g.id and c.business_type = 7 and c.delete_flag = 0 UNION ALL
-            SELECT t.id FROM store_comment t INNER JOIN (SELECT id FROM store_comment c where c.business_id = g.id and c.business_type = 7 and c.delete_flag = 0) d ON t.reply_id = d.id and business_type = 6 and delete_flag = 0) a ) as commentCount
-<!--            (SELECT count(1) FROM store_comment c where c.business_id = g.id and c.business_type = 7 and c.delete_flag = 0 ) as commentCount-->
-        FROM
-            second_goods g inner join life_user u on u.id = g.user_id
-            left join life_like_record llr on llr.dianzan_id = #{phoneId} and llr.huifu_id = g.id and llr.type = 6 and llr.delete_flag = 0
-            left join life_collect lc on lc.business_id = g.id and lc.user_id = #{phoneId} and lc.delete_flag = 0 and lc.business_type = 1
-        where g.delete_flag = 0
-            and not exists (select 1 from shieldUser s where s.id = g.id)
-            and not exists (select 1 from second_shield s where s.user_id = #{userId} and s.shield_type = 1 and s.shield_id = g.id and s.delete_flag = 0)
-            and g.goods_status = 3
-            and g.position != '' and g.position is not null
-        order by g.release_time desc
+        SELECT * FROM (
+            SELECT
+                g.id,
+                g.user_id,
+                g.title,
+                g.description,
+                g.price,
+                g.price as amount,
+                g.position,
+                g.like_count,
+                g.collect_count,
+                g.category_one_id,
+                g.category_two_id,
+                g.label,
+                g.topic,
+                g.trade_id,
+                g.created_time,
+                g.created_user_id,
+                g.updated_time,
+                g.updated_user_id,
+                g.release_time,
+                u.user_name,
+                u.user_image,
+                CONCAT('user_', u.user_phone) as user_phone,
+                g.goods_status,
+                g.delete_flag,
+                ROUND(ST_Distance_Sphere(ST_GeomFromText(CONCAT('POINT(', REPLACE(#{position}, ',', ' '), ')' )), ST_GeomFromText(CONCAT('POINT(', REPLACE(g.position, ',', ' '), ')' ))) / 1000, 2) AS dist,
+                g.home_image,
+                g.video_first_frame,
+                case when llr.id is null then '0' else '1' end likeStatus,
+                case when lc.id is null then '0' else '1' end collectStatus,
+                (select count(1) from (SELECT id FROM store_comment c where c.business_id = g.id and c.business_type = 7 and c.delete_flag = 0 UNION ALL
+                SELECT t.id FROM store_comment t INNER JOIN (SELECT id FROM store_comment c where c.business_id = g.id and c.business_type = 7 and c.delete_flag = 0) d ON t.reply_id = d.id and business_type = 6 and delete_flag = 0) a ) as commentCount
+    <!--            (SELECT count(1) FROM store_comment c where c.business_id = g.id and c.business_type = 7 and c.delete_flag = 0 ) as commentCount-->
+            FROM
+                second_goods g inner join life_user u on u.id = g.user_id
+                left join life_like_record llr on llr.dianzan_id = #{phoneId} and llr.huifu_id = g.id and llr.type = 6 and llr.delete_flag = 0
+                left join life_collect lc on lc.business_id = g.id and lc.user_id = #{phoneId} and lc.delete_flag = 0 and lc.business_type = 1
+            where g.delete_flag = 0
+                and not exists (select 1 from shieldUser s where s.id = g.id)
+                and not exists (select 1 from second_shield s where s.user_id = #{userId} and s.shield_type = 1 and s.shield_id = g.id and s.delete_flag = 0)
+                and g.goods_status = 3
+                and g.position != '' and g.position is not null
+            order by g.release_time desc
+        ) a where a.dist &lt; #{radiusKm}
     </select>
 
     <select id="querySecondGoodsDetail" resultType="shop.alien.entity.second.vo.SecondGoodsRecommendVo">

+ 6 - 4
alien-second/src/main/java/shop/alien/second/controller/SecondRecommendController.java

@@ -30,10 +30,11 @@ public class SecondRecommendController {
             @RequestParam(value = "pageSize", required = false) Integer pageSize,
             @RequestParam(value = "typeId", required = false) Integer typeId,
             @RequestParam(value = "longitude", required = false) String longitude,
-            @RequestParam(value = "latitude", required = false) String latitude) throws Exception {
+            @RequestParam(value = "latitude", required = false) String latitude,
+            @RequestParam(value = "radiusKm", required = false) String radiusKm) throws Exception {
         log.info("LifeCollectController.cancelCollect?pageNum={},pageSize={},longitude={},latitude={},typeId={}", pageNum, pageSize, longitude, latitude, typeId);
         IPage<SecondGoodsRecommendVo> page = new Page<>(pageNum, pageSize);
-        IPage<SecondGoodsRecommendVo> result = service.getSecondRecommendByPage(page, longitude, latitude, typeId);
+        IPage<SecondGoodsRecommendVo> result = service.getSecondRecommendByPage(page, longitude, latitude, typeId, radiusKm);
         return R.data(result, "查询成功");
     }
 
@@ -56,10 +57,11 @@ public class SecondRecommendController {
             @RequestParam(value = "pageNum", required = false) Integer pageNum,
             @RequestParam(value = "pageSize", required = false) Integer pageSize,
             @RequestParam(value = "longitude", required = false) String longitude,
-            @RequestParam(value = "latitude", required = false) String latitude) throws Exception {
+            @RequestParam(value = "latitude", required = false) String latitude,
+            @RequestParam(value = "radiusKm", required = false) String radiusKm) throws Exception {
         log.info("LifeCollectController.cancelCollect?pageNum={},pageSize={},longitude={},latitude={}", pageNum, pageSize, longitude, latitude);
         IPage<SecondGoodsRecommendVo> page = new Page<>(pageNum, pageSize);
-        IPage<SecondGoodsRecommendVo> result = service.querySecondNewGoodsByPage(page, longitude + "," + latitude);
+        IPage<SecondGoodsRecommendVo> result = service.querySecondNewGoodsByPage(page, longitude + "," + latitude, radiusKm);
         return R.data(result, "查询成功");
     }
 

+ 2 - 2
alien-second/src/main/java/shop/alien/second/service/SecondRecommendService.java

@@ -18,7 +18,7 @@ public interface SecondRecommendService extends IService<SecondGoodsRecommendVo>
      * @param typeId 类型ID
      * @return 推荐商品信息
      */
-    IPage<SecondGoodsRecommendVo> getSecondRecommendByPage(IPage<SecondGoodsRecommendVo> page, String longitude, String latitude, Integer typeId) throws Exception;
+    IPage<SecondGoodsRecommendVo> getSecondRecommendByPage(IPage<SecondGoodsRecommendVo> page, String longitude, String latitude, Integer typeId, String radiusKm) throws Exception;
 
     /**
      * 查询关注信息
@@ -34,7 +34,7 @@ public interface SecondRecommendService extends IService<SecondGoodsRecommendVo>
      * @param position 经纬度
      * @return 新品商品信息
      */
-    IPage<SecondGoodsRecommendVo> querySecondNewGoodsByPage(IPage<SecondGoodsRecommendVo> page, String position) throws Exception;
+    IPage<SecondGoodsRecommendVo> querySecondNewGoodsByPage(IPage<SecondGoodsRecommendVo> page, String position, String radiusKm) throws Exception;
 
     /**
      * 查询商品详情信息

+ 4 - 4
alien-second/src/main/java/shop/alien/second/service/impl/SecondRecommendServiceImpl.java

@@ -47,7 +47,7 @@ public class SecondRecommendServiceImpl extends ServiceImpl<SecondRecommendMappe
      */
     @Override
     public IPage<SecondGoodsRecommendVo> getSecondRecommendByPage(
-            IPage<SecondGoodsRecommendVo> page, String longitude, String latitude, Integer typeId) throws Exception {
+            IPage<SecondGoodsRecommendVo> page, String longitude, String latitude, Integer typeId, String radiusKm) throws Exception {
         try{
             JSONObject data = JwtUtil.getCurrentUserInfo();
             Integer userId = null;
@@ -60,7 +60,7 @@ public class SecondRecommendServiceImpl extends ServiceImpl<SecondRecommendMappe
             if (userId == null) {
                 return null;
             }
-            IPage<SecondGoodsRecommendVo> result = mapper.getSecondRecommendByPage(page, userId, longitude + "," + latitude, typeId, "user_" + phoneId);
+            IPage<SecondGoodsRecommendVo> result = mapper.getSecondRecommendByPage(page, userId, longitude + "," + latitude, typeId, "user_" + phoneId, radiusKm);
             for (SecondGoodsRecommendVo row : result.getRecords()) {
                 // 价格保留两位小数
                 row.setPrice(row.getAmount() != null ? row.getAmount().setScale(2, BigDecimal.ROUND_HALF_UP).toString() : null);
@@ -135,7 +135,7 @@ public class SecondRecommendServiceImpl extends ServiceImpl<SecondRecommendMappe
      * @return 关注列表
      */
     public IPage<SecondGoodsRecommendVo> querySecondNewGoodsByPage(
-            IPage<SecondGoodsRecommendVo> page, String position) throws Exception {
+            IPage<SecondGoodsRecommendVo> page, String position, String radiusKm) throws Exception {
         try {
             JSONObject data = JwtUtil.getCurrentUserInfo();
             String phoneId = null;
@@ -147,7 +147,7 @@ public class SecondRecommendServiceImpl extends ServiceImpl<SecondRecommendMappe
             if (StringUtil.isBlank(phoneId)) {
                 return null;
             }
-            IPage<SecondGoodsRecommendVo> list = mapper.querySecondNewGoodsByPage(page, userId,"user_" + phoneId, position);
+            IPage<SecondGoodsRecommendVo> list = mapper.querySecondNewGoodsByPage(page, userId,"user_" + phoneId, position, radiusKm);
             List<Integer> idList = list.getRecords().stream() // 创建流
                     .map(obj -> obj.getId())   // 提取每个元素的 ID
                     .collect(Collectors.toList());