فهرست منبع

bugfix:ai搜索

lyx 3 ماه پیش
والد
کامیت
f339037139
1فایلهای تغییر یافته به همراه84 افزوده شده و 0 حذف شده
  1. 84 0
      alien-store/src/main/java/shop/alien/store/controller/AiSearchController.java

+ 84 - 0
alien-store/src/main/java/shop/alien/store/controller/AiSearchController.java

@@ -0,0 +1,84 @@
+package shop.alien.store.controller;
+
+import io.swagger.annotations.Api;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.cloud.context.config.annotation.RefreshScope;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.CrossOrigin;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.client.RestTemplate;
+
+import java.util.HashMap;
+import java.util.Map;
+
+
+@Slf4j
+@Api(tags = {"ai搜索"})
+@CrossOrigin
+@RestController
+@RequestMapping("/aiSearch")
+@RequiredArgsConstructor
+@RefreshScope
+public class AiSearchController {
+
+    @Value("${third-party-ai-search.base-url:http://124.93.18.180:7870/api/v1/search}")
+    private String aiSearchUrl;
+
+    private final RestTemplate restTemplate;
+
+    @RequestMapping("/search")
+    public ResponseEntity<String> search(@RequestBody Map<String,String> map) {
+
+
+        // 初始化请求体Map
+        Map<String, Object> requestBody = new HashMap<>();
+        requestBody.put("query", map.get("storeName"));
+        requestBody.put("limit", map.get("pageSize"));
+        requestBody.put("user_lat", map.get("lat"));
+        requestBody.put("user_lng", map.get("lan"));
+        requestBody.put("category", map.get("category"));
+        HttpHeaders aiHeaders = new HttpHeaders();
+        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, null);
+        try {
+            ResponseEntity<String> stringResponseEntity = restTemplate.postForEntity(aiSearchUrl, request, String.class);
+            return stringResponseEntity;
+        } catch (Exception e) {
+            log.error("调用AI搜索接口 接口异常------", e);
+        }
+        return  ResponseEntity.badRequest().body(null);
+    }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+}