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.CsClass;
import com.ruoyi.cs.service.ICsClassService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 分类类别Controller
 * 
 * @author ruoyi
 * @date 2024-04-26
 */
@RestController
@RequestMapping("/cs/CsClass")
public class CsClassController extends BaseController
{
    @Resource
    private ICsClassService csClassService;


    /**
     * 获取类型列表by标记
     */
    @PreAuthorize("@ss.hasPermi('cs:CsClass:list')")
    @GetMapping("/getClassListByMark")
    public AjaxResult getClassListByMark(String classMark)
    {
        return AjaxResult.success(csClassService.selectCsClassListByClassMark(classMark));
    }

    /**
     * 查询分类类别列表
     */
    @PreAuthorize("@ss.hasPermi('cs:CsClass:list')")
    @GetMapping("/list")
    public TableDataInfo list(CsClass csClass)
    {
        startPage();
        List<CsClass> list = csClassService.selectCsClassList(csClass);
        return getDataTable(list);
    }

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

    /**
     * 获取分类类别详细信息
     */
    @PreAuthorize("@ss.hasPermi('cs:CsClass:query')")
    @GetMapping(value = "/{classId}")
    public AjaxResult getInfo(@PathVariable("classId") String classId)
    {
        return AjaxResult.success(csClassService.selectCsClassByClassId(classId));
    }

    /**
     * 新增分类类别
     */
    @PreAuthorize("@ss.hasPermi('cs:CsClass:add')")
    @Log(title = "分类类别", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CsClass csClass)
    {
        return toAjax(csClassService.insertCsClass(csClass));
    }

    /**
     * 修改分类类别
     */
    @PreAuthorize("@ss.hasPermi('cs:CsClass:edit')")
    @Log(title = "分类类别", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CsClass csClass)
    {
        return toAjax(csClassService.updateCsClass(csClass));
    }

    /**
     * 删除分类类别
     */
    @PreAuthorize("@ss.hasPermi('cs:CsClass:remove')")
    @Log(title = "分类类别", businessType = BusinessType.DELETE)
	@DeleteMapping("/{classIds}")
    public AjaxResult remove(@PathVariable String[] classIds)
    {
        return toAjax(csClassService.deleteCsClassByClassIds(classIds));
    }


}
