初始化v1.2
This commit is contained in:
+69
@@ -0,0 +1,69 @@
|
||||
package com.tongran.mtragent.service;
|
||||
|
||||
import com.tongran.mtragent.domain.AllMtrClient;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* mtr探测丢包clinetId记录Service接口
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-11-24
|
||||
*/
|
||||
public interface IAllMtrClientService
|
||||
{
|
||||
/**
|
||||
* 查询mtr探测丢包clinetId记录
|
||||
*
|
||||
* @param id mtr探测丢包clinetId记录主键
|
||||
* @return mtr探测丢包clinetId记录
|
||||
*/
|
||||
public AllMtrClient selectAllMtrClientById(Long id);
|
||||
|
||||
/**
|
||||
* 查询mtr探测丢包clinetId记录列表
|
||||
*
|
||||
* @param allMtrClient mtr探测丢包clinetId记录
|
||||
* @return mtr探测丢包clinetId记录集合
|
||||
*/
|
||||
public List<AllMtrClient> selectAllMtrClientList(AllMtrClient allMtrClient);
|
||||
|
||||
/**
|
||||
* 新增mtr探测丢包clinetId记录
|
||||
*
|
||||
* @param allMtrClient mtr探测丢包clinetId记录
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertAllMtrClient(AllMtrClient allMtrClient);
|
||||
|
||||
/**
|
||||
* 修改mtr探测丢包clinetId记录
|
||||
*
|
||||
* @param allMtrClient mtr探测丢包clinetId记录
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateAllMtrClient(AllMtrClient allMtrClient);
|
||||
|
||||
/**
|
||||
* 批量删除mtr探测丢包clinetId记录
|
||||
*
|
||||
* @param ids 需要删除的mtr探测丢包clinetId记录主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteAllMtrClientByIds(Long[] ids);
|
||||
|
||||
/**
|
||||
* 删除mtr探测丢包clinetId记录信息
|
||||
*
|
||||
* @param id mtr探测丢包clinetId记录主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteAllMtrClientById(Long id);
|
||||
|
||||
/**
|
||||
* 批量插入client记录
|
||||
* @param allMtrClientList
|
||||
* @return
|
||||
*/
|
||||
int batchInsertAllMtrClient(List<AllMtrClient> allMtrClientList);
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
package com.tongran.mtragent.service;
|
||||
|
||||
|
||||
import com.tongran.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);
|
||||
}
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
package com.tongran.mtragent.service;
|
||||
|
||||
|
||||
import com.tongran.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);
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
package com.tongran.mtragent.service;
|
||||
|
||||
|
||||
import com.tongran.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);
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
package com.tongran.mtragent.service;
|
||||
|
||||
|
||||
import com.tongran.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);
|
||||
}
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
package com.tongran.mtragent.service;
|
||||
|
||||
import com.tongran.mtragent.domain.AllMtrClient;
|
||||
import com.tongran.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);
|
||||
|
||||
/**
|
||||
* 获取所有标识
|
||||
* @param rmMtrClientRegistration
|
||||
* @return
|
||||
*/
|
||||
List<RmMtrClientRegistration> getAllLogicalNode(RmMtrClientRegistration rmMtrClientRegistration);
|
||||
/**
|
||||
* 根据mtrClientId查询包含的clientId
|
||||
* @param rmMtrClientRegistration
|
||||
* @return clientId列表
|
||||
*/
|
||||
List<AllMtrClient> getClientIdByMtrClientId(RmMtrClientRegistration rmMtrClientRegistration);
|
||||
}
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
package com.tongran.mtragent.service;
|
||||
|
||||
import com.tongran.mtragent.domain.RmMtrPolicyConfig;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
/**
|
||||
* 根据MTR客户端ID获取应该下发的策略列表
|
||||
*
|
||||
* @param mtrClientId MTR客户端ID
|
||||
* @return 策略列表
|
||||
*/
|
||||
List<RmMtrPolicyConfig> getPoliciesForMtrClient(String mtrClientId);
|
||||
}
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
package com.tongran.mtragent.service;
|
||||
|
||||
import com.tongran.mtragent.domain.RmMtrProbeResult;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 网络mtr探测结果Service接口
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-11-20
|
||||
*/
|
||||
public interface IRmMtrProbeResultService
|
||||
{
|
||||
/**
|
||||
* 查询网络mtr探测结果
|
||||
*
|
||||
* @param id 网络mtr探测结果主键
|
||||
* @return 网络mtr探测结果
|
||||
*/
|
||||
public RmMtrProbeResult selectRmMtrProbeResultById(Long id);
|
||||
|
||||
/**
|
||||
* 查询网络mtr探测结果列表
|
||||
*
|
||||
* @param rmMtrProbeResult 网络mtr探测结果
|
||||
* @return 网络mtr探测结果集合
|
||||
*/
|
||||
public List<RmMtrProbeResult> selectRmMtrProbeResultList(RmMtrProbeResult rmMtrProbeResult);
|
||||
|
||||
/**
|
||||
* 新增网络mtr探测结果
|
||||
*
|
||||
* @param rmMtrProbeResult 网络mtr探测结果
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertRmMtrProbeResult(RmMtrProbeResult rmMtrProbeResult);
|
||||
|
||||
/**
|
||||
* 修改网络mtr探测结果
|
||||
*
|
||||
* @param rmMtrProbeResult 网络mtr探测结果
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateRmMtrProbeResult(RmMtrProbeResult rmMtrProbeResult);
|
||||
|
||||
/**
|
||||
* 批量删除网络mtr探测结果
|
||||
*
|
||||
* @param ids 需要删除的网络mtr探测结果主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteRmMtrProbeResultByIds(Long[] ids);
|
||||
|
||||
/**
|
||||
* 删除网络mtr探测结果信息
|
||||
*
|
||||
* @param id 网络mtr探测结果主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteRmMtrProbeResultById(Long id);
|
||||
|
||||
public void batchInsertRmMtrProbeResult(RmMtrProbeResult result);
|
||||
|
||||
/**
|
||||
* 查看丢包率趋势
|
||||
* @param rmMtrProbeResult
|
||||
* @return
|
||||
*/
|
||||
Map<String, Object> getLossRateByMtrClientId(RmMtrProbeResult rmMtrProbeResult);
|
||||
}
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
package com.tongran.mtragent.service;
|
||||
|
||||
|
||||
import com.tongran.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);
|
||||
}
|
||||
+103
@@ -0,0 +1,103 @@
|
||||
package com.tongran.mtragent.service.impl;
|
||||
|
||||
import com.tongran.common.core.utils.DateUtils;
|
||||
import com.tongran.mtragent.domain.AllMtrClient;
|
||||
import com.tongran.mtragent.mapper.AllMtrClientMapper;
|
||||
import com.tongran.mtragent.service.IAllMtrClientService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* mtr探测丢包clinetId记录Service业务层处理
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-11-24
|
||||
*/
|
||||
@Service
|
||||
public class AllMtrClientServiceImpl implements IAllMtrClientService
|
||||
{
|
||||
@Autowired
|
||||
private AllMtrClientMapper allMtrClientMapper;
|
||||
|
||||
/**
|
||||
* 查询mtr探测丢包clinetId记录
|
||||
*
|
||||
* @param id mtr探测丢包clinetId记录主键
|
||||
* @return mtr探测丢包clinetId记录
|
||||
*/
|
||||
@Override
|
||||
public AllMtrClient selectAllMtrClientById(Long id)
|
||||
{
|
||||
return allMtrClientMapper.selectAllMtrClientById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询mtr探测丢包clinetId记录列表
|
||||
*
|
||||
* @param allMtrClient mtr探测丢包clinetId记录
|
||||
* @return mtr探测丢包clinetId记录
|
||||
*/
|
||||
@Override
|
||||
public List<AllMtrClient> selectAllMtrClientList(AllMtrClient allMtrClient)
|
||||
{
|
||||
return allMtrClientMapper.selectAllMtrClientList(allMtrClient);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增mtr探测丢包clinetId记录
|
||||
*
|
||||
* @param allMtrClient mtr探测丢包clinetId记录
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int insertAllMtrClient(AllMtrClient allMtrClient)
|
||||
{
|
||||
allMtrClient.setCreateTime(DateUtils.getNowDate());
|
||||
return allMtrClientMapper.insertAllMtrClient(allMtrClient);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改mtr探测丢包clinetId记录
|
||||
*
|
||||
* @param allMtrClient mtr探测丢包clinetId记录
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int updateAllMtrClient(AllMtrClient allMtrClient)
|
||||
{
|
||||
allMtrClient.setUpdateTime(DateUtils.getNowDate());
|
||||
return allMtrClientMapper.updateAllMtrClient(allMtrClient);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除mtr探测丢包clinetId记录
|
||||
*
|
||||
* @param ids 需要删除的mtr探测丢包clinetId记录主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteAllMtrClientByIds(Long[] ids)
|
||||
{
|
||||
return allMtrClientMapper.deleteAllMtrClientByIds(ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除mtr探测丢包clinetId记录信息
|
||||
*
|
||||
* @param id mtr探测丢包clinetId记录主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteAllMtrClientById(Long id)
|
||||
{
|
||||
return allMtrClientMapper.deleteAllMtrClientById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int batchInsertAllMtrClient(List<AllMtrClient> allMtrClientList) {
|
||||
int rows = allMtrClientMapper.batchInsertAllMtrClient(allMtrClientList);
|
||||
return rows;
|
||||
}
|
||||
}
|
||||
+97
@@ -0,0 +1,97 @@
|
||||
package com.tongran.mtragent.service.impl;
|
||||
|
||||
import com.tongran.common.core.utils.DateUtils;
|
||||
import com.tongran.mtragent.domain.InitialHeartbeatListenLog;
|
||||
import com.tongran.mtragent.mapper.InitialHeartbeatListenLogMapper;
|
||||
import com.tongran.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);
|
||||
}
|
||||
}
|
||||
+202
@@ -0,0 +1,202 @@
|
||||
package com.tongran.mtragent.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.tongran.common.core.constant.SecurityConstants;
|
||||
import com.tongran.common.core.domain.R;
|
||||
import com.tongran.common.core.enums.MsgEnum;
|
||||
import com.tongran.common.core.utils.DateUtils;
|
||||
import com.tongran.mtragent.domain.DeviceMessage;
|
||||
import com.tongran.mtragent.domain.RmAgentManagement;
|
||||
import com.tongran.mtragent.domain.vo.AgentUpdateMsgVo;
|
||||
import com.tongran.mtragent.domain.vo.PolicyTypeVo;
|
||||
import com.tongran.mtragent.domain.vo.PolicyVo;
|
||||
import com.tongran.mtragent.mapper.RmAgentManagementMapper;
|
||||
import com.tongran.mtragent.model.ProducerMode;
|
||||
import com.tongran.mtragent.producer.MessageProducer;
|
||||
import com.tongran.mtragent.service.IRmAgentManagementService;
|
||||
import com.tongran.system.api.RemoteRevenueConfigService;
|
||||
import com.tongran.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+97
@@ -0,0 +1,97 @@
|
||||
package com.tongran.mtragent.service.impl;
|
||||
|
||||
import com.tongran.common.core.utils.DateUtils;
|
||||
import com.tongran.mtragent.domain.RmAlarmLog;
|
||||
import com.tongran.mtragent.mapper.RmAlarmLogMapper;
|
||||
import com.tongran.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);
|
||||
}
|
||||
}
|
||||
+97
@@ -0,0 +1,97 @@
|
||||
package com.tongran.mtragent.service.impl;
|
||||
|
||||
import com.tongran.common.core.utils.DateUtils;
|
||||
import com.tongran.mtragent.domain.RmAlarmPushConfig;
|
||||
import com.tongran.mtragent.mapper.RmAlarmPushConfigMapper;
|
||||
import com.tongran.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);
|
||||
}
|
||||
}
|
||||
+231
@@ -0,0 +1,231 @@
|
||||
package com.tongran.mtragent.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.tongran.common.core.enums.MsgEnum;
|
||||
import com.tongran.common.core.utils.DateUtils;
|
||||
import com.tongran.mtragent.domain.AllMtrClient;
|
||||
import com.tongran.mtragent.domain.DeviceMessage;
|
||||
import com.tongran.mtragent.domain.RmMtrClientRegistration;
|
||||
import com.tongran.mtragent.domain.vo.AgentUpdateMsgVo;
|
||||
import com.tongran.mtragent.domain.vo.PolicyTypeVo;
|
||||
import com.tongran.mtragent.domain.vo.PolicyVo;
|
||||
import com.tongran.mtragent.mapper.AllMtrClientMapper;
|
||||
import com.tongran.mtragent.mapper.RmMtrClientRegistrationMapper;
|
||||
import com.tongran.mtragent.model.ProducerMode;
|
||||
import com.tongran.mtragent.producer.MessageProducer;
|
||||
import com.tongran.mtragent.service.IRmMtrClientRegistrationService;
|
||||
import com.tongran.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 AllMtrClientMapper allMtrClientMapper;
|
||||
@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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<RmMtrClientRegistration> getAllLogicalNode(RmMtrClientRegistration rmMtrClientRegistration) {
|
||||
List<RmMtrClientRegistration> list = rmMtrClientRegistrationMapper.getAllLogicalNode(rmMtrClientRegistration);
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AllMtrClient> getClientIdByMtrClientId(RmMtrClientRegistration rmMtrClientRegistration) {
|
||||
AllMtrClient allMtrClient = new AllMtrClient();
|
||||
allMtrClient.setMtrClientId(rmMtrClientRegistration.getMtrClientId());
|
||||
List<AllMtrClient> allMtrClientList = allMtrClientMapper.selectAllMtrClientList(allMtrClient);
|
||||
return allMtrClientList;
|
||||
}
|
||||
|
||||
}
|
||||
+329
@@ -0,0 +1,329 @@
|
||||
package com.tongran.mtragent.service.impl;
|
||||
|
||||
import com.tongran.common.core.constant.SecurityConstants;
|
||||
import com.tongran.common.core.domain.R;
|
||||
import com.tongran.common.core.utils.DateUtils;
|
||||
import com.tongran.common.core.utils.StringUtils;
|
||||
import com.tongran.common.security.utils.SecurityUtils;
|
||||
import com.tongran.mtragent.domain.RmMtrPolicyConfig;
|
||||
import com.tongran.mtragent.mapper.RmMtrPolicyConfigMapper;
|
||||
import com.tongran.mtragent.service.IRmMtrPolicyConfigService;
|
||||
import com.tongran.system.api.RemoteRocketMqService;
|
||||
import com.tongran.system.api.domain.RmNetworkInterfaceRemote;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 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());
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 辅助方法,给ip集合一一对应赋值
|
||||
* @param mtrPolicyConfig
|
||||
*/
|
||||
public void setServeripToClientId(RmMtrPolicyConfig mtrPolicyConfig){
|
||||
String serverGroupStr = mtrPolicyConfig.getServerGroup();
|
||||
if(serverGroupStr == null){
|
||||
return;
|
||||
}
|
||||
// 使用Set自动去重
|
||||
Set<String> allIpsSet = new HashSet<>();
|
||||
String[] clientIds = serverGroupStr.split("\n");
|
||||
Map<String, List<String>> clientIdToIpsMap = new HashMap<>();
|
||||
for (String clientId : clientIds) {
|
||||
RmNetworkInterfaceRemote query = new RmNetworkInterfaceRemote();
|
||||
query.setClientIds(clientId);
|
||||
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) {
|
||||
List<String> ips = networkList.getData().stream()
|
||||
.map(RmNetworkInterfaceRemote::getPublicIp)
|
||||
.filter(StringUtils::isNotBlank)
|
||||
.collect(Collectors.toList());
|
||||
if (!ips.isEmpty()) {
|
||||
clientIdToIpsMap.put(clientId, ips);
|
||||
allIpsSet.addAll(ips); // 自动去重
|
||||
}
|
||||
clientIdToIpsMap.put(clientId, ips);
|
||||
}
|
||||
// 将Set转换为分号分隔的字符串
|
||||
String allIps = String.join(";", allIpsSet);
|
||||
mtrPolicyConfig.setServeripGroup(allIps);
|
||||
mtrPolicyConfig.setClientIdToIpsMap(clientIdToIpsMap);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 新增mtr探测策略配置
|
||||
*
|
||||
* @param rmMtrPolicyConfig mtr探测策略配置
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int insertRmMtrPolicyConfig(RmMtrPolicyConfig rmMtrPolicyConfig)
|
||||
{
|
||||
rmMtrPolicyConfig.setCreateTime(DateUtils.getNowDate());
|
||||
rmMtrPolicyConfig.setUpdateTime(DateUtils.getNowDate());
|
||||
rmMtrPolicyConfig.setCreateBy(SecurityUtils.getUsername());
|
||||
// 数据表触发器,优先级自增
|
||||
rmMtrPolicyConfig.setPriority(null);
|
||||
// 给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);
|
||||
}
|
||||
/**
|
||||
* 根据MTR客户端ID获取应该下发的策略列表
|
||||
*
|
||||
* @param mtrClientId MTR客户端ID
|
||||
* @return 策略列表
|
||||
*/
|
||||
@Override
|
||||
public List<RmMtrPolicyConfig> getPoliciesForMtrClient(String mtrClientId) {
|
||||
List<RmMtrPolicyConfig> result = new ArrayList<>();
|
||||
if (mtrClientId == null || mtrClientId.trim().isEmpty()) {
|
||||
return result;
|
||||
}
|
||||
|
||||
// 查询所有有效的策略(探测标志为1)
|
||||
RmMtrPolicyConfig query = new RmMtrPolicyConfig();
|
||||
query.setProbeFlag(1L); // 只查询启用探测的策略
|
||||
List<RmMtrPolicyConfig> allPolicies = rmMtrPolicyConfigMapper.selectRmMtrPolicyConfigList(query);
|
||||
|
||||
if (allPolicies == null || allPolicies.isEmpty()) {
|
||||
return result;
|
||||
}
|
||||
|
||||
// 按优先级降序排序(优先级高的在前面)
|
||||
List<RmMtrPolicyConfig> sortedPolicies = allPolicies.stream()
|
||||
.filter(p -> p.getPriority() != null && p.getProbeFlag() != null)
|
||||
.sorted((p1, p2) -> Long.compare(p2.getPriority(), p1.getPriority()))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 构建最终的服务器分配映射
|
||||
Map<String, String> serverAssignment = new HashMap<>();
|
||||
|
||||
// 从高优先级到低优先级处理策略
|
||||
for (RmMtrPolicyConfig policy : sortedPolicies) {
|
||||
List<String> serverIds = getServerIdsFromPolicy(policy);
|
||||
if (serverIds.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 处理每个服务器:只有这个服务器还没有被处理过时,才处理当前策略
|
||||
for (String serverId : serverIds) {
|
||||
if (!serverAssignment.containsKey(serverId)) {
|
||||
if (policy.getProbeFlag() == 1) {
|
||||
// 探测:记录分配给哪个MTR客户端
|
||||
serverAssignment.put(serverId, policy.getMtrClientId());
|
||||
} else {
|
||||
// 不探测:记录为null
|
||||
serverAssignment.put(serverId, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 找出应该由当前请求客户端执行的服务器
|
||||
List<String> assignedServers = new ArrayList<>();
|
||||
for (Map.Entry<String, String> entry : serverAssignment.entrySet()) {
|
||||
String serverId = entry.getKey();
|
||||
String assignedClientId = entry.getValue();
|
||||
|
||||
// 只有当分配给的客户端是当前请求客户端,且不是null(即需要探测)时
|
||||
if (mtrClientId.equals(assignedClientId)) {
|
||||
assignedServers.add(serverId);
|
||||
}
|
||||
}
|
||||
|
||||
// 如果没有服务器分配给当前客户端,返回空列表
|
||||
if (assignedServers.isEmpty()) {
|
||||
return result;
|
||||
}
|
||||
|
||||
// 找出每个服务器最终生效的策略(最高优先级的那个)
|
||||
Map<RmMtrPolicyConfig, List<String>> policyServersMap = new HashMap<>();
|
||||
for (String serverId : assignedServers) {
|
||||
RmMtrPolicyConfig finalPolicy = findFinalPolicyForServer(serverId, sortedPolicies);
|
||||
if (finalPolicy != null) {
|
||||
policyServersMap.computeIfAbsent(finalPolicy, k -> new ArrayList<>()).add(serverId);
|
||||
}
|
||||
}
|
||||
|
||||
// 创建策略副本返回
|
||||
for (Map.Entry<RmMtrPolicyConfig, List<String>> entry : policyServersMap.entrySet()) {
|
||||
RmMtrPolicyConfig newPolicy = createPolicyCopy(entry.getKey(), entry.getValue());
|
||||
setServeripToClientId(newPolicy);
|
||||
result.add(newPolicy);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 找出服务器最终生效的策略(最高优先级的那个)
|
||||
*/
|
||||
private RmMtrPolicyConfig findFinalPolicyForServer(String serverId, List<RmMtrPolicyConfig> sortedPolicies) {
|
||||
for (RmMtrPolicyConfig policy : sortedPolicies) {
|
||||
if (containsServer(policy, serverId)) {
|
||||
return policy;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从策略中提取服务器ID列表
|
||||
*/
|
||||
private List<String> getServerIdsFromPolicy(RmMtrPolicyConfig policy) {
|
||||
List<String> serverIds = new ArrayList<>();
|
||||
if (policy.getServerGroup() != null) {
|
||||
String serverGroup = policy.getServerGroup();
|
||||
String[] ids = serverGroup.split("\n");
|
||||
for (String id : ids) {
|
||||
if (id != null && !id.trim().isEmpty()) {
|
||||
serverIds.add(id.trim());
|
||||
}
|
||||
}
|
||||
}
|
||||
return serverIds;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查策略是否包含指定服务器
|
||||
*/
|
||||
private boolean containsServer(RmMtrPolicyConfig policy, String serverId) {
|
||||
List<String> serverIds = getServerIdsFromPolicy(policy);
|
||||
return serverIds.contains(serverId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建策略副本
|
||||
*/
|
||||
private RmMtrPolicyConfig createPolicyCopy(RmMtrPolicyConfig original, List<String> serverIds) {
|
||||
RmMtrPolicyConfig copy = new RmMtrPolicyConfig();
|
||||
copy.setId(original.getId());
|
||||
copy.setPolicyName(original.getPolicyName());
|
||||
copy.setPriority(original.getPriority());
|
||||
copy.setMtrClientId(original.getMtrClientId());
|
||||
copy.setProbeFlag(original.getProbeFlag());
|
||||
copy.setStartTime(original.getStartTime());
|
||||
copy.setEndTime(original.getEndTime());
|
||||
copy.setProbeFrequency(original.getProbeFrequency());
|
||||
|
||||
// 服务器组用换行符连接
|
||||
copy.setServerGroup(String.join("\n", serverIds));
|
||||
copy.setServeripGroup(original.getServeripGroup());
|
||||
|
||||
copy.setCreateTime(original.getCreateTime());
|
||||
copy.setUpdateTime(original.getUpdateTime());
|
||||
copy.setCreateBy(original.getCreateBy());
|
||||
copy.setUpdateBy(original.getUpdateBy());
|
||||
|
||||
return copy;
|
||||
}
|
||||
}
|
||||
+219
@@ -0,0 +1,219 @@
|
||||
package com.tongran.mtragent.service.impl;
|
||||
|
||||
import com.tongran.common.core.utils.DateUtils;
|
||||
import com.tongran.common.core.utils.EchartsDataUtils;
|
||||
import com.tongran.common.core.utils.TableSubUtil;
|
||||
import com.tongran.mtragent.domain.RmMtrProbeResult;
|
||||
import com.tongran.mtragent.mapper.RmMtrProbeResultMapper;
|
||||
import com.tongran.mtragent.service.IRmMtrProbeResultService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Isolation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 网络mtr探测结果Service业务层处理
|
||||
*
|
||||
* @author gyt
|
||||
* @date 2025-11-20
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class RmMtrProbeResultServiceImpl implements IRmMtrProbeResultService
|
||||
{
|
||||
@Autowired
|
||||
private RmMtrProbeResultMapper rmMtrProbeResultMapper;
|
||||
|
||||
private final static String TABLE_PREFIX = "rm_mtr_probe_result";
|
||||
|
||||
/**
|
||||
* 查询网络mtr探测结果
|
||||
*
|
||||
* @param id 网络mtr探测结果主键
|
||||
* @return 网络mtr探测结果
|
||||
*/
|
||||
@Override
|
||||
public RmMtrProbeResult selectRmMtrProbeResultById(Long id)
|
||||
{
|
||||
return rmMtrProbeResultMapper.selectRmMtrProbeResultById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询网络mtr探测结果列表
|
||||
*
|
||||
* @param rmMtrProbeResult 网络mtr探测结果
|
||||
* @return 网络mtr探测结果
|
||||
*/
|
||||
@Override
|
||||
public List<RmMtrProbeResult> selectRmMtrProbeResultList(RmMtrProbeResult rmMtrProbeResult)
|
||||
{
|
||||
return rmMtrProbeResultMapper.selectRmMtrProbeResultList(rmMtrProbeResult);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增网络mtr探测结果
|
||||
*
|
||||
* @param rmMtrProbeResult 网络mtr探测结果
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int insertRmMtrProbeResult(RmMtrProbeResult rmMtrProbeResult)
|
||||
{
|
||||
Date createTime = rmMtrProbeResult.getCreateTime();
|
||||
String tableName = TableSubUtil.getTableName(createTime, TABLE_PREFIX);
|
||||
return rmMtrProbeResultMapper.insertRmMtrProbeResult(rmMtrProbeResult);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改网络mtr探测结果
|
||||
*
|
||||
* @param rmMtrProbeResult 网络mtr探测结果
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int updateRmMtrProbeResult(RmMtrProbeResult rmMtrProbeResult)
|
||||
{
|
||||
rmMtrProbeResult.setUpdateTime(DateUtils.getNowDate());
|
||||
return rmMtrProbeResultMapper.updateRmMtrProbeResult(rmMtrProbeResult);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除网络mtr探测结果
|
||||
*
|
||||
* @param ids 需要删除的网络mtr探测结果主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteRmMtrProbeResultByIds(Long[] ids)
|
||||
{
|
||||
return rmMtrProbeResultMapper.deleteRmMtrProbeResultByIds(ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除网络mtr探测结果信息
|
||||
*
|
||||
* @param id 网络mtr探测结果主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteRmMtrProbeResultById(Long id)
|
||||
{
|
||||
return rmMtrProbeResultMapper.deleteRmMtrProbeResultById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
|
||||
public void batchInsertRmMtrProbeResult(RmMtrProbeResult rmMtrProbeResult) {
|
||||
if (rmMtrProbeResult == null) {
|
||||
return;
|
||||
}
|
||||
List<RmMtrProbeResult> dataList = rmMtrProbeResult.getList();
|
||||
if (dataList == null || dataList.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 按表名分组批量插入
|
||||
Map<String, List<RmMtrProbeResult>> groupedData = dataList.stream()
|
||||
.map(data -> {
|
||||
try {
|
||||
RmMtrProbeResult processed = new RmMtrProbeResult();
|
||||
BeanUtils.copyProperties(data, processed);
|
||||
if (data.getCreateTime() == null) {
|
||||
processed.setCreateTime(new Date());
|
||||
}
|
||||
if(data.getUpdateTime() == null){
|
||||
processed.setUpdateTime(new Date());
|
||||
}
|
||||
processed.setTableName(TableSubUtil.getTableName(data.getCreateTime(), TABLE_PREFIX));
|
||||
return processed;
|
||||
} catch (Exception e) {
|
||||
log.error("RmMtrProbeResult数据处理失败", e);
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.filter(Objects::nonNull) // 过滤掉处理失败的数据
|
||||
.collect(Collectors.groupingBy(
|
||||
RmMtrProbeResult::getTableName,
|
||||
LinkedHashMap::new, // 保持插入顺序
|
||||
Collectors.toList()));
|
||||
|
||||
groupedData.forEach((tableName, list) -> {
|
||||
try {
|
||||
RmMtrProbeResult batchData = new RmMtrProbeResult();
|
||||
BeanUtils.copyProperties(rmMtrProbeResult, batchData);
|
||||
batchData.setTableName(tableName);
|
||||
batchData.setList(list);
|
||||
rmMtrProbeResultMapper.batchInsertRmMtrProbeResult(batchData);
|
||||
} catch (Exception e) {
|
||||
log.error("表{}插入失败", tableName, e);
|
||||
throw new RuntimeException("批量插入失败", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 分表查询探测结果
|
||||
* @param queryParam
|
||||
* @return
|
||||
*/
|
||||
public List<RmMtrProbeResult> getListByTime(RmMtrProbeResult queryParam){
|
||||
// 获取涉及的表名
|
||||
Set<String> tableNames = TableSubUtil.getExistingTableNamesBetween(
|
||||
queryParam.getStartTime(),
|
||||
queryParam.getEndTime(),
|
||||
TABLE_PREFIX
|
||||
);
|
||||
|
||||
// 并行查询各表
|
||||
return tableNames.parallelStream()
|
||||
.flatMap(tableName -> {
|
||||
RmMtrProbeResult condition = new RmMtrProbeResult();
|
||||
condition.setTableName(tableName);
|
||||
condition.setMtrClientId(queryParam.getMtrClientId());
|
||||
condition.setClientId(queryParam.getClientId());
|
||||
condition.setStartTime(queryParam.getStartTime());
|
||||
condition.setEndTime(queryParam.getEndTime());
|
||||
return rmMtrProbeResultMapper.selectByCondition(condition).stream();
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看丢包率趋势
|
||||
* @param rmMtrProbeResult
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> getLossRateByMtrClientId(RmMtrProbeResult rmMtrProbeResult) {
|
||||
if(rmMtrProbeResult.getStartTime() == null && rmMtrProbeResult.getEndTime() == null){
|
||||
String[] timeRange = DateUtils.getTodayTimeRange();
|
||||
rmMtrProbeResult.setStartTime(timeRange[0]);
|
||||
rmMtrProbeResult.setEndTime(timeRange[1]);
|
||||
}
|
||||
List<RmMtrProbeResult> list = getListByTime(rmMtrProbeResult);
|
||||
if(list == null){
|
||||
list = new ArrayList<>();
|
||||
}
|
||||
try {
|
||||
Map<String, Function<RmMtrProbeResult, ?>> extractors = new LinkedHashMap<>();
|
||||
|
||||
extractors.put("packetLossRate", info ->
|
||||
info != null && info.getPacketLossRate() != null ?
|
||||
info.getPacketLossRate() :
|
||||
0);
|
||||
Map<String, Object> resultMap = EchartsDataUtils.buildEchartsDataAutoPadding(
|
||||
list, RmMtrProbeResult::getCreateTime, extractors, rmMtrProbeResult.getStartTime(), rmMtrProbeResult.getEndTime()
|
||||
);
|
||||
return resultMap;
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+182
@@ -0,0 +1,182 @@
|
||||
package com.tongran.mtragent.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.tongran.common.core.enums.MsgEnum;
|
||||
import com.tongran.common.core.utils.DateUtils;
|
||||
import com.tongran.mtragent.domain.DeviceMessage;
|
||||
import com.tongran.mtragent.domain.RmNetworkInterface;
|
||||
import com.tongran.mtragent.domain.vo.PolicyTypeVo;
|
||||
import com.tongran.mtragent.mapper.RmNetworkInterfaceMapper;
|
||||
import com.tongran.mtragent.model.ProducerMode;
|
||||
import com.tongran.mtragent.producer.MessageProducer;
|
||||
import com.tongran.mtragent.service.IRmNetworkInterfaceService;
|
||||
import com.tongran.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user