| @@ -2,9 +2,12 @@ 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; | |||
| @@ -14,7 +17,9 @@ 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 | |||
| @@ -31,11 +36,32 @@ public class VideoSchedule { | |||
| @Autowired | |||
| String videoType; | |||
| /** | |||
| * 生成视频 | |||
| */ | |||
| @Scheduled(cron = "0 20/30 * * * *?") // 每小时检查一次 | |||
| public void userVideoCreateSchedule() { | |||
| UserMouldVideo userVideo = new UserMouldVideo(); | |||
| userVideo.setStartDate(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 couponVideoUploadSchedule() { | |||
| public void userVideoUploadSchedule() { | |||
| List<UserMouldVideo> videos = userMouldVideoService.getVideoIdNullList(); | |||
| if (videos != null && videos.size() > 0) { | |||
| for (UserMouldVideo video : videos) { | |||
| @@ -52,13 +78,15 @@ public class VideoSchedule { | |||
| * 获取时长和大小 | |||
| */ | |||
| @Scheduled(cron = "0 15/30 * * * *?") // 每小时检查一次 | |||
| public void couponVideoDetailSchedule() { | |||
| 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()) { | |||
| if (videoDetail.isSuccess() | |||
| && StringUtils.isNotBlank(videoDetail.getDuration()) | |||
| && !"0.0".equals(videoDetail.getDuration())) { | |||
| video.setVideoTime(videoDetail.getDuration()); | |||
| video.setVideoSize(videoDetail.getSize()); | |||
| userMouldVideoService.updateById(video); | |||
| @@ -6,6 +6,7 @@ import com.iformall.domain.po.sm.MouldPatch; | |||
| import com.iformall.domain.po.sm.UserMouldVideo; | |||
| import java.util.List; | |||
| import java.util.concurrent.Future; | |||
| public interface UserMouldVideoService { | |||
| @@ -20,6 +21,8 @@ public interface UserMouldVideoService { | |||
| PageInfo<UserMouldVideo> listAsPage(UserMouldVideo record, Integer pageIndex, Integer pageSize); | |||
| PageInfo<UserMouldVideo> cListAsPage(UserMouldVideo record, Integer pageIndex, Integer pageSize); | |||
| List<UserMouldVideo> findList(UserMouldVideo record); | |||
| /** | |||
| * 根据Id获得实体 | |||
| * | |||
| @@ -42,7 +45,7 @@ public interface UserMouldVideoService { | |||
| */ | |||
| void deleteById(Long id); | |||
| void createVideo(UserMouldVideo mouldVideo); | |||
| Future createVideo(UserMouldVideo mouldVideo); | |||
| void uploadVideo(UserMouldVideo mouldVideo); | |||
| @@ -53,4 +56,5 @@ public interface UserMouldVideoService { | |||
| List<UserMouldVideo> getVideoSizeNullList(); | |||
| int updateById(UserMouldVideo video); | |||
| } | |||
| @@ -17,11 +17,13 @@ import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.scheduling.annotation.Async; | |||
| import org.springframework.scheduling.annotation.AsyncResult; | |||
| import org.springframework.stereotype.Service; | |||
| import java.net.URL; | |||
| import java.util.Date; | |||
| import java.util.List; | |||
| import java.util.concurrent.Future; | |||
| @Service | |||
| @@ -48,6 +50,11 @@ public class UserMouldVideoServiceImpl implements UserMouldVideoService { | |||
| return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> userMouldVideoMapper.findCList(record)); | |||
| } | |||
| @Override | |||
| public List<UserMouldVideo> findList(UserMouldVideo record) { | |||
| return userMouldVideoMapper.findList(record); | |||
| } | |||
| @Override | |||
| public UserMouldVideo getById(Long id) { | |||
| return userMouldVideoMapper.selectById(id); | |||
| @@ -78,7 +85,7 @@ public class UserMouldVideoServiceImpl implements UserMouldVideoService { | |||
| @Async | |||
| @Override | |||
| public void createVideo(UserMouldVideo mouldVideo) { | |||
| public Future createVideo(UserMouldVideo mouldVideo) { | |||
| UserMouldVideo videoUpd = new UserMouldVideo(); | |||
| videoUpd.setId(mouldVideo.getId()); | |||
| @@ -86,14 +93,14 @@ public class UserMouldVideoServiceImpl implements UserMouldVideoService { | |||
| videoUpd.setVideoStatus(EnumVideoStatus.fail.getCode()); | |||
| videoUpd.setVideoMsg("未找到人物模板数据"); | |||
| this.saveOrUpdate(videoUpd); | |||
| return; | |||
| return new AsyncResult<>(0); | |||
| } | |||
| if(StringUtils.isBlank(mouldVideo.getPaperwork())){ | |||
| videoUpd.setVideoStatus(EnumVideoStatus.fail.getCode()); | |||
| videoUpd.setVideoMsg("未填写视频文案"); | |||
| this.saveOrUpdate(videoUpd); | |||
| return; | |||
| return new AsyncResult<>(0); | |||
| } | |||
| try{ | |||
| @@ -108,19 +115,19 @@ public class UserMouldVideoServiceImpl implements UserMouldVideoService { | |||
| videoUpd.setTitle(mouldVideo.getTitle()); | |||
| this.uploadVideo(videoUpd); | |||
| return; | |||
| return new AsyncResult<>(1); | |||
| } | |||
| videoUpd.setVideoStatus(EnumVideoStatus.fail.getCode()); | |||
| videoUpd.setVideoMsg(video.getMsg()); | |||
| this.saveOrUpdate(videoUpd); | |||
| return; | |||
| return new AsyncResult<>(0); | |||
| }catch(Exception e){ | |||
| e.printStackTrace(); | |||
| videoUpd.setVideoStatus(EnumVideoStatus.fail.getCode()); | |||
| videoUpd.setVideoMsg(e.getMessage()); | |||
| this.saveOrUpdate(videoUpd); | |||
| return; | |||
| return new AsyncResult<>(0); | |||
| } | |||
| } | |||
| @@ -387,6 +387,20 @@ public class DateUtils { | |||
| Date date = new Date(myTime * 1000); | |||
| return formatter.format(date); | |||
| } | |||
| /** | |||
| * 获得当前时间前几小时的时间 | |||
| * | |||
| * @param hour | |||
| * 前几小时 | |||
| * @return | |||
| */ | |||
| public static Date getHourDateBefore(int hour, Date myDate) { | |||
| SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | |||
| long myTime = (myDate.getTime() / 1000) - 60 * 60 * hour; | |||
| Date date = new Date(myTime * 1000); | |||
| return date; | |||
| } | |||
| /** | |||
| * 获得当前时间前几秒的时间 | |||
| @@ -145,7 +145,9 @@ public class AliyunVideoExcutor implements VideoExcutor { | |||
| }else{ | |||
| VideUploadResult result = getVideoDetailFromApi(videoId); | |||
| if(this.videoStatus.equals(result.getStatus())){ | |||
| UploadCacheHelper.cacheVideoDetail(redisTemplate, videoId,result); | |||
| if(StringUtils.isNotBlank(result.getDuration()) && !"0.0".equals(result.getDuration())){ | |||
| UploadCacheHelper.cacheVideoDetail(redisTemplate, videoId,result); | |||
| } | |||
| }else{ | |||
| //还不能播放 | |||
| result.setSuccess(false); | |||