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

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

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.auth.api.client.SysUserFeignService;
import com.ym.mec.biz.dal.dao.MusicGroupDao;
import com.ym.mec.biz.dal.dao.MusicGroupPaymentCalenderCourseSettingsDao;
import com.ym.mec.biz.dal.dao.MusicGroupPaymentCalenderDao;
import com.ym.mec.biz.dal.dto.StudentPreRegistrationDto;
import com.ym.mec.biz.dal.entity.StudentPreRegistration;
import com.ym.mec.biz.dal.page.StudentPreRegistrationQueryInfo;
import com.ym.mec.biz.service.EmployeeService;
import com.ym.mec.biz.service.MusicGroupSubjectPlanService;
import com.ym.mec.biz.service.StudentPreRegistrationService;
import com.ym.mec.biz.service.StudentRegistrationService;
import com.ym.mec.common.controller.BaseController;
import com.ym.mec.common.page.PageInfo;

@RequestMapping("eduStudentRegistration")
@Api(tags = "学生报名信息服务")
@RestController
public class EduStudentRegistrationController extends BaseController {

    @Autowired
    private StudentRegistrationService studentRegistrationService;
    @Autowired
    private MusicGroupSubjectPlanService musicGroupSubjectPlanService;
    @Autowired
    private MusicGroupPaymentCalenderDao musicGroupPaymentCalenderDao;
    @Autowired
    private MusicGroupPaymentCalenderCourseSettingsDao musicGroupPaymentCalenderCourseSettingsDao;
    @Autowired
    private StudentPreRegistrationService studentPreRegistrationService;
    @Autowired
    private MusicGroupDao musicGroupDao;
    @Autowired
    private SysUserFeignService sysUserFeignService;
    @Autowired
    private EmployeeService employeeService;

    @ApiOperation(value = "乐团预报名列表分页查询")
    @GetMapping("/queryPreApplyList")
    public Object queryPreApplyList(StudentPreRegistrationQueryInfo queryInfo) {
    	ModelMap model = new ModelMap();
    	PageInfo<StudentPreRegistrationDto> dataList = studentPreRegistrationService.queryListForPage(queryInfo);
    	model.put("dataList", dataList);
    	
    	Map<String, Object> params = new HashMap<String, Object>();
		params.put("musicGroupId", queryInfo.getMusicGroupId());
    	List<StudentPreRegistration> studentPreRegistrationList = studentPreRegistrationService.findAll(params);
    	
    	int instrument = 0;
    	long cloudTeacher = 0;
		for (StudentPreRegistration spr : studentPreRegistrationList) {
			if (spr.getCloudTeacherMethod() != null && spr.getCloudTeacherMethod().equals("OWNED")) {
				++cloudTeacher;
			}
			if (spr.getKitPurchaseMethod() != null && spr.getKitPurchaseMethod().equals("OWNED")) {
				++instrument;
			}
		}
    	
    	model.put("instrument", instrument);
    	model.put("cloudTeacher", cloudTeacher);
    	model.put("total", studentPreRegistrationList.size());
    	
    	model.put("musicGroup", musicGroupDao.get(queryInfo.getMusicGroupId()));
    	
        return succeed(model);
    }
}
