|
- package com.iformall.schedule;
-
- import com.iformall.domain.po.sm.UserMouldVideo;
- import com.iformall.domain.po.tt.TtCoupon;
- import com.iformall.enums.EnumVideoStatus;
- import com.iformall.mapper.TtCouponMapper;
- import com.iformall.service.sm.UserMouldVideoService;
- import com.iformall.utils.DateUtils;
- import com.iformall.video.VideoFactory;
- import com.iformall.video.aliyun.sdk.server.UploadCacheHelper;
- import com.iformall.video.entity.VideUploadResult;
- import org.apache.commons.lang3.StringUtils;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.context.annotation.Configuration;
- import org.springframework.scheduling.annotation.EnableScheduling;
- import org.springframework.scheduling.annotation.Scheduled;
-
- import java.util.Date;
- import java.util.List;
- import java.util.concurrent.Future;
-
- @Configuration
- @EnableScheduling
- public class VideoSchedule {
-
- private final Logger logger = LoggerFactory.getLogger(this.getClass());
-
- @Autowired
- private UserMouldVideoService userMouldVideoService;
-
- @Autowired
- VideoFactory videoFactory;
-
- @Autowired
- String videoType;
-
- /**
- * 生成视频
- */
- @Scheduled(cron = "0 20/30 * * * *?") // 每小时检查一次
- public void userVideoCreateSchedule() {
- UserMouldVideo userVideo = new UserMouldVideo();
- userVideo.setVideoStartDate(DateUtils.getHourDateBefore(2,new Date()));
- userVideo.setVideoStatus(EnumVideoStatus.fail.getCode());
- List<UserMouldVideo> list = userMouldVideoService.findList(userVideo);
- if (list != null && list.size() > 0) {
- for (UserMouldVideo video : list) {
- try {
- Future future = userMouldVideoService.createVideo(video);
- future.get();
- } catch (Exception e) {
- logger.error("TtCouponVideoSchedule error.couponVideoSchedule:"+video.getId(),e);
- }
- }
- }
- }
-
- /**
- * 上传阿里云
- */
- @Scheduled(cron = "0 */30 * * * *?") // 每小时检查一次
- public void userVideoUploadSchedule() {
- List<UserMouldVideo> videos = userMouldVideoService.getVideoIdNullList();
- if (videos != null && videos.size() > 0) {
- for (UserMouldVideo video : videos) {
- try {
- userMouldVideoService.uploadVideo(video);
- } catch (Exception e) {
- logger.error("TtCouponVideoSchedule error.couponVideoSchedule:"+video.getId(),e);
- }
- }
- }
- }
-
- /**
- * 获取时长和大小
- */
- @Scheduled(cron = "0 15/30 * * * *?") // 每小时检查一次
- public void userVideoDetailSchedule() {
- List<UserMouldVideo> videos = userMouldVideoService.getVideoSizeNullList();
- if (videos != null && videos.size() > 0) {
- for (UserMouldVideo video : videos) {
- try {
- VideUploadResult videoDetail = videoFactory.getExcutor(videoType).getVideoDetailWithCache(video.getVideoId());
- if (videoDetail.isSuccess()
- && StringUtils.isNotBlank(videoDetail.getDuration())
- && !"0.0".equals(videoDetail.getDuration())) {
- video.setVideoTime(videoDetail.getDuration());
- video.setVideoSize(videoDetail.getSize());
- userMouldVideoService.updateById(video);
- }
- } catch (Exception e) {
- logger.error("TtCouponVideoSchedule error.couponVideoSchedule:"+video.getId(),e);
- }
- }
- }
- }
-
- }
|