BUGFIX:imageToSketch 积分扣除校验

This commit is contained in:
2024-10-29 09:57:34 +08:00
parent 0ea96c728c
commit 78bfc16287
3 changed files with 11 additions and 2 deletions

View File

@@ -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<GenerateMapper, Generate> 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<GenerateMapper, Generate> 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<GenerateMapper, Generate> 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);