修复部分逻辑

This commit is contained in:
chenxudong 2025-04-02 11:46:18 +08:00
parent 1a42ca6a55
commit ef3b453bce
4 changed files with 22 additions and 9 deletions

View File

@ -99,6 +99,10 @@
<artifactId>aspectjweaver</artifactId> <artifactId>aspectjweaver</artifactId>
<version>1.9.7</version> <version>1.9.7</version>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
</dependencies> </dependencies>
<build> <build>

View File

@ -13,6 +13,7 @@ import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.util.StopWatch; import org.springframework.util.StopWatch;
import reactor.core.publisher.Flux;
import java.util.Objects; import java.util.Objects;
@ -26,6 +27,7 @@ public class ServiceAspect {
*/ */
@Around("execution(* com.electromagnetic.industry.software.manage.controller..*.*(..)))") @Around("execution(* com.electromagnetic.industry.software.manage.controller..*.*(..)))")
public Object process(ProceedingJoinPoint jp) throws Throwable { public Object process(ProceedingJoinPoint jp) throws Throwable {
String methodInfo = jp.getTarget().getClass().getSimpleName() + "." String methodInfo = jp.getTarget().getClass().getSimpleName() + "."
+ jp.getSignature().getName(); + jp.getSignature().getName();
Object[] args = jp.getArgs(); Object[] args = jp.getArgs();
@ -41,15 +43,16 @@ public class ServiceAspect {
} }
UserThreadLocal.setReqArgs(paramInfo); UserThreadLocal.setReqArgs(paramInfo);
Object rvt = jp.proceed(); 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("")); UserThreadLocal.setRes(ElectromagneticResultUtil.success(""));
return rvt;
} }
UserThreadLocal.setRes((ElectromagneticResult) rvt);
String returnInfo = JSONUtil.toJsonStr(rvt);
log.info("请求接口结束:{},返回参数:{},接口耗时:{}", methodInfo, returnInfo, (System.currentTimeMillis() - startTime) + "毫秒");
stopwatch.stop(); stopwatch.stop();
log.debug(stopwatch.prettyPrint()); log.debug(stopwatch.prettyPrint());
return rvt; return rvt;
} }
} }

View File

@ -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.common.util.ElectromagneticResultUtil;
import com.electromagnetic.industry.software.manage.pojo.req.ChatQueryDTO; import com.electromagnetic.industry.software.manage.pojo.req.ChatQueryDTO;
import com.electromagnetic.industry.software.manage.service.serviceimpl.AiChatService; 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.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import reactor.core.publisher.Flux;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.IOException; import java.io.IOException;
import java.time.Duration;
@RestController @RestController
@RequestMapping("/data/ed/ai/") @RequestMapping("/data/ed/ai/")
@ -22,9 +25,11 @@ public class AiChatController {
@Resource @Resource
private AiChatService aiChatService; private AiChatService aiChatService;
@RequestMapping(value = "chat") @RequestMapping(value = "chat", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
public ElectromagneticResult<?> chat(@RequestBody ChatQueryDTO chatQueryDTO) { public Flux<String> chat(@RequestBody ChatQueryDTO chatQueryDTO) {
return aiChatService.chat(chatQueryDTO.getQuestion()); 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") @RequestMapping(value = "addKnowledge")

View File

@ -24,6 +24,7 @@ public class AiChatService {
public ElectromagneticResult<?> chat(String message) { public ElectromagneticResult<?> chat(String message) {
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
map.put("msg", message);
String url = StrFormatter.format("http://{}:{}/data/ed/ai/chat", elePropertyConfig.getAiRemoteHost(), elePropertyConfig.getAiRemotePort()); String url = StrFormatter.format("http://{}:{}/data/ed/ai/chat", elePropertyConfig.getAiRemoteHost(), elePropertyConfig.getAiRemotePort());
String res = HttpUtil.post(url, JSONUtil.toJsonStr(map), 5 * 60 * 1000); String res = HttpUtil.post(url, JSONUtil.toJsonStr(map), 5 * 60 * 1000);
ElectromagneticResult<?> result = JSONUtil.toBean(res, ElectromagneticResult.class); ElectromagneticResult<?> result = JSONUtil.toBean(res, ElectromagneticResult.class);