package com.yida.data.school.classSchedule.controller;

import com.yida.data.common.core.common.ResultBean;
import com.yida.data.common.core.entity.classschedule.EduSemester;
import com.yida.data.school.classSchedule.service.EduSemesterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 学期管理表 Controller
 *
 * @author wjm
 * @date 2021-08-13 11:28:42
 */
@Api(tags = "课程表-学期")
@Slf4j
@Validated
@RestController
@RequestMapping("/classSchedule/semester")
@RequiredArgsConstructor
public class EduSemesterController {

    private final EduSemesterService eduSemesterService;

    /***
     * @Author jianMingWang
     * @Description 查询学期
     * @Date 13:53 2021/8/13
     * @Param []
     * @return com.yida.data.common.core.common.ResultBean<java.util.List < com.yida.data.common.core.entity.classschedule.EduSemester>>
     **/
    @ApiOperation("查询所有学期")
    @GetMapping("/listSemester")
    public ResultBean<List<EduSemester>> findList() {
        return ResultBean.buildSuccess(eduSemesterService.list());
    }

    @ApiOperation("保存学期")
    @PostMapping("/saveSemster")
    public ResultBean saveSemester(@RequestBody EduSemester semester) {
        eduSemesterService.saveOrUpdate(semester);
        return ResultBean.buildSuccess();
    }

    @ApiOperation("删除学期")
    @PostMapping("/delSemesterBatch")
    public ResultBean delSemesterBatch(@RequestBody List<Long> ids) {
        eduSemesterService.removeByIds(ids);
        return ResultBean.buildSuccess();
    }

    @ApiOperation("根据日期查询当前学期")
    @GetMapping("/getSemesterByDate")
    public ResultBean<EduSemester> getNowSemester(@ApiParam("日期，yyyy-MM-dd") String date) {
        return ResultBean.buildSuccess(eduSemesterService.getSemesterByDate(date));
    }

}
