package com.hw.wms.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.hw.wms.domain.WmsBaseCategory;
import com.hw.wms.service.IWmsBaseCategoryService;
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.wms.domain.WmsBaseWarehouse;
import com.hw.wms.service.IWmsBaseWarehouseService;
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 xs
 * @date 2023-12-20
 */
@RestController
@RequestMapping("/wmswarehouse")
public class WmsBaseWarehouseController extends BaseController
{
    @Autowired
    private IWmsBaseWarehouseService wmsBaseWarehouseService;

    @Autowired
    private IWmsBaseCategoryService wmsBaseCategoryService;

    /**
     * 查询仓库列表
     */
    @RequiresPermissions("wms:wmswarehouse:list")
    @GetMapping("/list")
    public TableDataInfo list(WmsBaseWarehouse wmsBaseWarehouse)
    {
        startPage();
        List<WmsBaseWarehouse> list = wmsBaseWarehouseService.selectWmsBaseWarehouseJoinList(wmsBaseWarehouse);
        return getDataTable(list);
    }

    /**
     * 导出仓库列表
     */
    @RequiresPermissions("wms:wmswarehouse:export")
    @Log(title = "仓库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WmsBaseWarehouse wmsBaseWarehouse)
    {
        List<WmsBaseWarehouse> list = wmsBaseWarehouseService.selectWmsBaseWarehouseJoinList(wmsBaseWarehouse);
        ExcelUtil<WmsBaseWarehouse> util = new ExcelUtil<WmsBaseWarehouse>(WmsBaseWarehouse.class);
        util.exportExcel(response, list, "仓库数据");
    }

    /**
     * 获取仓库详细信息
     */
    @RequiresPermissions("wms:wmswarehouse:query")
    @GetMapping(value = "/{warehouseId}")
    public AjaxResult getInfo(@PathVariable("warehouseId") Long warehouseId)
    {
        return success(wmsBaseWarehouseService.selectWmsBaseWarehouseByWarehouseId(warehouseId));
    }

    /**
     * 新增仓库
     */
    @RequiresPermissions("wms:wmswarehouse:add")
    @Log(title = "仓库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WmsBaseWarehouse wmsBaseWarehouse)
    {
        return toAjax(wmsBaseWarehouseService.insertWmsBaseWarehouse(wmsBaseWarehouse));
    }

    /**
     * 修改仓库
     */
    @RequiresPermissions("wms:wmswarehouse:edit")
    @Log(title = "仓库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WmsBaseWarehouse wmsBaseWarehouse)
    {
        return toAjax(wmsBaseWarehouseService.updateWmsBaseWarehouse(wmsBaseWarehouse));
    }

    /**
     * 删除仓库
     */
    @RequiresPermissions("wms:wmswarehouse:remove")
    @Log(title = "仓库", businessType = BusinessType.DELETE)
	@DeleteMapping("/{warehouseIds}")
    public AjaxResult remove(@PathVariable Long[] warehouseIds)
    {
        return toAjax(wmsBaseWarehouseService.deleteWmsBaseWarehouseByWarehouseIds(warehouseIds));
    }


    /**
     * 查询仓库类别列表，提供给添加、修改、查询仓库等使用
     */
    @RequiresPermissions("wms:wmswarehouse:list")
    @GetMapping("/getWarehouseCategories")
    public AjaxResult getWarehouseCategories(WmsBaseCategory wmsBaseCategory)
    {
        List<WmsBaseCategory> list = wmsBaseCategoryService.selectWmsBaseCategoryList(wmsBaseCategory);
        return success(list);
    }

}
