package com.sundot.airport.web.controller.system;

import java.util.List;
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.sundot.airport.common.annotation.Log;
import com.sundot.airport.common.core.controller.BaseController;
import com.sundot.airport.common.core.domain.AjaxResult;
import com.sundot.airport.common.enums.BusinessType;
import com.sundot.airport.system.domain.BaseCheckCategory;
import com.sundot.airport.system.service.IBaseCheckCategoryService;
import com.sundot.airport.common.utils.poi.ExcelUtil;

/**
 * 检查项分类Controller
 *
 * @author ruoyi
 * @date 2025-07-11
 */
@RestController
@RequestMapping("/system/checkCategory")
public class BaseCheckCategoryController extends BaseController {
    @Autowired
    private IBaseCheckCategoryService baseCheckCategoryService;

    /**
     * 查询检查项分类列表
     */
    @PreAuthorize("@ss.hasPermi('system:checkCategory:list')")
    @GetMapping("/list")
    public AjaxResult list(BaseCheckCategory baseCheckCategory) {
        List<BaseCheckCategory> list = baseCheckCategoryService.selectBaseCheckCategoryList(baseCheckCategory);
        return success(list);
    }

    /**
     * 导出检查项分类列表
     */
    @PreAuthorize("@ss.hasPermi('system:checkCategory:export')")
    @Log(title = "检查项分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BaseCheckCategory baseCheckCategory) {
        List<BaseCheckCategory> list = baseCheckCategoryService.selectBaseCheckCategoryList(baseCheckCategory);
        ExcelUtil<BaseCheckCategory> util = new ExcelUtil<BaseCheckCategory>(BaseCheckCategory.class);
        util.exportExcel(response, list, "检查项分类数据");
    }

    /**
     * 获取检查项分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:checkCategory:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(baseCheckCategoryService.selectBaseCheckCategoryById(id));
    }

    /**
     * 新增检查项分类
     */
    @PreAuthorize("@ss.hasPermi('system:checkCategory:add')")
    @Log(title = "检查项分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BaseCheckCategory baseCheckCategory) {
        baseCheckCategory.setCreateBy(getUsername());
        return toAjax(baseCheckCategoryService.insertBaseCheckCategory(baseCheckCategory));
    }

    /**
     * 修改检查项分类
     */
    @PreAuthorize("@ss.hasPermi('system:checkCategory:edit')")
    @Log(title = "检查项分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaseCheckCategory baseCheckCategory) {
        baseCheckCategory.setUpdateBy(getUsername());
        return toAjax(baseCheckCategoryService.updateBaseCheckCategory(baseCheckCategory));
    }

    /**
     * 删除检查项分类
     */
    @PreAuthorize("@ss.hasPermi('system:checkCategory:remove')")
    @Log(title = "检查项分类", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(baseCheckCategoryService.deleteBaseCheckCategoryByIds(ids));
    }

    /**
     * 查询检查项分类列表树形结构
     */
    @PreAuthorize("@ss.hasPermi('system:checkCategory:list')")
    @GetMapping("/listTree")
    public AjaxResult listTree(BaseCheckCategory baseCheckCategory) {
        List<BaseCheckCategory> list = baseCheckCategoryService.selectBaseCheckCategoryListTree(baseCheckCategory);
        return success(list);
    }
}
