AvsampleCallBackControllerApi.java 2.27 KB
package com.cnlive.shenhe.api;

import com.alibaba.fastjson.JSONObject;
import com.cnlive.shenhe.bean.ErrorEnum;
import com.cnlive.shenhe.bean.ResponseBean;
import com.cnlive.shenhe.entity.ShyVideos;
import com.cnlive.shenhe.serviceImpl.VideosServiceImpl;
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.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @Auther: 周伟鹏
 * @Date: 2018/12/21 13:43
 * @Description:抽帧回调接口
 */
@Controller
@RequestMapping("/api/avsample")
public class AvsampleCallBackControllerApi {

    private static Logger logger = LoggerFactory.getLogger(AvsampleCallBackControllerApi.class);

    @Autowired
    VideosServiceImpl videosService;

    /**
     * 接收抽帧结果
     * @param json
     */
    @PostMapping("/callback")
    @ResponseBody
    public ResponseBean callback(@RequestBody JSONObject json) {
        logger.info("抽帧回调请求。。。。json=="+json.toJSONString());
        String taskId = json.getString("taskId");
        if(CommonUtils.isNotEmpty(taskId)){
            ShyVideos shyVideo = new ShyVideos();
            shyVideo.setTask_id(taskId);
            List<ShyVideos> shyVideosList = videosService.findshyVideo(shyVideo);
            if(!shyVideosList.isEmpty()){
                ShyVideos video = shyVideosList.get(0);
                Integer code = json.getInteger("code");
                if(code==3){
                    video.setAvsample(CommonConst.AVSAMPLE_SUCCESS);
                    video.setAvsample_imgs(json.getJSONArray("images").toJSONString());
                }else{
                    video.setAvsample(CommonConst.AVSAMPLE_FAIL);
                }
                video.setAvsample_msg(json.toJSONString());
                videosService.updateshyVideos(video);
            }

            return new ResponseBean();
        }
        return new ResponseBean(ErrorEnum.ERROR);
    }
}