TASK:模块化;
This commit is contained in:
@@ -35,7 +35,7 @@ public class CloudTask implements Serializable {
|
||||
|
||||
private Integer completedNum;
|
||||
|
||||
private Decimal costCredits;
|
||||
private Integer costCredits;
|
||||
|
||||
private Integer status;
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@@ -19,4 +20,7 @@ public class ThreeDModule implements Serializable {
|
||||
private Long id;
|
||||
private Long projectId;
|
||||
private Long threeDSimpleId;
|
||||
private Long collectionElementId;
|
||||
private BigDecimal x;
|
||||
private BigDecimal y;
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ public class ModuleSaveDTO {
|
||||
@ApiModelProperty("手稿板图片id 数组")
|
||||
private List<CollectionSketchDTO> sketchBoard;
|
||||
|
||||
private Long patternMaking3D;
|
||||
private PatternMaking3DDTO patternMaking3D;
|
||||
|
||||
// private MoodBoardModuleChooseVO moodBoard;
|
||||
// private List<CollectionElementVO> printBoard;
|
||||
|
||||
13
src/main/java/com/ai/da/model/dto/PatternMaking3DDTO.java
Normal file
13
src/main/java/com/ai/da/model/dto/PatternMaking3DDTO.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package com.ai.da.model.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Data
|
||||
public class PatternMaking3DDTO {
|
||||
private Long threeDSimpleId;
|
||||
private Long collectionElementId;
|
||||
private BigDecimal x;
|
||||
private BigDecimal y;
|
||||
}
|
||||
@@ -3,7 +3,9 @@ package com.ai.da.model.vo;
|
||||
import com.ai.da.mapper.primary.entity.ThreeDLayout;
|
||||
import com.ai.da.mapper.primary.entity.ThreeDPatternLayout;
|
||||
import lombok.Data;
|
||||
import org.apache.poi.hpsf.Decimal;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@@ -14,4 +16,8 @@ public class ThreeDVO {
|
||||
// private ThreeDPatternLayout threeDPatternLayoutUrl;
|
||||
private String threeDPatternLayoutUrl;
|
||||
private String threeDSimpleUrl;
|
||||
|
||||
private BigDecimal x;
|
||||
private BigDecimal y;
|
||||
private String printUrl;
|
||||
}
|
||||
|
||||
@@ -27,6 +27,8 @@ public interface CreditsService extends IService<CreditsDetail> {
|
||||
|
||||
Boolean creditsPreDeduction(CreditsEventsEnum event, Integer num);
|
||||
|
||||
Boolean creditsPreDeduction(Integer credits);
|
||||
|
||||
void addRecordToCreditsDeduction(Long accountId, String taskId, CreditsEventsEnum creditsEventsEnum);
|
||||
|
||||
Boolean taskCreditsDeduction(Long accountId, String taskId);
|
||||
|
||||
@@ -227,6 +227,32 @@ public class CreditsServiceImpl extends ServiceImpl<CreditsDetailMapper, Credits
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean creditsPreDeduction(Integer credits) {
|
||||
|
||||
Long accountId = UserContext.getUserHolder().getId();
|
||||
|
||||
// 1、获取当前在积分预扣除区,未来需要预扣除的积分总和
|
||||
Set<String> keys = redisUtil.getKeysFromString(creditsDeduction + ":" + accountId + ":*");
|
||||
List<String> multiValue = redisUtil.getMultiValue(keys);
|
||||
// 1.1 预扣除区 积分总和
|
||||
int sum = multiValue.stream().mapToInt(Integer::parseInt).sum();
|
||||
// 1.2 加上本次操作需要扣除的积分
|
||||
sum += credits;
|
||||
|
||||
// 2、获取当前积分
|
||||
BigDecimal existingCredits = accountMapper.selectById(accountId).getCredits();
|
||||
BigDecimal subtract = existingCredits.subtract(new BigDecimal(sum));
|
||||
|
||||
// 3、判断剩余积分是否够本次操作
|
||||
if (subtract.compareTo(BigDecimal.ZERO) < 0) {
|
||||
// 3.1 不够,直接返回余额不够,充值
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRecordToCreditsDeduction(Long accountId, String taskId, CreditsEventsEnum creditsEventsEnum) {
|
||||
// 5、添加当前任务的预扣积分到redis 任务有效期一天,若待扣积分两天还没被移除,说明任务已经失败,待扣积分自动失效
|
||||
|
||||
@@ -1825,10 +1825,10 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
|
||||
}else if (cloudTaskDTO.getBuildType().equals(BuildType.TO_PRODUCT_IMAGE.getValue())) {
|
||||
ToProductImageDTO toProductImageDTO = cloudTaskDTO.getToProductImage();
|
||||
// 判断用户当前积分是否够本次生成消耗
|
||||
// Boolean preDeduction = creditsService.creditsPreDeduction(CreditsEventsEnum.TO_PRODUCT_IMAGE, toProductImageDTO.getToProductImageVOList().size());
|
||||
// if (!preDeduction) {
|
||||
// throw new BusinessException("Your remaining credits are insufficient for this generation. Please recharge.", ResultEnum.WARNING.getCode());
|
||||
// }
|
||||
Boolean preDeduction = creditsService.creditsPreDeduction(cloudTaskDTO.getCostCredits());
|
||||
if (!preDeduction) {
|
||||
throw new BusinessException("Your remaining credits are insufficient for this generation. Please recharge.", ResultEnum.WARNING.getCode());
|
||||
}
|
||||
AuthPrincipalVo userHolder = UserContext.getUserHolder();
|
||||
|
||||
String batchTaskId = UUID.randomUUID() + "-" + userHolder.getId();
|
||||
@@ -1955,10 +1955,10 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
|
||||
}else if (cloudTaskDTO.getBuildType().equals(BuildType.RELIGHT.getValue())) {
|
||||
ToProductImageDTO toProductImageDTO = cloudTaskDTO.getToProductImage();
|
||||
// 判断用户当前积分是否够本次生成消耗
|
||||
// Boolean preDeduction = creditsService.creditsPreDeduction(CreditsEventsEnum.RELIGHT, toProductImageDTO.getToProductImageVOList().size());
|
||||
// if (!preDeduction) {
|
||||
// throw new BusinessException("Your remaining credits are insufficient for this generation. Please recharge.", ResultEnum.WARNING.getCode());
|
||||
// }
|
||||
Boolean preDeduction = creditsService.creditsPreDeduction(cloudTaskDTO.getCostCredits());
|
||||
if (!preDeduction) {
|
||||
throw new BusinessException("Your remaining credits are insufficient for this generation. Please recharge.", ResultEnum.WARNING.getCode());
|
||||
}
|
||||
|
||||
AuthPrincipalVo userHolder = UserContext.getUserHolder();
|
||||
String batchTaskId = UUID.randomUUID() + "-" + userHolder.getId();
|
||||
@@ -2066,17 +2066,16 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
|
||||
return batchTaskId;
|
||||
} else if (cloudTaskDTO.getBuildType().equals(BuildType.POSE_TRANSFORM.getValue())) {
|
||||
Long accountId = UserContext.getUserHolder().getId();
|
||||
|
||||
Boolean preDeduction = creditsService.creditsPreDeduction(cloudTaskDTO.getCostCredits());
|
||||
if (!preDeduction) {
|
||||
throw new BusinessException("Your remaining credits are insufficient for this generation. Please recharge.", ResultEnum.WARNING.getCode());
|
||||
}
|
||||
List<PoseTransformBatchDTO> poseTransformList = cloudTaskDTO.getPoseTransform();
|
||||
if (CollectionUtil.isNotEmpty(poseTransformList)) {
|
||||
String taskBatchId = UUID.randomUUID().toString() + "-" + accountId;
|
||||
for (PoseTransformBatchDTO poseTransformBatchDTO : poseTransformList) {
|
||||
// 1、判断用户当前积分是否够本次生成消耗
|
||||
CreditsEventsEnum creditsEventsEnum = CreditsEventsEnum.POSE_TRANSFORMATION;
|
||||
Boolean preDeduction = creditsService.creditsPreDeduction(creditsEventsEnum, 1);
|
||||
if (!preDeduction) {
|
||||
throw new BusinessException("remaining.credits.insufficient", ResultEnum.WARNING.getCode());
|
||||
}
|
||||
|
||||
// 3、生成唯一id 使用uuid,由于uuid重复的几率很小,故取消对uuid重复性的校验
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
|
||||
@@ -1643,6 +1643,10 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
|
||||
if (CollectionUtil.isNotEmpty(threeDModules)) {
|
||||
ThreeDModule threeDModule = threeDModules.get(0);
|
||||
ThreeDVO patternMaking3D = getLayoutDetail(threeDModule.getThreeDSimpleId());
|
||||
CollectionElement collectionElement = collectionElementMapper.selectById(threeDModule.getCollectionElementId());
|
||||
patternMaking3D.setPrintUrl(minioUtil.getPreSignedUrl(collectionElement.getUrl(), CommonConstant.MINIO_IMAGE_EXPIRE_TIME));
|
||||
patternMaking3D.setX(threeDModule.getX());
|
||||
patternMaking3D.setY(threeDModule.getY());
|
||||
moduleChooseVO.setPatternMaking3D(patternMaking3D);
|
||||
}
|
||||
}
|
||||
@@ -1892,7 +1896,8 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
|
||||
collectionElementMapper.deleteBatchIds(old);
|
||||
}
|
||||
}
|
||||
if (moduleSaveDTO.getPatternMaking3D() != null) {
|
||||
if (Objects.nonNull(moduleSaveDTO.getPatternMaking3D())) {
|
||||
PatternMaking3DDTO patternMaking3D = moduleSaveDTO.getPatternMaking3D();
|
||||
|
||||
QueryWrapper<ThreeDModule> threeDModuleQueryWrapper = new QueryWrapper<>();
|
||||
threeDModuleQueryWrapper.lambda().eq(ThreeDModule::getProjectId, projectId);
|
||||
@@ -1901,12 +1906,18 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
|
||||
if (CollectionUtils.isEmpty(threeDModuleList)) {
|
||||
ThreeDModule threeDModule = new ThreeDModule();
|
||||
threeDModule.setProjectId(projectId);
|
||||
threeDModule.setThreeDSimpleId(moduleSaveDTO.getPatternMaking3D());
|
||||
threeDModule.setThreeDSimpleId(patternMaking3D.getThreeDSimpleId());
|
||||
threeDModule.setX(patternMaking3D.getX());
|
||||
threeDModule.setY(patternMaking3D.getY());
|
||||
threeDModule.setCollectionElementId(patternMaking3D.getCollectionElementId());
|
||||
threeDModuleMapper.insert(threeDModule);
|
||||
}else {
|
||||
ThreeDModule threeDModule = threeDModuleList.get(0);
|
||||
if (!Objects.equals(moduleSaveDTO.getPatternMaking3D(), threeDModule.getThreeDSimpleId())) {
|
||||
threeDModule.setThreeDSimpleId(moduleSaveDTO.getPatternMaking3D());
|
||||
threeDModule.setThreeDSimpleId(patternMaking3D.getThreeDSimpleId());
|
||||
threeDModule.setX(patternMaking3D.getX());
|
||||
threeDModule.setY(patternMaking3D.getY());
|
||||
threeDModule.setCollectionElementId(patternMaking3D.getCollectionElementId());
|
||||
threeDModuleMapper.updateById(threeDModule);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user