TASK:试用用户机器人余额;

This commit is contained in:
shahaibo
2024-01-30 14:20:01 +08:00
parent 5975519c39
commit 878b5a129c

View File

@@ -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,11 +261,18 @@ public class ChatRobotServiceImpl implements ChatRobotService {
List<ChatRobot> chatRobots = chatRobotMapper.selectList(queryWrapper);
if (!CollectionUtils.isEmpty(chatRobots)) {
BigDecimal totalCostUsed = chatRobots.get(0).getTotalCost();
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");
}
}
}
}
@Override
public String chatBufferFlush(ChatFlushDTO chatFlushDTO) {
@@ -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);
}
}
}