|
|
@@ -1,5 +1,6 @@
|
|
|
package shop.alien.store.controller;
|
|
|
|
|
|
+import com.alibaba.fastjson2.JSONObject;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
@@ -14,6 +15,7 @@ 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 shop.alien.entity.result.R;
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
@@ -34,7 +36,7 @@ public class AiSearchController {
|
|
|
private final RestTemplate restTemplate;
|
|
|
|
|
|
@RequestMapping("/search")
|
|
|
- public ResponseEntity<String> search(@RequestBody Map<String,String> map) {
|
|
|
+ public R search(@RequestBody Map<String,String> map) {
|
|
|
|
|
|
|
|
|
// 初始化请求体Map
|
|
|
@@ -52,11 +54,18 @@ public class AiSearchController {
|
|
|
HttpEntity<Map<String, Object>> request = new HttpEntity<>(requestBody, null);
|
|
|
try {
|
|
|
ResponseEntity<String> stringResponseEntity = restTemplate.postForEntity(aiSearchUrl, request, String.class);
|
|
|
- return stringResponseEntity;
|
|
|
+ String body = stringResponseEntity.getBody();
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(body);
|
|
|
+ JSONObject jsonObject1 = new JSONObject();
|
|
|
+ jsonObject1.put("total",jsonObject.get("total"));
|
|
|
+ jsonObject1.put("records",jsonObject.get("results"));
|
|
|
+ jsonObject1.put("size",map.get("pageSize"));
|
|
|
+ log.info("调用AI搜索接口 接口返回------{}", body);
|
|
|
+ return R.data(jsonObject1);
|
|
|
} catch (Exception e) {
|
|
|
log.error("调用AI搜索接口 接口异常------", e);
|
|
|
}
|
|
|
- return ResponseEntity.badRequest().body(null);
|
|
|
+ return R.fail("请求失败");
|
|
|
}
|
|
|
|
|
|
|