package com.ym.mec.web.controller;

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

import java.util.Date;
import java.util.List;

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

import com.ym.mec.biz.dal.dto.HighClassGroup;
import com.ym.mec.biz.dal.entity.ClassGroup;
import com.ym.mec.biz.dal.entity.ClassGroupTeacherMapper;
import com.ym.mec.biz.service.ClassGroupService;
import com.ym.mec.biz.service.ClassGroupTeacherMapperService;
import com.ym.mec.common.controller.BaseController;
import com.ym.mec.common.page.QueryInfo;

@RequestMapping("classGroup")
@Api(tags = "班级服务")
@RestController
public class ClassGroupController extends BaseController {

    @Autowired
    private ClassGroupService classGroupService;
    @Autowired
    private ClassGroupTeacherMapperService classGroupTeacherMapperService;

    @ApiOperation(value = "新增单技班班级")
    @PostMapping("/add")
    public Object add(@RequestBody ClassGroup classGroup) throws Exception {
        return succeed(classGroupService.addClassGroup(classGroup));
    }

    @ApiOperation(value = "新增合奏班")
    @PostMapping("/addMixClass")
    public Object addMixClass(@ApiParam(value = "乐团编号", required = true) @RequestParam Integer musicGroupId,
                              @ApiParam(value = "班级名称", required = true) String name,
                              @ApiParam(value = "班级编号,号分割", required = true) String classGroupIds) throws Exception {
        return succeed(classGroupService.addMixClassGroup(musicGroupId, name, classGroupIds));
    }

    @ApiOperation(value = "新增提高班")
    @PostMapping("/addHighClass")
    public Object addHighClass(@ApiParam(value = "乐团提高班json", required = true) @RequestParam List<HighClassGroup> HighClassGroupList) throws Exception {
        if (HighClassGroupList.size() <= 0) {
            return failed("参数不合法");
        }
        return succeed(classGroupService.addHighClassGroup(HighClassGroupList));
    }

    @ApiOperation(value = "删除班级")
    @PostMapping("/del/{id}")
    public Object del(@ApiParam(value = "班级编号", required = true) @PathVariable("id") Integer id) {
        classGroupService.delete(id);
        return succeed();
    }

    @ApiOperation(value = "修改班级")
    @PostMapping("/update")
    public Object update(ClassGroup classGroup) {
        classGroup.setUpdateTime(new Date());
        classGroupService.update(classGroup);
        return succeed();
    }

    @ApiOperation(value = "分页查询班级列表")
    @GetMapping("/queryPage")
    public Object queryPage(QueryInfo queryInfo) {
        return succeed(classGroupService.queryPage(queryInfo));
    }

    @ApiOperation(value = "合奏班相关班级获取")
    @GetMapping("/findClassGroupAboutMix")
    public Object findClassGroupAboutMix(@ApiParam(value = "乐团编号", required = true) @RequestParam Integer musicGroupId,
                                         @ApiParam(value = "班级编号", required = false) Integer mixClassGroupId) {
        return succeed(classGroupService.findClassGroup(musicGroupId, mixClassGroupId));
    }

    @ApiOperation(value = "乐团单技班列表")
    @GetMapping("/findMusicGroupClass")
    public Object findMusicGroupClass(@ApiParam(value = "乐团编号", required = true) @RequestParam Integer musicGroupId) {
        return succeed(classGroupService.findAllNormalClassGroupByMusicGroupId(musicGroupId));
    }

    @ApiOperation(value = "乐团合奏班列表")
    @GetMapping("/findMixMusicGroupClass")
    public Object findMixMusicGroupClass(@ApiParam(value = "乐团编号", required = true) @RequestParam Integer musicGroupId) {
        return succeed(classGroupService.findAllMixClassGroupByMusicGroupId(musicGroupId));
    }

    @ApiOperation(value = "乐团班级老师设置")
    @GetMapping("/addClassGroupTeacher")
    public Object addClassGroupTeacher(@ApiParam(value = "乐团班级老师json", required = true) @RequestParam List<ClassGroupTeacherMapper> classGroupTeacherMapperList) {
        if (classGroupTeacherMapperList.size() <= 0) {
            return failed("参数不合法");
        }
        return succeed(classGroupTeacherMapperService.classGroupTeachersInsert(classGroupTeacherMapperList));
    }

    @ApiOperation(value = "获取乐团班级老师")
    @GetMapping("/findMusicGroupClassTeacher")
    public Object findMusicGroupClassTeacher(@ApiParam(value = "乐团编号", required = true) @RequestParam Integer musicGroupId) {
        return succeed(classGroupService.getClassGroupAndTeachers(musicGroupId));
    }

    @ApiOperation(value = "获取乐团班级老师课酬")
    @GetMapping("/findMusicGroupClassTeacherSalary")
    public Object findMusicGroupClassTeacherSalary(@ApiParam(value = "乐团编号", required = true) @RequestParam Integer musicGroupId) {
        return succeed(classGroupService.getClassGroupAndTeacherSalary(musicGroupId));
    }

    @ApiOperation(value = "乐团班级老师课酬确认")
    @GetMapping("/setClassGroupTeacherSalary")
    public Object setClassGroupTeacherSalary(@ApiParam(value = "乐团班级老师json", required = true) @RequestParam List<ClassGroupTeacherMapper> classGroupTeacherMapperList) throws Exception {
        if (classGroupTeacherMapperList.size() <= 0) {
            return failed("参数不合法");
        }
        return succeed(classGroupTeacherMapperService.classGroupTeacherMapperUpdate(classGroupTeacherMapperList));
    }


}
