| @@ -176,7 +176,7 @@ public class PhotoSpeakVideoController extends BaseController { | |||||
| mouldVideoUpd.setCreateVideoDate(new Date()); | mouldVideoUpd.setCreateVideoDate(new Date()); | ||||
| photoSpeakVideoService.saveOrUpdate(mouldVideoUpd); | photoSpeakVideoService.saveOrUpdate(mouldVideoUpd); | ||||
| photoSpeakVideoService.createVideo(mouldVideo); | |||||
| photoSpeakVideoService.createVideo(mouldVideo,true); | |||||
| return new ResultData(); | return new ResultData(); | ||||
| } | } | ||||
| @@ -57,7 +57,7 @@ public class PhotoSpeakSchedule { | |||||
| if (list != null && list.size() > 0) { | if (list != null && list.size() > 0) { | ||||
| for (PhotoSpeakVideo video : list) { | for (PhotoSpeakVideo video : list) { | ||||
| try { | try { | ||||
| Future future = photoSpeakVideoService.createVideo(video); | |||||
| Future future = photoSpeakVideoService.createVideo(video,false); | |||||
| future.get(); | future.get(); | ||||
| } catch (Exception e) { | } catch (Exception e) { | ||||
| logger.error("TtCouponVideoSchedule error.couponVideoSchedule:"+video.getId(),e); | logger.error("TtCouponVideoSchedule error.couponVideoSchedule:"+video.getId(),e); | ||||
| @@ -45,7 +45,7 @@ public interface PhotoSpeakVideoService { | |||||
| */ | */ | ||||
| void deleteById(Long id); | void deleteById(Long id); | ||||
| Future createVideo(PhotoSpeakVideo mouldVideo); | |||||
| Future createVideo(PhotoSpeakVideo mouldVideo,Boolean flag); | |||||
| void uploadVideo(PhotoSpeakVideo mouldVideo); | void uploadVideo(PhotoSpeakVideo mouldVideo); | ||||
| @@ -11,7 +11,7 @@ public interface UserCreateVideoNumService { | |||||
| Boolean initializationUserCreateVideoNum(Long id); | Boolean initializationUserCreateVideoNum(Long id); | ||||
| void addOrSubtractNumberOfTimes(Integer type, UserCreateVideoNum createVideoNum); | |||||
| Boolean addOrSubtractNumberOfTimes(Integer type, UserCreateVideoNum createVideoNum); | |||||
| UserCreateVideoNum queryInfoByUserId(Long userId); | UserCreateVideoNum queryInfoByUserId(Long userId); | ||||
| @@ -156,7 +156,7 @@ public class PhotoSpeakVideoServiceImpl implements PhotoSpeakVideoService { | |||||
| @Async | @Async | ||||
| @Override | @Override | ||||
| public Future createVideo(PhotoSpeakVideo photoSpeakVideo) { | |||||
| public Future createVideo(PhotoSpeakVideo photoSpeakVideo,Boolean flag) { | |||||
| boolean isCreate = false; | boolean isCreate = false; | ||||
| String msg = ""; | String msg = ""; | ||||
| PhotoSpeakVideo videoUpd = new PhotoSpeakVideo(); | PhotoSpeakVideo videoUpd = new PhotoSpeakVideo(); | ||||
| @@ -238,18 +238,24 @@ public class PhotoSpeakVideoServiceImpl implements PhotoSpeakVideoService { | |||||
| return new AsyncResult<>(0); | return new AsyncResult<>(0); | ||||
| } | } | ||||
| //修改用户生成视频次数 | |||||
| UserCreateVideoNum createVideoNum = userCreateVideoNumService.queryInfoByUserId(photoSpeakVideo.getUserId()); | |||||
| if (ObjectUtils.isEmpty(createVideoNum)) { | |||||
| return new AsyncResult<>("用户没有生成视频次数"); | |||||
| }else { | |||||
| //剩余条数 | |||||
| Integer residueNum = createVideoNum.getResidueNum(); | |||||
| if (residueNum.intValue() <= 0){ | |||||
| return new AsyncResult<>("剩余生成视频次数不足"); | |||||
| }else { | |||||
| //减去生成视频次数 | |||||
| userCreateVideoNumService.addOrSubtractNumberOfTimes(1, createVideoNum); | |||||
| UserCreateVideoNum createVideoNum = new UserCreateVideoNum(); | |||||
| if (flag) { | |||||
| //修改用户生成视频次数 | |||||
| createVideoNum = userCreateVideoNumService.queryInfoByUserId(photoSpeakVideo.getUserId()); | |||||
| if (ObjectUtils.isEmpty(createVideoNum)) { | |||||
| return new AsyncResult<>("用户没有生成视频次数"); | |||||
| } else { | |||||
| //剩余条数 | |||||
| Integer residueNum = createVideoNum.getResidueNum(); | |||||
| if (residueNum.intValue() <= 0) { | |||||
| return new AsyncResult<>("剩余生成视频次数不足"); | |||||
| } else { | |||||
| //减去生成视频次数 | |||||
| Boolean times = userCreateVideoNumService.addOrSubtractNumberOfTimes(1, createVideoNum); | |||||
| if (!times) { | |||||
| return new AsyncResult<>("剩余生成视频次数不足"); | |||||
| } | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| @@ -296,14 +302,18 @@ public class PhotoSpeakVideoServiceImpl implements PhotoSpeakVideoService { | |||||
| videoUpd.setVideoMsg(video.getMsg()); | videoUpd.setVideoMsg(video.getMsg()); | ||||
| this.saveOrUpdate(videoUpd); | this.saveOrUpdate(videoUpd); | ||||
| //如果生成视频失败了,就把创建视频的次数加回去 | |||||
| userCreateVideoNumService.addOrSubtractNumberOfTimes(2, createVideoNum); | |||||
| if (flag) { | |||||
| //如果生成视频失败了,就把创建视频的次数加回去 | |||||
| userCreateVideoNumService.addOrSubtractNumberOfTimes(2, createVideoNum); | |||||
| } | |||||
| return new AsyncResult<>(0); | return new AsyncResult<>(0); | ||||
| } catch (Exception e) { | } catch (Exception e) { | ||||
| e.printStackTrace(); | e.printStackTrace(); | ||||
| //如果生成视频失败了,就把创建视频的次数加回去 | |||||
| userCreateVideoNumService.addOrSubtractNumberOfTimes(2, createVideoNum); | |||||
| if (flag) { | |||||
| //如果生成视频失败了,就把创建视频的次数加回去 | |||||
| userCreateVideoNumService.addOrSubtractNumberOfTimes(2, createVideoNum); | |||||
| } | |||||
| videoUpd.setVideoStatus(EnumVideoStatus.fail.getCode()); | videoUpd.setVideoStatus(EnumVideoStatus.fail.getCode()); | ||||
| videoUpd.setVideoMsg("请求异常"); | videoUpd.setVideoMsg("请求异常"); | ||||
| this.saveOrUpdate(videoUpd); | this.saveOrUpdate(videoUpd); | ||||
| @@ -49,7 +49,7 @@ public class UserCreateVideoNumServiceImpl implements UserCreateVideoNumService | |||||
| } | } | ||||
| @Override | @Override | ||||
| public void addOrSubtractNumberOfTimes(Integer type, UserCreateVideoNum createVideoNum) { | |||||
| public Boolean addOrSubtractNumberOfTimes(Integer type, UserCreateVideoNum createVideoNum) { | |||||
| UserCreateVideoNum videoNum = new UserCreateVideoNum(); | UserCreateVideoNum videoNum = new UserCreateVideoNum(); | ||||
| videoNum.setUpdateDate(new Date()); | videoNum.setUpdateDate(new Date()); | ||||
| videoNum.setId(createVideoNum.getId()); | videoNum.setId(createVideoNum.getId()); | ||||
| @@ -60,7 +60,11 @@ public class UserCreateVideoNumServiceImpl implements UserCreateVideoNumService | |||||
| videoNum.setResidueNum(createVideoNum.getResidueNum() + 1); | videoNum.setResidueNum(createVideoNum.getResidueNum() + 1); | ||||
| videoNum.setCreateNum(createVideoNum.getCreateNum() - 1); | videoNum.setCreateNum(createVideoNum.getCreateNum() - 1); | ||||
| } | } | ||||
| userCreateVideoNumMapper.updateById(videoNum); | |||||
| if (videoNum.getResidueNum() >= 0) { | |||||
| return userCreateVideoNumMapper.updateById(videoNum) > 0; | |||||
| } else { | |||||
| return false; | |||||
| } | |||||
| } | } | ||||
| @Override | @Override | ||||