package com.tongran.rocketmq.controller;

import com.tongran.common.core.domain.R;
import com.tongran.common.core.utils.poi.ExcelUtil;
import com.tongran.common.core.web.controller.BaseController;
import com.tongran.common.core.web.domain.AjaxResult;
import com.tongran.common.log.annotation.Log;
import com.tongran.common.log.enums.BusinessType;
import com.tongran.common.security.annotation.InnerAuth;
import com.tongran.common.security.annotation.RequiresPermissions;
import com.tongran.rocketmq.domain.RmNetworkInterface;
import com.tongran.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 tongran
 * @date 2025-10-14
 */
@RestController
@RequestMapping("/networkInterface")
@RequiresPermissions("system:registration")
public class RmNetworkInterfaceController extends BaseController
{
    @Autowired
    private IRmNetworkInterfaceService rmNetworkInterfaceService;

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

    /**
     * 导出客户端网络接口信息列表
     */
    @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, "客户端网络接口信息数据");
    }

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

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

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

    /**
     * 删除客户端网络接口信息
     */
    @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);
    }

}
