GetTxVodJob.java 2.27 KB
Newer Older
张辰's avatar
张辰 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
package com.tanpu.feo.feojob.jobs;

import com.tanpu.feo.feojob.dao.user.entity.CurriculumRes;
import com.tanpu.feo.feojob.dao.user.entity.CurriculumResExample;
import com.tanpu.feo.feojob.dao.user.entity.UserCsFileRecord;
import com.tanpu.feo.feojob.dao.user.mapper.CurriculumResMapper;
import com.tanpu.feo.feojob.dao.user.mapper.UserCsFileRecordMapper;
import com.tanpu.feo.feojob.service.CurriculumResService;
import com.tanpu.feo.feojob.utils.TxVodUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Component
@Slf4j
张辰's avatar
张辰 committed
22
public class GetTxVodJob {
张辰's avatar
张辰 committed
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40

    @Resource
    private CurriculumResService curriculumResService;

    @Resource
    private UserCsFileRecordMapper userCsFileRecordMapper;

    @Resource
    private CurriculumResMapper resMapper;

    @Scheduled(cron = "0 * * * * ? ")
    public void execute() {
        List<UserCsFileRecord> records = curriculumResService.selectShortVideoForUndoneVodTask();

        for (UserCsFileRecord record : records) {
            try {
                executeTask(record);
            } catch (Exception e) {
xd's avatar
xd committed
41
                log.error("error in parse short video task. guid: {}", record.getGuid(), e);
张辰's avatar
张辰 committed
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
            }
        }
    }

    public void executeTask(UserCsFileRecord record) {
        String taskId = record.getExt2();
        if (StringUtils.isBlank(taskId)) {
            return;
        }

        Map<String, String> resultMap = TxVodUtil.getTransUrlByFileId(taskId);
        String videoUrl = resultMap.get("videoUrl");
        String coverUrl = resultMap.get("coverUrl");

        if (StringUtils.isNotBlank(videoUrl) && StringUtils.isNotBlank(coverUrl)) {
            // 更新视频资源
            CurriculumRes res = new CurriculumRes();
            res.setId(record.getRefid());
            res.setAudio(videoUrl);
            res.setCover(coverUrl);
            resMapper.updateByPrimaryKeySelective(res);

            // 更新cs file record
            record.setExt1("");
            userCsFileRecordMapper.updateByPrimaryKeySelective(record);
        }
    }
}