package com.ruoyi.web.controller.sapAccount;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
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.sapAccount.domain.SapAccount;
import com.ruoyi.sapAccount.service.ISapAccountService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 业务账户Controller
 *
 * @author ruoyi
 * @date 2024-03-11
 */
@RestController
@RequestMapping("/sapAccount/sapAccount")
public class SapAccountController extends BaseController
{
    @Autowired
    private ISapAccountService sapAccountService;

    /**
     * 查询业务账户列表
     */
    @PreAuthorize("@ss.hasPermi('sapAccount:sapAccount:list')")
    @GetMapping("/list")
    public TableDataInfo list(SapAccount sapAccount)
    {
        startPage();
        List<SapAccount> list = sapAccountService.selectSapAccountList(sapAccount);
        return getDataTable(list);
    }

    /**
     * 导出业务账户列表
     */
    @PreAuthorize("@ss.hasPermi('sapAccount:sapAccount:export')")
    @Log(title = "业务账户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SapAccount sapAccount)
    {
        List<SapAccount> list = sapAccountService.selectSapAccountList(sapAccount);
        ExcelUtil<SapAccount> util = new ExcelUtil<SapAccount>(SapAccount.class);
        util.exportExcel(response, list, "业务账户数据");
    }

    /**
     * 获取业务账户详细信息
     */
    @PreAuthorize("@ss.hasPermi('sapAccount:sapAccount:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sapAccountService.selectSapAccountById(id));
    }

    /**
     * 新增业务账户
     */
    @PreAuthorize("@ss.hasPermi('sapAccount:sapAccount:add')")
    @Log(title = "业务账户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SapAccount sapAccount)
    {
        return toAjax(sapAccountService.insertSapAccount(sapAccount));
    }

    /**
     * 修改业务账户
     */
    @PreAuthorize("@ss.hasPermi('sapAccount:sapAccount:edit')")
    @Log(title = "业务账户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SapAccount sapAccount)
    {
        return toAjax(sapAccountService.updateSapAccount(sapAccount));
    }

    /**
     * 删除业务账户
     */
    @PreAuthorize("@ss.hasPermi('sapAccount:sapAccount:remove')")
    @Log(title = "业务账户", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sapAccountService.deleteSapAccountByIds(ids));
    }
}
