diff --git a/src/main/java/com/ai/da/service/impl/GenerateServiceImpl.java b/src/main/java/com/ai/da/service/impl/GenerateServiceImpl.java index adccc341..283879fa 100644 --- a/src/main/java/com/ai/da/service/impl/GenerateServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/GenerateServiceImpl.java @@ -4,6 +4,7 @@ import com.ai.da.common.config.exception.BusinessException; import com.ai.da.common.constant.CommonConstant; import com.ai.da.common.context.UserContext; import com.ai.da.common.enums.*; +import com.ai.da.common.response.ResultEnum; import com.ai.da.common.utils.*; import com.ai.da.mapper.primary.*; import com.ai.da.mapper.primary.entity.*; @@ -560,7 +561,7 @@ public class GenerateServiceImpl extends ServiceImpl i // 2、判断用户当前积分是否够本次生成消耗 Boolean preDeduction = creditsService.creditsPreDeduction(creditsEventsEnum, 1); if (!preDeduction) { - throw new BusinessException("Not enough Credits"); + throw new BusinessException("remaining.credits.insufficient"); } // 3、生成唯一id 使用uuid,由于uuid重复的几率很小,故取消对uuid重复性的校验 @@ -779,6 +780,13 @@ public class GenerateServiceImpl extends ServiceImpl i Long accountId = UserContext.getUserHolder().getId(); log.info("imageToSketch parameter : {}", imageToSketchDTO); + // 检查积分是否够本次扣除 + CreditsEventsEnum event = CreditsEventsEnum.IMAGE_TO_SKETCH; + Boolean b = creditsService.checkCredits(accountId, event, 1); + if (!b){ + throw new BusinessException("remaining.credits.insufficient", ResultEnum.PROMPT.getCode()); + } + CollectionElement collectionElement = collectionElementService.getById(imageToSketchDTO.getElementId()); String imagePath = collectionElement.getUrl(); @@ -823,7 +831,6 @@ public class GenerateServiceImpl extends ServiceImpl i String clothCategory = pythonService.getClothCategory(sketchPath, imageToSketchDTO.getGender()); - CreditsEventsEnum event = CreditsEventsEnum.IMAGE_TO_SKETCH; BigDecimal existingCredits = accountService.getById(accountId).getCredits(); BigDecimal subtract = existingCredits.subtract(new BigDecimal(event.getValue())); accountService.updateCreditsAndEndTime(accountId, subtract.toString(), null); diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 605b072c..974fee23 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -5,4 +5,4 @@ #spring.profiles.active=prod #����application-dev�ļ�(��������) -spring.profiles.active=prod +spring.profiles.active=dev diff --git a/src/main/resources/messages_en.properties b/src/main/resources/messages_en.properties index 0b3ad1b3..529b7bcf 100644 --- a/src/main/resources/messages_en.properties +++ b/src/main/resources/messages_en.properties @@ -147,6 +147,7 @@ you.have.not.followed.the.current.user=You have not followed the current user remaining.modifications=Remaining modifications are 0 you.have.participated.in.the.event=You have participated in the event. only.original.works.can.participate.in.the.event=Sorry, only original works can participate in the event. +remaining.credits.insufficient=Your remaining credits are insufficient for this generation. Please recharge. # 可能会报异常 # Informative: diff --git a/src/main/resources/messages_zh.properties b/src/main/resources/messages_zh.properties index 836ad494..c9ed6c67 100644 --- a/src/main/resources/messages_zh.properties +++ b/src/main/resources/messages_zh.properties @@ -142,6 +142,7 @@ you.have.not.followed.the.current.user=您还未关注当前用户 remaining.modifications=剩余修改次数为0 you.have.participated.in.the.event=您已经参与活动。 only.original.works.can.participate.in.the.event=抱歉,只有原创作品能参与活动。 +remaining.credits.insufficient=您的剩余积分不够本次生成消耗,请充值 # 可能会报异常 # Informative: