|
|
@@ -21,12 +21,17 @@ 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.*;
|
|
|
+import shop.alien.entity.store.CommonRating;
|
|
|
+import shop.alien.entity.store.LifeBlacklist;
|
|
|
+import shop.alien.entity.store.StoreImg;
|
|
|
+import shop.alien.entity.store.StoreUser;
|
|
|
import shop.alien.entity.store.vo.StoreBannerVo;
|
|
|
-import shop.alien.entity.store.vo.StoreBusinessInfoVo;
|
|
|
import shop.alien.entity.store.vo.StoreBusinessStatusVo;
|
|
|
import shop.alien.entity.store.vo.StoreInfoVo;
|
|
|
-import shop.alien.mapper.*;
|
|
|
+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;
|
|
|
@@ -53,7 +58,6 @@ public class AiSearchController {
|
|
|
|
|
|
private final StoreImgMapper storeImgMapper;
|
|
|
private final StoreUserMapper storeUserMapper;
|
|
|
- private final LifeUserMapper lifeUserMapper;
|
|
|
|
|
|
@Value("${third-party-ai-search.exact.base-url:http://124.93.18.180:7870/api/v1/search}")
|
|
|
private String aiSearchExactUrl;
|
|
|
@@ -71,88 +75,80 @@ public class AiSearchController {
|
|
|
private final LifeBlacklistMapper lifeBlacklistMapper;
|
|
|
private final AiAuthTokenUtil aiAuthTokenUtil;
|
|
|
|
|
|
- @TrackEvent(
|
|
|
- eventType = "SEARCH",
|
|
|
- eventCategory = "TRAFFIC",
|
|
|
- storeId = "",
|
|
|
- targetType = "STORE"
|
|
|
- )
|
|
|
- @RequestMapping("/search")
|
|
|
- public R search(@RequestBody Map<String,String> map) {
|
|
|
-
|
|
|
-
|
|
|
- // 初始化请求体Map
|
|
|
- Map<String, Object> requestBody = new HashMap<>();
|
|
|
- requestBody.put("query", map.get("storeName"));
|
|
|
- requestBody.put("page_size", map.get("pageSize"));
|
|
|
- requestBody.put("user_lat", map.get("lat"));
|
|
|
- requestBody.put("user_lng", map.get("lon"));
|
|
|
- requestBody.put("category", map.get("category"));
|
|
|
- requestBody.put("page", map.get("pageNum"));
|
|
|
- requestBody.put("sort_by", map.get("sortBy"));
|
|
|
- if("distance".equals(map.get("sortBy"))){
|
|
|
- requestBody.put("sort_order", "asc");
|
|
|
- } else {
|
|
|
- requestBody.put("sort_order", "desc");
|
|
|
- }
|
|
|
- LifeUser lifeUser = lifeUserMapper.selectById(map.get("userId"));
|
|
|
- if(lifeUser!=null){
|
|
|
- requestBody.put("fans_id","user_"+lifeUser.getUserPhone());
|
|
|
- }
|
|
|
- HttpHeaders aiHeaders = new HttpHeaders();
|
|
|
- String accessToken = aiAuthTokenUtil.getAccessToken();
|
|
|
- aiHeaders.setContentType(MediaType.APPLICATION_JSON);
|
|
|
- aiHeaders.set("Authorization", "Bearer " + accessToken);
|
|
|
-// aiHeaders.set("Authorization", "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1cHN0b3JlQGFkbWluLmNvbSIsImlkIjo2LCJ0aW1lIjoxNzYyOTI1NDAzLjY1MTY5MjZ9.07lz8Ox2cGC28UCmqcKCt5R6Rfwtgs-Eiu0ttgWRxws");
|
|
|
-
|
|
|
- HttpEntity<Map<String, Object>> request = new HttpEntity<>(requestBody, aiHeaders);
|
|
|
- try {
|
|
|
- log.info("调用AI检索店铺列表最上面根据店铺名查询 接口入参------{}", requestBody);
|
|
|
- ResponseEntity<String> stringResponseEntity = restTemplate.postForEntity(aiSearchExactUrl, request, String.class);
|
|
|
- String body = stringResponseEntity.getBody();
|
|
|
- log.info("调用AI检索店铺列表最上面根据店铺名查询 接口返回------{}", body);
|
|
|
- JSONObject jsonObject = JSONObject.parseObject(body);
|
|
|
- JSONObject jsonObject1 = new JSONObject();
|
|
|
- // 生活服务类别:转换为StoreInfoVo,确保返回的字段名按照StoreInfoVo定义
|
|
|
- // 模糊搜索:从related_results和matched_results字段获取数据
|
|
|
- List<StoreInfoVo> relatedResult = convertToStoreInfoList(jsonObject.getJSONArray("related_results"),map.get("userId"));
|
|
|
- List<StoreInfoVo> matchedResult = convertToStoreInfoList(jsonObject.getJSONArray("matched_results"),map.get("userId"));
|
|
|
-
|
|
|
- // 并发处理图片和营业时间,提升性能
|
|
|
- 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<>();
|
|
|
-// List<StoreInfoVo> matchedResults = new ArrayList<>();
|
|
|
-// matchedResults.addAll(matchedResult);
|
|
|
-// 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"));
|
|
|
- jsonObject1.put("size", map.get("pageSize"));
|
|
|
- log.info("调用AI搜索店铺列表最上面根据店铺名查询 后端处理后数据接口返回------{}", jsonObject1);
|
|
|
- return R.data(jsonObject1);
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("调用AI搜索接口 接口异常------", e);
|
|
|
- }
|
|
|
- return R.fail("请求失败");
|
|
|
- }
|
|
|
+// @TrackEvent(
|
|
|
+// eventType = "SEARCH",
|
|
|
+// eventCategory = "TRAFFIC",
|
|
|
+// storeId = "",
|
|
|
+// targetType = "STORE"
|
|
|
+// )
|
|
|
+// @RequestMapping("/search")
|
|
|
+// public R search(@RequestBody Map<String,String> map) {
|
|
|
+//
|
|
|
+//
|
|
|
+// // 初始化请求体Map
|
|
|
+// Map<String, Object> requestBody = new HashMap<>();
|
|
|
+// requestBody.put("query", map.get("storeName"));
|
|
|
+// requestBody.put("page_size", map.get("pageSize"));
|
|
|
+// requestBody.put("user_lat", map.get("lat"));
|
|
|
+// requestBody.put("user_lng", map.get("lon"));
|
|
|
+// requestBody.put("category", map.get("category"));
|
|
|
+// requestBody.put("page", map.get("pageNum"));
|
|
|
+// requestBody.put("sort_by", map.get("sortBy"));
|
|
|
+// requestBody.put("sort_order", "desc");
|
|
|
+// HttpHeaders aiHeaders = new HttpHeaders();
|
|
|
+// String accessToken = aiAuthTokenUtil.getAccessToken();
|
|
|
+// aiHeaders.setContentType(MediaType.APPLICATION_JSON);
|
|
|
+// aiHeaders.set("Authorization", "Bearer " + accessToken);
|
|
|
+//// aiHeaders.set("Authorization", "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1cHN0b3JlQGFkbWluLmNvbSIsImlkIjo2LCJ0aW1lIjoxNzYyOTI1NDAzLjY1MTY5MjZ9.07lz8Ox2cGC28UCmqcKCt5R6Rfwtgs-Eiu0ttgWRxws");
|
|
|
+//
|
|
|
+// HttpEntity<Map<String, Object>> request = new HttpEntity<>(requestBody, aiHeaders);
|
|
|
+// try {
|
|
|
+// log.info("调用AI检索店铺列表最上面根据店铺名查询 接口入参------{}", requestBody);
|
|
|
+// ResponseEntity<String> stringResponseEntity = restTemplate.postForEntity(aiSearchExactUrl, request, String.class);
|
|
|
+// String body = stringResponseEntity.getBody();
|
|
|
+// log.info("调用AI检索店铺列表最上面根据店铺名查询 接口返回------{}", body);
|
|
|
+// JSONObject jsonObject = JSONObject.parseObject(body);
|
|
|
+// JSONObject jsonObject1 = new JSONObject();
|
|
|
+// // 生活服务类别:转换为StoreInfoVo,确保返回的字段名按照StoreInfoVo定义
|
|
|
+// // 模糊搜索:从related_results和matched_results字段获取数据
|
|
|
+// List<StoreInfoVo> relatedResult = convertToStoreInfoList(jsonObject.getJSONArray("related_results"),map.get("userId"));
|
|
|
+// List<StoreInfoVo> matchedResult = convertToStoreInfoList(jsonObject.getJSONArray("matched_results"),map.get("userId"));
|
|
|
+//
|
|
|
+// // 并发处理图片和营业时间,提升性能
|
|
|
+// 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<>();
|
|
|
+//// List<StoreInfoVo> matchedResults = new ArrayList<>();
|
|
|
+//// matchedResults.addAll(matchedResult);
|
|
|
+//// 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"));
|
|
|
+// jsonObject1.put("size", map.get("pageSize"));
|
|
|
+// log.info("调用AI搜索店铺列表最上面根据店铺名查询 后端处理后数据接口返回------{}", jsonObject1);
|
|
|
+// return R.data(jsonObject1);
|
|
|
+// } catch (Exception e) {
|
|
|
+// log.error("调用AI搜索接口 接口异常------", e);
|
|
|
+// }
|
|
|
+// return R.fail("请求失败");
|
|
|
+// }
|
|
|
|
|
|
@RequestMapping("/fuzzySearch")
|
|
|
public R fuzzySearch(@RequestBody Map<String,String> map) {
|
|
|
@@ -165,11 +161,7 @@ public class AiSearchController {
|
|
|
requestBody.put("category", map.get("category"));
|
|
|
requestBody.put("page", map.get("pageNum"));
|
|
|
requestBody.put("sort_by", map.get("sortBy"));
|
|
|
- if("distance".equals(map.get("sortBy"))){
|
|
|
- requestBody.put("sort_order", "asc");
|
|
|
- } else {
|
|
|
- requestBody.put("sort_order", "desc");
|
|
|
- }
|
|
|
+ requestBody.put("sort_order", "desc");
|
|
|
HttpHeaders aiHeaders = new HttpHeaders();
|
|
|
String accessToken = aiAuthTokenUtil.getAccessToken();
|
|
|
aiHeaders.setContentType(MediaType.APPLICATION_JSON);
|
|
|
@@ -390,7 +382,7 @@ public class AiSearchController {
|
|
|
|
|
|
/**
|
|
|
* 批量填充营业时间到StoreInfoVo列表中
|
|
|
- * 通过调用storeInfoService.getStoreInfoBusinessHours方法获取营业时间(包含节假日信息)
|
|
|
+ * 通过调用storeInfoService.getStoreBusinessStatus方法获取营业时间
|
|
|
*
|
|
|
* @param result StoreInfoVo列表
|
|
|
*/
|
|
|
@@ -399,38 +391,32 @@ public class AiSearchController {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- // 遍历result集合,为每个门店调用getStoreInfoBusinessHours方法
|
|
|
+ // 遍历result集合,为每个门店调用getStoreBusinessStatus方法
|
|
|
for (StoreInfoVo storeInfo : result) {
|
|
|
if (storeInfo.getId() != null) {
|
|
|
try {
|
|
|
- // 调用getStoreInfoBusinessHours方法获取营业时间(包含节假日信息)
|
|
|
- List<StoreBusinessInfoVo> storeBusinessInfoVos = storeInfoService.getStoreInfoBusinessHours(storeInfo.getId());
|
|
|
- if (storeBusinessInfoVos != null && !storeBusinessInfoVos.isEmpty()) {
|
|
|
- // 设置包含节假日信息的营业时间列表
|
|
|
- storeInfo.setStoreBusinessInfoVos(storeBusinessInfoVos);
|
|
|
- // 转换为 List<StoreBusinessInfo> 用于兼容原有字段(StoreBusinessInfoVo 继承自 StoreBusinessInfo)
|
|
|
- List<StoreBusinessInfo> storeBusinessInfos = new ArrayList<>(storeBusinessInfoVos);
|
|
|
- storeInfo.setStoreBusinessInfos(storeBusinessInfos);
|
|
|
- // 设置第一个营业时间信息到 storeBusinessInfo 字段
|
|
|
- if (!storeBusinessInfos.isEmpty()) {
|
|
|
- storeInfo.setStoreBusinessInfo(storeBusinessInfos.get(0));
|
|
|
- }
|
|
|
- // 同时设置到openTime字段(格式化为字符串列表)
|
|
|
- List<String> openTimeList = storeBusinessInfoVos.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);
|
|
|
- }
|
|
|
- // 获取营业状态(通过getStoreBusinessStatus方法)
|
|
|
+ // 调用getStoreBusinessStatus方法获取营业时间
|
|
|
StoreBusinessStatusVo businessStatus = storeInfoService.getStoreBusinessStatus(String.valueOf(storeInfo.getId()));
|
|
|
- if (businessStatus != null && businessStatus.getYyFlag() != null) {
|
|
|
- storeInfo.setYyFlag(businessStatus.getYyFlag());
|
|
|
+ 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);
|