package com.fs.oms.controller;

import java.util.ArrayList;
import java.util.List;

import com.fs.common.core.domain.R;
import com.fs.oms.vo.OmsSupplierGoodsListVO;
import com.fs.oms.vo.OmsSupplierProductVO;
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.OmsSupplierGoods;
import com.fs.oms.service.IOmsSupplierGoodsService;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;

/**
 * 供应商商品Controller
 *
 * @author fs
 * @date 2023-06-14
 */
@RestController
@RequestMapping("/oms/supplierProduct")
public class OmsSupplierGoodsController extends BaseController
{
    @Autowired
    private IOmsSupplierGoodsService omsSupplierGoodsService;

    /**
     * 查询供应商商品列表
     */
    @PreAuthorize("@ss.hasPermi('oms:supplierProduct:list')")
    @GetMapping("/list")
    public TableDataInfo list(OmsSupplierGoods omsSupplierGoods)
    {
        startPage();
        List<OmsSupplierGoodsListVO> list = omsSupplierGoodsService.selectOmsSupplierListVO(omsSupplierGoods);
        return getDataTable(list);
    }

    /**
     * 导出供应商商品列表
     */
//    @PreAuthorize("@ss.hasPermi('oms:supplierProduct:export')")
//    @Log(title = "供应商商品", businessType = BusinessType.EXPORT)
//    @GetMapping("/export")
//    public AjaxResult export(OmsSupplierGoods omsSupplierGoods)
//    {
//        List<OmsSupplierGoods> list = omsSupplierGoodsService.selectOmsSupplierGoodsList(omsSupplierGoods);
//        ExcelUtil<OmsSupplierGoods> util = new ExcelUtil<OmsSupplierGoods>(OmsSupplierGoods.class);
//        return util.exportExcel(list, "supplierProduct");
//    }

    /**
     * 获取供应商商品详细信息
     */
    @PreAuthorize("@ss.hasPermi('oms:supplierProduct:query')")
    @GetMapping(value = "/{id}")
    public R getInfo(@PathVariable("id") Long id)
    {
        OmsSupplierGoods omsSupplierGoods = omsSupplierGoodsService.selectOmsSupplierGoodsById(id);
        List <OmsSupplierGoods> list = new ArrayList<>();
        list.add(omsSupplierGoods);
        return R.ok().put("data",omsSupplierGoods).put("selectProucts",list);

    }

    /**
     * 新增供应商商品
     */
    @PreAuthorize("@ss.hasPermi('oms:supplierProduct:add')")
    @Log(title = "供应商商品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OmsSupplierGoods omsSupplierGoods)
    {
        return toAjax(omsSupplierGoodsService.insertOmsSupplierGoods(omsSupplierGoods));
    }

    /**
     * 修改供应商商品
     */
    @PreAuthorize("@ss.hasPermi('oms:supplierProduct:edit')")
    @Log(title = "供应商商品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OmsSupplierGoods omsSupplierGoods)
    {
        return toAjax(omsSupplierGoodsService.updateOmsSupplierGoods(omsSupplierGoods));
    }

    /**
     * 删除供应商商品
     */
    @PreAuthorize("@ss.hasPermi('oms:supplierProduct:remove')")
    @Log(title = "供应商商品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(omsSupplierGoodsService.deleteOmsSupplierGoodsByIds(ids));
    }


    /**
     * 添加商品列表
     */
    @GetMapping("productList")
    public TableDataInfo productList(OmsSupplierProductVO omsSupplierProductVO)
    {
        startPage();
        List<OmsSupplierProductVO> list = omsSupplierGoodsService.selectOmsProductList(omsSupplierProductVO);
        return getDataTable(list);
    }
}
