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.BaseSeizeItem;
import com.sundot.airport.system.service.IBaseSeizeItemService;
import com.sundot.airport.common.utils.poi.ExcelUtil;
import com.sundot.airport.common.core.page.TableDataInfo;

/**
 * 查获物品Controller
 *
 * @author ruoyi
 * @date 2025-07-08
 */
@RestController
@RequestMapping("/system/item")
public class BaseSeizeItemController extends BaseController {
    @Autowired
    private IBaseSeizeItemService baseSeizeItemService;

    /**
     * 查询查获物品列表
     */
    @PreAuthorize("@ss.hasPermi('system:item:list')")
    @GetMapping("/list")
    public TableDataInfo list(BaseSeizeItem baseSeizeItem) {
        startPage();
        List<BaseSeizeItem> list = baseSeizeItemService.selectBaseSeizeItemList(baseSeizeItem);
        return getDataTable(list);
    }

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

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

    /**
     * 新增查获物品
     */
    @PreAuthorize("@ss.hasPermi('system:item:add')")
    @Log(title = "查获物品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BaseSeizeItem baseSeizeItem) {
        baseSeizeItem.setCreateBy(getUsername());
        return toAjax(baseSeizeItemService.insertBaseSeizeItem(baseSeizeItem));
    }

    /**
     * 修改查获物品
     */
    @PreAuthorize("@ss.hasPermi('system:item:edit')")
    @Log(title = "查获物品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaseSeizeItem baseSeizeItem) {
        baseSeizeItem.setUpdateBy(getUsername());
        return toAjax(baseSeizeItemService.updateBaseSeizeItem(baseSeizeItem));
    }

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

    /**
     * 根据分类编码查询查获物品列表
     */
    @PreAuthorize("@ss.hasPermi('system:item:list')")
    @GetMapping(value = "/list/{categoryCode}")
    public AjaxResult list(@PathVariable("categoryCode") String categoryCode) {
        return success(baseSeizeItemService.selectSeizeItemListByCategoryCode(categoryCode));
    }
}
