package com.ruoyi.controller;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.springframework.data.annotation.Reference;
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.CsCompanyClass;
import com.ruoyi.cs.service.ICsCompanyClassService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 单位类别Controller
 *
 * @author ruoyi
 * @date 2024-04-22
 */
@RestController
@RequestMapping("/cs/csCompanyClass")
public class CsCompanyClassController extends BaseController
{
    @Resource
    private ICsCompanyClassService csCompanyClassService;

    /**
     * 查询单位类别列表
     */
    @PreAuthorize("@ss.hasPermi('cs:csCompanyClass:list')")
    @GetMapping("/list")
    public TableDataInfo list(CsCompanyClass csCompanyClass)
    {
        startPage();
        csCompanyClass.setDelFlag("0");
        List<CsCompanyClass> list = csCompanyClassService.selectCsCompanyClassList(csCompanyClass);
        return getDataTable(list);
    }

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

    /**
     * 获取单位类别详细信息
     */
    @PreAuthorize("@ss.hasPermi('cs:csCompanyClass:query')")
    @GetMapping(value = "/{companyClassId}")
    public AjaxResult getInfo(@PathVariable("companyClassId") String companyClassId)
    {
        return AjaxResult.success(csCompanyClassService.selectCsCompanyClassByCompanyClassId(companyClassId));
    }

    /**
     * 新增单位类别
     */
    @PreAuthorize("@ss.hasPermi('cs:csCompanyClass:add')")
    @Log(title = "单位类别", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CsCompanyClass csCompanyClass)
    {
        return toAjax(csCompanyClassService.insertCsCompanyClass(csCompanyClass));
    }

    /**
     * 修改单位类别
     */
    @PreAuthorize("@ss.hasPermi('cs:csCompanyClass:edit')")
    @Log(title = "单位类别", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CsCompanyClass csCompanyClass)
    {
        return toAjax(csCompanyClassService.updateCsCompanyClass(csCompanyClass));
    }

    /**
     * 删除单位类别
     */
    @PreAuthorize("@ss.hasPermi('cs:csCompanyClass:remove')")
    @Log(title = "单位类别", businessType = BusinessType.DELETE)
	@DeleteMapping("/{companyClassIds}")
    public AjaxResult remove(@PathVariable String[] companyClassIds)
    {
        return toAjax(csCompanyClassService.deleteCsCompanyClassByCompanyClassIds(companyClassIds));
    }
}
