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

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

import com.sundot.airport.common.annotation.Anonymous;
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.BaseSeizeCategory;
import com.sundot.airport.system.service.IBaseSeizeCategoryService;
import com.sundot.airport.common.utils.poi.ExcelUtil;

/**
 * 查获物品分类Controller
 *
 * @author ruoyi
 * @date 2025-07-08
 */
@RestController
@RequestMapping("/system/category")
public class BaseSeizeCategoryController extends BaseController {
    @Autowired
    private IBaseSeizeCategoryService baseSeizeCategoryService;

    /**
     * 查询查获物品分类列表
     */
    @Anonymous
    @GetMapping("/list")
    public AjaxResult list(BaseSeizeCategory baseSeizeCategory) {
        List<BaseSeizeCategory> list = baseSeizeCategoryService.selectBaseSeizeCategoryList(baseSeizeCategory);
        return success(list);
    }

    /**
     * 导出查获物品分类列表
     */
    @PreAuthorize("@ss.hasPermi('system:category:export')")
    @Log(title = "查获物品分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BaseSeizeCategory baseSeizeCategory) {
        List<BaseSeizeCategory> list = baseSeizeCategoryService.selectBaseSeizeCategoryList(baseSeizeCategory);
        ExcelUtil<BaseSeizeCategory> util = new ExcelUtil<BaseSeizeCategory>(BaseSeizeCategory.class);
        util.exportExcel(response, list, "查获物品分类数据");
    }

    /**
     * 获取查获物品分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:category:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(baseSeizeCategoryService.selectBaseSeizeCategoryById(id));
    }

    /**
     * 新增查获物品分类
     */
    @PreAuthorize("@ss.hasPermi('system:category:add')")
    @Log(title = "查获物品分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BaseSeizeCategory baseSeizeCategory) {
        baseSeizeCategory.setCreateBy(getUsername());
        return toAjax(baseSeizeCategoryService.insertBaseSeizeCategory(baseSeizeCategory));
    }

    /**
     * 修改查获物品分类
     */
    @PreAuthorize("@ss.hasPermi('system:category:edit')")
    @Log(title = "查获物品分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaseSeizeCategory baseSeizeCategory) {
        baseSeizeCategory.setUpdateBy(getUsername());
        return toAjax(baseSeizeCategoryService.updateBaseSeizeCategory(baseSeizeCategory));
    }

    /**
     * 删除查获物品分类
     */
    @PreAuthorize("@ss.hasPermi('system:category:remove')")
    @Log(title = "查获物品分类", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(baseSeizeCategoryService.deleteBaseSeizeCategoryByIds(ids));
    }

    /**
     * 查询查获物品分类列表树形结构
     */
    @PreAuthorize("@ss.hasPermi('system:category:list')")
    @GetMapping("/listTree")
    public AjaxResult listTree(BaseSeizeCategory baseSeizeCategory) {
        List<BaseSeizeCategory> list = baseSeizeCategoryService.selectBaseSeizeCategoryListTree(baseSeizeCategory);
        return success(list);
    }
}
