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.CopyUtil;
import com.ai.da.common.utils.MD5Utils; import com.ai.da.common.utils.MD5Utils;
import com.ai.da.common.utils.MinioUtil; import com.ai.da.common.utils.MinioUtil;
import com.ai.da.mapper.AccountMapper;
import com.ai.da.mapper.LibraryMapper; 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.entity.ChatRobot;
import com.ai.da.mapper.ChatRobotMapper; import com.ai.da.mapper.ChatRobotMapper;
import com.ai.da.mapper.entity.Library; import com.ai.da.mapper.entity.Library;
@@ -74,6 +76,8 @@ public class ChatRobotServiceImpl implements ChatRobotService {
@Value("${minio.bucketName.sysImage}") @Value("${minio.bucketName.sysImage}")
private String sysImage; private String sysImage;
@Resource
private AccountMapper accountMapper;
Gson gson = new GsonBuilder().create(); Gson gson = new GsonBuilder().create();
private final ExecutorService executorService = Executors.newSingleThreadExecutor(); private final ExecutorService executorService = Executors.newSingleThreadExecutor();
@@ -257,11 +261,18 @@ public class ChatRobotServiceImpl implements ChatRobotService {
List<ChatRobot> chatRobots = chatRobotMapper.selectList(queryWrapper); List<ChatRobot> chatRobots = chatRobotMapper.selectList(queryWrapper);
if (!CollectionUtils.isEmpty(chatRobots)) { if (!CollectionUtils.isEmpty(chatRobots)) {
BigDecimal totalCostUsed = chatRobots.get(0).getTotalCost(); 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) { if (totalCostUsed.add(totalCost).compareTo(BigDecimal.valueOf(5)) > 0) {
throw new BusinessException("Your balance is insufficient"); throw new BusinessException("Your balance is insufficient");
} }
} }
} }
}
@Override @Override
public String chatBufferFlush(ChatFlushDTO chatFlushDTO) { public String chatBufferFlush(ChatFlushDTO chatFlushDTO) {
@@ -323,9 +334,13 @@ public class ChatRobotServiceImpl implements ChatRobotService {
if (CollectionUtils.isEmpty(chatRobots)) { if (CollectionUtils.isEmpty(chatRobots)) {
return BigDecimal.ONE; return BigDecimal.ONE;
} else { } else {
Account account = accountMapper.selectById(userId);
BigDecimal totalCost = BigDecimal.valueOf(5).subtract(chatRobots.get(0).getTotalCost()); BigDecimal totalCost = BigDecimal.valueOf(5).subtract(chatRobots.get(0).getTotalCost());
BigDecimal result = totalCost.divide(BigDecimal.valueOf(5), 4, RoundingMode.HALF_UP); if (account.getIsTrial() == 1) {
return result; return totalCost.divide(BigDecimal.valueOf(0.1), 4, RoundingMode.HALF_UP);
}else {
return totalCost.divide(BigDecimal.valueOf(5), 4, RoundingMode.HALF_UP);
}
} }
} }