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.BaseProduct;
import com.op.wms.service.IBaseProductService;
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("/product")
public class BaseProductController extends BaseController {
	@Autowired
	private IBaseProductService baseProductService;

	/**
	 * 查询物料信息列表
	 */
	@RequiresPermissions("wms:product:list")
	@GetMapping("/list")
	public TableDataInfo list(BaseProduct baseProduct) {
		startPage();
		List<BaseProduct> list = baseProductService.selectBaseProductList(baseProduct);
		return getDataTable(list);
	}

	/**
	 * 导出物料信息列表
	 */
	@RequiresPermissions("wms:product:export")
	@Log(title = "物料信息", businessType = BusinessType.EXPORT)
	@PostMapping("/export")
	public void export(HttpServletResponse response, BaseProduct baseProduct) {
		List<BaseProduct> list = baseProductService.selectBaseProductList(baseProduct);
		ExcelUtil<BaseProduct> util = new ExcelUtil<BaseProduct>(BaseProduct.class);
		util.exportExcel(response, list, "物料信息数据");
	}

	/**
	 * 获取物料信息详细信息
	 */
	@RequiresPermissions("wms:product:query")
	@GetMapping(value = "/{productId}")
	public AjaxResult getInfo(@PathVariable("productId") String productId) {
		return success(baseProductService.selectBaseProductByProductId(productId));
	}

	/**
	 * 新增物料信息
	 */
	@RequiresPermissions("wms:product:add")
	@Log(title = "物料信息", businessType = BusinessType.INSERT)
	@PostMapping
	public AjaxResult add(@RequestBody BaseProduct baseProduct) {
		return toAjax(baseProductService.insertBaseProduct(baseProduct));
	}

	/**
	 * 修改物料信息
	 */
	@RequiresPermissions("wms:product:edit")
	@Log(title = "物料信息", businessType = BusinessType.UPDATE)
	@PutMapping
	public AjaxResult edit(@RequestBody BaseProduct baseProduct) {
		return toAjax(baseProductService.updateBaseProduct(baseProduct));
	}

	/**
	 * 删除物料信息
	 */
	@RequiresPermissions("wms:product:remove")
	@Log(title = "物料信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{productIds}")
	public AjaxResult remove(@PathVariable String[] productIds) {
		return toAjax(baseProductService.deleteBaseProductByProductIds(productIds));
	}
}
