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.CourseChange;
import com.ruoyi.system.service.ICourseChangeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 调课Controller
 * 
 * @author ruoyi
 * @date 2023-06-02
 */
@RestController
@RequestMapping("/course/change")
public class CourseChangeController extends BaseController
{
    @Autowired
    private ICourseChangeService courseChangeService;

    /**
     * 查询调课列表
     */
    @PreAuthorize("@ss.hasPermi('course:change:list')")
    @GetMapping("/list")
    public TableDataInfo list(CourseChange courseChange)
    {
        startPage();
        List<CourseChange> list = courseChangeService.selectCourseChangeList(courseChange);
        return getDataTable(list);
    }

    /**
     * 查询调课列表(与课表一起)
     */
    @GetMapping("/list/class")
    public TableDataInfo courseList(CourseChange courseChange)
    {
        startPage();
        List<CourseChange> list = courseChangeService.courseList(courseChange);
        return getDataTable(list);
    }


    /**
     * 导出调课列表
     */
    @PreAuthorize("@ss.hasPermi('course:change:export')")
    @Log(title = "调课", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CourseChange courseChange)
    {
        List<CourseChange> list = courseChangeService.selectCourseChangeList(courseChange);
        ExcelUtil<CourseChange> util = new ExcelUtil<CourseChange>(CourseChange.class);
        util.exportExcel(response, list, "调课数据");
    }

    /**
     * 获取调课详细信息
     */
    @PreAuthorize("@ss.hasPermi('course:change:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(courseChangeService.selectCourseChangeById(id));
    }

    /**
     * 新增调课
     */
    @PreAuthorize("@ss.hasPermi('course:change:add')")
    @Log(title = "调课", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CourseChange courseChange)
    {
        return courseChangeService.insertCourseChange(courseChange);
    }

    /**
     * 修改调课
     */
    @PreAuthorize("@ss.hasPermi('course:change:edit')")
    @Log(title = "调课", businessType = BusinessType.UPDATE)
    @PostMapping("/put")
    public AjaxResult edit(@RequestBody CourseChange courseChange)
    {
        return toAjax(courseChangeService.updateCourseChange(courseChange));
    }


    /**
     * 回复调课
     */
    @PreAuthorize("@ss.hasPermi('course:change:reply')")
    @Log(title = "调课", businessType = BusinessType.UPDATE)
    @GetMapping("/reply")
    public AjaxResult reply(CourseChange courseChange)
    {
        return courseChangeService.updateCourseChangeReply(courseChange);
    }

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