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

/**
 * 项目类别Controller
 *
 * @author ruoyi
 * @date 2024-04-22
 */
@RestController
@RequestMapping("/cs/csProjectClass")
public class CsProjectClassController extends BaseController
{
    @Resource
    private ICsProjectClassService csProjectClassService;

    /**
     * 查询项目类别列表
     */
    @PreAuthorize("@ss.hasPermi('cs:csProjectClass:list')")
    @GetMapping("/list")
    public TableDataInfo list(CsProjectClass csProjectClass)
    {
        startPage();
        csProjectClass.setDelFlag("0");
        List<CsProjectClass> list = csProjectClassService.selectCsProjectClassList(csProjectClass);
        return getDataTable(list);
    }

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

    /**
     * 获取项目类别详细信息
     */
    @PreAuthorize("@ss.hasPermi('cs:csProjectClass:query')")
    @GetMapping(value = "/{projectClassId}")
    public AjaxResult getInfo(@PathVariable("projectClassId") String projectClassId)
    {
        return AjaxResult.success(csProjectClassService.selectCsProjectClassByProjectClassId(projectClassId));
    }

    /**
     * 新增项目类别
     */
    @PreAuthorize("@ss.hasPermi('cs:csProjectClass:add')")
    @Log(title = "项目类别", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CsProjectClass csProjectClass)
    {
        return toAjax(csProjectClassService.insertCsProjectClass(csProjectClass));
    }

    /**
     * 修改项目类别
     */
    @PreAuthorize("@ss.hasPermi('cs:csProjectClass:edit')")
    @Log(title = "项目类别", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CsProjectClass csProjectClass)
    {
        return toAjax(csProjectClassService.updateCsProjectClass(csProjectClass));
    }

    /**
     * 删除项目类别
     */
    @PreAuthorize("@ss.hasPermi('cs:csProjectClass:remove')")
    @Log(title = "项目类别", businessType = BusinessType.DELETE)
	@DeleteMapping("/{projectClassIds}")
    public AjaxResult remove(@PathVariable String[] projectClassIds)
    {
        return toAjax(csProjectClassService.deleteCsProjectClassByProjectClassIds(projectClassIds));
    }
}
