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.SysCustomer;
import com.op.wms.service.ISysCustomerService;
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("/customer")
public class SysCustomerController extends BaseController {
	@Autowired
	private ISysCustomerService sysCustomerService;

	/**
	 * 查询客户管理列表
	 */
	@RequiresPermissions("wms:customer:list")
	@GetMapping("/list")
	public TableDataInfo list(SysCustomer sysCustomer) {
		startPage();
		List<SysCustomer> list = sysCustomerService.selectSysCustomerList(sysCustomer);
		return getDataTable(list);
	}

	/**
	 * 导出客户管理列表
	 */
	@RequiresPermissions("wms:customer:export")
	@Log(title = "客户管理", businessType = BusinessType.EXPORT)
	@PostMapping("/export")
	public void export(HttpServletResponse response, SysCustomer sysCustomer) {
		List<SysCustomer> list = sysCustomerService.selectSysCustomerList(sysCustomer);
		ExcelUtil<SysCustomer> util = new ExcelUtil<SysCustomer>(SysCustomer.class);
		util.exportExcel(response, list, "客户管理数据");
	}

	/**
	 * 获取客户管理详细信息
	 */
	@RequiresPermissions("wms:customer:query")
	@GetMapping(value = "/{clientId}")
	public AjaxResult getInfo(@PathVariable("clientId") Long clientId) {
		return success(sysCustomerService.selectSysCustomerByClientId(clientId));
	}

	/**
	 * 新增客户管理
	 */
	@RequiresPermissions("wms:customer:add")
	@Log(title = "客户管理", businessType = BusinessType.INSERT)
	@PostMapping
	public AjaxResult add(@RequestBody SysCustomer sysCustomer) {
		return toAjax(sysCustomerService.insertSysCustomer(sysCustomer));
	}

	/**
	 * 修改客户管理
	 */
	@RequiresPermissions("wms:customer:edit")
	@Log(title = "客户管理", businessType = BusinessType.UPDATE)
	@PutMapping
	public AjaxResult edit(@RequestBody SysCustomer sysCustomer) {
		return toAjax(sysCustomerService.updateSysCustomer(sysCustomer));
	}

	/**
	 * 删除客户管理
	 */
	@RequiresPermissions("wms:customer:remove")
	@Log(title = "客户管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{clientIds}")
	public AjaxResult remove(@PathVariable Long[] clientIds) {
		return toAjax(sysCustomerService.deleteSysCustomerByClientIds(clientIds));
	}
}
