后台服务
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.

101 line
3.7 KiB

  1. package com.iformall.schedule;
  2. import com.iformall.domain.po.sm.UserMouldVideo;
  3. import com.iformall.domain.po.tt.TtCoupon;
  4. import com.iformall.enums.EnumVideoStatus;
  5. import com.iformall.mapper.TtCouponMapper;
  6. import com.iformall.service.sm.UserMouldVideoService;
  7. import com.iformall.utils.DateUtils;
  8. import com.iformall.video.VideoFactory;
  9. import com.iformall.video.aliyun.sdk.server.UploadCacheHelper;
  10. import com.iformall.video.entity.VideUploadResult;
  11. import org.apache.commons.lang3.StringUtils;
  12. import org.slf4j.Logger;
  13. import org.slf4j.LoggerFactory;
  14. import org.springframework.beans.factory.annotation.Autowired;
  15. import org.springframework.context.annotation.Configuration;
  16. import org.springframework.scheduling.annotation.EnableScheduling;
  17. import org.springframework.scheduling.annotation.Scheduled;
  18. import java.util.Date;
  19. import java.util.List;
  20. import java.util.concurrent.Future;
  21. @Configuration
  22. @EnableScheduling
  23. public class VideoSchedule {
  24. private final Logger logger = LoggerFactory.getLogger(this.getClass());
  25. @Autowired
  26. private UserMouldVideoService userMouldVideoService;
  27. @Autowired
  28. VideoFactory videoFactory;
  29. @Autowired
  30. String videoType;
  31. /**
  32. * 生成视频
  33. */
  34. @Scheduled(cron = "0 20/30 * * * *?") // 每小时检查一次
  35. public void userVideoCreateSchedule() {
  36. UserMouldVideo userVideo = new UserMouldVideo();
  37. userVideo.setVideoStartDate(DateUtils.getHourDateBefore(2,new Date()));
  38. userVideo.setVideoStatus(EnumVideoStatus.fail.getCode());
  39. List<UserMouldVideo> list = userMouldVideoService.findList(userVideo);
  40. if (list != null && list.size() > 0) {
  41. for (UserMouldVideo video : list) {
  42. try {
  43. Future future = userMouldVideoService.createVideo(video);
  44. future.get();
  45. } catch (Exception e) {
  46. logger.error("TtCouponVideoSchedule error.couponVideoSchedule:"+video.getId(),e);
  47. }
  48. }
  49. }
  50. }
  51. /**
  52. * 上传阿里云
  53. */
  54. @Scheduled(cron = "0 */30 * * * *?") // 每小时检查一次
  55. public void userVideoUploadSchedule() {
  56. List<UserMouldVideo> videos = userMouldVideoService.getVideoIdNullList();
  57. if (videos != null && videos.size() > 0) {
  58. for (UserMouldVideo video : videos) {
  59. try {
  60. userMouldVideoService.uploadVideo(video);
  61. } catch (Exception e) {
  62. logger.error("TtCouponVideoSchedule error.couponVideoSchedule:"+video.getId(),e);
  63. }
  64. }
  65. }
  66. }
  67. /**
  68. * 获取时长和大小
  69. */
  70. @Scheduled(cron = "0 15/30 * * * *?") // 每小时检查一次
  71. public void userVideoDetailSchedule() {
  72. List<UserMouldVideo> videos = userMouldVideoService.getVideoSizeNullList();
  73. if (videos != null && videos.size() > 0) {
  74. for (UserMouldVideo video : videos) {
  75. try {
  76. VideUploadResult videoDetail = videoFactory.getExcutor(videoType).getVideoDetailWithCache(video.getVideoId());
  77. if (videoDetail.isSuccess()
  78. && StringUtils.isNotBlank(videoDetail.getDuration())
  79. && !"0.0".equals(videoDetail.getDuration())) {
  80. video.setVideoTime(videoDetail.getDuration());
  81. video.setVideoSize(videoDetail.getSize());
  82. userMouldVideoService.updateById(video);
  83. }
  84. } catch (Exception e) {
  85. logger.error("TtCouponVideoSchedule error.couponVideoSchedule:"+video.getId(),e);
  86. }
  87. }
  88. }
  89. }
  90. }