package com.xhkjedu.slive.controller.recordserver;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xhkjedu.annotation.Action;
import com.xhkjedu.slive.model.recordserver.LRecordserver;
import com.xhkjedu.slive.service.recordserver.RecordserverService;
import com.xhkjedu.slive.vo.liveplay.RecordserverVo;
import com.xhkjedu.utils.N_Utils;
import com.xhkjedu.utils.PageUtil;
import com.xhkjedu.vo.PageResult;
import com.xhkjedu.vo.ResultVo;
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.RestController;

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

/**
 * @author ywx
 * @classname RecordserverController
 * @description 录制服务管理
 * @date 2022/12/2 9:42
 **/
@RestController
@RequestMapping("/lrs")
public class RecordserverController {
    @Resource
    private RecordserverService recordserverService;

    /*
     * 添加
     * @Param [rs]
     * @Author ywx
     * @Date 2022/12/2 9:57
     * @return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/add")
    @Action("录制服务-增加")
    public ResultVo add(@RequestBody LRecordserver rs) {
        N_Utils.validation(new Object[]{rs.getRsname(), "录制服务名称", 2, rs.getRsname(), "录制服务地址", 2
                , rs.getRsmaxnum(), "录制服务最大使用量", 1, rs.getCreateid(), "创建人id", 1});
        recordserverService.save(rs);
        return new ResultVo(0, "保存成功");
    }

    /*
     * 修改
     * @Param [rs]
     * @Author ywx
     * @Date 2022/12/2 9:58
     * @return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/update")
    @Action("录制服务-修改")
    public ResultVo update(@RequestBody LRecordserver rs) {
        N_Utils.validation(new Object[]{rs.getRsid(), "录制服务id", 1, rs.getHandleid(), "操作人id", 1});
        recordserverService.update(rs);
        return new ResultVo(0, "修改成功");
    }

    /*
     * 删除
     * @Param [rs]
     * @Author ywx
     * @Date 2022/12/2 10:00
     * @return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/delete")
    @Action("录制服务-删除")
    public ResultVo delete(@RequestBody LRecordserver rs) {
        Integer rsid = rs.getRsid();
        N_Utils.validation(new Object[]{rsid, "录制服务id", 1});
        recordserverService.deleteById(rsid);
        return new ResultVo(0, "删除成功");
    }

    /*
     * 列表
     * @Param [rs]
     * @Author ywx
     * @Date 2022/12/2 10:08
     * @return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/list")
    public ResultVo list(@RequestBody LRecordserver rs) {
        N_Utils.validation(new Object[]{rs.getPage(), "显示页码", 1, rs.getPageSize(), "显示条数", 1});
        PageHelper.startPage(rs.getPage(), rs.getPageSize());
        List<Map> list = recordserverService.findAll(rs);
        PageResult pageResult = PageUtil.getPageResult(new PageInfo<>(list));
        return new ResultVo(0, "获取列表成功", pageResult);
    }

    /*
     * 开启
     * @Param [rs]
     * @Author ywx
     * @Date 2022/12/2 10:13
     * @return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/open")
    @Action("录制服务-开启")
    public ResultVo open(@RequestBody LRecordserver rs) {
        N_Utils.validation(new Object[]{rs.getRsid(), "录制服务id", 1, rs.getHandleid(), "操作人id", 1});
        rs.setRsstate(1);
        recordserverService.updateStateById(rs);
        return new ResultVo(0, "开启成功");
    }

    /*
     * 关闭
     * @Param [rs]
     * @Author ywx
     * @Date 2022/12/2 10:16
     * @return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/close")
    @Action("录制服务-关闭")
    public ResultVo close(@RequestBody LRecordserver rs) {
        N_Utils.validation(new Object[]{rs.getRsid(), "录制服务id", 1, rs.getHandleid(), "操作人id", 1});
        rs.setRsstate(0);
        recordserverService.updateStateById(rs);
        return new ResultVo(0, "关闭成功");
    }

    /*
     * 开始录制
     * @Param [csp]
     * @Author ywx
     * @Date 2022/12/2 10:53
     * @return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/start")
    public ResultVo start(@RequestBody RecordserverVo rs) {
        N_Utils.validation(new Object[]{rs.getChannel(), "频道", 2, rs.getTid(), "教师id", 1
                , rs.getSectionid(), "课节id", 1});
        return recordserverService.start(rs);
    }

    /*
     * 停止录制
     * @Param [rs]
     * @Author ywx
     * @Date 2022/12/2 13:24
     * @return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/stop")
    public ResultVo stop(@RequestBody RecordserverVo rs) {
        N_Utils.validation(new Object[]{rs.getSid(), "sid", 2});
        return recordserverService.stop(rs);
    }

    /*
     * 是否有录制
     * @Param [rs]
     * @Author ywx
     * @Date 2022/12/2 13:26
     * @return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/has_recorder")
    public ResultVo hasRecorder(@RequestBody RecordserverVo rs) {
        N_Utils.validation(new Object[]{rs.getSid(), "sid", 2});
        return recordserverService.hasRecorder(rs);
    }
}
