|
@@ -36,6 +36,7 @@ import org.apache.http.impl.client.CloseableHttpClient;
|
|
|
import org.apache.http.impl.client.HttpClients;
|
|
|
import org.apache.http.util.EntityUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
@@ -76,14 +77,17 @@ public class DialogueController extends BaseController {
|
|
|
@Autowired
|
|
|
private TempUserService tempUserService;
|
|
|
|
|
|
+ @Value("${chat_url}")
|
|
|
+ private String chat_url;
|
|
|
+
|
|
|
@PostMapping("/saveChat")
|
|
|
@JwtIgnore
|
|
|
@ApiOperation(value = "保存对话", notes = "参数包括:phone:手机号, dialogueId:对话id(为空时是新建对话), content:消息内容,image:图片(可以为空)")
|
|
|
- public Result saveChat(MultipartFile image, String phone, String dialogueId, String content) {
|
|
|
+ public Result saveChat(MultipartFile image, String phone, String dialogueId, String content) throws InterruptedException {
|
|
|
TempUserEntity tempUser = this.tempUserService.findByIp(phone);
|
|
|
if (tempUser != null) {
|
|
|
if (tempUser.getRemainingCount() <= 0) {
|
|
|
- return fail("体验次数已用完,请注册新账号!");
|
|
|
+ return noAuth("体验次数已用完,请注册新账号!");
|
|
|
} else {
|
|
|
tempUser.setRemainingCount(tempUser.getRemainingCount() - 1);
|
|
|
this.tempUserService.save(tempUser);
|
|
@@ -207,11 +211,13 @@ public class DialogueController extends BaseController {
|
|
|
|
|
|
// 创建请求
|
|
|
Request request = new Request.Builder().header("Content-Type", "application/json").header("Accept", "text/event-stream")
|
|
|
- .url(Constant.INVOKE_IP_PROT + Constant.CHAT_PATH)
|
|
|
+ .url(chat_url + Constant.CHAT_PATH)
|
|
|
.post(requestBody)
|
|
|
.build();
|
|
|
// 发送请求并处理响应
|
|
|
- try (Response response = client.newCall(request).execute()) {
|
|
|
+ String progress = "undo";
|
|
|
+ try ( Response response = client.newCall(request).execute()) {
|
|
|
+ progress = "doing" ;
|
|
|
if (!response.isSuccessful()) {
|
|
|
log.error("Unexpected code " + response);
|
|
|
return fail();
|
|
@@ -269,6 +275,7 @@ public class DialogueController extends BaseController {
|
|
|
}
|
|
|
Thread.sleep(5);
|
|
|
}
|
|
|
+ progress = "done";
|
|
|
} catch (InterruptedException e) {
|
|
|
throw new RuntimeException(e);
|
|
|
} finally {
|
|
@@ -289,7 +296,9 @@ public class DialogueController extends BaseController {
|
|
|
chatHistoryEntity.setCreateTime(DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss.SSS"));
|
|
|
chatHistoryEntity.setUpdateTime(DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss.SSS"));
|
|
|
chatHistoryEntity = this.chatHistoryService.save(chatHistoryEntity);
|
|
|
-
|
|
|
+ while (progress.equals("doing")){
|
|
|
+ Thread.sleep(100);
|
|
|
+ }
|
|
|
return success(chatHistoryEntity);
|
|
|
}
|
|
|
|