package com.ruoyi.rocketmq.controller;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.InnerAuth;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.rocketmq.domain.RmNetworkInterface;
import com.ruoyi.rocketmq.service.IRmNetworkInterfaceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

/**
 * 客户端网络接口信息Controller
 * 
 * @author gyt
 * @date 2025-10-14
 */
@RestController
@RequestMapping("/networkInterface")
public class RmNetworkInterfaceController extends BaseController
{
    @Autowired
    private IRmNetworkInterfaceService rmNetworkInterfaceService;

    /**
     * 查询客户端网络接口信息列表
     */
    @RequiresPermissions("rocketmq:networkInterface:list")
    @PostMapping("/list")
    public AjaxResult list(@RequestBody RmNetworkInterface rmNetworkInterface)
    {
        List<RmNetworkInterface> list = rmNetworkInterfaceService.selectRmNetworkInterfaceList(rmNetworkInterface);
        return success(list);
    }

    /**
     * 导出客户端网络接口信息列表
     */
    @RequiresPermissions("rocketmq:networkInterface:export")
    @Log(title = "客户端网络接口信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RmNetworkInterface rmNetworkInterface)
    {
        List<RmNetworkInterface> list = rmNetworkInterfaceService.selectRmNetworkInterfaceList(rmNetworkInterface);
        ExcelUtil<RmNetworkInterface> util = new ExcelUtil<RmNetworkInterface>(RmNetworkInterface.class);
        util.exportExcel(response, list, "客户端网络接口信息数据");
    }

    /**
     * 获取客户端网络接口信息详细信息
     */
    @RequiresPermissions("rocketmq:networkInterface:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(rmNetworkInterfaceService.selectRmNetworkInterfaceById(id));
    }

    /**
     * 新增客户端网络接口信息
     */
    @RequiresPermissions("rocketmq:networkInterface:add")
    @Log(title = "客户端网络接口信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RmNetworkInterface rmNetworkInterface)
    {
        return toAjax(rmNetworkInterfaceService.insertRmNetworkInterface(rmNetworkInterface));
    }

    /**
     * 修改客户端网络接口信息
     */
    @RequiresPermissions("rocketmq:networkInterface:edit")
    @Log(title = "客户端网络接口信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RmNetworkInterface rmNetworkInterface)
    {
        return toAjax(rmNetworkInterfaceService.updateRmNetworkInterface(rmNetworkInterface));
    }

    /**
     * 删除客户端网络接口信息
     */
    @RequiresPermissions("rocketmq:networkInterface:remove")
    @Log(title = "客户端网络接口信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(rmNetworkInterfaceService.deleteRmNetworkInterfaceByIds(ids));
    }
    /**
     * 远程调用查询客户端网络接口信息列表
     */
    @InnerAuth
    @PostMapping("/getNetworkInterfaceList")
    public R getNetworkInterfaceList(@RequestBody RmNetworkInterface rmNetworkInterface)
    {
        List<RmNetworkInterface> list = rmNetworkInterfaceService.selectRmNetworkInterfaceList(rmNetworkInterface);
        return R.ok(list);
    }
    /**
     * 远程调用修改客户端网络接口信息
     */
    @InnerAuth
    @PostMapping("/bindPublicIp")
    public R<Integer> bindPublicIp(@RequestBody RmNetworkInterface rmNetworkInterface)
    {
        int rows = rmNetworkInterfaceService.bindPublicIp(rmNetworkInterface);
        return R.ok(rows);
    }

}
