From 8f832ec441d79d6d9f4d0483798cefca7983062f Mon Sep 17 00:00:00 2001 From: xupei Date: Wed, 31 Jan 2024 14:59:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9C=BA=E5=99=A8=E4=BA=BA=E8=AF=95=E7=94=A8?= =?UTF-8?q?=E5=88=B0=E6=9C=9F=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../security/filter/AuthenticationFilter.java | 2 +- .../da/service/impl/ChatRobotServiceImpl.java | 17 +++++++++++++---- src/main/resources/application.properties | 4 ++-- src/main/resources/messages_en.properties | 2 ++ src/main/resources/messages_zh.properties | 2 ++ 5 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/ai/da/common/security/filter/AuthenticationFilter.java b/src/main/java/com/ai/da/common/security/filter/AuthenticationFilter.java index c2625612..6efefd84 100644 --- a/src/main/java/com/ai/da/common/security/filter/AuthenticationFilter.java +++ b/src/main/java/com/ai/da/common/security/filter/AuthenticationFilter.java @@ -47,7 +47,7 @@ public class AuthenticationFilter extends OncePerRequestFilter { "/api/third/party/addUser","/api/third/party/addTrialUser", "/api/third/party/editUser", "/api/element/initDefaultSysFile", "/api/third/party/addNoLoginRequiredNew","/api/third/party/deleteNoLoginRequiredNew", "/api/third/party/existNoLoginRequired","/api/third/party/getRedirectUrl", - "/api/python/chatStream", +// "/api/python/chatStream", "/api/python/flush", "/api/account/healthy" ); diff --git a/src/main/java/com/ai/da/service/impl/ChatRobotServiceImpl.java b/src/main/java/com/ai/da/service/impl/ChatRobotServiceImpl.java index 650deb4c..9cfffaf1 100644 --- a/src/main/java/com/ai/da/service/impl/ChatRobotServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/ChatRobotServiceImpl.java @@ -182,7 +182,8 @@ public class ChatRobotServiceImpl implements ChatRobotService { chatRobot.setSessionId(data.getString("session_id")); BigDecimal totalCost = data.getBigDecimal("total_cost"); // 校验本次余额够不够 - checkBalance(totalCost, chatSendDTO.getUser_id()); + ChatRobotVO balance = checkBalance(totalCost, chatSendDTO.getUser_id()); + if (!Objects.isNull(balance)) return balance; chatRobot.setTotalCost(totalCost); chatRobot.setTotalTokens(data.getLong("total_tokens")); chatRobot.setUserId(chatSendDTO.getUser_id()); @@ -252,7 +253,7 @@ public class ChatRobotServiceImpl implements ChatRobotService { throw new BusinessException("chat-bot.interface.exception"); } - private void checkBalance(BigDecimal totalCost, Long userId) { + private ChatRobotVO checkBalance(BigDecimal totalCost, Long userId) { QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq("user_id", userId); queryWrapper.ge("create_time", LocalDateTime.now().withDayOfMonth(1).withHour(0).withMinute(0).withSecond(0)); @@ -262,16 +263,24 @@ public class ChatRobotServiceImpl implements ChatRobotService { if (!CollectionUtils.isEmpty(chatRobots)) { BigDecimal totalCostUsed = chatRobots.get(0).getTotalCost(); Account account = accountMapper.selectById(userId); + ChatRobot chatRobot = new ChatRobot(); if (account.getIsTrial() == 1) { if (totalCostUsed.add(totalCost).compareTo(BigDecimal.valueOf(0.1)) > 0) { - throw new BusinessException("Your balance is insufficient"); + String messageFromResource = BusinessException.getMessageFromResource("balance.insufficient.for.trial"); + chatRobot.setOutput(messageFromResource); +// throw new BusinessException("Your balance is insufficient"); + return CopyUtil.copyObject(chatRobot, ChatRobotVO.class); } }else { if (totalCostUsed.add(totalCost).compareTo(BigDecimal.valueOf(5)) > 0) { - throw new BusinessException("Your balance is insufficient"); + String messageFromResource = BusinessException.getMessageFromResource("balance.insufficient.for.paying"); + chatRobot.setOutput(messageFromResource); +// throw new BusinessException("Your balance is insufficient"); + return CopyUtil.copyObject(chatRobot, ChatRobotVO.class); } } } + return null; } @Override diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 47a99eb3..ec94939b 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,8 +1,8 @@ #����application-test�ļ�(���Ի���) -#spring.profiles.active=test +spring.profiles.active=test #����application-prod�ļ�(��������) -spring.profiles.active=test +#spring.profiles.active=prod #����application-dev�ļ�(��������) #spring.profiles.active=dev diff --git a/src/main/resources/messages_en.properties b/src/main/resources/messages_en.properties index 3fa4295a..ca17378d 100644 --- a/src/main/resources/messages_en.properties +++ b/src/main/resources/messages_en.properties @@ -152,6 +152,8 @@ classificationName.already.exists=The label name you've entered already exists. # 用来提醒用户可能会导致不良后果的操作,但不一定是错误。用户需要认真考虑是否继续当前操作。 the.classification.you.deleted.has.associated.library=The label you are attempting to delete is associated with existing data. Are you sure you wish to proceed with deletion? the.model.has.been.referenced.by.the.workspace=This model is currently in use by a workspace. Deleting it might affect the workspace. Confirm deletion only if you are sure. +balance.insufficient.for.trial=Want to continue using it immediately? Please consider upgrading to our subscription plan to get more quota. +balance.insufficient.for.paying=You have reached your usage limit for this month. # Errors: # 这类错误是由系统内部错误引起的,用户通常无法自行解决,需要联系支持或等待系统管理员介入。 diff --git a/src/main/resources/messages_zh.properties b/src/main/resources/messages_zh.properties index 6f330d93..8fecb5f9 100644 --- a/src/main/resources/messages_zh.properties +++ b/src/main/resources/messages_zh.properties @@ -150,6 +150,8 @@ classificationName.already.exists=您输入的标签名已存在。请输入不 # 用来提醒用户可能会导致不良后果的操作,但不一定是错误。用户需要认真考虑是否继续当前操作。 the.classification.you.deleted.has.associated.library=您正在尝试删除的标签与现有数据相关联。您确定要继续删除吗? the.model.has.been.referenced.by.the.workspace=此模型当前正在工作区中使用。删除它可能会影响工作区。仅在确信后再确认删除。 +balance.insufficient.for.trial=想要立即继续使用?请考虑升级到我们的订阅计划,以获得更多额度。 +balance.insufficient.for.paying=您已达到本月的使用额度限制。 # Errors: # 这类错误是由系统内部错误引起的,用户通常无法自行解决,需要联系支持或等待系统管理员介入。