修复部分逻辑
This commit is contained in:
parent
1a42ca6a55
commit
ef3b453bce
|
|
@ -99,6 +99,10 @@
|
|||
<artifactId>aspectjweaver</artifactId>
|
||||
<version>1.9.7</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-webflux</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import org.aspectj.lang.reflect.MethodSignature;
|
|||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.StopWatch;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
|
|
@ -26,6 +27,7 @@ public class ServiceAspect {
|
|||
*/
|
||||
@Around("execution(* com.electromagnetic.industry.software.manage.controller..*.*(..)))")
|
||||
public Object process(ProceedingJoinPoint jp) throws Throwable {
|
||||
|
||||
String methodInfo = jp.getTarget().getClass().getSimpleName() + "."
|
||||
+ jp.getSignature().getName();
|
||||
Object[] args = jp.getArgs();
|
||||
|
|
@ -41,13 +43,14 @@ public class ServiceAspect {
|
|||
}
|
||||
UserThreadLocal.setReqArgs(paramInfo);
|
||||
Object rvt = jp.proceed();
|
||||
if (rvt instanceof ResponseEntity) {
|
||||
|
||||
if (rvt instanceof ElectromagneticResult) {
|
||||
UserThreadLocal.setRes((ElectromagneticResult) rvt);
|
||||
String returnInfo = JSONUtil.toJsonStr(rvt);
|
||||
log.info("请求接口结束:{},返回参数:{},接口耗时:{}", methodInfo, returnInfo, (System.currentTimeMillis() - startTime) + "毫秒");
|
||||
} else {
|
||||
UserThreadLocal.setRes(ElectromagneticResultUtil.success(""));
|
||||
return rvt;
|
||||
}
|
||||
UserThreadLocal.setRes((ElectromagneticResult) rvt);
|
||||
String returnInfo = JSONUtil.toJsonStr(rvt);
|
||||
log.info("请求接口结束:{},返回参数:{},接口耗时:{}", methodInfo, returnInfo, (System.currentTimeMillis() - startTime) + "毫秒");
|
||||
stopwatch.stop();
|
||||
log.debug(stopwatch.prettyPrint());
|
||||
return rvt;
|
||||
|
|
|
|||
|
|
@ -6,14 +6,17 @@ import com.electromagnetic.industry.software.common.resp.ElectromagneticResult;
|
|||
import com.electromagnetic.industry.software.common.util.ElectromagneticResultUtil;
|
||||
import com.electromagnetic.industry.software.manage.pojo.req.ChatQueryDTO;
|
||||
import com.electromagnetic.industry.software.manage.service.serviceimpl.AiChatService;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.IOException;
|
||||
import java.time.Duration;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/data/ed/ai/")
|
||||
|
|
@ -22,9 +25,11 @@ public class AiChatController {
|
|||
@Resource
|
||||
private AiChatService aiChatService;
|
||||
|
||||
@RequestMapping(value = "chat")
|
||||
public ElectromagneticResult<?> chat(@RequestBody ChatQueryDTO chatQueryDTO) {
|
||||
return aiChatService.chat(chatQueryDTO.getQuestion());
|
||||
@RequestMapping(value = "chat", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
|
||||
public Flux<String> chat(@RequestBody ChatQueryDTO chatQueryDTO) {
|
||||
String content = aiChatService.chat(chatQueryDTO.getQuestion()).getData().toString();
|
||||
String[] stringArray = StrUtil.split(content, 1);
|
||||
return Flux.just(stringArray).delayElements(Duration.ofMillis(5000));
|
||||
}
|
||||
|
||||
@RequestMapping(value = "addKnowledge")
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ public class AiChatService {
|
|||
|
||||
public ElectromagneticResult<?> chat(String message) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("msg", message);
|
||||
String url = StrFormatter.format("http://{}:{}/data/ed/ai/chat", elePropertyConfig.getAiRemoteHost(), elePropertyConfig.getAiRemotePort());
|
||||
String res = HttpUtil.post(url, JSONUtil.toJsonStr(map), 5 * 60 * 1000);
|
||||
ElectromagneticResult<?> result = JSONUtil.toBean(res, ElectromagneticResult.class);
|
||||
|
|
|
|||
Loading…
Reference in New Issue