package com.ruoyi.web.controller.course;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.CourseTable;
import com.ruoyi.system.service.ICourseTableService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 课程Controller
 * 
 * @author ruoyi
 * @date 2023-05-24
 */
@RestController
@RequestMapping("/course/table")
public class CourseTableController extends BaseController
{
    @Autowired
    private ICourseTableService courseTableService;

    /**
     * 查询课程列表
     */
    @GetMapping("/list")
    public TableDataInfo list(CourseTable courseTable)
    {
        startPage();
        List<CourseTable> list = courseTableService.selectCourseTableList(courseTable);
        return getDataTable(list);
    }

    /**
     * 导出课程列表
     */
    @PreAuthorize("@ss.hasPermi('course:table:export')")
    @Log(title = "课程", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CourseTable courseTable)
    {
        List<CourseTable> list = courseTableService.selectCourseTableList(courseTable);
        ExcelUtil<CourseTable> util = new ExcelUtil<CourseTable>(CourseTable.class);
        util.exportExcel(response, list, "课程数据");
    }

    /**
     * 获取课程详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(courseTableService.selectCourseTableById(id));
    }

    /**
     * 新增课程
     */
    @PreAuthorize("@ss.hasPermi('course:table:add')")
    @Log(title = "课程", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CourseTable courseTable)
    {
        return toAjax(courseTableService.insertCourseTable(courseTable));
    }

    /**
     * 修改课程
     */
    @PreAuthorize("@ss.hasPermi('course:table:edit')")
    @Log(title = "课程", businessType = BusinessType.UPDATE)
    @PostMapping("/put")
    public AjaxResult edit(@RequestBody CourseTable courseTable)
    {
        return toAjax(courseTableService.updateCourseTable(courseTable));
    }

    /**
     * 删除课程
     */
    @PreAuthorize("@ss.hasPermi('course:table:remove')")
    @Log(title = "课程", businessType = BusinessType.DELETE)
	@GetMapping("/delete/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(courseTableService.deleteCourseTableByIds(ids));
    }


    /**
     * app查询班级授课老师和名称
     * @param schoolId
     * @param classId
     * @return
     */
    @GetMapping(value = "/now")
    public AjaxResult now(Long schoolId, Long classId)
    {
        return courseTableService.now(schoolId,classId);
    }

}
