package com.xhkjedu.sapi.controller.analyze;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xhkjedu.sapi.model.subjectbook.TResource;
import com.xhkjedu.sapi.service.analyze.SchoolResourceService;
import com.xhkjedu.utils.N_Utils;
import com.xhkjedu.utils.PageUtil;
import com.xhkjedu.vo.PageResult;
import com.xhkjedu.vo.ResultVo;
import com.xhkjedu.sapi.vo.analyze.*;
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;

/**
 * @ClassName SchoolPeopleController
 * Description TODO 资源概况
 * Author WN
 * Date 2020/8/8 10:18
 **/
@RestController
@RequestMapping("/schoolr")
public class SchoolResourceController {

    @Autowired
    private SchoolResourceService schoolResourceService;

    /**
     *功能描述 资源总数量、下载数量、大小
     * @author WN
     * @date 2020/8/8
     * @param  * @param tClass
     * @return com.xhkjedu.vo.ResultVo
     */
    @PostMapping("/allnum")
    public ResultVo getSchoolAllNum(@RequestBody TResource tResource){
        N_Utils.validation(new Object[]{tResource.getSchoolid(),"学校id",1});
        SchoolResourceNumVo sr = schoolResourceService.getSchoolResourceNum(tResource.getSchoolid());
        return  new ResultVo(0,"",sr);
    }

    /**
     *功能描述 资源分布--资源分类统计
     * @author WN
     * @date 2020/8/9
     * @param  * @param tResource
     * @return com.xhkjedu.vo.ResultVo
     */
    @PostMapping("/rtype")
    public ResultVo getSchoolResourceType(@RequestBody TResource  tResource){
        N_Utils.validation(new Object[]{tResource.getSchoolid(),"学校id",1});
        List<SchoolResourceTypeNumVo> lst = schoolResourceService.listSchoolResourceTypeNum(tResource.getSchoolid());
        return  new ResultVo(0,"",lst);
    }

    /**
     *功能描述 资源分布--资源格式统计
     * @author WN
     * @date 2020/8/9
     * @param  * @param tResource
     * @return com.xhkjedu.vo.ResultVo
     */
    @PostMapping("/rclass")
    public ResultVo getSchoolResourceClass(@RequestBody TResource  tResource){
        N_Utils.validation(new Object[]{tResource.getSchoolid(),"学校id",1});
        List<SchoolResourceClassNumVo> lst = schoolResourceService.listSchoolResourceClassNum(tResource.getSchoolid());
        return  new ResultVo(0,"",lst);
    }

    /**
     *功能描述 资源上传量
     * @author WN
     * @date 2020/8/9
     * @param  * @param srparams
     * @return com.xhkjedu.vo.ResultVo
     */
    @PostMapping("/rupload")
    public ResultVo listSchoolResourceUpload(@RequestBody SchoolParams srparams){
        N_Utils.validation(new Object[]{srparams.getSchoolid(),"学校id",1,
                srparams.getType(),"时间段",1});
        List<SchoolResourceUploadNumVo> lst = schoolResourceService.listSchoolResourceUploadNum(srparams.getSchoolid(),srparams.getType());
        return  new ResultVo(0,"",lst);
    }

    /**
     *功能描述  资源排行榜
     * @author WN
     * @date 2020/8/9
     * @param  * @param srparams
     * @return com.xhkjedu.vo.ResultVo
     */
    @PostMapping("/rrank")
    public ResultVo listSchoolResourceRank(@RequestBody SchoolParams srparams){
        N_Utils.validation(new Object[]{srparams.getSchoolid(),"学校id",1,
                srparams.getType(),"时间段",1});
        List<SchoolResourceRankVo> lst = schoolResourceService.listSchoolResourceRank(srparams.getSchoolid(),srparams.getType(),srparams.getSubjectid(),srparams.getGradeid());
        return  new ResultVo(0,"",lst);
    }

    /**
     * 资源上传详情排行
     * @Param [params]
     * @Author ywx
     * @Date 2020/11/26 11:27
     * @return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/rrank2")
    public ResultVo listSchoolResourceRank2(@RequestBody SchoolParams params){
        N_Utils.validation(new Object[]{params.getSchoolid(),"学校id",1});
        if (N_Utils.isEmptyInteger(params.getPage())) {
            List<SchoolUserResourceNumVo> lst = schoolResourceService.listSchoolResourceRank2(params);
            return new ResultVo(0,"",lst);
        } else {
            PageHelper.startPage(params.getPage(),params.getPageSize());
            List<SchoolUserResourceNumVo> lst = schoolResourceService.listSchoolResourceRank2(params);
            PageResult pageResult = PageUtil.getPageResult(new PageInfo(lst));
            return new ResultVo(0,"",pageResult);
        }
    }

    /**
     *功能描述  结构性试题统计--各学科试题
     * @author WN
     * @date 2020/8/9
     * @param  * @param srparams
     * @return com.xhkjedu.vo.ResultVo
     */
    @PostMapping("/qsnum")
    public ResultVo listSchoolResourceQuestionSubject(@RequestBody SchoolParams srparams){
        N_Utils.validation(new Object[]{srparams.getSchoolid(),"学校id",1});
        List<SchoolResourceQuestionVo> lst = schoolResourceService.listSchoolResourceQuestion(srparams);
        return  new ResultVo(0,"",lst);
    }

    /**
     *功能描述 结构性试题统计--年级试题
     * @author WN
     * @date 2020/8/10
     * @param  * @param srparams
     * @return com.xhkjedu.vo.ResultVo
     */
    @PostMapping("/qgnum")
    public ResultVo listSchoolResourceQuestionGrade(@RequestBody SchoolParams srparams){
        N_Utils.validation(new Object[]{srparams.getSchoolid(),"学校id",1});
        List<SchoolResourceQuestionVo> lst = schoolResourceService.listSchoolResourceQuestionGrade(srparams);
        return  new ResultVo(0,"",lst);
    }

    /**
     *功能描述  结构性试题统计--教师上传排行榜
     * @author WN
     * @date 2020/8/9
     * @param  * @param srparams
     * @return com.xhkjedu.vo.ResultVo
     */
    @PostMapping("/qrank")
    public ResultVo listSchoolResourceQuestionRank(@RequestBody SchoolParams srparams){
        N_Utils.validation(new Object[]{srparams.getSchoolid(),"学校id",1});
        if (N_Utils.isEmptyInteger(srparams.getPage())) {
            List<SchoolResourceQuestionRankVo> lst = schoolResourceService.listSchoolResourceQuestionRank(srparams);
            return new ResultVo(0,"",lst);
        } else {
            PageHelper.startPage(srparams.getPage(),srparams.getPageSize());
            List<SchoolResourceQuestionRankVo> lst = schoolResourceService.listSchoolResourceQuestionRank(srparams);
            PageResult pageResult = PageUtil.getPageResult(new PageInfo(lst));
            return new ResultVo(0,"",pageResult);
        }
    }

    @PostMapping("/qnum")
    public ResultVo getSchoolQuestionNum(@RequestBody SchoolParams srparams){
        N_Utils.validation(new Object[]{srparams.getSchoolid(),"学校id",1});
        SchoolQuestionVo questionVo = schoolResourceService.getSchoolQuestionNum(srparams.getSchoolid());
        return  new ResultVo(0,"结构性试题数量统计",questionVo);
    }

    @PostMapping("/qgupload")
    public ResultVo listSchoolGQuestionUpload(@RequestBody SchoolParams params){
        N_Utils.validation(new Object[]{params.getSchoolid(),"学校id",1,params.getType(),"时间段",1});
        List<SchoolQuestionUploadNumVo> lst = schoolResourceService.listSchoolGQuestionUpload(params.getSchoolid(),params.getType());
        return  new ResultVo(0,"获取按年级试题上传变化列表",lst);
    }

    @PostMapping("/qsupload")
    public ResultVo listSchoolSQuestionUpload(@RequestBody SchoolParams params){
        N_Utils.validation(new Object[]{params.getSchoolid(),"学校id",1,params.getType(),"时间段",1});
        List<SchoolQuestionUploadNumVo> lst = schoolResourceService.listSchoolSQuestionUpload(params.getSchoolid(),params.getType());
        return  new ResultVo(0,"获取按科目试题上传变化列表",lst);
    }

    @PostMapping("/month_add")
    public ResultVo monthAdd(@RequestBody SchoolParams srparams){
        N_Utils.validation(new Object[]{srparams.getSchoolid(),"学校id",1});
        List<SchoolAddNumVo> lst = schoolResourceService.listMonthAdd(srparams.getSchoolid());
        return  new ResultVo(0,"获取本月新增情况成功",lst);
    }

    @PostMapping("/rgrade")
    public ResultVo getSchoolResourceGrade(@RequestBody TResource  tResource){
        N_Utils.validation(new Object[]{tResource.getSchoolid(),"学校id",1});
        List<SchoolResourceGradeNumVo> lst = schoolResourceService.listSchoolResourceGrade(tResource.getSchoolid());
        return  new ResultVo(0,"获取按年级资源统计列表成功",lst);
    }

    @PostMapping("/rsubject")
    public ResultVo getSchoolResourceSubject(@RequestBody TResource  tResource){
        N_Utils.validation(new Object[]{tResource.getSchoolid(),"学校id",1});
        List<SchoolResourceSubjectNumVo> lst = schoolResourceService.listSchoolResourceSubject(tResource.getSchoolid());
        return  new ResultVo(0,"获取按科目资源统计列表成功",lst);
    }

}
