package com.shzg.project.worn.controller;

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

import com.shzg.project.worn.domain.dto.WornOutboundUpdateDTO;
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.shzg.framework.aspectj.lang.annotation.Log;
import com.shzg.framework.aspectj.lang.enums.BusinessType;
import com.shzg.project.worn.domain.WornOutboundItem;
import com.shzg.project.worn.service.IWornOutboundItemService;
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/outboundItem")
public class WornOutboundItemController extends BaseController
{
    @Autowired
    private IWornOutboundItemService wornOutboundItemService;

    /**
     * 查询出库单明细列表
     */
    @PreAuthorize("@ss.hasPermi('worn:outboundItem:list')")
    @GetMapping("/list")
    public TableDataInfo list(WornOutboundItem wornOutboundItem)
    {
        startPage();
        List<WornOutboundItem> list = wornOutboundItemService.selectWornOutboundItemList(wornOutboundItem);
        return getDataTable(list);
    }

    /**
     * 导出出库单明细列表
     */
    @PreAuthorize("@ss.hasPermi('worn:outboundItem:export')")
    @Log(title = "出库单明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WornOutboundItem wornOutboundItem)
    {
        List<WornOutboundItem> list = wornOutboundItemService.selectWornOutboundItemList(wornOutboundItem);
        ExcelUtil<WornOutboundItem> util = new ExcelUtil<WornOutboundItem>(WornOutboundItem.class);
        util.exportExcel(response, list, "出库单明细数据");
    }

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

    /**
     * 新增出库单明细
     */
    @PreAuthorize("@ss.hasPermi('worn:outboundItem:add')")
    @Log(title = "出库单明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WornOutboundItem wornOutboundItem)
    {
        return toAjax(wornOutboundItemService.insertWornOutboundItem(wornOutboundItem));
    }

    /**
     * 修改出库单明细
     */
    @PreAuthorize("@ss.hasPermi('worn:outboundItem:edit')")
    @Log(title = "出库单明细", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    public AjaxResult edit(@RequestBody WornOutboundUpdateDTO dto)
    {
        return toAjax(wornOutboundItemService.updateWornOutboundItem(dto));
    }

    /**
     * 删除出库单明细
     */
    @PreAuthorize("@ss.hasPermi('worn:outboundItem:remove')")
    @Log(title = "出库单明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(wornOutboundItemService.deleteWornOutboundItemByIds(ids));
    }
    /**
     * 根据出库单号查询出库单明细
     */
    @PostMapping("/getByBillNo")
    public AjaxResult getByBillNo(@RequestBody WornOutboundItem wornOutboundItem)
    {
        WornOutboundUpdateDTO dto = wornOutboundItemService.selectWornOutboundItemByBillNo(wornOutboundItem);
        return AjaxResult.success(dto);
    }
}
