From 878b5a129ce6bf6cd36f1ada196ed8aac54eb75e Mon Sep 17 00:00:00 2001 From: shahaibo <1023316923@qq.com> Date: Tue, 30 Jan 2024 14:20:01 +0800 Subject: [PATCH] =?UTF-8?q?TASK:=E8=AF=95=E7=94=A8=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E6=9C=BA=E5=99=A8=E4=BA=BA=E4=BD=99=E9=A2=9D;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../da/service/impl/ChatRobotServiceImpl.java | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/ai/da/service/impl/ChatRobotServiceImpl.java b/src/main/java/com/ai/da/service/impl/ChatRobotServiceImpl.java index 5f06a194..1300292f 100644 --- a/src/main/java/com/ai/da/service/impl/ChatRobotServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/ChatRobotServiceImpl.java @@ -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,8 +261,15 @@ public class ChatRobotServiceImpl implements ChatRobotService { List chatRobots = chatRobotMapper.selectList(queryWrapper); if (!CollectionUtils.isEmpty(chatRobots)) { BigDecimal totalCostUsed = chatRobots.get(0).getTotalCost(); - if (totalCostUsed.add(totalCost).compareTo(BigDecimal.valueOf(5)) > 0) { - throw new BusinessException("Your balance is insufficient"); + 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"); + } } } } @@ -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); + } } }