zhangchen 1 settimana fa
parent
commit
fb4a008237

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

@@ -26,4 +26,6 @@ public interface SecondRecommendMapper extends BaseMapper<SecondGoodsRecommendVo
     List<SecondCommentVo> querySecondCommentInfo(@Param("ids") List<Integer> ids);
 
     SecondGoodsRecommendVo querySecondGoodsDetail(@Param("goodsId") Integer goodsId, @Param("phoneId") String phoneId, @Param("position") String position);
+
+    SecondGoodsRecommendVo querySecondGoodsDetailWithoutPosition(@Param("goodsId") Integer goodsId, @Param("phoneId") String phoneId);
 }

+ 31 - 0
alien-entity/src/main/resources/mapper/second/SecondGoodsInfoMapper.xml

@@ -267,4 +267,35 @@
             and g.position != '' and g.position is not null
     </select>
 
+    <select id="querySecondGoodsDetailWithoutPosition" resultType="shop.alien.entity.second.vo.SecondGoodsRecommendVo">
+        select
+            g.id,
+            g.user_id,
+            g.title,
+            g.description,
+            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.home_image,
+            g.release_time,
+            g.video_first_frame,
+            lu.user_name,
+            CONCAT('user_', lu.user_phone) as user_phone,
+            lu.user_image,
+            goods_status,
+            NULL AS dist,
+            case when llr.id is null then '0' else '1' end likeStatus,
+            case when lc.id is null then '0' else '1' end collectStatus
+        from second_goods g inner join life_user lu on g.user_id = lu.id and lu.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
+            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.id = #{goodsId} and g.delete_flag = 0
+            and g.position != '' and g.position is not null
+    </select>
+
 </mapper>

+ 9 - 1
alien-second/src/main/java/shop/alien/second/controller/SecondRecommendController.java

@@ -7,6 +7,7 @@ import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiSort;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.util.StringUtils;
 import org.springframework.web.bind.annotation.*;
 import shop.alien.entity.result.R;
 import shop.alien.entity.second.vo.SecondGoodsRecommendVo;
@@ -73,7 +74,7 @@ public class SecondRecommendController {
             @RequestParam(value = "longitude", required = false) String longitude,
             @RequestParam(value = "latitude", required = false) String latitude) throws Exception {
         log.info("LifeCollectController.cancelCollect?goodsId={},longitude={},latitude={}", goodsId, longitude, latitude);
-        return R.data(service.querySecondGoodsDetail(goodsId, longitude + "," + latitude), "查询成功");
+        return R.data(service.querySecondGoodsDetail(goodsId, buildUserPosition(longitude, latitude)), "查询成功");
     }
 
     @ApiOperation(value = "商品详情(匿名/带手机号)", notes = "需传当前用户 phoneId(可为裸手机号或 user_ 前缀),与 collect/addCollect 写入的 life_collect.user_id 一致;响应 collectStatus:0=未收藏,1=已收藏")
@@ -87,4 +88,11 @@ public class SecondRecommendController {
         return R.data(service.querySecondGoodsDetailWithOutJWT(phoneId, goodsId, longitude + "," + latitude), "查询成功");
     }
 
+    private static String buildUserPosition(String longitude, String latitude) {
+        if (!StringUtils.hasText(longitude) || !StringUtils.hasText(latitude)) {
+            return null;
+        }
+        return longitude.trim() + "," + latitude.trim();
+    }
+
 }

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

@@ -192,7 +192,9 @@ public class SecondRecommendServiceImpl extends ServiceImpl<SecondRecommendMappe
                 return null;
             }
             String collectUserId = toLifeCollectUserId(phoneId);
-            SecondGoodsRecommendVo item = mapper.querySecondGoodsDetail(goodsId, collectUserId, position);
+            SecondGoodsRecommendVo item = StringUtil.isBlank(position)
+                    ? mapper.querySecondGoodsDetailWithoutPosition(goodsId, collectUserId)
+                    : mapper.querySecondGoodsDetail(goodsId, collectUserId, position);
             applySecondGoodsDetailEnrichment(item, phoneId, goodsId);
             return item;
         } catch (Exception e) {