Explorar o código

feat:ai标签

刘云鑫 hai 2 meses
pai
achega
2cea933c61

+ 20 - 2
alien-store/src/main/java/shop/alien/store/controller/AiTagsController.java

@@ -2,6 +2,9 @@ package shop.alien.store.controller;
 
 import com.alibaba.fastjson2.JSONArray;
 import com.alibaba.fastjson2.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.RequiredArgsConstructor;
@@ -15,6 +18,8 @@ import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 import org.springframework.web.client.RestTemplate;
 import shop.alien.entity.result.R;
+import shop.alien.entity.store.CommonRating;
+import shop.alien.store.service.CommonRatingService;
 import shop.alien.store.util.ai.AiAuthTokenUtil;
 
 import java.util.ArrayList;
@@ -43,6 +48,7 @@ public class AiTagsController {
 
     private final RestTemplate restTemplate;
     private final AiAuthTokenUtil aiAuthTokenUtil;
+    private final CommonRatingService commonRatingService;
     /**
      * 获取店铺标签
      *
@@ -140,9 +146,21 @@ public class AiTagsController {
                 if(jsonArray.isEmpty()){
                     throw new Exception("ai接口失败");
                 }
-
+                // 2. 提取list中的数值(这里list是数值数组,而非对象数组)
+                List<Long> idList = new ArrayList<>();
+                for (int i = 0; i < jsonArray.size(); i++) {
+                    // 直接获取数值并转为Long类型
+                    Object value = jsonArray.get(i);
+                    if (value instanceof Number) {
+                        idList.add(((Number) value).longValue());
+                    }
+                }
+                Page<CommonRating> page1 = new Page<>(page, pageNum);
+                QueryWrapper<CommonRating> wrapper = new QueryWrapper<>();
+                wrapper.in("id",idList);
+                IPage<CommonRating> page2 = commonRatingService.page(page1, wrapper);
                 // 保持和原有接口一致的返回格式:将data节点重新封装(可根据实际需求调整)
-                return R.data(jsonArray);
+                return commonRatingService.doListBusinessWithType(page2, 1, null, null);
             } else {
                 return R.fail("获取店铺评价失败:" + exchange.getStatusCode());
             }

+ 3 - 0
alien-store/src/main/java/shop/alien/store/service/CommonRatingService.java

@@ -1,8 +1,10 @@
 package shop.alien.store.service;
 
+import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.IService;
 import shop.alien.entity.result.R;
 import shop.alien.entity.store.CommonRating;
+import shop.alien.entity.store.vo.CommonRatingVo;
 
 /**
  * 评价表 服务类
@@ -72,6 +74,7 @@ public interface CommonRatingService extends IService<CommonRating> {
      */
     R getMyRatingList(Integer pageNum, Integer pageSize, Integer businessType, Long userId, Integer auditStatus);
 
+    R<IPage<CommonRatingVo>> doListBusinessWithType(IPage<CommonRating> page2, Integer i, Long userId, Integer replyStatus);
 
   /*  /**
      * 根据业务类型和业务ID获取平均评分

+ 2 - 1
alien-store/src/main/java/shop/alien/store/service/impl/CommonRatingServiceImpl.java

@@ -548,7 +548,8 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
      * @param replyStatus 回复状态(0:全部, 1:已回复, 2:未回复)
      * @return R<IPage<CommonRatingVo>>
      */
-    private R<IPage<CommonRatingVo>> doListBusinessWithType(IPage<CommonRating> page1, Integer businessType, Long userId, Integer replyStatus) {
+    @Override
+    public R<IPage<CommonRatingVo>> doListBusinessWithType(IPage<CommonRating> page1, Integer businessType, Long userId, Integer replyStatus) {
         if(businessType == RatingBusinessTypeEnum.STORE_RATING.getBusinessType()){
             IPage<CommonRatingVo> result = new Page<>(page1.getCurrent(), page1.getSize(), page1.getTotal());
             List<CommonRatingVo> resultList = new ArrayList<>();