|
|
@@ -24,6 +24,7 @@ import shop.alien.entity.store.StoreUser;
|
|
|
import shop.alien.entity.store.vo.StoreInfoVo;
|
|
|
import shop.alien.mapper.StoreImgMapper;
|
|
|
import shop.alien.mapper.StoreUserMapper;
|
|
|
+import shop.alien.store.service.CommonRatingService;
|
|
|
import shop.alien.store.service.StoreImgService;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
|
@@ -54,6 +55,7 @@ public class AiSearchController {
|
|
|
|
|
|
private final RestTemplate restTemplate;
|
|
|
private final StoreImgService storeImgService;
|
|
|
+ private final CommonRatingService commonRatingService;
|
|
|
|
|
|
@RequestMapping("/search")
|
|
|
public R search(@RequestBody Map<String,String> map) {
|
|
|
@@ -133,6 +135,9 @@ public class AiSearchController {
|
|
|
|
|
|
// 查找图片并设置到result中(图片类型1-入口图)
|
|
|
fillStoreImages(result, 1);
|
|
|
+
|
|
|
+ // 填充评论总数
|
|
|
+ fillRatingCount(result);
|
|
|
|
|
|
jsonObject1.put("records", result);
|
|
|
|
|
|
@@ -231,6 +236,40 @@ public class AiSearchController {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 填充评论总数到StoreInfoVo列表中
|
|
|
+ *
|
|
|
+ * @param result StoreInfoVo列表
|
|
|
+ */
|
|
|
+ private void fillRatingCount(List<StoreInfoVo> result) {
|
|
|
+ if (result == null || result.isEmpty()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (StoreInfoVo storeInfo : result) {
|
|
|
+ if (storeInfo.getId() != null) {
|
|
|
+ try {
|
|
|
+ // 调用评论服务获取评论总数,businessId传id,businessType传1
|
|
|
+ Object ratingCountObj = commonRatingService.getRatingCount(storeInfo.getId(), 1);
|
|
|
+
|
|
|
+ // 将返回的Object转换为Map
|
|
|
+ if (ratingCountObj instanceof Map) {
|
|
|
+ Map<String, Object> ratingCountMap = (Map<String, Object>) ratingCountObj;
|
|
|
+ // 从map中取出totalCount字段
|
|
|
+ Object totalCount = ratingCountMap.get("totalCount");
|
|
|
+ if (totalCount != null) {
|
|
|
+ // 赋值给totalNum字段(转为String类型)
|
|
|
+ storeInfo.setTotalNum(String.valueOf(totalCount));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("获取评论总数失败,storeId: {}", storeInfo.getId(), e);
|
|
|
+ // 如果获取失败,继续处理下一个,不影响其他数据
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 将下划线命名转换为驼峰命名
|
|
|
* 例如: store_tel -> storeTel, created_time -> createdTime
|
|
|
*/
|