TASK:模块化;

This commit is contained in:
shahaibo
2025-04-22 13:48:36 +08:00
parent b19bbf91f2
commit aa1c48fcfe
6 changed files with 118 additions and 2 deletions

View File

@@ -124,6 +124,8 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
@Resource
private RedisUtil redisUtil;
@Resource
private PoseTransformationMapper poseTransformationMapper;
@Resource
private DesignBatchMapper designBatchMapper;
@@ -2062,6 +2064,45 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
cloudTask.setStatus(0);
cloudTaskMapper.insert(cloudTask);
return batchTaskId;
} else if (cloudTaskDTO.getBuildType().equals(BuildType.POSE_TRANSFORM.getValue())) {
Long accountId = UserContext.getUserHolder().getId();
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();
String taskId = uuid + "-" + accountId;
PoseTransformation poseTransformation = new PoseTransformation();
poseTransformation.setProjectId(cloudTaskDTO.getProjectId());
poseTransformation.setAccountId(accountId);
poseTransformation.setUniqueId(taskId);
poseTransformation.setProductImage(poseTransformBatchDTO.getProductImage());
poseTransformation.setPoseId(poseTransformBatchDTO.getPoseId());
poseTransformation.setCreateTime(LocalDateTime.now());
poseTransformation.setTaskIdBatch(taskBatchId);
poseTransformationMapper.insert(poseTransformation);
Boolean b = pythonService.poseTransformationBatch(poseTransformBatchDTO.getProductImage(), poseTransformBatchDTO.getPoseId(), taskId);
if (b){
// 6、添加预扣除积分到redis
creditsService.addRecordToCreditsDeduction(accountId, uuid, creditsEventsEnum);
// 6.1 添加积分扣除记录到db
creditsService.preInsert(accountId, creditsEventsEnum.getName(), uuid, Boolean.TRUE, null);
return taskId;
}
throw new BusinessException("pose transformation error", ResultEnum.ERROR.getCode());
}
}
}
return null;
}