package com.ym.mec.teacher.controller;

import com.ym.mec.auth.api.client.SysUserFeignService;
import com.ym.mec.auth.api.entity.SysUser;
import com.ym.mec.biz.dal.dto.CountStudentTrainDataDto;
import com.ym.mec.biz.dal.dto.MusicCompareRankingDto;
import com.ym.mec.biz.dal.entity.SysMusicCompareRecord;
import com.ym.mec.biz.dal.page.SysMusicCompareRecordQueryInfo;
import com.ym.mec.biz.service.SysMusicCompareRecordService;
import com.ym.mec.common.controller.BaseController;
import com.ym.mec.common.entity.HttpResponseResult;
import com.ym.mec.common.exception.BizException;
import com.ym.mec.common.page.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import static com.ym.mec.biz.dal.enums.FeatureType.CLOUD_STUDY_EVALUATION;

/**
 * @Author Joburgess
 * @Date 2021/8/11 0011
 */
@Api("云教练")
@RestController
@RequestMapping("cloudStudy")
public class CloudStudyController extends BaseController {

    @Autowired
    private SysUserFeignService sysUserFeignService;
    @Autowired
    private SysMusicCompareRecordService sysMusicCompareRecordService;

    @ApiOperation("查询乐团学员训练数据")
    @GetMapping("queryMusicGroupStudentTrainData")
    public HttpResponseResult<PageInfo<MusicCompareRankingDto>> queryMusicGroupStudentTrainData(SysMusicCompareRecordQueryInfo queryInfo){
        return succeed(sysMusicCompareRecordService.queryMusicGroupStudentTrainData(queryInfo));
    }

    @ApiOperation("学员训练数据")
    @GetMapping("queryStudentTrainData")
    public HttpResponseResult<PageInfo<SysMusicCompareRecord>> queryStudentTrainData(SysMusicCompareRecordQueryInfo queryInfo){
        return succeed(sysMusicCompareRecordService.queryStudentTrainData(queryInfo));
    }

    @ApiOperation("学员训练统计")
    @GetMapping("countStudentTrain")
    public HttpResponseResult<PageInfo<CountStudentTrainDataDto>> countStudentTrain(SysMusicCompareRecordQueryInfo queryInfo){
        SysUser sysUser = sysUserFeignService.queryUserInfo();
        if(sysUser == null){
            throw new BizException("请登录");
        }
        queryInfo.setTeacherId(sysUser.getId());
        return succeed(sysMusicCompareRecordService.countStudentTrain(queryInfo));
    }

    @ApiOperation("学员评测列表")
    @GetMapping("queryMusicCompareRecord")
    public HttpResponseResult<PageInfo<SysMusicCompareRecord>> queryMusicCompareRecord(SysMusicCompareRecordQueryInfo queryInfo){
        if(queryInfo.getFeatureType() == null){
            queryInfo.setFeatureType(CLOUD_STUDY_EVALUATION);
        }
        return succeed(sysMusicCompareRecordService.queryPage(queryInfo));
    }

}
