From 878b5a129ce6bf6cd36f1ada196ed8aac54eb75e Mon Sep 17 00:00:00 2001 From: shahaibo <1023316923@qq.com> Date: Tue, 30 Jan 2024 14:20:01 +0800 Subject: [PATCH 1/3] =?UTF-8?q?TASK:=E8=AF=95=E7=94=A8=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E6=9C=BA=E5=99=A8=E4=BA=BA=E4=BD=99=E9=A2=9D;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../da/service/impl/ChatRobotServiceImpl.java | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) 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 5f06a194..1300292f 100644 --- a/src/main/java/com/ai/da/service/impl/ChatRobotServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/ChatRobotServiceImpl.java @@ -9,7 +9,9 @@ import com.ai.da.common.enums.LibraryLevel1TypeEnum; import com.ai.da.common.utils.CopyUtil; import com.ai.da.common.utils.MD5Utils; import com.ai.da.common.utils.MinioUtil; +import com.ai.da.mapper.AccountMapper; import com.ai.da.mapper.LibraryMapper; +import com.ai.da.mapper.entity.Account; import com.ai.da.mapper.entity.ChatRobot; import com.ai.da.mapper.ChatRobotMapper; import com.ai.da.mapper.entity.Library; @@ -74,6 +76,8 @@ public class ChatRobotServiceImpl implements ChatRobotService { @Value("${minio.bucketName.sysImage}") private String sysImage; + @Resource + private AccountMapper accountMapper; Gson gson = new GsonBuilder().create(); private final ExecutorService executorService = Executors.newSingleThreadExecutor(); @@ -257,8 +261,15 @@ public class ChatRobotServiceImpl implements ChatRobotService { List chatRobots = chatRobotMapper.selectList(queryWrapper); if (!CollectionUtils.isEmpty(chatRobots)) { BigDecimal totalCostUsed = chatRobots.get(0).getTotalCost(); - if (totalCostUsed.add(totalCost).compareTo(BigDecimal.valueOf(5)) > 0) { - throw new BusinessException("Your balance is insufficient"); + Account account = accountMapper.selectById(userId); + if (account.getIsTrial() == 1) { + if (totalCostUsed.add(totalCost).compareTo(BigDecimal.valueOf(0.1)) > 0) { + throw new BusinessException("Your balance is insufficient"); + } + }else { + if (totalCostUsed.add(totalCost).compareTo(BigDecimal.valueOf(5)) > 0) { + throw new BusinessException("Your balance is insufficient"); + } } } } @@ -323,9 +334,13 @@ public class ChatRobotServiceImpl implements ChatRobotService { if (CollectionUtils.isEmpty(chatRobots)) { return BigDecimal.ONE; } else { + Account account = accountMapper.selectById(userId); BigDecimal totalCost = BigDecimal.valueOf(5).subtract(chatRobots.get(0).getTotalCost()); - BigDecimal result = totalCost.divide(BigDecimal.valueOf(5), 4, RoundingMode.HALF_UP); - return result; + if (account.getIsTrial() == 1) { + return totalCost.divide(BigDecimal.valueOf(0.1), 4, RoundingMode.HALF_UP); + }else { + return totalCost.divide(BigDecimal.valueOf(5), 4, RoundingMode.HALF_UP); + } } } From 5e1573ae0966a6b933e78080cee669e283a750bd Mon Sep 17 00:00:00 2001 From: shahaibo <1023316923@qq.com> Date: Tue, 30 Jan 2024 15:07:34 +0800 Subject: [PATCH 2/3] =?UTF-8?q?TASK:=E8=AF=95=E7=94=A8=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E6=9C=BA=E5=99=A8=E4=BA=BA=E4=BD=99=E9=A2=9D;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/ai/da/service/impl/ChatRobotServiceImpl.java | 1 + 1 file changed, 1 insertion(+) 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 1300292f..650deb4c 100644 --- a/src/main/java/com/ai/da/service/impl/ChatRobotServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/ChatRobotServiceImpl.java @@ -337,6 +337,7 @@ public class ChatRobotServiceImpl implements ChatRobotService { Account account = accountMapper.selectById(userId); BigDecimal totalCost = BigDecimal.valueOf(5).subtract(chatRobots.get(0).getTotalCost()); if (account.getIsTrial() == 1) { + totalCost = BigDecimal.valueOf(0.1).subtract(chatRobots.get(0).getTotalCost()); return totalCost.divide(BigDecimal.valueOf(0.1), 4, RoundingMode.HALF_UP); }else { return totalCost.divide(BigDecimal.valueOf(5), 4, RoundingMode.HALF_UP); From 8f832ec441d79d6d9f4d0483798cefca7983062f Mon Sep 17 00:00:00 2001 From: xupei Date: Wed, 31 Jan 2024 14:59:19 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E6=9C=BA=E5=99=A8=E4=BA=BA=E8=AF=95?= =?UTF-8?q?=E7=94=A8=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: # 这类错误是由系统内部错误引起的,用户通常无法自行解决,需要联系支持或等待系统管理员介入。