package com.ym.mec.student.controller;

import com.ym.mec.biz.dal.entity.SysMusicCompareRecord;
import com.ym.mec.biz.service.SysMusicCompareRecordService;
import com.ym.mec.biz.service.SysUserService;
import com.ym.mec.common.controller.BaseController;
import com.ym.mec.common.entity.HttpResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
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.Objects;

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

    @Autowired
    private SysUserService sysUserService;
    @Autowired
    private SysMusicCompareRecordService sysMusicCompareRecordService;

    @ApiOperation(value = "添加记录")
    @PostMapping("add")
    public HttpResponseResult add(SysMusicCompareRecord record){
        if(Objects.isNull(record.getFeature())){
            return failed("请设置功能点");
        }
        Integer userId = sysUserService.getUserId();
        record.setUserId(userId);
        record.setClientId("student");
        
        sysMusicCompareRecordService.insert(record);
        
        ModelMap model = new ModelMap();
        model.put("totalPlayTimeOfCurrentDate", sysMusicCompareRecordService.queryCurrentDatePlayTimeByUserId(userId));
        
        return succeed(model);
    }

    @ApiOperation(value = "用户最后一次评测数据")
    @GetMapping("getLastEvaluationMusicalNotesPlayStats")
    public HttpResponseResult getLastEvaluationMusicalNotesPlayStats(Long recordId){
        return succeed(sysMusicCompareRecordService.getLastEvaluationMusicalNotesPlayStats(sysUserService.getUserId(), recordId));
    }

}
