package com.op.wms.controller;

import java.util.List;
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.op.common.log.annotation.Log;
import com.op.common.log.enums.BusinessType;
import com.op.common.security.annotation.RequiresPermissions;
import com.op.wms.domain.BaseWarehouse;
import com.op.wms.service.IBaseWarehouseService;
import com.op.common.core.web.controller.BaseController;
import com.op.common.core.web.domain.AjaxResult;
import com.op.common.core.utils.poi.ExcelUtil;
import com.op.common.core.web.page.TableDataInfo;

/**
 * 仓库管理Controller
 * 
 * @author Open Platform
 * @date 2023-07-04
 */
@RestController
@RequestMapping("/warehouse")
public class BaseWarehouseController extends BaseController {
	@Autowired
	private IBaseWarehouseService baseWarehouseService;

	/**
	 * 查询仓库管理列表
	 */
	@RequiresPermissions("wms:warehouse:list")
	@GetMapping("/list")
	public TableDataInfo list(BaseWarehouse baseWarehouse) {
		startPage();
		List<BaseWarehouse> list = baseWarehouseService.selectBaseWarehouseList(baseWarehouse);
		return getDataTable(list);
	}

	/**
	 * 导出仓库管理列表
	 */
	@RequiresPermissions("wms:warehouse:export")
	@Log(title = "仓库管理", businessType = BusinessType.EXPORT)
	@PostMapping("/export")
	public void export(HttpServletResponse response, BaseWarehouse baseWarehouse) {
		List<BaseWarehouse> list = baseWarehouseService.selectBaseWarehouseList(baseWarehouse);
		ExcelUtil<BaseWarehouse> util = new ExcelUtil<BaseWarehouse>(BaseWarehouse.class);
		util.exportExcel(response, list, "仓库管理数据");
	}

	/**
	 * 获取仓库管理详细信息
	 */
	@RequiresPermissions("wms:warehouse:query")
	@GetMapping(value = "/{warehouseId}")
	public AjaxResult getInfo(@PathVariable("warehouseId") String warehouseId) {
		return success(baseWarehouseService.selectBaseWarehouseByWarehouseId(warehouseId));
	}

	/**
	 * 新增仓库管理
	 */
	@RequiresPermissions("wms:warehouse:add")
	@Log(title = "仓库管理", businessType = BusinessType.INSERT)
	@PostMapping
	public AjaxResult add(@RequestBody BaseWarehouse baseWarehouse) {
		return toAjax(baseWarehouseService.insertBaseWarehouse(baseWarehouse));
	}

	/**
	 * 修改仓库管理
	 */
	@RequiresPermissions("wms:warehouse:edit")
	@Log(title = "仓库管理", businessType = BusinessType.UPDATE)
	@PutMapping
	public AjaxResult edit(@RequestBody BaseWarehouse baseWarehouse) {
		return toAjax(baseWarehouseService.updateBaseWarehouse(baseWarehouse));
	}

	/**
	 * 删除仓库管理
	 */
	@RequiresPermissions("wms:warehouse:remove")
	@Log(title = "仓库管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{warehouseIds}")
	public AjaxResult remove(@PathVariable String[] warehouseIds) {
		return toAjax(baseWarehouseService.deleteBaseWarehouseByWarehouseIds(warehouseIds));
	}
}
