package com.ruoyi.goods.controller;

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.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.goods.domain.TCanteenInventory;
import com.ruoyi.goods.service.ITCanteenInventoryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 库存Controller
 * 
 * @author ruoyi
 * @date 2025-04-22
 */
@RestController
@RequestMapping("/goods/inventory")
public class TCanteenInventoryController extends BaseController
{
    @Autowired
    private ITCanteenInventoryService tCanteenInventoryService;

    /**
     * 查询库存列表
     */
    @PreAuthorize("@ss.hasPermi('goods:inventory:list')")
    @GetMapping("/list")
    public TableDataInfo list(TCanteenInventory tCanteenInventory)
    {
        startPage();
        List<TCanteenInventory> list = tCanteenInventoryService.selectTCanteenInventoryList(tCanteenInventory);
        return getDataTable(list);
    }

    /**
     * 导出库存列表
     */
    @PreAuthorize("@ss.hasPermi('goods:inventory:export')")
    @Log(title = "库存", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TCanteenInventory tCanteenInventory)
    {
        List<TCanteenInventory> list = tCanteenInventoryService.selectTCanteenInventoryList(tCanteenInventory);
        ExcelUtil<TCanteenInventory> util = new ExcelUtil<TCanteenInventory>(TCanteenInventory.class);
        util.exportExcel(response, list, "库存数据");
    }

    /**
     * 获取库存详细信息
     */
    @PreAuthorize("@ss.hasPermi('goods:inventory:query')")
    @GetMapping(value = "/{inventoryId}")
    public AjaxResult getInfo(@PathVariable("inventoryId") Long inventoryId)
    {
        return success(tCanteenInventoryService.selectTCanteenInventoryByInventoryId(inventoryId));
    }

    /**
     * 新增库存
     */
    @PreAuthorize("@ss.hasPermi('goods:inventory:add')")
    @Log(title = "库存", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TCanteenInventory tCanteenInventory)
    {
        return toAjax(tCanteenInventoryService.insertTCanteenInventory(tCanteenInventory));
    }

    /**
     * 修改库存
     */
    @PreAuthorize("@ss.hasPermi('goods:inventory:edit')")
    @Log(title = "库存", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TCanteenInventory tCanteenInventory)
    {
        return toAjax(tCanteenInventoryService.updateTCanteenInventory(tCanteenInventory));
    }

    /**
     * 删除库存
     */
    @PreAuthorize("@ss.hasPermi('goods:inventory:remove')")
    @Log(title = "库存", businessType = BusinessType.DELETE)
	@DeleteMapping("/{inventoryIds}")
    public AjaxResult remove(@PathVariable Long[] inventoryIds)
    {
        return toAjax(tCanteenInventoryService.deleteTCanteenInventoryByInventoryIds(inventoryIds));
    }
}
