package com.bonus.system.controller;

import com.bonus.common.core.utils.poi.ExcelUtil;
import com.bonus.common.core.web.controller.BaseController;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.common.core.web.page.TableDataInfo;
import com.bonus.common.log.annotation.SysLog;
import com.bonus.common.log.enums.OperaType;
import com.bonus.common.security.annotation.RequiresPermissions;
import com.bonus.system.domain.SysIpWhitelist;
import com.bonus.system.service.ISysIpWhitelistService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

/**
 * 白名单管理Controller
 *
 * @author bonus
 * @date 2024-11-06
 */
@RestController
@RequestMapping("/whitelist")
public class SysIpWhitelistController extends BaseController
{
    @Autowired
    private ISysIpWhitelistService sysIpWhitelistService;

    /**
     * 查询白名单管理列表
     */
    @RequiresPermissions("system:whitelist:list")
    @GetMapping("/list")
    public TableDataInfo list(SysIpWhitelist sysIpWhitelist)
    {
        try {
            startPage();
            List<SysIpWhitelist> list = sysIpWhitelistService.selectSysIpWhitelistList(sysIpWhitelist);
            return getDataTable(list);
        }catch (Exception e){
            return getDataTable(new ArrayList<>());
        }

    }

    /**
     * 导出白名单管理列表
     */
    @RequiresPermissions("system:whitelist:export")
    @PostMapping("/export")
    @SysLog(title = "白名单管理", businessType = OperaType.EXPORT,logType = 0,module = "白名单管理",details = "导出白名单管理列表")
    public void export(HttpServletResponse response, SysIpWhitelist sysIpWhitelist)
    {
        List<SysIpWhitelist> list = sysIpWhitelistService.selectSysIpWhitelistList(sysIpWhitelist);
        ExcelUtil<SysIpWhitelist> util = new ExcelUtil<SysIpWhitelist>(SysIpWhitelist.class);
        util.exportExcel(response, list, "白名单管理数据");
    }

    /**
     * 获取白名单管理详细信息
     */
    @RequiresPermissions("system:whitelist:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return sysIpWhitelistService.selectSysIpWhitelistById(id);
    }

    /**
     * 新增白名单管理
     */
    @RequiresPermissions("system:whitelist:add")
    @PostMapping("/add")
    @SysLog(title = "白名单管理", businessType = OperaType.INSERT,logType = 0,module = "白名单管理",details = "导出白名单管理列表")
    public AjaxResult add(@RequestBody SysIpWhitelist sysIpWhitelist)
    {
        return sysIpWhitelistService.insertSysIpWhitelist(sysIpWhitelist);
    }

    /**
     * 修改白名单管理
     */
    @RequiresPermissions("system:whitelist:edit")
    @PostMapping("/edit")
    @SysLog(title = "白名单管理", businessType = OperaType.UPDATE,logType = 0,module = "白名单管理",details = "导出白名单管理列表")
    public AjaxResult edit(@RequestBody SysIpWhitelist sysIpWhitelist)
    {
        return sysIpWhitelistService.updateSysIpWhitelist(sysIpWhitelist);
    }

    /**
     * 删除白名单管理
     */
    @RequiresPermissions("system:whitelist:remove")
    @PostMapping("/{ids}")
    @SysLog(title = "白名单管理", businessType = OperaType.DELETE,logType = 0,module = "白名单管理",details = "导出白名单管理列表")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return sysIpWhitelistService.deleteSysIpWhitelistByIds(ids);
    }

    /**
     * 删除白名单管理
     */
    @PostMapping("/updateSysIpWhitelistStatus")
    @SysLog(title = "白名单管理", businessType = OperaType.DELETE,logType = 0,module = "白名单管理",details = "导出白名单管理列表")
    public AjaxResult updateSysIpWhitelistStatus(@RequestBody SysIpWhitelist sysIpWhitelist)
    {
        return sysIpWhitelistService.updateSysIpWhitelistStatus(sysIpWhitelist);
    }



}
