package com.ruoyi.controller;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.cs.domain.CsResourceClass;
import com.ruoyi.cs.service.ICsResourceClassService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 资源分类Controller
 *
 * @author ruoyi
 * @date 2024-04-22
 */
@RestController
@RequestMapping("/cs/csResourceClass")
public class CsResourceClassController extends BaseController
{
    @Resource
    private ICsResourceClassService csResourceClassService;

    /**
     * 查询资源分类列表
     */
    @PreAuthorize("@ss.hasPermi('cs:csResourceClass:list')")
    @GetMapping("/list")
    public TableDataInfo list(CsResourceClass csResourceClass)
    {
        startPage();
        csResourceClass.setDelFlag("0");
        List<CsResourceClass> list = csResourceClassService.selectCsResourceClassList(csResourceClass);
        return getDataTable(list);
    }

    /**
     * 导出资源分类列表
     */
    @PreAuthorize("@ss.hasPermi('cs:csResourceClass:export')")
    @Log(title = "资源分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CsResourceClass csResourceClass)
    {
        List<CsResourceClass> list = csResourceClassService.selectCsResourceClassList(csResourceClass);
        ExcelUtil<CsResourceClass> util = new ExcelUtil<CsResourceClass>(CsResourceClass.class);
        util.exportExcel(response, list, "资源分类数据");
    }

    /**
     * 获取资源分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('cs:csResourceClass:query')")
    @GetMapping(value = "/{resourceClassId}")
    public AjaxResult getInfo(@PathVariable("resourceClassId") String resourceClassId)
    {
        return AjaxResult.success(csResourceClassService.selectCsResourceClassByResourceClassId(resourceClassId));
    }

    /**
     * 新增资源分类
     */
    @PreAuthorize("@ss.hasPermi('cs:csResourceClass:add')")
    @Log(title = "资源分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CsResourceClass csResourceClass)
    {
        return toAjax(csResourceClassService.insertCsResourceClass(csResourceClass));
    }

    /**
     * 修改资源分类
     */
    @PreAuthorize("@ss.hasPermi('cs:csResourceClass:edit')")
    @Log(title = "资源分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CsResourceClass csResourceClass)
    {
        return toAjax(csResourceClassService.updateCsResourceClass(csResourceClass));
    }

    /**
     * 删除资源分类
     */
    @PreAuthorize("@ss.hasPermi('cs:csResourceClass:remove')")
    @Log(title = "资源分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{resourceClassIds}")
    public AjaxResult remove(@PathVariable String[] resourceClassIds)
    {
        return toAjax(csResourceClassService.deleteCsResourceClassByResourceClassIds(resourceClassIds));
    }
}
