package com.ruoyi.web.controller.business;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.SysConfigApi;
import com.ruoyi.business.service.ISysConfigApiService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 系统配置信息Controller
 * 
 * @author xiatao
 * @date 2022-01-18
 */
@Controller
@RequestMapping("/business/configApi")
public class SysConfigApiController extends BaseController
{
    private String prefix = "business/configApi";

    @Autowired
    private ISysConfigApiService sysConfigApiService;

    @RequiresPermissions("business:configApi:view")
    @GetMapping()
    public String configApi()
    {
        return prefix + "/configApi";
    }

    /**
     * 查询系统配置信息列表
     */
    @RequiresPermissions("business:configApi:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysConfigApi sysConfigApi)
    {
        startPage();
        List<SysConfigApi> list = sysConfigApiService.selectSysConfigApiList(sysConfigApi);
        return getDataTable(list);
    }

    /**
     * 导出系统配置信息列表
     */
    @RequiresPermissions("business:configApi:export")
    @Log(title = "系统配置信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SysConfigApi sysConfigApi)
    {
        List<SysConfigApi> list = sysConfigApiService.selectSysConfigApiList(sysConfigApi);
        ExcelUtil<SysConfigApi> util = new ExcelUtil<SysConfigApi>(SysConfigApi.class);
        return util.exportExcel(list, "系统配置信息数据");
    }

    /**
     * 新增系统配置信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存系统配置信息
     */
    @RequiresPermissions("business:configApi:add")
    @Log(title = "系统配置信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SysConfigApi sysConfigApi)
    {
        return toAjax(sysConfigApiService.insertSysConfigApi(sysConfigApi));
    }

    /**
     * 修改系统配置信息
     */
    @RequiresPermissions("business:configApi:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        SysConfigApi sysConfigApi = sysConfigApiService.selectSysConfigApiById(id);
        mmap.put("sysConfigApi", sysConfigApi);
        return prefix + "/edit";
    }

    /**
     * 修改保存系统配置信息
     */
    @RequiresPermissions("business:configApi:edit")
    @Log(title = "系统配置信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SysConfigApi sysConfigApi)
    {
        return toAjax(sysConfigApiService.updateSysConfigApi(sysConfigApi));
    }

    /**
     * 删除系统配置信息
     */
    @RequiresPermissions("business:configApi:remove")
    @Log(title = "系统配置信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sysConfigApiService.deleteSysConfigApiByIds(ids));
    }
}
