package com.xhkjedu.sstudy.controller.recite;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xhkjedu.sstudy.model.recite.TReciteStudent;
import com.xhkjedu.sstudy.service.recite.ReciteStudentService;
import com.xhkjedu.sstudy.vo.recite.ReciteStudentVo;
import com.xhkjedu.utils.N_Utils;
import com.xhkjedu.utils.PageUtil;
import com.xhkjedu.vo.PageResult;
import com.xhkjedu.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
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 java.util.List;
import java.util.Map;

/**
 * @ClassName ReciteStudentController
 * Description 学生背诵
 * Author WN
 * Date 2020/6/10 14:39
 **/
@RestController
@RequestMapping("/recites")
public class ReciteStudentController {
    @Autowired
    private ReciteStudentService reciteStudentService;

    /**
     *功能描述  背诵列表
     * @author WN
     * @date 2020/6/10
     * @param  * @param reciteStudent
     * @return com.xhkjedu.vo.ResultVo
     */
    @PostMapping("/list")
    public ResultVo list(@RequestBody TReciteStudent reciteStudent){
        Integer page = reciteStudent.getPage();
        Integer pageSize = reciteStudent.getPageSize();
        N_Utils.validation(new Object[]{
                page,"显示页码",1,pageSize,"显示条数",1,
                reciteStudent.getStudentid(),"学生id",1});
        reciteStudent.setPage((page-1)*pageSize);
        List<ReciteStudentVo> lst = reciteStudentService.listStuReceites(reciteStudent);
        return new ResultVo(0,"获取背诵列表成功",lst);
    }

    /**
     *功能描述  保存背诵内容
     * @author WN
     * @date 2020/6/10
     * @param  * @param reciteStudent
     * @return com.xhkjedu.vo.ResultVo
     */
    @PostMapping("/up")
    public ResultVo update(@RequestBody TReciteStudent reciteStudent){
        N_Utils.validation(new Object[]{
                reciteStudent.getReciteid(),"背诵id",1,
                reciteStudent.getStudentid(),"学生id",1,
                reciteStudent.getStarttime(),"开始时间",1,
                reciteStudent.getStoptime(),"结束时间",1,
                reciteStudent.getCosttime(),"花费时长",1
        });
        Integer result = reciteStudentService.updateStudRecite(reciteStudent);
        if(result>0){
            return new ResultVo(0,"保存成功");
        }else{
            return new ResultVo(1,"保存失败");
        }
    }

    /**
     *功能描述 获取背诵内容
     * @author WN
     * @date 2020/6/10
     * @param  * @param reciteStudent
     * @return com.xhkjedu.vo.ResultVo
     */
    @PostMapping("/detail")
    public ResultVo getReciteStudent(@RequestBody TReciteStudent reciteStudent){
        N_Utils.validation(new Object[]{reciteStudent.getStudentid(),"学生id",1,reciteStudent.getReciteid(),"背诵id",1});
        ReciteStudentVo reciteStudentVo = reciteStudentService.getReciteStuByRsid(reciteStudent.getStudentid(),reciteStudent.getReciteid());
        return new ResultVo(0,"获取学生背诵内容成功",reciteStudentVo);
    }

    /**
     *功能描述  背诵统计
     * @author WN
     * @date 2020/6/17
     * @param  * @param reciteStudent
     * @return com.xhkjedu.vo.ResultVo
     */
    @PostMapping("/classanaly")
    public ResultVo listReciteClass(@RequestBody TReciteStudent reciteStudent){
        N_Utils.validation(new Object[]{reciteStudent.getReciteid(),"背诵id",1,
                reciteStudent.getTeacherid(),"教师id",1,reciteStudent.getSchoolid(),"学校id",1});
        List<Map> list = reciteStudentService.listRecitesClassForAnalyze(reciteStudent);
        return new ResultVo(0,"获取班级背诵情况成功",list);
    }

    /**
     *功能描述 背诵学生--网页--列表
     * @author WN
     * @date 2022/2/22
     * @param  * @param student
     * @return com.xhkjedu.vo.ResultVo
     */
    @PostMapping("/stw_recite")
    public ResultVo listReciteStuWeb(@RequestBody TReciteStudent student){
        Integer page = student.getPage();
        Integer pageSize = student.getPageSize();
        N_Utils.validation(new Object[]{
                page,"显示页码",1,pageSize,"显示条数",1,
                student.getStudentid(),"学生id",1});
        PageHelper.startPage(page, pageSize);
        List<ReciteStudentVo> list = reciteStudentService.listReciteStuWeb(student);
        PageResult pageResult = PageUtil.getPageResult(new PageInfo(list));
        return new ResultVo(0,"获取背诵列表成功",pageResult);
    }
}
