package com.xhkjedu.slive.controller.liveplay;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xhkjedu.annotation.Action;
import com.xhkjedu.slive.model.liveplay.LCourse;
import com.xhkjedu.slive.service.liveplay.CsService;
import com.xhkjedu.slive.vo.liveplay.CourseParams;
import com.xhkjedu.slive.vo.liveplay.CourseVo;
import com.xhkjedu.utils.DatesUtil;
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 CsController
 * @description 专题直播
 * @date 2022/9/22 16:41
 **/
@RestController
@RequestMapping("/cs")
public class CsController {
    @Resource
    private CsService csService;

    @PostMapping("/add")
    @Action("专题直播-增加")
    public ResultVo add(@RequestBody LCourse course) {
        N_Utils.validation(new Object[]{course.getSubjectid(), "科目id", 2});
        if (DatesUtil.dateNan(course.getBegindate()) || DatesUtil.dateNan(course.getEnddate())) {
            return new ResultVo(1, "日期格式不正确");
        }
        return csService.save(course);
    }

    @PostMapping("/list")
    public ResultVo list(@RequestBody LCourse course) {
        N_Utils.validation(new Object[]{course.getPage(), "显示页码", 1
                , course.getPageSize(), "显示条数", 1, course.getCreateid(), "用户id", 1});
        PageHelper.startPage(course.getPage(), course.getPageSize());
        List<CourseVo> list = csService.listAll(course);
        PageResult pageResult = PageUtil.getPageResult(new PageInfo(list));
        return new ResultVo(0, "获取课程列表成功", pageResult);
    }

    @PostMapping("/list_class")
    public ResultVo listClass(@RequestBody LCourse course) {
        Integer courseid = course.getCourseid();
        N_Utils.validation(new Object[]{courseid, "课程id", 1});
        List<Map> list = csService.listClass(courseid);
        return new ResultVo(0, "获取课程班级列表成功", list);
    }

    @PostMapping("/kj_mydate")
    public ResultVo listMySectionDate(@RequestBody CourseParams params) {
        N_Utils.validation(new Object[]{params.getTimestr(), "月份", 2, params.getTeacherid(), "用户id", 1});
        List<Map> list = csService.listMySectionDate(params);
        return new ResultVo(0, "获取月份下课节数量成功", list);
    }

    @PostMapping("/list_mydate")
    public ResultVo listMyByDate(@RequestBody CourseParams params) {
        N_Utils.validation(new Object[]{params.getTimestr(), "日期", 2, params.getTeacherid(), "用户id", 1});
        List<Map> list = csService.listMySection(params);
        return new ResultVo(0, "获取我的课节列表成功", list);
    }
}
