Jelajahi Sumber

feat(second): 添加无需JWT的商品详情查询接口

- 在SecondRecommendController中新增querySecondGoodsDetailWithOutJWT方法
- 实现无需认证的商品详情查询功能,支持传入手机ID参数
- 在SecondRecommendService中添加对应的服务接口定义
- 在SecondRecommendServiceImpl中实现完整的业务逻辑
- 包含图片信息设置、关注状态判断、距离计算等功能
- 添加视频URL优先排序的图片列表处理逻辑
fcw 21 jam lalu
induk
melakukan
0041e42554

+ 11 - 0
alien-second/src/main/java/shop/alien/second/controller/SecondRecommendController.java

@@ -75,4 +75,15 @@ public class SecondRecommendController {
         return R.data(service.querySecondGoodsDetail(goodsId, longitude + "," + latitude), "查询成功");
     }
 
+    @ApiOperation("搜索商品详情")
+    @PostMapping("/querySecondGoodsDetailWithOutJWT")
+    public R<SecondGoodsRecommendVo> querySecondGoodsDetailWithOutJWT(
+            @RequestParam(value = "phoneId", required = false) String phoneId,
+            @RequestParam(value = "goodsId", required = false) Integer goodsId,
+            @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.querySecondGoodsDetailWithOutJWT(phoneId, goodsId, longitude + "," + latitude), "查询成功");
+    }
+
 }

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

@@ -44,5 +44,13 @@ public interface SecondRecommendService extends IService<SecondGoodsRecommendVo>
      */
     SecondGoodsRecommendVo querySecondGoodsDetail(Integer goodsId, String position) throws Exception;
 
+    /**
+     * 添加关注信息
+     * @param goodsId 商品ID
+     * @param phoneId 手机ID
+     * @return 是否成功
+     */
+    SecondGoodsRecommendVo querySecondGoodsDetailWithOutJWT(String phoneId, Integer goodsId, String position) throws Exception;
+
 
 }

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

@@ -244,6 +244,65 @@ public class SecondRecommendServiceImpl extends ServiceImpl<SecondRecommendMappe
         }
     }
 
+    @Override
+    public SecondGoodsRecommendVo querySecondGoodsDetailWithOutJWT(String phoneId, Integer goodsId, String position) throws Exception {
+        try {
+            if (StringUtil.isBlank(phoneId)) {
+                return null;
+            }
+            SecondGoodsRecommendVo item = mapper.querySecondGoodsDetail(goodsId, "user_" + phoneId, position);
+
+            if (item != null) {
+                // 设置图片信息
+                QueryWrapper<StoreImg> query = new QueryWrapper<>();
+                query.lambda()
+                        .eq(StoreImg::getImgType, 18) // 商品 图片
+                        .eq(StoreImg::getDeleteFlag, 0)
+                        .eq(StoreImg::getStoreId, goodsId);
+                List<StoreImg> storeImgs = storeImgMapper.selectList(query);
+                // 设置图片信息
+                if (storeImgs.size() > 0) {
+                    // 先按视频后缀排序,再按ImgSort排序
+                    String[] items = storeImgs.stream()
+                            .sorted((o1, o2) -> {
+                                boolean o1IsMp4 = isVideoUrl(o1.getImgUrl());
+                                boolean o2IsMp4 = isVideoUrl(o2.getImgUrl());
+                                // 如果都是.mp4或都不是.mp4,则按ImgSort排序
+                                if (o1IsMp4 && o2IsMp4 || !o1IsMp4 && !o2IsMp4) {
+                                    return o1.getImgSort().compareTo(o2.getImgSort());
+                                }
+                                // 否则,.mp4的排在前面
+                                return o1IsMp4 ? -1 : 1;
+                            }).map(StoreImg::getImgUrl).toArray(String[]::new);
+                    item.setImgList(items);
+                }
+
+                // 查看是否关注
+                QueryWrapper<LifeFans> query1 = new QueryWrapper<>();
+                query1.lambda()
+                        .eq(LifeFans::getFollowedId, item.getUserPhone()) // 商品图片
+                        .eq(LifeFans::getDeleteFlag, 0)
+                        .eq(LifeFans::getFansId, "user_" + phoneId);
+                List<LifeFans> lifeFans = lifeFansMapper.selectList(query1);
+                // 关注状态添加
+                if (lifeFans.size() > 0) {
+                    item.setFansStatus(1);
+                }
+
+                // 距离拼接
+                if (StringUtil.isNotBlank(item.getDist())) {
+                    item.setPosition("距离" + item.getDist() + "km");
+                }
+                item.setPrice(item.getAmount() != null ? item.getAmount().setScale(2, BigDecimal.ROUND_HALF_UP).toString() : null);
+            }
+
+            return item;
+        } catch (Exception e) {
+            log.error("SecondRecommendServiceImpl.querySecondGoodsDetail Error Mgs={}", e.getMessage());
+            throw new Exception(e);
+        }
+    }
+
     public static void main(String[] args) {
         List<StoreImg> storeImgs = new ArrayList<>();
         StoreImg storeImg = new StoreImg();