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:
@@ -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"
|
||||
);
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user