package com.ruoyi.base.controller;

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.base.domain.RobotOpsWhitelist;
import com.ruoyi.base.service.IRobotOpsWhitelistService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 访客白名单Controller
 *
 * @author ruoyi
 * @date 2026-04-29
 */
@RestController
@RequestMapping("/base/whitelist")
public class RobotOpsWhitelistController extends BaseController
{
    @Autowired
    private IRobotOpsWhitelistService robotOpsWhitelistService;

    /**
     * 查询访客白名单列表
     */
    @PreAuthorize("@ss.hasPermi('base:whitelist:list')")
    @GetMapping("/list")
    public TableDataInfo list(RobotOpsWhitelist robotOpsWhitelist)
    {
        startPage();
        List<RobotOpsWhitelist> list = robotOpsWhitelistService.selectRobotOpsWhitelistList(robotOpsWhitelist);
        return getDataTable(list);
    }

    /**
     * 导出访客白名单列表
     */
    @PreAuthorize("@ss.hasPermi('base:whitelist:export')")
    @Log(title = "访客白名单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RobotOpsWhitelist robotOpsWhitelist)
    {
        List<RobotOpsWhitelist> list = robotOpsWhitelistService.selectRobotOpsWhitelistList(robotOpsWhitelist);
        ExcelUtil<RobotOpsWhitelist> util = new ExcelUtil<RobotOpsWhitelist>(RobotOpsWhitelist.class);
        util.exportExcel(response, list, "访客白名单数据");
    }

    /**
     * 获取访客白名单详细信息
     */
    @PreAuthorize("@ss.hasPermi('base:whitelist:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(robotOpsWhitelistService.selectRobotOpsWhitelistById(id));
    }

    /**
     * 新增访客白名单
     */
    @PreAuthorize("@ss.hasPermi('base:whitelist:add')")
    @Log(title = "访客白名单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RobotOpsWhitelist robotOpsWhitelist)
    {
        return toAjax(robotOpsWhitelistService.insertRobotOpsWhitelist(robotOpsWhitelist));
    }

    /**
     * 修改访客白名单
     */
    @PreAuthorize("@ss.hasPermi('base:whitelist:edit')")
    @Log(title = "访客白名单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RobotOpsWhitelist robotOpsWhitelist)
    {
        return toAjax(robotOpsWhitelistService.updateRobotOpsWhitelist(robotOpsWhitelist));
    }

    /**
     * 删除访客白名单
     */
    @PreAuthorize("@ss.hasPermi('base:whitelist:remove')")
    @Log(title = "访客白名单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(robotOpsWhitelistService.deleteRobotOpsWhitelistByIds(ids));
    }
}
