修改json格式化
This commit is contained in:
@@ -1,9 +1,12 @@
|
|||||||
package com.volvo.ai.analytic.center.controller;
|
package com.volvo.ai.analytic.center.controller;
|
||||||
|
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonParser;
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.volvo.ai.analytic.center.dto.req.AnalysisQueryReq;
|
import com.volvo.ai.analytic.center.dto.req.AnalysisQueryReq;
|
||||||
import com.volvo.ai.analytic.center.dto.req.AnalysisReq;
|
import com.volvo.ai.analytic.center.dto.req.AnalysisReq;
|
||||||
import com.volvo.ai.analytic.center.dto.resp.AnalysisDifyResultDTO;
|
|
||||||
import com.volvo.ai.analytic.center.dto.resp.AnalysisResp;
|
import com.volvo.ai.analytic.center.dto.resp.AnalysisResp;
|
||||||
import com.volvo.ai.analytic.center.service.AiAnalysisDifyService;
|
import com.volvo.ai.analytic.center.service.AiAnalysisDifyService;
|
||||||
import com.volvo.common.core.util.ResultMsg;
|
import com.volvo.common.core.util.ResultMsg;
|
||||||
@@ -14,7 +17,10 @@ import org.apache.rocketmq.spring.core.RocketMQTemplate;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
|
||||||
@RestController()
|
@RestController()
|
||||||
@@ -42,9 +48,19 @@ public class AiAnalysisDifyController {
|
|||||||
|
|
||||||
@PostMapping("/aiAnalyze")
|
@PostMapping("/aiAnalyze")
|
||||||
@ApiOperation(value = "Ai解析接口")
|
@ApiOperation(value = "Ai解析接口")
|
||||||
public AnalysisResp<Object> aiAnalyze(@Validated @RequestBody AnalysisReq analysisReq) {
|
public AnalysisResp<Object> aiAnalyze(@Validated @RequestBody String message) {
|
||||||
log.info("aiAnalyze data: {}",analysisReq);
|
log.info("aiAnalyze data: {}",message);
|
||||||
return aiAnalysisDifyService.aiAnalyze(analysisReq);
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
objectMapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_CONTROL_CHARS, true); // 允许未转义的控制字符
|
||||||
|
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||||
|
try {
|
||||||
|
AnalysisReq analysisReq = objectMapper.readValue(message, AnalysisReq.class);
|
||||||
|
analysisReq.validate();
|
||||||
|
return aiAnalysisDifyService.aiAnalyze(analysisReq);
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
log.info("aiAnalyze data error: {}",e);
|
||||||
|
return AnalysisResp.failed("解析失败");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/query")
|
@PostMapping("/query")
|
||||||
|
|||||||
Reference in New Issue
Block a user