Bläddra i källkod

bugfix:2792查询列表过滤黑名单

刘云鑫 2 månader sedan
förälder
incheckning
dfd6f0a9e1

+ 16 - 5
alien-store/src/main/java/shop/alien/store/controller/AiSearchController.java

@@ -19,6 +19,7 @@ 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.vo.StoreInfoVo;
 import shop.alien.mapper.LifeBlacklistMapper;
@@ -80,15 +81,15 @@ public class AiSearchController {
 
         HttpEntity<Map<String, Object>> request = new HttpEntity<>(requestBody, null);
         try {
-            
+
             ResponseEntity<String> stringResponseEntity = restTemplate.postForEntity(aiSearchExactUrl, request, String.class);
             String body = stringResponseEntity.getBody();
             JSONObject jsonObject = JSONObject.parseObject(body);
             JSONObject jsonObject1 = new JSONObject();
             // 生活服务类别:转换为StoreInfoVo,确保返回的字段名按照StoreInfoVo定义
             // 模糊搜索:从related_results和matched_results字段获取数据
-            List<StoreInfoVo> relatedResult = convertToStoreInfoList(jsonObject.getJSONArray("related_results"));
-            List<StoreInfoVo> matchedResult = convertToStoreInfoList(jsonObject.getJSONArray("matched_results"));
+            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);
@@ -134,7 +135,7 @@ public class AiSearchController {
             JSONObject jsonObject = JSONObject.parseObject(body);
             JSONObject jsonObject1 = new JSONObject();
             // 模糊搜索:从related_results和matched_results字段获取数据
-            List<StoreInfoVo> result = convertToStoreInfoList(jsonObject.getJSONArray("results"));
+            List<StoreInfoVo> result = convertToStoreInfoList(jsonObject.getJSONArray("results"),map.get("userId"));
 
             // 查找图片并设置到result中(图片类型1-入口图)
             fillStoreImages(result, 1);
@@ -154,7 +155,14 @@ public class AiSearchController {
         return  R.fail("请求失败");
     }
 
-    private List<StoreInfoVo> convertToStoreInfoList(JSONArray results) {
+    private List<StoreInfoVo> convertToStoreInfoList(JSONArray results, String  userId) {
+        // 查找用户拉黑的商户
+        QueryWrapper<LifeBlacklist> queryWrapper = new QueryWrapper<LifeBlacklist>();
+        queryWrapper.eq("blocker_id",userId);
+        queryWrapper.eq("blocker_type",2);
+        queryWrapper.eq("blocked_type",1);
+        List<LifeBlacklist> lifeBlacklists = lifeBlacklistMapper.selectList(queryWrapper);
+        List<String> blockedIds = lifeBlacklists.stream().map(x -> x.getBlockedId()).collect(Collectors.toList());
         List<StoreInfoVo> storeInfoList = new ArrayList<>();
         if (results != null) {
             for (int i = 0; i < results.size(); i++) {
@@ -178,6 +186,9 @@ public class AiSearchController {
 
                 // 使用JSON.parseObject方法进行转换
                 StoreInfoVo storeInfo = JSON.parseObject(camelCaseItem.toJSONString(), StoreInfoVo.class);
+                if(blockedIds.contains(storeInfo.getId())){
+                    continue;
+                }
                 storeInfoList.add(storeInfo);
             }
         }