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.MusicalNotesPlayStatDto;
import com.ym.mec.biz.dal.entity.SysMusicCompareRecord;
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 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.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Objects;

/**
 * @Author Joburgess
 * @Date 2021/8/13 0013
 */
@Api(tags = "云教练记录")
@RequestMapping("sysMusicRecord")
@RestController
public class SysMusicCompareRecordController extends BaseController {

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

    @ApiOperation(value = "添加记录")
    @PostMapping("add")
    public HttpResponseResult add(SysMusicCompareRecord record){
        SysUser sysUser = sysUserFeignService.queryUserInfo();
        if(sysUser == null){
            throw new BizException("请登录");
        }
        if(Objects.isNull(record.getFeature())){
            return failed("请设置功能点");
        }
        record.setUserId(sysUser.getId());
        record.setClientId("teacher");
        return succeed(sysMusicCompareRecordService.insert(record));
    }

    @ApiOperation(value = "用户最后一次评测数据")
    @GetMapping("getLastEvaluationMusicalNotesPlayStats")
    public HttpResponseResult getLastEvaluationMusicalNotesPlayStats(Long recordId){
        SysUser sysUser = sysUserFeignService.queryUserInfo();
        if(sysUser == null){
            throw new BizException("请登录");
        }
        return succeed(sysMusicCompareRecordService.getLastEvaluationMusicalNotesPlayStats(sysUser.getId(), recordId));
    }

}
