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.TbStudyCenterFile;
import com.ruoyi.hezhi.service.ITbStudyCenterFileService;
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-11-18
 */
@RestController
@RequestMapping("/hezhi/studyCenterFile")
public class TbStudyCenterFileController extends BaseController
{
    @Autowired
    private ITbStudyCenterFileService tbStudyCenterFileService;

    /**
     * 查询学习中心文件列表
     */
    @PreAuthorize("@ss.hasPermi('hezhi:studyCenterFile:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbStudyCenterFile tbStudyCenterFile)
    {
        startPage();
        List<TbStudyCenterFile> list = tbStudyCenterFileService.selectTbStudyCenterFileList(tbStudyCenterFile);
        return getDataTable(list);
    }

    /**
     * 导出学习中心文件列表
     */
    @PreAuthorize("@ss.hasPermi('hezhi:studyCenterFile:export')")
    @Log(title = "学习中心文件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbStudyCenterFile tbStudyCenterFile)
    {
        List<TbStudyCenterFile> list = tbStudyCenterFileService.selectTbStudyCenterFileList(tbStudyCenterFile);
        ExcelUtil<TbStudyCenterFile> util = new ExcelUtil<TbStudyCenterFile>(TbStudyCenterFile.class);
        util.exportExcel(response, list, "学习中心文件数据");
    }

    /**
     * 获取学习中心文件详细信息
     */
    @PreAuthorize("@ss.hasPermi('hezhi:studyCenterFile:query')")
    @GetMapping(value = "/{studyCenterFileId}")
    public AjaxResult getInfo(@PathVariable("studyCenterFileId") Long studyCenterFileId)
    {
        return success(tbStudyCenterFileService.selectTbStudyCenterFileByStudyCenterFileId(studyCenterFileId));
    }

    /**
     * 新增学习中心文件
     */
    @PreAuthorize("@ss.hasPermi('hezhi:studyCenterFile:add')")
    @Log(title = "学习中心文件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbStudyCenterFile tbStudyCenterFile)
    {
        return toAjax(tbStudyCenterFileService.insertTbStudyCenterFile(tbStudyCenterFile));
    }

    /**
     * 修改学习中心文件
     */
    @PreAuthorize("@ss.hasPermi('hezhi:studyCenterFile:edit')")
    @Log(title = "学习中心文件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbStudyCenterFile tbStudyCenterFile)
    {
        return toAjax(tbStudyCenterFileService.updateTbStudyCenterFile(tbStudyCenterFile));
    }

    /**
     * 删除学习中心文件
     */
    @PreAuthorize("@ss.hasPermi('hezhi:studyCenterFile:remove')")
    @Log(title = "学习中心文件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{studyCenterFileIds}")
    public AjaxResult remove(@PathVariable Long[] studyCenterFileIds)
    {
        return toAjax(tbStudyCenterFileService.deleteTbStudyCenterFileByStudyCenterFileIds(studyCenterFileIds));
    }
}
