Sfoglia il codice sorgente

修改提示信息

private_deployment
lrh 1 anno fa
parent
commit
4a5ab9d345
1 ha cambiato i file con 6 aggiunte e 183 eliminazioni
  1. +6
    -183
      suimangService/src/main/java/com/iformall/service/sm/impl/PhotoSpeakVideoServiceImpl.java

+ 6
- 183
suimangService/src/main/java/com/iformall/service/sm/impl/PhotoSpeakVideoServiceImpl.java Vedi File

@@ -22,9 +22,13 @@ import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;

import javax.transaction.xa.XAException;
@@ -33,6 +37,7 @@ import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicInteger;


@Service
@@ -191,190 +196,8 @@ public class PhotoSpeakVideoServiceImpl implements PhotoSpeakVideoService {
photoSpeakVideoMapper.deleteById(id);
}

@Override
public Future createVideo(PhotoSpeakVideo photoSpeakVideo,Boolean flag) {
boolean isCreate = false;
String msg = "";
PhotoSpeakVideo videoUpd = new PhotoSpeakVideo();
videoUpd.setId(photoSpeakVideo.getId());

String personPhotoUrl = null;
if (photoSpeakVideo.getPersonPhotoId() == null) {
msg = "未查询到人物照片";
} else {
personPhotoUrl = photoSpeakVideo.getPersonPhotoUrl();
PersonPhoto personPhotoInfo = personPhotoService.getById(photoSpeakVideo.getPersonPhotoId());
//如果是上传图片就去检验合法
if (EnumMouldSendType.build.getCode().equals(personPhotoInfo.getSendType())) {
//校验图片是否合法
AiCheckPhotoParam param = new AiCheckPhotoParam();
param.setImg(Base64Util.imageUrlToBase64(personPhotoUrl));
AiCheckPhotoResult result = AiVideoHelper.checkPhoto(param);
if (result.getCode() != 2000) {
videoUpd.setVideoStatus(EnumVideoStatus.fail.getCode());
videoUpd.setVideoMsg("图片质量审核:" + result.getMsg());
this.saveOrUpdate(videoUpd);
return new AsyncResult<>(0);
}
}
}

if(StringUtils.isBlank(personPhotoUrl)){
videoUpd.setVideoStatus(EnumVideoStatus.fail.getCode());
videoUpd.setVideoMsg(msg);
this.saveOrUpdate(videoUpd);
return new AsyncResult<>(0);
}

Integer voiceFrom = photoSpeakVideo.getVoiceFrom();
String voiceMouldSmId = null;
String voiceType = "default";//默认
Integer sex = 1;
Double videoTime = null;//用户创建视频的时长

//TODO 关闭用户相关流程
UserCreateVideoNum videoNum = userCreateVideoNumService.queryInfoByUserId(photoSpeakVideo.getUserId());
// if (videoNum == null) {
// videoUpd.setVideoStatus(EnumVideoStatus.fail.getCode());
// videoUpd.setVideoMsg("用户没有创建视频时长");
// this.saveOrUpdate(videoUpd);
// return new AsyncResult<>(0);
// } else {
// if (DateUtils.isDateAfter(String.valueOf(videoNum.getEffectiveDate()))) {
// videoUpd.setVideoStatus(EnumVideoStatus.fail.getCode());
// videoUpd.setVideoMsg("有效期已到期");
// this.saveOrUpdate(videoUpd);
// return new AsyncResult<>(0);
// }
// }

String voiceMaterialUrl = null;
if(EnumVoiceFrom.FROM_MOULD.getCode().equals(voiceFrom)){
try{
JSONObject personMouldObject = JSONObject.parseObject(photoSpeakVideo.getVoiceMouldSm());
voiceMouldSmId = personMouldObject.getString("mouldSmId");
Integer speakType = personMouldObject.getInteger("speakType");
Integer personType = personMouldObject.getInteger("personType");
sex = personMouldObject.getInteger("sex");
if(speakType != null && speakType > 0){
voiceType = EnumSpeakType.getEnum(speakType).getType();
}else if(personType != null && personType > 0){
voiceType = EnumPersonType.getEnum(personType).getType();
}

}catch(Exception e){}
if(StringUtils.isBlank(voiceMouldSmId)){
msg = "参数错误,未找到声音模板数据";
}

//获取视频时长
AiPreviewParam param = new AiPreviewParam();
if (StringUtils.isBlank(photoSpeakVideo.getPaperwork())){
msg = "未填写视频文案数据";
}
param.setGen_txt(photoSpeakVideo.getPaperwork().replaceAll(str, "[*]"));
param.setGender(sex == 1 ? "male" : "female");
param.setVoice_id(voiceMouldSmId);
param.setVoice_style(voiceType);
AiPreviewResult result = AiVideoHelper.voicePreview(param);
if (result.isSuccess()) {
videoTime = result.getTime();
}
}else if(EnumVoiceFrom.FROM_UPD.getCode().equals(voiceFrom)){
voiceMaterialUrl = photoSpeakVideo.getVoiceMaterialUrl();
VoiceMaterial voiceMaterial = voiceMaterialService.getById(photoSpeakVideo.getVoiceMaterialId());
if(StringUtils.isBlank(voiceMaterialUrl)){
voiceMaterialService.handVideoUrl(voiceMaterial);
voiceMaterialUrl = voiceMaterial.getMaterial();
videoUpd.setVoiceMaterialUrl(voiceMaterialUrl);
}
if(StringUtils.isBlank(voiceMaterialUrl)){
msg = "未找到上传声音文件";
}

//判断用户时长是否够创建该视频
VideUploadResult videoDetail = videoFactory.getExcutor(videoType).getVideoDetailWithCache(voiceMaterial.getVideoId());
if (videoDetail.isSuccess() && StringUtils.isNotBlank(videoDetail.getDuration()) && !"0.0".equals(videoDetail.getDuration())) {
String duration = videoDetail.getDuration();
videoTime = Double.valueOf(duration);
}
} else if (EnumVoiceFrom.MUSIC.getCode().equals(voiceFrom)) {
Long musicId = photoSpeakVideo.getMusicId();
MusicInfo musicInfo = musicInfoService.getById(musicId);
if (ObjectUtils.isEmpty(musicInfo)) {
msg = "未找到音乐文件";
}
voiceMaterialUrl = musicInfo.getUrl();
if (StringUtils.isBlank(voiceMaterialUrl)) {
msg = "音乐文件错误";
}
videoTime = Double.valueOf(musicInfo.getTime());
} else {
msg = "声音数据异常";
}

//判断获取创建的视频时长
if (videoTime == null){
videoUpd.setVideoStatus(EnumVideoStatus.fail.getCode());
videoUpd.setVideoMsg("获取创建的视频时长失败");
this.saveOrUpdate(videoUpd);
return new AsyncResult<>(0);
}

//TODO 关闭用户相关流程
//获取套餐信息
// UserConsumptionPackage infoById = userConsumptionPackageService.getPackageInfoById(videoNum.getPackageId());
// if (infoById == null){
// videoUpd.setVideoStatus(EnumVideoStatus.fail.getCode());
// videoUpd.setVideoMsg("套餐信息不存在");
// this.saveOrUpdate(videoUpd);
// return new AsyncResult<>(0);
// }
// //生成视频时长不能超过对应套餐的时长
// if (infoById.getChargeTime() < videoTime) {
// videoUpd.setVideoStatus(EnumVideoStatus.fail.getCode());
// videoUpd.setVideoMsg("视频时长不能超过" + infoById.getChargeTime() + "s");
// this.saveOrUpdate(videoUpd);
// return new AsyncResult<>(0);
// }
videoUpd.setVideoTime(String.valueOf(videoTime));

if(StringUtils.isBlank(voiceMouldSmId) && StringUtils.isBlank(voiceMaterialUrl)){
videoUpd.setVideoStatus(EnumVideoStatus.fail.getCode());
videoUpd.setVideoMsg(msg);
this.saveOrUpdate(videoUpd);
return new AsyncResult<>(0);
}

String paperwork = photoSpeakVideo.getPaperwork();
if(EnumVoiceFrom.FROM_MOULD.getCode().equals(voiceFrom) && StringUtils.isBlank(paperwork)){
videoUpd.setVideoStatus(EnumVideoStatus.fail.getCode());
videoUpd.setVideoMsg("未填写视频文案数据");
this.saveOrUpdate(videoUpd);
return new AsyncResult<>(0);
}

double useCredit = 0;
//修改用户创建视频时间表
if (flag) {
// //每秒消耗的积分
// double i = (double)( videoNum.getVideoPrice() / 60);
// i = i < 1 ? 1.0 : i; //如果小于1 就直接取1
// //用户创建视频需要时积分
// useCredit = (videoTime * i);
// //判断用户积分是否足够
// if (videoNum.getResidueCredits() < useCredit) {
// videoUpd.setVideoStatus(EnumVideoStatus.fail.getCode());
// videoUpd.setVideoMsg("创建视频时长不足,请充值");
// this.saveOrUpdate(videoUpd);
// return new AsyncResult<>(0);
// }
// useCredit = Math.round(useCredit);
//如果时间够,就去减去相对应的数据
userCreateVideoNumService.addOrSubtractNumberOfTimes(1, videoNum, useCredit, videoTime);
}

@Async
@Override
public ResultData createVideo(PhotoSpeakVideo photoSpeakVideo) {
try {
AiPhotoSpeakParam param = new AiPhotoSpeakParam();


Caricamento…
Annulla
Salva