Browse Source

1.新增错误码2002,临时用户体验次数用完
2.大模型链接地址动态调整,外置配置文件
3.启动命令:nohup java -jar AIquantum-v1.1-20250325093034.jar --spring.config.location=./application.yml > ai_20250325.log &

zzf 1 week ago
parent
commit
5f9f845ce7

+ 4 - 0
src/main/java/com/rf/AIquantum/base/rest/BaseController.java

@@ -48,6 +48,10 @@ public class BaseController {
         return new Result<>(HttpStatus.RUNTIME_EXCEPTION, message);
     }
 
+    protected static <T> Result<T> noAuth(String message) {
+        return new Result<>(HttpStatus.NO_AUTH_ERROR, message);
+    }
+
     protected static <T> Result<T> fail(String code ,T data ,String message){
         if(data == null)
             return new Result<>(code,message);

+ 4 - 1
src/main/java/com/rf/AIquantum/dialogue/rest/ChatHistoryController.java

@@ -21,6 +21,7 @@ import okhttp3.Response;
 import okio.BufferedSource;
 import org.apache.commons.lang.StringUtils;
 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 javax.servlet.http.HttpServletResponse;
@@ -47,6 +48,8 @@ public class ChatHistoryController extends BaseController {
 
     @Autowired
     private SseEmitterService sseEmitterService;
+    @Value("${chat_url}")
+    private String chat_url;
 
     @GetMapping("/findChats")
     @ApiOperation(value = "查询聊天记录", notes = "参数包括:pageNum:页码, pageSize:数量, dialogueId:对话id")
@@ -137,7 +140,7 @@ public class ChatHistoryController 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();
         // 发送请求并处理响应

+ 14 - 5
src/main/java/com/rf/AIquantum/dialogue/rest/DialogueController.java

@@ -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);
     }
 

+ 1 - 1
src/main/java/com/rf/AIquantum/user/rest/UserController.java

@@ -265,7 +265,7 @@ public class UserController extends BaseController {
             tempUserEntity = this.tempUserService.save(tempUserEntity);
         }else {
             if(tempUserEntity.getRemainingCount() == 0){
-                return fail("体验次数已用完,请注册新账号!");
+                return noAuth("体验次数已用完,请注册新账号!");
             }
         }
         UserEntity userEntity = new UserEntity();

+ 2 - 0
src/main/java/com/rf/AIquantum/utils/HttpStatus.java

@@ -11,6 +11,8 @@ public interface HttpStatus {
 
     String RUNTIME_EXCEPTION = "2001";
 
+     String NO_AUTH_ERROR = "2002";
+
     String SERVER_EXCEPTION = "500100";
 
     String PARAMETER_ISNULL = "500101";

+ 2 - 1
src/main/resources/config/application-prod.yml

@@ -41,7 +41,8 @@ spring:
         exclusions: "*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*"
         enabled: true
         session-stat-enable: true
-
+#大模型地址
+chat_url: https://u439933-be67-e6e9dd45.bjc1.seetacloud.com:8443
 
 
 

+ 2 - 0
src/main/resources/config/application-test.yml

@@ -44,6 +44,8 @@ spring:
 #swagger 显示隐藏配置
 swagger:
   show: true
+#大模型地址
+chat_url: https://u439933-be67-e6e9dd45.bjc1.seetacloud.com:8443