package com.fs.oms.controller;

import java.util.List;

import com.fs.common.utils.bean.BeanUtils;
import com.fs.core.security.SecurityUtils;
import com.fs.oms.dto.OmsPurchaseOrderDTO;
import com.fs.oms.vo.OmsPurchaseOrderVO;
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.fs.common.annotation.Log;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.enums.BusinessType;
import com.fs.oms.domain.OmsPurchaseOrder;
import com.fs.oms.service.IOmsPurchaseOrderService;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;

/**
 * oms采购单Controller
 *
 * @author oms
 * @date 2023-07-03
 */
@RestController
@RequestMapping("/oms/purchaseOrder")
public class OmsPurchaseOrderController extends BaseController
{
    @Autowired
    private IOmsPurchaseOrderService omsPurchaseOrderService;

    /**
     * 查询oms采购单列表
     */
    @PreAuthorize("@ss.hasPermi('oms:purchaseOrder:list')")
    @GetMapping("/list")
    public TableDataInfo list(OmsPurchaseOrderVO omsPurchaseOrderVO)
    {
        startPage();
        List<OmsPurchaseOrderVO> list = omsPurchaseOrderService.selectOmsPurchaseOrderList(omsPurchaseOrderVO);
        return getDataTable(list);
    }

//    /**
//     * 导出oms采购单列表
//     */
//    @PreAuthorize("@ss.hasPermi('oms:purchaseOrder:export')")
//    @Log(title = "oms采购单", businessType = BusinessType.EXPORT)
//    @GetMapping("/export")
//    public AjaxResult export(OmsPurchaseOrder omsPurchaseOrder)
//    {
//        List<OmsPurchaseOrder> list = omsPurchaseOrderService.selectOmsPurchaseOrderList(omsPurchaseOrder);
//        ExcelUtil<OmsPurchaseOrder> util = new ExcelUtil<OmsPurchaseOrder>(OmsPurchaseOrder.class);
//        return util.exportExcel(list, "purchaseOrder");
//    }

    /**
     * 获取oms采购单详细信息
     */
    @PreAuthorize("@ss.hasPermi('oms:purchaseOrder:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(omsPurchaseOrderService.selectOmsPurchaseOrderById(id));
    }

    /**
     * 新增oms采购单
     */
    @PreAuthorize("@ss.hasPermi('oms:purchaseOrder:add')")
    @Log(title = "oms采购单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OmsPurchaseOrderDTO omsPurchaseOrderDTO)
    {
        OmsPurchaseOrder omsPurchaseOrder = new OmsPurchaseOrder();
        try {
            // 将源实体的属性复制到目标实体
            BeanUtils.copyBeanProp(omsPurchaseOrder,omsPurchaseOrderDTO);
        } catch (Exception e) {
            // 处理异常情况
            e.printStackTrace();
        }
        omsPurchaseOrder.setCreateUserId(SecurityUtils.getLoginUser().getUser().getUserId());
        return toAjax(omsPurchaseOrderService.insertOmsPurchaseOrder(omsPurchaseOrder));
    }

    /**
     * 修改oms采购单
     */
    @PreAuthorize("@ss.hasPermi('oms:purchaseOrder:edit')")
    @Log(title = "oms采购单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OmsPurchaseOrder omsPurchaseOrder)
    {
        return toAjax(omsPurchaseOrderService.updateOmsPurchaseOrder(omsPurchaseOrder));
    }

    /**
     * 删除oms采购单
     */
    @PreAuthorize("@ss.hasPermi('oms:purchaseOrder:remove')")
    @Log(title = "oms采购单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(omsPurchaseOrderService.deleteOmsPurchaseOrderByIds(ids));
    }
}
