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.TbContinuingEducationClass;
import com.ruoyi.hezhi.service.ITbContinuingEducationClassService;
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-10-23
 */
@RestController
@RequestMapping("/hezhi/continuingEducationClass")
public class TbContinuingEducationClassController extends BaseController
{
    @Autowired
    private ITbContinuingEducationClassService tbContinuingEducationClassService;

    /**
     * 查询继续教育分类列表
     */
    @PreAuthorize("@ss.hasPermi('hezhi:continuingEducationClass:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbContinuingEducationClass tbContinuingEducationClass)
    {
        startPage();
        List<TbContinuingEducationClass> list = tbContinuingEducationClassService.selectTbContinuingEducationClassList(tbContinuingEducationClass);
        return getDataTable(list);
    }

    /**
     * 导出继续教育分类列表
     */
    @PreAuthorize("@ss.hasPermi('hezhi:continuingEducationClass:export')")
    @Log(title = "继续教育分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbContinuingEducationClass tbContinuingEducationClass)
    {
        List<TbContinuingEducationClass> list = tbContinuingEducationClassService.selectTbContinuingEducationClassList(tbContinuingEducationClass);
        ExcelUtil<TbContinuingEducationClass> util = new ExcelUtil<TbContinuingEducationClass>(TbContinuingEducationClass.class);
        util.exportExcel(response, list, "继续教育分类数据");
    }

    /**
     * 获取继续教育分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('hezhi:continuingEducationClass:query')")
    @GetMapping(value = "/{continuingEducationClassId}")
    public AjaxResult getInfo(@PathVariable("continuingEducationClassId") Long continuingEducationClassId)
    {
        return success(tbContinuingEducationClassService.selectTbContinuingEducationClassByContinuingEducationClassId(continuingEducationClassId));
    }

    /**
     * 新增继续教育分类
     */
    @PreAuthorize("@ss.hasPermi('hezhi:continuingEducationClass:add')")
    @Log(title = "继续教育分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbContinuingEducationClass tbContinuingEducationClass)
    {
        return toAjax(tbContinuingEducationClassService.insertTbContinuingEducationClass(tbContinuingEducationClass));
    }

    /**
     * 修改继续教育分类
     */
    @PreAuthorize("@ss.hasPermi('hezhi:continuingEducationClass:edit')")
    @Log(title = "继续教育分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbContinuingEducationClass tbContinuingEducationClass)
    {
        return toAjax(tbContinuingEducationClassService.updateTbContinuingEducationClass(tbContinuingEducationClass));
    }

    /**
     * 删除继续教育分类
     */
    @PreAuthorize("@ss.hasPermi('hezhi:continuingEducationClass:remove')")
    @Log(title = "继续教育分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{continuingEducationClassIds}")
    public AjaxResult remove(@PathVariable Long[] continuingEducationClassIds)
    {
        return toAjax(tbContinuingEducationClassService.deleteTbContinuingEducationClassByContinuingEducationClassIds(continuingEducationClassIds));
    }

    /**
     * 获取继续教育分类列表
     * @return 结果
     */
    @GetMapping("/getAllContinuingEducationClassList")
    public AjaxResult getAllContinuingEducationClassList(){
        List<TbContinuingEducationClass> allContinuingEducationClassList = tbContinuingEducationClassService.getAllContinuingEducationClassList();
        return AjaxResult.success(allContinuingEducationClassList);
    }

}
