package com.zhongzheng.controller.polyv;

import com.zhongzheng.common.core.domain.model.LoginUser;
import com.zhongzheng.common.core.page.TableDataInfo;
import com.zhongzheng.common.utils.ServletUtils;
import com.zhongzheng.framework.web.service.TokenService;
import com.zhongzheng.modules.exam.bo.ExamApplyQueryBo;
import com.zhongzheng.modules.exam.vo.ExamApplyVo;
import com.zhongzheng.modules.polyv.bo.PolyvCataQueryBo;
import com.zhongzheng.modules.polyv.bo.PolyvVideoQueryBo;
import com.zhongzheng.modules.polyv.service.IPolyvCataService;
import com.zhongzheng.modules.polyv.vo.*;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.zhongzheng.common.core.controller.BaseController;
import com.zhongzheng.common.core.domain.AjaxResult;
import com.zhongzheng.modules.polyv.service.IPolyvVideoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import java.util.List;

/**
 * 保利威视频信息Controller
 *
 * @author zhongzheng
 * @date 2021-06-11
 */
@Api(value = "保利威视频信息控制器", tags = {"保利威视频信息管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/polyv/video")
public class PolyvVideoController extends BaseController {

    private final IPolyvVideoService iPolyvVideoService;
    private final IPolyvCataService iPolyvCataService;

    @Autowired
    private TokenService tokenService;
    /**
     * 获取保利威视频信息详细信息
     */
    @ApiOperation("获取保利威视频信息详细信息")
    @GetMapping("/{vid}")
    public AjaxResult<PolyvVideoQuerVo> getInfo(@PathVariable("vid") String vid) throws Exception {
        return AjaxResult.success(iPolyvVideoService.queryById(vid));
    }

    @ApiOperation("获取保利威视频播放凭证")
    @PreAuthorize("@ss.hasPermi('modules.polyv:video:query')")
    @GetMapping("/sign/{vid}")
    public AjaxResult<String> getPlayPcSign(@PathVariable("vid") String vid) throws Exception {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        String viewerId = String.valueOf(loginUser.getUser().getUserId());
        String token = iPolyvVideoService.polyvbPcSignRequest(vid,viewerId);
        return AjaxResult.success("成功",token);
    }

    /**
     * 获取保利威视频信息详细信息
     */
    @ApiOperation("获取保利威视频上传签名")
    @GetMapping("/getPolyvUpload")
    public AjaxResult<PolyvVo> getPolyvUpload() throws Exception {
        return AjaxResult.success(iPolyvVideoService.getPolyvUpload());
    }

    /**
     * 查询保利威分类列表
     */
    @ApiOperation("查询保利威分类列表")
    @PreAuthorize("@ss.hasPermi('system:cata:list')")
    @GetMapping("/listCata")
    public TableDataInfo<PolyvCataVo> list(PolyvCataQueryBo bo) {
        startPage();
        List<PolyvCataVo> list = iPolyvCataService.queryList(bo);
        return getDataTable(list);
    }

    /**
     * 查询保利威视频分类
     */
    @ApiOperation("更新视频分类")
    @PreAuthorize("@ss.hasPermi('modules.polyv:video:edit')")
    @PostMapping("/cata")
    public  AjaxResult list(@RequestBody PolyvVideoQueryBo bo) throws Exception {
        List<PolyvCataData> list = iPolyvVideoService.queryCataList(bo);
        return AjaxResult.success();
    }
    /**
     * 查询考试安排列表
     */
    @ApiOperation("同步保利威视频")
    @PreAuthorize("@ss.hasPermi('polyv:video:edit')")
    @PostMapping("/importList")
    public TableDataInfo<PolyvVideoVo> listPolyv(@RequestBody PolyvVideoQueryBo bo) throws Exception {
        //不传分页默认为20，传100000拿到所有数据
        bo.setPageSize(100000);
        bo.setPageNum(1);
        TableDataInfo list = iPolyvVideoService.queryPolyv(bo);
        return list;
    }

}
