|
|
@@ -27,77 +27,25 @@ import java.util.UUID;
|
|
|
|
|
|
@RestController
|
|
|
@RequestMapping(value = "/chat")
|
|
|
-public class BaiduAiController {
|
|
|
+public class BaiduAiController extends CertifyApiController{
|
|
|
|
|
|
@Autowired
|
|
|
private BaiduAiService baiduAiService;
|
|
|
|
|
|
@RequestMapping(value = "/send")
|
|
|
- public SseEmitter sendChat(@RequestBody InputSendChat in){
|
|
|
+ public Object sendChat(@RequestBody InputSendChat in){
|
|
|
if (in.getUserId()==null ){
|
|
|
in.setUserId(UUID.randomUUID().toString());
|
|
|
in.setStream(true);
|
|
|
}
|
|
|
-// List<Messages> messages =new ArrayList<>();
|
|
|
-// messages.add(new Messages("user","实用新型专利主要应用哪些领域?"));
|
|
|
-// in.setMessages(messages);
|
|
|
if (in.getMessages()==null||in.getMessages().isEmpty()){
|
|
|
- throw new BusinessException("消息内容不能为空");
|
|
|
+ Result res= new Result();
|
|
|
+ res.getError().add(buildError(ErrorConstants.PARAM_ERROR,"访问参数"));
|
|
|
+ return res;
|
|
|
}
|
|
|
return baiduAiService.sendChat(in);
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- @RequestMapping("/start")
|
|
|
- public SseEmitter testSseEmitter(String clientId) {
|
|
|
- // 默认30秒超时,设置为0L则永不超时
|
|
|
- SseEmitterUTF8 sseEmitter = new SseEmitterUTF8(3600_000L);
|
|
|
-// if (clientId==null)clientId=UUID.randomUUID().toString();
|
|
|
- SseMap.sseEmitterMap.put(clientId, new SseResult(clientId, System.currentTimeMillis(), sseEmitter));
|
|
|
- return sseEmitter;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 向SseEmitter对象发送数据
|
|
|
- *
|
|
|
- * @param clientId
|
|
|
- * @return
|
|
|
- */
|
|
|
- @RequestMapping("/send2")
|
|
|
- public String setSseEmitter(String clientId) {
|
|
|
- try {
|
|
|
- SseResult result = SseMap.sseEmitterMap.get(clientId);
|
|
|
- if (result != null && result.sseEmitter != null) {
|
|
|
- long timeInMillis = Calendar.getInstance().getTimeInMillis();
|
|
|
- String re = "{\"success\":true,\"message\":\"操作成功!\",\"code\":200,\"result\":{\"id\":1018},\"timestamp\":"+timeInMillis+"}";
|
|
|
- result.sseEmitter.send(re);
|
|
|
- }
|
|
|
- } catch (IOException e) {
|
|
|
- LoggerUtils.error(getClass(),"IOException");
|
|
|
- return "error";
|
|
|
- }
|
|
|
- return "Succeed!";
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 将SseEmitter对象设置成完成
|
|
|
- *
|
|
|
- * @param clientId
|
|
|
- * @return
|
|
|
- */
|
|
|
- @RequestMapping("/end")
|
|
|
- public String completeSseEmitter(String clientId) {
|
|
|
- SseResult result = SseMap.sseEmitterMap.get(clientId);
|
|
|
- if (result != null) {
|
|
|
- SseMap.sseEmitterMap.remove(clientId);
|
|
|
- result.sseEmitter.complete();
|
|
|
- }
|
|
|
- return "Succeed!";
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
}
|