package com.ym.mec.teacher.controller;

import com.ym.mec.biz.dal.dto.BaseMapDto;
import com.ym.mec.biz.dal.page.StudentManageQueryInfo;
import com.ym.mec.biz.service.StudentManageService;
import com.ym.mec.biz.service.SysUserCashAccountService;
import com.ym.mec.biz.service.SysUserService;
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 io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Optional;

@Api(tags = "学生管理")
@RequestMapping("/student")
@RestController
public class StudentController extends BaseController {

    @Autowired
    private SysUserCashAccountService sysUserCashAccountService;
    @Resource
    private SysUserService sysUserService;
    @Autowired
    private StudentManageService studentManageService;

    @ApiOperation(value = "获取学员账户信息")
    @GetMapping("/userCashAccount/get")
    public Object getStudentCashAccount(Integer id) {
        Optional.ofNullable(id).orElseThrow(() -> new BizException("学生id不能为空！"));
        return succeed(sysUserCashAccountService.get(id));
    }


    @ApiOperation(value = "获取学生列表")
    @PostMapping("/queryStudentList")
    public Object queryStudentList(@RequestBody StudentManageQueryInfo queryInfo){
        queryInfo.setTeacherId(sysUserService.getUserId());
        queryInfo.setIsExport(false);
        return succeed(studentManageService.findStudentsByOrganId(queryInfo));
    }

    @ApiOperation(value = "根据学生ID获取其所在的乐团")
    @GetMapping("/findStudentMusicGroups")
    public Object findStudentMusicGroups(@ApiParam(value = "学生编号", required = true) Integer userId){
        return succeed(studentManageService.findStudentMusicGroupsByUserId(userId));
    }

    @ApiOperation(value = "获取老师关联的学员声部列表")
    @GetMapping("/queryStuSubjectId")
    public HttpResponseResult<List<BaseMapDto>> queryStuSubjectId(){
        return succeed(studentManageService.queryStuSubjectId(sysUserService.getUserId()));
    }

}
