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.TbTypeCourse;
import com.ruoyi.hezhi.service.ITbTypeCourseService;
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-19
 */
@RestController
@RequestMapping("/hezhi/typeCourse")
public class TbTypeCourseController extends BaseController
{
    @Autowired
    private ITbTypeCourseService tbTypeCourseService;

    /**
     * 查询类型课程关联列表
     */
    @PreAuthorize("@ss.hasPermi('hezhi:typeCourse:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbTypeCourse tbTypeCourse)
    {
        startPage();
        List<TbTypeCourse> list = tbTypeCourseService.selectTbTypeCourseList(tbTypeCourse);
        return getDataTable(list);
    }

    /**
     * 导出类型课程关联列表
     */
    @PreAuthorize("@ss.hasPermi('hezhi:typeCourse:export')")
    @Log(title = "类型课程关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbTypeCourse tbTypeCourse)
    {
        List<TbTypeCourse> list = tbTypeCourseService.selectTbTypeCourseList(tbTypeCourse);
        ExcelUtil<TbTypeCourse> util = new ExcelUtil<TbTypeCourse>(TbTypeCourse.class);
        util.exportExcel(response, list, "类型课程关联数据");
    }

    /**
     * 获取类型课程关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('hezhi:typeCourse:query')")
    @GetMapping(value = "/{typeCourseId}")
    public AjaxResult getInfo(@PathVariable("typeCourseId") Long typeCourseId)
    {
        return success(tbTypeCourseService.selectTbTypeCourseByTypeCourseId(typeCourseId));
    }

    /**
     * 新增类型课程关联
     */
    @PreAuthorize("@ss.hasPermi('hezhi:typeCourse:add')")
    @Log(title = "类型课程关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbTypeCourse tbTypeCourse)
    {
        return toAjax(tbTypeCourseService.insertTbTypeCourse(tbTypeCourse));
    }

    /**
     * 修改类型课程关联
     */
    @PreAuthorize("@ss.hasPermi('hezhi:typeCourse:edit')")
    @Log(title = "类型课程关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbTypeCourse tbTypeCourse)
    {
        return toAjax(tbTypeCourseService.updateTbTypeCourse(tbTypeCourse));
    }

    /**
     * 删除类型课程关联
     */
    @PreAuthorize("@ss.hasPermi('hezhi:typeCourse:remove')")
    @Log(title = "类型课程关联", businessType = BusinessType.DELETE)
	@DeleteMapping("/{typeCourseIds}")
    public AjaxResult remove(@PathVariable Long[] typeCourseIds)
    {
        return toAjax(tbTypeCourseService.deleteTbTypeCourseByTypeCourseIds(typeCourseIds));
    }
}
