From 88b031e8c14a201852c908a6ae10261630471d04 Mon Sep 17 00:00:00 2001 From: lrh <1585126058@qq.com> Date: Mon, 5 Jun 2023 15:47:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=94=9F=E6=88=90=E8=A7=86?= =?UTF-8?q?=E9=A2=91=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../iformall/schedule/PhotoSpeakSchedule.java | 106 ++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 suimangSchedule/src/main/java/com/iformall/schedule/PhotoSpeakSchedule.java diff --git a/suimangSchedule/src/main/java/com/iformall/schedule/PhotoSpeakSchedule.java b/suimangSchedule/src/main/java/com/iformall/schedule/PhotoSpeakSchedule.java new file mode 100644 index 0000000..f3bfdd5 --- /dev/null +++ b/suimangSchedule/src/main/java/com/iformall/schedule/PhotoSpeakSchedule.java @@ -0,0 +1,106 @@ +package com.iformall.schedule; + +import com.iformall.domain.po.sm.PhotoSpeakVideo; +import com.iformall.domain.po.sm.UserMouldVideo; +import com.iformall.domain.po.sm.VideoTrans; +import com.iformall.enums.EnumVideoStatus; +import com.iformall.enums.EnumaVideoTransStatus; +import com.iformall.mapper.VideoTransMapper; +import com.iformall.service.sm.PhotoSpeakVideoService; +import com.iformall.service.sm.UserMouldVideoService; +import com.iformall.utils.DateUtils; +import com.iformall.video.VideoFactory; +import com.iformall.video.entity.VideTransResult; +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 PhotoSpeakSchedule { + + private final Logger logger = LoggerFactory.getLogger(this.getClass()); + + @Autowired + private PhotoSpeakVideoService photoSpeakVideoService; + + @Autowired + VideoFactory videoFactory; + + @Autowired + String videoType; + + /** + * 生成视频 + */ + @Scheduled(cron = "0 20/30 * * * *?") // 每半小时检查一次 + public void photoSpeakCreateSchedule() { + PhotoSpeakVideo videoUpd = new PhotoSpeakVideo(); + videoUpd.setVideoStartDate(DateUtils.getHourDateBefore(2,new Date())); + videoUpd.setVideoStatus(EnumVideoStatus.fail.getCode()); + List list = photoSpeakVideoService.findList(videoUpd); + if (list != null && list.size() > 0) { + for (PhotoSpeakVideo video : list) { + try { + Future future = photoSpeakVideoService.createVideo(video); + future.get(); + } catch (Exception e) { + logger.error("TtCouponVideoSchedule error.couponVideoSchedule:"+video.getId(),e); + } + } + } + } + + /** + * 上传阿里云 + */ + @Scheduled(cron = "0 */30 * * * *?") // 每半小时检查一次 + public void userVideoUploadSchedule() { + List videos = photoSpeakVideoService.getNotUploadList(); + if (videos != null && videos.size() > 0) { + for (PhotoSpeakVideo video : videos) { + try { + photoSpeakVideoService.uploadVideo(video); + } catch (Exception e) { + logger.error("TtCouponVideoSchedule error.couponVideoSchedule:"+video.getId(),e); + } + } + } + } + + /** + * 获取时长和大小 + */ + @Scheduled(cron = "0 1/5 * * * *?") // 每五分钟检查一次 + public void userVideoDetailSchedule() { + List videos = photoSpeakVideoService.getUpLoadIngList(); + if (videos != null && videos.size() > 0) { + for (PhotoSpeakVideo video : videos) { + try { + VideUploadResult videoDetail = videoFactory.getExcutor(videoType).getVideoDetailWithCache(video.getVideoId()); + if (videoDetail.isSuccess() + && StringUtils.isNotBlank(videoDetail.getDuration()) + && !"0.0".equals(videoDetail.getDuration())) { + video.setCoverImg(videoDetail.getCoverURL()); + video.setVideoPlayUrl(videoDetail.getVideoUrl()); + video.setVideoTime(videoDetail.getDuration()); + video.setVideoSize(videoDetail.getSize()); + video.setVideoStatus(EnumVideoStatus.upload_success.getCode()); + photoSpeakVideoService.updateById(video); + } + } catch (Exception e) { + logger.error("TtCouponVideoSchedule error.couponVideoSchedule:"+video.getId(),e); + } + } + } + } +} \ No newline at end of file