package com.fs.store.controller;

import java.util.List;

import com.fs.store.domain.FsWarehouses;
import com.fs.store.service.IFsWarehousesService;
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.fs.common.annotation.Log;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.enums.BusinessType;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;

/**
 * 仓库Controller
 *
 * @author fs
 * @date 2025-03-07
 */
@RestController
@RequestMapping("/system/warehouses")
public class FsWarehousesController extends BaseController
{
    @Autowired
    private IFsWarehousesService fsWarehousesService;

    /**
     * 查询仓库列表
     */
    @PreAuthorize("@ss.hasPermi('system:warehouses:list')")
    @GetMapping("/list")
    public TableDataInfo list(FsWarehouses fsWarehouses)
    {
        startPage();
        List<FsWarehouses> list = fsWarehousesService.selectFsWarehousesList(fsWarehouses);
        return getDataTable(list);
    }

    /**
     * 查询仓库列表-不分页
     */
    @PreAuthorize("@ss.hasPermi('system:warehouses:list')")
    @GetMapping("/listAll")
    public AjaxResult listAll(FsWarehouses fsWarehouses)
    {
        List<FsWarehouses> list = fsWarehousesService.selectFsWarehousesList(fsWarehouses);
        return AjaxResult.success(list);
    }

    /**
     * 导出仓库列表
     */
    @PreAuthorize("@ss.hasPermi('system:warehouses:export')")
    @Log(title = "仓库", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsWarehouses fsWarehouses)
    {
        List<FsWarehouses> list = fsWarehousesService.selectFsWarehousesList(fsWarehouses);
        ExcelUtil<FsWarehouses> util = new ExcelUtil<FsWarehouses>(FsWarehouses.class);
        return util.exportExcel(list, "warehouses");
    }

    /**
     * 获取仓库详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:warehouses:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(fsWarehousesService.selectFsWarehousesById(id));
    }

    /**
     * 新增仓库
     */
    @PreAuthorize("@ss.hasPermi('system:warehouses:add')")
    @Log(title = "仓库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FsWarehouses fsWarehouses)
    {
        return toAjax(fsWarehousesService.insertFsWarehouses(fsWarehouses));
    }

    /**
     * 修改仓库
     */
    @PreAuthorize("@ss.hasPermi('system:warehouses:edit')")
    @Log(title = "仓库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FsWarehouses fsWarehouses)
    {
        return toAjax(fsWarehousesService.updateFsWarehouses(fsWarehouses));
    }

    /**
     * 删除仓库
     */
    @PreAuthorize("@ss.hasPermi('system:warehouses:remove')")
    @Log(title = "仓库", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids)
    {
        return toAjax(fsWarehousesService.deleteFsWarehousesByIds(ids));
    }
}
