package com.ruoyi.web.controller.info;

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.system.domain.SysInterfaceForeign;
import com.ruoyi.system.service.ISysInterfaceForeignService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 对外接口调用配置Controller
 * 
 * @author ruoyi
 * @date 2022-10-31
 */
@RestController
@RequestMapping("/system/foreign")
public class SysInterfaceForeignController extends BaseController
{
    @Autowired
    private ISysInterfaceForeignService sysInterfaceForeignService;

    /**
     * 查询对外接口调用配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:foreign:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysInterfaceForeign sysInterfaceForeign)
    {
        startPage();
        List<SysInterfaceForeign> list = sysInterfaceForeignService.selectSysInterfaceForeignList(sysInterfaceForeign);
        return getDataTable(list);
    }

    /**
     * 导出对外接口调用配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:foreign:export')")
    @Log(title = "对外接口调用配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysInterfaceForeign sysInterfaceForeign)
    {
        List<SysInterfaceForeign> list = sysInterfaceForeignService.selectSysInterfaceForeignList(sysInterfaceForeign);
        ExcelUtil<SysInterfaceForeign> util = new ExcelUtil<SysInterfaceForeign>(SysInterfaceForeign.class);
        util.exportExcel(response, list, "对外接口调用配置数据");
    }

    /**
     * 获取对外接口调用配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:foreign:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(sysInterfaceForeignService.selectSysInterfaceForeignById(id));
    }

    /**
     * 新增对外接口调用配置
     */
    @PreAuthorize("@ss.hasPermi('system:foreign:add')")
    @Log(title = "对外接口调用配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysInterfaceForeign sysInterfaceForeign)
    {
        return toAjax(sysInterfaceForeignService.insertSysInterfaceForeign(sysInterfaceForeign));
    }

    /**
     * 修改对外接口调用配置
     */
    @PreAuthorize("@ss.hasPermi('system:foreign:edit')")
    @Log(title = "对外接口调用配置", businessType = BusinessType.UPDATE)
    @PostMapping("put")
    public AjaxResult edit(@RequestBody SysInterfaceForeign sysInterfaceForeign)
    {
        return toAjax(sysInterfaceForeignService.updateSysInterfaceForeign(sysInterfaceForeign));
    }

    /**
     * 删除对外接口调用配置
     */
    @PreAuthorize("@ss.hasPermi('system:foreign:remove')")
    @Log(title = "对外接口调用配置", businessType = BusinessType.DELETE)
    @GetMapping(value = "/delete/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysInterfaceForeignService.deleteSysInterfaceForeignByIds(ids));
    }
}
