VideosJob.java 3.19 KB
package com.cnlive.shenhe.job;

import com.alibaba.fastjson.JSONObject;
import com.cnlive.shenhe.entity.ShySites;
import com.cnlive.shenhe.entity.ShyVideos;
import com.cnlive.shenhe.serviceImpl.CommentsServiceImpl;
import com.cnlive.shenhe.serviceImpl.SitesServiceImpl;
import com.cnlive.shenhe.serviceImpl.UsersServiceImpl;
import com.cnlive.shenhe.serviceImpl.VideosServiceImpl;
import com.cnlive.shenhe.utils.AuditPass;
import com.cnlive.shenhe.utils.CommonConst;
import com.cnlive.shenhe.utils.CommonUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@Component
public class VideosJob {
    private static Logger logger = LoggerFactory.getLogger(VideosJob.class);
    @Autowired
    SitesServiceImpl sitesService;
    @Autowired
    AuditPass Pass;
    @Autowired
    CommentsServiceImpl commentsService;
    @Autowired
    UsersServiceImpl usersService;
    @Autowired
    VideosServiceImpl videosService;


    @Scheduled(fixedRate =  60 * 1000)
    public void updateVideos() {
        //收集免审的spid
        List<ShySites> sitesList = sitesService.findAll();
        ArrayList<Integer> sites = new ArrayList<Integer>();
        for (ShySites shySites : sitesList) {
            if (CommonUtils.isNotEmpty(shySites.getWrite_business())) {
                String[] business = shySites.getWrite_business().split(",");
                List<String> asList = Arrays.asList(business);
                if (asList.contains(CommonConst.BUSINESS_VIDEO + "")) {
                    sites.add(shySites.getSpid());
                }
            }
        }
        //遍历免审的spid去更改状态值
        ShyVideos shyVideos = new ShyVideos();
        for (int spid : sites) {
            shyVideos.setSpid(spid);
            shyVideos.setState(CommonConst.AUDIT_INTT);
            List<ShyVideos> shyVideosList = videosService.findshyVideo(shyVideos);
            if (shyVideosList.size() > 0) {
                for (ShyVideos video : shyVideosList) {
                    JSONObject result = new JSONObject();
                    try {
                        result = Pass.auditPass(video.getVideo_id(), 3, "", "", video.getCallback());
                        Integer code = result.getInteger("code");
                        if (0 == code) {
                            int i = videosService.updateVideo(video.getId(), video.getAuditor_id(), CommonConst.AUDIT_SUCCESS, "");
                            if (i != 1) {
                                logger.error("点播视频更改失败,activity_id:{}", video.getVideo_id());
                            }
                        } else {
                            logger.error("点播视频回调失败,activity_id:{},code:{},msg:{}", video.getVideo_id(), code, result.getString("msg"));
                        }
                    } catch (Exception e) {
                        logger.error("点播视频回调失败,activity_id:{}", video.getVideo_id());
                    }
                }
            }
        }
    }

}