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.BaseSupplier;
import com.op.wms.service.IBaseSupplierService;
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("/supplier")
public class BaseSupplierController extends BaseController {
	@Autowired
	private IBaseSupplierService baseSupplierService;

	/**
	 * 查询供应商管理列表
	 */
	@RequiresPermissions("wms:supplier:list")
	@GetMapping("/list")
	public TableDataInfo list(BaseSupplier baseSupplier) {
		startPage();
		List<BaseSupplier> list = baseSupplierService.selectBaseSupplierList(baseSupplier);
		return getDataTable(list);
	}

	/**
	 * 导出供应商管理列表
	 */
	@RequiresPermissions("wms:supplier:export")
	@Log(title = "供应商管理", businessType = BusinessType.EXPORT)
	@PostMapping("/export")
	public void export(HttpServletResponse response, BaseSupplier baseSupplier) {
		List<BaseSupplier> list = baseSupplierService.selectBaseSupplierList(baseSupplier);
		ExcelUtil<BaseSupplier> util = new ExcelUtil<BaseSupplier>(BaseSupplier.class);
		util.exportExcel(response, list, "供应商管理数据");
	}

	/**
	 * 获取供应商管理详细信息
	 */
	@RequiresPermissions("wms:supplier:query")
	@GetMapping(value = "/{supplierId}")
	public AjaxResult getInfo(@PathVariable("supplierId") String supplierId) {
		return success(baseSupplierService.selectBaseSupplierBySupplierId(supplierId));
	}

	/**
	 * 新增供应商管理
	 */
	@RequiresPermissions("wms:supplier:add")
	@Log(title = "供应商管理", businessType = BusinessType.INSERT)
	@PostMapping
	public AjaxResult add(@RequestBody BaseSupplier baseSupplier) {
		return toAjax(baseSupplierService.insertBaseSupplier(baseSupplier));
	}

	/**
	 * 修改供应商管理
	 */
	@RequiresPermissions("wms:supplier:edit")
	@Log(title = "供应商管理", businessType = BusinessType.UPDATE)
	@PutMapping
	public AjaxResult edit(@RequestBody BaseSupplier baseSupplier) {
		return toAjax(baseSupplierService.updateBaseSupplier(baseSupplier));
	}

	/**
	 * 删除供应商管理
	 */
	@RequiresPermissions("wms:supplier:remove")
	@Log(title = "供应商管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{supplierIds}")
	public AjaxResult remove(@PathVariable String[] supplierIds) {
		return toAjax(baseSupplierService.deleteBaseSupplierBySupplierIds(supplierIds));
	}
}
