package com.shzg.project.worn.controller;

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

import com.shzg.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.shzg.framework.aspectj.lang.annotation.Log;
import com.shzg.framework.aspectj.lang.enums.BusinessType;
import com.shzg.project.worn.domain.WornOutboundBill;
import com.shzg.project.worn.service.IWornOutboundBillService;
import com.shzg.framework.web.controller.BaseController;
import com.shzg.framework.web.domain.AjaxResult;
import com.shzg.common.utils.poi.ExcelUtil;
import com.shzg.framework.web.page.TableDataInfo;

/**
 * 出库单据Controller
 * 
 * @author shzg
 * @date 2026-04-08
 */
@RestController
@RequestMapping("/worn/outboundBill")
public class WornOutboundBillController extends BaseController
{
    @Autowired
    private IWornOutboundBillService wornOutboundBillService;

    /**
     * 查询出库单据列表
     */
    @PreAuthorize("@ss.hasPermi('worn:outboundBill:list')")
    @GetMapping("/list")
    public TableDataInfo list(WornOutboundBill wornOutboundBill)
    {
        startPage();
        if (!SecurityUtils.isAdmin())
        {
            wornOutboundBill.setProjectId(SecurityUtils.getDeptId());
        }
        List<WornOutboundBill> list = wornOutboundBillService.selectWornOutboundBillList(wornOutboundBill);
        return getDataTable(list);
    }

    /**
     * 导出出库单据列表
     */
    @PreAuthorize("@ss.hasPermi('worn:outboundBill:export')")
    @Log(title = "出库单据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WornOutboundBill wornOutboundBill)
    {
        List<WornOutboundBill> list = wornOutboundBillService.selectWornOutboundBillList(wornOutboundBill);
        ExcelUtil<WornOutboundBill> util = new ExcelUtil<WornOutboundBill>(WornOutboundBill.class);
        util.exportExcel(response, list, "出库单据数据");
    }

    /**
     * 获取出库单据详细信息
     */
    @PreAuthorize("@ss.hasPermi('worn:outboundBill:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(wornOutboundBillService.selectWornOutboundBillById(id));
    }

    /**
     * 新增出库单据
     */
    @PreAuthorize("@ss.hasPermi('worn:outboundBill:add')")
    @Log(title = "出库单据", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody WornOutboundBill wornOutboundBill)
    {
        return toAjax(wornOutboundBillService.insertWornOutboundBill(wornOutboundBill));
    }

    /**
     * 修改出库单据
     */
    @PreAuthorize("@ss.hasPermi('worn:outboundBill:edit')")
    @Log(title = "出库单据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WornOutboundBill wornOutboundBill)
    {
        return toAjax(wornOutboundBillService.updateWornOutboundBill(wornOutboundBill));
    }

    /**
     * 删除出库单据
     */
    @PreAuthorize("@ss.hasPermi('worn:outboundBill:remove')")
    @Log(title = "出库单据", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(wornOutboundBillService.deleteWornOutboundBillByIds(ids));
    }
    /**
     * 完成出库
     */
    @PostMapping("/complete")
    public AjaxResult complete(@RequestBody WornOutboundBill wornOutboundBill)
    {
        return toAjax(wornOutboundBillService.completeWornOutboundBill(wornOutboundBill));
    }

}
