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.BaseEquipment;
import com.op.wms.service.IBaseEquipmentService;
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-20
 */
@RestController
@RequestMapping("/equipment")
public class BaseEquipmentController extends BaseController {
	@Autowired
	private IBaseEquipmentService baseEquipmentService;

	/**
	 * 查询设备管理列表
	 */
	@RequiresPermissions("wms:equipment:list")
	@GetMapping("/list")
	public TableDataInfo list(BaseEquipment baseEquipment) {
		startPage();
		List<BaseEquipment> list = baseEquipmentService.selectBaseEquipmentList(baseEquipment);
		return getDataTable(list);
	}

	/**
	 * 导出设备管理列表
	 */
	@RequiresPermissions("wms:equipment:export")
	@Log(title = "设备管理", businessType = BusinessType.EXPORT)
	@PostMapping("/export")
	public void export(HttpServletResponse response, BaseEquipment baseEquipment) {
		List<BaseEquipment> list = baseEquipmentService.selectBaseEquipmentList(baseEquipment);
		ExcelUtil<BaseEquipment> util = new ExcelUtil<BaseEquipment>(BaseEquipment.class);
		util.exportExcel(response, list, "设备管理数据");
	}

	/**
	 * 获取设备管理详细信息
	 */
	@RequiresPermissions("wms:equipment:query")
	@GetMapping(value = "/{equipmentId}")
	public AjaxResult getInfo(@PathVariable("equipmentId") Long equipmentId) {
		return success(baseEquipmentService.selectBaseEquipmentByEquipmentId(equipmentId));
	}

	/**
	 * 新增设备管理
	 */
	@RequiresPermissions("wms:equipment:add")
	@Log(title = "设备管理", businessType = BusinessType.INSERT)
	@PostMapping
	public AjaxResult add(@RequestBody BaseEquipment baseEquipment) {
		return toAjax(baseEquipmentService.insertBaseEquipment(baseEquipment));
	}

	/**
	 * 修改设备管理
	 */
	@RequiresPermissions("wms:equipment:edit")
	@Log(title = "设备管理", businessType = BusinessType.UPDATE)
	@PutMapping
	public AjaxResult edit(@RequestBody BaseEquipment baseEquipment) {
		return toAjax(baseEquipmentService.updateBaseEquipment(baseEquipment));
	}

	/**
	 * 删除设备管理
	 */
	@RequiresPermissions("wms:equipment:remove")
	@Log(title = "设备管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{equipmentIds}")
	public AjaxResult remove(@PathVariable Long[] equipmentIds) {
		return toAjax(baseEquipmentService.deleteBaseEquipmentByEquipmentIds(equipmentIds));
	}
}
