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.BaseArea;
import com.op.wms.service.IBaseAreaService;
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("/area")
public class BaseAreaController extends BaseController {
	@Autowired
	private IBaseAreaService baseAreaService;

	/**
	 * 查询库区列表
	 */
	@RequiresPermissions("wms:area:list")
	@GetMapping("/list")
	public TableDataInfo list(BaseArea baseArea) {
		startPage();
		List<BaseArea> list = baseAreaService.selectBaseAreaList(baseArea);
		return getDataTable(list);
	}

	/**
	 * 导出库区列表
	 */
	@RequiresPermissions("wms:area:export")
	@Log(title = "库区", businessType = BusinessType.EXPORT)
	@PostMapping("/export")
	public void export(HttpServletResponse response, BaseArea baseArea) {
		List<BaseArea> list = baseAreaService.selectBaseAreaList(baseArea);
		ExcelUtil<BaseArea> util = new ExcelUtil<BaseArea>(BaseArea.class);
		util.exportExcel(response, list, "库区数据");
	}

	/**
	 * 获取库区详细信息
	 */
	@RequiresPermissions("wms:area:query")
	@GetMapping(value = "/{areaId}")
	public AjaxResult getInfo(@PathVariable("areaId") String areaId) {
		return success(baseAreaService.selectBaseAreaByAreaId(areaId));
	}

	/**
	 * 新增库区
	 */
	@RequiresPermissions("wms:area:add")
	@Log(title = "库区", businessType = BusinessType.INSERT)
	@PostMapping
	public AjaxResult add(@RequestBody BaseArea baseArea) {
		return toAjax(baseAreaService.insertBaseArea(baseArea));
	}

	/**
	 * 修改库区
	 */
	@RequiresPermissions("wms:area:edit")
	@Log(title = "库区", businessType = BusinessType.UPDATE)
	@PutMapping
	public AjaxResult edit(@RequestBody BaseArea baseArea) {
		return toAjax(baseAreaService.updateBaseArea(baseArea));
	}

	/**
	 * 删除库区
	 */
	@RequiresPermissions("wms:area:remove")
	@Log(title = "库区", businessType = BusinessType.DELETE)
	@DeleteMapping("/{areaIds}")
	public AjaxResult remove(@PathVariable String[] areaIds) {
		return toAjax(baseAreaService.deleteBaseAreaByAreaIds(areaIds));
	}
}
