package com.hw.mes.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
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.hw.common.log.annotation.Log;
import com.hw.common.log.enums.BusinessType;
import com.hw.common.security.annotation.RequiresPermissions;
import com.hw.mes.domain.MesPurchaseOrder;
import com.hw.mes.service.IMesPurchaseOrderService;
import com.hw.common.core.web.controller.BaseController;
import com.hw.common.core.web.domain.AjaxResult;
import com.hw.common.core.utils.poi.ExcelUtil;
import com.hw.common.core.web.page.TableDataInfo;

/**
 * 采购订单信息Controller
 * 
 * @author Yinq
 * @date 2024-02-19
 */
@RestController
@RequestMapping("/purchaseOrder")
public class MesPurchaseOrderController extends BaseController
{
    @Autowired
    private IMesPurchaseOrderService mesPurchaseOrderService;

    /**
     * 查询采购订单信息列表
     */
    @RequiresPermissions("mes:purchaseOrder:list")
    @GetMapping("/list")
    public TableDataInfo list(MesPurchaseOrder mesPurchaseOrder)
    {
        startPage();
        List<MesPurchaseOrder> list = mesPurchaseOrderService.selectMesPurchaseOrderList(mesPurchaseOrder);
        return getDataTable(list);
    }

    /**
     * 导出采购订单信息列表
     */
    @RequiresPermissions("mes:purchaseOrder:export")
    @Log(title = "采购订单信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MesPurchaseOrder mesPurchaseOrder)
    {
        List<MesPurchaseOrder> list = mesPurchaseOrderService.selectMesPurchaseOrderList(mesPurchaseOrder);
        ExcelUtil<MesPurchaseOrder> util = new ExcelUtil<MesPurchaseOrder>(MesPurchaseOrder.class);
        util.exportExcel(response, list, "采购订单信息数据");
    }

    /**
     * 获取采购订单信息详细信息
     */
    @RequiresPermissions("mes:purchaseOrder:query")
    @GetMapping(value = "/{purchaseOrderId}")
    public AjaxResult getInfo(@PathVariable("purchaseOrderId") Long purchaseOrderId)
    {
        return success(mesPurchaseOrderService.selectMesPurchaseOrderByPurchaseOrderId(purchaseOrderId));
    }

    /**
     * 新增采购订单信息
     */
    @RequiresPermissions("mes:purchaseOrder:add")
    @Log(title = "采购订单信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MesPurchaseOrder mesPurchaseOrder)
    {
        return toAjax(mesPurchaseOrderService.insertMesPurchaseOrder(mesPurchaseOrder));
    }

    /**
     * 修改采购订单信息
     */
    @RequiresPermissions("mes:purchaseOrder:edit")
    @Log(title = "采购订单信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MesPurchaseOrder mesPurchaseOrder)
    {
        return toAjax(mesPurchaseOrderService.updateMesPurchaseOrder(mesPurchaseOrder));
    }

    /**
     * 删除采购订单信息
     */
    @RequiresPermissions("mes:purchaseOrder:remove")
    @Log(title = "采购订单信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{purchaseOrderIds}")
    public AjaxResult remove(@PathVariable Long[] purchaseOrderIds)
    {
        return toAjax(mesPurchaseOrderService.deleteMesPurchaseOrderByPurchaseOrderIds(purchaseOrderIds));
    }
}
