package com.yonge.cooleshow.tenant.controller;

import com.yonge.cooleshow.auth.api.client.SysUserFeignService;
import com.yonge.cooleshow.auth.api.entity.SysUser;
import com.yonge.cooleshow.biz.dal.queryInfo.SysMusicCompareRecordQueryInfo;
import com.yonge.cooleshow.biz.dal.service.SysMusicCompareRecordService;
import com.yonge.cooleshow.common.controller.BaseController;
import com.yonge.cooleshow.common.entity.HttpResponseResult;
import com.yonge.toolset.base.page.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

@Api(tags = "学生端训练记录")
@RequestMapping("${app-config.url.tenant:}/studentMusicCompareRecord")
@RestController
public class SysMusicCompareRecordController extends BaseController {

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


    @ApiOperation("学生端学员评测记录")
    @PostMapping("queryStudentTrain")
    public HttpResponseResult<PageInfo<SysMusicCompareRecordQueryInfo.StudentMusicCompareRecord>>
    queryStudentTrain(@RequestBody SysMusicCompareRecordQueryInfo.StudentMusicCompareRecordQuery query){
        SysUser sysUser = sysUserFeignService.queryUserInfo();
        if (sysUser == null) {
            return failed("获取用户信息失败");
        }
        query.setUserId(sysUser.getId());
        return succeed(sysMusicCompareRecordService.queryStudentTrain(query));
    }

    @ApiOperation("学员训练统计以及基本信息查询")
    @PostMapping("studentTrainStat")
    public HttpResponseResult<SysMusicCompareRecordQueryInfo.StudentMusicCompareRecordDto>
    studentTrainStat(@RequestBody SysMusicCompareRecordQueryInfo.StudentMusicCompareRecordQuery query){
        SysUser sysUser = sysUserFeignService.queryUserInfo();
        if (sysUser == null) {
            return failed("获取用户信息失败");
        }
        query.setUserId(sysUser.getId());
        return succeed(sysMusicCompareRecordService.studentTrainStat(query));
    }

    @ApiOperation("云教练排行榜")
    @PostMapping("rankingList")
    public HttpResponseResult<SysMusicCompareRecordQueryInfo.StatDto> rankingList(
            @RequestBody SysMusicCompareRecordQueryInfo.StudentCompareRecordQueryInfo queryInfo){
        SysUser sysUser = sysUserFeignService.queryUserInfo();
        if (sysUser == null) {
            return failed("获取用户信息失败");
        }
        queryInfo.setUserId(sysUser.getId());
        queryInfo.setTenantId(sysUser.getTenantId());
        return succeed(sysMusicCompareRecordService.rankingList(queryInfo));
    }

    @ApiOperation("学员训练数据统计")
    @PostMapping("studentTrainData")
    public HttpResponseResult studentTrainData(@RequestBody SysMusicCompareRecordQueryInfo.TeacherCompareRecordQueryInfo queryInfo){
        SysUser sysUser = sysUserFeignService.queryUserInfo();
        if (sysUser == null) {
            return failed("获取用户信息失败");
        }
        queryInfo.setUserId(sysUser.getId());
        return succeed(sysMusicCompareRecordService.studentTrainData(queryInfo));
    }
    @ApiOperation("学员训练数据统计每周")
    @GetMapping("studentTrainDataByWeek")
    public HttpResponseResult studentTrainDataByWeek(SysMusicCompareRecordQueryInfo.TeacherCompareRecordQueryInfo queryInfo){

        if (StringUtils.isEmpty(queryInfo.getStartTime())) {
            return failed("时间不能为空");
        }
        queryInfo.setClientId("student");
        return succeed(sysMusicCompareRecordService.studentTrainData(queryInfo));
    }

}
