后台服务
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

162 lines
6.5 KiB

  1. package com.iformall.schedule;
  2. import com.iformall.domain.po.sm.PhotoSpeakVideo;
  3. import com.iformall.domain.po.sm.UserMouldVideo;
  4. import com.iformall.domain.po.sm.VideoTrans;
  5. import com.iformall.enums.EnumVideoStatus;
  6. import com.iformall.enums.EnumaVideoTransStatus;
  7. import com.iformall.mapper.VideoTransMapper;
  8. import com.iformall.service.sm.PhotoSpeakVideoService;
  9. import com.iformall.service.sm.UserCreateVideoNumService;
  10. import com.iformall.service.sm.UserMouldVideoService;
  11. import com.iformall.utils.DateUtils;
  12. import com.iformall.video.VideoFactory;
  13. import com.iformall.video.entity.VideTransResult;
  14. import com.iformall.video.entity.VideUploadResult;
  15. import org.apache.commons.lang3.StringUtils;
  16. import org.slf4j.Logger;
  17. import org.slf4j.LoggerFactory;
  18. import org.springframework.beans.factory.annotation.Autowired;
  19. import org.springframework.context.annotation.Configuration;
  20. import org.springframework.scheduling.annotation.EnableScheduling;
  21. import org.springframework.scheduling.annotation.Scheduled;
  22. import java.util.Date;
  23. import java.util.HashMap;
  24. import java.util.List;
  25. import java.util.Map;
  26. import java.util.concurrent.Future;
  27. import java.util.stream.Collectors;
  28. @Configuration
  29. @EnableScheduling
  30. public class PhotoSpeakSchedule {
  31. private final Logger logger = LoggerFactory.getLogger(this.getClass());
  32. @Autowired
  33. private PhotoSpeakVideoService photoSpeakVideoService;
  34. @Autowired
  35. VideoFactory videoFactory;
  36. @Autowired
  37. String videoType;
  38. @Autowired
  39. private UserCreateVideoNumService userCreateVideoNumService;
  40. /**
  41. * 生成视频
  42. */
  43. @Scheduled(cron = "0 20/30 * * * *?") // 每半小时检查一次
  44. public void photoSpeakCreateSchedule() {
  45. PhotoSpeakVideo videoUpd = new PhotoSpeakVideo();
  46. videoUpd.setVideoStartDate(DateUtils.getHourDateBefore(2,new Date()));
  47. videoUpd.setVideoStatus(EnumVideoStatus.fail.getCode());
  48. List<PhotoSpeakVideo> list = photoSpeakVideoService.findList(videoUpd);
  49. if (list != null && list.size() > 0) {
  50. for (PhotoSpeakVideo video : list) {
  51. try {
  52. Future future = photoSpeakVideoService.createVideo(video,false);
  53. future.get();
  54. } catch (Exception e) {
  55. logger.error("TtCouponVideoSchedule error.couponVideoSchedule:"+video.getId(),e);
  56. }
  57. }
  58. }
  59. }
  60. /**
  61. * 上传阿里云
  62. */
  63. @Scheduled(cron = "0 */30 * * * *?") // 每半小时检查一次
  64. public void userVideoUploadSchedule() {
  65. List<PhotoSpeakVideo> videos = photoSpeakVideoService.getNotUploadList();
  66. if (videos != null && videos.size() > 0) {
  67. for (PhotoSpeakVideo video : videos) {
  68. try {
  69. photoSpeakVideoService.uploadVideo(video);
  70. } catch (Exception e) {
  71. logger.error("TtCouponVideoSchedule error.couponVideoSchedule:"+video.getId(),e);
  72. }
  73. }
  74. }
  75. }
  76. /**
  77. * 获取时长和大小
  78. */
  79. @Scheduled(cron = "0 1/5 * * * *?") // 每五分钟检查一次
  80. public void userVideoDetailSchedule() {
  81. List<PhotoSpeakVideo> videos = photoSpeakVideoService.getUpLoadIngList();
  82. if (videos != null && videos.size() > 0) {
  83. for (PhotoSpeakVideo video : videos) {
  84. try {
  85. VideUploadResult videoDetail = videoFactory.getExcutor(videoType).getVideoDetailWithCache(video.getVideoId());
  86. if (videoDetail.isSuccess()
  87. && StringUtils.isNotBlank(videoDetail.getDuration())
  88. && !"0.0".equals(videoDetail.getDuration())) {
  89. video.setCoverImg(videoDetail.getCoverURL());
  90. video.setVideoPlayUrl(videoDetail.getVideoUrl());
  91. video.setVideoTime(videoDetail.getDuration());
  92. video.setVideoSize(videoDetail.getSize());
  93. video.setVideoStatus(EnumVideoStatus.upload_success.getCode());
  94. photoSpeakVideoService.updateById(video);
  95. }
  96. } catch (Exception e) {
  97. logger.error("TtCouponVideoSchedule error.couponVideoSchedule:"+video.getId(),e);
  98. }
  99. }
  100. }
  101. }
  102. /**
  103. * 获取超分时长和大小
  104. */
  105. @Scheduled(cron = "0 1/5 * * * *?") // 每五分钟检查一次
  106. public void userVideoHyDetailSchedule() {
  107. List<PhotoSpeakVideo> videos = photoSpeakVideoService.getUpLoadHyIngList();
  108. if (videos != null && videos.size() > 0) {
  109. for (PhotoSpeakVideo video : videos) {
  110. try {
  111. VideUploadResult videoDetail = videoFactory.getExcutor(videoType).getVideoDetailWithCache(video.getVideoId());
  112. if (videoDetail.isSuccess()
  113. && StringUtils.isNotBlank(videoDetail.getDuration())
  114. && !"0.0".equals(videoDetail.getDuration())) {
  115. video.setCoverImg(videoDetail.getCoverURL());
  116. video.setVideoPlayUrl(videoDetail.getVideoUrl());
  117. video.setVideoTime(videoDetail.getDuration());
  118. video.setVideoSize(videoDetail.getSize());
  119. video.setVideoHyStatus(EnumVideoStatus.upload_success.getCode());
  120. photoSpeakVideoService.updateById(video);
  121. }
  122. } catch (Exception e) {
  123. logger.error("TtCouponVideoSchedule error.couponVideoSchedule:"+video.getId(),e);
  124. }
  125. }
  126. }
  127. }
  128. /**
  129. * 超分生成视频
  130. */
  131. @Scheduled(cron = "0 20/30 * * * *?") // 每半小时检查一次
  132. public void photoSpeakCreateHySchedule() {
  133. PhotoSpeakVideo videoUpd = new PhotoSpeakVideo();
  134. videoUpd.setVideoStartDate(DateUtils.getHourDateBefore(2, new Date()));
  135. videoUpd.setVideoHyStatus(EnumVideoStatus.fail.getCode());
  136. List<PhotoSpeakVideo> list = photoSpeakVideoService.findList(videoUpd);
  137. if (list != null && list.size() > 0) {
  138. for (PhotoSpeakVideo video : list) {
  139. try {
  140. if (StringUtils.isNotEmpty(video.getSaveDir())) {
  141. photoSpeakVideoService.videoHy(video, false);
  142. }
  143. } catch (Exception e) {
  144. logger.error("TtCouponVideoSchedule error.couponVideoSchedule:" + video.getId(), e);
  145. }
  146. }
  147. }
  148. }
  149. }