package com.ym.mec.student.controller;

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.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ym.mec.biz.dal.dao.ClassGroupDao;
import com.ym.mec.biz.dal.dao.StudentRegistrationDao;
import com.ym.mec.biz.dal.dto.MusicGroupBasicDto;
import com.ym.mec.biz.dal.entity.MusicGroup;
import com.ym.mec.biz.dal.page.MusicGroupRecordStudentQueryInfo;
import com.ym.mec.biz.service.CooperationOrganLinkmanService;
import com.ym.mec.biz.service.MusicGroupService;
import com.ym.mec.biz.service.OrganizationService;
import com.ym.mec.biz.service.StudentRegistrationService;
import com.ym.mec.common.controller.BaseController;

@RequestMapping("musicGroupRecord")
@Api(tags = "乐团档案")
@RestController
public class MusicGroupRecordController extends BaseController {

	@Autowired
	private CooperationOrganLinkmanService cooperationOrganLinkmanService;
	
	@Autowired
	private MusicGroupService musicGroupService;
	
	@Autowired
	private OrganizationService organizationService;
	
	@Autowired
	private StudentRegistrationDao studentRegistrationDao;
	
	@Autowired
	private StudentRegistrationService studentRegistrationService;
	
	@Autowired
	private ClassGroupDao classGroupDao;

	@ApiOperation(value = "查询基本信息")
	@GetMapping("/queryBasicInfo")
	public Object queryBasicInfo(String musicGroupId) {
		
		MusicGroupBasicDto musicGroupBasicDto = musicGroupService.queryBasicInfo(musicGroupId);
		
		if(musicGroupBasicDto != null){
			Integer cooperationOrganId = musicGroupBasicDto.getCooperationOrganId();
			musicGroupBasicDto.setCooperationOrganLinkmanList(cooperationOrganLinkmanService.queryByCooperationOrganId(cooperationOrganId));
		}
		
		return succeed(musicGroupBasicDto);
	}

	@ApiOperation(value = "查询学员、师资")
	@GetMapping("/queryStudentAndTeacher")
	public Object queryStudentAndTeacher(String musicGroupId) {
		
		MusicGroup musicGroup = musicGroupService.get(musicGroupId);
		if(musicGroup == null){
			return failed("乐团信息查询失败");
		}
		
		ModelMap model = new ModelMap();

		model.put("subject", studentRegistrationDao.countStudentWithSubjectByMusicGroupId(musicGroupId));
		
		model.put("gradeMap", organizationService.getGradeList(musicGroup.getOrganId()));
		model.put("grade", studentRegistrationDao.countStudentWithGradeByMusicGroupId(musicGroupId));
		model.put("teacher", classGroupDao.countTeacherByMusicGroupId(musicGroupId));
		
		return succeed(model);
	}

	@ApiOperation(value = "学员列表")
	@GetMapping("/queryStudentInfo")
	public Object queryStudentInfo(MusicGroupRecordStudentQueryInfo queryInfo) {
		return succeed(studentRegistrationService.queryStudentRegisterInstrumentsDetailList(queryInfo));
	}

}
