|
@@ -15,6 +15,7 @@ import org.springframework.web.bind.annotation.RequestBody;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
+import shop.alien.lawyer.service.AiUserAuditTaskService;
|
|
|
import shop.alien.lawyer.util.ai.AiAuthTokenUtil;
|
|
import shop.alien.lawyer.util.ai.AiAuthTokenUtil;
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
@@ -31,11 +32,10 @@ public class AiAutoReview {
|
|
|
|
|
|
|
|
private final RestTemplate restTemplate;
|
|
private final RestTemplate restTemplate;
|
|
|
|
|
|
|
|
- @Value("${third-party-ai-auto-review.base-url:http://192.168.2.250:9100/ai/auto-review/api/v1/lawyer_complaint_audit_task/submit}")
|
|
|
|
|
- private String aiAutoReviewUrl;
|
|
|
|
|
|
|
+ private final AiUserAuditTaskService aiUserAuditTaskService;
|
|
|
|
|
|
|
|
- @Value("${third-party-ai-auto-review.base-url:http://192.168.2.250:9100/ai/auto-review/api/v1/lawyer_user_complaint_audit_task/submit}")
|
|
|
|
|
- private String aiUserAuditTaskUrl;
|
|
|
|
|
|
|
+ @Value("${third-party-ai-auto-review.lawyer-complaint-url:http://192.168.2.250:9100/ai/auto-review/api/v1/lawyer_complaint_audit_task/submit}")
|
|
|
|
|
+ private String aiAutoReviewUrl;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 调用 AI 服务,获取申诉结果
|
|
* 调用 AI 服务,获取申诉结果
|
|
@@ -66,27 +66,52 @@ public class AiAutoReview {
|
|
|
return ResponseEntity.badRequest().body(null);
|
|
return ResponseEntity.badRequest().body(null);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 用户申诉任务接口(异步处理)
|
|
|
|
|
+ * <p>
|
|
|
|
|
+ * 接口立即返回,AI服务调用在后台异步执行
|
|
|
|
|
+ * </p>
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param requestBody 请求参数
|
|
|
|
|
+ * @return 立即返回成功响应
|
|
|
|
|
+ */
|
|
|
@RequestMapping("/userAuditTask")
|
|
@RequestMapping("/userAuditTask")
|
|
|
- public ResponseEntity<String> userAuditTask(@RequestBody Map<String, Object> requestBody){
|
|
|
|
|
|
|
+ public ResponseEntity<String> userAuditTask(@RequestBody Map<String, Object> requestBody) {
|
|
|
|
|
+ log.info("接收用户申诉任务请求,请求参数:{}", requestBody);
|
|
|
|
|
+
|
|
|
|
|
+ // 参数校验
|
|
|
|
|
+ if (requestBody == null || requestBody.isEmpty()) {
|
|
|
|
|
+ log.warn("用户申诉任务请求参数为空");
|
|
|
|
|
+ JSONObject errorData = new JSONObject();
|
|
|
|
|
+ errorData.put("code", 400);
|
|
|
|
|
+ errorData.put("message", "请求参数不能为空");
|
|
|
|
|
+ return ResponseEntity.badRequest().body(errorData.toJSONString());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 同步获取访问令牌(不在异步中执行)
|
|
|
String accessToken = aiAuthTokenUtil.getAccessToken();
|
|
String accessToken = aiAuthTokenUtil.getAccessToken();
|
|
|
- JSONObject data = new JSONObject();
|
|
|
|
|
if (!StringUtils.hasText(accessToken)) {
|
|
if (!StringUtils.hasText(accessToken)) {
|
|
|
- data.put("fail","登录失败");
|
|
|
|
|
- return ResponseEntity.badRequest().body(data.toJSONString());
|
|
|
|
|
|
|
+ log.error("调用AI用户申诉接口失败,获取accessToken失败");
|
|
|
|
|
+ JSONObject errorData = new JSONObject();
|
|
|
|
|
+ errorData.put("code", 500);
|
|
|
|
|
+ errorData.put("message", "获取访问令牌失败");
|
|
|
|
|
+ return ResponseEntity.status(500).body(errorData.toJSONString());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 初始化请求体Map
|
|
|
|
|
- HttpHeaders aiHeaders = new HttpHeaders();
|
|
|
|
|
- aiHeaders.setContentType(MediaType.APPLICATION_JSON);
|
|
|
|
|
- aiHeaders.set("Authorization", "Bearer " + accessToken);
|
|
|
|
|
-
|
|
|
|
|
- HttpEntity<Map<String, Object>> request = new HttpEntity<>(requestBody, aiHeaders);
|
|
|
|
|
|
|
+ // 异步调用AI服务(传递已获取的访问令牌)
|
|
|
try {
|
|
try {
|
|
|
- ResponseEntity<String> stringResponseEntity = restTemplate.postForEntity(aiUserAuditTaskUrl, request, String.class);
|
|
|
|
|
- return stringResponseEntity;
|
|
|
|
|
|
|
+ aiUserAuditTaskService.asyncCallUserAuditTask(requestBody, accessToken);
|
|
|
|
|
+ log.info("用户申诉任务已提交异步处理,请求参数:{}", requestBody);
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
- log.error("调用AI用户申诉接口 接口异常------", e);
|
|
|
|
|
|
|
+ log.error("提交用户申诉任务异步处理失败,请求参数:{},异常信息:{}", requestBody, e.getMessage(), e);
|
|
|
}
|
|
}
|
|
|
- return ResponseEntity.badRequest().body(null);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // 立即返回成功响应
|
|
|
|
|
+ JSONObject responseData = new JSONObject();
|
|
|
|
|
+ responseData.put("code", 200);
|
|
|
|
|
+ responseData.put("message", "用户申诉任务已提交,正在后台处理");
|
|
|
|
|
+ responseData.put("data", new JSONObject());
|
|
|
|
|
+
|
|
|
|
|
+ return ResponseEntity.ok(responseData.toJSONString());
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|