单条语音结果入库
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
package com.volvo.ai.analytic.center.mq;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.volvo.ai.analytic.center.constant.Constant;
|
||||
import com.volvo.ai.analytic.center.entity.TmCorpusQuestionReport;
|
||||
import com.volvo.ai.analytic.center.feign.DiFyFeign;
|
||||
import com.volvo.ai.analytic.center.mapper.TmCorpusQuestionReportMapper;
|
||||
import com.volvo.ai.analytic.center.utils.ConstantStr;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
|
||||
@@ -13,6 +16,7 @@ import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -27,7 +31,8 @@ public class CorpusQuestionConsumer implements RocketMQListener<Map<String, Obje
|
||||
@Value("${dify.corpusQuestion.token:app-erbXevAmaQiyg5QFPn2NpJ7G}")
|
||||
private String corpusQuestionToken;
|
||||
|
||||
|
||||
@Autowired
|
||||
TmCorpusQuestionReportMapper tmCorpusQuestionReportMapper;
|
||||
@Autowired
|
||||
private DiFyFeign diFyFeign;
|
||||
|
||||
@@ -40,9 +45,33 @@ public class CorpusQuestionConsumer implements RocketMQListener<Map<String, Obje
|
||||
Map<String, Object> requestMap = new HashMap<>();
|
||||
requestMap.put("inputs", inputMap);
|
||||
requestMap.put("user", ConstantStr.CORPUS_QUESTION_USER);
|
||||
requestMap.put("response_mode","blocking");
|
||||
requestMap.put("response_mode", "blocking");
|
||||
|
||||
JSONObject difyResult = diFyFeign.runWorkflows("Bearer " + corpusQuestionToken, requestMap);
|
||||
log.info("dify corpusQuestionResult {}", difyResult.toJSONString());
|
||||
try {
|
||||
JSONObject difyResult = diFyFeign.runWorkflows("Bearer " + corpusQuestionToken, requestMap);
|
||||
log.info("dify corpusQuestionResult {}", difyResult.toJSONString());
|
||||
JSONObject data = difyResult.getJSONObject("data");
|
||||
|
||||
if (data.get("status").equals("succeeded")) {
|
||||
JSONObject outputJson = data.getJSONObject("outputs");
|
||||
JSONObject textJsonObject = JSONObject.parseObject(outputJson.getString("text"));
|
||||
JSONObject consultingScenario = textJsonObject.getJSONObject("consultingScenario");
|
||||
TmCorpusQuestionReport tmCorpusQuestionReport = new TmCorpusQuestionReport();
|
||||
tmCorpusQuestionReport.setBusinessType(outputJson.getString("businessType"));
|
||||
tmCorpusQuestionReport.setSourceCorpusId(outputJson.getString("sourceCorpusId"));
|
||||
|
||||
Date sourceCorpusDate = DateUtil.parse(outputJson.getString("sourceCorpusTime"), "yyyy-MM-dd HH:mm:ss");
|
||||
tmCorpusQuestionReport.setAnalysisResultJson(outputJson.toJSONString());
|
||||
tmCorpusQuestionReport.setMainCategory(consultingScenario.getString("mainCategory"));
|
||||
tmCorpusQuestionReport.setSubCategory(consultingScenario.getString("subCategory"));
|
||||
tmCorpusQuestionReport.setConfidence(consultingScenario.getString("confidence"));
|
||||
tmCorpusQuestionReport.setSourceCorpusTime(sourceCorpusDate);
|
||||
tmCorpusQuestionReportMapper.insert(tmCorpusQuestionReport);
|
||||
} else {
|
||||
log.info("dify corpusQuestion fail {}", JSON.toJSONString(inputMap));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.info("dify corpusQuestion Exception {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user