package com.fs.oms.controller;

import java.util.List;

import com.fs.common.core.domain.R;
import com.fs.oms.domain.OmsWarehouse;
import com.fs.oms.vo.OmsSupplierExportVO;
import com.fs.oms.vo.OmsSupplierListVO;
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.OmsSupplier;
import com.fs.oms.service.IOmsSupplierService;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;

/**
 * 供应商管理Controller
 *
 * @author fs
 * @date 2023-06-15
 */
@RestController
@RequestMapping("/oms/supplier")
public class OmsSupplierController extends BaseController
{
    @Autowired
    private IOmsSupplierService omsSupplierService;

    /**
     * 查询供应商管理列表
     */
    @PreAuthorize("@ss.hasPermi('oms:supplier:list')")
    @GetMapping("/list")
    public TableDataInfo list(OmsSupplier omsSupplier)
    {
        startPage();
        List<OmsSupplierListVO> list = omsSupplierService.selectOmsSupplierList(omsSupplier);
        return getDataTable(list);
    }

    /**
     * 导出供应商管理列表
     */
    @PreAuthorize("@ss.hasPermi('oms:supplier:export')")
    @Log(title = "供应商管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(OmsSupplier omsSupplier)
    {
        List<OmsSupplierExportVO> list = omsSupplierService.selectSupplierExport(omsSupplier);
        ExcelUtil<OmsSupplierExportVO> util = new ExcelUtil<OmsSupplierExportVO>(OmsSupplierExportVO.class);
        return util.exportExcel(list, "supplier");
    }

    /**
     * 获取供应商管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('oms:supplier:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(omsSupplierService.selectOmsSupplierById(id));
    }

    /**
     * 新增供应商管理
     */
    @PreAuthorize("@ss.hasPermi('oms:supplier:add')")
    @Log(title = "供应商管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OmsSupplier omsSupplier)
    {
        return toAjax(omsSupplierService.insertOmsSupplier(omsSupplier));
    }

    /**
     * 修改供应商管理
     */
    @PreAuthorize("@ss.hasPermi('oms:supplier:edit')")
    @Log(title = "供应商管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OmsSupplier omsSupplier)
    {
        return toAjax(omsSupplierService.updateOmsSupplier(omsSupplier));
    }

    /**
     * 删除供应商管理
     */
    @PreAuthorize("@ss.hasPermi('oms:supplier:remove')")
    @Log(title = "供应商管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(omsSupplierService.deleteOmsSupplierByIds(ids));
    }
    @GetMapping("byStatus")
    public R getInfo(OmsSupplier omsSupplier)
    {

        List<OmsSupplier> list = omsSupplierService.selectOmsSupplierByStatus(omsSupplier);
        return R.ok().put("data",list);
    }

}
