Compare commits
48 Commits
master
...
saas_houdu
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
12ca2b2066 | ||
|
|
c91504912b | ||
|
|
bd65b27605 | ||
|
|
68e042d9fc | ||
|
|
1adc72032a | ||
|
|
d9bd70860c | ||
|
|
50d817091e | ||
|
|
2910280746 | ||
|
|
4da0c86ca4 | ||
|
|
70e943269a | ||
|
|
5c3b6df591 | ||
|
|
80533dc1a3 | ||
|
|
4137028deb | ||
|
|
4d1503e988 | ||
|
|
a5b304c809 | ||
|
|
ce95462d74 | ||
|
|
7190df25f7 | ||
|
|
c4b380437f | ||
|
|
5e5330a924 | ||
|
|
b0868dfe2d | ||
|
|
d0ac03ffbf | ||
|
|
e9970b94a9 | ||
|
|
1dc32ec24e | ||
|
|
84e003893d | ||
|
|
fe1763386a | ||
|
|
b38cd83ee1 | ||
|
|
d1db8a5865 | ||
|
|
841dd84a99 | ||
|
|
07baaf07b0 | ||
|
|
01c51b39fe | ||
|
|
c0f057d7ed | ||
|
|
15ecd5caaf | ||
|
|
8c439013e1 | ||
|
|
46bf4c4114 | ||
|
|
36362e2236 | ||
|
|
37eff51e48 | ||
|
|
31d8114c05 | ||
|
|
4fdaadee65 | ||
|
|
52728eba49 | ||
|
|
b0e63880fc | ||
|
|
b3f16d2c8f | ||
|
|
c6937eb44b | ||
|
|
3019f65515 | ||
|
|
87824abb77 | ||
|
|
7da5e19cfa | ||
|
|
054b0f1272 | ||
|
|
6ffdf8d355 | ||
|
|
7b5c782079 |
@@ -7,9 +7,7 @@ import com.ruoyi.common.core.web.page.TableDataInfo;
|
||||
import com.ruoyi.system.api.domain.*;
|
||||
import com.ruoyi.system.api.factory.RemoteRevenueConfigFallbackFactory;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestHeader;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -89,4 +87,50 @@ public interface RemoteRevenueConfigService
|
||||
@PostMapping("/registration/getListByHardwareSn")
|
||||
public R<RmResourceRegistrationRemote> getListByHardwareSn(@RequestBody RmResourceRegistrationRemote rmResourceRegistrationRemote, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
||||
|
||||
/**
|
||||
* 根据clientId获取交换机名称信息
|
||||
* @param rmSwitchManagementRemote
|
||||
* @param source
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/switchManagement/getSwitchNameByClientId")
|
||||
public R<List<RmSwitchManagementRemote>> getSwitchNameByClientId(@RequestBody RmSwitchManagementRemote rmSwitchManagementRemote, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
||||
/**
|
||||
* 根据clientId修改交换机在线状态
|
||||
* @param rmSwitchManagementRemote
|
||||
* @param source
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/switchManagement/updateSwitchMsgByClientId")
|
||||
public R<Integer> updateSwitchMsgByClientId(@RequestBody RmSwitchManagementRemote rmSwitchManagementRemote, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
||||
|
||||
/**
|
||||
* 自动注册
|
||||
* @param rmRegisterMsgRemote
|
||||
* @param source
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/registration/innerAddRegist")
|
||||
public R<Integer> innerAddRegist(@RequestBody RmRegisterMsgRemote rmRegisterMsgRemote, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
||||
/**
|
||||
* 添加节点标识
|
||||
* @param rmResourceRegistrationRemote
|
||||
* @param source
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/registration/innerUpdateRegist")
|
||||
public R<Integer> innerUpdateRegist(@RequestBody RmResourceRegistrationRemote rmResourceRegistrationRemote, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
||||
|
||||
/**
|
||||
* 获取95值列表
|
||||
* @param epsNodeBandwidthRemote
|
||||
* @param source
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/bandwidth/getEpsNodeBandWidthList")
|
||||
public R<List<EpsNodeBandwidthRemote>> getEpsNodeBandWidthList(@RequestBody EpsNodeBandwidthRemote epsNodeBandwidthRemote, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
||||
|
||||
@GetMapping("/businessScript/inner/{id}")
|
||||
public R<EpsBusinessScriptRemote> getBusinessScriptMsgByScriptId(@PathVariable("id") Long id, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
||||
|
||||
}
|
||||
|
||||
@@ -4,6 +4,9 @@ import com.ruoyi.common.core.constant.SecurityConstants;
|
||||
import com.ruoyi.common.core.constant.ServiceNameConstants;
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import com.ruoyi.system.api.domain.RmAlarmRecordRemote;
|
||||
import com.ruoyi.system.api.domain.RmDeployScriptRemote;
|
||||
import com.ruoyi.system.api.domain.RmMonitorPolicyRemote;
|
||||
import com.ruoyi.system.api.domain.RmNetworkInterfaceRemote;
|
||||
import com.ruoyi.system.api.factory.RemoteRocketMqFallbackFactory;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@@ -42,4 +45,57 @@ public interface RemoteRocketMqService {
|
||||
*/
|
||||
@GetMapping("/alarmRecord/alarmHandlingStatus")
|
||||
public R<Map> alarmHandlingStatus(@RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
||||
|
||||
/**
|
||||
* 获取网卡接口列表
|
||||
* @param rmNetworkInterfaceRemote
|
||||
* @param source
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/networkInterface/getNetworkInterfaceList")
|
||||
public R<List<RmNetworkInterfaceRemote>> getNetworkInterfaceList(@RequestBody RmNetworkInterfaceRemote rmNetworkInterfaceRemote, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
||||
|
||||
/**
|
||||
* 获取网卡接口列表
|
||||
* @param rmNetworkInterfaceRemote
|
||||
* @param source
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/networkInterface/bindPublicIp")
|
||||
public R<Integer> bindPublicIp(@RequestBody RmNetworkInterfaceRemote rmNetworkInterfaceRemote, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
||||
/**
|
||||
* 下发策略
|
||||
* @param id
|
||||
* @param source
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/monitorPolicy/innerIssueSwitchPolicy")
|
||||
public R<String> innerIssueSwitchPolicy(Long id, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
||||
/**
|
||||
* 查询策略信息
|
||||
* @param rmMonitorPolicyRemote
|
||||
* @param source
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/monitorPolicy/getPolicyMsgInner")
|
||||
public R<List<RmMonitorPolicyRemote>> getPolicyMsgInner(@RequestBody RmMonitorPolicyRemote rmMonitorPolicyRemote, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
||||
/**
|
||||
* 策略添加新设备
|
||||
* @param rmMonitorPolicyRemote
|
||||
* @param source
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/monitorPolicy/updatePolicyMsgInner")
|
||||
public R<Integer> updatePolicyMsgInner(@RequestBody RmMonitorPolicyRemote rmMonitorPolicyRemote, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
||||
|
||||
/**
|
||||
* 下发优先级为0的策略
|
||||
* @param clientId
|
||||
* @param source
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/monitorPolicy/issueDefaultPolicyByClientId")
|
||||
public R<Integer> issueDefaultPolicyByClientId(String clientId, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
||||
@PostMapping("policy/addDeployScript")
|
||||
R<Integer> addDeployScript(@RequestBody RmDeployScriptRemote addData, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.ruoyi.system.api.domain;
|
||||
|
||||
import com.ruoyi.common.core.annotation.Excel;
|
||||
import com.ruoyi.common.core.web.domain.BaseEntity;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 业务脚本管理对象 eps_business_script
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-10-13
|
||||
*/
|
||||
@Data
|
||||
public class EpsBusinessScriptRemote extends BaseEntity
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 主键ID */
|
||||
private Long id;
|
||||
|
||||
/** 脚本名称 */
|
||||
@Excel(name = "脚本名称")
|
||||
private String scriptName;
|
||||
|
||||
/** 脚本文件地址 */
|
||||
@Excel(name = "脚本文件地址")
|
||||
private String scriptPath;
|
||||
|
||||
/** 脚本默认参数 */
|
||||
@Excel(name = "脚本默认参数")
|
||||
private String defaultParams;
|
||||
/** 结果失败判断关键字 */
|
||||
@Excel(name = "结果失败判断关键字")
|
||||
private String failedKeywords;
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
package com.ruoyi.system.api.domain;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.ruoyi.common.core.annotation.Excel;
|
||||
import com.ruoyi.common.core.web.domain.BaseEntity;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class EpsNodeBandwidthRemote extends BaseEntity {
|
||||
/** id */
|
||||
private Long id;
|
||||
|
||||
/** 节点名称 */
|
||||
@Excel(name = "节点名称")
|
||||
private String nodeName;
|
||||
|
||||
/** 硬件SN */
|
||||
@Excel(name = "硬件SN")
|
||||
private String hardwareSn;
|
||||
/** 带宽值类型
|
||||
* 1-95带宽值Mbps/日
|
||||
* 2-95带宽值Mbps/月
|
||||
* 3-包端带宽值Mbps/日
|
||||
* 4-月均日95值Mbps
|
||||
* 5-有效-95带宽值Mbps/日
|
||||
* 6-有效-95带宽值Mbps/月
|
||||
* 7-有效-月均日95值
|
||||
* */
|
||||
private String bandwidthType;
|
||||
|
||||
/** 带宽值结果 */
|
||||
private BigDecimal bandwidthResult;
|
||||
|
||||
/** 95带宽值Mbps/日 */
|
||||
@Excel(name = "95带宽值Mbps/日")
|
||||
private BigDecimal bandwidth95Daily;
|
||||
|
||||
/** 95带宽值Mbps/月 */
|
||||
@Excel(name = "95带宽值Mbps/月")
|
||||
private BigDecimal bandwidth95Monthly;
|
||||
|
||||
/** 月均日95值 */
|
||||
@Excel(name = "月均日95值")
|
||||
private BigDecimal avgMonthlyBandwidth95;
|
||||
|
||||
/** 包端带宽值Mbps/日 */
|
||||
@Excel(name = "包端带宽值Mbps/日")
|
||||
private BigDecimal packageBandwidthDaily;
|
||||
|
||||
/** 有效-95带宽值Mbps/日 */
|
||||
@Excel(name = "有效-95带宽值Mbps/日")
|
||||
private BigDecimal effectiveBandwidth95Daily;
|
||||
|
||||
/** 有效-95带宽值Mbps/月 */
|
||||
@Excel(name = "有效-95带宽值Mbps/月")
|
||||
private BigDecimal effectiveBandwidth95Monthly;
|
||||
|
||||
/** 有效-月均95值 */
|
||||
@Excel(name = "有效-月均95值")
|
||||
private BigDecimal effectiveAvgMonthlyBandwidth95;
|
||||
/** 金山流量Mbps/日 */
|
||||
private BigDecimal machineFlow;
|
||||
|
||||
/** 设备业务客户id */
|
||||
@Excel(name = "设备业务客户id")
|
||||
private String customerId;
|
||||
|
||||
/** 设备业务客户名称 */
|
||||
@Excel(name = "设备业务客户名称")
|
||||
private String customerName;
|
||||
|
||||
/** 业务号 */
|
||||
@Excel(name = "业务号")
|
||||
private String serviceNumber;
|
||||
|
||||
/** 上联交换机 */
|
||||
@Excel(name = "上联交换机")
|
||||
private String uplinkSwitch;
|
||||
|
||||
/** 创建人id */
|
||||
@Excel(name = "创建人id")
|
||||
private Long creatorId;
|
||||
|
||||
/** 创建人名称 */
|
||||
@Excel(name = "创建人名称")
|
||||
private String creatorName;
|
||||
|
||||
/** 交换机sn */
|
||||
@Excel(name = "交换机sn")
|
||||
private String switchSn;
|
||||
|
||||
/** 接口名称 */
|
||||
@Excel(name = "接口名称")
|
||||
private String interfaceName;
|
||||
|
||||
/** 资源类型(1服务器,2交换机) */
|
||||
@Excel(name = "资源类型")
|
||||
private String resourceType;
|
||||
|
||||
/** 接口连接设备类型(1服务器,2机房出口) */
|
||||
@Excel(name = "接口连接设备类型")
|
||||
private String interfaceLinkDeviceType;
|
||||
/** 业务名称 */
|
||||
@Excel(name = "业务名称")
|
||||
private String businessName;
|
||||
|
||||
/** 业务代码 */
|
||||
@Excel(name = "业务代码")
|
||||
private String businessId;
|
||||
/** 创建时间 */
|
||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||
private Date createTime;
|
||||
/** 开始时间 */
|
||||
private String startTime;
|
||||
/** 结束时间 */
|
||||
private String endTime;
|
||||
/** 月份 */
|
||||
private String monthTime;
|
||||
/** 备注 */
|
||||
private String remark1;
|
||||
/** 创建时间 */
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date createDatetime;
|
||||
|
||||
private List<String> nodeNames;
|
||||
|
||||
private List<String> switchNames;
|
||||
/** 计算方式 */
|
||||
private String calculationMode;
|
||||
/** 客户端id */
|
||||
private String clientId;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.ruoyi.system.api.domain;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class NetworkInfo {
|
||||
// 运营商
|
||||
@JsonProperty("carrier")
|
||||
private String carrier;
|
||||
// 市
|
||||
@JsonProperty("city")
|
||||
private String city;
|
||||
// 网关
|
||||
@JsonProperty("gateway")
|
||||
private String gateway;
|
||||
// IPv4 地址
|
||||
@JsonProperty("ipv4")
|
||||
private String ipv4;
|
||||
// MAC 地址
|
||||
@JsonProperty("mac")
|
||||
private String mac;
|
||||
// 接口名称:eth0, enp3s0
|
||||
@JsonProperty("name")
|
||||
private String name;
|
||||
// 省
|
||||
@JsonProperty("province")
|
||||
private String province;
|
||||
// 公网 IP
|
||||
@JsonProperty("publicIp")
|
||||
private String publicIp;
|
||||
@JsonProperty("type")
|
||||
private String type;
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
package com.ruoyi.system.api.domain;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.ruoyi.common.core.annotation.Excel;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class RmDeployScriptRemote {
|
||||
/** 策略ID */
|
||||
private Long id;
|
||||
|
||||
/** 策略名称 */
|
||||
@Excel(name = "策略名称")
|
||||
private String policyName;
|
||||
|
||||
/** 策略描述 */
|
||||
@Excel(name = "策略描述")
|
||||
private String description;
|
||||
|
||||
/** 关联资源组ID */
|
||||
@Excel(name = "关联资源组ID")
|
||||
private Long resourceGroupId;
|
||||
|
||||
/** 包含的设备ID列表(逗号分隔) */
|
||||
private String includedDevicesId;
|
||||
/** 包含设备 */
|
||||
@Excel(name = "包含设备")
|
||||
private String includedDevicesName;
|
||||
|
||||
/** 源文件地址格式 */
|
||||
@Excel(name = "源文件地址格式")
|
||||
private String sourceFilePathType;
|
||||
/** 源文件路径 */
|
||||
@Excel(name = "源文件路径")
|
||||
private String sourceFilePath;
|
||||
|
||||
/** 目标目录 */
|
||||
@Excel(name = "目标目录")
|
||||
private String targetDirectory;
|
||||
|
||||
/** 命令执行内容 */
|
||||
@Excel(name = "命令执行内容")
|
||||
private String commandContent;
|
||||
|
||||
/** 0=立即执行,1=定时执行 */
|
||||
@Excel(name = "执行方式", readConverterExp = "0=立即执行,1=定时执行")
|
||||
private Integer executionMethod;
|
||||
|
||||
/** 定时执行时间 */
|
||||
@Excel(name = "定时执行时间")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date scheduledTime;
|
||||
/** 定时执行时间(时间戳秒) */
|
||||
private Long policyTime;
|
||||
|
||||
/** 策略状态:0-未下发,1-已下发 */
|
||||
@Excel(name = "策略状态:0-未下发,1-已下发")
|
||||
private String policyStatus;
|
||||
|
||||
/** 策略下发时间 */
|
||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||
@Excel(name = "策略下发时间", width = 30, dateFormat = "yyyy-MM-dd")
|
||||
private Date deployTime;
|
||||
|
||||
/** 脚本类型 */
|
||||
@Excel(name = "脚本类型")
|
||||
private String scriptType;
|
||||
/** 资源组名称 */
|
||||
private String resourceGroupName;
|
||||
/** 资源组置空 */
|
||||
private Boolean resourceGroupIdNull;
|
||||
/** 部署设备 */
|
||||
private String deployDevice;
|
||||
/** 业务脚本名称 */
|
||||
private String scriptName;
|
||||
/** 业务脚本文件地址 */
|
||||
private String scriptPath;
|
||||
/** 业务脚本参数 */
|
||||
private String defaultParams;
|
||||
/** 业务下发名称 */
|
||||
private String taskName;
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.ruoyi.system.api.domain;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.ruoyi.common.core.annotation.Excel;
|
||||
import com.ruoyi.common.core.web.domain.BaseEntity;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
@Data
|
||||
public class RmMonitorPolicyRemote extends BaseEntity {
|
||||
|
||||
/** 主键ID */
|
||||
private Long id;
|
||||
|
||||
|
||||
/** 策略名称 */
|
||||
@Excel(name = "策略名称")
|
||||
private String policyName;
|
||||
|
||||
/** 描述 */
|
||||
@Excel(name = "描述")
|
||||
private String description;
|
||||
|
||||
/** 资源组ID */
|
||||
private Long resourceGroupId;
|
||||
/** 资源组名称 */
|
||||
@Excel(name = "关联资源组")
|
||||
private String resourceGroupName;
|
||||
/** 模板ID */
|
||||
private Long templateId;
|
||||
/** 模板名称 */
|
||||
@Excel(name = "关联监控模板")
|
||||
private String templateName;
|
||||
|
||||
/** 状态:0-待下发,1-已下发 */
|
||||
@Excel(name = "策略状态", readConverterExp = "0=待下发,1=已下发")
|
||||
private String status;
|
||||
|
||||
/** 下发策略时间 */
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@Excel(name = "下发策略时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date deployTime;
|
||||
/** 资源类型,linux switch */
|
||||
private String resourceType;
|
||||
/** 查询条件名称 */
|
||||
private String queryName;
|
||||
/** 创建时间 */
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@Excel(name = "创建时间")
|
||||
private Date createTime;
|
||||
/** 修改时间 */
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@Excel(name = "修改时间")
|
||||
private Date updateTime;
|
||||
/** 交换机类型 */
|
||||
private String switchType;
|
||||
/** 部署设备 */
|
||||
private String deployDevice;
|
||||
/** 优先级 */
|
||||
private String priority;
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.ruoyi.system.api.domain;
|
||||
|
||||
import com.ruoyi.common.core.annotation.Excel;
|
||||
import com.ruoyi.common.core.web.domain.BaseEntity;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class RmNetworkInterfaceRemote extends BaseEntity {
|
||||
/** 主键ID */
|
||||
private Long id;
|
||||
|
||||
/** 客户端ID */
|
||||
@Excel(name = "客户端ID")
|
||||
private String clientId;
|
||||
|
||||
/** 运营商 */
|
||||
@Excel(name = "运营商")
|
||||
private String isp;
|
||||
|
||||
/** 省 */
|
||||
@Excel(name = "省")
|
||||
private String province;
|
||||
|
||||
/** 市 */
|
||||
@Excel(name = "市")
|
||||
private String city;
|
||||
|
||||
/** 公网IP */
|
||||
@Excel(name = "公网IP")
|
||||
private String publicIp;
|
||||
|
||||
/** 接口名称 */
|
||||
@Excel(name = "接口名称")
|
||||
private String interfaceName;
|
||||
|
||||
/** MAC地址 */
|
||||
@Excel(name = "MAC地址")
|
||||
private String macAddress;
|
||||
|
||||
/** 接口类型 */
|
||||
@Excel(name = "接口类型")
|
||||
private String interfaceType;
|
||||
|
||||
/** IPv4地址 */
|
||||
@Excel(name = "IPv4地址")
|
||||
private String ipv4Address;
|
||||
|
||||
/** 网关 */
|
||||
@Excel(name = "网关")
|
||||
private String gateway;
|
||||
/** 绑定ip 1业务IP,2管理ip */
|
||||
private String bindIp;
|
||||
/** 新旧标识 */
|
||||
private Integer newFlag;
|
||||
/** 服务器clientId集合 */
|
||||
private String clientIds;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.ruoyi.system.api.domain;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class RmRegisterMsgRemote {
|
||||
@JsonProperty("clientId")
|
||||
private String clientId;
|
||||
|
||||
@JsonProperty("sn")
|
||||
private String sn;
|
||||
|
||||
@JsonProperty("networkInfo")
|
||||
private List<NetworkInfo> networkInfo;
|
||||
|
||||
@JsonProperty("timestamp")
|
||||
private long timestamp;
|
||||
}
|
||||
@@ -1,9 +1,12 @@
|
||||
package com.ruoyi.system.api.domain;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.ruoyi.common.core.annotation.Excel;
|
||||
import com.ruoyi.common.core.web.domain.BaseEntity;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 资源注册对象 rm_resource_registration
|
||||
*
|
||||
@@ -127,5 +130,53 @@ public class RmResourceRegistrationRemote extends BaseEntity
|
||||
private String monitorItems;
|
||||
/** 自动发现项 */
|
||||
private String discoveryRules;
|
||||
/**
|
||||
* 客户端ID
|
||||
*/
|
||||
private String clientId;
|
||||
|
||||
/**
|
||||
* 运营商
|
||||
*/
|
||||
private String operator;
|
||||
|
||||
/**
|
||||
* 省
|
||||
*/
|
||||
private String province;
|
||||
|
||||
/**
|
||||
* 公网IP
|
||||
*/
|
||||
private String publicIp;
|
||||
|
||||
/**
|
||||
* 业务名称
|
||||
*/
|
||||
private String businessName;
|
||||
|
||||
/**
|
||||
* 逻辑节点标识
|
||||
*/
|
||||
private String logicalNodeId;
|
||||
|
||||
/**
|
||||
* 多公网IP状态
|
||||
*/
|
||||
private String multiPublicIpStatus;
|
||||
|
||||
/**
|
||||
* 心跳次数
|
||||
*/
|
||||
private Integer heartbeatCount;
|
||||
|
||||
/**
|
||||
* 心跳周期(单位:秒)
|
||||
*/
|
||||
private Integer heartbeatInterval;
|
||||
/** 上机时间 */
|
||||
@Excel(name = "上机时间")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date onboardTime;
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
package com.ruoyi.system.api.domain;
|
||||
|
||||
import com.ruoyi.common.core.annotation.Excel;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
@Data
|
||||
public class RmSwitchManagementRemote {
|
||||
/** 主键ID */
|
||||
private Long id;
|
||||
|
||||
/** 交换机名称 */
|
||||
@Excel(name = "交换机名称")
|
||||
private String switchName;
|
||||
|
||||
/** 硬件SN序列号 */
|
||||
@Excel(name = "硬件SN序列号")
|
||||
private String hardwareSn;
|
||||
|
||||
/** SNMP采集地址 */
|
||||
@Excel(name = "SNMP采集地址")
|
||||
private String snmpAddress;
|
||||
|
||||
/** SNMP采集端口 */
|
||||
@Excel(name = "SNMP采集端口")
|
||||
private Long snmpPort;
|
||||
|
||||
/** 在线状态(0-离线,1-在线) */
|
||||
@Excel(name = "在线状态(0-离线,1-在线)")
|
||||
private String onlineStatus;
|
||||
/** 上机时间 */
|
||||
private Date upTime;
|
||||
/** 心跳监测次数 */
|
||||
@Excel(name = "心跳监测次数")
|
||||
private String heartbeatCount;
|
||||
|
||||
/** 心跳监测周期(秒) */
|
||||
@Excel(name = "心跳监测周期(秒)")
|
||||
private String heartbeatInterval;
|
||||
|
||||
/** 心跳检测OID */
|
||||
@Excel(name = "心跳检测OID")
|
||||
private String heartbeatOid;
|
||||
|
||||
/** SNMP版本(v1/v2c/v3) */
|
||||
@Excel(name = "SNMP版本(v1/v2c/v3)")
|
||||
private String snmpVersion;
|
||||
|
||||
/** 读写权限 */
|
||||
@Excel(name = "读写权限")
|
||||
private String readWritePermission;
|
||||
|
||||
/** 安全级别 */
|
||||
@Excel(name = "安全级别")
|
||||
private String securityLevel;
|
||||
|
||||
/** 加密方式 */
|
||||
@Excel(name = "加密方式")
|
||||
private String encryptionMethod;
|
||||
|
||||
/** 团体名称 */
|
||||
@Excel(name = "团体名称")
|
||||
private String communityName;
|
||||
|
||||
/** 密码 */
|
||||
@Excel(name = "密码")
|
||||
private String switchPassword;
|
||||
/** 交换机类型 */
|
||||
private String switchType;
|
||||
/** 用户名 */
|
||||
private String switchUser;
|
||||
/** 自动生成客户端id(uuid) */
|
||||
private String clientId;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.ruoyi.system.api.domain;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class RouteMsg {
|
||||
/** 网卡名称 */
|
||||
private String name;
|
||||
/** 网关地址 */
|
||||
private String gateway;
|
||||
|
||||
}
|
||||
@@ -59,12 +59,42 @@ public class RemoteRevenueConfigFallbackFactory implements FallbackFactory<Remot
|
||||
|
||||
@Override
|
||||
public R<TableDataInfo> getRegistrationList(RmResourceRegistrationRemote rmResourceRegistrationRemote, String source) {
|
||||
return R.fail("获取资源注册列表信息失败" + throwable.getMessage());
|
||||
return R.fail("获取资源注册列表信息失败:" + throwable.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public R<RmResourceRegistrationRemote> getListByHardwareSn(RmResourceRegistrationRemote rmResourceRegistrationRemote, String source) {
|
||||
return R.fail("根据SN获取资源注册列表信息失败" + throwable.getMessage());
|
||||
return R.fail("根据SN获取资源注册列表信息失败:" + throwable.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public R<List<RmSwitchManagementRemote>> getSwitchNameByClientId(RmSwitchManagementRemote rmSwitchManagementRemote, String source) {
|
||||
return R.fail("根据clientId获取交换机信息失败:" + throwable.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public R<Integer> updateSwitchMsgByClientId(RmSwitchManagementRemote rmSwitchManagementRemote, String source) {
|
||||
return R.fail("根据clientId修改交换机信息失败:" + throwable.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public R<Integer> innerAddRegist(RmRegisterMsgRemote rmRegisterMsgRemote, String source) {
|
||||
return R.fail("自动注册失败:" + throwable.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public R<Integer> innerUpdateRegist(RmResourceRegistrationRemote rmResourceRegistrationRemote, String source) {
|
||||
return R.fail("修改服务器注册信息失败:" + throwable.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public R<List<EpsNodeBandwidthRemote>> getEpsNodeBandWidthList(EpsNodeBandwidthRemote epsNodeBandwidthRemote, String source) {
|
||||
return R.fail("获取95值列表失败:" + throwable.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public R<EpsBusinessScriptRemote> getBusinessScriptMsgByScriptId(Long id, String source) {
|
||||
return R.fail("获取错误关键词失败:" + throwable.getMessage());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -3,6 +3,9 @@ package com.ruoyi.system.api.factory;
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import com.ruoyi.system.api.RemoteRocketMqService;
|
||||
import com.ruoyi.system.api.domain.RmAlarmRecordRemote;
|
||||
import com.ruoyi.system.api.domain.RmDeployScriptRemote;
|
||||
import com.ruoyi.system.api.domain.RmMonitorPolicyRemote;
|
||||
import com.ruoyi.system.api.domain.RmNetworkInterfaceRemote;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||
@@ -45,6 +48,41 @@ public class RemoteRocketMqFallbackFactory implements FallbackFactory<RemoteRock
|
||||
public R<Map> alarmHandlingStatus(String source) {
|
||||
return R.fail(throwable.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public R<List<RmNetworkInterfaceRemote>> getNetworkInterfaceList(RmNetworkInterfaceRemote rmNetworkInterfaceRemote, String source) {
|
||||
return R.fail(throwable.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public R<Integer> bindPublicIp(RmNetworkInterfaceRemote rmNetworkInterfaceRemote, String source) {
|
||||
return R.fail(throwable.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public R<String> innerIssueSwitchPolicy(Long id, String source) {
|
||||
return R.fail(throwable.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public R<List<RmMonitorPolicyRemote>> getPolicyMsgInner(RmMonitorPolicyRemote rmMonitorPolicyRemote, String source) {
|
||||
return R.fail(throwable.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public R<Integer> updatePolicyMsgInner(RmMonitorPolicyRemote rmMonitorPolicyRemote, String source) {
|
||||
return R.fail(throwable.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public R<Integer> issueDefaultPolicyByClientId(String clientId, String source) {
|
||||
return R.fail(throwable.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public R<Integer> addDeployScript(RmDeployScriptRemote addData, String source) {
|
||||
return R.fail(throwable.getMessage());
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,12 @@ import lombok.NoArgsConstructor;
|
||||
@NoArgsConstructor
|
||||
public enum MsgEnum {
|
||||
|
||||
多公网IP探测("NETWORK_DETECT"),
|
||||
|
||||
获取最新策略("GET_POLICY"),
|
||||
|
||||
获取最新策略应答("GET_POLICY_RSP"),
|
||||
|
||||
注册("REGISTER"),
|
||||
|
||||
注册应答("REGISTER_RSP"),
|
||||
|
||||
@@ -0,0 +1,240 @@
|
||||
package com.ruoyi.common.core.utils;
|
||||
|
||||
public class ConvertOtherTypeUtil {
|
||||
/**
|
||||
* 根据接口类型代码获取对应的类型名称
|
||||
* @param typeCode 接口类型代码 (1, 2, 3...)
|
||||
* @return 接口类型名称,如果未找到返回 "unknown"
|
||||
*/
|
||||
public static String getInterfaceTypeName(int typeCode) {
|
||||
switch (typeCode) {
|
||||
case 1: return "other";
|
||||
case 2: return "regular1822";
|
||||
case 3: return "hdh1822";
|
||||
case 4: return "ddnX25";
|
||||
case 5: return "rfc877x25";
|
||||
case 6: return "ethernetCsmacd";
|
||||
case 7: return "iso88023Csmacd";
|
||||
case 8: return "iso88024TokenBus";
|
||||
case 9: return "iso88025TokenRing";
|
||||
case 10: return "iso88026Man";
|
||||
case 11: return "starLan";
|
||||
case 12: return "proteon10Mbit";
|
||||
case 13: return "proteon80Mbit";
|
||||
case 14: return "hyperchannel";
|
||||
case 15: return "fddi";
|
||||
case 16: return "lapb";
|
||||
case 17: return "sdlc";
|
||||
case 18: return "ds1";
|
||||
case 19: return "e1";
|
||||
case 20: return "basicISDN";
|
||||
case 21: return "primaryISDN";
|
||||
case 22: return "propPointToPointSerial";
|
||||
case 23: return "ppp";
|
||||
case 24: return "softwareLoopback";
|
||||
case 25: return "eon";
|
||||
case 26: return "ethernet3Mbit";
|
||||
case 27: return "nsip";
|
||||
case 28: return "slip";
|
||||
case 29: return "ultra";
|
||||
case 30: return "ds3";
|
||||
case 31: return "sip";
|
||||
case 32: return "frameRelay";
|
||||
case 33: return "rs232";
|
||||
case 34: return "para";
|
||||
case 35: return "arcnet";
|
||||
case 36: return "arcnetPlus";
|
||||
case 37: return "atm";
|
||||
case 38: return "miox25";
|
||||
case 39: return "sonet";
|
||||
case 40: return "x25ple";
|
||||
case 41: return "iso88022llc";
|
||||
case 42: return "localTalk";
|
||||
case 43: return "smdsDxi";
|
||||
case 44: return "frameRelayService";
|
||||
case 45: return "v35";
|
||||
case 46: return "hssi";
|
||||
case 47: return "hippi";
|
||||
case 48: return "modem";
|
||||
case 49: return "aal5";
|
||||
case 50: return "sonetPath";
|
||||
case 51: return "sonetVT";
|
||||
case 52: return "smdsIcip";
|
||||
case 53: return "propVirtual";
|
||||
case 54: return "propMultiplexor";
|
||||
case 55: return "ieee80212";
|
||||
case 56: return "fibreChannel";
|
||||
case 57: return "hippiInterface";
|
||||
case 58: return "frameRelayInterconnect";
|
||||
case 59: return "aflane8023";
|
||||
case 60: return "aflane8025";
|
||||
case 61: return "cctEmul";
|
||||
case 62: return "fastEther";
|
||||
case 63: return "isdn";
|
||||
case 64: return "v11";
|
||||
case 65: return "v36";
|
||||
case 66: return "g703at64k";
|
||||
case 67: return "g703at2mb";
|
||||
case 68: return "qllc";
|
||||
case 69: return "fastEtherFX";
|
||||
case 70: return "channel";
|
||||
case 71: return "ieee80211";
|
||||
case 72: return "ibm370parChan";
|
||||
case 73: return "escon";
|
||||
case 74: return "dlsw";
|
||||
case 75: return "isdns";
|
||||
case 76: return "isdnu";
|
||||
case 77: return "lapd";
|
||||
case 78: return "ipSwitch";
|
||||
case 79: return "rsrb";
|
||||
case 80: return "atmLogical";
|
||||
case 81: return "ds0";
|
||||
case 82: return "ds0Bundle";
|
||||
case 83: return "bsc";
|
||||
case 84: return "async";
|
||||
case 85: return "cnr";
|
||||
case 86: return "iso88025Dtr";
|
||||
case 87: return "eplrs";
|
||||
case 88: return "arap";
|
||||
case 89: return "propCnls";
|
||||
case 90: return "hostPad";
|
||||
case 91: return "termPad";
|
||||
case 92: return "frameRelayMPI";
|
||||
case 93: return "x213";
|
||||
case 94: return "adsl";
|
||||
case 95: return "radsl";
|
||||
case 96: return "sdsl";
|
||||
case 97: return "vdsl";
|
||||
case 98: return "iso88025CRFPInt";
|
||||
case 99: return "myrinet";
|
||||
case 100: return "voiceEM";
|
||||
case 101: return "voiceFXO";
|
||||
case 102: return "voiceFXS";
|
||||
case 103: return "voiceEncap";
|
||||
case 104: return "voiceOverIp";
|
||||
case 105: return "atmDxi";
|
||||
case 106: return "atmFuni";
|
||||
case 107: return "atmIma";
|
||||
case 108: return "pppMultilinkBundle";
|
||||
case 109: return "ipOverCdlc";
|
||||
case 110: return "ipOverClaw";
|
||||
case 111: return "stackToStack";
|
||||
case 112: return "virtualIpAddress";
|
||||
case 113: return "mpc";
|
||||
case 114: return "ipOverAtm";
|
||||
case 115: return "iso88025Fiber";
|
||||
case 116: return "tdlc";
|
||||
case 117: return "gigabitEthernet";
|
||||
case 118: return "hdlc";
|
||||
case 119: return "lapf";
|
||||
case 120: return "v37";
|
||||
case 121: return "x25mlp";
|
||||
case 122: return "x25huntGroup";
|
||||
case 123: return "trasnpHdlc";
|
||||
case 124: return "interleave";
|
||||
case 125: return "fast";
|
||||
case 126: return "ip";
|
||||
case 127: return "docsCableMaclayer";
|
||||
case 128: return "docsCableDownstream";
|
||||
case 129: return "docsCableUpstream";
|
||||
case 130: return "a12MppSwitch";
|
||||
case 131: return "tunnel";
|
||||
case 132: return "coffee";
|
||||
case 133: return "ces";
|
||||
case 134: return "atmSubInterface";
|
||||
case 135: return "l2vlan";
|
||||
case 136: return "l3ipvlan";
|
||||
case 137: return "l3ipxvlan";
|
||||
case 138: return "digitalPowerline";
|
||||
case 139: return "mediaMailOverIp";
|
||||
case 140: return "dtm";
|
||||
case 141: return "dcn";
|
||||
case 142: return "ipForward";
|
||||
case 143: return "msdsl";
|
||||
case 144: return "ieee1394";
|
||||
case 145: return "if-gsn";
|
||||
case 146: return "dvbRccMacLayer";
|
||||
case 147: return "dvbRccDownstream";
|
||||
case 148: return "dvbRccUpstream";
|
||||
case 149: return "atmVirtual";
|
||||
case 150: return "mplsTunnel";
|
||||
case 151: return "srp";
|
||||
case 152: return "voiceOverAtm";
|
||||
case 153: return "voiceOverFrameRelay";
|
||||
case 154: return "idsl";
|
||||
case 155: return "compositeLink";
|
||||
case 156: return "ss7SigLink";
|
||||
case 157: return "propWirelessP2P";
|
||||
case 158: return "frForward";
|
||||
case 159: return "rfc1483";
|
||||
case 160: return "usb";
|
||||
case 161: return "ieee8023adLag";
|
||||
case 162: return "bgppolicyaccounting";
|
||||
case 163: return "frf16MfrBundle";
|
||||
case 164: return "h323Gatekeeper";
|
||||
case 165: return "h323Proxy";
|
||||
case 166: return "mpls";
|
||||
case 167: return "mfSigLink";
|
||||
case 168: return "hdsl2";
|
||||
case 169: return "shdsl";
|
||||
case 170: return "ds1FDL";
|
||||
case 171: return "pos";
|
||||
case 172: return "dvbAsiIn";
|
||||
case 173: return "dvbAsiOut";
|
||||
case 174: return "plc";
|
||||
case 175: return "nfas";
|
||||
case 176: return "tr008";
|
||||
case 177: return "gr303RDT";
|
||||
case 178: return "gr303IDT";
|
||||
case 179: return "isup";
|
||||
case 180: return "propDocsWirelessMaclayer";
|
||||
case 181: return "propDocsWirelessDownstream";
|
||||
case 182: return "propDocsWirelessUpstream";
|
||||
case 183: return "hiperlan2";
|
||||
case 184: return "propBWAp2Mp";
|
||||
case 185: return "sonetOverheadChannel";
|
||||
case 186: return "digitalWrapperOverheadChannel";
|
||||
case 187: return "aal2";
|
||||
case 188: return "radioMAC";
|
||||
case 189: return "atmRadio";
|
||||
case 190: return "imt";
|
||||
case 191: return "mvl";
|
||||
case 192: return "reachDSL";
|
||||
case 193: return "frDlciEndPt";
|
||||
case 194: return "atmVciEndPt";
|
||||
case 195: return "opticalChannel";
|
||||
case 196: return "opticalTransport";
|
||||
case 197: return "propAtm";
|
||||
case 198: return "voiceOverCable";
|
||||
case 199: return "infiniband";
|
||||
case 200: return "teLink";
|
||||
case 201: return "q2931";
|
||||
case 202: return "virtualTg";
|
||||
case 203: return "sipTg";
|
||||
case 204: return "sipSig";
|
||||
case 205: return "docsCableUpstreamChannel";
|
||||
case 206: return "econet";
|
||||
case 207: return "pon155";
|
||||
case 208: return "pon622";
|
||||
case 209: return "bridge";
|
||||
case 210: return "linegroup";
|
||||
case 211: return "voiceEMFGD";
|
||||
case 212: return "voiceFGDEANA";
|
||||
case 213: return "voiceDID";
|
||||
case 214: return "mpegTransport";
|
||||
case 215: return "sixToFour";
|
||||
case 216: return "gtp";
|
||||
case 217: return "pdnEtherLoop1";
|
||||
case 218: return "pdnEtherLoop2";
|
||||
case 219: return "opticalChannelGroup";
|
||||
case 220: return "homepna";
|
||||
case 221: return "gfp";
|
||||
case 222: return "ciscoISLvlan";
|
||||
case 223: return "actelisMetaLOOP";
|
||||
case 224: return "fcipLink";
|
||||
case 225: return "rpr";
|
||||
case 226: return "qam";
|
||||
default: return "unknown";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,416 @@
|
||||
package com.ruoyi.common.core.utils;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class EchartsDataUtils {
|
||||
|
||||
/**
|
||||
* 构建ECharts图表数据
|
||||
* @param list 原始数据列表
|
||||
* @param timeExtractor 时间字段提取函数
|
||||
* @param dataExtractors 数据提取器Map (key: 数据名称, value: 数据提取函数)
|
||||
* @param <T> 数据类型泛型
|
||||
* @return 包含xData和yData的Map
|
||||
*/
|
||||
public static <T> Map<String, Object> buildEchartsData(
|
||||
List<T> list,
|
||||
Function<T, Date> timeExtractor,
|
||||
Map<String, Function<T, ?>> dataExtractors) {
|
||||
|
||||
// 按时间排序
|
||||
List<T> sortedList = list.stream()
|
||||
.sorted(Comparator.comparing(timeExtractor))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 准备X轴数据
|
||||
List<String> xAxisData = sortedList.stream()
|
||||
.map(item -> DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss", timeExtractor.apply(item)))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 准备Y轴数据
|
||||
Map<String, Object> yData = new LinkedHashMap<>();
|
||||
dataExtractors.forEach((name, extractor) -> {
|
||||
yData.put(name, sortedList.stream().map(extractor).collect(Collectors.toList()));
|
||||
});
|
||||
|
||||
// 构建返回结果
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put("xData", xAxisData);
|
||||
result.put("yData", yData);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 微秒转秒
|
||||
*/
|
||||
public static double convertMicrosecondsToSeconds(long microseconds) {
|
||||
return Math.round(microseconds / 1_000_000.0 * 100.0) / 100.0;
|
||||
}
|
||||
/**
|
||||
* 构建ECharts图表数据(带时间补全和特殊值处理)
|
||||
* @param list 原始数据列表
|
||||
* @param timeExtractor 时间字段提取函数
|
||||
* @param dataExtractors 数据提取器Map
|
||||
* @param startTime 开始时间字符串(格式:yyyy-MM-dd HH:mm:ss)
|
||||
* @param endTime 结束时间字符串(格式:yyyy-MM-dd HH:mm:ss)
|
||||
* @param <T> 数据类型泛型
|
||||
* @return 包含xData和yData的Map
|
||||
*/
|
||||
public static <T> Map<String, Object> buildEchartsDataAutoPadding(
|
||||
List<T> list,
|
||||
Function<T, Date> timeExtractor,
|
||||
Map<String, Function<T, ?>> dataExtractors,
|
||||
String startTime,
|
||||
String endTime) {
|
||||
|
||||
try {
|
||||
// 解析时间字符串
|
||||
Date startDate = parseStringToDate(startTime);
|
||||
Date endDate = parseStringToDate(endTime);
|
||||
|
||||
if (startDate == null || endDate == null) {
|
||||
throw new IllegalArgumentException("开始时间或结束时间格式错误");
|
||||
}
|
||||
|
||||
if (startDate.after(endDate)) {
|
||||
throw new IllegalArgumentException("开始时间不能晚于结束时间");
|
||||
}
|
||||
|
||||
if (list == null || list.isEmpty()) {
|
||||
return createEmptyResult(dataExtractors.keySet(), startTime, endTime);
|
||||
}
|
||||
|
||||
// 按时间排序
|
||||
List<T> sortedList = list.stream()
|
||||
.sorted(Comparator.comparing(timeExtractor))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 自动检测时间间隔
|
||||
long timeInterval = detectTimeInterval(sortedList, timeExtractor);
|
||||
|
||||
// 生成完整的时间序列
|
||||
List<Date> fullTimeSeries = generateTimeSeries(startDate, endDate, timeInterval);
|
||||
|
||||
// 创建时间到数据的映射(考虑时间精度)
|
||||
Map<Long, T> timeDataMap = sortedList.stream()
|
||||
.collect(Collectors.toMap(
|
||||
item -> normalizeTime(timeExtractor.apply(item), timeInterval),
|
||||
Function.identity(),
|
||||
(a, b) -> a
|
||||
));
|
||||
|
||||
// 准备X轴和Y轴数据
|
||||
List<String> xAxisData = new ArrayList<>();
|
||||
Map<String, Object> yData = new LinkedHashMap<>();
|
||||
|
||||
// 初始化Y轴数据结构
|
||||
dataExtractors.keySet().forEach(name ->
|
||||
yData.put(name, new ArrayList<>()));
|
||||
|
||||
// 特殊处理:查找percentile95的固定值
|
||||
Object fixedPercentile95Value = findFixedValueForPercentile95(sortedList, dataExtractors);
|
||||
|
||||
// 检测整个数据集中是否有真实数据
|
||||
boolean hasRealData = checkHasRealData(sortedList, dataExtractors);
|
||||
|
||||
// 记录当前处理的时间点索引
|
||||
int timeIndex = 0;
|
||||
|
||||
for (Date time : fullTimeSeries) {
|
||||
// X轴数据
|
||||
xAxisData.add(parseDateToStr(time));
|
||||
|
||||
// Y轴数据
|
||||
Long normalizedTime = normalizeTime(time, timeInterval);
|
||||
T item = timeDataMap.get(normalizedTime);
|
||||
|
||||
for (Map.Entry<String, Function<T, ?>> entry : dataExtractors.entrySet()) {
|
||||
String name = entry.getKey();
|
||||
Function<T, ?> extractor = entry.getValue();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Object> seriesData = (List<Object>) yData.get(name);
|
||||
|
||||
if (item != null) {
|
||||
Object value = extractor.apply(item);
|
||||
seriesData.add(value != null ? value : getDefaultValue(name, fixedPercentile95Value, timeIndex, hasRealData));
|
||||
} else {
|
||||
// 智能数据补全
|
||||
seriesData.add(getDefaultValue(name, fixedPercentile95Value, timeIndex, hasRealData));
|
||||
}
|
||||
}
|
||||
|
||||
timeIndex++;
|
||||
}
|
||||
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put("xData", xAxisData);
|
||||
result.put("yData", yData);
|
||||
return result;
|
||||
|
||||
} catch (Exception e) {
|
||||
// 记录日志
|
||||
System.err.println("构建图表数据失败: " + e.getMessage());
|
||||
return createEmptyResult(dataExtractors.keySet(), startTime, endTime);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测整个数据集中是否有真实数据(非null)
|
||||
*/
|
||||
private static <T> boolean checkHasRealData(List<T> list, Map<String, Function<T, ?>> dataExtractors) {
|
||||
for (T item : list) {
|
||||
for (Map.Entry<String, Function<T, ?>> entry : dataExtractors.entrySet()) {
|
||||
String name = entry.getKey();
|
||||
Function<T, ?> extractor = entry.getValue();
|
||||
|
||||
Object value = extractor.apply(item);
|
||||
if (value != null) {
|
||||
return true; // 发现至少一个真实数据
|
||||
}
|
||||
}
|
||||
}
|
||||
return false; // 没有发现任何真实数据
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断值是否为0(支持多种数值类型)
|
||||
*/
|
||||
private static boolean isZeroValue(Object value) {
|
||||
if (value == null) return true;
|
||||
|
||||
if (value instanceof Number) {
|
||||
return ((Number) value).doubleValue() == 0.0;
|
||||
}
|
||||
if (value instanceof BigDecimal) {
|
||||
return ((BigDecimal) value).compareTo(BigDecimal.ZERO) == 0;
|
||||
}
|
||||
if (value instanceof String) {
|
||||
try {
|
||||
return new BigDecimal(value.toString()).compareTo(BigDecimal.ZERO) == 0;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 智能获取默认值
|
||||
* 策略:
|
||||
* 1. 如果整个数据集有真实数据:所有缺失点都补null
|
||||
* 2. 如果整个数据集没有真实数据:第一个点补0,其他点补null
|
||||
* 3. percentile95特殊处理:使用固定值
|
||||
*/
|
||||
private static Object getDefaultValue(String metricName, Object fixedPercentile95Value,
|
||||
int timeIndex, boolean hasRealData) {
|
||||
|
||||
// percentile95特殊处理
|
||||
if ("percentile95".equals(metricName) && !fixedPercentile95Value.equals(0)) {
|
||||
return fixedPercentile95Value;
|
||||
}
|
||||
// deployDevice特殊处理
|
||||
if ("deployDevice".equals(metricName)) {
|
||||
return fixedPercentile95Value;
|
||||
}
|
||||
// 智能补全策略
|
||||
if (hasRealData) {
|
||||
// 数据集中有真实数据:所有缺失点都补null
|
||||
return null;
|
||||
} else {
|
||||
// 数据集中没有真实数据:第一个点补0,其他点补null
|
||||
if (timeIndex == 0) {
|
||||
return 0;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建空结果(智能补全策略)
|
||||
*/
|
||||
private static Map<String, Object> createEmptyResult(Set<String> dataNames, String startTime, String endTime) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
|
||||
try {
|
||||
// 解析时间范围
|
||||
Date startDate = parseStringToDate(startTime);
|
||||
Date endDate = parseStringToDate(endTime);
|
||||
|
||||
if (startDate != null && endDate != null && !startDate.after(endDate)) {
|
||||
// 使用默认时间间隔生成完整时间序列
|
||||
long defaultInterval = 300000L; // 5分钟
|
||||
List<Date> fullTimeSeries = generateTimeSeries(startDate, endDate, defaultInterval);
|
||||
|
||||
// 构建x轴数据
|
||||
List<String> xAxisData = new ArrayList<>();
|
||||
for (Date date : fullTimeSeries) {
|
||||
xAxisData.add(parseDateToStr(date));
|
||||
}
|
||||
result.put("xData", xAxisData);
|
||||
|
||||
// 构建y轴数据(空数据集:第一个点补0,其他点补null)
|
||||
Map<String, Object> yData = new LinkedHashMap<>();
|
||||
int dataSize = xAxisData.size();
|
||||
dataNames.forEach(name -> {
|
||||
List<Object> seriesData = new ArrayList<>();
|
||||
for (int i = 0; i < dataSize; i++) {
|
||||
// deployDevice特殊处理:始终补空字符串
|
||||
if ("deployDevice".equals(name)) {
|
||||
seriesData.add("");
|
||||
}
|
||||
else if (i == 0) {
|
||||
// 第一个点补0
|
||||
seriesData.add(0);
|
||||
} else {
|
||||
// 其他点补null
|
||||
seriesData.add(null);
|
||||
}
|
||||
}
|
||||
yData.put(name, seriesData);
|
||||
});
|
||||
result.put("yData", yData);
|
||||
|
||||
} else {
|
||||
// 时间解析失败时返回空数据
|
||||
result.put("xData", new ArrayList<>());
|
||||
Map<String, Object> yData = new LinkedHashMap<>();
|
||||
dataNames.forEach(name -> yData.put(name, new ArrayList<>()));
|
||||
result.put("yData", yData);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
// 异常时返回空数据
|
||||
result.put("xData", new ArrayList<>());
|
||||
Map<String, Object> yData = new LinkedHashMap<>();
|
||||
dataNames.forEach(name -> yData.put(name, new ArrayList<>()));
|
||||
result.put("yData", yData);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查找特殊字段的固定值
|
||||
* percentile95: 第一个非零值
|
||||
* deployDevice: 第一个非空值,没值填充空字符串
|
||||
*/
|
||||
private static <T> Object findFixedValueForPercentile95(List<T> list, Map<String, Function<T, ?>> dataExtractors) {
|
||||
// 处理percentile95字段
|
||||
if (dataExtractors.containsKey("percentile95")) {
|
||||
Function<T, ?> extractor = dataExtractors.get("percentile95");
|
||||
for (T item : list) {
|
||||
Object value = extractor.apply(item);
|
||||
if (value != null && !isZeroValue(value)) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 处理deployDevice字段
|
||||
if (dataExtractors.containsKey("deployDevice")) {
|
||||
Function<T, ?> extractor = dataExtractors.get("deployDevice");
|
||||
for (T item : list) {
|
||||
Object value = extractor.apply(item);
|
||||
if (value != null) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
return ""; // deployDevice没值返回空字符串
|
||||
}
|
||||
|
||||
return 0; // 默认返回0
|
||||
}
|
||||
|
||||
/**
|
||||
* 字符串转日期
|
||||
*/
|
||||
private static Date parseStringToDate(String dateStr) {
|
||||
if (dateStr == null || dateStr.trim().isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
sdf.setLenient(false); // 严格模式
|
||||
return sdf.parse(dateStr);
|
||||
} catch (ParseException e) {
|
||||
System.err.println("日期解析失败: " + dateStr);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 日期转字符串
|
||||
*/
|
||||
private static String parseDateToStr(Date date) {
|
||||
if (date == null) {
|
||||
return "";
|
||||
}
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
return sdf.format(date);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成完整的时间序列
|
||||
*/
|
||||
private static List<Date> generateTimeSeries(Date start, Date end, long interval) {
|
||||
List<Date> timeSeries = new ArrayList<>();
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(start);
|
||||
|
||||
// 确保开始时间对齐到时间间隔
|
||||
long startMillis = normalizeTime(start, interval);
|
||||
calendar.setTimeInMillis(startMillis);
|
||||
|
||||
while (!calendar.getTime().after(end)) {
|
||||
timeSeries.add(calendar.getTime());
|
||||
calendar.setTimeInMillis(calendar.getTimeInMillis() + interval);
|
||||
}
|
||||
return timeSeries;
|
||||
}
|
||||
|
||||
/**
|
||||
* 自动检测时间间隔
|
||||
*/
|
||||
private static <T> long detectTimeInterval(List<T> list, Function<T, Date> timeExtractor) {
|
||||
if (list.size() < 2) {
|
||||
return 300000; // 默认5分钟
|
||||
}
|
||||
|
||||
// 计算时间间隔的众数
|
||||
Map<Long, Integer> intervalCount = new HashMap<>();
|
||||
for (int i = 1; i < list.size(); i++) {
|
||||
long interval = timeExtractor.apply(list.get(i)).getTime() -
|
||||
timeExtractor.apply(list.get(i - 1)).getTime();
|
||||
if (interval > 0) {
|
||||
intervalCount.merge(interval, 1, Integer::sum);
|
||||
}
|
||||
}
|
||||
|
||||
// 如果没有有效间隔,使用默认值
|
||||
if (intervalCount.isEmpty()) {
|
||||
return 300000L;
|
||||
}
|
||||
|
||||
return intervalCount.entrySet().stream()
|
||||
.max(Map.Entry.comparingByValue())
|
||||
.map(Map.Entry::getKey)
|
||||
.orElse(300000L);
|
||||
}
|
||||
|
||||
/**
|
||||
* 时间标准化(对齐到时间间隔)
|
||||
*/
|
||||
private static long normalizeTime(Date time, long interval) {
|
||||
long timeMillis = time.getTime();
|
||||
return (timeMillis / interval) * interval;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,387 @@
|
||||
package com.ruoyi.common.core.utils;
|
||||
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.List;
|
||||
|
||||
public class SpeedUtils {
|
||||
|
||||
public static class SpeedResult {
|
||||
private BigDecimal avgInSpeedGb; // 平均输入速度 (Gb)
|
||||
private BigDecimal avgOutSpeedGb; // 平均输出速度 (Gb)
|
||||
private BigDecimal maxInSpeedGb; // 最大输入速度 (Gb)
|
||||
private BigDecimal maxOutSpeedGb; // 最大输出速度 (Gb)
|
||||
private BigDecimal lastInSpeedGb; // 最后一个输入速度 (Gb)
|
||||
private BigDecimal lastOutSpeedGb;// 最后一个输出速度 (Gb)
|
||||
private String recommendedUnit; // 基于平均值推荐的单位
|
||||
|
||||
public SpeedResult(BigDecimal avgInSpeedGb, BigDecimal avgOutSpeedGb,
|
||||
BigDecimal maxInSpeedGb, BigDecimal maxOutSpeedGb,
|
||||
BigDecimal lastInSpeedGb, BigDecimal lastOutSpeedGb,
|
||||
String recommendedUnit) {
|
||||
this.avgInSpeedGb = avgInSpeedGb;
|
||||
this.avgOutSpeedGb = avgOutSpeedGb;
|
||||
this.maxInSpeedGb = maxInSpeedGb;
|
||||
this.maxOutSpeedGb = maxOutSpeedGb;
|
||||
this.lastInSpeedGb = lastInSpeedGb;
|
||||
this.lastOutSpeedGb = lastOutSpeedGb;
|
||||
this.recommendedUnit = recommendedUnit;
|
||||
}
|
||||
|
||||
// Getters
|
||||
public BigDecimal getAvgInSpeedGb() { return avgInSpeedGb; }
|
||||
public BigDecimal getAvgOutSpeedGb() { return avgOutSpeedGb; }
|
||||
public BigDecimal getMaxInSpeedGb() { return maxInSpeedGb; }
|
||||
public BigDecimal getMaxOutSpeedGb() { return maxOutSpeedGb; }
|
||||
public BigDecimal getLastInSpeedGb() { return lastInSpeedGb; }
|
||||
public BigDecimal getLastOutSpeedGb() { return lastOutSpeedGb; }
|
||||
public String getRecommendedUnit() { return recommendedUnit; }
|
||||
|
||||
public void setRecommendedUnit(String recommendedUnit) {
|
||||
this.recommendedUnit = recommendedUnit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format(
|
||||
"平均输入速度: %s Gb, 平均输出速度: %s Gb\n" +
|
||||
"最大输入速度: %s Gb, 最大输出速度: %s Gb\n" +
|
||||
"最后输入速度: %s Gb, 最后输出速度: %s Gb\n" +
|
||||
"推荐单位(基于平均值): %s",
|
||||
avgInSpeedGb.setScale(2, RoundingMode.HALF_UP),
|
||||
avgOutSpeedGb.setScale(2, RoundingMode.HALF_UP),
|
||||
maxInSpeedGb.setScale(2, RoundingMode.HALF_UP),
|
||||
maxOutSpeedGb.setScale(2, RoundingMode.HALF_UP),
|
||||
lastInSpeedGb.setScale(2, RoundingMode.HALF_UP),
|
||||
lastOutSpeedGb.setScale(2, RoundingMode.HALF_UP),
|
||||
recommendedUnit
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public static SpeedResult calculateWithAverageBasedUnit(List<?> list,
|
||||
String inSpeedField, String outSpeedField)
|
||||
throws NoSuchFieldException, IllegalAccessException {
|
||||
|
||||
if (list == null || list.isEmpty()) {
|
||||
return new SpeedResult(
|
||||
BigDecimal.ZERO, BigDecimal.ZERO,
|
||||
BigDecimal.ZERO, BigDecimal.ZERO,
|
||||
BigDecimal.ZERO, BigDecimal.ZERO,
|
||||
"Kb"
|
||||
);
|
||||
}
|
||||
|
||||
BigDecimal totalInSpeedBit = BigDecimal.ZERO;
|
||||
BigDecimal totalOutSpeedBit = BigDecimal.ZERO;
|
||||
BigDecimal maxInSpeedGb = BigDecimal.ZERO;
|
||||
BigDecimal maxOutSpeedGb = BigDecimal.ZERO;
|
||||
BigDecimal lastInSpeedGb = BigDecimal.ZERO;
|
||||
BigDecimal lastOutSpeedGb = BigDecimal.ZERO;
|
||||
|
||||
final BigDecimal GB_DIVISOR = new BigDecimal("1000000000");
|
||||
|
||||
// 计算总和(bit)和Gb值
|
||||
for (Object obj : list) {
|
||||
try {
|
||||
java.lang.reflect.Field inField = obj.getClass().getDeclaredField(inSpeedField);
|
||||
java.lang.reflect.Field outField = obj.getClass().getDeclaredField(outSpeedField);
|
||||
|
||||
inField.setAccessible(true);
|
||||
outField.setAccessible(true);
|
||||
|
||||
BigDecimal inSpeedBit = (BigDecimal) inField.get(obj) == null ? BigDecimal.ZERO : (BigDecimal) inField.get(obj);
|
||||
BigDecimal outSpeedBit = (BigDecimal) outField.get(obj) == null ? BigDecimal.ZERO : (BigDecimal) outField.get(obj);
|
||||
|
||||
// 累加bit值(用于计算平均值)
|
||||
totalInSpeedBit = totalInSpeedBit.add(inSpeedBit);
|
||||
totalOutSpeedBit = totalOutSpeedBit.add(outSpeedBit);
|
||||
|
||||
// 转换为Gb并更新最大值
|
||||
BigDecimal inSpeedGb = inSpeedBit.divide(GB_DIVISOR, 2, RoundingMode.HALF_UP);
|
||||
BigDecimal outSpeedGb = outSpeedBit.divide(GB_DIVISOR, 2, RoundingMode.HALF_UP);
|
||||
|
||||
maxInSpeedGb = maxInSpeedGb.max(inSpeedGb);
|
||||
maxOutSpeedGb = maxOutSpeedGb.max(outSpeedGb);
|
||||
|
||||
// 记录最后一个值
|
||||
lastInSpeedGb = inSpeedGb;
|
||||
lastOutSpeedGb = outSpeedGb;
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("无法获取速度字段值", e);
|
||||
}
|
||||
}
|
||||
|
||||
// 计算Gb平均值
|
||||
BigDecimal size = new BigDecimal(list.size());
|
||||
BigDecimal avgInSpeedGb = totalInSpeedBit.divide(GB_DIVISOR, 2, RoundingMode.HALF_UP)
|
||||
.divide(size, 2, RoundingMode.HALF_UP);
|
||||
BigDecimal avgOutSpeedGb = totalOutSpeedBit.divide(GB_DIVISOR, 2, RoundingMode.HALF_UP)
|
||||
.divide(size, 2, RoundingMode.HALF_UP);
|
||||
|
||||
// 基于平均值的较大值确定推荐单位
|
||||
BigDecimal maxAvgBit = avgInSpeedGb.compareTo(avgOutSpeedGb) > 0 ?
|
||||
avgInSpeedGb.multiply(GB_DIVISOR) :
|
||||
avgOutSpeedGb.multiply(GB_DIVISOR);
|
||||
|
||||
String recommendedUnit;
|
||||
if (maxAvgBit.compareTo(new BigDecimal("1000000000")) >= 0) {
|
||||
recommendedUnit = "Gb";
|
||||
} else if (maxAvgBit.compareTo(new BigDecimal("1000000")) >= 0) {
|
||||
recommendedUnit = "Mb";
|
||||
} else{
|
||||
recommendedUnit = "Kb";
|
||||
}
|
||||
|
||||
return new SpeedResult(
|
||||
avgInSpeedGb, avgOutSpeedGb,
|
||||
maxInSpeedGb, maxOutSpeedGb,
|
||||
lastInSpeedGb, lastOutSpeedGb,
|
||||
recommendedUnit
|
||||
);
|
||||
}
|
||||
// 工具方法:获取单位换算除数
|
||||
public static BigDecimal getDivisor(String unit) {
|
||||
switch (unit) {
|
||||
case "Gb": return new BigDecimal("1000000000");
|
||||
case "Mb": return new BigDecimal("1000000");
|
||||
case "Kb": return new BigDecimal("1000");
|
||||
default: return BigDecimal.ONE; // bit
|
||||
}
|
||||
}
|
||||
public static String calculateUnit(List<?> list,
|
||||
String inSpeedField, String outSpeedField)
|
||||
throws NoSuchFieldException, IllegalAccessException {
|
||||
|
||||
if (list == null || list.isEmpty()) {
|
||||
return "Kb";
|
||||
}
|
||||
|
||||
BigDecimal totalInSpeedBit = BigDecimal.ZERO;
|
||||
BigDecimal totalOutSpeedBit = BigDecimal.ZERO;
|
||||
BigDecimal maxInSpeedGb = BigDecimal.ZERO;
|
||||
BigDecimal maxOutSpeedGb = BigDecimal.ZERO;
|
||||
BigDecimal lastInSpeedGb = BigDecimal.ZERO;
|
||||
BigDecimal lastOutSpeedGb = BigDecimal.ZERO;
|
||||
|
||||
final BigDecimal GB_DIVISOR = new BigDecimal("1000000000");
|
||||
|
||||
// 计算总和(bit)和Gb值
|
||||
for (Object obj : list) {
|
||||
try {
|
||||
java.lang.reflect.Field inField = obj.getClass().getDeclaredField(inSpeedField);
|
||||
java.lang.reflect.Field outField = obj.getClass().getDeclaredField(outSpeedField);
|
||||
|
||||
inField.setAccessible(true);
|
||||
outField.setAccessible(true);
|
||||
|
||||
BigDecimal inSpeedBit = (BigDecimal) inField.get(obj) == null ? BigDecimal.ZERO : (BigDecimal) inField.get(obj);
|
||||
BigDecimal outSpeedBit = (BigDecimal) outField.get(obj) == null ? BigDecimal.ZERO : (BigDecimal) outField.get(obj);
|
||||
|
||||
// 累加bit值(用于计算平均值)
|
||||
totalInSpeedBit = totalInSpeedBit.add(inSpeedBit);
|
||||
totalOutSpeedBit = totalOutSpeedBit.add(outSpeedBit);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("无法获取速度字段值", e);
|
||||
}
|
||||
}
|
||||
|
||||
// 计算Gb平均值
|
||||
BigDecimal size = new BigDecimal(list.size());
|
||||
BigDecimal avgInSpeedGb = totalInSpeedBit.divide(size, 2, RoundingMode.HALF_UP);
|
||||
BigDecimal avgOutSpeedGb = totalOutSpeedBit.divide(size, 2, RoundingMode.HALF_UP);
|
||||
|
||||
// 基于平均值的较大值确定推荐单位
|
||||
BigDecimal maxAvgBit = avgInSpeedGb.compareTo(avgOutSpeedGb) > 0 ?
|
||||
avgInSpeedGb : avgOutSpeedGb;
|
||||
|
||||
String recommendedUnit;
|
||||
if (maxAvgBit.compareTo(new BigDecimal("1000000000")) >= 0) {
|
||||
recommendedUnit = "Gb";
|
||||
} else if (maxAvgBit.compareTo(new BigDecimal("1000000")) >= 0) {
|
||||
recommendedUnit = "Mb";
|
||||
} else{
|
||||
recommendedUnit = "Kb";
|
||||
}
|
||||
|
||||
return recommendedUnit;
|
||||
}
|
||||
/**
|
||||
* 计算String类型(存储数字)的速度统计结果
|
||||
* @param list 数据列表
|
||||
* @param inSpeedField 输入速度字段名
|
||||
* @param outSpeedField 输出速度字段名
|
||||
* @return SpeedResult 速度统计结果
|
||||
*/
|
||||
public static SpeedResult calculateWithStringTraffic(List<?> list,
|
||||
String inSpeedField, String outSpeedField)
|
||||
throws NoSuchFieldException, IllegalAccessException {
|
||||
|
||||
if (list == null || list.isEmpty()) {
|
||||
return new SpeedResult(
|
||||
BigDecimal.ZERO, BigDecimal.ZERO,
|
||||
BigDecimal.ZERO, BigDecimal.ZERO,
|
||||
BigDecimal.ZERO, BigDecimal.ZERO,
|
||||
"bit"
|
||||
);
|
||||
}
|
||||
|
||||
BigDecimal totalInSpeedBit = BigDecimal.ZERO;
|
||||
BigDecimal totalOutSpeedBit = BigDecimal.ZERO;
|
||||
BigDecimal maxInSpeedGb = BigDecimal.ZERO;
|
||||
BigDecimal maxOutSpeedGb = BigDecimal.ZERO;
|
||||
BigDecimal lastInSpeedGb = BigDecimal.ZERO;
|
||||
BigDecimal lastOutSpeedGb = BigDecimal.ZERO;
|
||||
|
||||
final BigDecimal GB_DIVISOR = new BigDecimal("1000000000");
|
||||
|
||||
// 计算总和(bit)和Gb值
|
||||
for (Object obj : list) {
|
||||
try {
|
||||
java.lang.reflect.Field inField = obj.getClass().getDeclaredField(inSpeedField);
|
||||
java.lang.reflect.Field outField = obj.getClass().getDeclaredField(outSpeedField);
|
||||
|
||||
inField.setAccessible(true);
|
||||
outField.setAccessible(true);
|
||||
|
||||
// 处理String类型的数字值
|
||||
String inSpeedStr = (String) inField.get(obj);
|
||||
String outSpeedStr = (String) outField.get(obj);
|
||||
|
||||
BigDecimal inSpeedBit = convertStringToBigDecimal(inSpeedStr);
|
||||
BigDecimal outSpeedBit = convertStringToBigDecimal(outSpeedStr);
|
||||
|
||||
// 累加bit值(用于计算平均值)
|
||||
totalInSpeedBit = totalInSpeedBit.add(inSpeedBit);
|
||||
totalOutSpeedBit = totalOutSpeedBit.add(outSpeedBit);
|
||||
|
||||
// 转换为Gb并更新最大值
|
||||
BigDecimal inSpeedGb = inSpeedBit.divide(GB_DIVISOR, 2, RoundingMode.HALF_UP);
|
||||
BigDecimal outSpeedGb = outSpeedBit.divide(GB_DIVISOR, 2, RoundingMode.HALF_UP);
|
||||
|
||||
maxInSpeedGb = maxInSpeedGb.max(inSpeedGb);
|
||||
maxOutSpeedGb = maxOutSpeedGb.max(outSpeedGb);
|
||||
|
||||
// 记录最后一个值
|
||||
lastInSpeedGb = inSpeedGb;
|
||||
lastOutSpeedGb = outSpeedGb;
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("无法获取或转换速度字段值", e);
|
||||
}
|
||||
}
|
||||
|
||||
// 计算Gb平均值
|
||||
BigDecimal size = new BigDecimal(list.size());
|
||||
BigDecimal avgInSpeedGb = totalInSpeedBit.divide(GB_DIVISOR, 2, RoundingMode.HALF_UP)
|
||||
.divide(size, 2, RoundingMode.HALF_UP);
|
||||
BigDecimal avgOutSpeedGb = totalOutSpeedBit.divide(GB_DIVISOR, 2, RoundingMode.HALF_UP)
|
||||
.divide(size, 2, RoundingMode.HALF_UP);
|
||||
|
||||
// 基于平均值的较大值确定推荐单位
|
||||
BigDecimal maxAvgBit = avgInSpeedGb.compareTo(avgOutSpeedGb) > 0 ?
|
||||
avgInSpeedGb.multiply(GB_DIVISOR) :
|
||||
avgOutSpeedGb.multiply(GB_DIVISOR);
|
||||
|
||||
String recommendedUnit;
|
||||
if (maxAvgBit.compareTo(new BigDecimal("1000000000")) >= 0) {
|
||||
recommendedUnit = "Gb";
|
||||
} else if (maxAvgBit.compareTo(new BigDecimal("1000000")) >= 0) {
|
||||
recommendedUnit = "Mb";
|
||||
} else {
|
||||
recommendedUnit = "Kb";
|
||||
}
|
||||
|
||||
return new SpeedResult(
|
||||
avgInSpeedGb, avgOutSpeedGb,
|
||||
maxInSpeedGb, maxOutSpeedGb,
|
||||
lastInSpeedGb, lastOutSpeedGb,
|
||||
recommendedUnit
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将String类型的数字转换为BigDecimal
|
||||
* @param numberStr 数字字符串
|
||||
* @return BigDecimal值,转换失败返回0
|
||||
*/
|
||||
private static BigDecimal convertStringToBigDecimal(String numberStr) {
|
||||
if (numberStr == null || numberStr.trim().isEmpty()) {
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
try {
|
||||
return new BigDecimal(numberStr.trim());
|
||||
} catch (Exception e) {
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 仅计算String类型(存储数字)的推荐单位
|
||||
* @param list 数据列表
|
||||
* @param inSpeedField 输入速度字段名
|
||||
* @param outSpeedField 输出速度字段名
|
||||
* @return 推荐单位
|
||||
*/
|
||||
public static String calculateUnitWithStringTraffic(List<?> list,
|
||||
String inSpeedField, String outSpeedField)
|
||||
throws NoSuchFieldException, IllegalAccessException {
|
||||
|
||||
if (list == null || list.isEmpty()) {
|
||||
return "Kb";
|
||||
}
|
||||
|
||||
BigDecimal totalInSpeedBit = BigDecimal.ZERO;
|
||||
BigDecimal totalOutSpeedBit = BigDecimal.ZERO;
|
||||
|
||||
// 计算总和(bit)
|
||||
for (Object obj : list) {
|
||||
try {
|
||||
java.lang.reflect.Field inField = obj.getClass().getDeclaredField(inSpeedField);
|
||||
java.lang.reflect.Field outField = obj.getClass().getDeclaredField(outSpeedField);
|
||||
|
||||
inField.setAccessible(true);
|
||||
outField.setAccessible(true);
|
||||
|
||||
// 处理String类型的数字值
|
||||
String inSpeedStr = (String) inField.get(obj);
|
||||
String outSpeedStr = (String) outField.get(obj);
|
||||
|
||||
BigDecimal inSpeedBit = convertStringToBigDecimal(inSpeedStr);
|
||||
BigDecimal outSpeedBit = convertStringToBigDecimal(outSpeedStr);
|
||||
|
||||
totalInSpeedBit = totalInSpeedBit.add(inSpeedBit);
|
||||
totalOutSpeedBit = totalOutSpeedBit.add(outSpeedBit);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("无法获取或转换速度字段值", e);
|
||||
}
|
||||
}
|
||||
|
||||
// 计算平均值
|
||||
BigDecimal size = new BigDecimal(list.size());
|
||||
BigDecimal avgInSpeedBit = totalInSpeedBit.divide(size, 2, RoundingMode.HALF_UP);
|
||||
BigDecimal avgOutSpeedBit = totalOutSpeedBit.divide(size, 2, RoundingMode.HALF_UP);
|
||||
|
||||
// 基于平均值的较大值确定推荐单位
|
||||
BigDecimal maxAvgBit = avgInSpeedBit.compareTo(avgOutSpeedBit) > 0 ?
|
||||
avgInSpeedBit : avgOutSpeedBit;
|
||||
|
||||
String recommendedUnit;
|
||||
if (maxAvgBit.compareTo(new BigDecimal("1000000000")) >= 0) {
|
||||
recommendedUnit = "Gb";
|
||||
} else if (maxAvgBit.compareTo(new BigDecimal("1000000")) >= 0) {
|
||||
recommendedUnit = "Mb";
|
||||
} else {
|
||||
recommendedUnit = "Kb";
|
||||
}
|
||||
|
||||
return recommendedUnit;
|
||||
}
|
||||
|
||||
// Mbit 转 Bit 换算:1 Mbit = 1,000,000 Bit
|
||||
public static BigDecimal mbitToBit(BigDecimal mbitValue) {
|
||||
if (mbitValue == null) return BigDecimal.ZERO;
|
||||
return mbitValue.multiply(new BigDecimal("1000000"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,171 @@
|
||||
package com.ruoyi.common.core.utils;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class UnitChangeUtil {
|
||||
|
||||
private static final double GB = 1024.0 * 1024.0 * 1024.0;
|
||||
|
||||
/**
|
||||
* long类型字节转化为Gb
|
||||
* @param bytes
|
||||
* @return
|
||||
*/
|
||||
public static double bytesToGb(long bytes) {
|
||||
double gb = bytes / GB;
|
||||
BigDecimal bd = new BigDecimal(gb);
|
||||
bd = bd.setScale(2, RoundingMode.HALF_UP);
|
||||
return bd.doubleValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* String类型字节转化为Gb
|
||||
* @param bytes
|
||||
* @return
|
||||
*/
|
||||
public static BigDecimal bytesToGb(String bytes) {
|
||||
// 参数校验
|
||||
if (bytes == null || bytes.trim().isEmpty()) {
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
BigDecimal bytesValue = new BigDecimal(bytes);
|
||||
BigDecimal bd = bytesValue.divide(BigDecimal.valueOf(GB), 2, RoundingMode.HALF_UP);
|
||||
return bd;
|
||||
}
|
||||
|
||||
/**
|
||||
* Kb转化为Gb
|
||||
* @param kbValue
|
||||
* @return
|
||||
*/
|
||||
public static double convertKbToGb(String kbValue) {
|
||||
if (kbValue == null || kbValue.trim().isEmpty()) {
|
||||
throw new IllegalArgumentException("KB值不能为空");
|
||||
}
|
||||
|
||||
double kb = Double.parseDouble(kbValue.trim());
|
||||
double gb = kb / (1024.0 * 1024.0);
|
||||
|
||||
BigDecimal bd = new BigDecimal(gb);
|
||||
bd = bd.setScale(2, RoundingMode.HALF_UP);
|
||||
return bd.doubleValue();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 工具方法:将毫秒值转换为运行时长
|
||||
* @param uptimeMillis
|
||||
* @return
|
||||
*/
|
||||
public static String formatUptime(long uptimeMillis) {
|
||||
if (uptimeMillis <= 0) {
|
||||
return "0秒";
|
||||
}
|
||||
|
||||
long days = TimeUnit.MILLISECONDS.toDays(uptimeMillis);
|
||||
long hours = TimeUnit.MILLISECONDS.toHours(uptimeMillis) % 24;
|
||||
long minutes = TimeUnit.MILLISECONDS.toMinutes(uptimeMillis) % 60;
|
||||
long seconds = TimeUnit.MILLISECONDS.toSeconds(uptimeMillis) % 60;
|
||||
|
||||
long months = days / 30;
|
||||
days = days % 30;
|
||||
|
||||
return String.format("%d个月%d天%d小时%d分%d秒", months, days, hours, minutes, seconds);
|
||||
}
|
||||
|
||||
/**
|
||||
* 工具方法- 将秒值转换为运行时长
|
||||
* @param uptimeSeconds
|
||||
* @return
|
||||
*/
|
||||
public static String formatUptimeSeconds(long uptimeSeconds) {
|
||||
if (uptimeSeconds <= 0) {
|
||||
return "0秒";
|
||||
}
|
||||
|
||||
long days = TimeUnit.SECONDS.toDays(uptimeSeconds);
|
||||
long hours = TimeUnit.SECONDS.toHours(uptimeSeconds) % 24;
|
||||
long minutes = TimeUnit.SECONDS.toMinutes(uptimeSeconds) % 60;
|
||||
long seconds = uptimeSeconds % 60;
|
||||
|
||||
long months = days / 30;
|
||||
days = days % 30;
|
||||
|
||||
return String.format("%d个月%d天%d小时%d分%d秒", months, days, hours, minutes, seconds);
|
||||
}
|
||||
/**
|
||||
* 将字符串小数值格式化为保留两位小数(高精度)
|
||||
* @param numberStr 数字字符串
|
||||
* @return 保留两位小数的字符串,如果转换失败返回原字符串
|
||||
*/
|
||||
public static String formatDecimal(String numberStr) {
|
||||
if (numberStr == null || numberStr.trim().isEmpty()) {
|
||||
return numberStr;
|
||||
}
|
||||
|
||||
try {
|
||||
if("NaN".equals(numberStr)){
|
||||
numberStr = "0";
|
||||
}
|
||||
BigDecimal number = new BigDecimal(numberStr);
|
||||
return number.setScale(1, RoundingMode.HALF_UP).toString();
|
||||
} catch (NumberFormatException e) {
|
||||
return numberStr; // 转换失败返回原字符串
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 次数单位换算
|
||||
* @param count
|
||||
* @return
|
||||
*/
|
||||
public static String formatWithUnit(long count) {
|
||||
String[] units = {"", "万", "百万", "亿"};
|
||||
double[] divisors = {1, 10_000.0, 1_000_000.0, 100_000_000.0};
|
||||
|
||||
int unitIndex = 0;
|
||||
double value = count;
|
||||
|
||||
for (int i = divisors.length - 1; i >= 0; i--) {
|
||||
if (count >= divisors[i]) {
|
||||
unitIndex = i;
|
||||
value = count / divisors[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 根据数值大小决定小数位数
|
||||
String formatPattern = (value >= 100 || unitIndex == 0) ? "%.0f %s次" : "%.1f %s次";
|
||||
return String.format(formatPattern, value, units[unitIndex]).trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* 简洁版本:所有值都显示为KB及以上单位
|
||||
*/
|
||||
public static String formatWithKbMin(long bytes) {
|
||||
if (bytes == 0) {
|
||||
return "0.00 KB";
|
||||
}
|
||||
|
||||
final String[] units = {"KB", "MB", "GB", "TB"};
|
||||
double value = bytes / 1024.0;
|
||||
int unitIndex = 0;
|
||||
|
||||
while (value >= 1024 && unitIndex < units.length - 1) {
|
||||
value /= 1024;
|
||||
unitIndex++;
|
||||
}
|
||||
|
||||
// 四舍五入到两位小数
|
||||
double roundedValue = Math.round(value * 100.0) / 100.0;
|
||||
|
||||
// 处理四舍五入后可能出现的情况
|
||||
if (roundedValue == 0.0 && value > 0) {
|
||||
roundedValue = 0.01; // 最小值显示为0.01而不是0.00
|
||||
}
|
||||
|
||||
return String.format("%.2f %s", roundedValue, units[unitIndex]);
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,7 @@
|
||||
<module>ruoyi-gen</module>
|
||||
<module>ruoyi-job</module>
|
||||
<module>ruoyi-file</module>
|
||||
<module>ruoyi-mtragent</module>
|
||||
</modules>
|
||||
|
||||
<artifactId>ruoyi-modules</artifactId>
|
||||
|
||||
100
ruoyi-modules/ruoyi-mtragent/pom.xml
Normal file
100
ruoyi-modules/ruoyi-mtragent/pom.xml
Normal file
@@ -0,0 +1,100 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
<artifactId>ruoyi-modules</artifactId>
|
||||
<version>3.6.6</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>ruoyi-modules-mtragent</artifactId>
|
||||
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<!--rocketmq消息队列-->
|
||||
<dependency>
|
||||
<groupId>org.apache.rocketmq</groupId>
|
||||
<artifactId>rocketmq-client</artifactId>
|
||||
<version> 4.9.0</version>
|
||||
</dependency>
|
||||
|
||||
<!-- SpringCloud Alibaba Nacos -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- SpringCloud Alibaba Nacos Config -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-client</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- SpringCloud Alibaba Sentinel -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- SpringBoot Actuator -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Mysql驱动包 -->
|
||||
<dependency>
|
||||
<groupId>com.mysql</groupId>
|
||||
<artifactId>mysql-connector-j</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- RuoYi Common Log -->
|
||||
<dependency>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
<artifactId>ruoyi-common-log</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- RuoYi Common Swagger-->
|
||||
<dependency>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
<artifactId>ruoyi-common-swagger</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
<artifactId>ruoyi-common-security</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- yml调用pom变量 -->
|
||||
<dependency>
|
||||
<groupId>org.yaml</groupId>
|
||||
<artifactId>snakeyaml</artifactId>
|
||||
<version>1.28</version>
|
||||
</dependency>
|
||||
|
||||
<!-- SpringBoot Web -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.ruoyi.testrocketmq;
|
||||
package com.ruoyi.mtragent;
|
||||
|
||||
import com.ruoyi.common.security.annotation.EnableCustomConfig;
|
||||
import com.ruoyi.common.security.annotation.EnableRyFeignClients;
|
||||
@@ -15,11 +15,11 @@ import org.springframework.scheduling.annotation.EnableAsync;
|
||||
@EnableRyFeignClients
|
||||
@SpringBootApplication
|
||||
@EnableAsync
|
||||
public class RocketMQApplication
|
||||
public class RuoYiMtragentApplication
|
||||
{
|
||||
public static void main(String[] args)
|
||||
{
|
||||
SpringApplication.run(RocketMQApplication.class, args);
|
||||
System.out.println("(♥◠‿◠)ノ゙ RocketMQ模块启动成功 ლ(´ڡ`ლ)゙");
|
||||
SpringApplication.run(RuoYiMtragentApplication.class, args);
|
||||
System.out.println("(♥◠‿◠)ノ゙ RuoYiMtragent模块启动成功 ლ(´ڡ`ლ)゙");
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.ruoyi.testrocketmq.config;
|
||||
package com.ruoyi.mtragent.config;
|
||||
|
||||
import com.ruoyi.testrocketmq.consumer.RocketMsgListener;
|
||||
import com.ruoyi.testrocketmq.enums.MessageCodeEnum;
|
||||
import com.ruoyi.testrocketmq.model.ConsumerMode;
|
||||
import com.ruoyi.mtragent.consumer.RocketMsgListener;
|
||||
import com.ruoyi.mtragent.enums.MessageTopic;
|
||||
import com.ruoyi.mtragent.model.ConsumerMode;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
|
||||
import org.apache.rocketmq.client.exception.MQClientException;
|
||||
@@ -12,6 +12,8 @@ import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 消费者配置
|
||||
*/
|
||||
@@ -19,17 +21,22 @@ import org.springframework.context.annotation.Configuration;
|
||||
@Configuration
|
||||
@Slf4j
|
||||
public class ConsumerConfig {
|
||||
|
||||
@Autowired
|
||||
private ConsumerMode consumerMode;
|
||||
|
||||
@Autowired
|
||||
private RocketMsgListener rocketMsgListener;
|
||||
|
||||
@Bean
|
||||
public DefaultMQPushConsumer getRocketMQConsumer() throws MQClientException {
|
||||
// ConsumerMode consumerMode = new ConsumerMode();
|
||||
DefaultMQPushConsumer consumer = new DefaultMQPushConsumer(consumerMode.getGroupName());
|
||||
public DefaultMQPushConsumer getRocketMQConsumer() {
|
||||
//构建客户端连接
|
||||
DefaultMQPushConsumer consumer = new DefaultMQPushConsumer(consumerMode.getAgentGroup());
|
||||
//
|
||||
consumer.setNamesrvAddr(consumerMode.getNamesrvAddr());
|
||||
consumer.setConsumeThreadMin(consumerMode.getConsumeThreadMin());
|
||||
consumer.setConsumeThreadMax(consumerMode.getConsumeThreadMax());
|
||||
consumer.registerMessageListener(new RocketMsgListener());
|
||||
consumer.registerMessageListener(rocketMsgListener);
|
||||
/**
|
||||
* 1. CONSUME_FROM_LAST_OFFSET:第一次启动从队列最后位置消费,后续再启动接着上次消费的进度开始消费
|
||||
* 2. CONSUME_FROM_FIRST_OFFSET:第一次启动从队列初始位置消费,后续再启动接着上次消费的进度开始消费
|
||||
@@ -41,7 +48,7 @@ public class ConsumerConfig {
|
||||
* CLUSTERING (集群模式) :默认模式,同一个ConsumerGroup(groupName相同)每个consumer只消费所订阅消息的一部分内容,同一个ConsumerGroup里所有的Consumer消息加起来才是所
|
||||
* 订阅topic整体,从而达到负载均衡的目的
|
||||
* BROADCASTING (广播模式) :同一个ConsumerGroup每个consumer都消费到所订阅topic所有消息,也就是一个消费会被多次分发,被多个consumer消费。
|
||||
*
|
||||
* 需要注意的是,在广播模式下,每个Consumer都会独立地处理相同的消息副本。这可能会导致一些潜在的问题,例如消息重复处理或者资源浪费。因此,在使用广播模式时,请确保消息的处理逻辑是幂等的,并仔细考虑系统资源的消耗。
|
||||
*/
|
||||
// consumer.setMessageModel(MessageModel.BROADCASTING);
|
||||
|
||||
@@ -50,11 +57,17 @@ public class ConsumerConfig {
|
||||
try {
|
||||
/**
|
||||
* 订阅topic,可以对指定消息进行过滤,例如:"TopicTest","tagl||tag2||tag3",*或null表示topic所有消息
|
||||
* 由于官方并没有给直接订阅全部消息示例 所以使用list列表循环订阅所有topic
|
||||
*/
|
||||
consumer.subscribe(MessageCodeEnum.ORDER_MESSAGE.getCode(),"*");
|
||||
consumer.subscribe(MessageCodeEnum.USER_MESSAGE.getCode(),"*");
|
||||
// 获取所有topic列表
|
||||
MessageTopic messageTopic = new MessageTopic();
|
||||
List<String> allTopics = messageTopic.RocketMQTopicList();
|
||||
//订阅所有topic
|
||||
for (String topic : allTopics) {
|
||||
consumer.subscribe(topic,"*");
|
||||
}
|
||||
consumer.start();
|
||||
log.info("消费者初始化成功:{}", consumer.toString());
|
||||
log.info("消费者初始化成功:{}", consumer);
|
||||
} catch (MQClientException e) {
|
||||
e.printStackTrace();
|
||||
log.error("消费者初始化失败:{}",e.getMessage());
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.ruoyi.testrocketmq.config;
|
||||
package com.ruoyi.mtragent.config;
|
||||
|
||||
import com.ruoyi.testrocketmq.model.ProducerMode;
|
||||
import com.ruoyi.mtragent.model.ProducerMode;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.rocketmq.client.exception.MQClientException;
|
||||
import org.apache.rocketmq.client.producer.DefaultMQProducer;
|
||||
@@ -9,20 +9,28 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
|
||||
/**
|
||||
* mq搭建地址连接
|
||||
* 生产者初者连接信息 具体看nacos配置
|
||||
*/
|
||||
@Configuration
|
||||
@Slf4j
|
||||
public class ProducerConfig {
|
||||
|
||||
/**
|
||||
* 远程调用连接信息
|
||||
*/
|
||||
public static DefaultMQProducer producer;
|
||||
|
||||
/**
|
||||
* 连接客户端信息配置 具体看nacos配置
|
||||
*/
|
||||
@Autowired
|
||||
private ProducerMode producerMode;
|
||||
|
||||
|
||||
|
||||
@Bean
|
||||
public DefaultMQProducer getRocketMQProducer() {
|
||||
producer = new DefaultMQProducer(producerMode.getGroupName());
|
||||
producer = new DefaultMQProducer(producerMode.getAgentGroup());
|
||||
producer.setNamesrvAddr(producerMode.getNamesrvAddr());
|
||||
//如果需要同一个jvm中不同的producer往不同的mq集群发送消息,需要设置不同的instanceName
|
||||
if(producerMode.getMaxMessageSize()!=null){
|
||||
@@ -0,0 +1,94 @@
|
||||
package com.ruoyi.mtragent.consumer;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.ruoyi.mtragent.domain.DeviceMessage;
|
||||
import com.ruoyi.mtragent.enums.MessageCodeEnum;
|
||||
import com.ruoyi.mtragent.handler.MessageHandler;
|
||||
import com.ruoyi.mtragent.producer.ConsumeException;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext;
|
||||
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus;
|
||||
import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently;
|
||||
import org.apache.rocketmq.common.message.MessageExt;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 消息监听
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class RocketMsgListener implements MessageListenerConcurrently {
|
||||
@Autowired
|
||||
private MessageHandler messageHandler;
|
||||
|
||||
/**
|
||||
* 消费消息
|
||||
* @param list msgs.size() >= 1
|
||||
* DefaultMQPushConsumer.consumeMessageBatchMaxSize=1,you can modify here
|
||||
* 这里只设置为1,当设置为多个时,list中只要有一条消息消费失败,就会整体重试
|
||||
* @param consumeConcurrentlyContext 上下文信息
|
||||
* @return 消费状态 成功(CONSUME_SUCCESS)或者 重试 (RECONSUME_LATER)
|
||||
*/
|
||||
@Override
|
||||
public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> list, ConsumeConcurrentlyContext consumeConcurrentlyContext) {
|
||||
try{
|
||||
//消息不等于空情况
|
||||
if (!CollectionUtils.isEmpty(list)) {
|
||||
//获取topic
|
||||
for (MessageExt messageExt : list) {
|
||||
// 解析消息内容
|
||||
String body = new String(messageExt.getBody());
|
||||
log.info("接受到的消息为:{}", body);
|
||||
String tags = messageExt.getTags();
|
||||
String topic = messageExt.getTopic();
|
||||
String msgId = messageExt.getMsgId();
|
||||
String keys = messageExt.getKeys();
|
||||
int reConsume = messageExt.getReconsumeTimes();
|
||||
// 消息已经重试了3次,如果不需要再次消费,则返回成功
|
||||
if (reConsume == 3) {
|
||||
// TODO 补偿信息
|
||||
log.error("消息消费三次失败,消息内容:{}", body);
|
||||
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;//根据业务返回是否正常
|
||||
}
|
||||
if(MessageCodeEnum.TR_MTRAGENT_UP.getCode().equals(topic)){
|
||||
// 拿到信息
|
||||
DeviceMessage message = JSON.parseObject(body, DeviceMessage.class);
|
||||
// 处理消息
|
||||
messageHandler.handleMessage(message);
|
||||
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;//业务处理成功
|
||||
}
|
||||
// 根据不同的topic处理不同的业务 这里以订单消息为例子
|
||||
}
|
||||
}
|
||||
// 消息消费失败
|
||||
//broker会根据设置的messageDelayLevel发起重试,默认16次
|
||||
return ConsumeConcurrentlyStatus.RECONSUME_LATER;
|
||||
} catch (Exception e) {
|
||||
// 调用 handleException 方法处理异常并返回处理结果
|
||||
return handleException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 异常处理
|
||||
*
|
||||
* @param e 捕获的异常
|
||||
* @return 消息消费结果
|
||||
*/
|
||||
private static ConsumeConcurrentlyStatus handleException(final Exception e) {
|
||||
Class exceptionClass = e.getClass();
|
||||
if (exceptionClass.equals(UnsupportedEncodingException.class)) {
|
||||
log.error(e.getMessage());
|
||||
} else if (exceptionClass.equals(ConsumeException.class)) {
|
||||
log.error(e.getMessage());
|
||||
} else{
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
return ConsumeConcurrentlyStatus.RECONSUME_LATER;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.ruoyi.mtragent.consumer;
|
||||
|
||||
import org.apache.rocketmq.client.producer.LocalTransactionState;
|
||||
import org.apache.rocketmq.client.producer.TransactionListener;
|
||||
import org.apache.rocketmq.common.message.Message;
|
||||
import org.apache.rocketmq.common.message.MessageExt;
|
||||
|
||||
/**
|
||||
* 事物消息监听
|
||||
*/
|
||||
public class RocketMsgTransactionListenerImpl implements TransactionListener {
|
||||
|
||||
@Override
|
||||
public LocalTransactionState executeLocalTransaction(Message msg, Object arg) {
|
||||
// 在这里执行本地事务,比如数据库操作等
|
||||
// 如果本地事务执行成功,返回 COMMIT_MESSAGE
|
||||
// 如果本地事务执行失败,返回 ROLLBACK_MESSAGE
|
||||
// 如果本地事务执行中,可以返回 UNKNOW,RocketMQ 将会检查事务状态,并根据状态处理消息
|
||||
return LocalTransactionState.COMMIT_MESSAGE; // 根据实际情况返回对应的状态
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocalTransactionState checkLocalTransaction(MessageExt msg) {
|
||||
// 检查本地事务状态,如果本地事务执行成功,返回 COMMIT_MESSAGE
|
||||
// 如果本地事务执行失败,返回 ROLLBACK_MESSAGE
|
||||
// 如果本地事务仍在执行中,返回 UNKNOW,RocketMQ 将会继续检查事务状态
|
||||
return LocalTransactionState.COMMIT_MESSAGE; // 根据实际情况返回对应的状态
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
package com.ruoyi.mtragent.controller;
|
||||
|
||||
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.core.web.page.PageDomain;
|
||||
import com.ruoyi.common.core.web.page.TableDataInfo;
|
||||
import com.ruoyi.common.log.annotation.Log;
|
||||
import com.ruoyi.common.log.enums.BusinessType;
|
||||
import com.ruoyi.common.security.annotation.RequiresPermissions;
|
||||
import com.ruoyi.mtragent.domain.RmMtrClientRegistration;
|
||||
import com.ruoyi.mtragent.service.IRmMtrClientRegistrationService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* MTR客户端注册Controller
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-11-18
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/mtrClientRegistration")
|
||||
public class RmMtrClientRegistrationController extends BaseController
|
||||
{
|
||||
@Autowired
|
||||
private IRmMtrClientRegistrationService rmMtrClientRegistrationService;
|
||||
|
||||
/**
|
||||
* 查询MTR客户端注册列表
|
||||
*/
|
||||
@RequiresPermissions("mtragent:mtrClientRegistration:list")
|
||||
@PostMapping("/list")
|
||||
public TableDataInfo list(@RequestBody RmMtrClientRegistration rmMtrClientRegistration)
|
||||
{
|
||||
PageDomain pageDomain = new PageDomain();
|
||||
pageDomain.setPageNum(rmMtrClientRegistration.getPageNum());
|
||||
pageDomain.setPageSize(rmMtrClientRegistration.getPageSize());
|
||||
startPage(pageDomain);
|
||||
List<RmMtrClientRegistration> list = rmMtrClientRegistrationService.selectRmMtrClientRegistrationList(rmMtrClientRegistration);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出MTR客户端注册列表
|
||||
*/
|
||||
@RequiresPermissions("mtragent:mtrClientRegistration:export")
|
||||
@Log(title = "MTR客户端注册", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, RmMtrClientRegistration rmMtrClientRegistration)
|
||||
{
|
||||
List<RmMtrClientRegistration> list = rmMtrClientRegistrationService.selectRmMtrClientRegistrationList(rmMtrClientRegistration);
|
||||
ExcelUtil<RmMtrClientRegistration> util = new ExcelUtil<RmMtrClientRegistration>(RmMtrClientRegistration.class);
|
||||
util.showColumn(rmMtrClientRegistration.getProperties());
|
||||
util.exportExcel(response, list, "MTR客户端注册数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取MTR客户端注册详细信息
|
||||
*/
|
||||
@RequiresPermissions("mtragent:mtrClientRegistration:query")
|
||||
@GetMapping(value = "/{id}")
|
||||
public AjaxResult getInfo(@PathVariable("id") Long id)
|
||||
{
|
||||
return success(rmMtrClientRegistrationService.selectRmMtrClientRegistrationById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增MTR客户端注册
|
||||
*/
|
||||
@RequiresPermissions("mtragent:mtrClientRegistration:add")
|
||||
@Log(title = "MTR客户端注册", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public AjaxResult add(@RequestBody RmMtrClientRegistration rmMtrClientRegistration)
|
||||
{
|
||||
return toAjax(rmMtrClientRegistrationService.insertRmMtrClientRegistration(rmMtrClientRegistration));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改MTR客户端注册
|
||||
*/
|
||||
@RequiresPermissions("mtragent:mtrClientRegistration:edit")
|
||||
@Log(title = "MTR客户端注册", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public AjaxResult edit(@RequestBody RmMtrClientRegistration rmMtrClientRegistration)
|
||||
{
|
||||
return toAjax(rmMtrClientRegistrationService.updateRmMtrClientRegistration(rmMtrClientRegistration));
|
||||
}
|
||||
|
||||
/**
|
||||
* 配置更新策略
|
||||
* @param rmMtrClientRegistration
|
||||
* @return
|
||||
*/
|
||||
@RequiresPermissions("mtragent:mtrClientRegistration:add")
|
||||
@PostMapping("/addAgentUpdatePolicy")
|
||||
public AjaxResult addAgentUpdatePolicy(@RequestBody RmMtrClientRegistration rmMtrClientRegistration){
|
||||
int rows = rmMtrClientRegistrationService.addAgentUpdatePolicy(rmMtrClientRegistration);
|
||||
return toAjax(rows);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
package com.ruoyi.mtragent.controller;
|
||||
|
||||
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.core.web.page.PageDomain;
|
||||
import com.ruoyi.common.core.web.page.TableDataInfo;
|
||||
import com.ruoyi.common.log.annotation.Log;
|
||||
import com.ruoyi.common.log.enums.BusinessType;
|
||||
import com.ruoyi.common.security.annotation.RequiresPermissions;
|
||||
import com.ruoyi.mtragent.domain.RmMtrPolicyConfig;
|
||||
import com.ruoyi.mtragent.service.IRmMtrPolicyConfigService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* mtr探测策略配置Controller
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-11-18
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/mtrPolicyConfig")
|
||||
public class RmMtrPolicyConfigController extends BaseController
|
||||
{
|
||||
@Autowired
|
||||
private IRmMtrPolicyConfigService rmMtrPolicyConfigService;
|
||||
|
||||
/**
|
||||
* 查询mtr探测策略配置列表
|
||||
*/
|
||||
@RequiresPermissions("mtragent:mtrPolicyConfig:list")
|
||||
@PostMapping("/list")
|
||||
public TableDataInfo list(@RequestBody RmMtrPolicyConfig rmMtrPolicyConfig)
|
||||
{
|
||||
PageDomain pageDomain = new PageDomain();
|
||||
pageDomain.setPageNum(rmMtrPolicyConfig.getPageNum());
|
||||
pageDomain.setPageSize(rmMtrPolicyConfig.getPageSize());
|
||||
startPage(pageDomain);
|
||||
List<RmMtrPolicyConfig> list = rmMtrPolicyConfigService.selectRmMtrPolicyConfigList(rmMtrPolicyConfig);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出mtr探测策略配置列表
|
||||
*/
|
||||
@RequiresPermissions("mtragent:mtrPolicyConfig:export")
|
||||
@Log(title = "mtr探测策略配置", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, RmMtrPolicyConfig rmMtrPolicyConfig)
|
||||
{
|
||||
List<RmMtrPolicyConfig> list = rmMtrPolicyConfigService.selectRmMtrPolicyConfigList(rmMtrPolicyConfig);
|
||||
ExcelUtil<RmMtrPolicyConfig> util = new ExcelUtil<RmMtrPolicyConfig>(RmMtrPolicyConfig.class);
|
||||
util.showColumn(rmMtrPolicyConfig.getProperties());
|
||||
util.exportExcel(response, list, "mtr探测策略配置数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取mtr探测策略配置详细信息
|
||||
*/
|
||||
@RequiresPermissions("mtragent:mtrPolicyConfig:query")
|
||||
@GetMapping(value = "/{id}")
|
||||
public AjaxResult getInfo(@PathVariable("id") Long id)
|
||||
{
|
||||
return success(rmMtrPolicyConfigService.selectRmMtrPolicyConfigById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增mtr探测策略配置
|
||||
*/
|
||||
@RequiresPermissions("mtragent:mtrPolicyConfig:add")
|
||||
@Log(title = "mtr探测策略配置", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public AjaxResult add(@RequestBody RmMtrPolicyConfig rmMtrPolicyConfig)
|
||||
{
|
||||
return toAjax(rmMtrPolicyConfigService.insertRmMtrPolicyConfig(rmMtrPolicyConfig));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改mtr探测策略配置
|
||||
*/
|
||||
@RequiresPermissions("mtragent:mtrPolicyConfig:edit")
|
||||
@Log(title = "mtr探测策略配置", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public AjaxResult edit(@RequestBody RmMtrPolicyConfig rmMtrPolicyConfig)
|
||||
{
|
||||
return toAjax(rmMtrPolicyConfigService.updateRmMtrPolicyConfig(rmMtrPolicyConfig));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除mtr探测策略配置
|
||||
*/
|
||||
@RequiresPermissions("mtragent:mtrPolicyConfig:remove")
|
||||
@Log(title = "mtr探测策略配置", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{ids}")
|
||||
public AjaxResult remove(@PathVariable Long[] ids)
|
||||
{
|
||||
return toAjax(rmMtrPolicyConfigService.deleteRmMtrPolicyConfigByIds(ids));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
package com.ruoyi.mtragent.controller;
|
||||
|
||||
|
||||
import com.ruoyi.common.security.annotation.InnerAuth;
|
||||
import com.ruoyi.mtragent.producer.MessageProducer;
|
||||
import org.apache.rocketmq.client.producer.SendResult;
|
||||
import org.apache.rocketmq.common.message.Message;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 消息测试类Controller
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/rocketMessage")
|
||||
public class RocketMqController {
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 发送同步消息
|
||||
*/
|
||||
@PostMapping("/sendSynchronizeMessage")
|
||||
private Map sendSynchronizeMessage(){
|
||||
MessageProducer messageProducer = new MessageProducer();
|
||||
//调用MessageProducer配置好的消息方法
|
||||
SendResult sendResult = messageProducer.sendSynchronizeMessage("order-message","order_message_tag","title","content");
|
||||
Map<String,Object> result = new HashMap<>();
|
||||
result.put("data",sendResult);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 发送单向消息
|
||||
*/
|
||||
@PostMapping("/sendOnewayMessage")
|
||||
private Map sendOnewayMessage(@RequestParam("topic") String topic,@RequestParam("tag") String tag,@RequestParam("key") String key,@RequestParam("value") String value){
|
||||
MessageProducer messageProducer = new MessageProducer();
|
||||
//调用MessageProducer配置好的消息方法 topic需要你根据你们业务定制相应的
|
||||
messageProducer.sendOnewayMessage("order-message","order_timeout_tag","title","content");
|
||||
Map<String,Object> result = new HashMap<>();
|
||||
result.put("msg","发送成功");
|
||||
result.put("code",200);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 批量发送消息
|
||||
*/
|
||||
@PostMapping("/sendBatchMessage")
|
||||
private Map sendBatchMessage(){
|
||||
// 根据实际需求创建消息列表并返回
|
||||
List<Message> messages = new ArrayList<>();
|
||||
// 添加消息到列表
|
||||
messages.add(new Message("order-message", "order_timeout_tag", "Message 1".getBytes()));
|
||||
messages.add(new Message("order-message", "order_timeout_tag", "Message 2".getBytes()));
|
||||
messages.add(new Message("order-message", "order_timeout_tag", "Message 3".getBytes()));
|
||||
MessageProducer messageProducer = new MessageProducer();
|
||||
//调用MessageProducer配置好的消息方法 topic需要你根据你们业务定制相应的
|
||||
SendResult sendResult = messageProducer.sendBatchMessage(messages);
|
||||
Map<String,Object> result = new HashMap<>();
|
||||
result.put("data",sendResult);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 发送事物消息
|
||||
*/
|
||||
@PostMapping("/sendThingMessage")
|
||||
private Map sendThingMessage(@RequestParam("topic") String topic,@RequestParam("tag") String tag,@RequestParam("key") String key,@RequestParam("value") String value){
|
||||
MessageProducer messageProducer = new MessageProducer();
|
||||
//调用MessageProducer配置好的消息方法 topic需要你根据你们业务定制相应的
|
||||
SendResult sendResult = messageProducer.sendThingMessage("order-message","order_timeout_tag","title","content");
|
||||
Map<String,Object> result = new HashMap<>();
|
||||
result.put("data",sendResult);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 发送有序的消息
|
||||
*/
|
||||
@PostMapping("/sendOrderlyMessage")
|
||||
private Map sendOrderlyMessage(){
|
||||
// 根据实际需求创建消息列表并返回
|
||||
List<Message> messages = new ArrayList<>();
|
||||
// 添加消息到列表
|
||||
messages.add(new Message("order-message", "order_timeout_tag", "Message 1".getBytes()));
|
||||
messages.add(new Message("order-message", "order_timeout_tag", "Message 2".getBytes()));
|
||||
messages.add(new Message("order-message", "order_timeout_tag", "Message 3".getBytes()));
|
||||
Integer messageQueueNumber = 3;
|
||||
MessageProducer messageProducer = new MessageProducer();
|
||||
//调用MessageProducer配置好的消息方法 topic需要你根据你们业务定制相应的
|
||||
SendResult sendResult = messageProducer.sendOrderlyMessage(messages,messageQueueNumber);
|
||||
Map<String,Object> result = new HashMap<>();
|
||||
result.put("data",sendResult);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送延迟消息
|
||||
*/
|
||||
@PostMapping("/sendDelayMessage")
|
||||
private Map sendDelayMessage(@RequestParam("topic") String topic,@RequestParam("tag") String tag,@RequestParam("key") String key,@RequestParam("value") String value){
|
||||
MessageProducer messageProducer = new MessageProducer();
|
||||
//调用MessageProducer配置好的消息方法 topic需要你根据你们业务定制相应的
|
||||
SendResult sendResult = messageProducer.sendDelayMessage("order-message","order_timeout_tag","title","content",4);
|
||||
Map<String,Object> result = new HashMap<>();
|
||||
result.put("data",sendResult);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 发送异步的消息
|
||||
*/
|
||||
@InnerAuth
|
||||
@PostMapping("/sendAsyncProducerMessage")
|
||||
private Map sendAsyncProducerMessage(@RequestParam("topic") String topic,@RequestParam("tag") String tag,@RequestParam("key") String key,@RequestParam("value") String value){
|
||||
MessageProducer messageProducer = new MessageProducer();
|
||||
//调用MessageProducer配置好的消息方法 topic需要你根据你们业务定制相应的
|
||||
SendResult sendResult = messageProducer.sendAsyncProducerMessage(topic,tag,key,value);
|
||||
Map<String,Object> result = new HashMap<>();
|
||||
result.put("data",sendResult);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.ruoyi.mtragent.domain;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class DeviceMessage {
|
||||
private String clientId;
|
||||
private String dataType;
|
||||
private String data;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.ruoyi.mtragent.domain;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.ruoyi.common.core.annotation.Excel;
|
||||
import com.ruoyi.common.core.web.domain.BaseEntity;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 心跳信息对象 initial_heartbeat_listen
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-09-08
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class InitialHeartbeatListen extends BaseEntity
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 客户端ID */
|
||||
private String clientId;
|
||||
/** 节点 */
|
||||
private String logicalNode;
|
||||
/** sn */
|
||||
private String sn;
|
||||
|
||||
/** 强度值 */
|
||||
@Excel(name = "强度值")
|
||||
private Long strength;
|
||||
/** 服务名称 */
|
||||
private String name;
|
||||
/** 版本 */
|
||||
private String version;
|
||||
/** 服务启动时间 */
|
||||
private Long startupTime;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.ruoyi.mtragent.domain;
|
||||
|
||||
import com.ruoyi.common.core.annotation.Excel;
|
||||
import com.ruoyi.common.core.web.domain.BaseEntity;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 心跳信息日志对象 initial_heartbeat_listen_log
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-09-08
|
||||
*/
|
||||
@Data
|
||||
public class InitialHeartbeatListenLog extends BaseEntity
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Long id;
|
||||
/** 客户端ID */
|
||||
private String clientId;
|
||||
|
||||
/** 状态0-正常 1-恢复 2-两次丢失 3-三次丢失 */
|
||||
@Excel(name = "状态0-正常 1-恢复 2-两次丢失 3-三次丢失")
|
||||
private String status;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.ruoyi.mtragent.domain;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.ruoyi.system.api.domain.NetworkInfo;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
public class NetworkInfoDeserializer extends JsonDeserializer<List<NetworkInfo>> {
|
||||
// 添加无参构造函数(Jackson 需要)
|
||||
public NetworkInfoDeserializer() {
|
||||
}
|
||||
@Override
|
||||
public List<NetworkInfo> deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
|
||||
ObjectMapper mapper = (ObjectMapper) p.getCodec();
|
||||
JsonNode node = mapper.readTree(p);
|
||||
|
||||
// 如果 networkInfo 是字符串(如日志中的情况),先解析字符串
|
||||
if (node.isTextual()) {
|
||||
String jsonStr = node.textValue();
|
||||
return mapper.readValue(jsonStr, new TypeReference<List<NetworkInfo>>() {});
|
||||
}
|
||||
// 如果 networkInfo 是数组,直接解析
|
||||
else if (node.isArray()) {
|
||||
return mapper.readValue(node.traverse(), new TypeReference<List<NetworkInfo>>() {});
|
||||
}
|
||||
throw new IOException("Invalid networkInfo format");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
package com.ruoyi.mtragent.domain;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.ruoyi.common.core.annotation.Excel;
|
||||
import com.ruoyi.common.core.web.domain.BaseEntity;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* Agent管理对象 rm_agent_management
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-09-15
|
||||
*/
|
||||
@Data
|
||||
public class RmAgentManagement extends BaseEntity
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 主键ID */
|
||||
private Long id;
|
||||
|
||||
/** 硬件SN码 */
|
||||
@Excel(name = "硬件SN码")
|
||||
private String hardwareSn;
|
||||
|
||||
/** 资源名称 */
|
||||
@Excel(name = "资源名称")
|
||||
private String resourceName;
|
||||
|
||||
/** 内网IP地址 */
|
||||
@Excel(name = "内网IP地址")
|
||||
private String internalIp;
|
||||
|
||||
/** Agent状态:0-离线,1-在线,2-异常 */
|
||||
@Excel(name = "Agent状态:0-离线,1-在线,2-异常")
|
||||
private String status;
|
||||
|
||||
/** Agent版本号 */
|
||||
@Excel(name = "Agent版本号")
|
||||
private String agentVersion;
|
||||
|
||||
/** 执行方式 */
|
||||
@Excel(name = "执行方式")
|
||||
private Integer method;
|
||||
|
||||
/** 定时更新时间(cron表达式) */
|
||||
@Excel(name = "定时更新时间")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date scheduledUpdateTime;
|
||||
/** 文件地址格式 */
|
||||
@Excel(name = "文件地址格式")
|
||||
private Long fileUrlType;
|
||||
|
||||
/** 文件地址 */
|
||||
@Excel(name = "文件地址")
|
||||
private String fileUrl;
|
||||
/** 文件目录 */
|
||||
@Excel(name = "文件目录")
|
||||
private String fileDirectory;
|
||||
|
||||
/** 最后一次更新结果(success/failure) */
|
||||
@Excel(name = "最后一次更新结果", readConverterExp = "s=uccess/failure")
|
||||
private String lastUpdateResult;
|
||||
|
||||
/** 最后一次更新时间 */
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@Excel(name = "最后一次更新时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date lastUpdateTime;
|
||||
/** 生效服务器id */
|
||||
private String includeIds;
|
||||
/** 生效服务器名称 */
|
||||
private String includeNames;
|
||||
/** 查询条件名称 */
|
||||
private String queryName;
|
||||
/** 文件MD5 */
|
||||
private String fileMd5;
|
||||
/** 客户端id */
|
||||
private String clientId;
|
||||
/** 部署设备 */
|
||||
private String deployDevice;
|
||||
/** 管理网公网Ip */
|
||||
private String managePublicIp;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.ruoyi.mtragent.domain;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.ruoyi.common.core.annotation.Excel;
|
||||
import com.ruoyi.common.core.web.domain.BaseEntity;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 客户端告警信息对象 rm_alarm_log
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-11-10
|
||||
*/
|
||||
@Data
|
||||
public class RmAlarmLog extends BaseEntity
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 主键ID */
|
||||
private Long id;
|
||||
|
||||
/** 客户端ID */
|
||||
@Excel(name = "客户端ID")
|
||||
private String clientId;
|
||||
|
||||
/** 告警时间 */
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@Excel(name = "告警时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date alarmTime;
|
||||
|
||||
/** 管理网-公网IP */
|
||||
@Excel(name = "管理网-公网IP")
|
||||
private String mgmPublicIp;
|
||||
|
||||
/** 告警类型 */
|
||||
@Excel(name = "告警类型")
|
||||
private String alarmType;
|
||||
|
||||
/** 告警内容 */
|
||||
@Excel(name = "告警内容")
|
||||
private String alarmContent;
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.ruoyi.mtragent.domain;
|
||||
|
||||
import com.ruoyi.common.core.annotation.Excel;
|
||||
import com.ruoyi.common.core.web.domain.BaseEntity;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 告警推送配置对象 rm_alarm_push_config
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-11-11
|
||||
*/
|
||||
@Data
|
||||
public class RmAlarmPushConfig extends BaseEntity
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 主键ID */
|
||||
private Long id;
|
||||
|
||||
/** 配置名称 */
|
||||
@Excel(name = "配置名称")
|
||||
private String configName;
|
||||
|
||||
/** 推送方式 */
|
||||
@Excel(name = "推送方式")
|
||||
private String pushMethod;
|
||||
|
||||
/** 推送地址 */
|
||||
@Excel(name = "推送地址")
|
||||
private String pushAddress;
|
||||
|
||||
/** 推送告警类型 */
|
||||
@Excel(name = "推送告警类型")
|
||||
private String pushAlarmTypes;
|
||||
|
||||
/** 消息内容 */
|
||||
@Excel(name = "消息内容")
|
||||
private String messageContent;
|
||||
|
||||
/** 消息提示人手机号 */
|
||||
@Excel(name = "消息提示人手机号")
|
||||
private String contactPhones;
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
package com.ruoyi.mtragent.domain;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.ruoyi.common.core.annotation.Excel;
|
||||
import com.ruoyi.common.core.web.domain.BaseEntity;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* MTR客户端注册对象 rm_mtr_client_registration
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-11-18
|
||||
*/
|
||||
@Data
|
||||
public class RmMtrClientRegistration extends BaseEntity
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 主键ID */
|
||||
private Long id;
|
||||
|
||||
/** MTR客户端ID */
|
||||
@Excel(name = "MTR客户端ID")
|
||||
private String mtrClientId;
|
||||
|
||||
/** 描述 */
|
||||
@Excel(name = "描述")
|
||||
private String description;
|
||||
|
||||
/** 版本 */
|
||||
@Excel(name = "版本")
|
||||
private String version;
|
||||
|
||||
/** 标识 */
|
||||
@Excel(name = "标识")
|
||||
private String logicalNode;
|
||||
|
||||
/** 注册时间 */
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@Excel(name = "注册时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date registerTime;
|
||||
|
||||
/** 注册状态(0-未注册,1-已注册) */
|
||||
@Excel(name = "注册状态(0-未注册,1-已注册)")
|
||||
private String registerStatus;
|
||||
|
||||
/** 在线状态(0-离线,1-在线) */
|
||||
@Excel(name = "在线状态(0-离线,1-在线)")
|
||||
private String onlineStatus;
|
||||
|
||||
/** 心跳时间间隔(秒) */
|
||||
@Excel(name = "心跳时间间隔(秒)")
|
||||
private Integer heartbeatInterval;
|
||||
|
||||
/** 心跳次数 */
|
||||
@Excel(name = "心跳次数")
|
||||
private Integer heartbeatCount;
|
||||
|
||||
/** 更新方式 */
|
||||
@Excel(name = "更新方式")
|
||||
private String method;
|
||||
|
||||
/** 定时更新时间 */
|
||||
@Excel(name = "定时更新时间")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date scheduledUpdateTime;
|
||||
|
||||
/** 文件地址 */
|
||||
@Excel(name = "文件地址")
|
||||
private String filePath;
|
||||
|
||||
/** 文件MD5值 */
|
||||
@Excel(name = "文件MD5值")
|
||||
private String fileMd5;
|
||||
|
||||
/** 最后一次更新结果 */
|
||||
@Excel(name = "最后一次更新结果")
|
||||
private String lastUpdateResult;
|
||||
|
||||
/** 最后一次更新时间 */
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@Excel(name = "最后一次更新时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date lastUpdateTime;
|
||||
|
||||
/** 网卡信息(JSON格式) */
|
||||
@Excel(name = "网卡信息(JSON格式)")
|
||||
private String networkInfo;
|
||||
/** 部署设备 */
|
||||
private String mtrClientIds;
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.ruoyi.mtragent.domain;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.ruoyi.common.core.annotation.Excel;
|
||||
import com.ruoyi.common.core.web.domain.BaseEntity;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* mtr探测策略配置对象 rm_mtr_policy_config
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-11-18
|
||||
*/
|
||||
@Data
|
||||
public class RmMtrPolicyConfig extends BaseEntity
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 主键ID */
|
||||
private Long id;
|
||||
|
||||
/** 策略名称 */
|
||||
@Excel(name = "策略名称")
|
||||
private String policyName;
|
||||
|
||||
/** 优先级 */
|
||||
@Excel(name = "优先级")
|
||||
private Long priority;
|
||||
|
||||
/** MTR客户端ID */
|
||||
@Excel(name = "MTR客户端ID")
|
||||
private String mtrClientId;
|
||||
|
||||
/** 服务器集合(换行符分割) */
|
||||
@Excel(name = "服务器集合(换行符分割)")
|
||||
private String serverGroup;
|
||||
/** 探测目标ip集合 */
|
||||
private String serveripGroup;
|
||||
|
||||
/** 是否探测(0-否,1-是) */
|
||||
@Excel(name = "是否探测(0-否,1-是)")
|
||||
private Long probeFlag;
|
||||
|
||||
/** 开始时间 */
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@Excel(name = "开始时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date startTime;
|
||||
|
||||
/** 结束时间 */
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@Excel(name = "结束时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date endTime;
|
||||
|
||||
/** 探测频率(秒) */
|
||||
@Excel(name = "探测频率(秒)")
|
||||
private Long probeFrequency;
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package com.ruoyi.mtragent.domain;
|
||||
|
||||
import com.ruoyi.common.core.annotation.Excel;
|
||||
import com.ruoyi.common.core.web.domain.BaseEntity;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 客户端网络接口信息对象 rm_network_interface
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-10-14
|
||||
*/
|
||||
@Data
|
||||
public class RmNetworkInterface extends BaseEntity
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 主键ID */
|
||||
private Long id;
|
||||
|
||||
/** 客户端ID */
|
||||
@Excel(name = "客户端ID")
|
||||
private String clientId;
|
||||
|
||||
/** 运营商 */
|
||||
@Excel(name = "运营商")
|
||||
private String isp;
|
||||
|
||||
/** 省 */
|
||||
@Excel(name = "省")
|
||||
private String province;
|
||||
|
||||
/** 市 */
|
||||
@Excel(name = "市")
|
||||
private String city;
|
||||
|
||||
/** 公网IP */
|
||||
@Excel(name = "公网IP")
|
||||
private String publicIp;
|
||||
|
||||
/** 接口名称 */
|
||||
@Excel(name = "接口名称")
|
||||
private String interfaceName;
|
||||
|
||||
/** MAC地址 */
|
||||
@Excel(name = "MAC地址")
|
||||
private String macAddress;
|
||||
|
||||
/** 接口类型 */
|
||||
@Excel(name = "接口类型")
|
||||
private String interfaceType;
|
||||
|
||||
/** IPv4地址 */
|
||||
@Excel(name = "IPv4地址")
|
||||
private String ipv4Address;
|
||||
|
||||
/** 网关 */
|
||||
@Excel(name = "网关")
|
||||
private String gateway;
|
||||
/** 绑定ip 1业务IP,2管理ip */
|
||||
private String bindIp;
|
||||
/** 是否为新信息 */
|
||||
private Integer newFlag;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.ruoyi.mtragent.domain.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class AgentUpdateMsgVo {
|
||||
/**文件地址,外网HTTP(S)地址 */
|
||||
private String fileUrl;
|
||||
/** 文件MD5 */
|
||||
private String fileMd5;
|
||||
/** 执行方式:0、立即执行;1、定时执行; */
|
||||
private Integer method;
|
||||
/** 定时时间,执行方式为1、定时执行时该字段必传 */
|
||||
private long policyTime;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.ruoyi.mtragent.domain.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class MessageVo {
|
||||
|
||||
private String clientId;
|
||||
|
||||
private String dataType;
|
||||
|
||||
private String data;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.ruoyi.mtragent.domain.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
@Data
|
||||
public class PolicyTypeVo {
|
||||
|
||||
/** 服务器监控策略信息 */
|
||||
private String monitors;
|
||||
/** 服务器脚本策略信息 */
|
||||
private String scripts;
|
||||
/** agent更新信息 */
|
||||
private String versions;
|
||||
/** 路由信息 */
|
||||
private String routes;
|
||||
/** 时间戳 */
|
||||
private Long timestamp = Instant.now().getEpochSecond();
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.ruoyi.mtragent.domain.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class PolicyVo<T> {
|
||||
/** 更新时间戳 */
|
||||
private Long upTime = Instant.now().getEpochSecond();
|
||||
/** 更新内容 */
|
||||
private List<T> contents;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.ruoyi.mtragent.domain.vo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.ruoyi.mtragent.domain.NetworkInfoDeserializer;
|
||||
import com.ruoyi.system.api.domain.NetworkInfo;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class RegisterMsgVo {
|
||||
@JsonProperty("clientId")
|
||||
private String clientId;
|
||||
|
||||
@JsonProperty("sn")
|
||||
private String sn;
|
||||
|
||||
@JsonProperty("networkInfo")
|
||||
@JsonDeserialize(using = NetworkInfoDeserializer.class)
|
||||
private List<NetworkInfo> networkInfo;
|
||||
|
||||
@JsonProperty("timestamp")
|
||||
private long timestamp;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.ruoyi.mtragent.domain.vo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class RspVo {
|
||||
/**
|
||||
* 状态码,0、失败;1、成功
|
||||
*/
|
||||
private Integer resCode;
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
private String resMag;
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
private String resMsg;
|
||||
|
||||
private String result;
|
||||
/**
|
||||
* 时间戳
|
||||
*/
|
||||
private Long timestamp = Instant.now().getEpochSecond();
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.ruoyi.mtragent.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public enum AlarmTypeEnum {
|
||||
服务器下线("1", "服务器下线"),
|
||||
交换机下线("2", "交换机下线");
|
||||
private final String code;
|
||||
private final String msg;
|
||||
AlarmTypeEnum(String code, String msg){
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package com.ruoyi.mtragent.enums;
|
||||
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 用于传递topic和 tag
|
||||
* 也用于接收消息后判断不同的消息处理不同的业务
|
||||
*/
|
||||
@Getter
|
||||
public enum MessageCodeEnum {
|
||||
|
||||
/**
|
||||
* agent数据采集的信息
|
||||
*/
|
||||
AGENT_MESSAGE_TOPIC("agent_up","agent数据采集的信息topic"),
|
||||
|
||||
TONGRAN_AGENT_UP("tongran_agent_up","agent数据采集的信息topic"),
|
||||
|
||||
TR_AGENT_UP("tr_agent_up","agent数据采集的信息topic v1.1"),
|
||||
|
||||
TR_MTRAGENT_UP("tr_mtragent_up","mtragent监测丢包率的信息topic"),
|
||||
|
||||
/**
|
||||
* 系统消息
|
||||
*/
|
||||
NOTE_MESSAGE_TOPIC("system-message","系统消息服务模块topic名称"),
|
||||
/**
|
||||
* 用户消息
|
||||
*/
|
||||
USER_MESSAGE_TOPIC("user-message","用户消息服务模块topic名称"),
|
||||
|
||||
/**
|
||||
* 订单消息
|
||||
*/
|
||||
ORDER_MESSAGE_TOPIC("order-message","订单消息服务模块topic名称"),
|
||||
|
||||
/**
|
||||
* 用户消息tag
|
||||
*/
|
||||
USER_MESSAGE_TAG("user_message_tag","用户消息推送"),
|
||||
|
||||
/**
|
||||
* 系统消息tag
|
||||
*/
|
||||
NOTE_MESSAGE_TAG("system_message_tag","系统消息推送"),
|
||||
|
||||
/**
|
||||
* 订单消息
|
||||
*/
|
||||
ORDER_MESSAGE_TAG("order_message_tag","订单消息推送"),
|
||||
|
||||
/**
|
||||
* 订单处理编号
|
||||
*/
|
||||
ORDER_TIMEOUT_TAG("order_timeout_tag","订单超时处理");
|
||||
|
||||
|
||||
private final String code;
|
||||
private final String msg;
|
||||
|
||||
MessageCodeEnum(String code, String msg){
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.ruoyi.mtragent.enums;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 定义topic列表
|
||||
*/
|
||||
public class MessageTopic {
|
||||
|
||||
//在这里添加topic 用于批量订阅
|
||||
public List<String> RocketMQTopicList(){
|
||||
List<String> getTopicLists=new ArrayList<>();
|
||||
// agent采集消息
|
||||
// getTopicLists.add("agent_up");
|
||||
getTopicLists.add("tr_mtragent_up");
|
||||
return getTopicLists;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.ruoyi.mtragent.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public enum PushMethodEnum {
|
||||
企业微信("1", "企业微信");
|
||||
private final String code;
|
||||
private final String msg;
|
||||
PushMethodEnum(String code, String msg){
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.ruoyi.mtragent.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public enum ServerLogoEnum {
|
||||
交换卷文件的可用空间("systemSwapSizeFreeCollect", "交换卷/文件的可用空间(字节)"),
|
||||
内存利用率("memoryUtilizationCollect", "内存利用率"),
|
||||
可用交换空间百分比("systemSwapSizePercentCollect", "可用交换空间百分比"),
|
||||
可用内存("memorySizeAvailableCollect", "可用内存"),
|
||||
可用内存百分比("memorySizePercentCollect", "可用内存百分比"),
|
||||
正在运行的进程数("procNumRunCollect", "正在运行的进程数"),
|
||||
登录用户数("systemUsersNumCollect", "登录用户数"),
|
||||
进程数("procNumCollect", "进程数");
|
||||
private final String code;
|
||||
private final String msg;
|
||||
ServerLogoEnum(String code, String msg){
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.ruoyi.mtragent.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public enum SwitchLogo {
|
||||
设备CPU使用率("hwEntityCpuUsage", "设备CPU使用率"),
|
||||
设备内存使用率("hwEntityMemUsage", "设备内存使用率(%)"),
|
||||
系统平均功率("hwAveragePower", "系统平均功率(%)"),
|
||||
系统实时功率("hwCurrentPower", "系统实时功率(%)");
|
||||
private final String code;
|
||||
private final String msg;
|
||||
SwitchLogo(String code, String msg){
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,546 @@
|
||||
package com.ruoyi.mtragent.handler;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.ruoyi.common.core.constant.SecurityConstants;
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import com.ruoyi.common.core.enums.MsgEnum;
|
||||
import com.ruoyi.common.core.utils.DateUtils;
|
||||
import com.ruoyi.common.core.utils.StringUtils;
|
||||
import com.ruoyi.mtragent.domain.*;
|
||||
import com.ruoyi.mtragent.domain.vo.MessageVo;
|
||||
import com.ruoyi.mtragent.domain.vo.RegisterMsgVo;
|
||||
import com.ruoyi.mtragent.domain.vo.RspVo;
|
||||
import com.ruoyi.mtragent.enums.AlarmTypeEnum;
|
||||
import com.ruoyi.mtragent.enums.PushMethodEnum;
|
||||
import com.ruoyi.mtragent.producer.MessageProducer;
|
||||
import com.ruoyi.mtragent.service.*;
|
||||
import com.ruoyi.mtragent.utils.JsonDataParser;
|
||||
import com.ruoyi.mtragent.utils.WeChatWorkBot;
|
||||
import com.ruoyi.system.api.RemoteRevenueConfigService;
|
||||
import com.ruoyi.system.api.domain.NetworkInfo;
|
||||
import com.ruoyi.system.api.domain.RmSwitchManagementRemote;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.data.redis.core.RedisOperations;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.core.SessionCallback;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* 设备消息处理器
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@EnableScheduling
|
||||
public class MessageHandler {
|
||||
|
||||
private final Map<String, Consumer<DeviceMessage>> messageHandlers = new HashMap<>();
|
||||
// 心跳状态
|
||||
private static final String HEARTBEAT_STATUS_PREFIX = "mtr:heartbeat:status:";
|
||||
// 心跳时间
|
||||
private static final String HEARTBEAT_TIME_PREFIX = "mtr:heartbeat:time:";
|
||||
// 心跳告警
|
||||
private static final String HEARTBEAT_ALERT_PREFIX = "mtr:heartbeat:alert:";
|
||||
String HEARTBEAT_RECOVERY_COUNT_PREFIX = "mtr:heartbeat:recovery:count:";
|
||||
|
||||
String HEARTBEAT_COUNT_PREFIX = "mtr:heartbeat:count:";
|
||||
private static final long HEARTBEAT_TIMEOUT = 30000; // 3分钟超时
|
||||
|
||||
|
||||
@Autowired
|
||||
private RedisTemplate<String, String> redisTemplate;
|
||||
@Autowired
|
||||
private IRmAgentManagementService rmAgentManagementService;
|
||||
@Autowired
|
||||
private RemoteRevenueConfigService remoteRevenueConfigService;
|
||||
@Autowired
|
||||
private IRmAlarmPushConfigService rmAlarmPushConfigService;
|
||||
@Autowired
|
||||
private IRmAlarmLogService rmAlarmLogService;
|
||||
@Autowired
|
||||
private IInitialHeartbeatListenLogService initialHeartbeatListenLogService;
|
||||
@Autowired
|
||||
private IRmNetworkInterfaceService rmNetworkInterfaceService;
|
||||
@Autowired
|
||||
private IRmMtrClientRegistrationService rmMtrClientRegistrationService;
|
||||
|
||||
|
||||
/**
|
||||
* 初始化处理器映射
|
||||
*/
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
registerHandler(MsgEnum.Agent版本更新应答.getValue(), this::handleAgentUpdateRspMessage);
|
||||
|
||||
// 其他类型消息可以单独注册处理器
|
||||
registerHandler(MsgEnum.注册.getValue(), this::handleRegisterMessage);
|
||||
registerHandler(MsgEnum.心跳上报.getValue(), this::handleHeartbeatMessage);
|
||||
registerHandler(MsgEnum.多公网IP探测.getValue(), this::handleNetWorkDelectMessage);
|
||||
}
|
||||
private void handleRegisterMessage(DeviceMessage message) {
|
||||
MessageProducer messageProducer = new MessageProducer();
|
||||
List<RegisterMsgVo> interfaces = JsonDataParser.parseJsonData(message.getData(), RegisterMsgVo.class);
|
||||
if(!interfaces.isEmpty()) {
|
||||
String clientId = message.getClientId();
|
||||
RegisterMsgVo registerMsg = interfaces.get(0);
|
||||
// 时间戳转换
|
||||
long timestamp = registerMsg.getTimestamp();
|
||||
long millis = timestamp * 1000;
|
||||
Date createTime = new Date(millis / 1000 * 1000); // 去除毫秒
|
||||
String timeStr = DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss", createTime);
|
||||
List<NetworkInfo> networkInfoList = registerMsg.getNetworkInfo();
|
||||
if(!networkInfoList.isEmpty()){
|
||||
RmMtrClientRegistration rmMtrClientRegistrationQuery = new RmMtrClientRegistration();
|
||||
rmMtrClientRegistrationQuery.setMtrClientId(clientId);
|
||||
List<RmMtrClientRegistration> mtrClientRegistrationList = rmMtrClientRegistrationService.selectRmMtrClientRegistrationList(rmMtrClientRegistrationQuery);
|
||||
if(mtrClientRegistrationList == null || mtrClientRegistrationList.isEmpty()){
|
||||
// 构建mtrClient信息
|
||||
RmMtrClientRegistration insertData = new RmMtrClientRegistration();
|
||||
try {
|
||||
insertData.setMtrClientId(registerMsg.getClientId());
|
||||
insertData.setRegisterStatus("1");
|
||||
insertData.setHeartbeatCount(3);
|
||||
insertData.setHeartbeatInterval(30);
|
||||
insertData.setCreateTime(createTime);
|
||||
insertData.setRegisterTime(createTime);
|
||||
insertData.setNetworkInfo(JSONObject.toJSONString(networkInfoList));
|
||||
rmMtrClientRegistrationService.insertRmMtrClientRegistration(insertData);
|
||||
// 构建注册应答信息
|
||||
MessageVo messageVo = new MessageVo();
|
||||
messageVo.setClientId(registerMsg.getClientId());
|
||||
messageVo.setDataType(MsgEnum.注册应答.getValue());
|
||||
RspVo rspVo = new RspVo();
|
||||
rspVo.setResCode(1);
|
||||
rspVo.setResMag("注册成功");
|
||||
messageVo.setData(JSONObject.toJSONString(rspVo));
|
||||
messageProducer.sendAsyncProducerMessage(
|
||||
"tr_mtragent_down", "", "mtrregist_rsp", JSONObject.toJSONString(messageVo)
|
||||
);
|
||||
}catch (Exception e){
|
||||
log.error("注册服务器失败:{}",e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* agent更新响应
|
||||
* @param message
|
||||
*/
|
||||
private void handleAgentUpdateRspMessage(DeviceMessage message) {
|
||||
List<RspVo> rspVoList = JsonDataParser.parseJsonData(message.getData(), RspVo.class);
|
||||
if (!rspVoList.isEmpty()) {
|
||||
RspVo rsp = rspVoList.get(0);
|
||||
if(rsp.getResCode() == 1){
|
||||
RmMtrClientRegistration rmMtrClientRegistration = new RmMtrClientRegistration();
|
||||
rmMtrClientRegistration.setMtrClientId(message.getClientId());
|
||||
rmMtrClientRegistration.setLastUpdateResult("1");
|
||||
rmMtrClientRegistration.setLastUpdateTime(DateUtils.getNowDate());
|
||||
rmMtrClientRegistrationService.updateRmMtrClientRegistration(rmMtrClientRegistration);
|
||||
}else{
|
||||
RmMtrClientRegistration rmMtrClientRegistration = new RmMtrClientRegistration();
|
||||
rmMtrClientRegistration.setMtrClientId(message.getClientId());
|
||||
rmMtrClientRegistration.setDescription(rsp.getResMag());
|
||||
rmMtrClientRegistration.setLastUpdateResult("0");
|
||||
rmMtrClientRegistration.setLastUpdateTime(DateUtils.getNowDate());
|
||||
rmMtrClientRegistrationService.updateRmMtrClientRegistration(rmMtrClientRegistration);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册消息处理器
|
||||
*/
|
||||
private void registerHandler(String dataType, Consumer<DeviceMessage> handler) {
|
||||
messageHandlers.put(dataType, handler);
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理设备消息(对外暴露的主方法)
|
||||
*/
|
||||
public void handleMessage(DeviceMessage message) {
|
||||
String dataType = message.getDataType();
|
||||
Consumer<DeviceMessage> handler = messageHandlers.get(dataType);
|
||||
|
||||
if (handler != null) {
|
||||
handler.accept(message);
|
||||
} else {
|
||||
log.warn("未知数据类型:{}", dataType);
|
||||
}
|
||||
}
|
||||
|
||||
// ========== 具体的消息处理方法 ==========
|
||||
|
||||
/**
|
||||
* 监听心跳
|
||||
* @param message
|
||||
*/
|
||||
private void handleHeartbeatMessage(DeviceMessage message) {
|
||||
List<InitialHeartbeatListen> heartbeats = JsonDataParser.parseJsonData(message.getData(), InitialHeartbeatListen.class);
|
||||
if(!heartbeats.isEmpty()){
|
||||
InitialHeartbeatListen heartbeat = heartbeats.get(0);
|
||||
String clientId = message.getClientId();
|
||||
String version = heartbeat.getVersion();
|
||||
String name = heartbeat.getName();
|
||||
log.debug("处理心跳消息,客户端ID: {}, 时间: {}", clientId, heartbeat.getTimestamp());
|
||||
|
||||
// 使用Redis存储状态
|
||||
String statusKey = HEARTBEAT_STATUS_PREFIX + clientId;
|
||||
String timeKey = HEARTBEAT_TIME_PREFIX + clientId;
|
||||
String recoveryCountKey = HEARTBEAT_RECOVERY_COUNT_PREFIX + clientId;
|
||||
String heartbeatCountKey = HEARTBEAT_COUNT_PREFIX + clientId;
|
||||
String alertKey = HEARTBEAT_ALERT_PREFIX + clientId;
|
||||
|
||||
try {
|
||||
// 记录处理前状态(调试用)
|
||||
String prevStatus = redisTemplate.opsForValue().get(statusKey);
|
||||
String prevTime = redisTemplate.opsForValue().get(timeKey);
|
||||
String prevHeartbeatCount = redisTemplate.opsForValue().get(heartbeatCountKey);
|
||||
Boolean prevAlertStatus = redisTemplate.hasKey(alertKey);
|
||||
log.debug("客户端ID: {} 处理前状态 - status: {}, time: {}, heartbeatCount: {}, hasAlert: {}",
|
||||
clientId, prevStatus, prevTime, prevHeartbeatCount, prevAlertStatus);
|
||||
|
||||
// 原子递增心跳计数(线程安全)
|
||||
Long newHeartbeatCount = redisTemplate.opsForValue().increment(heartbeatCountKey);
|
||||
|
||||
// 使用事务更新状态和时间
|
||||
redisTemplate.execute(new SessionCallback<Object>() {
|
||||
@Override
|
||||
public Object execute(RedisOperations operations) throws DataAccessException {
|
||||
operations.multi();
|
||||
// 重置丢失计数为0,设置最后心跳时间
|
||||
operations.opsForValue().set(statusKey, "0");
|
||||
operations.opsForValue().set(timeKey, String.valueOf(System.currentTimeMillis()));
|
||||
return operations.exec();
|
||||
}
|
||||
});
|
||||
|
||||
log.debug("客户端ID: {} 心跳处理完成,当前心跳次数: {}", clientId, newHeartbeatCount);
|
||||
|
||||
// 检查是否之前有告警状态(心跳恢复检测)
|
||||
if (Boolean.TRUE.equals(redisTemplate.hasKey(alertKey))) {
|
||||
log.info("客户端ID: {} 检测到心跳恢复", clientId);
|
||||
|
||||
// 原子递增恢复计数
|
||||
Long recoveryCount = redisTemplate.opsForValue().increment(recoveryCountKey);
|
||||
|
||||
log.debug("客户端ID: {} 恢复计数: {}", clientId, recoveryCount);
|
||||
|
||||
if (recoveryCount >= 2) {
|
||||
// 达到2次恢复,清除告警状态
|
||||
log.warn("客户端ID: {} 心跳恢复达到{}次,清除告警状态", clientId, recoveryCount);
|
||||
insertHeartbeatLog(clientId, "2", "心跳恢复,设备在线状态改为在线");
|
||||
|
||||
// 清理告警相关key
|
||||
redisTemplate.delete(alertKey);
|
||||
redisTemplate.delete(recoveryCountKey);
|
||||
|
||||
// 修改资源状态为在线
|
||||
updateResourceStatus(clientId, "1");
|
||||
|
||||
log.info("客户端ID: {} 告警状态已清除", clientId);
|
||||
} else {
|
||||
// 未达到2次,只记录恢复次数
|
||||
log.info("客户端ID: {} 心跳恢复第{}次", clientId, recoveryCount);
|
||||
}
|
||||
}
|
||||
|
||||
// 只有达到3次心跳才执行数据库操作
|
||||
if (newHeartbeatCount >= 3) {
|
||||
log.info("客户端ID: {} 达到{}次心跳,开始执行数据库操作", clientId, newHeartbeatCount);
|
||||
// agent更新结果存储
|
||||
RmMtrClientRegistration queryMtrClient = new RmMtrClientRegistration();
|
||||
queryMtrClient.setMtrClientId(clientId);
|
||||
List<RmMtrClientRegistration> mtrClientRegistrationList = rmMtrClientRegistrationService.selectRmMtrClientRegistrationList(queryMtrClient);
|
||||
if(mtrClientRegistrationList != null && !mtrClientRegistrationList.isEmpty()){
|
||||
RmMtrClientRegistration rmMtrClientRegistration = mtrClientRegistrationList.get(0);
|
||||
boolean needUpdate = false;
|
||||
RmMtrClientRegistration updateData = new RmMtrClientRegistration();
|
||||
updateData.setId(rmMtrClientRegistration.getId());
|
||||
if(rmMtrClientRegistration.getLogicalNode() == null ||
|
||||
!StringUtils.equals(rmMtrClientRegistration.getLogicalNode(), heartbeat.getLogicalNode())){
|
||||
updateData.setLogicalNode(heartbeat.getLogicalNode());
|
||||
needUpdate = true;
|
||||
}
|
||||
if("0".equals(rmMtrClientRegistration.getOnlineStatus())){
|
||||
updateData.setOnlineStatus("1");
|
||||
needUpdate = true;
|
||||
}
|
||||
if(!StringUtils.equals(rmMtrClientRegistration.getVersion(), version)){
|
||||
updateData.setVersion(version);
|
||||
updateData.setLastUpdateTime(DateUtils.getNowDate());
|
||||
updateData.setLastUpdateResult("1");
|
||||
if(rmMtrClientRegistration.getMethod() == null){
|
||||
updateData.setMethod("0");
|
||||
}
|
||||
needUpdate = true;
|
||||
}
|
||||
if(needUpdate){
|
||||
rmMtrClientRegistrationService.updateRmMtrClientRegistration(updateData);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
log.debug("客户端ID: {} 当前心跳次数: {},未达到3次,跳过数据库操作", clientId, newHeartbeatCount);
|
||||
}
|
||||
|
||||
// 记录处理后状态(调试用)
|
||||
String currentStatus = redisTemplate.opsForValue().get(statusKey);
|
||||
String currentTime = redisTemplate.opsForValue().get(timeKey);
|
||||
String currentHeartbeatCount = redisTemplate.opsForValue().get(heartbeatCountKey);
|
||||
Boolean currentAlertStatus = redisTemplate.hasKey(alertKey);
|
||||
log.debug("客户端ID: {} 处理后状态 - status: {}, time: {}, heartbeatCount: {}, hasAlert: {}",
|
||||
clientId, currentStatus, currentTime, currentHeartbeatCount, currentAlertStatus);
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("处理心跳消息异常, clientId: {}", clientId, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 添加一个定时任务方法,定期检查心跳状态
|
||||
@Scheduled(fixedRate = 60000) // 每60s检查一次
|
||||
public void checkHeartbeatStatus() {
|
||||
long currentTime = System.currentTimeMillis();
|
||||
log.debug("开始心跳状态检查,当前时间: {}", currentTime);
|
||||
|
||||
// 获取所有客户端时间键
|
||||
Set<String> timeKeys = redisTemplate.keys(HEARTBEAT_TIME_PREFIX + "*");
|
||||
if (timeKeys == null) {
|
||||
log.debug("未找到任何心跳时间键");
|
||||
return;
|
||||
}
|
||||
|
||||
log.debug("找到 {} 个客户端需要检查", timeKeys.size());
|
||||
|
||||
for (String timeKey : timeKeys) {
|
||||
String clientId = timeKey.substring(HEARTBEAT_TIME_PREFIX.length());
|
||||
String statusKey = HEARTBEAT_STATUS_PREFIX + clientId;
|
||||
String alertKey = HEARTBEAT_ALERT_PREFIX + clientId;
|
||||
String heartbeatCountKey = HEARTBEAT_COUNT_PREFIX + clientId;
|
||||
|
||||
try {
|
||||
// 检查是否已经存在告警
|
||||
String existingAlert = redisTemplate.opsForValue().get(alertKey);
|
||||
if ("1".equals(existingAlert)) {
|
||||
log.debug("客户端ID: {} 已有告警,跳过检查", clientId);
|
||||
continue; // 如果已有告警,跳过处理
|
||||
}
|
||||
|
||||
String lastTimeStr = redisTemplate.opsForValue().get(timeKey);
|
||||
if (lastTimeStr == null) {
|
||||
log.debug("客户端ID: {} 时间键为空,跳过", clientId);
|
||||
continue;
|
||||
}
|
||||
|
||||
long lastHeartbeatTime = Long.parseLong(lastTimeStr);
|
||||
long timeDiff = currentTime - lastHeartbeatTime;
|
||||
|
||||
log.debug("客户端ID: {} 最后心跳: {}, 时间差: {}ms, 超时阈值: {}ms",
|
||||
clientId, lastHeartbeatTime, timeDiff, HEARTBEAT_TIMEOUT);
|
||||
|
||||
if (timeDiff > HEARTBEAT_TIMEOUT) {
|
||||
// 心跳超时处理 - 使用原子操作增加计数
|
||||
Long lostCount = redisTemplate.opsForValue().increment(statusKey);
|
||||
if (lostCount == 1) {
|
||||
// 确保第一次增加时值为1
|
||||
redisTemplate.opsForValue().set(statusKey, "1");
|
||||
lostCount = 1L;
|
||||
}
|
||||
|
||||
log.warn("客户端ID: {} 心跳超时,连续次数: {}, 时间差: {}ms",
|
||||
clientId, lostCount, timeDiff);
|
||||
|
||||
if (lostCount >= 3) {
|
||||
log.warn("客户端ID: {} 连续三次心跳丢失,触发告警", clientId);
|
||||
insertHeartbeatLog(clientId, "3", "连续三次心跳丢失");
|
||||
// 告警
|
||||
insertAlarmRecords(clientId);
|
||||
redisTemplate.opsForValue().set(HEARTBEAT_ALERT_PREFIX + clientId, "1");
|
||||
// 设置告警后删除timeKey和statusKey
|
||||
redisTemplate.delete(timeKey);
|
||||
redisTemplate.delete(statusKey);
|
||||
redisTemplate.delete(heartbeatCountKey);
|
||||
|
||||
log.info("客户端ID: {} 已设置告警并清理心跳记录", clientId);
|
||||
// 修改资源状态
|
||||
updateResourceStatus(clientId, "0");
|
||||
}
|
||||
} else {
|
||||
// 如果心跳正常,重置丢失次数
|
||||
String currentStatus = redisTemplate.opsForValue().get(statusKey);
|
||||
if (!"0".equals(currentStatus)) {
|
||||
redisTemplate.opsForValue().set(statusKey, "0");
|
||||
log.debug("客户端ID: {} 心跳正常,重置丢失次数从 {} 到 0", clientId, currentStatus);
|
||||
} else {
|
||||
log.debug("客户端ID: {} 心跳正常,状态已是0", clientId);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("检查心跳状态异常, clientId: {}", clientId, e);
|
||||
}
|
||||
}
|
||||
|
||||
log.debug("心跳状态检查完成");
|
||||
}
|
||||
|
||||
// 更新资源状态的公共方法
|
||||
private void updateResourceStatus(String clientId, String status) {
|
||||
log.info("开启更新资源状态========");
|
||||
RmMtrClientRegistration updateData = new RmMtrClientRegistration();
|
||||
updateData.setMtrClientId(clientId);
|
||||
updateData.setOnlineStatus(status);
|
||||
rmMtrClientRegistrationService.updateRmMtrClientRegistration(updateData);
|
||||
}
|
||||
// 插入心跳日志到数据库
|
||||
private void insertHeartbeatLog(String machineId, String status, String remark) {
|
||||
try {
|
||||
InitialHeartbeatListenLog listenLog = new InitialHeartbeatListenLog();
|
||||
listenLog.setClientId(machineId);
|
||||
listenLog.setStatus(status); // 0-离线 1-在线 2-恢复 3-三次丢失
|
||||
listenLog.setRemark(remark);
|
||||
listenLog.setCreateTime(new Date());
|
||||
|
||||
// 调用DAO或Service插入日志
|
||||
initialHeartbeatListenLogService.insertInitialHeartbeatListenLog(listenLog);
|
||||
log.info("已记录心跳日志,客户端ID: {}, 状态: {}", machineId, status);
|
||||
} catch (Exception e) {
|
||||
log.error("插入心跳日志失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加告警日志并推送消息到企业微信
|
||||
* @param clientId
|
||||
*/
|
||||
private void insertAlarmRecords(String clientId) {
|
||||
// 查询clientId是否为交换机唯一标识
|
||||
boolean isSwitch = false;
|
||||
String switchName = "";
|
||||
RmSwitchManagementRemote rmSwitchManagementRemote = new RmSwitchManagementRemote();
|
||||
rmSwitchManagementRemote.setClientId(clientId);
|
||||
R<List<RmSwitchManagementRemote>> rmSwitchManagementRemoteListR = remoteRevenueConfigService.getSwitchNameByClientId(rmSwitchManagementRemote, SecurityConstants.INNER);
|
||||
if (rmSwitchManagementRemoteListR != null &&
|
||||
rmSwitchManagementRemoteListR.getData() != null &&
|
||||
!rmSwitchManagementRemoteListR.getData().isEmpty()) {
|
||||
isSwitch = true;
|
||||
switchName = rmSwitchManagementRemoteListR.getData().get(0).getSwitchName();
|
||||
}
|
||||
|
||||
// 创建告警日志记录
|
||||
RmAlarmLog rmAlarmLog = createAlarmLog(clientId, isSwitch, switchName);
|
||||
|
||||
// 插入告警日志
|
||||
rmAlarmLogService.insertRmAlarmLog(rmAlarmLog);
|
||||
|
||||
// 发送告警推送
|
||||
sendAlarmPush(rmAlarmLog, isSwitch);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建告警日志记录
|
||||
*/
|
||||
private RmAlarmLog createAlarmLog(String clientId, boolean isSwitch, String switchName) {
|
||||
RmAlarmLog rmAlarmLog = new RmAlarmLog();
|
||||
String alarmContent = clientId + "下线";
|
||||
|
||||
if (isSwitch) {
|
||||
rmAlarmLog.setClientId(switchName);
|
||||
rmAlarmLog.setAlarmType("2");
|
||||
} else {
|
||||
// 查询管理网公网ip
|
||||
RmNetworkInterface rmNetworkInterface = new RmNetworkInterface();
|
||||
rmNetworkInterface.setClientId(clientId);
|
||||
rmNetworkInterface.setNewFlag(1);
|
||||
List<RmNetworkInterface> interfaceList = rmNetworkInterfaceService.selectRmNetworkInterfaceList(rmNetworkInterface);
|
||||
if (interfaceList != null && !interfaceList.isEmpty()) {
|
||||
interfaceList.stream()
|
||||
.filter(info -> "2".equals(info.getBindIp()) || "3".equals(info.getBindIp()))
|
||||
.findFirst()
|
||||
.ifPresent(networkInterface -> {
|
||||
rmAlarmLog.setMgmPublicIp(networkInterface.getPublicIp());
|
||||
});
|
||||
}
|
||||
rmAlarmLog.setClientId(clientId);
|
||||
rmAlarmLog.setAlarmType("1");
|
||||
}
|
||||
|
||||
rmAlarmLog.setAlarmContent(alarmContent);
|
||||
rmAlarmLog.setAlarmTime(DateUtils.getNowDate());
|
||||
return rmAlarmLog;
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送告警推送
|
||||
*/
|
||||
private void sendAlarmPush(RmAlarmLog rmAlarmLog, boolean isSwitch) {
|
||||
String alarmTypeCode = isSwitch ? AlarmTypeEnum.交换机下线.getCode() : AlarmTypeEnum.服务器下线.getCode();
|
||||
String alarmTypeMsg = isSwitch ? AlarmTypeEnum.交换机下线.getMsg() : AlarmTypeEnum.服务器下线.getMsg();
|
||||
|
||||
RmAlarmPushConfig rmAlarmPushConfig = new RmAlarmPushConfig();
|
||||
rmAlarmPushConfig.setPushMethod(PushMethodEnum.企业微信.getCode());
|
||||
rmAlarmPushConfig.setPushAlarmTypes(alarmTypeCode);
|
||||
List<RmAlarmPushConfig> alarmConfigList = rmAlarmPushConfigService.selectRmAlarmPushConfigList(rmAlarmPushConfig);
|
||||
|
||||
if (alarmConfigList != null && !alarmConfigList.isEmpty()) {
|
||||
for (RmAlarmPushConfig alarmPushConfig : alarmConfigList) {
|
||||
String contentTemplate = alarmPushConfig.getMessageContent();
|
||||
String webhookUrl = alarmPushConfig.getPushAddress();
|
||||
Map<String, Object> alarmMap = new HashMap<>();
|
||||
alarmMap.put("告警时间", rmAlarmLog.getAlarmTime());
|
||||
alarmMap.put("管理网-公网IP", rmAlarmLog.getMgmPublicIp());
|
||||
alarmMap.put("告警类型", alarmTypeMsg);
|
||||
alarmMap.put("告警设备", rmAlarmLog.getClientId());
|
||||
alarmMap.put("告警内容", rmAlarmLog.getAlarmContent());
|
||||
|
||||
if (alarmPushConfig.getContactPhones() != null) {
|
||||
String[] phones = alarmPushConfig.getContactPhones().split(",");
|
||||
WeChatWorkBot.sendTemplateMessage(webhookUrl, contentTemplate, alarmMap, rmAlarmLog.getAlarmContent(), phones, false);
|
||||
} else {
|
||||
WeChatWorkBot.sendTemplateMessage(webhookUrl, contentTemplate, alarmMap);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存网卡信息
|
||||
* @param message
|
||||
*/
|
||||
private void handleNetWorkDelectMessage(DeviceMessage message) {
|
||||
List<RegisterMsgVo> interfaces = JsonDataParser.parseJsonData(message.getData(), RegisterMsgVo.class);
|
||||
if(!interfaces.isEmpty()) {
|
||||
String mtrClientId = message.getClientId();
|
||||
RegisterMsgVo registerMsg = interfaces.get(0);
|
||||
// 时间戳转换
|
||||
long timestamp = registerMsg.getTimestamp();
|
||||
long millis = timestamp * 1000;
|
||||
Date createTime = new Date(millis / 1000 * 1000); // 去除毫秒
|
||||
List<NetworkInfo> networkInfoList = registerMsg.getNetworkInfo();
|
||||
if(!networkInfoList.isEmpty()){
|
||||
String networkInfo = JSONObject.toJSONString(networkInfoList);
|
||||
// 查询mtrClient信息
|
||||
RmMtrClientRegistration rmMtrClientRegistration = new RmMtrClientRegistration();
|
||||
rmMtrClientRegistration.setMtrClientId(mtrClientId);
|
||||
List<RmMtrClientRegistration> mtrClientRegistrationList = rmMtrClientRegistrationService.selectRmMtrClientRegistrationList(rmMtrClientRegistration);
|
||||
if(mtrClientRegistrationList != null && !mtrClientRegistrationList.isEmpty()){
|
||||
RmMtrClientRegistration mtrClientRegistration = mtrClientRegistrationList.get(0);
|
||||
// 如果网卡信息有变动,更新网卡信息
|
||||
if(!networkInfo.equals(mtrClientRegistration.getNetworkInfo())){
|
||||
RmMtrClientRegistration updateData = new RmMtrClientRegistration();
|
||||
updateData.setId(mtrClientRegistration.getId());
|
||||
updateData.setNetworkInfo(networkInfo);
|
||||
rmMtrClientRegistrationService.updateRmMtrClientRegistration(updateData);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.ruoyi.mtragent.mapper;
|
||||
|
||||
|
||||
import com.ruoyi.mtragent.domain.InitialHeartbeatListenLog;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 心跳信息日志Mapper接口
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-09-08
|
||||
*/
|
||||
public interface InitialHeartbeatListenLogMapper
|
||||
{
|
||||
/**
|
||||
* 查询心跳信息日志
|
||||
*
|
||||
* @param clientId 心跳信息日志主键
|
||||
* @return 心跳信息日志
|
||||
*/
|
||||
public InitialHeartbeatListenLog selectInitialHeartbeatListenLogByClientId(String clientId);
|
||||
|
||||
/**
|
||||
* 查询心跳信息日志列表
|
||||
*
|
||||
* @param initialHeartbeatListenLog 心跳信息日志
|
||||
* @return 心跳信息日志集合
|
||||
*/
|
||||
public List<InitialHeartbeatListenLog> selectInitialHeartbeatListenLogList(InitialHeartbeatListenLog initialHeartbeatListenLog);
|
||||
|
||||
/**
|
||||
* 新增心跳信息日志
|
||||
*
|
||||
* @param initialHeartbeatListenLog 心跳信息日志
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertInitialHeartbeatListenLog(InitialHeartbeatListenLog initialHeartbeatListenLog);
|
||||
|
||||
/**
|
||||
* 修改心跳信息日志
|
||||
*
|
||||
* @param initialHeartbeatListenLog 心跳信息日志
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateInitialHeartbeatListenLog(InitialHeartbeatListenLog initialHeartbeatListenLog);
|
||||
|
||||
/**
|
||||
* 删除心跳信息日志
|
||||
*
|
||||
* @param clientId 心跳信息日志主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteInitialHeartbeatListenLogByClientId(String clientId);
|
||||
|
||||
/**
|
||||
* 批量删除心跳信息日志
|
||||
*
|
||||
* @param clientIds 需要删除的数据主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteInitialHeartbeatListenLogByClientIds(String[] clientIds);
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package com.ruoyi.mtragent.mapper;
|
||||
|
||||
|
||||
import com.ruoyi.mtragent.domain.RmAgentManagement;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Agent管理Mapper接口
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-09-15
|
||||
*/
|
||||
public interface RmAgentManagementMapper
|
||||
{
|
||||
/**
|
||||
* 查询Agent管理
|
||||
*
|
||||
* @param id Agent管理主键
|
||||
* @return Agent管理
|
||||
*/
|
||||
public RmAgentManagement selectRmAgentManagementById(Long id);
|
||||
|
||||
/**
|
||||
* 查询Agent管理列表
|
||||
*
|
||||
* @param rmAgentManagement Agent管理
|
||||
* @return Agent管理集合
|
||||
*/
|
||||
public List<RmAgentManagement> selectRmAgentManagementList(RmAgentManagement rmAgentManagement);
|
||||
|
||||
/**
|
||||
* 新增Agent管理
|
||||
*
|
||||
* @param rmAgentManagement Agent管理
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertRmAgentManagement(RmAgentManagement rmAgentManagement);
|
||||
|
||||
/**
|
||||
* 修改Agent管理
|
||||
*
|
||||
* @param rmAgentManagement Agent管理
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateRmAgentManagement(RmAgentManagement rmAgentManagement);
|
||||
|
||||
/**
|
||||
* 删除Agent管理
|
||||
*
|
||||
* @param id Agent管理主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteRmAgentManagementById(Long id);
|
||||
|
||||
/**
|
||||
* 批量删除Agent管理
|
||||
*
|
||||
* @param ids 需要删除的数据主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteRmAgentManagementByIds(Long[] ids);
|
||||
|
||||
void updateRmAgentManagementBySn(RmAgentManagement rmAgentManagement);
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.ruoyi.mtragent.mapper;
|
||||
|
||||
|
||||
import com.ruoyi.mtragent.domain.RmAlarmLog;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 客户端告警信息Mapper接口
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-11-10
|
||||
*/
|
||||
public interface RmAlarmLogMapper
|
||||
{
|
||||
/**
|
||||
* 查询客户端告警信息
|
||||
*
|
||||
* @param id 客户端告警信息主键
|
||||
* @return 客户端告警信息
|
||||
*/
|
||||
public RmAlarmLog selectRmAlarmLogById(Long id);
|
||||
|
||||
/**
|
||||
* 查询客户端告警信息列表
|
||||
*
|
||||
* @param rmAlarmLog 客户端告警信息
|
||||
* @return 客户端告警信息集合
|
||||
*/
|
||||
public List<RmAlarmLog> selectRmAlarmLogList(RmAlarmLog rmAlarmLog);
|
||||
|
||||
/**
|
||||
* 新增客户端告警信息
|
||||
*
|
||||
* @param rmAlarmLog 客户端告警信息
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertRmAlarmLog(RmAlarmLog rmAlarmLog);
|
||||
|
||||
/**
|
||||
* 修改客户端告警信息
|
||||
*
|
||||
* @param rmAlarmLog 客户端告警信息
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateRmAlarmLog(RmAlarmLog rmAlarmLog);
|
||||
|
||||
/**
|
||||
* 删除客户端告警信息
|
||||
*
|
||||
* @param id 客户端告警信息主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteRmAlarmLogById(Long id);
|
||||
|
||||
/**
|
||||
* 批量删除客户端告警信息
|
||||
*
|
||||
* @param ids 需要删除的数据主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteRmAlarmLogByIds(Long[] ids);
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.ruoyi.mtragent.mapper;
|
||||
|
||||
|
||||
import com.ruoyi.mtragent.domain.RmAlarmPushConfig;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 告警推送配置Mapper接口
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-11-11
|
||||
*/
|
||||
public interface RmAlarmPushConfigMapper
|
||||
{
|
||||
/**
|
||||
* 查询告警推送配置
|
||||
*
|
||||
* @param id 告警推送配置主键
|
||||
* @return 告警推送配置
|
||||
*/
|
||||
public RmAlarmPushConfig selectRmAlarmPushConfigById(Long id);
|
||||
|
||||
/**
|
||||
* 查询告警推送配置列表
|
||||
*
|
||||
* @param rmAlarmPushConfig 告警推送配置
|
||||
* @return 告警推送配置集合
|
||||
*/
|
||||
public List<RmAlarmPushConfig> selectRmAlarmPushConfigList(RmAlarmPushConfig rmAlarmPushConfig);
|
||||
|
||||
/**
|
||||
* 新增告警推送配置
|
||||
*
|
||||
* @param rmAlarmPushConfig 告警推送配置
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertRmAlarmPushConfig(RmAlarmPushConfig rmAlarmPushConfig);
|
||||
|
||||
/**
|
||||
* 修改告警推送配置
|
||||
*
|
||||
* @param rmAlarmPushConfig 告警推送配置
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateRmAlarmPushConfig(RmAlarmPushConfig rmAlarmPushConfig);
|
||||
|
||||
/**
|
||||
* 删除告警推送配置
|
||||
*
|
||||
* @param id 告警推送配置主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteRmAlarmPushConfigById(Long id);
|
||||
|
||||
/**
|
||||
* 批量删除告警推送配置
|
||||
*
|
||||
* @param ids 需要删除的数据主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteRmAlarmPushConfigByIds(Long[] ids);
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.ruoyi.mtragent.mapper;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.mtragent.domain.RmMtrClientRegistration;
|
||||
|
||||
/**
|
||||
* MTR客户端注册Mapper接口
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-11-18
|
||||
*/
|
||||
public interface RmMtrClientRegistrationMapper
|
||||
{
|
||||
/**
|
||||
* 查询MTR客户端注册
|
||||
*
|
||||
* @param id MTR客户端注册主键
|
||||
* @return MTR客户端注册
|
||||
*/
|
||||
public RmMtrClientRegistration selectRmMtrClientRegistrationById(Long id);
|
||||
|
||||
/**
|
||||
* 查询MTR客户端注册列表
|
||||
*
|
||||
* @param rmMtrClientRegistration MTR客户端注册
|
||||
* @return MTR客户端注册集合
|
||||
*/
|
||||
public List<RmMtrClientRegistration> selectRmMtrClientRegistrationList(RmMtrClientRegistration rmMtrClientRegistration);
|
||||
|
||||
/**
|
||||
* 新增MTR客户端注册
|
||||
*
|
||||
* @param rmMtrClientRegistration MTR客户端注册
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertRmMtrClientRegistration(RmMtrClientRegistration rmMtrClientRegistration);
|
||||
|
||||
/**
|
||||
* 修改MTR客户端注册
|
||||
*
|
||||
* @param rmMtrClientRegistration MTR客户端注册
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateRmMtrClientRegistration(RmMtrClientRegistration rmMtrClientRegistration);
|
||||
|
||||
/**
|
||||
* 删除MTR客户端注册
|
||||
*
|
||||
* @param id MTR客户端注册主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteRmMtrClientRegistrationById(Long id);
|
||||
|
||||
/**
|
||||
* 批量删除MTR客户端注册
|
||||
*
|
||||
* @param ids 需要删除的数据主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteRmMtrClientRegistrationByIds(Long[] ids);
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.ruoyi.mtragent.mapper;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.mtragent.domain.RmMtrPolicyConfig;
|
||||
|
||||
/**
|
||||
* mtr探测策略配置Mapper接口
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-11-18
|
||||
*/
|
||||
public interface RmMtrPolicyConfigMapper
|
||||
{
|
||||
/**
|
||||
* 查询mtr探测策略配置
|
||||
*
|
||||
* @param id mtr探测策略配置主键
|
||||
* @return mtr探测策略配置
|
||||
*/
|
||||
public RmMtrPolicyConfig selectRmMtrPolicyConfigById(Long id);
|
||||
|
||||
/**
|
||||
* 查询mtr探测策略配置列表
|
||||
*
|
||||
* @param rmMtrPolicyConfig mtr探测策略配置
|
||||
* @return mtr探测策略配置集合
|
||||
*/
|
||||
public List<RmMtrPolicyConfig> selectRmMtrPolicyConfigList(RmMtrPolicyConfig rmMtrPolicyConfig);
|
||||
|
||||
/**
|
||||
* 新增mtr探测策略配置
|
||||
*
|
||||
* @param rmMtrPolicyConfig mtr探测策略配置
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertRmMtrPolicyConfig(RmMtrPolicyConfig rmMtrPolicyConfig);
|
||||
|
||||
/**
|
||||
* 修改mtr探测策略配置
|
||||
*
|
||||
* @param rmMtrPolicyConfig mtr探测策略配置
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateRmMtrPolicyConfig(RmMtrPolicyConfig rmMtrPolicyConfig);
|
||||
|
||||
/**
|
||||
* 删除mtr探测策略配置
|
||||
*
|
||||
* @param id mtr探测策略配置主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteRmMtrPolicyConfigById(Long id);
|
||||
|
||||
/**
|
||||
* 批量删除mtr探测策略配置
|
||||
*
|
||||
* @param ids 需要删除的数据主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteRmMtrPolicyConfigByIds(Long[] ids);
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package com.ruoyi.mtragent.mapper;
|
||||
|
||||
|
||||
import com.ruoyi.mtragent.domain.RmNetworkInterface;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 客户端网络接口信息Mapper接口
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-10-14
|
||||
*/
|
||||
public interface RmNetworkInterfaceMapper
|
||||
{
|
||||
/**
|
||||
* 查询客户端网络接口信息
|
||||
*
|
||||
* @param id 客户端网络接口信息主键
|
||||
* @return 客户端网络接口信息
|
||||
*/
|
||||
public RmNetworkInterface selectRmNetworkInterfaceById(Long id);
|
||||
|
||||
/**
|
||||
* 查询客户端网络接口信息列表
|
||||
*
|
||||
* @param rmNetworkInterface 客户端网络接口信息
|
||||
* @return 客户端网络接口信息集合
|
||||
*/
|
||||
public List<RmNetworkInterface> selectRmNetworkInterfaceList(RmNetworkInterface rmNetworkInterface);
|
||||
|
||||
/**
|
||||
* 新增客户端网络接口信息
|
||||
*
|
||||
* @param rmNetworkInterface 客户端网络接口信息
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertRmNetworkInterface(RmNetworkInterface rmNetworkInterface);
|
||||
|
||||
/**
|
||||
* 修改客户端网络接口信息
|
||||
*
|
||||
* @param rmNetworkInterface 客户端网络接口信息
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateRmNetworkInterface(RmNetworkInterface rmNetworkInterface);
|
||||
|
||||
/**
|
||||
* 删除客户端网络接口信息
|
||||
*
|
||||
* @param id 客户端网络接口信息主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteRmNetworkInterfaceById(Long id);
|
||||
|
||||
/**
|
||||
* 批量删除客户端网络接口信息
|
||||
*
|
||||
* @param ids 需要删除的数据主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteRmNetworkInterfaceByIds(Long[] ids);
|
||||
|
||||
int updateRmNetworkInterfaceByMac(RmNetworkInterface rmNetworkInterface);
|
||||
}
|
||||
@@ -1,10 +1,14 @@
|
||||
package com.ruoyi.testrocketmq.model;
|
||||
package com.ruoyi.mtragent.model;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 消费者初始化
|
||||
* 消费者连接信息 具体看nacos配置
|
||||
*/
|
||||
@Data
|
||||
@Configuration
|
||||
@Component
|
||||
@@ -19,4 +23,8 @@ public class ConsumerMode {
|
||||
private int consumeThreadMax;
|
||||
@Value("${suning.rocketmq.conumer.consumeMessageBatchMaxSize}")
|
||||
private int consumeMessageBatchMaxSize;
|
||||
@Value("${suning.rocketmq.conumer.agentTopic}")
|
||||
private String agentTopic;
|
||||
@Value("${suning.rocketmq.conumer.agentGroup}")
|
||||
private String agentGroup;
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.ruoyi.testrocketmq.model;
|
||||
package com.ruoyi.mtragent.model;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
@@ -14,6 +14,10 @@ import org.springframework.context.annotation.Configuration;
|
||||
public class ProducerMode {
|
||||
@Value("${suning.rocketmq.producer.groupName}")
|
||||
private String groupName;
|
||||
@Value("${suning.rocketmq.producer.agentTopic}")
|
||||
private String agentTopic;
|
||||
@Value("${suning.rocketmq.producer.agentGroup}")
|
||||
private String agentGroup;
|
||||
@Value("${suning.rocketmq.namesrvAddr}")
|
||||
private String namesrvAddr;
|
||||
@Value("${suning.rocketmq.producer.maxMessageSize}")
|
||||
@@ -1,7 +1,10 @@
|
||||
package com.ruoyi.testrocketmq.producer;
|
||||
package com.ruoyi.mtragent.producer;
|
||||
|
||||
/**
|
||||
* @author 影子
|
||||
* 用于捕捉异常非受检异常(unchecked exception)
|
||||
* RuntimeException 和其子类的异常在编译时不需要进行强制性的异常处理,可以选择在运行时进行捕获和处理
|
||||
* 可选择使用
|
||||
*/
|
||||
public class ConsumeException extends RuntimeException{
|
||||
private static final long serialVersionUID = 4093867789628938836L;
|
||||
@@ -0,0 +1,225 @@
|
||||
package com.ruoyi.mtragent.producer;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.ruoyi.mtragent.consumer.RocketMsgTransactionListenerImpl;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.rocketmq.client.exception.MQBrokerException;
|
||||
import org.apache.rocketmq.client.exception.MQClientException;
|
||||
import org.apache.rocketmq.client.producer.SendCallback;
|
||||
import org.apache.rocketmq.client.producer.SendResult;
|
||||
import org.apache.rocketmq.client.producer.TransactionMQProducer;
|
||||
import org.apache.rocketmq.client.producer.TransactionSendResult;
|
||||
import org.apache.rocketmq.common.message.Message;
|
||||
import org.apache.rocketmq.remoting.common.RemotingHelper;
|
||||
import org.apache.rocketmq.remoting.exception.RemotingException;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import static com.ruoyi.mtragent.config.ProducerConfig.producer;
|
||||
|
||||
|
||||
/**
|
||||
* 消息发送
|
||||
*/
|
||||
@Slf4j
|
||||
public class MessageProducer {
|
||||
|
||||
|
||||
/**
|
||||
* 同步发送消息
|
||||
* @param topic 主题
|
||||
* @param tag 标签
|
||||
* @param key 自定义的key,根据业务来定
|
||||
* @param value 消息的内容
|
||||
* 通过调用 send() 方法发送消息,阻塞等待服务器响应。
|
||||
*/
|
||||
public SendResult sendSynchronizeMessage(String topic, String tag, String key, String value){
|
||||
String body = "topic:【"+topic+"】, tag:【"+tag+"】, key:【"+key+"】, value:【"+value+"】";
|
||||
try {
|
||||
Message msg = new Message(topic,tag,key, value.getBytes(RemotingHelper.DEFAULT_CHARSET));
|
||||
System.out.println("生产者发送消息:"+ JSON.toJSONString(value));
|
||||
SendResult result = producer.send(msg);
|
||||
return result;
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
log.error("消息初始化失败!body:{}",body);
|
||||
|
||||
} catch (MQClientException | InterruptedException | RemotingException | MQBrokerException e) {
|
||||
log.error("消息发送失败! body:{}",body);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 单向发送消息
|
||||
* @param topic 主题
|
||||
* @param tag 标签
|
||||
* @param key 自定义的key,根据业务来定
|
||||
* @param value 消息的内容
|
||||
* 单向发送:通过调用 sendOneway() 方法发送消息,不关心发送结果,适用于对可靠性要求不高的场景。
|
||||
*/
|
||||
public void sendOnewayMessage(String topic, String tag, String key, String value){
|
||||
String body = "topic:【"+topic+"】, tag:【"+tag+"】, key:【"+key+"】, value:【"+value+"】";
|
||||
try {
|
||||
Message msg = new Message(topic,tag,key, value.getBytes(RemotingHelper.DEFAULT_CHARSET));
|
||||
System.out.println("生产者发送消息:"+ JSON.toJSONString(value));
|
||||
producer.sendOneway(msg);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
log.error("消息初始化失败!body:{}",body);
|
||||
|
||||
} catch (MQClientException | InterruptedException | RemotingException e) {
|
||||
log.error("消息发送失败! body:{}",body);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 批量发送消息
|
||||
* @param messages 消息列表
|
||||
* 批量发送:通过调用 send() 方法并传入多条消息,实现批量发送消息。
|
||||
*/
|
||||
public SendResult sendBatchMessage(List<Message> messages){
|
||||
String body = messages.toString();
|
||||
try {
|
||||
System.out.println("生产者发送消息:"+ messages);
|
||||
// 发送批量消息
|
||||
SendResult sendResult = producer.send(messages);
|
||||
return sendResult;
|
||||
} catch (MQClientException | InterruptedException | RemotingException e) {
|
||||
log.error("消息发送失败! body:{}",body);
|
||||
} catch (MQBrokerException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 事务消息发送
|
||||
* @param topic 主题
|
||||
* @param tag 标签
|
||||
* @param key 自定义的key,根据业务来定
|
||||
* @param value 消息的内容
|
||||
* 事务消息发送:通过使用事务监听器实现本地事务执行和消息发送的一致性。
|
||||
*/
|
||||
public SendResult sendThingMessage(String topic, String tag, String key, String value){
|
||||
String body = "topic:【"+topic+"】, tag:【"+tag+"】, key:【"+key+"】, value:【"+value+"】";
|
||||
try {
|
||||
// 实例化事务生产者
|
||||
TransactionMQProducer transactionMQProducer = new TransactionMQProducer(producer.getProducerGroup());
|
||||
transactionMQProducer.setNamesrvAddr(producer.getNamesrvAddr());
|
||||
// 设置事务监听器
|
||||
transactionMQProducer.setTransactionListener(new RocketMsgTransactionListenerImpl());
|
||||
Message msg = new Message(topic,tag,key, value.getBytes(RemotingHelper.DEFAULT_CHARSET));
|
||||
System.out.println("生产者发送消息:"+ JSON.toJSONString(value));
|
||||
// 发送事务消息
|
||||
TransactionSendResult sendResult = transactionMQProducer.sendMessageInTransaction(msg, null);
|
||||
return sendResult;
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
log.error("消息初始化失败!body:{}",body);
|
||||
|
||||
} catch (MQClientException e) {
|
||||
log.error("消息发送失败! body:{}",body);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 发送有序的消息
|
||||
* @param messagesList Message集合
|
||||
* @param messageQueueNumber 消息队列数量,根据实际情况设定
|
||||
* 顺序发送: messageQueueNumber 表示消息的业务标识,可以根据具体需求进行设置来保证消息按顺序发送。
|
||||
*/
|
||||
public SendResult sendOrderlyMessage(List<Message> messagesList, Integer messageQueueNumber) {
|
||||
SendResult result = null;
|
||||
for (Message message : messagesList) {
|
||||
try {
|
||||
result = producer.send(message, (list, msg, arg) -> {
|
||||
Integer queueNumber = (Integer) arg;
|
||||
//int queueIndex = queueNumber % list.size();
|
||||
return list.get(queueNumber);
|
||||
}, messageQueueNumber);//根据编号取模,选择消息队列
|
||||
} catch (MQClientException | RemotingException | MQBrokerException | InterruptedException e) {
|
||||
log.error("发送有序消息失败");
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送延迟消息
|
||||
* @param topic 主题
|
||||
* @param tag 标签
|
||||
* @param key 自定义的key,根据业务来定
|
||||
* @param value 消息的内容
|
||||
* 延迟发送:通过设置延迟级别来实现延迟发送消息。
|
||||
*/
|
||||
public SendResult sendDelayMessage(String topic, String tag, String key, String value, Integer level)
|
||||
{
|
||||
SendResult result = null;
|
||||
try
|
||||
{
|
||||
Message msg = new Message(topic,tag,key, value.getBytes(RemotingHelper.DEFAULT_CHARSET));
|
||||
System.out.println("生产者发送消息:"+ JSON.toJSONString(value));
|
||||
//设置消息延迟级别,我这里设置5,对应就是延时一分钟
|
||||
// "1s 5s 10s 30s 1m 2m 3m 4m 5m 6m 7m 8m 9m 10m 20m 30m 1h 2h"
|
||||
msg.setDelayTimeLevel(level);
|
||||
// 发送消息到一个Broker
|
||||
result = producer.send(msg);
|
||||
// 通过sendResult返回消息是否成功送达
|
||||
log.info("发送延迟消息结果:======sendResult:{}", result);
|
||||
DateFormat format =new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
log.info("发送时间:{}", format.format(new Date()));
|
||||
return result;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
log.error("延迟消息队列推送消息异常:{},推送内容:{}", e.getMessage(), result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* 发送异步的消息
|
||||
* @param topic 主题
|
||||
* @param tag 标签
|
||||
* @param key 自定义的key,根据业务来定
|
||||
* @param value 消息的内容
|
||||
* 通过调用 send() 方法,并传入一个 SendCallback 对象,在发送消息的同时可以继续处理其他逻辑,消息发送结果通过回调函数通知。
|
||||
*/
|
||||
public SendResult sendAsyncProducerMessage(String topic, String tag, String key, String value){
|
||||
|
||||
try {
|
||||
//创建一个消息实例,指定主题、标签和消息体。
|
||||
Message msg = new Message(topic,tag,key, value.getBytes(RemotingHelper.DEFAULT_CHARSET));
|
||||
System.out.println("生产者发送消息:"+ JSON.toJSONString(value));
|
||||
producer.send(msg,new SendCallback() {
|
||||
// 异步回调的处理
|
||||
@Override
|
||||
public void onSuccess(SendResult sendResult) {
|
||||
System.out.printf("%-10d 异步发送消息成功 %s %n", msg, sendResult.getMsgId());
|
||||
}
|
||||
@Override
|
||||
public void onException(Throwable e) {
|
||||
System.out.printf("%-10d 异步发送消息失败 %s %n", msg, e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
} catch (MQClientException e) {
|
||||
e.printStackTrace();
|
||||
} catch (RemotingException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.ruoyi.mtragent.service;
|
||||
|
||||
|
||||
import com.ruoyi.mtragent.domain.InitialHeartbeatListenLog;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 心跳信息日志Service接口
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-09-08
|
||||
*/
|
||||
public interface IInitialHeartbeatListenLogService
|
||||
{
|
||||
/**
|
||||
* 查询心跳信息日志
|
||||
*
|
||||
* @param clientId 心跳信息日志主键
|
||||
* @return 心跳信息日志
|
||||
*/
|
||||
public InitialHeartbeatListenLog selectInitialHeartbeatListenLogByClientId(String clientId);
|
||||
|
||||
/**
|
||||
* 查询心跳信息日志列表
|
||||
*
|
||||
* @param initialHeartbeatListenLog 心跳信息日志
|
||||
* @return 心跳信息日志集合
|
||||
*/
|
||||
public List<InitialHeartbeatListenLog> selectInitialHeartbeatListenLogList(InitialHeartbeatListenLog initialHeartbeatListenLog);
|
||||
|
||||
/**
|
||||
* 新增心跳信息日志
|
||||
*
|
||||
* @param initialHeartbeatListenLog 心跳信息日志
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertInitialHeartbeatListenLog(InitialHeartbeatListenLog initialHeartbeatListenLog);
|
||||
|
||||
/**
|
||||
* 修改心跳信息日志
|
||||
*
|
||||
* @param initialHeartbeatListenLog 心跳信息日志
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateInitialHeartbeatListenLog(InitialHeartbeatListenLog initialHeartbeatListenLog);
|
||||
|
||||
/**
|
||||
* 批量删除心跳信息日志
|
||||
*
|
||||
* @param clientIds 需要删除的心跳信息日志主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteInitialHeartbeatListenLogByClientIds(String[] clientIds);
|
||||
|
||||
/**
|
||||
* 删除心跳信息日志信息
|
||||
*
|
||||
* @param clientId 心跳信息日志主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteInitialHeartbeatListenLogByClientId(String clientId);
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package com.ruoyi.mtragent.service;
|
||||
|
||||
|
||||
import com.ruoyi.mtragent.domain.RmAgentManagement;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Agent管理Service接口
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-09-15
|
||||
*/
|
||||
public interface IRmAgentManagementService
|
||||
{
|
||||
/**
|
||||
* 查询Agent管理
|
||||
*
|
||||
* @param id Agent管理主键
|
||||
* @return Agent管理
|
||||
*/
|
||||
public RmAgentManagement selectRmAgentManagementById(Long id);
|
||||
|
||||
/**
|
||||
* 查询Agent管理列表
|
||||
*
|
||||
* @param rmAgentManagement Agent管理
|
||||
* @return Agent管理集合
|
||||
*/
|
||||
public List<RmAgentManagement> selectRmAgentManagementList(RmAgentManagement rmAgentManagement);
|
||||
|
||||
|
||||
/**
|
||||
* 保存最后更新结果
|
||||
*
|
||||
* @param rmAgentManagement Agent管理
|
||||
* @return 结果
|
||||
*/
|
||||
public void updateRmAgentManagementByHardwareSn(RmAgentManagement rmAgentManagement);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 手动立即更新agent
|
||||
* @param rmAgentManagement
|
||||
* @return
|
||||
*/
|
||||
int updateAgentNow(RmAgentManagement rmAgentManagement);
|
||||
|
||||
/**
|
||||
* 配置更新策略
|
||||
* @param rmAgentManagement
|
||||
* @return
|
||||
*/
|
||||
int addUpdatePolicy(RmAgentManagement rmAgentManagement);
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.ruoyi.mtragent.service;
|
||||
|
||||
|
||||
import com.ruoyi.mtragent.domain.RmAlarmLog;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 客户端告警信息Service接口
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-11-10
|
||||
*/
|
||||
public interface IRmAlarmLogService
|
||||
{
|
||||
/**
|
||||
* 查询客户端告警信息
|
||||
*
|
||||
* @param id 客户端告警信息主键
|
||||
* @return 客户端告警信息
|
||||
*/
|
||||
public RmAlarmLog selectRmAlarmLogById(Long id);
|
||||
|
||||
/**
|
||||
* 查询客户端告警信息列表
|
||||
*
|
||||
* @param rmAlarmLog 客户端告警信息
|
||||
* @return 客户端告警信息集合
|
||||
*/
|
||||
public List<RmAlarmLog> selectRmAlarmLogList(RmAlarmLog rmAlarmLog);
|
||||
|
||||
/**
|
||||
* 新增客户端告警信息
|
||||
*
|
||||
* @param rmAlarmLog 客户端告警信息
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertRmAlarmLog(RmAlarmLog rmAlarmLog);
|
||||
|
||||
/**
|
||||
* 修改客户端告警信息
|
||||
*
|
||||
* @param rmAlarmLog 客户端告警信息
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateRmAlarmLog(RmAlarmLog rmAlarmLog);
|
||||
|
||||
/**
|
||||
* 批量删除客户端告警信息
|
||||
*
|
||||
* @param ids 需要删除的客户端告警信息主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteRmAlarmLogByIds(Long[] ids);
|
||||
|
||||
/**
|
||||
* 删除客户端告警信息信息
|
||||
*
|
||||
* @param id 客户端告警信息主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteRmAlarmLogById(Long id);
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.ruoyi.mtragent.service;
|
||||
|
||||
|
||||
import com.ruoyi.mtragent.domain.RmAlarmPushConfig;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 告警推送配置Service接口
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-11-11
|
||||
*/
|
||||
public interface IRmAlarmPushConfigService
|
||||
{
|
||||
/**
|
||||
* 查询告警推送配置
|
||||
*
|
||||
* @param id 告警推送配置主键
|
||||
* @return 告警推送配置
|
||||
*/
|
||||
public RmAlarmPushConfig selectRmAlarmPushConfigById(Long id);
|
||||
|
||||
/**
|
||||
* 查询告警推送配置列表
|
||||
*
|
||||
* @param rmAlarmPushConfig 告警推送配置
|
||||
* @return 告警推送配置集合
|
||||
*/
|
||||
public List<RmAlarmPushConfig> selectRmAlarmPushConfigList(RmAlarmPushConfig rmAlarmPushConfig);
|
||||
|
||||
/**
|
||||
* 新增告警推送配置
|
||||
*
|
||||
* @param rmAlarmPushConfig 告警推送配置
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertRmAlarmPushConfig(RmAlarmPushConfig rmAlarmPushConfig);
|
||||
|
||||
/**
|
||||
* 修改告警推送配置
|
||||
*
|
||||
* @param rmAlarmPushConfig 告警推送配置
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateRmAlarmPushConfig(RmAlarmPushConfig rmAlarmPushConfig);
|
||||
|
||||
/**
|
||||
* 批量删除告警推送配置
|
||||
*
|
||||
* @param ids 需要删除的告警推送配置主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteRmAlarmPushConfigByIds(Long[] ids);
|
||||
|
||||
/**
|
||||
* 删除告警推送配置信息
|
||||
*
|
||||
* @param id 告警推送配置主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteRmAlarmPushConfigById(Long id);
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package com.ruoyi.mtragent.service;
|
||||
|
||||
import com.ruoyi.mtragent.domain.RmMtrClientRegistration;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* MTR客户端注册Service接口
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-11-18
|
||||
*/
|
||||
public interface IRmMtrClientRegistrationService
|
||||
{
|
||||
/**
|
||||
* 查询MTR客户端注册
|
||||
*
|
||||
* @param id MTR客户端注册主键
|
||||
* @return MTR客户端注册
|
||||
*/
|
||||
public RmMtrClientRegistration selectRmMtrClientRegistrationById(Long id);
|
||||
|
||||
/**
|
||||
* 查询MTR客户端注册列表
|
||||
*
|
||||
* @param rmMtrClientRegistration MTR客户端注册
|
||||
* @return MTR客户端注册集合
|
||||
*/
|
||||
public List<RmMtrClientRegistration> selectRmMtrClientRegistrationList(RmMtrClientRegistration rmMtrClientRegistration);
|
||||
|
||||
/**
|
||||
* 新增MTR客户端注册
|
||||
*
|
||||
* @param rmMtrClientRegistration MTR客户端注册
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertRmMtrClientRegistration(RmMtrClientRegistration rmMtrClientRegistration);
|
||||
|
||||
/**
|
||||
* 修改MTR客户端注册
|
||||
*
|
||||
* @param rmMtrClientRegistration MTR客户端注册
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateRmMtrClientRegistration(RmMtrClientRegistration rmMtrClientRegistration);
|
||||
|
||||
/**
|
||||
* 批量删除MTR客户端注册
|
||||
*
|
||||
* @param ids 需要删除的MTR客户端注册主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteRmMtrClientRegistrationByIds(Long[] ids);
|
||||
|
||||
/**
|
||||
* 删除MTR客户端注册信息
|
||||
*
|
||||
* @param id MTR客户端注册主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteRmMtrClientRegistrationById(Long id);
|
||||
|
||||
/**
|
||||
* 配置更新策略
|
||||
* @param rmMtrClientRegistration
|
||||
* @return
|
||||
*/
|
||||
int addAgentUpdatePolicy(RmMtrClientRegistration rmMtrClientRegistration);
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.ruoyi.mtragent.service;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.mtragent.domain.RmMtrPolicyConfig;
|
||||
|
||||
/**
|
||||
* mtr探测策略配置Service接口
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-11-18
|
||||
*/
|
||||
public interface IRmMtrPolicyConfigService
|
||||
{
|
||||
/**
|
||||
* 查询mtr探测策略配置
|
||||
*
|
||||
* @param id mtr探测策略配置主键
|
||||
* @return mtr探测策略配置
|
||||
*/
|
||||
public RmMtrPolicyConfig selectRmMtrPolicyConfigById(Long id);
|
||||
|
||||
/**
|
||||
* 查询mtr探测策略配置列表
|
||||
*
|
||||
* @param rmMtrPolicyConfig mtr探测策略配置
|
||||
* @return mtr探测策略配置集合
|
||||
*/
|
||||
public List<RmMtrPolicyConfig> selectRmMtrPolicyConfigList(RmMtrPolicyConfig rmMtrPolicyConfig);
|
||||
|
||||
/**
|
||||
* 新增mtr探测策略配置
|
||||
*
|
||||
* @param rmMtrPolicyConfig mtr探测策略配置
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertRmMtrPolicyConfig(RmMtrPolicyConfig rmMtrPolicyConfig);
|
||||
|
||||
/**
|
||||
* 修改mtr探测策略配置
|
||||
*
|
||||
* @param rmMtrPolicyConfig mtr探测策略配置
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateRmMtrPolicyConfig(RmMtrPolicyConfig rmMtrPolicyConfig);
|
||||
|
||||
/**
|
||||
* 批量删除mtr探测策略配置
|
||||
*
|
||||
* @param ids 需要删除的mtr探测策略配置主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteRmMtrPolicyConfigByIds(Long[] ids);
|
||||
|
||||
/**
|
||||
* 删除mtr探测策略配置信息
|
||||
*
|
||||
* @param id mtr探测策略配置主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteRmMtrPolicyConfigById(Long id);
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package com.ruoyi.mtragent.service;
|
||||
|
||||
|
||||
import com.ruoyi.mtragent.domain.RmNetworkInterface;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 客户端网络接口信息Service接口
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-10-14
|
||||
*/
|
||||
public interface IRmNetworkInterfaceService
|
||||
{
|
||||
/**
|
||||
* 查询客户端网络接口信息
|
||||
*
|
||||
* @param id 客户端网络接口信息主键
|
||||
* @return 客户端网络接口信息
|
||||
*/
|
||||
public RmNetworkInterface selectRmNetworkInterfaceById(Long id);
|
||||
|
||||
/**
|
||||
* 查询客户端网络接口信息列表
|
||||
*
|
||||
* @param rmNetworkInterface 客户端网络接口信息
|
||||
* @return 客户端网络接口信息集合
|
||||
*/
|
||||
public List<RmNetworkInterface> selectRmNetworkInterfaceList(RmNetworkInterface rmNetworkInterface);
|
||||
|
||||
/**
|
||||
* 新增客户端网络接口信息
|
||||
*
|
||||
* @param rmNetworkInterface 客户端网络接口信息
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertRmNetworkInterface(RmNetworkInterface rmNetworkInterface);
|
||||
|
||||
/**
|
||||
* 修改客户端网络接口信息
|
||||
*
|
||||
* @param rmNetworkInterface 客户端网络接口信息
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateRmNetworkInterface(RmNetworkInterface rmNetworkInterface);
|
||||
/**
|
||||
* 修改客户端网络接口信息
|
||||
*
|
||||
* @param rmNetworkInterface 客户端网络接口信息
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateRmNetworkInterfaceByMac(RmNetworkInterface rmNetworkInterface);
|
||||
|
||||
/**
|
||||
* 批量删除客户端网络接口信息
|
||||
*
|
||||
* @param ids 需要删除的客户端网络接口信息主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteRmNetworkInterfaceByIds(Long[] ids);
|
||||
|
||||
/**
|
||||
* 删除客户端网络接口信息信息
|
||||
*
|
||||
* @param id 客户端网络接口信息主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteRmNetworkInterfaceById(Long id);
|
||||
|
||||
/**
|
||||
* 绑定公网ip
|
||||
* @param rmNetworkInterface
|
||||
* @return
|
||||
*/
|
||||
int bindPublicIp(RmNetworkInterface rmNetworkInterface);
|
||||
|
||||
/**
|
||||
* 更新路由信息
|
||||
* @param clientId
|
||||
*/
|
||||
void updateRouteMsg(String clientId);
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
package com.ruoyi.mtragent.service.impl;
|
||||
|
||||
import com.ruoyi.common.core.utils.DateUtils;
|
||||
import com.ruoyi.mtragent.domain.InitialHeartbeatListenLog;
|
||||
import com.ruoyi.mtragent.mapper.InitialHeartbeatListenLogMapper;
|
||||
import com.ruoyi.mtragent.service.IInitialHeartbeatListenLogService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 心跳信息日志Service业务层处理
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-09-08
|
||||
*/
|
||||
@Service
|
||||
public class InitialHeartbeatListenLogServiceImpl implements IInitialHeartbeatListenLogService
|
||||
{
|
||||
@Autowired
|
||||
private InitialHeartbeatListenLogMapper initialHeartbeatListenLogMapper;
|
||||
|
||||
/**
|
||||
* 查询心跳信息日志
|
||||
*
|
||||
* @param clientId 心跳信息日志主键
|
||||
* @return 心跳信息日志
|
||||
*/
|
||||
@Override
|
||||
public InitialHeartbeatListenLog selectInitialHeartbeatListenLogByClientId(String clientId)
|
||||
{
|
||||
return initialHeartbeatListenLogMapper.selectInitialHeartbeatListenLogByClientId(clientId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询心跳信息日志列表
|
||||
*
|
||||
* @param initialHeartbeatListenLog 心跳信息日志
|
||||
* @return 心跳信息日志
|
||||
*/
|
||||
@Override
|
||||
public List<InitialHeartbeatListenLog> selectInitialHeartbeatListenLogList(InitialHeartbeatListenLog initialHeartbeatListenLog)
|
||||
{
|
||||
return initialHeartbeatListenLogMapper.selectInitialHeartbeatListenLogList(initialHeartbeatListenLog);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增心跳信息日志
|
||||
*
|
||||
* @param initialHeartbeatListenLog 心跳信息日志
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int insertInitialHeartbeatListenLog(InitialHeartbeatListenLog initialHeartbeatListenLog)
|
||||
{
|
||||
initialHeartbeatListenLog.setCreateTime(DateUtils.getNowDate());
|
||||
return initialHeartbeatListenLogMapper.insertInitialHeartbeatListenLog(initialHeartbeatListenLog);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改心跳信息日志
|
||||
*
|
||||
* @param initialHeartbeatListenLog 心跳信息日志
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int updateInitialHeartbeatListenLog(InitialHeartbeatListenLog initialHeartbeatListenLog)
|
||||
{
|
||||
initialHeartbeatListenLog.setUpdateTime(DateUtils.getNowDate());
|
||||
return initialHeartbeatListenLogMapper.updateInitialHeartbeatListenLog(initialHeartbeatListenLog);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除心跳信息日志
|
||||
*
|
||||
* @param clientIds 需要删除的心跳信息日志主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteInitialHeartbeatListenLogByClientIds(String[] clientIds)
|
||||
{
|
||||
return initialHeartbeatListenLogMapper.deleteInitialHeartbeatListenLogByClientIds(clientIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除心跳信息日志信息
|
||||
*
|
||||
* @param clientId 心跳信息日志主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteInitialHeartbeatListenLogByClientId(String clientId)
|
||||
{
|
||||
return initialHeartbeatListenLogMapper.deleteInitialHeartbeatListenLogByClientId(clientId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,202 @@
|
||||
package com.ruoyi.mtragent.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.ruoyi.common.core.constant.SecurityConstants;
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import com.ruoyi.common.core.enums.MsgEnum;
|
||||
import com.ruoyi.common.core.utils.DateUtils;
|
||||
import com.ruoyi.mtragent.domain.DeviceMessage;
|
||||
import com.ruoyi.mtragent.domain.RmAgentManagement;
|
||||
import com.ruoyi.mtragent.domain.vo.AgentUpdateMsgVo;
|
||||
import com.ruoyi.mtragent.domain.vo.PolicyTypeVo;
|
||||
import com.ruoyi.mtragent.domain.vo.PolicyVo;
|
||||
import com.ruoyi.mtragent.mapper.RmAgentManagementMapper;
|
||||
import com.ruoyi.mtragent.model.ProducerMode;
|
||||
import com.ruoyi.mtragent.producer.MessageProducer;
|
||||
import com.ruoyi.mtragent.service.IRmAgentManagementService;
|
||||
import com.ruoyi.system.api.RemoteRevenueConfigService;
|
||||
import com.ruoyi.system.api.domain.RmResourceRegistrationRemote;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Agent管理Service业务层处理
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-09-15
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class RmAgentManagementServiceImpl implements IRmAgentManagementService
|
||||
{
|
||||
@Autowired
|
||||
private RmAgentManagementMapper rmAgentManagementMapper;
|
||||
@Autowired
|
||||
private RemoteRevenueConfigService remoteRevenueConfigService;
|
||||
@Autowired
|
||||
private ProducerMode producerMode;
|
||||
|
||||
/**
|
||||
* 查询Agent管理
|
||||
*
|
||||
* @param id Agent管理主键
|
||||
* @return Agent管理
|
||||
*/
|
||||
@Override
|
||||
public RmAgentManagement selectRmAgentManagementById(Long id)
|
||||
{
|
||||
RmAgentManagement agentManagement = rmAgentManagementMapper.selectRmAgentManagementById(id);
|
||||
if(agentManagement != null){
|
||||
if(agentManagement.getClientId() != null){
|
||||
// 赋其他值
|
||||
setPropties(agentManagement);
|
||||
}
|
||||
}
|
||||
return agentManagement;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询Agent管理列表
|
||||
*
|
||||
* @param rmAgentManagement Agent管理
|
||||
* @return Agent管理
|
||||
*/
|
||||
@Override
|
||||
public List<RmAgentManagement> selectRmAgentManagementList(RmAgentManagement rmAgentManagement)
|
||||
{
|
||||
List<RmAgentManagement> managementList = rmAgentManagementMapper.selectRmAgentManagementList(rmAgentManagement);
|
||||
for (RmAgentManagement agentManagement : managementList) {
|
||||
if(agentManagement.getClientId()!=null){
|
||||
// 查询注册表信息赋值
|
||||
setPropties(agentManagement);
|
||||
}
|
||||
}
|
||||
return managementList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据注册表赋值
|
||||
* @param agentManagement
|
||||
*/
|
||||
public void setPropties(RmAgentManagement agentManagement){
|
||||
String clientId = agentManagement.getClientId();
|
||||
// 设置其他信息
|
||||
RmResourceRegistrationRemote queryRegist = new RmResourceRegistrationRemote();
|
||||
queryRegist.setClientId(clientId);
|
||||
R<RmResourceRegistrationRemote> registMsgR = remoteRevenueConfigService.getListByHardwareSn(queryRegist, SecurityConstants.INNER);
|
||||
if(registMsgR != null && registMsgR.getData() != null){
|
||||
RmResourceRegistrationRemote registMsg = registMsgR.getData();
|
||||
agentManagement.setStatus(registMsg.getOnlineStatus());
|
||||
agentManagement.setHardwareSn(registMsg.getHardwareSn());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存最后更新结果
|
||||
*
|
||||
* @param rmAgentManagement Agent管理
|
||||
* @return 结果
|
||||
*/
|
||||
public void updateRmAgentManagementByHardwareSn(RmAgentManagement rmAgentManagement){
|
||||
rmAgentManagementMapper.updateRmAgentManagementBySn(rmAgentManagement);
|
||||
}
|
||||
|
||||
/**
|
||||
* 配置更新策略v1.1
|
||||
* @param rmAgentManagement
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int addUpdatePolicy(RmAgentManagement rmAgentManagement) {
|
||||
processAgentData(rmAgentManagement);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 手动立即更新
|
||||
* @param rmAgentManagement 更新信息
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int updateAgentNow(RmAgentManagement rmAgentManagement) {
|
||||
processAgentData(rmAgentManagement);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理agen更新数据
|
||||
* @param rmAgentManagement
|
||||
*/
|
||||
public void processAgentData(RmAgentManagement rmAgentManagement){
|
||||
String clientIds = rmAgentManagement.getDeployDevice();
|
||||
String[] clientIdArr = clientIds.split("\n");
|
||||
for (String clientId : clientIdArr) {
|
||||
// 创建新的对象,避免污染原始数据
|
||||
RmAgentManagement currentAgent = new RmAgentManagement();
|
||||
// 复制原始对象的属性
|
||||
BeanUtils.copyProperties(rmAgentManagement, currentAgent);
|
||||
// 设置当前循环的 clientId
|
||||
currentAgent.setClientId(clientId);
|
||||
currentAgent.setDeployDevice(clientId);
|
||||
// 查询该资源是否已经配置
|
||||
RmAgentManagement agentQueryParam = new RmAgentManagement();
|
||||
agentQueryParam.setClientId(clientId);
|
||||
List<RmAgentManagement> agentManagements = rmAgentManagementMapper.selectRmAgentManagementList(agentQueryParam);
|
||||
if(!agentManagements.isEmpty()){
|
||||
// 如果存在,修改
|
||||
currentAgent.setLastUpdateTime(DateUtils.getNowDate());
|
||||
if("0".equals(rmAgentManagement.getMethod())){
|
||||
currentAgent.setScheduledUpdateTime(null);
|
||||
}
|
||||
rmAgentManagementMapper.updateRmAgentManagement(currentAgent);
|
||||
}else{
|
||||
// 如果不存在,添加
|
||||
currentAgent.setLastUpdateTime(DateUtils.getNowDate());
|
||||
if("0".equals(rmAgentManagement.getMethod())){
|
||||
currentAgent.setScheduledUpdateTime(null);
|
||||
}
|
||||
rmAgentManagementMapper.insertRmAgentManagement(currentAgent);
|
||||
}
|
||||
// 构建更新策略
|
||||
AgentUpdateMsgVo agentUpdateMsgVo = new AgentUpdateMsgVo();
|
||||
agentUpdateMsgVo.setFileUrl(rmAgentManagement.getFileUrl());
|
||||
agentUpdateMsgVo.setFileMd5(rmAgentManagement.getFileMd5());
|
||||
agentUpdateMsgVo.setMethod(rmAgentManagement.getMethod());
|
||||
if(rmAgentManagement.getMethod() == 1){
|
||||
Date scheduledUpdateTime = rmAgentManagement.getScheduledUpdateTime();
|
||||
long scheduledTime = scheduledUpdateTime.toInstant().getEpochSecond();
|
||||
agentUpdateMsgVo.setPolicyTime(scheduledTime);
|
||||
}
|
||||
try {
|
||||
PolicyVo<AgentUpdateMsgVo> policyVo = new PolicyVo();
|
||||
List<AgentUpdateMsgVo> list = new ArrayList<>();
|
||||
list.add(agentUpdateMsgVo);
|
||||
policyVo.setContents(list);
|
||||
String policyVoStr = JSONObject.toJSONString(policyVo);
|
||||
PolicyTypeVo policyTypeVo = new PolicyTypeVo();
|
||||
policyTypeVo.setVersions(policyVoStr);
|
||||
String configJson = JSONObject.toJSONString(policyTypeVo);
|
||||
DeviceMessage deviceMessage = new DeviceMessage();
|
||||
deviceMessage.setClientId(clientId);
|
||||
deviceMessage.setDataType(MsgEnum.获取最新策略应答.getValue());
|
||||
deviceMessage.setData(configJson);
|
||||
MessageProducer messageProducer = new MessageProducer();
|
||||
|
||||
messageProducer.sendAsyncProducerMessage(
|
||||
producerMode.getAgentTopic(),
|
||||
"",
|
||||
"",
|
||||
JSONObject.toJSONString(deviceMessage)
|
||||
);
|
||||
} catch (Exception e) {
|
||||
log.error("发送设备配置失败,deviceId: {}", rmAgentManagement.getHardwareSn(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
package com.ruoyi.mtragent.service.impl;
|
||||
|
||||
import com.ruoyi.common.core.utils.DateUtils;
|
||||
import com.ruoyi.mtragent.domain.RmAlarmLog;
|
||||
import com.ruoyi.mtragent.mapper.RmAlarmLogMapper;
|
||||
import com.ruoyi.mtragent.service.IRmAlarmLogService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 客户端告警信息Service业务层处理
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-11-10
|
||||
*/
|
||||
@Service
|
||||
public class RmAlarmLogServiceImpl implements IRmAlarmLogService
|
||||
{
|
||||
@Autowired
|
||||
private RmAlarmLogMapper rmAlarmLogMapper;
|
||||
|
||||
/**
|
||||
* 查询客户端告警信息
|
||||
*
|
||||
* @param id 客户端告警信息主键
|
||||
* @return 客户端告警信息
|
||||
*/
|
||||
@Override
|
||||
public RmAlarmLog selectRmAlarmLogById(Long id)
|
||||
{
|
||||
return rmAlarmLogMapper.selectRmAlarmLogById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询客户端告警信息列表
|
||||
*
|
||||
* @param rmAlarmLog 客户端告警信息
|
||||
* @return 客户端告警信息
|
||||
*/
|
||||
@Override
|
||||
public List<RmAlarmLog> selectRmAlarmLogList(RmAlarmLog rmAlarmLog)
|
||||
{
|
||||
return rmAlarmLogMapper.selectRmAlarmLogList(rmAlarmLog);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增客户端告警信息
|
||||
*
|
||||
* @param rmAlarmLog 客户端告警信息
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int insertRmAlarmLog(RmAlarmLog rmAlarmLog)
|
||||
{
|
||||
rmAlarmLog.setCreateTime(DateUtils.getNowDate());
|
||||
return rmAlarmLogMapper.insertRmAlarmLog(rmAlarmLog);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改客户端告警信息
|
||||
*
|
||||
* @param rmAlarmLog 客户端告警信息
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int updateRmAlarmLog(RmAlarmLog rmAlarmLog)
|
||||
{
|
||||
rmAlarmLog.setUpdateTime(DateUtils.getNowDate());
|
||||
return rmAlarmLogMapper.updateRmAlarmLog(rmAlarmLog);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除客户端告警信息
|
||||
*
|
||||
* @param ids 需要删除的客户端告警信息主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteRmAlarmLogByIds(Long[] ids)
|
||||
{
|
||||
return rmAlarmLogMapper.deleteRmAlarmLogByIds(ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除客户端告警信息信息
|
||||
*
|
||||
* @param id 客户端告警信息主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteRmAlarmLogById(Long id)
|
||||
{
|
||||
return rmAlarmLogMapper.deleteRmAlarmLogById(id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
package com.ruoyi.mtragent.service.impl;
|
||||
|
||||
import com.ruoyi.common.core.utils.DateUtils;
|
||||
import com.ruoyi.mtragent.domain.RmAlarmPushConfig;
|
||||
import com.ruoyi.mtragent.mapper.RmAlarmPushConfigMapper;
|
||||
import com.ruoyi.mtragent.service.IRmAlarmPushConfigService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 告警推送配置Service业务层处理
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-11-11
|
||||
*/
|
||||
@Service
|
||||
public class RmAlarmPushConfigServiceImpl implements IRmAlarmPushConfigService
|
||||
{
|
||||
@Autowired
|
||||
private RmAlarmPushConfigMapper rmAlarmPushConfigMapper;
|
||||
|
||||
/**
|
||||
* 查询告警推送配置
|
||||
*
|
||||
* @param id 告警推送配置主键
|
||||
* @return 告警推送配置
|
||||
*/
|
||||
@Override
|
||||
public RmAlarmPushConfig selectRmAlarmPushConfigById(Long id)
|
||||
{
|
||||
return rmAlarmPushConfigMapper.selectRmAlarmPushConfigById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询告警推送配置列表
|
||||
*
|
||||
* @param rmAlarmPushConfig 告警推送配置
|
||||
* @return 告警推送配置
|
||||
*/
|
||||
@Override
|
||||
public List<RmAlarmPushConfig> selectRmAlarmPushConfigList(RmAlarmPushConfig rmAlarmPushConfig)
|
||||
{
|
||||
return rmAlarmPushConfigMapper.selectRmAlarmPushConfigList(rmAlarmPushConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增告警推送配置
|
||||
*
|
||||
* @param rmAlarmPushConfig 告警推送配置
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int insertRmAlarmPushConfig(RmAlarmPushConfig rmAlarmPushConfig)
|
||||
{
|
||||
rmAlarmPushConfig.setCreateTime(DateUtils.getNowDate());
|
||||
return rmAlarmPushConfigMapper.insertRmAlarmPushConfig(rmAlarmPushConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改告警推送配置
|
||||
*
|
||||
* @param rmAlarmPushConfig 告警推送配置
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int updateRmAlarmPushConfig(RmAlarmPushConfig rmAlarmPushConfig)
|
||||
{
|
||||
rmAlarmPushConfig.setUpdateTime(DateUtils.getNowDate());
|
||||
return rmAlarmPushConfigMapper.updateRmAlarmPushConfig(rmAlarmPushConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除告警推送配置
|
||||
*
|
||||
* @param ids 需要删除的告警推送配置主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteRmAlarmPushConfigByIds(Long[] ids)
|
||||
{
|
||||
return rmAlarmPushConfigMapper.deleteRmAlarmPushConfigByIds(ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除告警推送配置信息
|
||||
*
|
||||
* @param id 告警推送配置主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteRmAlarmPushConfigById(Long id)
|
||||
{
|
||||
return rmAlarmPushConfigMapper.deleteRmAlarmPushConfigById(id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,212 @@
|
||||
package com.ruoyi.mtragent.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.ruoyi.common.core.enums.MsgEnum;
|
||||
import com.ruoyi.common.core.utils.DateUtils;
|
||||
import com.ruoyi.mtragent.domain.DeviceMessage;
|
||||
import com.ruoyi.mtragent.domain.RmMtrClientRegistration;
|
||||
import com.ruoyi.mtragent.domain.vo.AgentUpdateMsgVo;
|
||||
import com.ruoyi.mtragent.domain.vo.PolicyTypeVo;
|
||||
import com.ruoyi.mtragent.domain.vo.PolicyVo;
|
||||
import com.ruoyi.mtragent.mapper.RmMtrClientRegistrationMapper;
|
||||
import com.ruoyi.mtragent.model.ProducerMode;
|
||||
import com.ruoyi.mtragent.producer.MessageProducer;
|
||||
import com.ruoyi.mtragent.service.IRmMtrClientRegistrationService;
|
||||
import com.ruoyi.system.api.domain.NetworkInfo;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
/**
|
||||
* MTR客户端注册Service业务层处理
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-11-18
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class RmMtrClientRegistrationServiceImpl implements IRmMtrClientRegistrationService
|
||||
{
|
||||
@Autowired
|
||||
private RmMtrClientRegistrationMapper rmMtrClientRegistrationMapper;
|
||||
@Autowired
|
||||
private ProducerMode producerMode;
|
||||
|
||||
/**
|
||||
* 查询MTR客户端注册
|
||||
*
|
||||
* @param id MTR客户端注册主键
|
||||
* @return MTR客户端注册
|
||||
*/
|
||||
@Override
|
||||
public RmMtrClientRegistration selectRmMtrClientRegistrationById(Long id)
|
||||
{
|
||||
RmMtrClientRegistration rmMtrClientRegistration = rmMtrClientRegistrationMapper.selectRmMtrClientRegistrationById(id);
|
||||
// 处理网卡信息
|
||||
setNetworkMsg(rmMtrClientRegistration);
|
||||
return rmMtrClientRegistration;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询MTR客户端注册列表
|
||||
*
|
||||
* @param rmMtrClientRegistration MTR客户端注册
|
||||
* @return MTR客户端注册
|
||||
*/
|
||||
@Override
|
||||
public List<RmMtrClientRegistration> selectRmMtrClientRegistrationList(RmMtrClientRegistration rmMtrClientRegistration)
|
||||
{
|
||||
List<RmMtrClientRegistration> list = rmMtrClientRegistrationMapper.selectRmMtrClientRegistrationList(rmMtrClientRegistration);
|
||||
for (RmMtrClientRegistration mtrClientRegistration : list) {
|
||||
// 处理网卡信息
|
||||
setNetworkMsg(rmMtrClientRegistration);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 网卡信息处理
|
||||
* @param rmMtrClientRegistration
|
||||
*/
|
||||
public void setNetworkMsg(RmMtrClientRegistration rmMtrClientRegistration){
|
||||
String networkMsg = rmMtrClientRegistration.getNetworkInfo();
|
||||
StringJoiner resultJoiner = new StringJoiner(";");
|
||||
if(networkMsg != null){
|
||||
List<NetworkInfo> networkInfoList = JSONObject.parseArray(networkMsg, NetworkInfo.class);
|
||||
for (NetworkInfo networkInfo : networkInfoList) {
|
||||
String name = networkInfo.getName() != null ? networkInfo.getName() : "";
|
||||
String mac = networkInfo.getMac() != null ? networkInfo.getMac() : "";
|
||||
String type = networkInfo.getType() != null ? networkInfo.getType() : "";
|
||||
String ipv4 = networkInfo.getIpv4() != null ? networkInfo.getIpv4() : "";
|
||||
// 单个对象的字段用逗号隔开
|
||||
StringJoiner objectJoiner = new StringJoiner(",");
|
||||
objectJoiner.add("接口名称:" + name)
|
||||
.add("MAC地址:" + mac)
|
||||
.add("接口类型:" + type)
|
||||
.add("IPv4地址:" + ipv4);
|
||||
resultJoiner.add(objectJoiner.toString());
|
||||
}
|
||||
rmMtrClientRegistration.setNetworkInfo(resultJoiner.toString());
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 新增MTR客户端注册
|
||||
*
|
||||
* @param rmMtrClientRegistration MTR客户端注册
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int insertRmMtrClientRegistration(RmMtrClientRegistration rmMtrClientRegistration)
|
||||
{
|
||||
rmMtrClientRegistration.setCreateTime(DateUtils.getNowDate());
|
||||
return rmMtrClientRegistrationMapper.insertRmMtrClientRegistration(rmMtrClientRegistration);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改MTR客户端注册
|
||||
*
|
||||
* @param rmMtrClientRegistration MTR客户端注册
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int updateRmMtrClientRegistration(RmMtrClientRegistration rmMtrClientRegistration)
|
||||
{
|
||||
rmMtrClientRegistration.setUpdateTime(DateUtils.getNowDate());
|
||||
return rmMtrClientRegistrationMapper.updateRmMtrClientRegistration(rmMtrClientRegistration);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除MTR客户端注册
|
||||
*
|
||||
* @param ids 需要删除的MTR客户端注册主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteRmMtrClientRegistrationByIds(Long[] ids)
|
||||
{
|
||||
return rmMtrClientRegistrationMapper.deleteRmMtrClientRegistrationByIds(ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除MTR客户端注册信息
|
||||
*
|
||||
* @param id MTR客户端注册主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteRmMtrClientRegistrationById(Long id)
|
||||
{
|
||||
return rmMtrClientRegistrationMapper.deleteRmMtrClientRegistrationById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 配置更新策略
|
||||
* @param rmMtrClientRegistration
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int addAgentUpdatePolicy(RmMtrClientRegistration rmMtrClientRegistration) {
|
||||
String mtrClientIdStr = rmMtrClientRegistration.getMtrClientIds();
|
||||
String[] mtrClientIdArr = mtrClientIdStr.split("\n");
|
||||
|
||||
// 只提取公共变量
|
||||
String method = rmMtrClientRegistration.getMethod();
|
||||
String fileMd5 = rmMtrClientRegistration.getFileMd5();
|
||||
String filePath = rmMtrClientRegistration.getFilePath();
|
||||
Date scheduledUpdateTime = rmMtrClientRegistration.getScheduledUpdateTime();
|
||||
|
||||
for (String mtrClientId : mtrClientIdArr) {
|
||||
// 配置更新参数
|
||||
RmMtrClientRegistration updateData = new RmMtrClientRegistration();
|
||||
updateData.setMtrClientId(mtrClientId);
|
||||
updateData.setMethod(method);
|
||||
updateData.setFileMd5(fileMd5);
|
||||
updateData.setFilePath(filePath);
|
||||
updateData.setScheduledUpdateTime(scheduledUpdateTime);
|
||||
if("0".equals(method)){
|
||||
updateData.setScheduledUpdateTime(null);
|
||||
}
|
||||
rmMtrClientRegistrationMapper.updateRmMtrClientRegistration(updateData);
|
||||
// 构建更新策略
|
||||
AgentUpdateMsgVo agentUpdateMsgVo = new AgentUpdateMsgVo();
|
||||
agentUpdateMsgVo.setFileUrl(filePath);
|
||||
agentUpdateMsgVo.setFileMd5(fileMd5);
|
||||
agentUpdateMsgVo.setMethod(Integer.valueOf(method));
|
||||
if("1".equals(method)){
|
||||
Date scheduledUpdateTimeInner = scheduledUpdateTime;
|
||||
long scheduledTime = scheduledUpdateTimeInner.toInstant().getEpochSecond();
|
||||
agentUpdateMsgVo.setPolicyTime(scheduledTime);
|
||||
}
|
||||
try {
|
||||
PolicyVo<AgentUpdateMsgVo> policyVo = new PolicyVo();
|
||||
List<AgentUpdateMsgVo> list = new ArrayList<>();
|
||||
list.add(agentUpdateMsgVo);
|
||||
policyVo.setContents(list);
|
||||
String policyVoStr = JSONObject.toJSONString(policyVo);
|
||||
PolicyTypeVo policyTypeVo = new PolicyTypeVo();
|
||||
policyTypeVo.setVersions(policyVoStr);
|
||||
String configJson = JSONObject.toJSONString(policyTypeVo);
|
||||
DeviceMessage deviceMessage = new DeviceMessage();
|
||||
deviceMessage.setClientId(mtrClientId);
|
||||
deviceMessage.setDataType(MsgEnum.获取最新策略应答.getValue());
|
||||
deviceMessage.setData(configJson);
|
||||
MessageProducer messageProducer = new MessageProducer();
|
||||
|
||||
messageProducer.sendAsyncProducerMessage(
|
||||
producerMode.getAgentTopic(),
|
||||
"",
|
||||
"",
|
||||
JSONObject.toJSONString(deviceMessage)
|
||||
);
|
||||
} catch (Exception e) {
|
||||
log.error("发送设备配置失败,deviceId: {}", mtrClientId, e);
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
package com.ruoyi.mtragent.service.impl;
|
||||
|
||||
import com.ruoyi.common.core.constant.SecurityConstants;
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import com.ruoyi.common.core.utils.DateUtils;
|
||||
import com.ruoyi.common.security.utils.SecurityUtils;
|
||||
import com.ruoyi.mtragent.domain.RmMtrPolicyConfig;
|
||||
import com.ruoyi.mtragent.mapper.RmMtrPolicyConfigMapper;
|
||||
import com.ruoyi.mtragent.service.IRmMtrPolicyConfigService;
|
||||
import com.ruoyi.system.api.RemoteRocketMqService;
|
||||
import com.ruoyi.system.api.domain.RmNetworkInterfaceRemote;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
/**
|
||||
* mtr探测策略配置Service业务层处理
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-11-18
|
||||
*/
|
||||
@Service
|
||||
public class RmMtrPolicyConfigServiceImpl implements IRmMtrPolicyConfigService
|
||||
{
|
||||
@Autowired
|
||||
private RmMtrPolicyConfigMapper rmMtrPolicyConfigMapper;
|
||||
@Autowired
|
||||
private RemoteRocketMqService remoteRocketMqService;
|
||||
|
||||
/**
|
||||
* 查询mtr探测策略配置
|
||||
*
|
||||
* @param id mtr探测策略配置主键
|
||||
* @return mtr探测策略配置
|
||||
*/
|
||||
@Override
|
||||
public RmMtrPolicyConfig selectRmMtrPolicyConfigById(Long id)
|
||||
{
|
||||
RmMtrPolicyConfig mtrPolicyConfig = rmMtrPolicyConfigMapper.selectRmMtrPolicyConfigById(id);
|
||||
mtrPolicyConfig.setServerGroup(mtrPolicyConfig.getServerGroup().replace("\n", ";"));
|
||||
return mtrPolicyConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询mtr探测策略配置列表
|
||||
*
|
||||
* @param rmMtrPolicyConfig mtr探测策略配置
|
||||
* @return mtr探测策略配置
|
||||
*/
|
||||
@Override
|
||||
public List<RmMtrPolicyConfig> selectRmMtrPolicyConfigList(RmMtrPolicyConfig rmMtrPolicyConfig)
|
||||
{
|
||||
List<RmMtrPolicyConfig> list = rmMtrPolicyConfigMapper.selectRmMtrPolicyConfigList(rmMtrPolicyConfig);
|
||||
for (RmMtrPolicyConfig mtrPolicyConfig : list) {
|
||||
mtrPolicyConfig.setServerGroup(mtrPolicyConfig.getServerGroup().replace("\n", ";"));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 辅助方法,给ip集合赋值
|
||||
* @param mtrPolicyConfig
|
||||
*/
|
||||
public void setServerip(RmMtrPolicyConfig mtrPolicyConfig){
|
||||
StringJoiner resultJoiner = new StringJoiner(";");
|
||||
String serverGroupStr = mtrPolicyConfig.getServerGroup().replace("\n",",");
|
||||
RmNetworkInterfaceRemote query = new RmNetworkInterfaceRemote();
|
||||
query.setClientIds(serverGroupStr);
|
||||
R<List<RmNetworkInterfaceRemote>> networkList = remoteRocketMqService.getNetworkInterfaceList(query, SecurityConstants.INNER);
|
||||
if(networkList != null && networkList.getData() != null){
|
||||
List<RmNetworkInterfaceRemote> rmNetworkInterfaceRemoteList = networkList.getData();
|
||||
if(!rmNetworkInterfaceRemoteList.isEmpty()){
|
||||
for (RmNetworkInterfaceRemote rmNetworkInterfaceRemote : rmNetworkInterfaceRemoteList) {
|
||||
String publicIp = rmNetworkInterfaceRemote.getPublicIp();
|
||||
resultJoiner.add(publicIp);
|
||||
}
|
||||
mtrPolicyConfig.setServeripGroup(resultJoiner.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增mtr探测策略配置
|
||||
*
|
||||
* @param rmMtrPolicyConfig mtr探测策略配置
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int insertRmMtrPolicyConfig(RmMtrPolicyConfig rmMtrPolicyConfig)
|
||||
{
|
||||
rmMtrPolicyConfig.setCreateTime(DateUtils.getNowDate());
|
||||
rmMtrPolicyConfig.setUpdateTime(DateUtils.getNowDate());
|
||||
rmMtrPolicyConfig.setCreateBy(SecurityUtils.getUsername());
|
||||
// 给ip赋值
|
||||
setServerip(rmMtrPolicyConfig);
|
||||
int rows = rmMtrPolicyConfigMapper.insertRmMtrPolicyConfig(rmMtrPolicyConfig);
|
||||
return rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改mtr探测策略配置
|
||||
*
|
||||
* @param rmMtrPolicyConfig mtr探测策略配置
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int updateRmMtrPolicyConfig(RmMtrPolicyConfig rmMtrPolicyConfig)
|
||||
{
|
||||
rmMtrPolicyConfig.setUpdateTime(DateUtils.getNowDate());
|
||||
return rmMtrPolicyConfigMapper.updateRmMtrPolicyConfig(rmMtrPolicyConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除mtr探测策略配置
|
||||
*
|
||||
* @param ids 需要删除的mtr探测策略配置主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteRmMtrPolicyConfigByIds(Long[] ids)
|
||||
{
|
||||
return rmMtrPolicyConfigMapper.deleteRmMtrPolicyConfigByIds(ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除mtr探测策略配置信息
|
||||
*
|
||||
* @param id mtr探测策略配置主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteRmMtrPolicyConfigById(Long id)
|
||||
{
|
||||
return rmMtrPolicyConfigMapper.deleteRmMtrPolicyConfigById(id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,182 @@
|
||||
package com.ruoyi.mtragent.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.ruoyi.common.core.enums.MsgEnum;
|
||||
import com.ruoyi.common.core.utils.DateUtils;
|
||||
import com.ruoyi.mtragent.domain.DeviceMessage;
|
||||
import com.ruoyi.mtragent.domain.RmNetworkInterface;
|
||||
import com.ruoyi.mtragent.domain.vo.PolicyTypeVo;
|
||||
import com.ruoyi.mtragent.mapper.RmNetworkInterfaceMapper;
|
||||
import com.ruoyi.mtragent.model.ProducerMode;
|
||||
import com.ruoyi.mtragent.producer.MessageProducer;
|
||||
import com.ruoyi.mtragent.service.IRmNetworkInterfaceService;
|
||||
import com.ruoyi.system.api.domain.RouteMsg;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 客户端网络接口信息Service业务层处理
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-10-14
|
||||
*/
|
||||
@Service
|
||||
public class RmNetworkInterfaceServiceImpl implements IRmNetworkInterfaceService
|
||||
{
|
||||
@Autowired
|
||||
private RmNetworkInterfaceMapper rmNetworkInterfaceMapper;
|
||||
@Autowired
|
||||
private ProducerMode producerMode;
|
||||
|
||||
/**
|
||||
* 查询客户端网络接口信息
|
||||
*
|
||||
* @param id 客户端网络接口信息主键
|
||||
* @return 客户端网络接口信息
|
||||
*/
|
||||
@Override
|
||||
public RmNetworkInterface selectRmNetworkInterfaceById(Long id)
|
||||
{
|
||||
return rmNetworkInterfaceMapper.selectRmNetworkInterfaceById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询客户端网络接口信息列表
|
||||
*
|
||||
* @param rmNetworkInterface 客户端网络接口信息
|
||||
* @return 客户端网络接口信息
|
||||
*/
|
||||
@Override
|
||||
public List<RmNetworkInterface> selectRmNetworkInterfaceList(RmNetworkInterface rmNetworkInterface)
|
||||
{
|
||||
return rmNetworkInterfaceMapper.selectRmNetworkInterfaceList(rmNetworkInterface);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增客户端网络接口信息
|
||||
*
|
||||
* @param rmNetworkInterface 客户端网络接口信息
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int insertRmNetworkInterface(RmNetworkInterface rmNetworkInterface)
|
||||
{
|
||||
rmNetworkInterface.setCreateTime(DateUtils.getNowDate());
|
||||
return rmNetworkInterfaceMapper.insertRmNetworkInterface(rmNetworkInterface);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改客户端网络接口信息
|
||||
*
|
||||
* @param rmNetworkInterface 客户端网络接口信息
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int updateRmNetworkInterface(RmNetworkInterface rmNetworkInterface)
|
||||
{
|
||||
rmNetworkInterface.setUpdateTime(DateUtils.getNowDate());
|
||||
return rmNetworkInterfaceMapper.updateRmNetworkInterface(rmNetworkInterface);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateRmNetworkInterfaceByMac(RmNetworkInterface rmNetworkInterface) {
|
||||
rmNetworkInterface.setUpdateTime(DateUtils.getNowDate());
|
||||
return rmNetworkInterfaceMapper.updateRmNetworkInterfaceByMac(rmNetworkInterface);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除客户端网络接口信息
|
||||
*
|
||||
* @param ids 需要删除的客户端网络接口信息主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteRmNetworkInterfaceByIds(Long[] ids)
|
||||
{
|
||||
return rmNetworkInterfaceMapper.deleteRmNetworkInterfaceByIds(ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除客户端网络接口信息信息
|
||||
*
|
||||
* @param id 客户端网络接口信息主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteRmNetworkInterfaceById(Long id)
|
||||
{
|
||||
return rmNetworkInterfaceMapper.deleteRmNetworkInterfaceById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定公网ip
|
||||
* @param rmNetworkInterface
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int bindPublicIp(RmNetworkInterface rmNetworkInterface) {
|
||||
return rmNetworkInterfaceMapper.updateRmNetworkInterface(rmNetworkInterface);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新路由信息
|
||||
* @param clientId
|
||||
*/
|
||||
public void updateRouteMsg(String clientId){
|
||||
MessageProducer messageProducer = new MessageProducer();
|
||||
// 查询路由是否有变化
|
||||
RmNetworkInterface rmNetworkInterface = new RmNetworkInterface();
|
||||
rmNetworkInterface.setClientId(clientId);
|
||||
rmNetworkInterface.setBindIp("2");
|
||||
List<RmNetworkInterface> networkInterfaces = rmNetworkInterfaceMapper.selectRmNetworkInterfaceList(rmNetworkInterface);
|
||||
if(!networkInterfaces.isEmpty()){
|
||||
List<RmNetworkInterface> oldList = networkInterfaces.stream()
|
||||
.filter(networkInterface -> networkInterface.getNewFlag() == 0)
|
||||
.collect(Collectors.toList());
|
||||
if(!oldList.isEmpty()){
|
||||
Map<String, Object> resultMap = new HashMap<>();
|
||||
// 增加静态路由
|
||||
RmNetworkInterface oldMsg = oldList.get(0);
|
||||
RouteMsg oldRouteMsg = new RouteMsg();
|
||||
oldRouteMsg.setGateway(oldMsg.getGateway());
|
||||
oldRouteMsg.setName(oldMsg.getInterfaceName());
|
||||
resultMap.put("delRoute", oldRouteMsg);
|
||||
List<RmNetworkInterface> newList = networkInterfaces.stream()
|
||||
.filter(networkInterface -> networkInterface.getNewFlag() == 1)
|
||||
.collect(Collectors.toList());
|
||||
RmNetworkInterface newMsg = newList.get(0);
|
||||
RouteMsg newRouteMsg = new RouteMsg();
|
||||
newRouteMsg.setGateway(newMsg.getGateway());
|
||||
newRouteMsg.setName(newMsg.getInterfaceName());
|
||||
resultMap.put("addRoute", newRouteMsg);
|
||||
resultMap.put("upTime", Instant.now().getEpochSecond());
|
||||
PolicyTypeVo policyTypeVo = new PolicyTypeVo();
|
||||
policyTypeVo.setRoutes(JSONObject.toJSONString(resultMap));
|
||||
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)
|
||||
);
|
||||
// 更新网卡信息表
|
||||
RmNetworkInterface updateQuery = new RmNetworkInterface();
|
||||
updateQuery.setNewFlag(999);
|
||||
updateQuery.setMacAddress(networkInterfaces.get(0).getMacAddress());
|
||||
rmNetworkInterfaceMapper.updateRmNetworkInterfaceByMac(updateQuery);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.ruoyi.mtragent.utils;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class JsonDataParser {
|
||||
private static final ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
/**
|
||||
* 通用JSON解析方法(兼容对象和数组)
|
||||
* @param jsonStr JSON字符串
|
||||
* @param valueType 目标实体类类型
|
||||
* @return 实体类List集合
|
||||
*/
|
||||
public static <T> List<T> parseJsonData(String jsonStr, Class<T> valueType) {
|
||||
if (!StringUtils.hasText(jsonStr)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
try {
|
||||
JsonNode rootNode = objectMapper.readTree(jsonStr);
|
||||
|
||||
if (rootNode.isArray()) {
|
||||
// 处理数组格式JSON
|
||||
return objectMapper.readValue(jsonStr,
|
||||
objectMapper.getTypeFactory().constructCollectionType(List.class, valueType));
|
||||
} else {
|
||||
// 处理单个对象格式JSON
|
||||
List<T> result = new ArrayList<>(1);
|
||||
result.add(objectMapper.readValue(jsonStr, valueType));
|
||||
return result;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("JSON解析失败: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
package com.ruoyi.mtragent.utils;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SwitchJsonDataParser {
|
||||
private static final ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
/**
|
||||
* 通用JSON解析方法(兼容对象和数组)
|
||||
* @param jsonStr JSON字符串
|
||||
* @param valueType 目标实体类类型
|
||||
* @return 实体类List集合
|
||||
*/
|
||||
public static <T> List<T> parseJsonData(String jsonStr, Class<T> valueType) {
|
||||
if (!StringUtils.hasText(jsonStr)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
try {
|
||||
JsonNode rootNode = objectMapper.readTree(jsonStr);
|
||||
|
||||
if (rootNode.isArray()) {
|
||||
// 处理数组格式JSON
|
||||
if (isStringArrayContainingJsonObjects((ArrayNode) rootNode)) {
|
||||
// 处理包含JSON对象字符串的数组 - 转换为真正的对象数组
|
||||
ArrayNode processedArray = processStringJsonArrayToObjectArray((ArrayNode) rootNode);
|
||||
return convertJsonArrayToList(processedArray, valueType);
|
||||
} else {
|
||||
// 处理普通JSON数组
|
||||
processJsonArray((ArrayNode) rootNode);
|
||||
return convertJsonArrayToList((ArrayNode) rootNode, valueType);
|
||||
}
|
||||
} else {
|
||||
// 处理单个对象格式JSON
|
||||
if (rootNode.isObject()) {
|
||||
processJsonObject((ObjectNode) rootNode);
|
||||
}
|
||||
List<T> result = new ArrayList<>(1);
|
||||
result.add(objectMapper.treeToValue(rootNode, valueType));
|
||||
return result;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("JSON解析失败: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将JsonArray转换为List<T>
|
||||
*/
|
||||
private static <T> List<T> convertJsonArrayToList(ArrayNode arrayNode, Class<T> valueType) throws Exception {
|
||||
List<T> result = new ArrayList<>();
|
||||
for (int i = 0; i < arrayNode.size(); i++) {
|
||||
JsonNode element = arrayNode.get(i);
|
||||
result.add(objectMapper.treeToValue(element, valueType));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否是包含JSON对象字符串的字符串数组
|
||||
*/
|
||||
private static boolean isStringArrayContainingJsonObjects(ArrayNode arrayNode) {
|
||||
if (arrayNode.size() == 0) return false;
|
||||
|
||||
JsonNode firstElement = arrayNode.get(0);
|
||||
if (firstElement.isTextual()) {
|
||||
try {
|
||||
String strValue = firstElement.textValue();
|
||||
// 检查是否是JSON对象格式的字符串
|
||||
if (strValue.startsWith("{") && strValue.endsWith("}")) {
|
||||
objectMapper.readTree(strValue);
|
||||
return true;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理包含JSON对象字符串的字符串数组,转换为真正的对象数组
|
||||
*/
|
||||
private static ArrayNode processStringJsonArrayToObjectArray(ArrayNode arrayNode) {
|
||||
ArrayNode resultArray = objectMapper.createArrayNode();
|
||||
|
||||
for (int i = 0; i < arrayNode.size(); i++) {
|
||||
JsonNode element = arrayNode.get(i);
|
||||
if (element.isTextual()) {
|
||||
try {
|
||||
String jsonString = element.textValue();
|
||||
JsonNode jsonNode = objectMapper.readTree(jsonString);
|
||||
|
||||
if (jsonNode.isObject()) {
|
||||
// 处理JSON对象中的 noSuchInstance
|
||||
processJsonObject((ObjectNode) jsonNode);
|
||||
resultArray.add(jsonNode);
|
||||
} else {
|
||||
resultArray.add(element);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// 如果解析失败,保持原样
|
||||
resultArray.add(element);
|
||||
}
|
||||
} else {
|
||||
resultArray.add(element);
|
||||
}
|
||||
}
|
||||
|
||||
return resultArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理JSON数组
|
||||
*/
|
||||
private static void processJsonArray(ArrayNode arrayNode) {
|
||||
for (int i = 0; i < arrayNode.size(); i++) {
|
||||
JsonNode element = arrayNode.get(i);
|
||||
if (element.isObject()) {
|
||||
processJsonObject((ObjectNode) element);
|
||||
} else if (element.isArray()) {
|
||||
processJsonArray((ArrayNode) element);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理JSON对象
|
||||
*/
|
||||
private static void processJsonObject(ObjectNode objectNode) {
|
||||
objectNode.fields().forEachRemaining(entry -> {
|
||||
JsonNode value = entry.getValue();
|
||||
if (value.isTextual() && "noSuchInstance".equals(value.textValue())) {
|
||||
objectNode.putNull(entry.getKey());
|
||||
} else if (value.isObject()) {
|
||||
processJsonObject((ObjectNode) value);
|
||||
} else if (value.isArray()) {
|
||||
processJsonArray((ArrayNode) value);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
package com.ruoyi.mtragent.utils;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class TableRouterUtil {
|
||||
|
||||
// 日期格式
|
||||
private static final DateTimeFormatter YEAR_MONTH_FORMAT =
|
||||
DateTimeFormatter.ofPattern("yyyy_MM");
|
||||
private static final DateTimeFormatter DATE_TIME_FORMATTER =
|
||||
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
// 表名前缀
|
||||
private static final String TABLE_PREFIX = "eps_initial_traffic";
|
||||
// 表名前缀
|
||||
private static final String TABLE_PREFIX_INITIAL = "initial_bandwidth_traffic";
|
||||
|
||||
|
||||
/**
|
||||
* 根据创建时间获取表名
|
||||
* @param createTime 记录创建时间
|
||||
* @return 对应的分表名称
|
||||
* @throws IllegalArgumentException 如果createTime为null
|
||||
*
|
||||
* 示例:
|
||||
* 2023-08-05 14:30:00 → eps_initial_traffic_2023_08_1_10
|
||||
* 2023-08-15 09:15:00 → eps_initial_traffic_2023_08_11_20
|
||||
* 2023-08-25 18:45:00 → eps_initial_traffic_2023_08_21_31
|
||||
*/
|
||||
public static String getTableName(LocalDateTime createTime) {
|
||||
if (createTime == null) {
|
||||
throw new IllegalArgumentException("创建时间不能为null");
|
||||
}
|
||||
|
||||
String yearMonth = createTime.format(YEAR_MONTH_FORMAT);
|
||||
int day = createTime.getDayOfMonth();
|
||||
|
||||
return String.format("%s_%s_%s",
|
||||
TABLE_PREFIX_INITIAL,
|
||||
yearMonth,
|
||||
getDayRange(day));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取时间范围内涉及的所有表名
|
||||
* @param startTime 开始时间 (格式: "yyyy-MM-dd HH:mm:ss")
|
||||
* @param endTime 结束时间 (格式: "yyyy-MM-dd HH:mm:ss")
|
||||
* @return 按时间顺序排列的表名集合
|
||||
*/
|
||||
public static Set<String> getTableNamesBetween(String startTime, String endTime) {
|
||||
LocalDateTime start = parseDateTime(startTime);
|
||||
LocalDateTime end = parseDateTime(endTime);
|
||||
validateTimeRange(start, end);
|
||||
|
||||
Set<String> tableNames = new LinkedHashSet<>();
|
||||
LocalDateTime current = start.withHour(0).withMinute(0).withSecond(0);
|
||||
|
||||
while (!current.isAfter(end)) {
|
||||
tableNames.add(getTableName(current));
|
||||
current = current.plusDays(1);
|
||||
}
|
||||
|
||||
return tableNames;
|
||||
}
|
||||
// 解析字符串为LocalDateTime
|
||||
private static LocalDateTime parseDateTime(String dateTimeStr) {
|
||||
if (dateTimeStr == null || dateTimeStr.trim().isEmpty()) {
|
||||
throw new IllegalArgumentException("时间字符串不能为空");
|
||||
}
|
||||
try {
|
||||
return LocalDateTime.parse(dateTimeStr, DATE_TIME_FORMATTER);
|
||||
} catch (Exception e) {
|
||||
throw new IllegalArgumentException("时间格式必须为: yyyy-MM-dd HH:mm:ss", e);
|
||||
}
|
||||
}
|
||||
|
||||
// 获取日期区间
|
||||
private static String getDayRange(int day) {
|
||||
if (day < 1 || day > 31) {
|
||||
throw new IllegalArgumentException("日期必须在1-31之间");
|
||||
}
|
||||
|
||||
if (day <= 10) return "1_10";
|
||||
if (day <= 20) return "11_20";
|
||||
return "21_31";
|
||||
}
|
||||
|
||||
// 验证时间范围
|
||||
private static void validateTimeRange(LocalDateTime start, LocalDateTime end) {
|
||||
if (start == null || end == null) {
|
||||
throw new IllegalArgumentException("时间范围参数不能为null");
|
||||
}
|
||||
if (start.isAfter(end)) {
|
||||
throw new IllegalArgumentException("开始时间不能晚于结束时间");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,285 @@
|
||||
package com.ruoyi.mtragent.utils;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import java.io.OutputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class WeChatWorkBot {
|
||||
private static final ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
/**
|
||||
* 发送基于模板的文本消息
|
||||
* @param webhookUrl webhook地址
|
||||
* @param template 消息模板,例如:"项目[项目名称]在[时间]发生[事件类型]"
|
||||
* @param fieldValues 字段值的映射,key为中文字段名,value为实际值(支持String、Number、Boolean等)
|
||||
* @return 是否发送成功
|
||||
*/
|
||||
public static boolean sendTemplateMessage(String webhookUrl, String template,
|
||||
Map<String, Object> fieldValues) {
|
||||
return sendTemplateMessage(webhookUrl, template, fieldValues, null, null, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送基于模板的文本消息(支持@功能)
|
||||
* @param webhookUrl webhook地址
|
||||
* @param template 消息模板
|
||||
* @param fieldValues 字段值的映射
|
||||
* @param mentionedMobiles 被@的用户列表(手机号)
|
||||
* @param mentionedAll 是否@所有人
|
||||
* @return 是否发送成功
|
||||
*/
|
||||
public static boolean sendTemplateMessage(String webhookUrl, String template,
|
||||
Map<String, Object> fieldValues,
|
||||
String[] mentionedMobiles, boolean mentionedAll) {
|
||||
return sendTemplateMessage(webhookUrl, template, fieldValues, null, mentionedMobiles, mentionedAll);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送基于模板的文本消息(完整参数)
|
||||
* @param webhookUrl webhook地址
|
||||
* @param template 消息模板
|
||||
* @param fieldValues 字段值的映射
|
||||
* @param defaultValue 未找到字段时的默认值
|
||||
* @param mentionedMobiles 被@的用户列表(手机号)
|
||||
* @param mentionedAll 是否@所有人
|
||||
* @return 是否发送成功
|
||||
*/
|
||||
public static boolean sendTemplateMessage(String webhookUrl, String template,
|
||||
Map<String, Object> fieldValues, Object defaultValue,
|
||||
String[] mentionedMobiles, boolean mentionedAll) {
|
||||
try {
|
||||
String actualContent = processTemplate(template, fieldValues, defaultValue);
|
||||
return sendTextMessage(webhookUrl, actualContent, mentionedMobiles, mentionedAll);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理模板,替换字段占位符
|
||||
* @param template 消息模板
|
||||
* @param fieldValues 字段值映射
|
||||
* @param defaultValue 默认值
|
||||
* @return 处理后的消息内容
|
||||
*/
|
||||
public static String processTemplate(String template, Map<String, Object> fieldValues,
|
||||
Object defaultValue) {
|
||||
if (template == null) return "";
|
||||
if (fieldValues == null || fieldValues.isEmpty()) {
|
||||
return template;
|
||||
}
|
||||
|
||||
Pattern pattern = Pattern.compile("\\[(.*?)\\]");
|
||||
Matcher matcher = pattern.matcher(template);
|
||||
StringBuffer result = new StringBuffer();
|
||||
|
||||
while (matcher.find()) {
|
||||
String fieldName = matcher.group(1);
|
||||
Object fieldValueObj = fieldValues.get(fieldName);
|
||||
String fieldValue = convertToString(fieldValueObj);
|
||||
|
||||
// 如果字段值为空,使用默认值或保留原占位符
|
||||
if (fieldValue == null || fieldValue.trim().isEmpty()) {
|
||||
fieldValue = convertToString(defaultValue);
|
||||
if (fieldValue == null) {
|
||||
fieldValue = "[" + fieldName + "]";
|
||||
}
|
||||
}
|
||||
|
||||
// 对替换值进行转义,防止正则表达式特殊字符问题
|
||||
matcher.appendReplacement(result, Matcher.quoteReplacement(fieldValue));
|
||||
}
|
||||
matcher.appendTail(result);
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 将对象转换为字符串
|
||||
* @param obj 要转换的对象
|
||||
* @return 字符串表示
|
||||
*/
|
||||
private static String convertToString(Object obj) {
|
||||
if (obj == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (obj instanceof String) {
|
||||
return (String) obj;
|
||||
} else if (obj instanceof Number || obj instanceof Boolean) {
|
||||
return String.valueOf(obj);
|
||||
} else if (obj instanceof java.util.Date) {
|
||||
return new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format((java.util.Date) obj);
|
||||
} else {
|
||||
return obj.toString();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证模板中的字段是否都有对应的值
|
||||
* @param template 消息模板
|
||||
* @param fieldValues 字段值映射
|
||||
* @return 是否所有字段都有值
|
||||
*/
|
||||
public static boolean validateTemplate(String template, Map<String, Object> fieldValues) {
|
||||
if (template == null || fieldValues == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Pattern pattern = Pattern.compile("\\[(.*?)\\]");
|
||||
Matcher matcher = pattern.matcher(template);
|
||||
|
||||
while (matcher.find()) {
|
||||
String fieldName = matcher.group(1);
|
||||
Object fieldValue = fieldValues.get(fieldName);
|
||||
String strValue = convertToString(fieldValue);
|
||||
|
||||
if (!fieldValues.containsKey(fieldName) ||
|
||||
strValue == null ||
|
||||
strValue.trim().isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取模板中的所有字段名
|
||||
* @param template 消息模板
|
||||
* @return 字段名列表
|
||||
*/
|
||||
public static java.util.List<String> getTemplateFields(String template) {
|
||||
java.util.List<String> fields = new java.util.ArrayList<>();
|
||||
if (template == null) {
|
||||
return fields;
|
||||
}
|
||||
|
||||
Pattern pattern = Pattern.compile("\\[(.*?)\\]");
|
||||
Matcher matcher = pattern.matcher(template);
|
||||
|
||||
while (matcher.find()) {
|
||||
fields.add(matcher.group(1));
|
||||
}
|
||||
return fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送Markdown模板消息
|
||||
* @param webhookUrl webhook地址
|
||||
* @param template Markdown模板
|
||||
* @param fieldValues 字段值映射
|
||||
* @return 是否发送成功
|
||||
*/
|
||||
public static boolean sendMarkdownTemplateMessage(String webhookUrl, String template,
|
||||
Map<String, Object> fieldValues) {
|
||||
return sendMarkdownTemplateMessage(webhookUrl, template, fieldValues, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送Markdown模板消息
|
||||
* @param webhookUrl webhook地址
|
||||
* @param template Markdown模板
|
||||
* @param fieldValues 字段值映射
|
||||
* @param defaultValue 默认值
|
||||
* @return 是否发送成功
|
||||
*/
|
||||
public static boolean sendMarkdownTemplateMessage(String webhookUrl, String template,
|
||||
Map<String, Object> fieldValues,
|
||||
Object defaultValue) {
|
||||
try {
|
||||
String actualContent = processTemplate(template, fieldValues, defaultValue);
|
||||
return sendMarkdownMessage(webhookUrl, actualContent);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送文本消息
|
||||
*/
|
||||
public static boolean sendTextMessage(String webhookUrl, String content) {
|
||||
return sendTextMessage(webhookUrl, content, null, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送文本消息(支持@功能)
|
||||
*/
|
||||
public static boolean sendTextMessage(String webhookUrl, String content,
|
||||
String[] mentionedMobiles, boolean mentionedAll) {
|
||||
try {
|
||||
Map<String, Object> message = new HashMap<>();
|
||||
message.put("msgtype", "text");
|
||||
|
||||
Map<String, Object> textContent = new HashMap<>();
|
||||
textContent.put("content", content);
|
||||
|
||||
if (mentionedAll) {
|
||||
textContent.put("mentioned_mobile_list", new String[]{"@all"});
|
||||
} else if (mentionedMobiles != null && mentionedMobiles.length > 0) {
|
||||
textContent.put("mentioned_mobile_list", mentionedMobiles);
|
||||
}
|
||||
|
||||
message.put("text", textContent);
|
||||
|
||||
return sendMessage(webhookUrl, mapper.writeValueAsString(message));
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送Markdown消息
|
||||
*/
|
||||
public static boolean sendMarkdownMessage(String webhookUrl, String content) {
|
||||
try {
|
||||
Map<String, Object> message = new HashMap<>();
|
||||
message.put("msgtype", "markdown");
|
||||
|
||||
Map<String, Object> markdownContent = new HashMap<>();
|
||||
markdownContent.put("content", content);
|
||||
|
||||
message.put("markdown", markdownContent);
|
||||
|
||||
return sendMessage(webhookUrl, mapper.writeValueAsString(message));
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean sendMessage(String webhookUrl, String jsonBody) {
|
||||
try {
|
||||
URL url = new URL(webhookUrl);
|
||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||
|
||||
connection.setRequestMethod("POST");
|
||||
connection.setRequestProperty("Content-Type", "application/json");
|
||||
connection.setDoOutput(true);
|
||||
connection.setConnectTimeout(5000);
|
||||
connection.setReadTimeout(10000);
|
||||
|
||||
try (OutputStream os = connection.getOutputStream()) {
|
||||
byte[] input = jsonBody.getBytes("UTF-8");
|
||||
os.write(input, 0, input.length);
|
||||
}
|
||||
|
||||
int responseCode = connection.getResponseCode();
|
||||
return responseCode == 200;
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
# Tomcat
|
||||
server:
|
||||
port: 9208
|
||||
|
||||
# Spring
|
||||
spring:
|
||||
application:
|
||||
# 应用名称
|
||||
name: ruoyi-mtragent
|
||||
profiles:
|
||||
# 环境配置
|
||||
active: dev
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
# 服务注册地址
|
||||
server-addr: 127.0.0.1:8848
|
||||
# server-addr: 172.16.15.103:8848
|
||||
# username: ${spring.cloud.nacos.config.username}
|
||||
# password: ${spring.cloud.nacos.config.password}
|
||||
config:
|
||||
# 配置中心地址
|
||||
server-addr: 127.0.0.1:8848
|
||||
# server-addr: 172.16.15.103:8848
|
||||
# username: nacos
|
||||
# password: nacos
|
||||
# 配置文件格式
|
||||
file-extension: yml
|
||||
# 共享配置
|
||||
shared-configs:
|
||||
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||
|
||||
redisson:
|
||||
singleServerConfig:
|
||||
address: redis://localhost:6379
|
||||
logging:
|
||||
level:
|
||||
com.ruoyi.app.mapper: DEBUG
|
||||
|
||||
|
||||
|
||||
72
ruoyi-modules/ruoyi-mtragent/src/main/resources/logback.xml
Normal file
72
ruoyi-modules/ruoyi-mtragent/src/main/resources/logback.xml
Normal file
@@ -0,0 +1,72 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration scan="true" scanPeriod="60 seconds" debug="false">
|
||||
<!-- 日志存放路径 -->
|
||||
<property name="log.path" value="logs/ruoyi-mtragent" />
|
||||
<!-- 日志输出格式 -->
|
||||
<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n" />
|
||||
|
||||
<!-- 控制台输出 -->
|
||||
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>${log.pattern}</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<!-- 业务日志输出 -->
|
||||
<appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${log.path}/info.log</file>
|
||||
<!-- 循环政策:基于时间创建日志文件 -->
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<!-- 日志文件名格式 -->
|
||||
<fileNamePattern>${log.path}/info.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||
<!-- 日志最大的历史 60天 -->
|
||||
<maxHistory>60</maxHistory>
|
||||
</rollingPolicy>
|
||||
<encoder>
|
||||
<pattern>${log.pattern}</pattern>
|
||||
</encoder>
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<!-- 过滤的级别 -->
|
||||
<level>INFO</level>
|
||||
<!-- 匹配时的操作:接收(记录) -->
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<!-- 不匹配时的操作:拒绝(不记录) -->
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<!-- 错误日志输出 -->
|
||||
<appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${log.path}/error.log</file>
|
||||
<!-- 循环政策:基于时间创建日志文件 -->
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<!-- 日志文件名格式 -->
|
||||
<fileNamePattern>${log.path}/error.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||
<!-- 日志最大的历史 60天 -->
|
||||
<maxHistory>60</maxHistory>
|
||||
</rollingPolicy>
|
||||
<encoder>
|
||||
<pattern>${log.pattern}</pattern>
|
||||
</encoder>
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<!-- 过滤的级别 -->
|
||||
<level>ERROR</level>
|
||||
<!-- 匹配时的操作:接收(记录) -->
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<!-- 不匹配时的操作:拒绝(不记录) -->
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<!-- MTR Agent模块日志级别控制 -->
|
||||
<logger name="com.ruoyi.mtragent" level="info" additivity="false">
|
||||
<appender-ref ref="console" /> <!-- 显式添加控制台 -->
|
||||
<appender-ref ref="file_info" />
|
||||
<appender-ref ref="file_error" />
|
||||
</logger>
|
||||
|
||||
<!-- 根日志配置 -->
|
||||
<root level="info">
|
||||
<appender-ref ref="console" />
|
||||
</root>
|
||||
</configuration>
|
||||
@@ -0,0 +1,81 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.ruoyi.mtragent.mapper.InitialHeartbeatListenLogMapper">
|
||||
|
||||
<resultMap type="InitialHeartbeatListenLog" id="InitialHeartbeatListenLogResult">
|
||||
<result property="id" column="id" />
|
||||
<result property="clientId" column="client_id" />
|
||||
<result property="status" column="status" />
|
||||
<result property="remark" column="remark" />
|
||||
<result property="createTime" column="create_time" />
|
||||
<result property="updateTime" column="update_time" />
|
||||
<result property="createBy" column="create_by" />
|
||||
<result property="updateBy" column="update_by" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectInitialHeartbeatListenLogVo">
|
||||
select id, client_id, status, remark, create_time, update_time, create_by, update_by from initial_heartbeat_listen_log
|
||||
</sql>
|
||||
|
||||
<select id="selectInitialHeartbeatListenLogList" parameterType="InitialHeartbeatListenLog" resultMap="InitialHeartbeatListenLogResult">
|
||||
<include refid="selectInitialHeartbeatListenLogVo"/>
|
||||
<where>
|
||||
<if test="clientId != null and clientId != ''"> and client_id = #{clientId}</if>
|
||||
<if test="status != null and status != ''"> and status = #{status}</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="selectInitialHeartbeatListenLogById" parameterType="Long" resultMap="InitialHeartbeatListenLogResult">
|
||||
<include refid="selectInitialHeartbeatListenLogVo"/>
|
||||
where id = #{id}
|
||||
</select>
|
||||
|
||||
<insert id="insertInitialHeartbeatListenLog" parameterType="InitialHeartbeatListenLog" useGeneratedKeys="true" keyProperty="id">
|
||||
insert into initial_heartbeat_listen_log
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="clientId != null">client_id,</if>
|
||||
<if test="status != null">status,</if>
|
||||
<if test="remark != null">remark,</if>
|
||||
<if test="createTime != null">create_time,</if>
|
||||
<if test="updateTime != null">update_time,</if>
|
||||
<if test="createBy != null">create_by,</if>
|
||||
<if test="updateBy != null">update_by,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="clientId != null">#{clientId},</if>
|
||||
<if test="status != null">#{status},</if>
|
||||
<if test="remark != null">#{remark},</if>
|
||||
<if test="createTime != null">#{createTime},</if>
|
||||
<if test="updateTime != null">#{updateTime},</if>
|
||||
<if test="createBy != null">#{createBy},</if>
|
||||
<if test="updateBy != null">#{updateBy},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<update id="updateInitialHeartbeatListenLog" parameterType="InitialHeartbeatListenLog">
|
||||
update initial_heartbeat_listen_log
|
||||
<trim prefix="SET" suffixOverrides=",">
|
||||
<if test="clientId != null">client_id = #{clientId},</if>
|
||||
<if test="status != null">status = #{status},</if>
|
||||
<if test="remark != null">remark = #{remark},</if>
|
||||
<if test="createTime != null">create_time = #{createTime},</if>
|
||||
<if test="updateTime != null">update_time = #{updateTime},</if>
|
||||
<if test="createBy != null">create_by = #{createBy},</if>
|
||||
<if test="updateBy != null">update_by = #{updateBy},</if>
|
||||
</trim>
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
||||
<delete id="deleteInitialHeartbeatListenLogById" parameterType="Long">
|
||||
delete from initial_heartbeat_listen_log where id = #{id}
|
||||
</delete>
|
||||
|
||||
<delete id="deleteInitialHeartbeatListenLogByIds" parameterType="String">
|
||||
delete from initial_heartbeat_listen_log where id in
|
||||
<foreach item="id" collection="array" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</delete>
|
||||
</mapper>
|
||||
@@ -0,0 +1,192 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.ruoyi.mtragent.mapper.RmAgentManagementMapper">
|
||||
|
||||
<resultMap type="RmAgentManagement" id="RmAgentManagementResult">
|
||||
<result property="id" column="id" />
|
||||
<result property="hardwareSn" column="hardware_sn" />
|
||||
<result property="resourceName" column="resource_name" />
|
||||
<result property="internalIp" column="internal_ip" />
|
||||
<result property="status" column="status" />
|
||||
<result property="agentVersion" column="agent_version" />
|
||||
<result property="method" column="method" />
|
||||
<result property="scheduledUpdateTime" column="scheduled_update_time" />
|
||||
<result property="fileUrlType" column="file_url_type" />
|
||||
<result property="fileUrl" column="file_url" />
|
||||
<result property="fileDirectory" column="file_directory" />
|
||||
<result property="lastUpdateResult" column="last_update_result" />
|
||||
<result property="lastUpdateTime" column="last_update_time" />
|
||||
<result property="createTime" column="create_time" />
|
||||
<result property="updateTime" column="update_time" />
|
||||
<result property="createBy" column="create_by" />
|
||||
<result property="updateBy" column="update_by" />
|
||||
<result property="fileMd5" column="file_md5" />
|
||||
<result property="clientId" column="client_id" />
|
||||
<result property="deployDevice" column="deploy_device" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectRmAgentManagementVo">
|
||||
select id, hardware_sn, resource_name, internal_ip, status, agent_version, method, scheduled_update_time, file_url_type, file_url, file_directory, last_update_result, last_update_time, create_time, update_time, create_by, update_by, file_md5, client_id, deploy_device from rm_agent_management
|
||||
</sql>
|
||||
|
||||
<select id="selectRmAgentManagementList" parameterType="RmAgentManagement" resultMap="RmAgentManagementResult">
|
||||
<include refid="selectRmAgentManagementVo"/>
|
||||
<where>
|
||||
<if test="hardwareSn != null and hardwareSn != ''"> and hardware_sn = #{hardwareSn}</if>
|
||||
<if test="resourceName != null and resourceName != ''"> and resource_name like concat('%', #{resourceName}, '%')</if>
|
||||
<if test="internalIp != null and internalIp != ''"> and internal_ip = #{internalIp}</if>
|
||||
<if test="status != null and status != ''"> and status = #{status}</if>
|
||||
<if test="agentVersion != null and agentVersion != ''"> and agent_version = #{agentVersion}</if>
|
||||
<if test="method != null "> and method = #{method}</if>
|
||||
<if test="scheduledUpdateTime != null and scheduledUpdateTime != ''"> and scheduled_update_time = #{scheduledUpdateTime}</if>
|
||||
<if test="fileUrlType != null "> and file_url_type = #{fileUrlType}</if>
|
||||
<if test="fileUrl != null and fileUrl != ''"> and file_url = #{fileUrl}</if>
|
||||
<if test="fileDirectory != null and fileDirectory != ''"> and file_directory = #{fileDirectory}</if>
|
||||
<if test="lastUpdateResult != null and lastUpdateResult != ''"> and last_update_result = #{lastUpdateResult}</if>
|
||||
<if test="lastUpdateTime != null "> and last_update_time = #{lastUpdateTime}</if>
|
||||
<if test="fileMd5 != null and fileMd5 != ''"> and file_md5 = #{fileMd5}</if>
|
||||
<if test="clientId != null and clientId != ''"> and client_id = #{clientId}</if>
|
||||
<if test="deployDevice != null and deployDevice != ''"> and deploy_device = #{deployDevice}</if>
|
||||
<if test="queryName != null and queryName != '' "> and (resource_name like concat('%', #{resourceName}, '%') or internal_ip = #{internalIp})</if>
|
||||
</where>
|
||||
order by last_update_time desc
|
||||
</select>
|
||||
|
||||
<select id="selectRmAgentManagementById" parameterType="Long" resultMap="RmAgentManagementResult">
|
||||
<include refid="selectRmAgentManagementVo"/>
|
||||
where id = #{id}
|
||||
</select>
|
||||
|
||||
<insert id="insertRmAgentManagement" parameterType="RmAgentManagement" useGeneratedKeys="true" keyProperty="id">
|
||||
insert into rm_agent_management
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="hardwareSn != null and hardwareSn != ''">hardware_sn,</if>
|
||||
<if test="resourceName != null and resourceName != ''">resource_name,</if>
|
||||
<if test="internalIp != null">internal_ip,</if>
|
||||
<if test="status != null and status != ''">status,</if>
|
||||
<if test="agentVersion != null">agent_version,</if>
|
||||
<if test="method != null">method,</if>
|
||||
<if test="scheduledUpdateTime != null">scheduled_update_time,</if>
|
||||
<if test="fileUrlType != null">file_url_type,</if>
|
||||
<if test="fileUrl != null">file_url,</if>
|
||||
<if test="fileDirectory != null">file_directory,</if>
|
||||
<if test="lastUpdateResult != null">last_update_result,</if>
|
||||
<if test="lastUpdateTime != null">last_update_time,</if>
|
||||
<if test="createTime != null">create_time,</if>
|
||||
<if test="updateTime != null">update_time,</if>
|
||||
<if test="createBy != null">create_by,</if>
|
||||
<if test="updateBy != null">update_by,</if>
|
||||
<if test="fileMd5 != null">file_md5,</if>
|
||||
<if test="clientId != null">client_id,</if>
|
||||
<if test="deployDevice != null">deploy_device,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="hardwareSn != null and hardwareSn != ''">#{hardwareSn},</if>
|
||||
<if test="resourceName != null and resourceName != ''">#{resourceName},</if>
|
||||
<if test="internalIp != null">#{internalIp},</if>
|
||||
<if test="status != null and status != ''">#{status},</if>
|
||||
<if test="agentVersion != null">#{agentVersion},</if>
|
||||
<if test="method != null">#{method},</if>
|
||||
<if test="scheduledUpdateTime != null">#{scheduledUpdateTime},</if>
|
||||
<if test="fileUrlType != null">#{fileUrlType},</if>
|
||||
<if test="fileUrl != null">#{fileUrl},</if>
|
||||
<if test="fileDirectory != null">#{fileDirectory},</if>
|
||||
<if test="lastUpdateResult != null">#{lastUpdateResult},</if>
|
||||
<if test="lastUpdateTime != null">#{lastUpdateTime},</if>
|
||||
<if test="createTime != null">#{createTime},</if>
|
||||
<if test="updateTime != null">#{updateTime},</if>
|
||||
<if test="createBy != null">#{createBy},</if>
|
||||
<if test="updateBy != null">#{updateBy},</if>
|
||||
<if test="fileMd5 != null">#{fileMd5},</if>
|
||||
<if test="clientId != null">#{clientId},</if>
|
||||
<if test="deployDevice != null">#{deployDevice},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<update id="updateRmAgentManagement" parameterType="RmAgentManagement">
|
||||
update rm_agent_management
|
||||
<trim prefix="SET" suffixOverrides=",">
|
||||
<if test="hardwareSn != null and hardwareSn != ''">hardware_sn = #{hardwareSn},</if>
|
||||
<if test="resourceName != null and resourceName != ''">resource_name = #{resourceName},</if>
|
||||
<if test="internalIp != null">internal_ip = #{internalIp},</if>
|
||||
<if test="status != null and status != ''">status = #{status},</if>
|
||||
<if test="agentVersion != null">agent_version = #{agentVersion},</if>
|
||||
<if test="method != null">method = #{method},</if>
|
||||
<if test="scheduledUpdateTime != null">scheduled_update_time = #{scheduledUpdateTime},</if>
|
||||
<if test="fileUrlType != null">file_url_type = #{fileUrlType},</if>
|
||||
<if test="fileUrl != null">file_url = #{fileUrl},</if>
|
||||
<if test="fileDirectory != null">file_directory = #{fileDirectory},</if>
|
||||
<if test="lastUpdateResult != null">last_update_result = #{lastUpdateResult},</if>
|
||||
<if test="lastUpdateTime != null">last_update_time = #{lastUpdateTime},</if>
|
||||
<if test="createTime != null">create_time = #{createTime},</if>
|
||||
<if test="updateTime != null">update_time = #{updateTime},</if>
|
||||
<if test="createBy != null">create_by = #{createBy},</if>
|
||||
<if test="updateBy != null">update_by = #{updateBy},</if>
|
||||
<if test="fileMd5 != null">file_md5 = #{fileMd5},</if>
|
||||
<if test="clientId != null">client_id = #{clientId},</if>
|
||||
<if test="deployDevice != null">deploy_device = #{deployDevice},</if>
|
||||
</trim>
|
||||
<where>
|
||||
<choose>
|
||||
<when test="id != null">
|
||||
and id = #{id}
|
||||
</when>
|
||||
<when test="clientId != null and clientId != ''">
|
||||
and client_id = #{clientId}
|
||||
</when>
|
||||
<otherwise>
|
||||
and 1=0 <!-- 如果没有提供任何条件,则不更新任何记录 -->
|
||||
</otherwise>
|
||||
</choose>
|
||||
</where>
|
||||
</update>
|
||||
|
||||
<delete id="deleteRmAgentManagementById" parameterType="Long">
|
||||
delete from rm_agent_management where id = #{id}
|
||||
</delete>
|
||||
|
||||
<delete id="deleteRmAgentManagementByIds" parameterType="String">
|
||||
delete from rm_agent_management where id in
|
||||
<foreach item="id" collection="array" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</delete>
|
||||
<update id="updateRmAgentManagementBySn" parameterType="RmAgentManagement">
|
||||
update rm_agent_management
|
||||
<trim prefix="SET" suffixOverrides=",">
|
||||
<if test="resourceName != null and resourceName != ''">resource_name = #{resourceName},</if>
|
||||
<if test="internalIp != null">internal_ip = #{internalIp},</if>
|
||||
<if test="status != null and status != ''">status = #{status},</if>
|
||||
<if test="agentVersion != null">agent_version = #{agentVersion},</if>
|
||||
<if test="method != null">method = #{method},</if>
|
||||
<if test="scheduledUpdateTime != null">scheduled_update_time = #{scheduledUpdateTime},</if>
|
||||
<if test="fileUrlType != null">file_url_type = #{fileUrlType},</if>
|
||||
<if test="fileUrl != null">file_url = #{fileUrl},</if>
|
||||
<if test="fileDirectory != null">file_directory = #{fileDirectory},</if>
|
||||
<if test="lastUpdateResult != null">last_update_result = #{lastUpdateResult},</if>
|
||||
<if test="lastUpdateTime != null">last_update_time = #{lastUpdateTime},</if>
|
||||
<if test="createTime != null">create_time = #{createTime},</if>
|
||||
<if test="updateTime != null">update_time = #{updateTime},</if>
|
||||
<if test="createBy != null">create_by = #{createBy},</if>
|
||||
<if test="updateBy != null">update_by = #{updateBy},</if>
|
||||
</trim>
|
||||
<where>
|
||||
<choose>
|
||||
<when test="id != null">
|
||||
and id = #{id}
|
||||
</when>
|
||||
<when test="clientId != null and clientId != ''">
|
||||
and client_id = #{clientId}
|
||||
</when>
|
||||
<when test="hardwareSn != null and hardwareSn != ''">
|
||||
and hardware_sn = #{hardwareSn}
|
||||
</when>
|
||||
<otherwise>
|
||||
and 1=0 <!-- 如果没有提供任何条件,则不更新任何记录 -->
|
||||
</otherwise>
|
||||
</choose>
|
||||
</where>
|
||||
</update>
|
||||
</mapper>
|
||||
@@ -0,0 +1,102 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.ruoyi.mtragent.mapper.RmAlarmLogMapper">
|
||||
|
||||
<resultMap type="RmAlarmLog" id="RmAlarmLogResult">
|
||||
<result property="id" column="id" />
|
||||
<result property="clientId" column="client_id" />
|
||||
<result property="alarmTime" column="alarm_time" />
|
||||
<result property="mgmPublicIp" column="mgm_public_ip" />
|
||||
<result property="alarmType" column="alarm_type" />
|
||||
<result property="alarmContent" column="alarm_content" />
|
||||
<result property="createTime" column="create_time" />
|
||||
<result property="updateTime" column="update_time" />
|
||||
<result property="createBy" column="create_by" />
|
||||
<result property="updateBy" column="update_by" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectRmAlarmLogVo">
|
||||
select id, client_id, alarm_time, mgm_public_ip, alarm_type, alarm_content, create_time, update_time, create_by, update_by from rm_alarm_log
|
||||
</sql>
|
||||
|
||||
<select id="selectRmAlarmLogList" parameterType="RmAlarmLog" resultMap="RmAlarmLogResult">
|
||||
<include refid="selectRmAlarmLogVo"/>
|
||||
<where>
|
||||
<if test="clientId != null and clientId != ''"> and client_id = #{clientId}</if>
|
||||
<if test="alarmTime != null "> and alarm_time = #{alarmTime}</if>
|
||||
<if test="mgmPublicIp != null and mgmPublicIp != ''"> and mgm_public_ip = #{mgmPublicIp}</if>
|
||||
<if test="alarmType != null and alarmType != ''"> and alarm_type = #{alarmType}</if>
|
||||
<if test="alarmContent != null and alarmContent != ''"> and alarm_content = #{alarmContent}</if>
|
||||
</where>
|
||||
order by alarm_time desc
|
||||
</select>
|
||||
|
||||
<select id="selectRmAlarmLogById" parameterType="Long" resultMap="RmAlarmLogResult">
|
||||
<include refid="selectRmAlarmLogVo"/>
|
||||
where id = #{id}
|
||||
</select>
|
||||
|
||||
<insert id="insertRmAlarmLog" parameterType="RmAlarmLog" useGeneratedKeys="true" keyProperty="id">
|
||||
insert into rm_alarm_log
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="clientId != null and clientId != ''">client_id,</if>
|
||||
<if test="alarmTime != null">alarm_time,</if>
|
||||
<if test="mgmPublicIp != null">mgm_public_ip,</if>
|
||||
<if test="alarmType != null">alarm_type,</if>
|
||||
<if test="alarmContent != null">alarm_content,</if>
|
||||
<if test="createTime != null">create_time,</if>
|
||||
<if test="updateTime != null">update_time,</if>
|
||||
<if test="createBy != null">create_by,</if>
|
||||
<if test="updateBy != null">update_by,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="clientId != null and clientId != ''">#{clientId},</if>
|
||||
<if test="alarmTime != null">#{alarmTime},</if>
|
||||
<if test="mgmPublicIp != null">#{mgmPublicIp},</if>
|
||||
<if test="alarmType != null">#{alarmType},</if>
|
||||
<if test="alarmContent != null">#{alarmContent},</if>
|
||||
<if test="createTime != null">#{createTime},</if>
|
||||
<if test="updateTime != null">#{updateTime},</if>
|
||||
<if test="createBy != null">#{createBy},</if>
|
||||
<if test="updateBy != null">#{updateBy},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<update id="updateRmAlarmLog" parameterType="RmAlarmLog">
|
||||
update rm_alarm_log
|
||||
<trim prefix="SET" suffixOverrides=",">
|
||||
<if test="mgmPublicIp != null">mgm_public_ip = #{mgmPublicIp},</if>
|
||||
<if test="alarmContent != null">alarm_content = #{alarmContent},</if>
|
||||
<if test="createTime != null">create_time = #{createTime},</if>
|
||||
<if test="updateTime != null">update_time = #{updateTime},</if>
|
||||
<if test="createBy != null">create_by = #{createBy},</if>
|
||||
<if test="updateBy != null">update_by = #{updateBy},</if>
|
||||
</trim>
|
||||
<where>
|
||||
<choose>
|
||||
<when test="id != null">
|
||||
and id = #[id]
|
||||
</when>
|
||||
<when test="clientId != null and alarmType != null">
|
||||
and client_id = #{clientId} and alarm_type = #{alarmType}
|
||||
</when>
|
||||
<otherwise>
|
||||
and 1=0
|
||||
</otherwise>
|
||||
</choose>
|
||||
</where>
|
||||
</update>
|
||||
|
||||
<delete id="deleteRmAlarmLogById" parameterType="Long">
|
||||
delete from rm_alarm_log where id = #{id}
|
||||
</delete>
|
||||
|
||||
<delete id="deleteRmAlarmLogByIds" parameterType="String">
|
||||
delete from rm_alarm_log where id in
|
||||
<foreach item="id" collection="array" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</delete>
|
||||
</mapper>
|
||||
@@ -0,0 +1,97 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.ruoyi.mtragent.mapper.RmAlarmPushConfigMapper">
|
||||
|
||||
<resultMap type="RmAlarmPushConfig" id="RmAlarmPushConfigResult">
|
||||
<result property="id" column="id" />
|
||||
<result property="configName" column="config_name" />
|
||||
<result property="pushMethod" column="push_method" />
|
||||
<result property="pushAddress" column="push_address" />
|
||||
<result property="pushAlarmTypes" column="push_alarm_types" />
|
||||
<result property="messageContent" column="message_content" />
|
||||
<result property="contactPhones" column="contact_phones" />
|
||||
<result property="createTime" column="create_time" />
|
||||
<result property="updateTime" column="update_time" />
|
||||
<result property="createBy" column="create_by" />
|
||||
<result property="updateBy" column="update_by" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectRmAlarmPushConfigVo">
|
||||
select id, config_name, push_method, push_address, push_alarm_types, message_content, contact_phones, create_time, update_time, create_by, update_by from rm_alarm_push_config
|
||||
</sql>
|
||||
|
||||
<select id="selectRmAlarmPushConfigList" parameterType="RmAlarmPushConfig" resultMap="RmAlarmPushConfigResult">
|
||||
<include refid="selectRmAlarmPushConfigVo"/>
|
||||
<where>
|
||||
<if test="configName != null and configName != ''"> and config_name like concat('%', #{configName}, '%')</if>
|
||||
<if test="pushMethod != null and pushMethod != ''"> and push_method = #{pushMethod}</if>
|
||||
<if test="pushAddress != null and pushAddress != ''"> and push_address = #{pushAddress}</if>
|
||||
<if test="pushAlarmTypes != null and pushAlarmTypes != ''"> and push_alarm_types = #{pushAlarmTypes}</if>
|
||||
<if test="messageContent != null and messageContent != ''"> and message_content = #{messageContent}</if>
|
||||
<if test="contactPhones != null and contactPhones != ''"> and contact_phones = #{contactPhones}</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="selectRmAlarmPushConfigById" parameterType="Long" resultMap="RmAlarmPushConfigResult">
|
||||
<include refid="selectRmAlarmPushConfigVo"/>
|
||||
where id = #{id}
|
||||
</select>
|
||||
|
||||
<insert id="insertRmAlarmPushConfig" parameterType="RmAlarmPushConfig" useGeneratedKeys="true" keyProperty="id">
|
||||
insert into rm_alarm_push_config
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="configName != null and configName != ''">config_name,</if>
|
||||
<if test="pushMethod != null and pushMethod != ''">push_method,</if>
|
||||
<if test="pushAddress != null and pushAddress != ''">push_address,</if>
|
||||
<if test="pushAlarmTypes != null">push_alarm_types,</if>
|
||||
<if test="messageContent != null">message_content,</if>
|
||||
<if test="contactPhones != null">contact_phones,</if>
|
||||
<if test="createTime != null">create_time,</if>
|
||||
<if test="updateTime != null">update_time,</if>
|
||||
<if test="createBy != null">create_by,</if>
|
||||
<if test="updateBy != null">update_by,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="configName != null and configName != ''">#{configName},</if>
|
||||
<if test="pushMethod != null and pushMethod != ''">#{pushMethod},</if>
|
||||
<if test="pushAddress != null and pushAddress != ''">#{pushAddress},</if>
|
||||
<if test="pushAlarmTypes != null">#{pushAlarmTypes},</if>
|
||||
<if test="messageContent != null">#{messageContent},</if>
|
||||
<if test="contactPhones != null">#{contactPhones},</if>
|
||||
<if test="createTime != null">#{createTime},</if>
|
||||
<if test="updateTime != null">#{updateTime},</if>
|
||||
<if test="createBy != null">#{createBy},</if>
|
||||
<if test="updateBy != null">#{updateBy},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<update id="updateRmAlarmPushConfig" parameterType="RmAlarmPushConfig">
|
||||
update rm_alarm_push_config
|
||||
<trim prefix="SET" suffixOverrides=",">
|
||||
<if test="configName != null and configName != ''">config_name = #{configName},</if>
|
||||
<if test="pushMethod != null and pushMethod != ''">push_method = #{pushMethod},</if>
|
||||
<if test="pushAddress != null and pushAddress != ''">push_address = #{pushAddress},</if>
|
||||
<if test="pushAlarmTypes != null">push_alarm_types = #{pushAlarmTypes},</if>
|
||||
<if test="messageContent != null">message_content = #{messageContent},</if>
|
||||
<if test="contactPhones != null">contact_phones = #{contactPhones},</if>
|
||||
<if test="createTime != null">create_time = #{createTime},</if>
|
||||
<if test="updateTime != null">update_time = #{updateTime},</if>
|
||||
<if test="createBy != null">create_by = #{createBy},</if>
|
||||
<if test="updateBy != null">update_by = #{updateBy},</if>
|
||||
</trim>
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
||||
<delete id="deleteRmAlarmPushConfigById" parameterType="Long">
|
||||
delete from rm_alarm_push_config where id = #{id}
|
||||
</delete>
|
||||
|
||||
<delete id="deleteRmAlarmPushConfigByIds" parameterType="String">
|
||||
delete from rm_alarm_push_config where id in
|
||||
<foreach item="id" collection="array" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</delete>
|
||||
</mapper>
|
||||
@@ -0,0 +1,159 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.ruoyi.mtragent.mapper.RmMtrClientRegistrationMapper">
|
||||
|
||||
<resultMap type="RmMtrClientRegistration" id="RmMtrClientRegistrationResult">
|
||||
<result property="id" column="id" />
|
||||
<result property="mtrClientId" column="mtr_client_id" />
|
||||
<result property="description" column="description" />
|
||||
<result property="version" column="version" />
|
||||
<result property="logicalNode" column="logical_node" />
|
||||
<result property="registerTime" column="register_time" />
|
||||
<result property="registerStatus" column="register_status" />
|
||||
<result property="onlineStatus" column="online_status" />
|
||||
<result property="heartbeatInterval" column="heartbeat_interval" />
|
||||
<result property="heartbeatCount" column="heartbeat_count" />
|
||||
<result property="method" column="method" />
|
||||
<result property="scheduledUpdateTime" column="scheduled_update_time" />
|
||||
<result property="filePath" column="file_path" />
|
||||
<result property="fileMd5" column="file_md5" />
|
||||
<result property="lastUpdateResult" column="last_update_result" />
|
||||
<result property="lastUpdateTime" column="last_update_time" />
|
||||
<result property="networkInfo" column="network_info" />
|
||||
<result property="createTime" column="create_time" />
|
||||
<result property="updateTime" column="update_time" />
|
||||
<result property="createBy" column="create_by" />
|
||||
<result property="updateBy" column="update_by" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectRmMtrClientRegistrationVo">
|
||||
select id, mtr_client_id, description, version, logical_node, register_time, register_status, online_status, heartbeat_interval, heartbeat_count, method, scheduled_update_time, file_path, file_md5, last_update_result, last_update_time, network_info, create_time, update_time, create_by, update_by from rm_mtr_client_registration
|
||||
</sql>
|
||||
|
||||
<select id="selectRmMtrClientRegistrationList" parameterType="RmMtrClientRegistration" resultMap="RmMtrClientRegistrationResult">
|
||||
<include refid="selectRmMtrClientRegistrationVo"/>
|
||||
<where>
|
||||
<if test="mtrClientId != null and mtrClientId != ''"> and mtr_client_id = #{mtrClientId}</if>
|
||||
<if test="description != null and description != ''"> and description = #{description}</if>
|
||||
<if test="version != null and version != ''"> and version = #{version}</if>
|
||||
<if test="logicalNode != null and logicalNode != ''"> and logical_node = #{logicalNode}</if>
|
||||
<if test="registerTime != null "> and register_time = #{registerTime}</if>
|
||||
<if test="registerStatus != null and registerStatus != ''"> and register_status = #{registerStatus}</if>
|
||||
<if test="onlineStatus != null and onlineStatus != ''"> and online_status = #{onlineStatus}</if>
|
||||
<if test="heartbeatInterval != null "> and heartbeat_interval = #{heartbeatInterval}</if>
|
||||
<if test="heartbeatCount != null "> and heartbeat_count = #{heartbeatCount}</if>
|
||||
<if test="method != null and method != ''"> and method = #{method}</if>
|
||||
<if test="scheduledUpdateTime != null and scheduledUpdateTime != ''"> and scheduled_update_time = #{scheduledUpdateTime}</if>
|
||||
<if test="filePath != null and filePath != ''"> and file_path = #{filePath}</if>
|
||||
<if test="fileMd5 != null and fileMd5 != ''"> and file_md5 = #{fileMd5}</if>
|
||||
<if test="lastUpdateResult != null and lastUpdateResult != ''"> and last_update_result = #{lastUpdateResult}</if>
|
||||
<if test="lastUpdateTime != null "> and last_update_time = #{lastUpdateTime}</if>
|
||||
<if test="networkInfo != null and networkInfo != ''"> and network_info = #{networkInfo}</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="selectRmMtrClientRegistrationById" parameterType="Long" resultMap="RmMtrClientRegistrationResult">
|
||||
<include refid="selectRmMtrClientRegistrationVo"/>
|
||||
where id = #{id}
|
||||
</select>
|
||||
|
||||
<insert id="insertRmMtrClientRegistration" parameterType="RmMtrClientRegistration" useGeneratedKeys="true" keyProperty="id">
|
||||
insert into rm_mtr_client_registration
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="mtrClientId != null and mtrClientId != ''">mtr_client_id,</if>
|
||||
<if test="description != null">description,</if>
|
||||
<if test="version != null and version != ''">version,</if>
|
||||
<if test="logicalNode != null">logical_node,</if>
|
||||
<if test="registerTime != null">register_time,</if>
|
||||
<if test="registerStatus != null and registerStatus != ''">register_status,</if>
|
||||
<if test="onlineStatus != null and onlineStatus != ''">online_status,</if>
|
||||
<if test="heartbeatInterval != null">heartbeat_interval,</if>
|
||||
<if test="heartbeatCount != null">heartbeat_count,</if>
|
||||
<if test="method != null">method,</if>
|
||||
<if test="scheduledUpdateTime != null">scheduled_update_time,</if>
|
||||
<if test="filePath != null">file_path,</if>
|
||||
<if test="fileMd5 != null">file_md5,</if>
|
||||
<if test="lastUpdateResult != null">last_update_result,</if>
|
||||
<if test="lastUpdateTime != null">last_update_time,</if>
|
||||
<if test="networkInfo != null">network_info,</if>
|
||||
<if test="createTime != null">create_time,</if>
|
||||
<if test="updateTime != null">update_time,</if>
|
||||
<if test="createBy != null">create_by,</if>
|
||||
<if test="updateBy != null">update_by,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="mtrClientId != null and mtrClientId != ''">#{mtrClientId},</if>
|
||||
<if test="description != null">#{description},</if>
|
||||
<if test="version != null and version != ''">#{version},</if>
|
||||
<if test="logicalNode != null">#{logicalNode},</if>
|
||||
<if test="registerTime != null">#{registerTime},</if>
|
||||
<if test="registerStatus != null and registerStatus != ''">#{registerStatus},</if>
|
||||
<if test="onlineStatus != null and onlineStatus != ''">#{onlineStatus},</if>
|
||||
<if test="heartbeatInterval != null">#{heartbeatInterval},</if>
|
||||
<if test="heartbeatCount != null">#{heartbeatCount},</if>
|
||||
<if test="method != null">#{method},</if>
|
||||
<if test="scheduledUpdateTime != null">#{scheduledUpdateTime},</if>
|
||||
<if test="filePath != null">#{filePath},</if>
|
||||
<if test="fileMd5 != null">#{fileMd5},</if>
|
||||
<if test="lastUpdateResult != null">#{lastUpdateResult},</if>
|
||||
<if test="lastUpdateTime != null">#{lastUpdateTime},</if>
|
||||
<if test="networkInfo != null">#{networkInfo},</if>
|
||||
<if test="createTime != null">#{createTime},</if>
|
||||
<if test="updateTime != null">#{updateTime},</if>
|
||||
<if test="createBy != null">#{createBy},</if>
|
||||
<if test="updateBy != null">#{updateBy},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<update id="updateRmMtrClientRegistration" parameterType="RmMtrClientRegistration">
|
||||
update rm_mtr_client_registration
|
||||
<trim prefix="SET" suffixOverrides=",">
|
||||
<if test="mtrClientId != null and mtrClientId != ''">mtr_client_id = #{mtrClientId},</if>
|
||||
<if test="description != null">description = #{description},</if>
|
||||
<if test="version != null and version != ''">version = #{version},</if>
|
||||
<if test="logicalNode != null">logical_node = #{logicalNode},</if>
|
||||
<if test="registerTime != null">register_time = #{registerTime},</if>
|
||||
<if test="registerStatus != null and registerStatus != ''">register_status = #{registerStatus},</if>
|
||||
<if test="onlineStatus != null and onlineStatus != ''">online_status = #{onlineStatus},</if>
|
||||
<if test="heartbeatInterval != null">heartbeat_interval = #{heartbeatInterval},</if>
|
||||
<if test="heartbeatCount != null">heartbeat_count = #{heartbeatCount},</if>
|
||||
<if test="method != null">method = #{method},</if>
|
||||
<if test="scheduledUpdateTime != null">scheduled_update_time = #{scheduledUpdateTime},</if>
|
||||
<if test="filePath != null">file_path = #{filePath},</if>
|
||||
<if test="fileMd5 != null">file_md5 = #{fileMd5},</if>
|
||||
<if test="lastUpdateResult != null">last_update_result = #{lastUpdateResult},</if>
|
||||
<if test="lastUpdateTime != null">last_update_time = #{lastUpdateTime},</if>
|
||||
<if test="networkInfo != null">network_info = #{networkInfo},</if>
|
||||
<if test="createTime != null">create_time = #{createTime},</if>
|
||||
<if test="updateTime != null">update_time = #{updateTime},</if>
|
||||
<if test="createBy != null">create_by = #{createBy},</if>
|
||||
<if test="updateBy != null">update_by = #{updateBy},</if>
|
||||
</trim>
|
||||
<where>
|
||||
<choose>
|
||||
<when test="id != null">
|
||||
and id=#{id}
|
||||
</when>
|
||||
<when test="mtrClientId">
|
||||
and mtr_client_id = #{mtrClientId}
|
||||
</when>
|
||||
<otherwise>
|
||||
and 1=0
|
||||
</otherwise>
|
||||
</choose>
|
||||
</where>
|
||||
</update>
|
||||
|
||||
<delete id="deleteRmMtrClientRegistrationById" parameterType="Long">
|
||||
delete from rm_mtr_client_registration where id = #{id}
|
||||
</delete>
|
||||
|
||||
<delete id="deleteRmMtrClientRegistrationByIds" parameterType="String">
|
||||
delete from rm_mtr_client_registration where id in
|
||||
<foreach item="id" collection="array" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</delete>
|
||||
</mapper>
|
||||
@@ -0,0 +1,112 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.ruoyi.mtragent.mapper.RmMtrPolicyConfigMapper">
|
||||
|
||||
<resultMap type="RmMtrPolicyConfig" id="RmMtrPolicyConfigResult">
|
||||
<result property="id" column="id" />
|
||||
<result property="policyName" column="policy_name" />
|
||||
<result property="priority" column="priority" />
|
||||
<result property="mtrClientId" column="mtr_client_id" />
|
||||
<result property="serverGroup" column="server_group" />
|
||||
<result property="serveripGroup" column="serverip_group" />
|
||||
<result property="probeFlag" column="probe_flag" />
|
||||
<result property="startTime" column="start_time" />
|
||||
<result property="endTime" column="end_time" />
|
||||
<result property="probeFrequency" column="probe_frequency" />
|
||||
<result property="createTime" column="create_time" />
|
||||
<result property="updateTime" column="update_time" />
|
||||
<result property="createBy" column="create_by" />
|
||||
<result property="updateBy" column="update_by" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectRmMtrPolicyConfigVo">
|
||||
select id, policy_name, priority, mtr_client_id, server_group, serverip_group, probe_flag, start_time, end_time, probe_frequency, create_time, update_time, create_by, update_by from rm_mtr_policy_config
|
||||
</sql>
|
||||
|
||||
<select id="selectRmMtrPolicyConfigList" parameterType="RmMtrPolicyConfig" resultMap="RmMtrPolicyConfigResult">
|
||||
<include refid="selectRmMtrPolicyConfigVo"/>
|
||||
<where>
|
||||
<if test="policyName != null and policyName != ''"> and policy_name like concat('%', #{policyName}, '%')</if>
|
||||
<if test="priority != null "> and priority = #{priority}</if>
|
||||
<if test="mtrClientId != null and mtrClientId != ''"> and mtr_client_id = #{mtrClientId}</if>
|
||||
<if test="serverGroup != null and serverGroup != ''"> and server_group = #{serverGroup}</if>
|
||||
<if test="serveripGroup != null and serveripGroup != ''"> and serverip_group = #{serveripGroup}</if>
|
||||
<if test="probeFlag != null "> and probe_flag = #{probeFlag}</if>
|
||||
<if test="startTime != null "> and start_time = #{startTime}</if>
|
||||
<if test="endTime != null "> and end_time = #{endTime}</if>
|
||||
<if test="probeFrequency != null "> and probe_frequency = #{probeFrequency}</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="selectRmMtrPolicyConfigById" parameterType="Long" resultMap="RmMtrPolicyConfigResult">
|
||||
<include refid="selectRmMtrPolicyConfigVo"/>
|
||||
where id = #{id}
|
||||
</select>
|
||||
|
||||
<insert id="insertRmMtrPolicyConfig" parameterType="RmMtrPolicyConfig" useGeneratedKeys="true" keyProperty="id">
|
||||
insert into rm_mtr_policy_config
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="policyName != null and policyName != ''">policy_name,</if>
|
||||
<if test="priority != null">priority,</if>
|
||||
<if test="mtrClientId != null and mtrClientId != ''">mtr_client_id,</if>
|
||||
<if test="serverGroup != null">server_group,</if>
|
||||
<if test="serveripGroup != null">serverip_group,</if>
|
||||
<if test="probeFlag != null">probe_flag,</if>
|
||||
<if test="startTime != null">start_time,</if>
|
||||
<if test="endTime != null">end_time,</if>
|
||||
<if test="probeFrequency != null">probe_frequency,</if>
|
||||
<if test="createTime != null">create_time,</if>
|
||||
<if test="updateTime != null">update_time,</if>
|
||||
<if test="createBy != null">create_by,</if>
|
||||
<if test="updateBy != null">update_by,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="policyName != null and policyName != ''">#{policyName},</if>
|
||||
<if test="priority != null">#{priority},</if>
|
||||
<if test="mtrClientId != null and mtrClientId != ''">#{mtrClientId},</if>
|
||||
<if test="serverGroup != null">#{serverGroup},</if>
|
||||
<if test="serveripGroup != null">#{serveripGroup},</if>
|
||||
<if test="probeFlag != null">#{probeFlag},</if>
|
||||
<if test="startTime != null">#{startTime},</if>
|
||||
<if test="endTime != null">#{endTime},</if>
|
||||
<if test="probeFrequency != null">#{probeFrequency},</if>
|
||||
<if test="createTime != null">#{createTime},</if>
|
||||
<if test="updateTime != null">#{updateTime},</if>
|
||||
<if test="createBy != null">#{createBy},</if>
|
||||
<if test="updateBy != null">#{updateBy},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<update id="updateRmMtrPolicyConfig" parameterType="RmMtrPolicyConfig">
|
||||
update rm_mtr_policy_config
|
||||
<trim prefix="SET" suffixOverrides=",">
|
||||
<if test="policyName != null and policyName != ''">policy_name = #{policyName},</if>
|
||||
<if test="priority != null">priority = #{priority},</if>
|
||||
<if test="mtrClientId != null and mtrClientId != ''">mtr_client_id = #{mtrClientId},</if>
|
||||
<if test="serverGroup != null">server_group = #{serverGroup},</if>
|
||||
<if test="serveripGroup != null">serverip_group = #{serveripGroup},</if>
|
||||
<if test="probeFlag != null">probe_flag = #{probeFlag},</if>
|
||||
<if test="startTime != null">start_time = #{startTime},</if>
|
||||
<if test="endTime != null">end_time = #{endTime},</if>
|
||||
<if test="probeFrequency != null">probe_frequency = #{probeFrequency},</if>
|
||||
<if test="createTime != null">create_time = #{createTime},</if>
|
||||
<if test="updateTime != null">update_time = #{updateTime},</if>
|
||||
<if test="createBy != null">create_by = #{createBy},</if>
|
||||
<if test="updateBy != null">update_by = #{updateBy},</if>
|
||||
</trim>
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
||||
<delete id="deleteRmMtrPolicyConfigById" parameterType="Long">
|
||||
delete from rm_mtr_policy_config where id = #{id}
|
||||
</delete>
|
||||
|
||||
<delete id="deleteRmMtrPolicyConfigByIds" parameterType="String">
|
||||
delete from rm_mtr_policy_config where id in
|
||||
<foreach item="id" collection="array" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</delete>
|
||||
</mapper>
|
||||
@@ -0,0 +1,148 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.ruoyi.mtragent.mapper.RmNetworkInterfaceMapper">
|
||||
|
||||
<resultMap type="RmNetworkInterface" id="RmNetworkInterfaceResult">
|
||||
<result property="id" column="id" />
|
||||
<result property="clientId" column="client_id" />
|
||||
<result property="isp" column="isp" />
|
||||
<result property="province" column="province" />
|
||||
<result property="city" column="city" />
|
||||
<result property="publicIp" column="public_ip" />
|
||||
<result property="interfaceName" column="interface_name" />
|
||||
<result property="macAddress" column="mac_address" />
|
||||
<result property="interfaceType" column="interface_type" />
|
||||
<result property="ipv4Address" column="ipv4_address" />
|
||||
<result property="gateway" column="gateway" />
|
||||
<result property="createTime" column="create_time" />
|
||||
<result property="updateTime" column="update_time" />
|
||||
<result property="createBy" column="create_by" />
|
||||
<result property="updateBy" column="update_by" />
|
||||
<result property="bindIp" column="bind_ip" />
|
||||
<result property="newFlag" column="new_flag" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectRmNetworkInterfaceVo">
|
||||
select id, client_id, isp, province, city, public_ip, interface_name, mac_address, interface_type, ipv4_address, gateway, create_time, update_time, create_by, update_by, bind_ip, new_flag from rm_network_interface
|
||||
</sql>
|
||||
|
||||
<select id="selectRmNetworkInterfaceList" parameterType="RmNetworkInterface" resultMap="RmNetworkInterfaceResult">
|
||||
<include refid="selectRmNetworkInterfaceVo"/>
|
||||
<where>
|
||||
<if test="clientId != null and clientId != ''"> and client_id = #{clientId}</if>
|
||||
<if test="isp != null and isp != ''"> and isp = #{isp}</if>
|
||||
<if test="province != null and province != ''"> and province = #{province}</if>
|
||||
<if test="city != null and city != ''"> and city = #{city}</if>
|
||||
<if test="publicIp != null and publicIp != ''"> and public_ip = #{publicIp}</if>
|
||||
<if test="interfaceName != null and interfaceName != ''"> and interface_name like concat('%', #{interfaceName}, '%')</if>
|
||||
<if test="macAddress != null and macAddress != ''"> and mac_address = #{macAddress}</if>
|
||||
<if test="interfaceType != null and interfaceType != ''"> and interface_type = #{interfaceType}</if>
|
||||
<if test="ipv4Address != null and ipv4Address != ''"> and ipv4_address = #{ipv4Address}</if>
|
||||
<if test="gateway != null and gateway != ''"> and gateway = #{gateway}</if>
|
||||
<if test="bindIp != null and bindIp != ''"> and bind_ip = #{bindIp}</if>
|
||||
<if test="newFlag != null "> and new_flag = #{newFlag}</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="selectRmNetworkInterfaceById" parameterType="Long" resultMap="RmNetworkInterfaceResult">
|
||||
<include refid="selectRmNetworkInterfaceVo"/>
|
||||
where id = #{id}
|
||||
</select>
|
||||
|
||||
<insert id="insertRmNetworkInterface" parameterType="RmNetworkInterface" useGeneratedKeys="true" keyProperty="id">
|
||||
insert into rm_network_interface
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="clientId != null and clientId != ''">client_id,</if>
|
||||
<if test="isp != null">isp,</if>
|
||||
<if test="province != null">province,</if>
|
||||
<if test="city != null">city,</if>
|
||||
<if test="publicIp != null">public_ip,</if>
|
||||
<if test="interfaceName != null and interfaceName != ''">interface_name,</if>
|
||||
<if test="macAddress != null">mac_address,</if>
|
||||
<if test="interfaceType != null">interface_type,</if>
|
||||
<if test="ipv4Address != null">ipv4_address,</if>
|
||||
<if test="gateway != null">gateway,</if>
|
||||
<if test="createTime != null">create_time,</if>
|
||||
<if test="updateTime != null">update_time,</if>
|
||||
<if test="createBy != null">create_by,</if>
|
||||
<if test="updateBy != null">update_by,</if>
|
||||
<if test="bindIp != null">bind_ip,</if>
|
||||
<if test="newFlag != null">new_flag,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="clientId != null and clientId != ''">#{clientId},</if>
|
||||
<if test="isp != null">#{isp},</if>
|
||||
<if test="province != null">#{province},</if>
|
||||
<if test="city != null">#{city},</if>
|
||||
<if test="publicIp != null">#{publicIp},</if>
|
||||
<if test="interfaceName != null and interfaceName != ''">#{interfaceName},</if>
|
||||
<if test="macAddress != null">#{macAddress},</if>
|
||||
<if test="interfaceType != null">#{interfaceType},</if>
|
||||
<if test="ipv4Address != null">#{ipv4Address},</if>
|
||||
<if test="gateway != null">#{gateway},</if>
|
||||
<if test="createTime != null">#{createTime},</if>
|
||||
<if test="updateTime != null">#{updateTime},</if>
|
||||
<if test="createBy != null">#{createBy},</if>
|
||||
<if test="updateBy != null">#{updateBy},</if>
|
||||
<if test="bindIp != null">#{bindIp},</if>
|
||||
<if test="newFlag != null">#{newFlag},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<update id="updateRmNetworkInterface" parameterType="RmNetworkInterface">
|
||||
update rm_network_interface
|
||||
<trim prefix="SET" suffixOverrides=",">
|
||||
<if test="clientId != null and clientId != ''">client_id = #{clientId},</if>
|
||||
<if test="isp != null">isp = #{isp},</if>
|
||||
<if test="province != null">province = #{province},</if>
|
||||
<if test="city != null">city = #{city},</if>
|
||||
<if test="publicIp != null">public_ip = #{publicIp},</if>
|
||||
<if test="interfaceName != null and interfaceName != ''">interface_name = #{interfaceName},</if>
|
||||
<if test="macAddress != null">mac_address = #{macAddress},</if>
|
||||
<if test="interfaceType != null">interface_type = #{interfaceType},</if>
|
||||
<if test="ipv4Address != null">ipv4_address = #{ipv4Address},</if>
|
||||
<if test="gateway != null">gateway = #{gateway},</if>
|
||||
<if test="createTime != null">create_time = #{createTime},</if>
|
||||
<if test="updateTime != null">update_time = #{updateTime},</if>
|
||||
<if test="createBy != null">create_by = #{createBy},</if>
|
||||
<if test="updateBy != null">update_by = #{updateBy},</if>
|
||||
<if test="bindIp != null">bind_ip = #{bindIp},</if>
|
||||
<if test="newFlag != null">new_flag = #{newFlag},</if>
|
||||
</trim>
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
||||
<delete id="deleteRmNetworkInterfaceById" parameterType="Long">
|
||||
delete from rm_network_interface where id = #{id}
|
||||
</delete>
|
||||
|
||||
<delete id="deleteRmNetworkInterfaceByIds" parameterType="String">
|
||||
delete from rm_network_interface where id in
|
||||
<foreach item="id" collection="array" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</delete>
|
||||
<update id="updateRmNetworkInterfaceByMac" parameterType="RmNetworkInterface">
|
||||
update rm_network_interface
|
||||
<trim prefix="SET" suffixOverrides=",">
|
||||
<if test="isp != null">isp = #{isp},</if>
|
||||
<if test="province != null">province = #{province},</if>
|
||||
<if test="city != null">city = #{city},</if>
|
||||
<if test="publicIp != null">public_ip = #{publicIp},</if>
|
||||
<if test="interfaceName != null and interfaceName != ''">interface_name = #{interfaceName},</if>
|
||||
<if test="macAddress != null">mac_address = #{macAddress},</if>
|
||||
<if test="interfaceType != null">interface_type = #{interfaceType},</if>
|
||||
<if test="ipv4Address != null">ipv4_address = #{ipv4Address},</if>
|
||||
<if test="gateway != null">gateway = #{gateway},</if>
|
||||
<if test="createTime != null">create_time = #{createTime},</if>
|
||||
<if test="updateTime != null">update_time = #{updateTime},</if>
|
||||
<if test="createBy != null">create_by = #{createBy},</if>
|
||||
<if test="updateBy != null">update_by = #{updateBy},</if>
|
||||
<if test="bindIp != null">bind_ip = #{bindIp},</if>
|
||||
<if test="newFlag != null">new_flag = #{newFlag},</if>
|
||||
</trim>
|
||||
where mac_address = #{macAddress} and clientId = #{clientId}
|
||||
</update>
|
||||
</mapper>
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.ruoyi.mtragent;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
/**
|
||||
* Unit test for simple App.
|
||||
*/
|
||||
public class AppTest
|
||||
extends TestCase
|
||||
{
|
||||
/**
|
||||
* Create the test case
|
||||
*
|
||||
* @param testName name of the test case
|
||||
*/
|
||||
public AppTest( String testName )
|
||||
{
|
||||
super( testName );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the suite of tests being tested
|
||||
*/
|
||||
public static Test suite()
|
||||
{
|
||||
return new TestSuite( AppTest.class );
|
||||
}
|
||||
|
||||
/**
|
||||
* Rigourous Test :-)
|
||||
*/
|
||||
public void testApp()
|
||||
{
|
||||
assertTrue( true );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,259 @@
|
||||
package com.ruoyi.system.config;
|
||||
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.ruoyi.common.core.utils.DateUtils;
|
||||
import com.ruoyi.system.domain.EpsInitialTrafficData;
|
||||
import com.ruoyi.system.domain.RmRegistrationMachine;
|
||||
import com.ruoyi.system.service.EpsInitialTrafficDataService;
|
||||
import com.ruoyi.system.service.IRmRegistrationMachineService;
|
||||
import com.ruoyi.system.util.TableRouterUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
||||
import javax.crypto.Mac;
|
||||
import javax.crypto.SecretKey;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import java.math.BigDecimal;
|
||||
import java.net.URI;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
@Component
|
||||
public class HmacScheduledTask {
|
||||
|
||||
private static final String MAC_NAME = "HmacSHA1";
|
||||
private static final String ENCODING = "UTF-8";
|
||||
|
||||
@Autowired
|
||||
private IRmRegistrationMachineService rmRegistrationMachineService;
|
||||
@Autowired
|
||||
private EpsInitialTrafficDataService epsInitialTrafficDataService;
|
||||
|
||||
|
||||
/**
|
||||
* 每小时执行一次,查询4小时前的数据
|
||||
* 例如:9:39执行时查询4:00-5:00的数据
|
||||
*/
|
||||
@Scheduled(cron = "0 0 * * * ?") // 每小时整点执行
|
||||
// 或者每5分钟执行一次:@Scheduled(cron = "0 */5 * * * ?")
|
||||
// @Scheduled(initialDelay = 5000, fixedDelay = Long.MAX_VALUE)
|
||||
public void executeHourlyTask() {
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
try {
|
||||
System.out.println("开始执行定时任务,时间:" + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
||||
|
||||
// 计算时间范围:当前时间往前推4小时的整点时间段
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
|
||||
// 计算查询的时间段(4小时前的整点小时)
|
||||
LocalDateTime queryBaseTime = now.minusHours(4);
|
||||
LocalDateTime startTime = queryBaseTime.withMinute(0).withSecond(0).withNano(0);
|
||||
LocalDateTime endTime = startTime.plusHours(1);
|
||||
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
String startTimeStr = startTime.format(formatter);
|
||||
String endTimeStr = endTime.format(formatter);
|
||||
|
||||
System.out.println("查询时间范围:" + startTimeStr + " 至 " + endTimeStr);
|
||||
|
||||
long timestamp = System.currentTimeMillis();
|
||||
String plainText = "efea5f0218c84a24b9fdab3264de3da5" + timestamp + "/supplier/outer/dev/getFlow";
|
||||
String secretKey = getHmac(plainText, "91a73fd806ab2c005c13b4dc19130a884e909dea3f72d46e30266fe1a1f588d8");
|
||||
|
||||
// 设置请求头
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("Content-Type", "application/json");
|
||||
headers.set("TOKEN", "efea5f0218c84a24b9fdab3264de3da5");
|
||||
headers.set("secret-key", secretKey);
|
||||
headers.set("timestamps", String.valueOf(timestamp));
|
||||
// 查询绑定的machinecode
|
||||
List<RmRegistrationMachine> machineList = rmRegistrationMachineService.selectRmRegistrationMachineList(new RmRegistrationMachine());
|
||||
for (RmRegistrationMachine rmRegistrationMachine : machineList) {
|
||||
// 构建URL
|
||||
URI uri = UriComponentsBuilder
|
||||
.fromHttpUrl("https://ecscm-openapi.ksyun.com/supplier/outer/dev/getFlow")
|
||||
.queryParam("srmChannel", "1000121954")
|
||||
.queryParam("startTime", startTimeStr)
|
||||
.queryParam("endTime", endTimeStr)
|
||||
.queryParam("machineCode", rmRegistrationMachine.getMachineCode())
|
||||
.build()
|
||||
.toUri();
|
||||
|
||||
HttpEntity<String> entity = new HttpEntity<>(headers);
|
||||
|
||||
// GET 请求
|
||||
ResponseEntity<String> response = restTemplate.exchange(
|
||||
uri,
|
||||
HttpMethod.GET,
|
||||
entity,
|
||||
String.class
|
||||
);
|
||||
String result = response.getBody();
|
||||
// 保存流量数据
|
||||
parseAndProcessResponse(result, rmRegistrationMachine.getClientId());
|
||||
}
|
||||
System.out.println("定时任务执行完成");
|
||||
|
||||
} catch (Exception e) {
|
||||
System.err.println("定时任务执行失败:" + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 解析和处理API响应
|
||||
*/
|
||||
private void parseAndProcessResponse(String responseBody, String clientId) {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
try {
|
||||
Map<String, Object> responseMap = objectMapper.readValue(responseBody, Map.class);
|
||||
|
||||
if (responseMap.get("code").equals(200)) {
|
||||
Map<String, Object> dataMap = (Map<String, Object>) responseMap.get("data");
|
||||
Integer total = (Integer) dataMap.get("total");
|
||||
List<Map<String, Object>> dataList = (List<Map<String, Object>>) dataMap.get("data");
|
||||
|
||||
System.out.println("成功获取数据,总记录数:" + total);
|
||||
|
||||
// 处理每条数据
|
||||
for (Map<String, Object> item : dataList) {
|
||||
processFlowData(item, clientId);
|
||||
}
|
||||
|
||||
} else {
|
||||
System.out.println("API返回错误:" + responseMap.get("msg"));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.err.println("JSON解析失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理单条流量数据
|
||||
*/
|
||||
private void processFlowData(Map<String, Object> flowData, String clientId) {
|
||||
String time = (String) flowData.get("time");
|
||||
// 科学计数法转换为BigDecimal
|
||||
BigDecimal flow = Optional.ofNullable(flowData.get("flow"))
|
||||
.map(Object::toString)
|
||||
.map(str -> {
|
||||
try {
|
||||
return new BigDecimal(str);
|
||||
} catch (NumberFormatException e) {
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
})
|
||||
.orElse(BigDecimal.ZERO);
|
||||
// 字节转bit
|
||||
flow = flow.multiply(new BigDecimal(8));
|
||||
String flowPlain = flow.toPlainString();
|
||||
String deviceid = (String) flowData.get("deviceid");
|
||||
String ip = (String) flowData.get("ip");
|
||||
String province = (String) flowData.get("province");
|
||||
|
||||
System.out.println(String.format("时间:%s, 流量:%.2f, 设备:%s, IP:%s, 省份:%s",
|
||||
time, flow, deviceid, ip, province));
|
||||
|
||||
String tableName = TableRouterUtil.getTableName(TableRouterUtil.parseDateTime(time));
|
||||
EpsInitialTrafficData epsInitialTrafficData = new EpsInitialTrafficData();
|
||||
epsInitialTrafficData.setTableName(tableName);
|
||||
epsInitialTrafficData.setCreateTime(DateUtils.parseDate(time));
|
||||
epsInitialTrafficData.setClientId(clientId);
|
||||
epsInitialTrafficData.setMachineFlow(flowPlain);
|
||||
epsInitialTrafficDataService.updateMachineTraffic(epsInitialTrafficData);
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试方法:手动执行查询指定时间段
|
||||
*/
|
||||
public void manualExecuteForTimeRange(LocalDateTime start, LocalDateTime end) {
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
try {
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
String startTimeStr = start.format(formatter);
|
||||
String endTimeStr = end.format(formatter);
|
||||
|
||||
System.out.println("手动执行查询,时间范围:" + startTimeStr + " 至 " + endTimeStr);
|
||||
|
||||
long timestamp = System.currentTimeMillis();
|
||||
String plainText = "efea5f0218c84a24b9fdab3264de3da5" + timestamp + "/supplier/outer/dev/getFlow";
|
||||
String secretKey = getHmac(plainText, "91a73fd806ab2c005c13b4dc19130a884e909dea3f72d46e30266fe1a1f588d8");
|
||||
|
||||
// 设置请求头
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("Content-Type", "application/json");
|
||||
headers.set("TOKEN", "efea5f0218c84a24b9fdab3264de3da5");
|
||||
headers.set("secret-key", secretKey);
|
||||
headers.set("timestamps", String.valueOf(timestamp));
|
||||
|
||||
// 构建URL
|
||||
URI uri = UriComponentsBuilder
|
||||
.fromHttpUrl("https://ecscm-openapi.ksyun.com/supplier/outer/dev/getFlow")
|
||||
.queryParam("srmChannel", "1000121954")
|
||||
.queryParam("startTime", startTimeStr)
|
||||
.queryParam("endTime", endTimeStr)
|
||||
.build()
|
||||
.toUri();
|
||||
|
||||
HttpEntity<String> entity = new HttpEntity<>(headers);
|
||||
|
||||
// GET 请求
|
||||
ResponseEntity<String> response = restTemplate.exchange(
|
||||
uri,
|
||||
HttpMethod.GET,
|
||||
entity,
|
||||
String.class
|
||||
);
|
||||
|
||||
System.out.println("手动执行API响应结果:" + response.getBody());
|
||||
|
||||
} catch (Exception e) {
|
||||
System.err.println("手动执行失败:" + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* HMAC加密方法
|
||||
*/
|
||||
public static String getHmac(String plainText, String encryptKey) {
|
||||
try{
|
||||
byte[] dataKey = encryptKey.getBytes(ENCODING);
|
||||
byte[] dataValue = plainText.getBytes(ENCODING);
|
||||
SecretKey secretKey = new SecretKeySpec(dataKey, MAC_NAME);
|
||||
Mac mac = Mac.getInstance(MAC_NAME);
|
||||
mac.init(secretKey);
|
||||
byte[] bytes = mac.doFinal(dataValue);
|
||||
String rs = encodeHex(bytes, false);
|
||||
return rs;
|
||||
} catch (Exception e){
|
||||
throw new IllegalArgumentException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据转16进制编码
|
||||
*/
|
||||
public static String encodeHex(final byte[] data, final boolean toLowerCase) {
|
||||
final char[] DIGITS_LOWER = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
|
||||
final char[] DIGITS_UPPER = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
|
||||
final char[] toDigits = toLowerCase ? DIGITS_LOWER : DIGITS_UPPER;
|
||||
final int l = data.length;
|
||||
final char[] out = new char[l << 1];
|
||||
for (int i = 0, j = 0; i < l; i++) {
|
||||
out[j++] = toDigits[(0xF0 & data[i]) >>> 4];
|
||||
out[j++] = toDigits[0x0F & data[i]];
|
||||
}
|
||||
return new String(out);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.ruoyi.system.config;
|
||||
|
||||
import com.ruoyi.common.core.utils.DateUtils;
|
||||
import com.ruoyi.system.domain.*;
|
||||
import com.ruoyi.system.service.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -35,11 +34,11 @@ public class TableScheduleConfig {
|
||||
@Autowired
|
||||
private IAllInterfaceNameService allInterfaceNameService;
|
||||
@Autowired
|
||||
private IEpsServerRevenueConfigService epsServerRevenueConfigService;
|
||||
@Autowired
|
||||
private IRmEpsTopologyManagementService rmEpsTopologyManagementService;
|
||||
@Autowired
|
||||
private IEpsMethodChangeRecordService epsMethodChangeRecordService;
|
||||
@Autowired
|
||||
private IRmMonitorConfigService rmMonitorConfigService;
|
||||
|
||||
// 每月25号创建下月表
|
||||
@Scheduled(cron = "0 0 0 25 * ?")
|
||||
@@ -48,6 +47,14 @@ public class TableScheduleConfig {
|
||||
epsInitialTrafficDataService.createNextMonthTables();
|
||||
}
|
||||
|
||||
/**
|
||||
* 每5分钟计算配置好的总流量
|
||||
*/
|
||||
@Scheduled(cron = "0 1/5 * * * ?")
|
||||
public void sumTrafficMyMonitorConfigScheduled() {
|
||||
rmMonitorConfigService.sumTrafficMyMonitorConfig(null);
|
||||
}
|
||||
|
||||
// 每天0点执行 计算95带宽值/日
|
||||
@Scheduled(cron = "0 4 0 * * ?", zone = "Asia/Shanghai")
|
||||
public void calculate95BandwidthDaily() {
|
||||
@@ -72,6 +79,26 @@ public class TableScheduleConfig {
|
||||
.thenRun(() -> executeWithLog("交换机带宽1024",
|
||||
() -> initialSwitchInfoDetailsService.calculateSwitch95BandwidthDaily(initialSwitchInfoDetails, dailyStartTime, dailyEndTime, "1024")));
|
||||
}
|
||||
// 每天5点04执行 计算金山95带宽值/日
|
||||
@Scheduled(cron = "0 4 5 * * ?", zone = "Asia/Shanghai")
|
||||
public void calculateJinShan95() {
|
||||
// 获取昨天的日期范围(北京时间)
|
||||
LocalDate yesterday = LocalDate.now(ZoneId.of("Asia/Shanghai")).minusDays(1);
|
||||
String dailyStartTime = yesterday.atStartOfDay().format(TIME_FORMAT); // 00:00:00
|
||||
String dailyEndTime = yesterday.atTime(23, 59, 59).format(TIME_FORMAT); // 23:59:59
|
||||
// 日
|
||||
String dayOrMonth = "1";
|
||||
// 95带宽值/日
|
||||
EpsInitialTrafficData queryParam = new EpsInitialTrafficData();
|
||||
queryParam.setDayOrMonth(dayOrMonth);
|
||||
InitialSwitchInfoDetails initialSwitchInfoDetails = new InitialSwitchInfoDetails();
|
||||
initialSwitchInfoDetails.setDayOrMonth(dayOrMonth);
|
||||
// 顺序执行链
|
||||
CompletableFuture.runAsync(() -> executeWithLog("金山业务带宽1000",
|
||||
() -> epsInitialTrafficDataService.calculate95ByJinShan(queryParam, dailyStartTime, dailyEndTime, "1000")))
|
||||
.thenRun(() -> executeWithLog("金山业务带宽1024",
|
||||
() -> epsInitialTrafficDataService.calculate95ByJinShan(queryParam, dailyStartTime, dailyEndTime, "1024")));
|
||||
}
|
||||
|
||||
// 每月1号0点执行 计算95带宽值/月
|
||||
@Scheduled(cron = "0 3 0 1 * ?", zone = "Asia/Shanghai")
|
||||
@@ -168,32 +195,14 @@ public class TableScheduleConfig {
|
||||
* 处理单个服务器的平均带宽计算
|
||||
*/
|
||||
private void processServerAvgBandwidth(EpsNodeBandwidth epsNodeBandwidth, AllInterfaceName allInterfaceName, String calculationMode) {
|
||||
final String deviceSn = allInterfaceName.getDeviceSn();
|
||||
final String clientId = allInterfaceName.getClientId();
|
||||
|
||||
try {
|
||||
// 1. 设置基础设备信息
|
||||
epsNodeBandwidth.setHardwareSn(deviceSn);
|
||||
|
||||
// 2. 查询服务器配置
|
||||
EpsServerRevenueConfig queryConfig = new EpsServerRevenueConfig();
|
||||
queryConfig.setHardwareSn(deviceSn);
|
||||
List<EpsServerRevenueConfig> configList = epsServerRevenueConfigService.selectEpsServerRevenueConfigList(queryConfig);
|
||||
EpsServerRevenueConfig serverConfig = configList.isEmpty() ? new EpsServerRevenueConfig() : configList.get(0);
|
||||
epsNodeBandwidth.setNodeName(serverConfig.getNodeName());
|
||||
|
||||
// 3. 检查是否需要处理业务变更
|
||||
boolean shouldProcessChange = serverConfig.getUpdateTime() != null
|
||||
&& epsNodeBandwidth.getStartTime() != null
|
||||
&& epsNodeBandwidth.getStartTime().length() >= 10
|
||||
&& "1".equals(serverConfig.getChanged())
|
||||
&& DateUtils.parseDateToStr("yyyy-MM", serverConfig.getUpdateTime())
|
||||
.equals(epsNodeBandwidth.getStartTime().substring(0, 7));
|
||||
|
||||
// 4. 处理业务变更情况
|
||||
if (shouldProcessChange) {
|
||||
epsNodeBandwidth.setClientId(clientId);
|
||||
// 查询业务变更记录
|
||||
EpsMethodChangeRecord changeQuery = new EpsMethodChangeRecord();
|
||||
changeQuery.setHardwareSn(deviceSn);
|
||||
changeQuery.setClientId(clientId);
|
||||
changeQuery.setStartTime(epsNodeBandwidth.getStartTime());
|
||||
changeQuery.setEndTime(epsNodeBandwidth.getEndTime());
|
||||
|
||||
@@ -217,9 +226,8 @@ public class TableScheduleConfig {
|
||||
|
||||
// 创建业务带宽对象
|
||||
EpsNodeBandwidth bandwidthWithBiz = new EpsNodeBandwidth();
|
||||
bandwidthWithBiz.setHardwareSn(deviceSn);
|
||||
bandwidthWithBiz.setClientId(clientId);
|
||||
bandwidthWithBiz.setCalculationMode(calculationMode);
|
||||
bandwidthWithBiz.setNodeName(serverConfig.getNodeName());
|
||||
bandwidthWithBiz.setStartTime(epsNodeBandwidth.getStartTime());
|
||||
bandwidthWithBiz.setEndTime(epsNodeBandwidth.getEndTime());
|
||||
bandwidthWithBiz.setBusinessId(businessCode);
|
||||
@@ -236,28 +244,38 @@ public class TableScheduleConfig {
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (!nullBusinessRecords.isEmpty()) {
|
||||
log.warn("服务器 {} 有 {} 条记录的businessCode为null", deviceSn, nullBusinessRecords.size());
|
||||
log.warn("服务器 {} 有 {} 条记录的businessCode为null", clientId, nullBusinessRecords.size());
|
||||
// 可以选择记录日志或进行其他处理
|
||||
}
|
||||
|
||||
return; // 业务变更处理完成后直接返回
|
||||
}
|
||||
String businessCode = null;
|
||||
String businessName = null;
|
||||
// 查询绑定的业务
|
||||
EpsMethodChangeRecord queryParam = new EpsMethodChangeRecord();
|
||||
queryParam.setClientId(clientId);
|
||||
List<EpsMethodChangeRecord> recordList = epsMethodChangeRecordService.selectEpsMethodChangeRecordList(queryParam);
|
||||
if(!recordList.isEmpty()){
|
||||
EpsMethodChangeRecord record = recordList.stream()
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
businessCode = record.getBusinessCode();
|
||||
businessName = record.getBusinessName();
|
||||
}
|
||||
|
||||
// 5. 处理正常情况(无业务变更或无需处理变更)
|
||||
EpsNodeBandwidth normalBandwidth = new EpsNodeBandwidth();
|
||||
normalBandwidth.setHardwareSn(deviceSn);
|
||||
normalBandwidth.setClientId(clientId);
|
||||
normalBandwidth.setCalculationMode(calculationMode);
|
||||
normalBandwidth.setNodeName(serverConfig.getNodeName());
|
||||
normalBandwidth.setStartTime(epsNodeBandwidth.getStartTime());
|
||||
normalBandwidth.setEndTime(epsNodeBandwidth.getEndTime());
|
||||
normalBandwidth.setBusinessId(serverConfig.getBusinessCode());
|
||||
normalBandwidth.setBusinessName(serverConfig.getBusinessName());
|
||||
normalBandwidth.setBusinessId(businessCode);
|
||||
normalBandwidth.setBusinessName(businessName);
|
||||
normalBandwidth.setResourceType("1");
|
||||
epsNodeBandwidthService.calculateAvg(normalBandwidth);
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("处理服务器 {} 平均带宽失败", deviceSn, e);
|
||||
log.error("处理服务器 {} 平均带宽失败", clientId, e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -285,48 +303,30 @@ public class TableScheduleConfig {
|
||||
* 处理单个交换机的平均带宽计算
|
||||
*/
|
||||
private void processSwitchAvgBandwidth(EpsNodeBandwidth epsNodeBandwidth, AllInterfaceName switchSnMsg, String calculationMode) {
|
||||
final String switchSn = switchSnMsg.getSwitchSn();
|
||||
final String clientId = switchSnMsg.getClientId();
|
||||
|
||||
try {
|
||||
// 1. 查询交换机拓扑信息
|
||||
RmEpsTopologyManagement managementQuery = new RmEpsTopologyManagement();
|
||||
managementQuery.setSwitchSn(switchSn);
|
||||
managementQuery.setClientId(clientId);
|
||||
List<RmEpsTopologyManagement> topologyList = rmEpsTopologyManagementService.selectRmEpsTopologyManagementList(managementQuery);
|
||||
|
||||
// 2. 设置基础信息
|
||||
RmEpsTopologyManagement topology = topologyList.isEmpty() ? new RmEpsTopologyManagement() : topologyList.get(0);
|
||||
epsNodeBandwidth.setSwitchSn(switchSn);
|
||||
if(!topologyList.isEmpty()){
|
||||
for (RmEpsTopologyManagement topology : topologyList) {
|
||||
epsNodeBandwidth.setClientId(clientId);
|
||||
epsNodeBandwidth.setInterfaceName(topology.getInterfaceName());
|
||||
|
||||
// 3. 判断连接设备类型
|
||||
boolean isServerConnected = "1".equals(topology.getConnectedDeviceType());
|
||||
|
||||
// 4. 处理服务器连接的情况
|
||||
if (isServerConnected && topology.getServerSn() != null) {
|
||||
if (isServerConnected && topology.getServerClientId() != null) {
|
||||
String serverClientId = topology.getServerClientId();
|
||||
String serverSn = topology.getServerSn();
|
||||
epsNodeBandwidth.setHardwareSn(serverSn);
|
||||
// 查询服务器配置
|
||||
EpsServerRevenueConfig queryConfig = new EpsServerRevenueConfig();
|
||||
queryConfig.setHardwareSn(serverSn);
|
||||
List<EpsServerRevenueConfig> configList = epsServerRevenueConfigService.selectEpsServerRevenueConfigList(queryConfig);
|
||||
EpsServerRevenueConfig serverConfig = configList.isEmpty() ? new EpsServerRevenueConfig() : configList.get(0);
|
||||
epsNodeBandwidth.setNodeName(serverConfig.getNodeName());
|
||||
|
||||
// 检查是否需要处理业务变更
|
||||
boolean shouldProcessChange = serverConfig.getUpdateTime() != null
|
||||
&& epsNodeBandwidth.getStartTime() != null
|
||||
&& epsNodeBandwidth.getStartTime().length() >= 10
|
||||
&& "1".equals(serverConfig.getChanged())
|
||||
&& DateUtils.parseDateToStr("yyyy-MM", serverConfig.getUpdateTime())
|
||||
.equals(epsNodeBandwidth.getStartTime().substring(0, 7));
|
||||
|
||||
if(shouldProcessChange){
|
||||
// 查询业务变更记录
|
||||
EpsMethodChangeRecord changeQuery = new EpsMethodChangeRecord();
|
||||
changeQuery.setHardwareSn(serverSn);
|
||||
changeQuery.setClientId(serverClientId);
|
||||
changeQuery.setStartTime(epsNodeBandwidth.getStartTime());
|
||||
changeQuery.setEndTime(epsNodeBandwidth.getEndTime());
|
||||
|
||||
List<EpsMethodChangeRecord> records = epsMethodChangeRecordService.selectEpsMethodChangeRecordList(changeQuery);
|
||||
|
||||
// 按businessCode分组处理
|
||||
@@ -349,11 +349,10 @@ public class TableScheduleConfig {
|
||||
|
||||
// 创建业务带宽对象
|
||||
EpsNodeBandwidth bandwidthWithBiz = new EpsNodeBandwidth();
|
||||
bandwidthWithBiz.setSwitchSn(switchSn);
|
||||
bandwidthWithBiz.setClientId(clientId);
|
||||
bandwidthWithBiz.setCalculationMode(calculationMode);
|
||||
bandwidthWithBiz.setInterfaceName(topology.getInterfaceName());
|
||||
bandwidthWithBiz.setHardwareSn(serverSn);
|
||||
bandwidthWithBiz.setNodeName(topology.getServerName());
|
||||
bandwidthWithBiz.setUplinkSwitch(topology.getSwitchName());
|
||||
bandwidthWithBiz.setInterfaceLinkDeviceType(topology.getConnectedDeviceType());
|
||||
bandwidthWithBiz.setStartTime(epsNodeBandwidth.getStartTime());
|
||||
@@ -361,7 +360,7 @@ public class TableScheduleConfig {
|
||||
bandwidthWithBiz.setBusinessId(businessCode);
|
||||
bandwidthWithBiz.setBusinessName(businessName);
|
||||
bandwidthWithBiz.setResourceType("2");
|
||||
|
||||
bandwidthWithBiz.setServerClientId(serverClientId);
|
||||
// 执行计算
|
||||
epsNodeBandwidthService.calculateAvg(bandwidthWithBiz);
|
||||
}
|
||||
@@ -372,34 +371,47 @@ public class TableScheduleConfig {
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (!nullBusinessRecords.isEmpty()) {
|
||||
log.warn("交换机 {} 有 {} 条记录的businessCode为null", switchSn, nullBusinessRecords.size());
|
||||
log.warn("交换机 {} 有 {} 条记录的businessCode为null", clientId, nullBusinessRecords.size());
|
||||
// 可以选择记录日志或进行其他处理
|
||||
}
|
||||
|
||||
return; // 业务变更处理完成后直接返回
|
||||
}
|
||||
}else{
|
||||
String businessCode = null;
|
||||
String businessName = null;
|
||||
// 查询绑定的业务
|
||||
EpsMethodChangeRecord queryParam = new EpsMethodChangeRecord();
|
||||
queryParam.setClientId(clientId);
|
||||
queryParam.setTrafficPort(topology.getServerPort());
|
||||
List<EpsMethodChangeRecord> recordList = epsMethodChangeRecordService.selectEpsMethodChangeRecordList(queryParam);
|
||||
if(!recordList.isEmpty()){
|
||||
EpsMethodChangeRecord record = recordList.stream()
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
businessCode = record.getBusinessCode();
|
||||
businessName = record.getBusinessName();
|
||||
}
|
||||
// 5. 处理普通情况(无变更记录)
|
||||
EpsNodeBandwidth normalBandwidth = new EpsNodeBandwidth();
|
||||
normalBandwidth.setSwitchSn(switchSn);
|
||||
normalBandwidth.setClientId(clientId);
|
||||
normalBandwidth.setBusinessId(businessCode);
|
||||
normalBandwidth.setBusinessName(businessName);
|
||||
normalBandwidth.setCalculationMode(calculationMode);
|
||||
normalBandwidth.setInterfaceName(topology.getInterfaceName());
|
||||
normalBandwidth.setHardwareSn(topology.getServerSn());
|
||||
normalBandwidth.setNodeName(topology.getServerName());
|
||||
normalBandwidth.setUplinkSwitch(topology.getSwitchName());
|
||||
normalBandwidth.setInterfaceLinkDeviceType(topology.getConnectedDeviceType());
|
||||
normalBandwidth.setStartTime(epsNodeBandwidth.getStartTime());
|
||||
normalBandwidth.setEndTime(epsNodeBandwidth.getEndTime());
|
||||
normalBandwidth.setBusinessId(serverConfig.getBusinessCode());
|
||||
normalBandwidth.setBusinessName(serverConfig.getBusinessName());
|
||||
normalBandwidth.setResourceType("2");
|
||||
normalBandwidth.setServerClientId(serverClientId);
|
||||
epsNodeBandwidthService.calculateAvg(normalBandwidth);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// 5. 处理机房出口情况
|
||||
EpsNodeBandwidth normalBandwidth = new EpsNodeBandwidth();
|
||||
normalBandwidth.setSwitchSn(switchSn);
|
||||
normalBandwidth.setClientId(clientId);
|
||||
normalBandwidth.setCalculationMode(calculationMode);
|
||||
normalBandwidth.setInterfaceName(topology.getInterfaceName());
|
||||
normalBandwidth.setInterfaceLinkDeviceType(topology.getConnectedDeviceType());
|
||||
@@ -407,9 +419,12 @@ public class TableScheduleConfig {
|
||||
normalBandwidth.setEndTime(epsNodeBandwidth.getEndTime());
|
||||
normalBandwidth.setResourceType("2");
|
||||
epsNodeBandwidthService.calculateAvg(normalBandwidth);
|
||||
|
||||
}
|
||||
}else{
|
||||
log.warn("未检测到拓扑配置,交换机clientId:{}", clientId);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("处理交换机 {} 平均带宽失败", switchSn, e);
|
||||
log.error("处理交换机 {} 平均带宽失败", clientId, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
package com.ruoyi.system.controller;
|
||||
|
||||
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.core.web.page.PageDomain;
|
||||
import com.ruoyi.common.core.web.page.TableDataInfo;
|
||||
import com.ruoyi.common.log.annotation.Log;
|
||||
import com.ruoyi.common.log.enums.BusinessType;
|
||||
import com.ruoyi.common.security.annotation.RequiresPermissions;
|
||||
import com.ruoyi.system.domain.EpsBusinessDeploy;
|
||||
import com.ruoyi.system.service.IEpsBusinessDeployService;
|
||||
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-13
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/businessDeploy")
|
||||
public class EpsBusinessDeployController extends BaseController
|
||||
{
|
||||
@Autowired
|
||||
private IEpsBusinessDeployService epsBusinessDeployService;
|
||||
|
||||
/**
|
||||
* 查询业务下发管理列表
|
||||
*/
|
||||
@RequiresPermissions("system:businessDeploy:list")
|
||||
@PostMapping("/list")
|
||||
public TableDataInfo list(@RequestBody EpsBusinessDeploy epsBusinessDeploy)
|
||||
{
|
||||
PageDomain pageDomain = new PageDomain();
|
||||
pageDomain.setPageNum(epsBusinessDeploy.getPageNum());
|
||||
pageDomain.setPageSize(epsBusinessDeploy.getPageSize());
|
||||
startPage(pageDomain);
|
||||
List<EpsBusinessDeploy> list = epsBusinessDeployService.selectEpsBusinessDeployList(epsBusinessDeploy);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出
|
||||
* @param response
|
||||
* @param epsBusinessDeploy
|
||||
*/
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, @RequestBody EpsBusinessDeploy epsBusinessDeploy)
|
||||
{
|
||||
List<EpsBusinessDeploy> list = epsBusinessDeployService.selectEpsBusinessDeployList(epsBusinessDeploy);
|
||||
ExcelUtil<EpsBusinessDeploy> util = new ExcelUtil<EpsBusinessDeploy>(EpsBusinessDeploy.class);
|
||||
util.showColumn(epsBusinessDeploy.getProperties());
|
||||
util.exportExcel(response, list, "业务下发管理");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取业务下发管理详细信息
|
||||
*/
|
||||
@RequiresPermissions("system:businessDeploy:query")
|
||||
@GetMapping(value = "/{id}")
|
||||
public AjaxResult getInfo(@PathVariable("id") Long id)
|
||||
{
|
||||
return success(epsBusinessDeployService.selectEpsBusinessDeployById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增业务下发管理
|
||||
*/
|
||||
@RequiresPermissions("system:businessDeploy:add")
|
||||
@Log(title = "业务下发管理", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public AjaxResult add(@RequestBody EpsBusinessDeploy epsBusinessDeploy)
|
||||
{
|
||||
return toAjax(epsBusinessDeployService.insertEpsBusinessDeploy(epsBusinessDeploy));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改业务下发管理
|
||||
*/
|
||||
@RequiresPermissions("system:businessDeploy:edit")
|
||||
@Log(title = "业务下发管理", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public AjaxResult edit(@RequestBody EpsBusinessDeploy epsBusinessDeploy)
|
||||
{
|
||||
return toAjax(epsBusinessDeployService.updateEpsBusinessDeploy(epsBusinessDeploy));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除业务下发管理
|
||||
*/
|
||||
@RequiresPermissions("system:businessDeploy:remove")
|
||||
@Log(title = "业务下发管理", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{ids}")
|
||||
public AjaxResult remove(@PathVariable Long[] ids)
|
||||
{
|
||||
return toAjax(epsBusinessDeployService.deleteEpsBusinessDeployByIds(ids));
|
||||
}
|
||||
|
||||
/**
|
||||
* 审核
|
||||
* @param epsBusinessDeploy
|
||||
* @return
|
||||
*/
|
||||
@RequiresPermissions("system:businessDeploy:review")
|
||||
@PostMapping("/reviewBusiness")
|
||||
public AjaxResult reviewBusiness(@RequestBody EpsBusinessDeploy epsBusinessDeploy){
|
||||
return toAjax(epsBusinessDeployService.reviewBusiness(epsBusinessDeploy));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
package com.ruoyi.system.controller;
|
||||
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import com.ruoyi.common.core.web.controller.BaseController;
|
||||
import com.ruoyi.common.core.web.domain.AjaxResult;
|
||||
import com.ruoyi.common.core.web.page.PageDomain;
|
||||
import com.ruoyi.common.core.web.page.TableDataInfo;
|
||||
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.system.domain.EpsBusinessScript;
|
||||
import com.ruoyi.system.service.IEpsBusinessScriptService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 业务脚本管理Controller
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-10-13
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/businessScript")
|
||||
public class EpsBusinessScriptController extends BaseController
|
||||
{
|
||||
@Autowired
|
||||
private IEpsBusinessScriptService epsBusinessScriptService;
|
||||
|
||||
/**
|
||||
* 查询业务脚本管理列表
|
||||
*/
|
||||
@RequiresPermissions("system:businessScript:list")
|
||||
@PostMapping("/list")
|
||||
public TableDataInfo list(@RequestBody EpsBusinessScript epsBusinessScript)
|
||||
{
|
||||
PageDomain pageDomain = new PageDomain();
|
||||
pageDomain.setPageNum(epsBusinessScript.getPageNum());
|
||||
pageDomain.setPageSize(epsBusinessScript.getPageSize());
|
||||
startPage(pageDomain);
|
||||
List<EpsBusinessScript> list = epsBusinessScriptService.selectEpsBusinessScriptList(epsBusinessScript);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取业务脚本管理详细信息
|
||||
*/
|
||||
@RequiresPermissions("system:businessScript:query")
|
||||
@GetMapping(value = "/{id}")
|
||||
public AjaxResult getInfo(@PathVariable("id") Long id)
|
||||
{
|
||||
return success(epsBusinessScriptService.selectEpsBusinessScriptById(id));
|
||||
}
|
||||
/**
|
||||
* 获取业务脚本管理详细信息
|
||||
*/
|
||||
@GetMapping(value = "/inner/{id}")
|
||||
@InnerAuth
|
||||
public R<EpsBusinessScript> innerGetInfo(@PathVariable("id") Long id)
|
||||
{
|
||||
return R.ok(epsBusinessScriptService.selectEpsBusinessScriptById(id));
|
||||
}
|
||||
/**
|
||||
* 新增业务脚本管理
|
||||
*/
|
||||
@RequiresPermissions("system:businessScript:add")
|
||||
@Log(title = "业务脚本管理", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public AjaxResult add(@RequestBody EpsBusinessScript epsBusinessScript)
|
||||
{
|
||||
return toAjax(epsBusinessScriptService.insertEpsBusinessScript(epsBusinessScript));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改业务脚本管理
|
||||
*/
|
||||
@RequiresPermissions("system:businessScript:edit")
|
||||
@Log(title = "业务脚本管理", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public AjaxResult edit(@RequestBody EpsBusinessScript epsBusinessScript)
|
||||
{
|
||||
return toAjax(epsBusinessScriptService.updateEpsBusinessScript(epsBusinessScript));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除业务脚本管理
|
||||
*/
|
||||
@RequiresPermissions("system:businessScript:remove")
|
||||
@Log(title = "业务脚本管理", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{ids}")
|
||||
public AjaxResult remove(@PathVariable Long[] ids)
|
||||
{
|
||||
return toAjax(epsBusinessScriptService.deleteEpsBusinessScriptByIds(ids));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有业务脚本名称
|
||||
* @return
|
||||
*/
|
||||
@RequiresPermissions("system:businessScript:list")
|
||||
@GetMapping("/getAllScriptName")
|
||||
public AjaxResult getAllScriptName(){
|
||||
List<EpsBusinessScript> list = epsBusinessScriptService.selectEpsBusinessScriptList(new EpsBusinessScript());
|
||||
return success(list);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.ruoyi.system.controller;
|
||||
|
||||
import com.ruoyi.common.core.web.domain.AjaxResult;
|
||||
import com.ruoyi.common.security.annotation.RequiresPermissions;
|
||||
import com.ruoyi.system.domain.EpsInitialTrafficData;
|
||||
import com.ruoyi.system.service.EpsInitialTrafficDataService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -10,13 +12,16 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.ruoyi.common.core.web.domain.AjaxResult.success;
|
||||
|
||||
/**
|
||||
* EPS初始流量数据控制器
|
||||
* 提供流量数据的REST接口
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/eps-traffic-data")
|
||||
@RequestMapping("/epsTrafficData")
|
||||
@RequiredArgsConstructor
|
||||
public class EpsInitialTrafficDataController {
|
||||
|
||||
@@ -53,4 +58,35 @@ public class EpsInitialTrafficDataController {
|
||||
List<EpsInitialTrafficData> result = epsInitialTrafficDataService.query(queryParam);
|
||||
return ResponseEntity.ok(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 图形分析 - 95值/日
|
||||
* @return
|
||||
*/
|
||||
@RequiresPermissions("system:bandwidth:list")
|
||||
@PostMapping("/getServerGraphicalAnalysisDaily")
|
||||
public AjaxResult getServerGraphicalAnalysisDaily(@RequestBody EpsInitialTrafficData queryParam){
|
||||
List<Map<String, Object>> echartsData = epsInitialTrafficDataService.getServerGraphicalAnalysisDaily(queryParam);
|
||||
return success(echartsData);
|
||||
}
|
||||
/**
|
||||
* 图形分析 - 95值/日
|
||||
* @return
|
||||
*/
|
||||
@RequiresPermissions("system:bandwidth:list")
|
||||
@PostMapping("/getServerGraphicalAnalysisMonthy")
|
||||
public AjaxResult getServerGraphicalAnalysisMonthy(@RequestBody EpsInitialTrafficData queryParam){
|
||||
List<Map<String, Object>> echartsData = epsInitialTrafficDataService.getServerGraphicalAnalysisMonthy(queryParam);
|
||||
return success(echartsData);
|
||||
}
|
||||
/**
|
||||
* 监控看板-详情视图 出入流量
|
||||
*/
|
||||
// @RequiresPermissions("system:bandwidth:list")
|
||||
// @PostMapping("/getServerTrafficByMonitorView")
|
||||
// public AjaxResult getServerTrafficByMonitorView(@RequestBody EpsInitialTrafficData queryParam)
|
||||
// {
|
||||
// Map<String, Object> echartsData = epsInitialTrafficDataService.getServerTrafficByMonitorView(queryParam);
|
||||
// return success(echartsData);
|
||||
// }
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.ruoyi.system.controller;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import com.ruoyi.common.core.exception.ServiceException;
|
||||
import com.ruoyi.common.core.utils.DateUtils;
|
||||
import com.ruoyi.common.core.utils.poi.ExcelUtil;
|
||||
@@ -10,6 +11,7 @@ import com.ruoyi.common.core.web.page.PageDomain;
|
||||
import com.ruoyi.common.core.web.page.TableDataInfo;
|
||||
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.system.domain.EpsInitialTrafficData;
|
||||
import com.ruoyi.system.domain.EpsNodeBandwidth;
|
||||
@@ -154,16 +156,13 @@ public class EpsNodeBandwidthController extends BaseController
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 相关数据
|
||||
*/
|
||||
@RequiresPermissions("system:bandwidth:query")
|
||||
@GetMapping(value = "relatedData/traffic")
|
||||
/**
|
||||
* 根据ID获取相关数据
|
||||
* @param id 资源ID
|
||||
* @return 表格数据信息
|
||||
*/
|
||||
@RequiresPermissions("system:bandwidth:query")
|
||||
@GetMapping(value = "relatedData/traffic")
|
||||
public TableDataInfo relatedData(Long id,Integer pageNum,Integer pageSize) {
|
||||
// 1. 参数校验
|
||||
if (id == null || id <= 0) {
|
||||
@@ -319,4 +318,32 @@ public class EpsNodeBandwidthController extends BaseController
|
||||
List<Map> list = epsNodeBandwidthService.graphicalAnalysis(epsNodeBandwidth, "7", ChronoUnit.MONTHS);
|
||||
return success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询节点带宽信息列表
|
||||
*/
|
||||
@PostMapping("/getEpsNodeBandWidthList")
|
||||
@InnerAuth
|
||||
public R<List<EpsNodeBandwidth>> getEpsNodeBandWidthList(@RequestBody EpsNodeBandwidth epsNodeBandwidth)
|
||||
{
|
||||
List<EpsNodeBandwidth> list = epsNodeBandwidthService.selectEpsNodeBandwidthList(epsNodeBandwidth);
|
||||
return R.ok(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 监控看板-详情视图 95值列表
|
||||
* @param epsNodeBandwidth
|
||||
* @return
|
||||
*/
|
||||
@RequiresPermissions("system:bandwidth:list")
|
||||
@PostMapping("/getListByMonitorView")
|
||||
public TableDataInfo getListByMonitorView(@RequestBody EpsNodeBandwidth epsNodeBandwidth)
|
||||
{
|
||||
PageDomain pageDomain = new PageDomain();
|
||||
pageDomain.setPageNum(epsNodeBandwidth.getPageNum());
|
||||
pageDomain.setPageSize(epsNodeBandwidth.getPageSize());
|
||||
startPage(pageDomain);
|
||||
List<EpsNodeBandwidth> list = epsNodeBandwidthService.getListByMonitorView(epsNodeBandwidth);
|
||||
return getDataTable(list);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,160 @@
|
||||
package com.ruoyi.system.controller;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
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.core.web.page.PageDomain;
|
||||
import com.ruoyi.common.core.web.page.TableDataInfo;
|
||||
import com.ruoyi.common.log.annotation.Log;
|
||||
import com.ruoyi.common.log.enums.BusinessType;
|
||||
import com.ruoyi.common.security.annotation.RequiresPermissions;
|
||||
import com.ruoyi.system.domain.EpsTaskStatistics;
|
||||
import com.ruoyi.system.service.IEpsTaskStatisticsService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 业务95值计算任务Controller
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-10-29
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/taskStatistics")
|
||||
public class EpsTaskStatisticsController extends BaseController
|
||||
{
|
||||
@Autowired
|
||||
private IEpsTaskStatisticsService epsTaskStatisticsService;
|
||||
|
||||
/**
|
||||
* 查询业务95值计算任务列表
|
||||
*/
|
||||
@RequiresPermissions("system:taskStatistics:list")
|
||||
@PostMapping("/list")
|
||||
public TableDataInfo list(@RequestBody EpsTaskStatistics epsTaskStatistics)
|
||||
{
|
||||
PageDomain pageDomain = new PageDomain();
|
||||
pageDomain.setPageNum(epsTaskStatistics.getPageNum());
|
||||
pageDomain.setPageSize(epsTaskStatistics.getPageSize());
|
||||
startPage(pageDomain);
|
||||
List<EpsTaskStatistics> list = epsTaskStatisticsService.selectEpsTaskStatisticsList(epsTaskStatistics);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出业务95值计算任务列表
|
||||
*/
|
||||
@RequiresPermissions("system:taskStatistics:export")
|
||||
@Log(title = "业务95值计算任务", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, @RequestBody EpsTaskStatistics epsTaskStatistics)
|
||||
{
|
||||
List<EpsTaskStatistics> list = epsTaskStatisticsService.selectEpsTaskStatisticsList(epsTaskStatistics);
|
||||
ExcelUtil<EpsTaskStatistics> util = new ExcelUtil<EpsTaskStatistics>(EpsTaskStatistics.class);
|
||||
util.showColumn(epsTaskStatistics.getProperties());
|
||||
util.exportExcel(response, list, "业务95值计算任务数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取业务95值计算任务详细信息
|
||||
*/
|
||||
@RequiresPermissions("system:taskStatistics:query")
|
||||
@GetMapping(value = "/{id}")
|
||||
public AjaxResult getInfo(@PathVariable("id") Long id)
|
||||
{
|
||||
return success(epsTaskStatisticsService.selectEpsTaskStatisticsById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增业务95值计算任务
|
||||
*/
|
||||
@RequiresPermissions("system:taskStatistics:add")
|
||||
@Log(title = "业务95值计算任务", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public AjaxResult add(@RequestBody EpsTaskStatistics epsTaskStatistics)
|
||||
{
|
||||
return toAjax(epsTaskStatisticsService.insertEpsTaskStatistics(epsTaskStatistics));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改业务95值计算任务
|
||||
*/
|
||||
@RequiresPermissions("system:taskStatistics:edit")
|
||||
@Log(title = "业务95值计算任务", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public AjaxResult edit(@RequestBody EpsTaskStatistics epsTaskStatistics)
|
||||
{
|
||||
return toAjax(epsTaskStatisticsService.updateEpsTaskStatistics(epsTaskStatistics));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除业务95值计算任务
|
||||
*/
|
||||
@RequiresPermissions("system:taskStatistics:remove")
|
||||
@Log(title = "业务95值计算任务", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{ids}")
|
||||
public AjaxResult remove(@PathVariable Long[] ids)
|
||||
{
|
||||
return toAjax(epsTaskStatisticsService.deleteEpsTaskStatisticsByIds(ids));
|
||||
}
|
||||
/**
|
||||
* 相关数据查询
|
||||
*/
|
||||
@RequiresPermissions("system:taskStatistics:list")
|
||||
@PostMapping("/getRelateData")
|
||||
public TableDataInfo getRelateData(@RequestBody EpsTaskStatistics epsTaskStatistics)
|
||||
{
|
||||
PageInfo<?> list = epsTaskStatisticsService.getRelateData(epsTaskStatistics);
|
||||
return getDataTable(list.getList(), list.getTotal());
|
||||
}
|
||||
/**
|
||||
* 修改相关数据
|
||||
* @param epsTaskStatistics
|
||||
* @return
|
||||
*/
|
||||
@RequiresPermissions("system:taskStatistics:edit")
|
||||
@PostMapping("/updateRelateData")
|
||||
public AjaxResult updateRelateData(@RequestBody EpsTaskStatistics epsTaskStatistics)
|
||||
{
|
||||
int rows = epsTaskStatisticsService.updateRelateData(epsTaskStatistics);
|
||||
return toAjax(rows);
|
||||
}
|
||||
/**
|
||||
* 重新计算
|
||||
*/
|
||||
@RequiresPermissions("system:taskStatistics:list")
|
||||
@PostMapping("/recaculate")
|
||||
public AjaxResult recaculate(@RequestBody EpsTaskStatistics epsTaskStatistics)
|
||||
{
|
||||
int rows = epsTaskStatisticsService.recaculate(epsTaskStatistics);
|
||||
return toAjax(rows);
|
||||
}
|
||||
/**
|
||||
* 图形查看
|
||||
*/
|
||||
@RequiresPermissions("system:taskStatistics:list")
|
||||
@PostMapping("/getRraphicalMsg")
|
||||
public AjaxResult getRraphicalMsg(@RequestBody EpsTaskStatistics epsTaskStatistics)
|
||||
{
|
||||
Map echartsMap = epsTaskStatisticsService.getRraphicalMsg(epsTaskStatistics);
|
||||
return success(echartsMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取月均日95值的日列表
|
||||
* @param epsTaskStatistics
|
||||
* @return
|
||||
*/
|
||||
@RequiresPermissions("system:taskStatistics:list")
|
||||
@PostMapping("/getAvgTimeList")
|
||||
public AjaxResult getAvgTimeList(@RequestBody EpsTaskStatistics epsTaskStatistics)
|
||||
{
|
||||
List<String> avgTimeList = epsTaskStatisticsService.getAvgTimeList(epsTaskStatistics);
|
||||
return success(avgTimeList);
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 交换机监控信息Controller
|
||||
@@ -105,4 +106,45 @@ public class InitialSwitchInfoDetailsController extends BaseController
|
||||
{
|
||||
return initialSwitchInfoDetailsService.autoSaveSwitchTraffic(initialSwitchInfoDetails);
|
||||
}
|
||||
/**
|
||||
* 图形分析-95带宽值mbps/日 v1.1
|
||||
*/
|
||||
@RequiresPermissions("system:bandwidth:list")
|
||||
@PostMapping("/getGraphicalAnalysisDaily")
|
||||
public AjaxResult getGraphicalAnalysisDaily(@RequestBody InitialSwitchInfoDetails initialSwitchInfoDetails)
|
||||
{
|
||||
List<Map<String, Object>> echartsData = initialSwitchInfoDetailsService.getGraphicalAnalysisDaily(initialSwitchInfoDetails);
|
||||
return success(echartsData);
|
||||
}
|
||||
/**
|
||||
* 图形分析-95带宽值mbps/月 v1.1
|
||||
*/
|
||||
@RequiresPermissions("system:bandwidth:list")
|
||||
@PostMapping("/getGraphicalAnalysisMonthy")
|
||||
public AjaxResult getGraphicalAnalysisMonthy(@RequestBody InitialSwitchInfoDetails initialSwitchInfoDetails)
|
||||
{
|
||||
List<Map<String, Object>> echartsData = initialSwitchInfoDetailsService.getGraphicalAnalysisMonthy(initialSwitchInfoDetails);
|
||||
return success(echartsData);
|
||||
}
|
||||
|
||||
/**
|
||||
* 监控看板-详情视图 出入流量
|
||||
*/
|
||||
// @RequiresPermissions("system:bandwidth:list")
|
||||
// @PostMapping("/getSwitchTrafficByMonitorView")
|
||||
// public AjaxResult getSwitchTrafficByMonitorView(@RequestBody InitialSwitchInfoDetails initialSwitchInfoDetails)
|
||||
// {
|
||||
// Map<String, Object> echartsData = initialSwitchInfoDetailsService.getMonitorViewDetails(initialSwitchInfoDetails);
|
||||
// return success(echartsData);
|
||||
// }
|
||||
/**
|
||||
* 监控看板-详情视图 出入流量列表
|
||||
*/
|
||||
@RequiresPermissions("system:bandwidth:list")
|
||||
@PostMapping("/geSwitchListByMonitorView")
|
||||
public TableDataInfo geSwitchListByMonitorView(@RequestBody InitialSwitchInfoDetails initialSwitchInfoDetails)
|
||||
{
|
||||
List<InitialSwitchInfoDetails> list = initialSwitchInfoDetailsService.geSwitchListByMonitorView(initialSwitchInfoDetails);
|
||||
return getDataTable(list);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
package com.ruoyi.system.controller;
|
||||
|
||||
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.RequiresPermissions;
|
||||
import com.ruoyi.system.domain.RmMonitorConfig;
|
||||
import com.ruoyi.system.service.IRmMonitorConfigService;
|
||||
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-11-12
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/monitorConfig")
|
||||
public class RmMonitorConfigController extends BaseController
|
||||
{
|
||||
@Autowired
|
||||
private IRmMonitorConfigService rmMonitorConfigService;
|
||||
|
||||
/**
|
||||
* 查询监控配置列表
|
||||
*/
|
||||
@RequiresPermissions("system:monitorConfig:list")
|
||||
@PostMapping("/list")
|
||||
public AjaxResult list(@RequestBody RmMonitorConfig rmMonitorConfig)
|
||||
{
|
||||
List<RmMonitorConfig> list = rmMonitorConfigService.selectRmMonitorConfigList(rmMonitorConfig);
|
||||
return success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出监控配置列表
|
||||
*/
|
||||
@RequiresPermissions("system:monitorConfig:export")
|
||||
@Log(title = "监控配置", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, RmMonitorConfig rmMonitorConfig)
|
||||
{
|
||||
List<RmMonitorConfig> list = rmMonitorConfigService.selectRmMonitorConfigList(rmMonitorConfig);
|
||||
ExcelUtil<RmMonitorConfig> util = new ExcelUtil<RmMonitorConfig>(RmMonitorConfig.class);
|
||||
util.exportExcel(response, list, "监控配置数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取监控配置详细信息
|
||||
*/
|
||||
@RequiresPermissions("system:monitorConfig:query")
|
||||
@GetMapping(value = "/{id}")
|
||||
public AjaxResult getInfo(@PathVariable("id") Long id)
|
||||
{
|
||||
return success(rmMonitorConfigService.selectRmMonitorConfigById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增监控配置
|
||||
*/
|
||||
@RequiresPermissions("system:monitorConfig:add")
|
||||
@Log(title = "监控配置", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public AjaxResult add(@RequestBody RmMonitorConfig rmMonitorConfig)
|
||||
{
|
||||
return toAjax(rmMonitorConfigService.insertRmMonitorConfig(rmMonitorConfig));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改监控配置
|
||||
*/
|
||||
@RequiresPermissions("system:monitorConfig:edit")
|
||||
@Log(title = "监控配置", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public AjaxResult edit(@RequestBody RmMonitorConfig rmMonitorConfig)
|
||||
{
|
||||
return toAjax(rmMonitorConfigService.updateRmMonitorConfig(rmMonitorConfig));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除监控配置
|
||||
*/
|
||||
@RequiresPermissions("system:monitorConfig:remove")
|
||||
@Log(title = "监控配置", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{ids}")
|
||||
public AjaxResult remove(@PathVariable Long[] ids)
|
||||
{
|
||||
return toAjax(rmMonitorConfigService.deleteRmMonitorConfigByIds(ids));
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user