package com.ruoyi.web.controller.sapCustomer;

import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.sapCustomer.domain.SapCustomer;
import com.ruoyi.sapCustomer.service.ISapCustomerService;
import org.springframework.security.access.prepost.PreAuthorize;
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.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.page.TableDataInfo;

import java.util.List;

/**
 * 客户管理Controller
 *
 * @author ruoyi
 * @date 2024-03-11
 */
@RestController
@RequestMapping("/sapCustomer/sapCustomer")
public class SapCustomerController extends BaseController
{
    @Autowired
    private ISapCustomerService sapCustomerService;

    /**
     * 查询客户管理列表
     */
    @PreAuthorize("@ss.hasPermi('sapCustomer:sapCustomer:list')")
    @GetMapping("/list")
    public TableDataInfo list(SapCustomer sapCustomer)
    {
        startPage();
        List<SapCustomer> list = sapCustomerService.selectSapCustomerList(sapCustomer);
        return getDataTable(list);
    }

    /**
     * 导出客户管理列表
     */
    @PreAuthorize("@ss.hasPermi('sapCustomer:sapCustomer:export')")
    @Log(title = "客户管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SapCustomer sapCustomer)
    {
        List<SapCustomer> list = sapCustomerService.selectSapCustomerList(sapCustomer);
        ExcelUtil<SapCustomer> util = new ExcelUtil<SapCustomer>(SapCustomer.class);
        util.exportExcel(response, list, "客户管理数据");
    }

    /**
     * 获取客户管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('sapCustomer:sapCustomer:query')")
    @GetMapping(value = "/{customerId}")
    public AjaxResult getInfo(@PathVariable("customerId") Long customerId)
    {
        return success(sapCustomerService.selectSapCustomerByCustomerId(customerId));
    }

    /**
     * 新增客户管理
     */
    @PreAuthorize("@ss.hasPermi('sapCustomer:sapCustomer:add')")
    @Log(title = "客户管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SapCustomer sapCustomer)
    {
        return toAjax(sapCustomerService.insertSapCustomer(sapCustomer));
    }

    /**
     * 修改客户管理
     */
    @PreAuthorize("@ss.hasPermi('sapCustomer:sapCustomer:edit')")
    @Log(title = "客户管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SapCustomer sapCustomer)
    {
        return toAjax(sapCustomerService.updateSapCustomer(sapCustomer));
    }

    /**
     * 删除客户管理
     */
    @PreAuthorize("@ss.hasPermi('sapCustomer:sapCustomer:remove')")
    @Log(title = "客户管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{customerIds}")
    public AjaxResult remove(@PathVariable Long[] customerIds)
    {
        return toAjax(sapCustomerService.deleteSapCustomerByCustomerIds(customerIds));
    }
}
