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.MesSaleOrder;
import com.hw.mes.service.IMesSaleOrderService;
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("/saleOrder")
public class MesSaleOrderController extends BaseController
{
    @Autowired
    private IMesSaleOrderService mesSaleOrderService;

    /**
     * 查询销售订单信息列表
     */
    @RequiresPermissions("mes:saleOrder:list")
    @GetMapping("/list")
    public TableDataInfo list(MesSaleOrder mesSaleOrder)
    {
        startPage();
        List<MesSaleOrder> list = mesSaleOrderService.selectMesSaleOrderList(mesSaleOrder);
        return getDataTable(list);
    }

    /**
     * 导出销售订单信息列表
     */
    @RequiresPermissions("mes:saleOrder:export")
    @Log(title = "销售订单信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MesSaleOrder mesSaleOrder)
    {
        List<MesSaleOrder> list = mesSaleOrderService.selectMesSaleOrderList(mesSaleOrder);
        ExcelUtil<MesSaleOrder> util = new ExcelUtil<MesSaleOrder>(MesSaleOrder.class);
        util.exportExcel(response, list, "销售订单信息数据");
    }

    /**
     * 获取销售订单信息详细信息
     */
    @RequiresPermissions("mes:saleOrder:query")
    @GetMapping(value = "/{saleOrderId}")
    public AjaxResult getInfo(@PathVariable("saleOrderId") Long saleOrderId)
    {
        return success(mesSaleOrderService.selectMesSaleOrderBySaleOrderId(saleOrderId));
    }

    /**
     * 新增销售订单信息
     */
    @RequiresPermissions("mes:saleOrder:add")
    @Log(title = "销售订单信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MesSaleOrder mesSaleOrder)
    {
        return toAjax(mesSaleOrderService.insertMesSaleOrder(mesSaleOrder));
    }

    /**
     * 修改销售订单信息
     */
    @RequiresPermissions("mes:saleOrder:edit")
    @Log(title = "销售订单信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MesSaleOrder mesSaleOrder)
    {
        return toAjax(mesSaleOrderService.updateMesSaleOrder(mesSaleOrder));
    }

    /**
     * 删除销售订单信息
     */
    @RequiresPermissions("mes:saleOrder:remove")
    @Log(title = "销售订单信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{saleOrderIds}")
    public AjaxResult remove(@PathVariable Long[] saleOrderIds)
    {
        return toAjax(mesSaleOrderService.deleteMesSaleOrderBySaleOrderIds(saleOrderIds));
    }
}
