机器人试用到期提示

This commit is contained in:
2024-01-31 14:59:19 +08:00
parent 5e1573ae09
commit 8f832ec441
5 changed files with 20 additions and 7 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