修改回调处理
This commit is contained in:
@@ -3,8 +3,8 @@ package com.volvo.ai.analytic.center.mq;
|
|||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.volvo.ai.analytic.center.dto.req.DiFyReq;
|
|
||||||
import com.volvo.ai.analytic.center.dto.resp.AnalysisDifyResultDTO;
|
import com.volvo.ai.analytic.center.dto.resp.AnalysisDifyResultDTO;
|
||||||
|
import com.volvo.ai.analytic.center.dto.resp.AnalysisResp;
|
||||||
import com.volvo.ai.analytic.center.entity.AiAnalysisRequestLogs;
|
import com.volvo.ai.analytic.center.entity.AiAnalysisRequestLogs;
|
||||||
import com.volvo.ai.analytic.center.service.AiAnalysisRequestLogsService;
|
import com.volvo.ai.analytic.center.service.AiAnalysisRequestLogsService;
|
||||||
import com.volvo.ai.analytic.center.service.DiFyService;
|
import com.volvo.ai.analytic.center.service.DiFyService;
|
||||||
@@ -15,13 +15,13 @@ import org.apache.rocketmq.spring.core.RocketMQListener;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||||
|
import org.springframework.http.HttpEntity;
|
||||||
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
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 java.util.concurrent.CompletableFuture;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ClassName AnalysisDifyMqConsumer
|
* @ClassName AnalysisDifyMqConsumer
|
||||||
* @Description AI解析MQ-Callback处理
|
* @Description AI解析MQ-Callback处理
|
||||||
@@ -62,11 +62,17 @@ public class AnalysisDifyCallbackMqConsumer implements RocketMQListener<MessageE
|
|||||||
log.info("analysisDifyCallbackMqConsumer 当前线程: {}, 线程ID: {}", Thread.currentThread().getName(), Thread.currentThread().getId());
|
log.info("analysisDifyCallbackMqConsumer 当前线程: {}, 线程ID: {}", Thread.currentThread().getName(), Thread.currentThread().getId());
|
||||||
String message = new String(messageExt.getBody());
|
String message = new String(messageExt.getBody());
|
||||||
log.info("analysisDifyCallbackMqConsumer message: " + message);
|
log.info("analysisDifyCallbackMqConsumer message: " + message);
|
||||||
AnalysisDifyResultDTO analysisResp = JSONObject.parseObject(message, AnalysisDifyResultDTO.class);
|
AnalysisDifyResultDTO analysisRestDto = JSONObject.parseObject(message, AnalysisDifyResultDTO.class);
|
||||||
AiAnalysisRequestLogs aiAnalysisRequestLogs = aiAnalysisRequestLogsService.queryByAiAnalysisRequestId(analysisResp.getAiAnalysisRequestId());
|
AiAnalysisRequestLogs aiAnalysisRequestLogs = aiAnalysisRequestLogsService.queryByAiAnalysisRequestId(analysisRestDto.getAiAnalysisRequestId());
|
||||||
|
AnalysisResp analysisResp = new AnalysisResp();
|
||||||
ResponseEntity<String> response = restTemplate.getForEntity(aiAnalysisRequestLogs.getCallbackUrl(), String.class);
|
analysisResp.setAiAnalysisRequestId(analysisRestDto.getAiAnalysisRequestId());
|
||||||
|
analysisResp.setData(analysisRestDto.getDifyResponse());
|
||||||
|
|
||||||
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
headers.set("Content-Type", "application/json");
|
||||||
|
// 封装请求体和请求头
|
||||||
|
HttpEntity<AnalysisResp> requestEntity = new HttpEntity<>(analysisResp, headers);
|
||||||
|
ResponseEntity<String> response = restTemplate.postForEntity(aiAnalysisRequestLogs.getCallbackUrl(), requestEntity, String.class); // 响应类型);
|
||||||
if (response.getStatusCode().is2xxSuccessful()) {
|
if (response.getStatusCode().is2xxSuccessful()) {
|
||||||
log.info("analysisDifyCallbackMqConsumer aiAnalysisRequestId:{},回调请求成功,url:{}: " ,analysisResp.getAiAnalysisRequestId(), aiAnalysisRequestLogs.getCallbackUrl());
|
log.info("analysisDifyCallbackMqConsumer aiAnalysisRequestId:{},回调请求成功,url:{}: " ,analysisResp.getAiAnalysisRequestId(), aiAnalysisRequestLogs.getCallbackUrl());
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user