1、修复昨日95值不显示问题。
2、开发frpc端口自动分配功能。
This commit is contained in:
+113
@@ -0,0 +1,113 @@
|
||||
package com.tongran.rocketmq.controller;
|
||||
|
||||
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.core.web.page.PageDomain;
|
||||
import com.tongran.common.core.web.page.TableDataInfo;
|
||||
import com.tongran.common.log.annotation.Log;
|
||||
import com.tongran.common.log.enums.BusinessType;
|
||||
import com.tongran.common.security.annotation.RequiresPermissions;
|
||||
import com.tongran.rocketmq.domain.RmFrpcConfigManage;
|
||||
import com.tongran.rocketmq.service.IRmFrpcConfigManageService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* FRPC配置管理Controller
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-12-19
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/frpcConfigManage")
|
||||
@RequiresPermissions("rocketmq:frpcConfigManage")
|
||||
public class RmFrpcConfigManageController extends BaseController
|
||||
{
|
||||
@Autowired
|
||||
private IRmFrpcConfigManageService rmFrpcConfigManageService;
|
||||
|
||||
/**
|
||||
* 查询FRPC配置管理列表
|
||||
*/
|
||||
@PostMapping("/list")
|
||||
public TableDataInfo list(@RequestBody RmFrpcConfigManage rmFrpcConfigManage)
|
||||
{
|
||||
PageDomain pageDomain = new PageDomain();
|
||||
pageDomain.setPageNum(rmFrpcConfigManage.getPageNum());
|
||||
pageDomain.setPageSize(rmFrpcConfigManage.getPageSize());
|
||||
startPage(pageDomain);
|
||||
List<RmFrpcConfigManage> list = rmFrpcConfigManageService.selectRmFrpcConfigManageList(rmFrpcConfigManage);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出FRPC配置管理列表
|
||||
*/
|
||||
@RequiresPermissions("rocketmq:frpcConfigManage:export")
|
||||
@Log(title = "FRPC配置管理", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, @RequestBody RmFrpcConfigManage rmFrpcConfigManage)
|
||||
{
|
||||
List<RmFrpcConfigManage> list = rmFrpcConfigManageService.selectRmFrpcConfigManageList(rmFrpcConfigManage);
|
||||
ExcelUtil<RmFrpcConfigManage> util = new ExcelUtil<RmFrpcConfigManage>(RmFrpcConfigManage.class);
|
||||
util.showColumn(rmFrpcConfigManage.getProperties());
|
||||
util.exportExcel(response, list, "FRPC配置管理数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取FRPC配置管理详细信息
|
||||
*/
|
||||
@RequiresPermissions("rocketmq:frpcConfigManage:query")
|
||||
@GetMapping(value = "/{id}")
|
||||
public AjaxResult getInfo(@PathVariable("id") Long id)
|
||||
{
|
||||
return success(rmFrpcConfigManageService.selectRmFrpcConfigManageById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增FRPC配置管理
|
||||
*/
|
||||
@RequiresPermissions("rocketmq:frpcConfigManage:add")
|
||||
@Log(title = "FRPC配置管理", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public AjaxResult add(@RequestBody RmFrpcConfigManage rmFrpcConfigManage)
|
||||
{
|
||||
return toAjax(rmFrpcConfigManageService.insertRmFrpcConfigManage(rmFrpcConfigManage));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改FRPC配置管理
|
||||
*/
|
||||
@RequiresPermissions("rocketmq:frpcConfigManage:edit")
|
||||
@Log(title = "FRPC配置管理", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public AjaxResult edit(@RequestBody RmFrpcConfigManage rmFrpcConfigManage)
|
||||
{
|
||||
return toAjax(rmFrpcConfigManageService.updateRmFrpcConfigManage(rmFrpcConfigManage));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除FRPC配置管理
|
||||
*/
|
||||
@RequiresPermissions("rocketmq:frpcConfigManage:remove")
|
||||
@Log(title = "FRPC配置管理", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{ids}")
|
||||
public AjaxResult remove(@PathVariable Long[] ids)
|
||||
{
|
||||
return toAjax(rmFrpcConfigManageService.deleteRmFrpcConfigManageByIds(ids));
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成FRP连接
|
||||
*/
|
||||
@Log(title = "生成FRP连接", businessType = BusinessType.OTHER)
|
||||
@PostMapping("/addFrpConnect")
|
||||
public AjaxResult addFrpConnect(@RequestBody RmFrpcConfigManage rmFrpcConfigManage)
|
||||
{
|
||||
return toAjax(rmFrpcConfigManageService.addFrpConnect(rmFrpcConfigManage));
|
||||
}
|
||||
}
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
package com.tongran.rocketmq.controller;
|
||||
|
||||
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.RequiresPermissions;
|
||||
import com.tongran.rocketmq.domain.RmFrpcPortMapping;
|
||||
import com.tongran.rocketmq.service.IRmFrpcPortMappingService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* FRPC端口映射配置Controller
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-12-19
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/frpcPortMapping")
|
||||
public class RmFrpcPortMappingController extends BaseController
|
||||
{
|
||||
@Autowired
|
||||
private IRmFrpcPortMappingService rmFrpcPortMappingService;
|
||||
|
||||
/**
|
||||
* 查询FRPC端口映射配置列表
|
||||
*/
|
||||
@RequiresPermissions("rocketmq:frpcPortMapping:list")
|
||||
@PostMapping("/list")
|
||||
public AjaxResult list(@RequestBody RmFrpcPortMapping rmFrpcPortMapping)
|
||||
{
|
||||
List<RmFrpcPortMapping> list = rmFrpcPortMappingService.selectRmFrpcPortMappingList(rmFrpcPortMapping);
|
||||
return success(list);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取FRPC端口映射配置详细信息
|
||||
*/
|
||||
@GetMapping(value = "/{id}")
|
||||
public AjaxResult getInfo(@PathVariable("id") Long id)
|
||||
{
|
||||
return success(rmFrpcPortMappingService.selectRmFrpcPortMappingById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增FRPC端口映射配置
|
||||
*/
|
||||
@Log(title = "FRPC端口映射配置", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public AjaxResult add(@RequestBody RmFrpcPortMapping rmFrpcPortMapping)
|
||||
{
|
||||
return toAjax(rmFrpcPortMappingService.insertRmFrpcPortMapping(rmFrpcPortMapping));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package com.tongran.rocketmq.domain;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.tongran.common.core.annotation.Excel;
|
||||
import com.tongran.common.core.web.domain.BaseEntity;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* FRPC配置管理对象 rm_frpc_config_manage
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-12-19
|
||||
*/
|
||||
@Data
|
||||
public class RmFrpcConfigManage extends BaseEntity
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 主键ID */
|
||||
private Long id;
|
||||
|
||||
/** 客户端ID */
|
||||
@Excel(name = "客户端ID")
|
||||
private String clientId;
|
||||
|
||||
/** FRPC服务器地址 */
|
||||
@Excel(name = "FRPC服务器地址")
|
||||
private String frpcServerAddr;
|
||||
|
||||
/** FRPC服务器端口 */
|
||||
@Excel(name = "FRPC服务器端口")
|
||||
private String frpcServerPort;
|
||||
|
||||
/** FRPC远程端口 */
|
||||
@Excel(name = "FRPC远程端口")
|
||||
private String frpcRemotePort;
|
||||
|
||||
/** FRPC本地端口 */
|
||||
@Excel(name = "FRPC本地端口")
|
||||
private String frpcLocalPort;
|
||||
|
||||
/** FRPC本地IP */
|
||||
@Excel(name = "FRPC本地IP")
|
||||
private String frpcLocalIp;
|
||||
|
||||
/** FRPC配置名称 */
|
||||
@Excel(name = "FRPC配置名称")
|
||||
private String frpcName;
|
||||
|
||||
/** FRP连接地址生成状态(0-未生成,1-生成中,2已生成) */
|
||||
@Excel(name = "FRP连接地址生成状态", readConverterExp = "0=未生成,1=生成中,2=已生成")
|
||||
private Long frpcConnectionStatus;
|
||||
|
||||
/** FRPC服务状态(0-未运行,1-运行) */
|
||||
@Excel(name = "FRPC服务状态", readConverterExp = "0=未运行,1=运行")
|
||||
private String frpcStatus;
|
||||
|
||||
/** FRPC连接生成时间 */
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@Excel(name = "FRPC连接生成时间", width = 30, dateFormat = "yyyy-MM-dd")
|
||||
private Date frpcCreateTime;
|
||||
/** 起始远程端口 */
|
||||
private Integer startRemotePort;
|
||||
|
||||
/** 结束远程端口 */
|
||||
private Integer endRemotePort;
|
||||
// 管理网相关字段
|
||||
|
||||
@Excel(name = "管理网-公网IP")
|
||||
private String mgmtPublicIp; // 管理网-公网IP
|
||||
|
||||
@Excel(name = "管理网-接口名称")
|
||||
private String mgmtInterfaceName; // 管理网-接口名称
|
||||
|
||||
@Excel(name = "管理网-mac地址")
|
||||
private String mgmtMacAddress; // 管理网-mac地址
|
||||
|
||||
@Excel(name = "管理网-接口类型")
|
||||
private String mgmtInterfaceType; // 管理网-接口类型
|
||||
|
||||
@Excel(name = "管理网-IPv4地址")
|
||||
private String mgmtIpv4Address; // 管理网-IPv4地址
|
||||
|
||||
@Excel(name = "管理网-网关")
|
||||
private String mgmtGateway; // 管理网-网关地址
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.tongran.rocketmq.domain;
|
||||
|
||||
import com.tongran.common.core.annotation.Excel;
|
||||
import com.tongran.common.core.web.domain.BaseEntity;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* FRPC端口映射配置对象 rm_frpc_port_mapping
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-12-19
|
||||
*/
|
||||
@Data
|
||||
public class RmFrpcPortMapping extends BaseEntity
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 主键ID */
|
||||
private Long id;
|
||||
|
||||
/** 起始远程端口 */
|
||||
@Excel(name = "起始远程端口")
|
||||
private Integer startRemotePort;
|
||||
|
||||
/** 结束远程端口 */
|
||||
@Excel(name = "结束远程端口")
|
||||
private Integer endRemotePort;
|
||||
|
||||
/** 服务器端口 */
|
||||
@Excel(name = "服务器端口")
|
||||
private String serverPort;
|
||||
|
||||
/** 服务器地址 */
|
||||
@Excel(name = "服务器地址")
|
||||
private String serverAddr;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.tongran.rocketmq.domain.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* FRPC端口映射配置对象 rm_frpc_port_mapping
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-12-19
|
||||
*/
|
||||
@Data
|
||||
public class FrpMsgVo
|
||||
{
|
||||
|
||||
/** 远程端口 */
|
||||
private Integer remotePort;
|
||||
|
||||
/** 服务器端口 */
|
||||
private String serverPort;
|
||||
|
||||
/** 服务器地址 */
|
||||
private String serverAddr;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.tongran.rocketmq.domain.vo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class FrpRspVo {
|
||||
/**
|
||||
* 状态码,0、失败;1、成功
|
||||
*/
|
||||
private Integer resCode;
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
private String resMsg;
|
||||
|
||||
/** frps地址 */
|
||||
private String serverAddr;
|
||||
/** frps端口 */
|
||||
private String serverPort;
|
||||
/** frpc端口 */
|
||||
private String remotePort;
|
||||
/** frpc 名称 */
|
||||
private String name;
|
||||
/** frpc 类型 */
|
||||
private String type;
|
||||
/** frpc 映射ip */
|
||||
private String localIP;
|
||||
/** frpc 映射端口 */
|
||||
private String localPort;
|
||||
/** frpc运行状态(0未运行,1已运行) */
|
||||
private String isRunning;
|
||||
|
||||
/**
|
||||
* 时间戳
|
||||
*/
|
||||
private Long timestamp = Instant.now().getEpochSecond();
|
||||
}
|
||||
@@ -17,6 +17,8 @@ public class PolicyTypeVo {
|
||||
private String routes;
|
||||
/** 业务网卡名称*/
|
||||
private String netName;
|
||||
/** frp配置信息 */
|
||||
private String frpMsg;
|
||||
/** 时间戳 */
|
||||
private Long timestamp = Instant.now().getEpochSecond();
|
||||
}
|
||||
|
||||
@@ -7,14 +7,10 @@ import com.tongran.common.core.enums.MsgEnum;
|
||||
import com.tongran.common.core.utils.DateUtils;
|
||||
import com.tongran.common.core.utils.StringUtils;
|
||||
import com.tongran.rocketmq.domain.*;
|
||||
import com.tongran.rocketmq.domain.vo.CollectDataVo;
|
||||
import com.tongran.rocketmq.domain.vo.RegisterMsgVo;
|
||||
import com.tongran.rocketmq.domain.vo.RspResultVo;
|
||||
import com.tongran.rocketmq.domain.vo.RspVo;
|
||||
import com.tongran.rocketmq.domain.vo.*;
|
||||
import com.tongran.rocketmq.enums.AlarmTypeEnum;
|
||||
import com.tongran.rocketmq.enums.PushMethodEnum;
|
||||
import com.tongran.rocketmq.service.*;
|
||||
import com.tongran.rocketmq.snmp.scheduler.MultiSwitchCollectionScheduler;
|
||||
import com.tongran.rocketmq.utils.DataProcessUtil;
|
||||
import com.tongran.rocketmq.utils.JsonDataParser;
|
||||
import com.tongran.rocketmq.utils.WeChatWorkBot;
|
||||
@@ -101,7 +97,7 @@ public class MessageHandler {
|
||||
@Autowired
|
||||
private IRmAlarmPushConfigService rmAlarmPushConfigService;
|
||||
@Autowired
|
||||
private MultiSwitchCollectionScheduler multiSwitchCollectionScheduler;
|
||||
private IRmFrpcConfigManageService rmFrpcConfigManageService;
|
||||
|
||||
|
||||
/**
|
||||
@@ -124,6 +120,39 @@ public class MessageHandler {
|
||||
registerHandler(MsgEnum.系统其他上报.getValue(), this::handleOtherSystemMessage);
|
||||
registerHandler(MsgEnum.心跳上报.getValue(), this::handleHeartbeatMessage);
|
||||
registerHandler(MsgEnum.多公网IP探测.getValue(), this::handleNetWorkDelectMessage);
|
||||
registerHandler(MsgEnum.修改frp配置文件应答.getValue(), this::handleUpdateFrpMessage);
|
||||
}
|
||||
|
||||
private void handleUpdateFrpMessage(DeviceMessage message) {
|
||||
List<FrpRspVo> rspVoList = JsonDataParser.parseJsonData(message.getData(), FrpRspVo.class);
|
||||
if (!rspVoList.isEmpty()) {
|
||||
FrpRspVo rsp = rspVoList.get(0);
|
||||
// 时间戳转换
|
||||
long timestamp = rsp.getTimestamp();
|
||||
long millis = timestamp * 1000;
|
||||
Date createTime = new Date(millis / 1000 * 1000); // 去除毫秒
|
||||
if(rsp.getResCode() == 1) {
|
||||
// 运行成功 修改相关信息
|
||||
RmFrpcConfigManage frpcData = new RmFrpcConfigManage();
|
||||
frpcData.setClientId(message.getClientId());
|
||||
frpcData.setFrpcName(rsp.getName());
|
||||
frpcData.setFrpcStatus(rsp.getIsRunning());
|
||||
frpcData.setFrpcLocalPort(rsp.getLocalPort());
|
||||
frpcData.setFrpcLocalIp(rsp.getLocalIP());
|
||||
frpcData.setFrpcCreateTime(createTime);
|
||||
frpcData.setFrpcConnectionStatus(2L);
|
||||
frpcData.setFrpcRemotePort(rsp.getRemotePort());
|
||||
frpcData.setFrpcServerAddr(rsp.getServerAddr());
|
||||
frpcData.setFrpcServerPort(rsp.getServerPort());
|
||||
rmFrpcConfigManageService.insertRmFrpcConfigManage(frpcData);
|
||||
} else if(rsp.getResCode() == 2){
|
||||
RmFrpcConfigManage configManage = new RmFrpcConfigManage();
|
||||
configManage.setFrpcRemotePort(rsp.getRemotePort());
|
||||
rmFrpcConfigManageService.addFrpConnect(configManage);
|
||||
} else{
|
||||
log.error("生成连接失败:{}",rsp.getResMsg());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
package com.tongran.rocketmq.mapper;
|
||||
|
||||
import java.util.List;
|
||||
import com.tongran.rocketmq.domain.RmFrpcConfigManage;
|
||||
|
||||
/**
|
||||
* FRPC配置管理Mapper接口
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-12-19
|
||||
*/
|
||||
public interface RmFrpcConfigManageMapper
|
||||
{
|
||||
/**
|
||||
* 查询FRPC配置管理
|
||||
*
|
||||
* @param id FRPC配置管理主键
|
||||
* @return FRPC配置管理
|
||||
*/
|
||||
public RmFrpcConfigManage selectRmFrpcConfigManageById(Long id);
|
||||
|
||||
/**
|
||||
* 查询FRPC配置管理列表
|
||||
*
|
||||
* @param rmFrpcConfigManage FRPC配置管理
|
||||
* @return FRPC配置管理集合
|
||||
*/
|
||||
public List<RmFrpcConfigManage> selectRmFrpcConfigManageList(RmFrpcConfigManage rmFrpcConfigManage);
|
||||
|
||||
/**
|
||||
* 新增FRPC配置管理
|
||||
*
|
||||
* @param rmFrpcConfigManage FRPC配置管理
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertRmFrpcConfigManage(RmFrpcConfigManage rmFrpcConfigManage);
|
||||
|
||||
/**
|
||||
* 修改FRPC配置管理
|
||||
*
|
||||
* @param rmFrpcConfigManage FRPC配置管理
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateRmFrpcConfigManage(RmFrpcConfigManage rmFrpcConfigManage);
|
||||
|
||||
/**
|
||||
* 删除FRPC配置管理
|
||||
*
|
||||
* @param id FRPC配置管理主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteRmFrpcConfigManageById(Long id);
|
||||
|
||||
/**
|
||||
* 批量删除FRPC配置管理
|
||||
*
|
||||
* @param ids 需要删除的数据主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteRmFrpcConfigManageByIds(Long[] ids);
|
||||
}
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
package com.tongran.rocketmq.mapper;
|
||||
|
||||
import com.tongran.rocketmq.domain.RmFrpcPortMapping;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* FRPC端口映射配置Mapper接口
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-12-19
|
||||
*/
|
||||
public interface RmFrpcPortMappingMapper
|
||||
{
|
||||
/**
|
||||
* 查询FRPC端口映射配置
|
||||
*
|
||||
* @param id FRPC端口映射配置主键
|
||||
* @return FRPC端口映射配置
|
||||
*/
|
||||
public RmFrpcPortMapping selectRmFrpcPortMappingById(Long id);
|
||||
|
||||
/**
|
||||
* 查询FRPC端口映射配置列表
|
||||
*
|
||||
* @param rmFrpcPortMapping FRPC端口映射配置
|
||||
* @return FRPC端口映射配置集合
|
||||
*/
|
||||
public List<RmFrpcPortMapping> selectRmFrpcPortMappingList(RmFrpcPortMapping rmFrpcPortMapping);
|
||||
|
||||
/**
|
||||
* 新增FRPC端口映射配置
|
||||
*
|
||||
* @param rmFrpcPortMapping FRPC端口映射配置
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertRmFrpcPortMapping(RmFrpcPortMapping rmFrpcPortMapping);
|
||||
|
||||
/**
|
||||
* 修改FRPC端口映射配置
|
||||
*
|
||||
* @param rmFrpcPortMapping FRPC端口映射配置
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateRmFrpcPortMapping(RmFrpcPortMapping rmFrpcPortMapping);
|
||||
|
||||
/**
|
||||
* 删除FRPC端口映射配置
|
||||
*
|
||||
* @param id FRPC端口映射配置主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteRmFrpcPortMappingById(Long id);
|
||||
|
||||
/**
|
||||
* 批量删除FRPC端口映射配置
|
||||
*
|
||||
* @param ids 需要删除的数据主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteRmFrpcPortMappingByIds(Long[] ids);
|
||||
|
||||
void truncateFrpcPortMapping();
|
||||
}
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
package com.tongran.rocketmq.service;
|
||||
|
||||
import com.tongran.rocketmq.domain.RmFrpcConfigManage;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* FRPC配置管理Service接口
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-12-19
|
||||
*/
|
||||
public interface IRmFrpcConfigManageService
|
||||
{
|
||||
/**
|
||||
* 查询FRPC配置管理
|
||||
*
|
||||
* @param id FRPC配置管理主键
|
||||
* @return FRPC配置管理
|
||||
*/
|
||||
public RmFrpcConfigManage selectRmFrpcConfigManageById(Long id);
|
||||
|
||||
/**
|
||||
* 查询FRPC配置管理列表
|
||||
*
|
||||
* @param rmFrpcConfigManage FRPC配置管理
|
||||
* @return FRPC配置管理集合
|
||||
*/
|
||||
public List<RmFrpcConfigManage> selectRmFrpcConfigManageList(RmFrpcConfigManage rmFrpcConfigManage);
|
||||
|
||||
/**
|
||||
* 新增FRPC配置管理
|
||||
*
|
||||
* @param rmFrpcConfigManage FRPC配置管理
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertRmFrpcConfigManage(RmFrpcConfigManage rmFrpcConfigManage);
|
||||
|
||||
/**
|
||||
* 修改FRPC配置管理
|
||||
*
|
||||
* @param rmFrpcConfigManage FRPC配置管理
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateRmFrpcConfigManage(RmFrpcConfigManage rmFrpcConfigManage);
|
||||
|
||||
/**
|
||||
* 批量删除FRPC配置管理
|
||||
*
|
||||
* @param ids 需要删除的FRPC配置管理主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteRmFrpcConfigManageByIds(Long[] ids);
|
||||
|
||||
/**
|
||||
* 删除FRPC配置管理信息
|
||||
*
|
||||
* @param id FRPC配置管理主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteRmFrpcConfigManageById(Long id);
|
||||
|
||||
/**
|
||||
* 生成frp连接
|
||||
* @param rmFrpcConfigManage
|
||||
* @return
|
||||
*/
|
||||
int addFrpConnect(RmFrpcConfigManage rmFrpcConfigManage);
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
package com.tongran.rocketmq.service;
|
||||
|
||||
import java.util.List;
|
||||
import com.tongran.rocketmq.domain.RmFrpcPortMapping;
|
||||
|
||||
/**
|
||||
* FRPC端口映射配置Service接口
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-12-19
|
||||
*/
|
||||
public interface IRmFrpcPortMappingService
|
||||
{
|
||||
/**
|
||||
* 查询FRPC端口映射配置
|
||||
*
|
||||
* @param id FRPC端口映射配置主键
|
||||
* @return FRPC端口映射配置
|
||||
*/
|
||||
public RmFrpcPortMapping selectRmFrpcPortMappingById(Long id);
|
||||
|
||||
/**
|
||||
* 查询FRPC端口映射配置列表
|
||||
*
|
||||
* @param rmFrpcPortMapping FRPC端口映射配置
|
||||
* @return FRPC端口映射配置集合
|
||||
*/
|
||||
public List<RmFrpcPortMapping> selectRmFrpcPortMappingList(RmFrpcPortMapping rmFrpcPortMapping);
|
||||
|
||||
/**
|
||||
* 新增FRPC端口映射配置
|
||||
*
|
||||
* @param rmFrpcPortMapping FRPC端口映射配置
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertRmFrpcPortMapping(RmFrpcPortMapping rmFrpcPortMapping);
|
||||
|
||||
/**
|
||||
* 修改FRPC端口映射配置
|
||||
*
|
||||
* @param rmFrpcPortMapping FRPC端口映射配置
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateRmFrpcPortMapping(RmFrpcPortMapping rmFrpcPortMapping);
|
||||
|
||||
/**
|
||||
* 批量删除FRPC端口映射配置
|
||||
*
|
||||
* @param ids 需要删除的FRPC端口映射配置主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteRmFrpcPortMappingByIds(Long[] ids);
|
||||
|
||||
/**
|
||||
* 删除FRPC端口映射配置信息
|
||||
*
|
||||
* @param id FRPC端口映射配置主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteRmFrpcPortMappingById(Long id);
|
||||
}
|
||||
+286
@@ -0,0 +1,286 @@
|
||||
package com.tongran.rocketmq.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.tongran.common.core.enums.MsgEnum;
|
||||
import com.tongran.common.core.utils.DateUtils;
|
||||
import com.tongran.rocketmq.domain.DeviceMessage;
|
||||
import com.tongran.rocketmq.domain.RmFrpcConfigManage;
|
||||
import com.tongran.rocketmq.domain.RmFrpcPortMapping;
|
||||
import com.tongran.rocketmq.domain.RmNetworkInterface;
|
||||
import com.tongran.rocketmq.domain.vo.FrpMsgVo;
|
||||
import com.tongran.rocketmq.domain.vo.PolicyTypeVo;
|
||||
import com.tongran.rocketmq.mapper.RmFrpcConfigManageMapper;
|
||||
import com.tongran.rocketmq.mapper.RmFrpcPortMappingMapper;
|
||||
import com.tongran.rocketmq.model.ProducerMode;
|
||||
import com.tongran.rocketmq.producer.MessageProducer;
|
||||
import com.tongran.rocketmq.service.IRmFrpcConfigManageService;
|
||||
import com.tongran.rocketmq.service.IRmNetworkInterfaceService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* FRPC配置管理Service业务层处理
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-12-19
|
||||
*/
|
||||
@Service
|
||||
public class RmFrpcConfigManageServiceImpl implements IRmFrpcConfigManageService
|
||||
{
|
||||
// Redis key定义
|
||||
private static final String USED_PORTS_KEY = "frpc:used_ports";
|
||||
|
||||
@Autowired
|
||||
private RedisTemplate<String, String> redisTemplate;
|
||||
@Autowired
|
||||
private RmFrpcConfigManageMapper rmFrpcConfigManageMapper;
|
||||
@Autowired
|
||||
private RmFrpcPortMappingMapper rmFrpcPortMappingMapper;
|
||||
@Autowired
|
||||
private IRmNetworkInterfaceService rmNetworkInterfaceService;
|
||||
@Autowired
|
||||
private ProducerMode producerMode;
|
||||
|
||||
/**
|
||||
* 查询FRPC配置管理
|
||||
*
|
||||
* @param id FRPC配置管理主键
|
||||
* @return FRPC配置管理
|
||||
*/
|
||||
@Override
|
||||
public RmFrpcConfigManage selectRmFrpcConfigManageById(Long id)
|
||||
{
|
||||
RmFrpcConfigManage rmFrpcConfigManage = rmFrpcConfigManageMapper.selectRmFrpcConfigManageById(id);
|
||||
setNetWorkMsg(rmFrpcConfigManage);
|
||||
return rmFrpcConfigManage;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询FRPC配置管理列表
|
||||
*
|
||||
* @param rmFrpcConfigManage FRPC配置管理
|
||||
* @return FRPC配置管理
|
||||
*/
|
||||
@Override
|
||||
public List<RmFrpcConfigManage> selectRmFrpcConfigManageList(RmFrpcConfigManage rmFrpcConfigManage)
|
||||
{
|
||||
List<RmFrpcConfigManage> list = rmFrpcConfigManageMapper.selectRmFrpcConfigManageList(rmFrpcConfigManage);
|
||||
if(list != null){
|
||||
for (RmFrpcConfigManage configManage : list) {
|
||||
// 设置管理网信息
|
||||
setNetWorkMsg(configManage);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
/**
|
||||
* 网卡信息赋值
|
||||
* @param frpcConfigManage
|
||||
*/
|
||||
public void setNetWorkMsg(RmFrpcConfigManage frpcConfigManage) {
|
||||
String clientId = frpcConfigManage.getClientId();
|
||||
// 根据clientId查询网卡信息
|
||||
RmNetworkInterface queryParam = new RmNetworkInterface();
|
||||
queryParam.setClientId(clientId);
|
||||
queryParam.setNewFlag(1);
|
||||
// 获取网络接口列表
|
||||
List<RmNetworkInterface> networkList = rmNetworkInterfaceService.selectRmNetworkInterfaceList(queryParam);
|
||||
|
||||
if (networkList == null || networkList.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (RmNetworkInterface network : networkList) {
|
||||
if ("2".equals(network.getBindIp()) || "3".equals(network.getBindIp())) {
|
||||
// 管理网IP处理
|
||||
frpcConfigManage.setMgmtPublicIp(network.getPublicIp());
|
||||
frpcConfigManage.setMgmtInterfaceName(network.getInterfaceName());
|
||||
frpcConfigManage.setMgmtMacAddress(network.getMacAddress());
|
||||
frpcConfigManage.setMgmtInterfaceType(network.getInterfaceType());
|
||||
frpcConfigManage.setMgmtIpv4Address(network.getIpv4Address());
|
||||
frpcConfigManage.setMgmtGateway(network.getGateway());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增FRPC配置管理
|
||||
*
|
||||
* @param rmFrpcConfigManage FRPC配置管理
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int insertRmFrpcConfigManage(RmFrpcConfigManage rmFrpcConfigManage)
|
||||
{
|
||||
rmFrpcConfigManage.setCreateTime(DateUtils.getNowDate());
|
||||
int rows = rmFrpcConfigManageMapper.insertRmFrpcConfigManage(rmFrpcConfigManage);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改FRPC配置管理
|
||||
*
|
||||
* @param rmFrpcConfigManage FRPC配置管理
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int updateRmFrpcConfigManage(RmFrpcConfigManage rmFrpcConfigManage)
|
||||
{
|
||||
rmFrpcConfigManage.setUpdateTime(DateUtils.getNowDate());
|
||||
return rmFrpcConfigManageMapper.updateRmFrpcConfigManage(rmFrpcConfigManage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除FRPC配置管理
|
||||
*
|
||||
* @param ids 需要删除的FRPC配置管理主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteRmFrpcConfigManageByIds(Long[] ids)
|
||||
{
|
||||
return rmFrpcConfigManageMapper.deleteRmFrpcConfigManageByIds(ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除FRPC配置管理信息
|
||||
*
|
||||
* @param id FRPC配置管理主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteRmFrpcConfigManageById(Long id)
|
||||
{
|
||||
return rmFrpcConfigManageMapper.deleteRmFrpcConfigManageById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int addFrpConnect(RmFrpcConfigManage rmFrpcConfigManage) {
|
||||
// 查询frps配置
|
||||
List<RmFrpcPortMapping> portMappingList = rmFrpcPortMappingMapper.selectRmFrpcPortMappingList(new RmFrpcPortMapping());
|
||||
Integer startRemotePort = rmFrpcConfigManage.getStartRemotePort();
|
||||
Integer endRemotePort = rmFrpcConfigManage.getEndRemotePort();
|
||||
String serverPort = null;
|
||||
String serverAddr = null;
|
||||
if(portMappingList != null && !portMappingList.isEmpty()){
|
||||
RmFrpcPortMapping portMapping = portMappingList.get(0);
|
||||
startRemotePort = portMapping.getStartRemotePort();
|
||||
endRemotePort = portMapping.getEndRemotePort();
|
||||
serverPort = portMapping.getServerPort();
|
||||
serverAddr = portMapping.getServerAddr();
|
||||
}
|
||||
if(startRemotePort == null || endRemotePort == null){
|
||||
throw new RuntimeException("请先设置FRPS端口范围");
|
||||
}
|
||||
String clientId = rmFrpcConfigManage.getClientId();
|
||||
if(rmFrpcConfigManage.getFrpcRemotePort() != null){
|
||||
// 此端口被占用存储到redis,再次随机可用端口
|
||||
addUsedPort(Integer.parseInt(rmFrpcConfigManage.getFrpcRemotePort()));
|
||||
}
|
||||
// 获取一个可用的随机端口
|
||||
int availablePort = getRandomAvailablePort(startRemotePort, endRemotePort);
|
||||
|
||||
if (availablePort != -1) {
|
||||
// 将端口标记为已使用
|
||||
if (addUsedPort(availablePort)) {
|
||||
// 构建端口下发信息
|
||||
FrpMsgVo frpMsgVo = new FrpMsgVo();
|
||||
frpMsgVo.setServerPort(serverPort);
|
||||
frpMsgVo.setServerAddr(serverAddr);
|
||||
frpMsgVo.setRemotePort(availablePort);
|
||||
String frpMsgStr = JSONObject.toJSONString(frpMsgVo);
|
||||
PolicyTypeVo policyTypeVo = new PolicyTypeVo();
|
||||
policyTypeVo.setFrpMsg(frpMsgStr);
|
||||
MessageProducer messageProducer = new MessageProducer();
|
||||
String configJson = JSONObject.toJSONString(policyTypeVo);
|
||||
DeviceMessage message = new DeviceMessage();
|
||||
message.setClientId(clientId);
|
||||
message.setData(configJson);
|
||||
message.setDataType(MsgEnum.获取最新策略应答.getValue());
|
||||
|
||||
messageProducer.sendAsyncProducerMessage(
|
||||
producerMode.getAgentTopic(),
|
||||
"",
|
||||
"",
|
||||
JSONObject.toJSONString(message)
|
||||
);
|
||||
}
|
||||
return 1;
|
||||
}else{
|
||||
throw new RuntimeException("该端口范围内无可用端口:" + startRemotePort + "~" + endRemotePort);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 获取下一个可用的随机端口
|
||||
*/
|
||||
public int getRandomAvailablePort(int startPort, int endPort) {
|
||||
validatePortRange(startPort, endPort);
|
||||
|
||||
// 获取已使用的端口集合
|
||||
Set<String> usedPorts = redisTemplate.opsForSet().members(USED_PORTS_KEY);
|
||||
if (usedPorts == null) {
|
||||
usedPorts = new HashSet<>();
|
||||
}
|
||||
|
||||
// 创建所有端口的列表
|
||||
List<Integer> allPorts = new ArrayList<>();
|
||||
for (int i = startPort; i <= endPort; i++) {
|
||||
allPorts.add(i);
|
||||
}
|
||||
|
||||
// 随机打乱
|
||||
Collections.shuffle(allPorts);
|
||||
|
||||
// 查找第一个未在Redis中存储的端口
|
||||
for (int port : allPorts) {
|
||||
if (!usedPorts.contains(String.valueOf(port))) {
|
||||
return port;
|
||||
}
|
||||
}
|
||||
|
||||
return -1; // 没有可用端口
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断端口是否可用(只检查Redis中是否存在)
|
||||
*/
|
||||
public boolean isPortAvailable(int port) {
|
||||
// 检查Redis中是否已使用
|
||||
Boolean isUsed = redisTemplate.opsForSet().isMember(USED_PORTS_KEY, String.valueOf(port));
|
||||
return !Boolean.TRUE.equals(isUsed);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加端口到已用集合
|
||||
*/
|
||||
public boolean addUsedPort(int port) {
|
||||
Long result = redisTemplate.opsForSet().add(USED_PORTS_KEY, String.valueOf(port));
|
||||
return result != null && result > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从已用集合中移除端口
|
||||
*/
|
||||
public boolean removeUsedPort(int port) {
|
||||
Long result = redisTemplate.opsForSet().remove(USED_PORTS_KEY, String.valueOf(port));
|
||||
return result != null && result > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证端口范围参数
|
||||
*/
|
||||
private void validatePortRange(int startPort, int endPort) {
|
||||
if (startPort < 1 || startPort > 65535) {
|
||||
throw new IllegalArgumentException("起始端口必须在1-65535之间");
|
||||
}
|
||||
if (endPort < 1 || endPort > 65535) {
|
||||
throw new IllegalArgumentException("结束端口必须在1-65535之间");
|
||||
}
|
||||
if (startPort > endPort) {
|
||||
throw new IllegalArgumentException("起始端口不能大于结束端口");
|
||||
}
|
||||
}
|
||||
}
|
||||
+100
@@ -0,0 +1,100 @@
|
||||
package com.tongran.rocketmq.service.impl;
|
||||
|
||||
import com.tongran.common.core.utils.DateUtils;
|
||||
import com.tongran.rocketmq.domain.RmFrpcPortMapping;
|
||||
import com.tongran.rocketmq.mapper.RmFrpcPortMappingMapper;
|
||||
import com.tongran.rocketmq.service.IRmFrpcPortMappingService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* FRPC端口映射配置Service业务层处理
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-12-19
|
||||
*/
|
||||
@Service
|
||||
public class RmFrpcPortMappingServiceImpl implements IRmFrpcPortMappingService
|
||||
{
|
||||
@Autowired
|
||||
private RmFrpcPortMappingMapper rmFrpcPortMappingMapper;
|
||||
|
||||
/**
|
||||
* 查询FRPC端口映射配置
|
||||
*
|
||||
* @param id FRPC端口映射配置主键
|
||||
* @return FRPC端口映射配置
|
||||
*/
|
||||
@Override
|
||||
public RmFrpcPortMapping selectRmFrpcPortMappingById(Long id)
|
||||
{
|
||||
return rmFrpcPortMappingMapper.selectRmFrpcPortMappingById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询FRPC端口映射配置列表
|
||||
*
|
||||
* @param rmFrpcPortMapping FRPC端口映射配置
|
||||
* @return FRPC端口映射配置
|
||||
*/
|
||||
@Override
|
||||
public List<RmFrpcPortMapping> selectRmFrpcPortMappingList(RmFrpcPortMapping rmFrpcPortMapping)
|
||||
{
|
||||
return rmFrpcPortMappingMapper.selectRmFrpcPortMappingList(rmFrpcPortMapping);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增FRPC端口映射配置
|
||||
*
|
||||
* @param rmFrpcPortMapping FRPC端口映射配置
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int insertRmFrpcPortMapping(RmFrpcPortMapping rmFrpcPortMapping)
|
||||
{
|
||||
// 清理配置表
|
||||
rmFrpcPortMappingMapper.truncateFrpcPortMapping();
|
||||
// 插入表
|
||||
int rows = rmFrpcPortMappingMapper.insertRmFrpcPortMapping(rmFrpcPortMapping);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改FRPC端口映射配置
|
||||
*
|
||||
* @param rmFrpcPortMapping FRPC端口映射配置
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int updateRmFrpcPortMapping(RmFrpcPortMapping rmFrpcPortMapping)
|
||||
{
|
||||
rmFrpcPortMapping.setUpdateTime(DateUtils.getNowDate());
|
||||
return rmFrpcPortMappingMapper.updateRmFrpcPortMapping(rmFrpcPortMapping);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除FRPC端口映射配置
|
||||
*
|
||||
* @param ids 需要删除的FRPC端口映射配置主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteRmFrpcPortMappingByIds(Long[] ids)
|
||||
{
|
||||
return rmFrpcPortMappingMapper.deleteRmFrpcPortMappingByIds(ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除FRPC端口映射配置信息
|
||||
*
|
||||
* @param id FRPC端口映射配置主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteRmFrpcPortMappingById(Long id)
|
||||
{
|
||||
return rmFrpcPortMappingMapper.deleteRmFrpcPortMappingById(id);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user