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.SysMachinery;
import com.op.wms.service.ISysMachineryService;
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-18
 */
@RestController
@RequestMapping("/machinery")
public class SysMachineryController extends BaseController {
	@Autowired
	private ISysMachineryService sysMachineryService;

	/**
	 * 查询机台管理列表
	 */
	@RequiresPermissions("wms:machinery:list")
	@GetMapping("/list")
	public TableDataInfo list(SysMachinery sysMachinery) {
		startPage();
		List<SysMachinery> list = sysMachineryService.selectSysMachineryList(sysMachinery);
		return getDataTable(list);
	}

	/**
	 * 导出机台管理列表
	 */
	@RequiresPermissions("wms:machinery:export")
	@Log(title = "机台管理", businessType = BusinessType.EXPORT)
	@PostMapping("/export")
	public void export(HttpServletResponse response, SysMachinery sysMachinery) {
		List<SysMachinery> list = sysMachineryService.selectSysMachineryList(sysMachinery);
		ExcelUtil<SysMachinery> util = new ExcelUtil<SysMachinery>(SysMachinery.class);
		util.exportExcel(response, list, "机台管理数据");
	}

	/**
	 * 获取机台管理详细信息
	 */
	@RequiresPermissions("wms:machinery:query")
	@GetMapping(value = "/{machineryId}")
	public AjaxResult getInfo(@PathVariable("machineryId") Long machineryId) {
		return success(sysMachineryService.selectSysMachineryByMachineryId(machineryId));
	}

	/**
	 * 新增机台管理
	 */
	@RequiresPermissions("wms:machinery:add")
	@Log(title = "机台管理", businessType = BusinessType.INSERT)
	@PostMapping
	public AjaxResult add(@RequestBody SysMachinery sysMachinery) {
		return toAjax(sysMachineryService.insertSysMachinery(sysMachinery));
	}

	/**
	 * 修改机台管理
	 */
	@RequiresPermissions("wms:machinery:edit")
	@Log(title = "机台管理", businessType = BusinessType.UPDATE)
	@PutMapping
	public AjaxResult edit(@RequestBody SysMachinery sysMachinery) {
		return toAjax(sysMachineryService.updateSysMachinery(sysMachinery));
	}

	/**
	 * 删除机台管理
	 */
	@RequiresPermissions("wms:machinery:remove")
	@Log(title = "机台管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{machineryIds}")
	public AjaxResult remove(@PathVariable Long[] machineryIds) {
		return toAjax(sysMachineryService.deleteSysMachineryByMachineryIds(machineryIds));
	}
}
