|
|
@@ -20,18 +20,19 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
import shop.alien.entity.result.R;
|
|
|
-import shop.alien.entity.store.LifeBlacklist;
|
|
|
-import shop.alien.entity.store.StoreImg;
|
|
|
-import shop.alien.entity.store.StoreUser;
|
|
|
+import shop.alien.entity.store.*;
|
|
|
+import shop.alien.entity.store.vo.StoreBannerVo;
|
|
|
import shop.alien.entity.store.vo.StoreInfoVo;
|
|
|
-import shop.alien.entity.store.CommonRating;
|
|
|
import shop.alien.mapper.CommonRatingMapper;
|
|
|
import shop.alien.mapper.LifeBlacklistMapper;
|
|
|
import shop.alien.mapper.StoreImgMapper;
|
|
|
import shop.alien.mapper.StoreUserMapper;
|
|
|
import shop.alien.store.annotation.TrackEvent;
|
|
|
import shop.alien.store.service.CommonRatingService;
|
|
|
+import shop.alien.store.service.StoreBannerService;
|
|
|
import shop.alien.store.service.StoreImgService;
|
|
|
+import shop.alien.store.service.StoreInfoService;
|
|
|
+import shop.alien.entity.store.vo.StoreBusinessStatusVo;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
|
import java.time.Instant;
|
|
|
@@ -63,8 +64,10 @@ public class AiSearchController {
|
|
|
|
|
|
private final RestTemplate restTemplate;
|
|
|
private final StoreImgService storeImgService;
|
|
|
+ private final StoreBannerService storeBannerService;
|
|
|
private final CommonRatingService commonRatingService;
|
|
|
private final CommonRatingMapper commonRatingMapper;
|
|
|
+ private final StoreInfoService storeInfoService;
|
|
|
|
|
|
private final LifeBlacklistMapper lifeBlacklistMapper;
|
|
|
|
|
|
@@ -105,9 +108,14 @@ public class AiSearchController {
|
|
|
List<StoreInfoVo> relatedResult = convertToStoreInfoList(jsonObject.getJSONArray("related_results"),map.get("userId"));
|
|
|
List<StoreInfoVo> matchedResult = convertToStoreInfoList(jsonObject.getJSONArray("matched_results"),map.get("userId"));
|
|
|
|
|
|
- // 查找图片并设置到result中(图片类型1-入口图)
|
|
|
- fillStoreImages(relatedResult, 1);
|
|
|
- fillStoreImages(matchedResult, 1);
|
|
|
+ // 并发处理图片和营业时间,提升性能
|
|
|
+ CompletableFuture<Void> relatedImageFuture = CompletableFuture.runAsync(() -> fillStoreImages(relatedResult, 1));
|
|
|
+ CompletableFuture<Void> matchedImageFuture = CompletableFuture.runAsync(() -> fillStoreImages(matchedResult, 1));
|
|
|
+ CompletableFuture<Void> relatedBusinessHoursFuture = CompletableFuture.runAsync(() -> fillBusinessHours(relatedResult));
|
|
|
+ CompletableFuture<Void> matchedBusinessHoursFuture = CompletableFuture.runAsync(() -> fillBusinessHours(matchedResult));
|
|
|
+
|
|
|
+ // 等待所有任务完成
|
|
|
+ CompletableFuture.allOf(relatedImageFuture, matchedImageFuture, relatedBusinessHoursFuture, matchedBusinessHoursFuture).join();
|
|
|
|
|
|
// 合并两个列表
|
|
|
// List<StoreInfoVo> relatedResults = new ArrayList<>();
|
|
|
@@ -116,6 +124,14 @@ public class AiSearchController {
|
|
|
// relatedResults.addAll(relatedResult);
|
|
|
jsonObject1.put("matchedRecords", matchedResult);
|
|
|
jsonObject1.put("relatedRecords", relatedResult);
|
|
|
+ // 根据matchedResult中的business_section_name去插入到storeBanners中
|
|
|
+ List<String> sectionNames = matchedResult.stream()
|
|
|
+ .map(StoreInfoVo::getBusinessSectionName)
|
|
|
+ .filter(StringUtils::isNotBlank)
|
|
|
+ .distinct()
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ List<StoreBannerVo> storeBanners = storeBannerService.getBannerByAISearch(sectionNames);
|
|
|
+ jsonObject1.put("storeBanners", storeBanners);
|
|
|
|
|
|
|
|
|
jsonObject1.put("total", jsonObject.get("total"));
|
|
|
@@ -154,12 +170,13 @@ public class AiSearchController {
|
|
|
// 模糊搜索:从related_results和matched_results字段获取数据
|
|
|
List<StoreInfoVo> result = convertToStoreInfoList(jsonObject.getJSONArray("results"),map.get("userId"));
|
|
|
|
|
|
- // 并发处理图片和评论数据,提升性能
|
|
|
+ // 并发处理图片、评论数据和营业时间,提升性能
|
|
|
CompletableFuture<Void> imageFuture = CompletableFuture.runAsync(() -> fillStoreImages(result, 1));
|
|
|
CompletableFuture<Void> ratingFuture = CompletableFuture.runAsync(() -> fillRatingCountBatch(result));
|
|
|
+ CompletableFuture<Void> businessHoursFuture = CompletableFuture.runAsync(() -> fillBusinessHours(result));
|
|
|
|
|
|
- // 等待两个任务完成
|
|
|
- CompletableFuture.allOf(imageFuture, ratingFuture).join();
|
|
|
+ // 等待所有任务完成
|
|
|
+ CompletableFuture.allOf(imageFuture, ratingFuture, businessHoursFuture).join();
|
|
|
|
|
|
jsonObject1.put("records", result);
|
|
|
|
|
|
@@ -349,6 +366,51 @@ public class AiSearchController {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 批量填充营业时间到StoreInfoVo列表中
|
|
|
+ * 通过调用storeInfoService.getStoreBusinessStatus方法获取营业时间
|
|
|
+ *
|
|
|
+ * @param result StoreInfoVo列表
|
|
|
+ */
|
|
|
+ private void fillBusinessHours(List<StoreInfoVo> result) {
|
|
|
+ if (result == null || result.isEmpty()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 遍历result集合,为每个门店调用getStoreBusinessStatus方法
|
|
|
+ for (StoreInfoVo storeInfo : result) {
|
|
|
+ if (storeInfo.getId() != null) {
|
|
|
+ try {
|
|
|
+ // 调用getStoreBusinessStatus方法获取营业时间
|
|
|
+ StoreBusinessStatusVo businessStatus = storeInfoService.getStoreBusinessStatus(String.valueOf(storeInfo.getId()));
|
|
|
+ if (businessStatus != null) {
|
|
|
+ // 设置营业时间信息到StoreInfoVo中
|
|
|
+ if (businessStatus.getStoreBusinessInfos() != null && !businessStatus.getStoreBusinessInfos().isEmpty()) {
|
|
|
+ storeInfo.setStoreBusinessInfos(businessStatus.getStoreBusinessInfos());
|
|
|
+ // 同时设置到openTime字段(格式化为字符串列表)
|
|
|
+ List<String> openTimeList = businessStatus.getStoreBusinessInfos().stream()
|
|
|
+ .map(info -> {
|
|
|
+ if (info.getBusinessDate() != null && info.getStartTime() != null && info.getEndTime() != null) {
|
|
|
+ return info.getBusinessDate() + " " + info.getStartTime() + "-" + info.getEndTime();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ })
|
|
|
+ .filter(time -> time != null)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ storeInfo.setOpenTime(openTimeList);
|
|
|
+ }
|
|
|
+ // 设置营业状态
|
|
|
+ if (businessStatus.getYyFlag() != null) {
|
|
|
+ storeInfo.setYyFlag(businessStatus.getYyFlag());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("获取门店营业时间失败,storeId: {}", storeInfo.getId(), e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 将下划线命名转换为驼峰命名
|
|
|
* 例如: store_tel -> storeTel, created_time -> createdTime
|
|
|
*/
|