package cn.teammodel.controller.admin.controller;

import cn.teammodel.common.R;
import cn.teammodel.controller.admin.service.AdminAppraiseService;
import cn.teammodel.model.dto.admin.appraise.TimeRangeDto;
import cn.teammodel.model.vo.admin.*;
import cn.teammodel.model.vo.appraise.RecordVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;

/**
 * 管理员首页
 * @author winter
 * &#064;create  2023-12-06 14:37
 */
@RestController
@RequestMapping("admin/index")
@Api(tags = "管理员端-首页数据")
public class IndexController {
    @Resource
    private AdminAppraiseService adminAppraiseService;


    @PostMapping("/")
    @ApiOperation("获取首页数据")
    public R<AppraiseIndexData> index(@Valid @RequestBody TimeRangeDto timeRangeDto){
        AppraiseIndexData appraiseIndexData = adminAppraiseService.getIndexData(timeRangeDto);
        return R.success(appraiseIndexData);
    }

    @PostMapping("latestRecord")
    @ApiOperation("查询时间范围最近评价(无参则当前周的所有记录)")
    public R<List<RecordVo>> latestRecord(@Valid @RequestBody TimeRangeDto timeRangeDto, HttpServletRequest request) {
        List<RecordVo> res = adminAppraiseService.conditionLatestRecord(timeRangeDto,request);
        return R.success(res);
    }

    @PostMapping("classRank")
    @ApiOperation("班级评价活跃排行榜: Top10")
    public R<List<RankPo>> classRank(@Valid @RequestBody TimeRangeDto timeRangeDto) {
        List<RankPo> res = adminAppraiseService.classRank(timeRangeDto);
        return R.success(res);
    }
    @PostMapping("studentRank")
    @ApiOperation("学生评价活跃排行榜: Top10")
    public R<List<StudentRankVo>> studentRank(@Valid @RequestBody TimeRangeDto timeRangeDto) {
        List<StudentRankVo> res = adminAppraiseService.studentRank(timeRangeDto);
        return R.success(res);
    }
    @PostMapping("teacherRank")
    @ApiOperation("老师评价活跃排行榜: Top10")
    public R<List<RankVo>> teacherRank(@Valid @RequestBody TimeRangeDto timeRangeDto) {
        List<RankVo> res = adminAppraiseService.teacherRank(timeRangeDto);
        return R.success(res);
    }
    @PostMapping("appraiseNodeRank")
    @ApiOperation("评价指标活跃排行榜: Top10")
    public R<List<AppraiseNodeRankVo>> appraiseNodeRank(@Valid @RequestBody TimeRangeDto timeRangeDto) {
        List<AppraiseNodeRankVo> res = adminAppraiseService.appraiseNodeRank(timeRangeDto);
        return R.success(res);
    }

}
