package com.hw.wms.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
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.WmsBaseCategory;
import com.hw.wms.service.IWmsBaseCategoryService;
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("/wmscategory")
public class WmsBaseCategoryController extends BaseController
{
    @Autowired
    private IWmsBaseCategoryService wmsBaseCategoryService;

    /**
     * 查询仓库类别列表
     */
    @RequiresPermissions("wms:wmscategory:list")
    @GetMapping("/list")
    public TableDataInfo list(WmsBaseCategory wmsBaseCategory)
    {
        startPage();
        List<WmsBaseCategory> list = wmsBaseCategoryService.selectWmsBaseCategoryList(wmsBaseCategory);
        return getDataTable(list);
    }

    /**
     * 导出仓库类别列表
     */
    @RequiresPermissions("wms:wmscategory:export")
    @Log(title = "仓库类别", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WmsBaseCategory wmsBaseCategory)
    {
        List<WmsBaseCategory> list = wmsBaseCategoryService.selectWmsBaseCategoryList(wmsBaseCategory);
        ExcelUtil<WmsBaseCategory> util = new ExcelUtil<WmsBaseCategory>(WmsBaseCategory.class);
        util.exportExcel(response, list, "仓库类别数据");
    }

    /**
     * 获取仓库类别详细信息
     */
    @RequiresPermissions("wms:wmscategory:query")
    @GetMapping(value = "/{categoryId}")
    public AjaxResult getInfo(@PathVariable("categoryId") Long categoryId)
    {
        return success(wmsBaseCategoryService.selectWmsBaseCategoryByCategoryId(categoryId));
    }

    /**
     * 新增仓库类别
     */
    @RequiresPermissions("wms:wmscategory:add")
    @Log(title = "仓库类别", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WmsBaseCategory wmsBaseCategory)
    {
        return toAjax(wmsBaseCategoryService.insertWmsBaseCategory(wmsBaseCategory));
    }

    /**
     * 修改仓库类别
     */
    @RequiresPermissions("wms:wmscategory:edit")
    @Log(title = "仓库类别", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WmsBaseCategory wmsBaseCategory)
    {
        return toAjax(wmsBaseCategoryService.updateWmsBaseCategory(wmsBaseCategory));
    }

    /**
     * 删除仓库类别
     */
    @RequiresPermissions("wms:wmscategory:remove")
    @Log(title = "仓库类别", businessType = BusinessType.DELETE)
	@DeleteMapping("/{categoryIds}")
    public AjaxResult remove(@PathVariable Long[] categoryIds)
    {
        return toAjax(wmsBaseCategoryService.deleteWmsBaseCategoryByCategoryIds(categoryIds));
    }
}
