package com.yonge.cooleshow.admin.controller;

import com.yonge.cooleshow.biz.dal.dto.SubjectHomeSearch;
import com.yonge.cooleshow.biz.dal.dto.req.TotalReq;
import com.yonge.cooleshow.biz.dal.service.HomeService;
import com.yonge.cooleshow.biz.dal.service.MusicSheetService;
import com.yonge.cooleshow.biz.dal.vo.CourseHomeVo;
import com.yonge.cooleshow.biz.dal.vo.HomeMusicSheetVo;
import com.yonge.cooleshow.biz.dal.vo.SubjectHomeVo;
import com.yonge.cooleshow.biz.dal.vo.res.HomeTotalStudent;
import com.yonge.cooleshow.biz.dal.vo.res.HomeTotalTeacher;
import com.yonge.cooleshow.biz.dal.vo.res.HomeUserToDoNum;
import com.yonge.cooleshow.common.controller.BaseController;
import com.yonge.cooleshow.common.entity.HttpResponseResult;
import com.yonge.toolset.base.page.PageInfo;
import com.yonge.toolset.base.page.QueryInfo;
import com.yonge.toolset.mybatis.support.PageUtil;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/home")
@Api(value = "首页", tags = "首页")
public class HomeController extends BaseController {
    @Autowired
    private HomeService homeService;

    @Autowired
    private MusicSheetService musicSheetService;

    @ApiOperation(value = "查询用户待办事项数")
    @PostMapping("/getUserToDoNum")
    @PreAuthorize("@pcs.hasPermissions('home/getUserToDoNum')")
    public HttpResponseResult<HomeUserToDoNum> getUserToDoNum() {
        return succeed(homeService.getUserToDoNum());
    }

    @ApiOperation(value = "老师数据统计")
    @PostMapping("/totalTeacher")
    @PreAuthorize("@pcs.hasPermissions('home/totalTeacher')")
    public HttpResponseResult<HomeTotalTeacher> totalTeacher(@Valid @RequestBody TotalReq totalReq) {
        return homeService.totalTeacher(totalReq);
    }

    @ApiOperation(value = "学员数据统计")
    @PostMapping("/totalStudent")
    @PreAuthorize("@pcs.hasPermissions('home/totalStudent')")
    public HttpResponseResult<HomeTotalStudent> totalStudent(@Valid @RequestBody TotalReq totalReq) {
        return homeService.totalStudent(totalReq);
    }

    @ApiOperation(value = "首页曲目点播数据")
    @PostMapping("/musicSheet")
    @PreAuthorize("@pcs.hasPermissions('home/musicSheet')")
    public HttpResponseResult<HomeMusicSheetVo> musicSheet() {
        return succeed(musicSheetService.getMusicSheetHome());
    }

    @ApiImplicitParams({
            @ApiImplicitParam(name = "dateTime", dataType = "String", value = "如果查询年数据 yyyy   如果查询月数据 yyyy-mm"),
            @ApiImplicitParam(name = "timeType", dataType = "String", value = " 时间类型 MONTH月度  YEAR年度"),
            @ApiImplicitParam(name = "type", dataType = "String", value = "类型  PRACTICE陪练课  LIVE直播课"),
    })
    @ApiOperation(value = "获取首页课程数据")
    @PostMapping("/courseHome")
    @PreAuthorize("@pcs.hasPermissions('home/courseHome')")
    public HttpResponseResult<CourseHomeVo> queryCourseHomeData(@RequestBody Map<String,Object> param) {
        return succeed(homeService.queryCourseHomeData(param));
    }



    @ApiOperation(value = "获取首页- 内容数据-声部数据")
    @PostMapping("/subjectHome")
    // @PreAuthorize("@pcs.hasPermissions('home/courseHome')")
    public HttpResponseResult<PageInfo<SubjectHomeVo>> subjectHome(@RequestBody SubjectHomeSearch query) {
        return succeed(homeService.subjectHome(PageUtil.getPage(query),query));
    }
}