package com.ym.mec.web.controller.education;

import com.ym.mec.biz.dal.dto.BaseMapDto;
import com.ym.mec.biz.dal.dto.EduOrganStudentDataDto;
import com.ym.mec.biz.dal.dto.StatDto;
import com.ym.mec.biz.dal.entity.Organization;
import com.ym.mec.biz.dal.entity.Subject;
import com.ym.mec.biz.dal.page.StudentQueryInfo;
import com.ym.mec.biz.service.OrganizationService;
import com.ym.mec.biz.service.StudentManageService;
import com.ym.mec.biz.service.StudentService;
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 io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author Joburgess
 * @Date 2021/8/17 0017
 */
@RequestMapping("eduStudent")
@Api(tags = "学生信息服务")
@RestController
public class EduStudentController extends BaseController {

    @Autowired
    private StudentService studentService;
    @Autowired
    private OrganizationService organizationService;
    @Autowired
    private StudentManageService studentManageService;

    @ApiOperation(value = "云教练学员数据")
    @GetMapping("/organStudentData")
    public HttpResponseResult<StatDto> organStudentData(StudentQueryInfo queryInfo){
        return succeed(studentService.organStudentData(queryInfo));
    }

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

    @ApiOperation(value = "分部云教练学员数据预览")
    @GetMapping("/organStudentOverView")
    public HttpResponseResult<List<EduOrganStudentDataDto>> organStudentOverView() throws Exception {
        List<Organization> organizations = organizationService.queryEmployeeOrgan();
        if(CollectionUtils.isEmpty(organizations)){
            return succeed(Collections.emptyList());
        }
        List<Integer> organIds = organizations.stream().map(Organization::getId).collect(Collectors.toList());
        return succeed(studentService.organStudentOverView(organIds));
    }

    @ApiOperation(value = "获取所选分部的学员声部列表")
    @GetMapping("/queryStuSubjectId")
    public HttpResponseResult<List<BaseMapDto>> queryStuSubjectId(){
        return succeed(studentService.queryStuSubjectId(organizationService.getEmployeeOrgan(null)));
    }
}
