package com.fs.oms.controller;

import java.util.List;

import com.fs.common.core.domain.R;
import com.fs.oms.domain.OmsPurchaseApply;
import com.fs.oms.vo.OmsPurchaseProductVO;
import com.fs.oms.vo.OmsWarehouseVO;
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.OmsWarehouse;
import com.fs.oms.service.IOmsWarehouseService;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;

/**
 * 仓库Controller
 *
 * @author fs
 * @date 2023-05-24
 */
@RestController
@RequestMapping("/oms/warehouse")
public class OmsWarehouseController extends BaseController
{
    @Autowired
    private IOmsWarehouseService omsWarehouseService;

    /**
     * 查询仓库列表
     */
    @PreAuthorize("@ss.hasPermi('oms:warehouse:list')")
    @GetMapping("/list")
    public TableDataInfo list(OmsWarehouse omsWarehouse)
    {
        startPage();
        List<OmsWarehouseVO> list = omsWarehouseService.selectOmsStoreListVO(omsWarehouse);
        return getDataTable(list);
    }


    /**
     * 查询渠道仓/逻辑仓仓库列表
     */
//    @PreAuthorize("@ss.hasPermi('oms:warehouse:list')")
//    @GetMapping("/wlist")
//    public TableDataInfo wlist(OmsWarehouse omsWarehouse)
//    {
//        startPage();
//        List<OmsWarehouseVO> list = omsWarehouseService.selectOmsStoreList1VO(omsWarehouse);
//        return getDataTable(list);
//    }

    /**
     * 导出仓库列表
     */
    @PreAuthorize("@ss.hasPermi('oms:warehouse:export')")
    @Log(title = "仓库", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(OmsWarehouse omsWarehouse)
    {
        List<OmsWarehouse> list = omsWarehouseService.selectOmsWarehouseList(omsWarehouse);
        ExcelUtil<OmsWarehouse> util = new ExcelUtil<OmsWarehouse>(OmsWarehouse.class);
        return util.exportExcel(list, "warehouse");
    }

    /**
     * 获取仓库详细信息
     */
    @PreAuthorize("@ss.hasPermi('oms:warehouse:query')")
    @GetMapping(value = "/{warehouseId}")
    public AjaxResult getInfo(@PathVariable("warehouseId") Long warehouseId)
    {
        return AjaxResult.success(omsWarehouseService.selectOmsWarehouseById(warehouseId));
    }

    /**
     * 新增仓库
     */
    @PreAuthorize("@ss.hasPermi('oms:warehouse:add')")
    @Log(title = "仓库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OmsWarehouse omsWarehouse)
    {
        return toAjax(omsWarehouseService.insertOmsWarehouse(omsWarehouse));
    }

    /**
     * 修改仓库
     */
    @PreAuthorize("@ss.hasPermi('oms:warehouse:edit')")
    @Log(title = "仓库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OmsWarehouse omsWarehouse)
    {
        return toAjax(omsWarehouseService.updateOmsWarehouse(omsWarehouse));
    }

    /**
     * 删除仓库
     */
    @PreAuthorize("@ss.hasPermi('oms:warehouse:remove')")
    @Log(title = "仓库", businessType = BusinessType.DELETE)
	@DeleteMapping("/{warehouseIds}")
    public AjaxResult remove(@PathVariable Long[] warehouseIds)
    {
        return toAjax(omsWarehouseService.deleteOmsWarehouseByIds(warehouseIds));
    }

    @GetMapping("name")
    public R getInfo(OmsWarehouse omsWarehouse)
    {
        List<OmsWarehouse> list = omsWarehouseService.selectOmsWarehouseName(omsWarehouse);
        return R.ok().put("data",list);
    }
}
