Merge branch 'dev/dev_xp' into dev/dev
This commit is contained in:
@@ -206,21 +206,24 @@ public class CreditsServiceImpl extends ServiceImpl<CreditsDetailMapper, Credits
|
||||
|
||||
Long accountId = UserContext.getUserHolder().getId();
|
||||
|
||||
// 1、获取当前在积分预扣除区,未来需要预扣除的积分总和
|
||||
// 1、获取预扣除区的积分总和(转为 BigDecimal),未来需要预扣除的积分总和
|
||||
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 += Integer.parseInt(event.getValue()) * num;
|
||||
BigDecimal sum = multiValue.stream()
|
||||
.map(value -> new BigDecimal(value)) // 将每个 String 转为 BigDecimal
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add); // 累加
|
||||
|
||||
// 2、获取当前积分
|
||||
// 2、加上本次操作的积分(BigDecimal 运算)
|
||||
BigDecimal currentDeduction = new BigDecimal(event.getValue()).multiply(new BigDecimal(num));
|
||||
sum = sum.add(currentDeduction);
|
||||
|
||||
// 3、获取当前积分
|
||||
BigDecimal existingCredits = accountMapper.selectById(accountId).getCredits();
|
||||
BigDecimal subtract = existingCredits.subtract(new BigDecimal(sum));
|
||||
BigDecimal subtract = existingCredits.subtract(sum);
|
||||
|
||||
// 3、判断剩余积分是否够本次操作
|
||||
// 4、判断剩余积分是否够本次操作
|
||||
if (subtract.compareTo(BigDecimal.ZERO) < 0) {
|
||||
// 3.1 不够,直接返回余额不够,充值
|
||||
// 4.1 不够,直接返回余额不够,充值
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
|
||||
|
||||
@@ -530,7 +530,7 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
|
||||
}
|
||||
|
||||
CreditsEventsEnum creditsEventsEnum = CreditsEventsEnum.OTHER;
|
||||
if (generateThroughImageTextDTO.getModelName().equals("wx")){
|
||||
if (!StringUtil.isNullOrEmpty(generateThroughImageTextDTO.getModelName()) && generateThroughImageTextDTO.getModelName().equals("wx")){
|
||||
String taskId = createAsyncTask(generateThroughImageTextDTO);
|
||||
// String taskId = "e53c86ea-53be-424b-8ac7-3c01c141f4f7";
|
||||
creditsEventsEnum = CreditsEventsEnum.WX_TEXT2IMG;
|
||||
@@ -1141,7 +1141,7 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
|
||||
String taskId;
|
||||
Boolean flag = false;
|
||||
PoseTransformation poseTransformation = new PoseTransformation();
|
||||
if (poseTransformDTO.getModelName().equals("wx")){
|
||||
if (!StringUtil.isNullOrEmpty(poseTransformDTO.getModelName()) && poseTransformDTO.getModelName().equals("wx")){
|
||||
taskId = animateAnyone(poseTransformDTO, accountId);
|
||||
if (!StringUtil.isNullOrEmpty(taskId)) flag = true;
|
||||
poseTransformation.setModelName("wx");
|
||||
@@ -1625,20 +1625,16 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
|
||||
private static final String GET_ASYNC_RESULT = "https://dashscope.aliyuncs.com/api/v1/tasks/";
|
||||
private static final String ANIMATE = "https://dashscope.aliyuncs.com/api/v1/services/aigc/image2video/video-synthesis/";
|
||||
public String animateAnyone(PoseTransformDTO poseTransformDTO, Long accountId){
|
||||
|
||||
accountId = 87L;
|
||||
String inputImage = poseTransformDTO.getProductImage();
|
||||
// inputImage = "aida-users/87/product_image/03983c74-741b-4d4d-820a-7c0a98a8f500-0-87.png";
|
||||
String inputImageUrl = minioUtil.getPreSignedUrl(inputImage, CommonConstant.MINIO_IMAGE_EXPIRE_TIME);
|
||||
// 1、输入图片检测
|
||||
checkImage(inputImageUrl);
|
||||
|
||||
// 2、动作模板生成
|
||||
/* 目前只有一个pose,所以不调获取templateId的方法,写死
|
||||
String videoPath = "aida-sys-image/pose/WeChat_20250408175337.mp4";
|
||||
String videoTemplateId = getVideoTemplateId(videoPath);*/
|
||||
String videoTemplateId = "AACT.8090e67b.-E3pujumEfCbDTI_rjSH-A.LwIlGT3j";;
|
||||
|
||||
String videoTemplateId = PoseEnum.getById(poseTransformDTO.getPoseId()).getTemplateId();
|
||||
if (StringUtil.isNullOrEmpty(videoTemplateId)){
|
||||
throw new BusinessException("unknown pose");
|
||||
}
|
||||
// 3、生成动图
|
||||
JSONObject requestBody1 = new JSONObject();
|
||||
requestBody1.set("model", "animate-anyone-gen2");
|
||||
|
||||
Reference in New Issue
Block a user