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.UserCreateVideoNumService; 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.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.Future; import java.util.stream.Collectors; @Configuration @EnableScheduling public class PhotoSpeakSchedule { private final Logger logger = LoggerFactory.getLogger(this.getClass()); @Autowired private PhotoSpeakVideoService photoSpeakVideoService; @Autowired VideoFactory videoFactory; @Autowired String videoType; @Autowired private UserCreateVideoNumService userCreateVideoNumService; /** * 生成视频 */ @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); } } } } /** * 统计用户创建视频成功的时长 */ @Scheduled(cron = "0 */30 * * * *?") // 每半小时检查一次 public void userCreateVideoTimeSchedule() { List videos = photoSpeakVideoService.getUploadSuccessList(); if (videos != null && videos.size() > 0) { HashMap map = new HashMap<>(); for (PhotoSpeakVideo video : videos) { try { if (map.get(video.getUserId()) == null) { map.put(video.getUserId(), Long.parseLong(video.getVideoTime())); } else { Long time = map.get(video.getUserId()); map.put(video.getUserId(), Long.parseLong(video.getVideoTime()) + time); } } catch (Exception e) { logger.error("TtCouponVideoSchedule error.couponVideoSchedule:" + video.getId(), e); } } userCreateVideoNumService.uploadUserCreateVideoNum(map); } } }