package cn.reghao.tnb.file.app.zjob.task;

import cn.reghao.jutil.jdk.web.result.Result;
import cn.reghao.jutil.jdk.web.result.ResultStatus;
import cn.reghao.tnb.content.api.iface.AdminVideoService;
import cn.reghao.tnb.file.app.zjob.db.JobDetailMapper;
import cn.reghao.tnb.file.app.zjob.model.constant.JobStatus;

import java.time.LocalDateTime;

/**
 * @author reghao
 * @date 2024-12-04 13:46:25
 */
public class PublishVideoTask implements Runnable {
    private final long jobId;
    private final JobDetailMapper jobDetailMapper;
    private final AdminVideoService adminVideoService;
    private final String videoId;

    public PublishVideoTask(long jobId, JobDetailMapper jobDetailMapper, AdminVideoService adminVideoService, String videoId) {
        this.jobId = jobId;
        this.jobDetailMapper = jobDetailMapper;
        this.adminVideoService = adminVideoService;
        this.videoId = videoId;
    }

    @Override
    public void run() {
        String status = JobStatus.Success.getDesc();
        try {
            Result result = adminVideoService.setVideoPostPublish(videoId);
            if (result.getCode() != ResultStatus.SUCCESS.getCode()) {
                status = JobStatus.Fail.getDesc();
            }
        } catch (Exception e) {
            e.printStackTrace();
            status = JobStatus.Fail.getDesc();
        }

        LocalDateTime current = LocalDateTime.now();
        jobDetailMapper.updateSetEnd(jobId, status, current);
    }
}
