|
@@ -12,6 +12,8 @@ import com.rf.AIquantum.dialogue.dao.model.DialogueEntity;
|
|
|
import com.rf.AIquantum.dialogue.service.ChatHistoryService;
|
|
|
import com.rf.AIquantum.dialogue.service.DialogueService;
|
|
|
import com.rf.AIquantum.filter.JwtIgnore;
|
|
|
+import com.rf.AIquantum.param.model.ParamEntry;
|
|
|
+import com.rf.AIquantum.param.service.ParamService;
|
|
|
import com.rf.AIquantum.user.dao.model.TempUserEntity;
|
|
|
import com.rf.AIquantum.user.dao.model.UserEntity;
|
|
|
import com.rf.AIquantum.user.service.TempUserService;
|
|
@@ -80,6 +82,9 @@ public class DialogueController extends BaseController {
|
|
|
@Value("${chat_url}")
|
|
|
private String chat_url;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ParamService paramService;
|
|
|
+
|
|
|
@PostMapping("/saveChat")
|
|
|
@JwtIgnore
|
|
|
@ApiOperation(value = "保存对话", notes = "参数包括:phone:手机号, dialogueId:对话id(为空时是新建对话), content:消息内容,image:图片(可以为空)")
|
|
@@ -92,7 +97,7 @@ public class DialogueController extends BaseController {
|
|
|
tempUser.setRemainingCount(tempUser.getRemainingCount() - 1);
|
|
|
this.tempUserService.save(tempUser);
|
|
|
}
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
UserEntity user = this.userService.findUserByPhone(phone);
|
|
|
if (user == null) {
|
|
|
return fail(null, "用户不存在");
|
|
@@ -208,7 +213,10 @@ public class DialogueController extends BaseController {
|
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
|
// 创建请求体
|
|
|
okhttp3.RequestBody requestBody = okhttp3.RequestBody.create(jsonChat.toJSONString(), MediaType.parse("application/json"));
|
|
|
-
|
|
|
+ ParamEntry paramEntry = this.paramService.findByParamName("chat_url");
|
|
|
+ if (paramEntry != null) {
|
|
|
+ chat_url = paramEntry.getParamValue();
|
|
|
+ }
|
|
|
// 创建请求
|
|
|
Request request = new Request.Builder().header("Content-Type", "application/json").header("Accept", "text/event-stream")
|
|
|
.url(chat_url + Constant.CHAT_PATH)
|
|
@@ -216,8 +224,8 @@ public class DialogueController extends BaseController {
|
|
|
.build();
|
|
|
// 发送请求并处理响应
|
|
|
String progress = "undo";
|
|
|
- try ( Response response = client.newCall(request).execute()) {
|
|
|
- progress = "doing" ;
|
|
|
+ try (Response response = client.newCall(request).execute()) {
|
|
|
+ progress = "doing";
|
|
|
if (!response.isSuccessful()) {
|
|
|
log.error("Unexpected code " + response);
|
|
|
return fail();
|
|
@@ -296,7 +304,7 @@ 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")){
|
|
|
+ while (progress.equals("doing")) {
|
|
|
Thread.sleep(100);
|
|
|
}
|
|
|
return success(chatHistoryEntity);
|