Merge remote-tracking branch 'origin/test/stable' into release/3.0

# Conflicts:
#	src/main/java/com/ai/da/service/impl/ChatRobotServiceImpl.java
#	src/main/resources/application.properties
This commit is contained in:
2024-01-31 15:13:02 +08:00
4 changed files with 18 additions and 5 deletions

View File

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

View File

@@ -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<ChatRobot> 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

View File

@@ -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:
# 这类错误是由系统内部错误引起的,用户通常无法自行解决,需要联系支持或等待系统管理员介入。

View File

@@ -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:
# 这类错误是由系统内部错误引起的,用户通常无法自行解决,需要联系支持或等待系统管理员介入。