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.TbStudyCenterClass;
import com.ruoyi.hezhi.service.ITbStudyCenterClassService;
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/studyCenterClass")
public class TbStudyCenterClassController extends BaseController
{
    @Autowired
    private ITbStudyCenterClassService tbStudyCenterClassService;

    /**
     * 查询学习中心分类列表
     */
    @PreAuthorize("@ss.hasPermi('hezhi:studyCenterClass:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbStudyCenterClass tbStudyCenterClass)
    {
        startPage();
        List<TbStudyCenterClass> list = tbStudyCenterClassService.selectTbStudyCenterClassList(tbStudyCenterClass);
        return getDataTable(list);
    }

    /**
     * 导出学习中心分类列表
     */
    @PreAuthorize("@ss.hasPermi('hezhi:studyCenterClass:export')")
    @Log(title = "学习中心分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbStudyCenterClass tbStudyCenterClass)
    {
        List<TbStudyCenterClass> list = tbStudyCenterClassService.selectTbStudyCenterClassList(tbStudyCenterClass);
        ExcelUtil<TbStudyCenterClass> util = new ExcelUtil<TbStudyCenterClass>(TbStudyCenterClass.class);
        util.exportExcel(response, list, "学习中心分类数据");
    }

    /**
     * 获取学习中心分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('hezhi:studyCenterClass:query')")
    @GetMapping(value = "/{studyCenterClassId}")
    public AjaxResult getInfo(@PathVariable("studyCenterClassId") Long studyCenterClassId)
    {
        return success(tbStudyCenterClassService.selectTbStudyCenterClassByStudyCenterClassId(studyCenterClassId));
    }

    /**
     * 新增学习中心分类
     */
    @PreAuthorize("@ss.hasPermi('hezhi:studyCenterClass:add')")
    @Log(title = "学习中心分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbStudyCenterClass tbStudyCenterClass)
    {
        return toAjax(tbStudyCenterClassService.insertTbStudyCenterClass(tbStudyCenterClass));
    }

    /**
     * 修改学习中心分类
     */
    @PreAuthorize("@ss.hasPermi('hezhi:studyCenterClass:edit')")
    @Log(title = "学习中心分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbStudyCenterClass tbStudyCenterClass)
    {
        return toAjax(tbStudyCenterClassService.updateTbStudyCenterClass(tbStudyCenterClass));
    }

    /**
     * 删除学习中心分类
     */
    @PreAuthorize("@ss.hasPermi('hezhi:studyCenterClass:remove')")
    @Log(title = "学习中心分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{studyCenterClassIds}")
    public AjaxResult remove(@PathVariable Long[] studyCenterClassIds)
    {
        return toAjax(tbStudyCenterClassService.deleteTbStudyCenterClassByStudyCenterClassIds(studyCenterClassIds));
    }

    /**
     * 所有学习中心分类列表
     * @return
     */
    @GetMapping("/getAllStudyCenterClassList")
    public AjaxResult getAllStudyCenterClassList() {
        TbStudyCenterClass studyCenterClass = new TbStudyCenterClass();
        studyCenterClass.setDelFlag(0);
        return AjaxResult.success(tbStudyCenterClassService.selectTbStudyCenterClassList(studyCenterClass));
    }
}
