package com.ruoyi.hezhi.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.hezhi.domain.TbTeacherCourse;
import com.ruoyi.hezhi.service.ITbTeacherCourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 老师课程关联Controller
 *
 * @author ruoyi
 * @date 2024-09-14
 */
@RestController
@RequestMapping("/hezhi/teacherCourse")
public class TbTeacherCourseController extends BaseController
{
    @Autowired
    private ITbTeacherCourseService tbTeacherCourseService;

    /**
     * 查询老师课程关联列表
     */
    @PreAuthorize("@ss.hasPermi('hezhi:teacherCourse:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbTeacherCourse tbTeacherCourse)
    {
        startPage();
        List<TbTeacherCourse> list = tbTeacherCourseService.selectTbTeacherCourseList(tbTeacherCourse);
        return getDataTable(list);
    }

    /**
     * 导出老师课程关联列表
     */
    @PreAuthorize("@ss.hasPermi('hezhi:teacherCourse:export')")
    @Log(title = "老师课程关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbTeacherCourse tbTeacherCourse)
    {
        List<TbTeacherCourse> list = tbTeacherCourseService.selectTbTeacherCourseList(tbTeacherCourse);
        ExcelUtil<TbTeacherCourse> util = new ExcelUtil<TbTeacherCourse>(TbTeacherCourse.class);
        util.exportExcel(response, list, "老师课程关联数据");
    }

    /**
     * 获取老师课程关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('hezhi:teacherCourse:query')")
    @GetMapping(value = "/{teacherCourseId}")
    public AjaxResult getInfo(@PathVariable("teacherCourseId") Long teacherCourseId)
    {
        return success(tbTeacherCourseService.selectTbTeacherCourseByTeacherCourseId(teacherCourseId));
    }

    /**
     * 新增老师课程关联
     */
    @PreAuthorize("@ss.hasPermi('hezhi:teacherCourse:add')")
    @Log(title = "老师课程关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbTeacherCourse tbTeacherCourse)
    {
        return toAjax(tbTeacherCourseService.insertTbTeacherCourse(tbTeacherCourse));
    }

    /**
     * 修改老师课程关联
     */
    @PreAuthorize("@ss.hasPermi('hezhi:teacherCourse:edit')")
    @Log(title = "老师课程关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbTeacherCourse tbTeacherCourse)
    {
        return toAjax(tbTeacherCourseService.updateTbTeacherCourse(tbTeacherCourse));
    }

    /**
     * 删除老师课程关联
     */
    @PreAuthorize("@ss.hasPermi('hezhi:teacherCourse:remove')")
    @Log(title = "老师课程关联", businessType = BusinessType.DELETE)
	@DeleteMapping("/{teacherCourseIds}")
    public AjaxResult remove(@PathVariable Long[] teacherCourseIds)
    {
        return toAjax(tbTeacherCourseService.deleteTbTeacherCourseByTeacherCourseIds(teacherCourseIds));
    }
}
