package com.ym.mec.web.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

import java.util.Date;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ym.mec.biz.dal.entity.StudentRegistration;
import com.ym.mec.biz.dal.page.StudentRegistrationQueryInfo;
import com.ym.mec.biz.service.StudentRegistrationService;
import com.ym.mec.common.controller.BaseController;

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

    @Autowired
    private StudentRegistrationService studentRegistrationService;

    @ApiOperation(value = "新增学生报名信息")
    @PostMapping("/add")
    public Object add(StudentRegistration studentRegistration) {
        studentRegistrationService.insert(studentRegistration);
        return succeed();
    }

    @ApiOperation(value = "删除学生报名信息")
    @PostMapping("/del/{id}")
    public Object del(@ApiParam(value = "学生报名信息编号", required = true) @PathVariable("id") Long id) {
        studentRegistrationService.delete(id);
        return succeed();
    }

    @ApiOperation(value = "修改学生报名信息")
    @PostMapping("/update")
    public Object update(StudentRegistration studentRegistration) {
        studentRegistration.setUpdateTime(new Date());
        studentRegistrationService.update(studentRegistration);
        return succeed();
    }

    @ApiOperation(value = "批量调剂学生报名专业")
    @PostMapping("/batchUpdateSubject")
    public Object batchUpdateSubject(String userId,Integer subId) {
        if (StringUtils.isEmpty(userId) || subId == null) {
            return failed();
        }
        return succeed(studentRegistrationService.batchUpdateSubject(userId, subId));
    }

    @ApiOperation(value = "乐团【报名中、缴费中】 学生详情列表分页查询")
    @GetMapping("/queryStudentApplyDetail")
    public Object queryStudentApplyDetail(StudentRegistrationQueryInfo queryInfo) {
        return succeed(studentRegistrationService.queryStudentDetailPage(queryInfo));
    }

    @ApiOperation(value = "学生报名缴费金额详情")
    @GetMapping("/queryFeeDetail")
    @ApiImplicitParams({@ApiImplicitParam(name = "studentId", value = "学生编号", required = true, dataType = "Integer"),
            @ApiImplicitParam(name = "musicGroupId", value = "乐团编号", required = true, dataType = "String")})
    public Object queryFeeDetail(String studentId,String musicGroupId) {
        if (StringUtils.isEmpty(studentId) || StringUtils.isEmpty(musicGroupId)) {
            return succeed(studentRegistrationService.queryFeeDetail(Integer.parseInt(studentId), musicGroupId));
        }
        return failed();
    }

    @ApiOperation(value = "获取未分班的学生")
    @GetMapping("/getNoClassStu")
    @ApiImplicitParams({@ApiImplicitParam(name = "musicGroupId", value = "乐团编号", required = true, dataType = "String"),
            @ApiImplicitParam(name = "actualSubjectId", value = "科目(声部)id", required = true, dataType = "int")})
    public Object getNoClassStuBySubjectId(Integer musicGroupId, Integer actualSubjectId) {
        return succeed(studentRegistrationService.getNoClassStuBySubjectId(musicGroupId, actualSubjectId));
    }

}
