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.BaseEquipmentProduct;
import com.op.wms.service.IBaseEquipmentProductService;
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("/equipmentBoundMaterials")
public class BaseEquipmentProductController extends BaseController {
	@Autowired
	private IBaseEquipmentProductService baseEquipmentProductService;

	/**
	 * 查询设备绑定产品列表
	 */
	@RequiresPermissions("wms:equipmentBoundMaterials:list")
	@GetMapping("/list")
	public TableDataInfo list(BaseEquipmentProduct baseEquipmentProduct) {
		startPage();
		List<BaseEquipmentProduct> list = baseEquipmentProductService.selectBaseEquipmentProductList(baseEquipmentProduct);
		return getDataTable(list);
	}

	/**
	 * 导出设备绑定产品列表
	 */
	@RequiresPermissions("wms:equipmentBoundMaterials:export")
	@Log(title = "设备绑定产品", businessType = BusinessType.EXPORT)
	@PostMapping("/export")
	public void export(HttpServletResponse response, BaseEquipmentProduct baseEquipmentProduct) {
		List<BaseEquipmentProduct> list = baseEquipmentProductService.selectBaseEquipmentProductList(baseEquipmentProduct);
		ExcelUtil<BaseEquipmentProduct> util = new ExcelUtil<BaseEquipmentProduct>(BaseEquipmentProduct.class);
		util.exportExcel(response, list, "设备绑定产品数据");
	}

	/**
	 * 获取设备绑定产品详细信息
	 */
	@RequiresPermissions("wms:equipmentBoundMaterials:query")
	@GetMapping(value = "/{equipmentId}")
	public AjaxResult getInfo(@PathVariable("equipmentId") Long equipmentId) {
		return success(baseEquipmentProductService.selectBaseEquipmentProductByEquipmentId(equipmentId));
	}

	/**
	 * 新增设备绑定产品
	 */
	@RequiresPermissions("wms:equipmentBoundMaterials:add")
	@Log(title = "设备绑定产品", businessType = BusinessType.INSERT)
	@PostMapping
	public AjaxResult add(@RequestBody BaseEquipmentProduct baseEquipmentProduct) {
		return toAjax(baseEquipmentProductService.insertBaseEquipmentProduct(baseEquipmentProduct));
	}

	/**
	 * 修改设备绑定产品
	 */
	@RequiresPermissions("wms:equipmentBoundMaterials:edit")
	@Log(title = "设备绑定产品", businessType = BusinessType.UPDATE)
	@PutMapping
	public AjaxResult edit(@RequestBody BaseEquipmentProduct baseEquipmentProduct) {
		return toAjax(baseEquipmentProductService.updateBaseEquipmentProduct(baseEquipmentProduct));
	}

	/**
	 * 删除设备绑定产品
	 */
	@RequiresPermissions("wms:equipmentBoundMaterials:remove")
	@Log(title = "设备绑定产品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{equipmentIds}")
	public AjaxResult remove(@PathVariable Long[] equipmentIds) {
		return toAjax(baseEquipmentProductService.deleteBaseEquipmentProductByEquipmentIds(equipmentIds));
	}
}
