package com.ruoyi.inventory.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.inventory.domain.OutboundOrders;
import com.ruoyi.inventory.service.IOutboundOrdersService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 出库单主Controller
 * 
 * @author ruoyi
 * @date 2025-12-03
 */
@RestController
@RequestMapping("/inventory/orders")
public class OutboundOrdersController extends BaseController
{
    @Autowired
    private IOutboundOrdersService outboundOrdersService;

    /**
     * 查询出库单主列表
     */
    @PreAuthorize("@ss.hasPermi('inventory:orders:list')")
    @GetMapping("/list")
    public TableDataInfo list(OutboundOrders outboundOrders)
    {
        startPage();
        List<OutboundOrders> list = outboundOrdersService.selectOutboundOrdersList(outboundOrders);
        return getDataTable(list);
    }

    /**
     * 导出出库单主列表
     */
    @PreAuthorize("@ss.hasPermi('inventory:orders:export')")
    @Log(title = "出库单主", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OutboundOrders outboundOrders)
    {
        List<OutboundOrders> list = outboundOrdersService.selectOutboundOrdersList(outboundOrders);
        ExcelUtil<OutboundOrders> util = new ExcelUtil<OutboundOrders>(OutboundOrders.class);
        util.exportExcel(response, list, "出库单主数据");
    }

    /**
     * 获取出库单主详细信息
     */
    @PreAuthorize("@ss.hasPermi('inventory:orders:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(outboundOrdersService.selectOutboundOrdersById(id));
    }

    /**
     * 新增出库单主
     */
    @PreAuthorize("@ss.hasPermi('inventory:orders:add')")
    @Log(title = "出库单主", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OutboundOrders outboundOrders)
    {
        return toAjax(outboundOrdersService.insertOutboundOrders(outboundOrders));
    }

    /**
     * 修改出库单主
     */
    @PreAuthorize("@ss.hasPermi('inventory:orders:edit')")
    @Log(title = "出库单主", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OutboundOrders outboundOrders)
    {
        return toAjax(outboundOrdersService.updateOutboundOrders(outboundOrders));
    }

    /**
     * 删除出库单主
     */
    @PreAuthorize("@ss.hasPermi('inventory:orders:remove')")
    @Log(title = "出库单主", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(outboundOrdersService.deleteOutboundOrdersByIds(ids));
    }
}
