相关接口增加ipv4、ipv6出入流量字段。
服务器管理列表新增字段和排序。 优化监控看板流量统计。
This commit is contained in:
+3
@@ -17,6 +17,9 @@ public class NetworkInfo {
|
||||
// IPv4 地址
|
||||
@JsonProperty("ipv4")
|
||||
private String ipv4;
|
||||
// IPv4 地址
|
||||
@JsonProperty("ipv6")
|
||||
private String ipv6;
|
||||
// MAC 地址
|
||||
@JsonProperty("mac")
|
||||
private String mac;
|
||||
|
||||
+2
@@ -44,6 +44,8 @@ public class RmNetworkInterfaceRemote extends BaseEntity {
|
||||
/** IPv4地址 */
|
||||
@Excel(name = "IPv4地址")
|
||||
private String ipv4Address;
|
||||
/** IPv6地址 */
|
||||
private String ipv6Address;
|
||||
|
||||
/** 网关 */
|
||||
@Excel(name = "网关")
|
||||
|
||||
-65
@@ -1,65 +0,0 @@
|
||||
package com.tongran.mtragent.domain;
|
||||
|
||||
import com.tongran.common.core.annotation.Excel;
|
||||
import com.tongran.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;
|
||||
|
||||
}
|
||||
-65
@@ -1,65 +0,0 @@
|
||||
package com.tongran.mtragent.mapper;
|
||||
|
||||
|
||||
import com.tongran.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);
|
||||
}
|
||||
-83
@@ -1,83 +0,0 @@
|
||||
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);
|
||||
}
|
||||
-182
@@ -1,182 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
-148
@@ -1,148 +0,0 @@
|
||||
<?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.tongran.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 client_id = #{clientId}
|
||||
</update>
|
||||
</mapper>
|
||||
+10
@@ -247,5 +247,15 @@ public class RmResourceRegistrationController extends BaseController
|
||||
{
|
||||
return toAjax(rmResourceRegistrationService.updateRemark(rmResourceRegistration));
|
||||
}
|
||||
/**
|
||||
* 添加上报带宽值
|
||||
*/
|
||||
@RequiresPermissions("system:registration:edit")
|
||||
@Log(title = "添加上报带宽值", businessType = BusinessType.UPDATE)
|
||||
@PostMapping("/addReportedBandwidth")
|
||||
public AjaxResult addReportedBandwidth(@RequestBody RmResourceRegistration rmResourceRegistration)
|
||||
{
|
||||
return toAjax(rmResourceRegistrationService.addReportedBandwidth(rmResourceRegistration));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+24
-2
@@ -117,6 +117,9 @@ public class RmResourceRegistration extends BaseEntity
|
||||
@Excel(name = "IP1-IPv4地址")
|
||||
private String ip1Ipv4Address; // IP1-IPv4地址
|
||||
|
||||
@Excel(name = "IP1-IPv6地址")
|
||||
private String ip1Ipv6Address; // IP1-IPv6地址
|
||||
|
||||
@Excel(name = "IP1-网关")
|
||||
private String ip1Gateway; // IP1-网关
|
||||
|
||||
@@ -145,6 +148,9 @@ public class RmResourceRegistration extends BaseEntity
|
||||
@Excel(name = "IP2-IPv4地址")
|
||||
private String ip2Ipv4Address;
|
||||
|
||||
@Excel(name = "IP2-IPv6地址")
|
||||
private String ip2Ipv6Address; // IP2-IPv6地址
|
||||
|
||||
@Excel(name = "IP2-网关")
|
||||
private String ip2Gateway;
|
||||
|
||||
@@ -173,6 +179,9 @@ public class RmResourceRegistration extends BaseEntity
|
||||
@Excel(name = "IP3-IPv4地址")
|
||||
private String ip3Ipv4Address;
|
||||
|
||||
@Excel(name = "IP3-IPv6地址")
|
||||
private String ip3Ipv6Address; // IP3-IPv6地址
|
||||
|
||||
@Excel(name = "IP3-网关")
|
||||
private String ip3Gateway;
|
||||
|
||||
@@ -200,8 +209,12 @@ public class RmResourceRegistration extends BaseEntity
|
||||
|
||||
@Excel(name = "管理网-IPv4地址")
|
||||
private String mgmtIpv4Address; // 管理网-IPv4地址
|
||||
|
||||
@Excel(name = "管理网-IPv6地址")
|
||||
private String mgmtIpv6Address; // 管理网-IPv6地址
|
||||
|
||||
@Excel(name = "管理网-网关")
|
||||
private String mgmtGateway; // 管理网-IPv4地址
|
||||
private String mgmtGateway; // 管理网-网关地址
|
||||
|
||||
/** 多条件查询 */
|
||||
private String queryParam;
|
||||
@@ -216,7 +229,7 @@ public class RmResourceRegistration extends BaseEntity
|
||||
private Date createTime;
|
||||
|
||||
/** 上机时间 */
|
||||
@Excel(name = "上机时间")
|
||||
@Excel(name = "上机时间", dateFormat = "yyyy-MM-dd HH:mm:ss")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date onboardTime;
|
||||
/** 服务器列表 */
|
||||
@@ -226,5 +239,14 @@ public class RmResourceRegistration extends BaseEntity
|
||||
/** 逻辑节点空标识 */
|
||||
private boolean logicalNodeEmpty;
|
||||
/** 昨日95值 */
|
||||
@Excel(name = "昨日95值(MBit)")
|
||||
private BigDecimal bandwidthResult;
|
||||
/** 上报带宽值(MBit) */
|
||||
@Excel(name = "上报带宽值(MBit)")
|
||||
private BigDecimal reportedBandwidth;
|
||||
/** 日95带宽值利用率 */
|
||||
@Excel(name = "日95带宽值利用率")
|
||||
private String bandwidthRate;
|
||||
/** 昨日95值排序 1正序 2倒叙 3不排序 */
|
||||
private Integer bandwidthResultSort;
|
||||
}
|
||||
+2
@@ -110,4 +110,6 @@ public interface RmResourceRegistrationMapper
|
||||
* @return
|
||||
*/
|
||||
int updateRemark(RmResourceRegistration rmResourceRegistration);
|
||||
|
||||
int addReportedBandwidth(RmResourceRegistration rmResourceRegistration);
|
||||
}
|
||||
|
||||
+7
@@ -132,4 +132,11 @@ public interface IRmResourceRegistrationService
|
||||
* @return
|
||||
*/
|
||||
int updateRemark(RmResourceRegistration rmResourceRegistration);
|
||||
|
||||
/**
|
||||
* 添加上报带宽值
|
||||
* @param rmResourceRegistration
|
||||
* @return
|
||||
*/
|
||||
int addReportedBandwidth(RmResourceRegistration rmResourceRegistration);
|
||||
}
|
||||
|
||||
+351
-81
@@ -20,6 +20,7 @@ import com.tongran.system.service.IRmResourceRegistrationService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
@@ -83,106 +84,199 @@ public class RmResourceRegistrationServiceImpl implements IRmResourceRegistratio
|
||||
* @return 资源注册
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> getRegistrationTableInfoList(RmResourceRegistration rmResourceRegistration)
|
||||
{
|
||||
Map<String, Object> resultMap = new HashMap();
|
||||
if(rmResourceRegistration.getQueryParam() == null || rmResourceRegistration.getQueryParam() == ""){
|
||||
public Map<String, Object> getRegistrationTableInfoList(RmResourceRegistration rmResourceRegistration) {
|
||||
long startTime = System.currentTimeMillis();
|
||||
Map<String, Object> resultMap = new HashMap<>();
|
||||
|
||||
// 获取参数
|
||||
String queryParam = rmResourceRegistration.getQueryParam();
|
||||
Integer bandwidthResultSort = rmResourceRegistration.getBandwidthResultSort();
|
||||
int pageNum = rmResourceRegistration.getPageNum() != null ? rmResourceRegistration.getPageNum() : 1;
|
||||
int pageSize = rmResourceRegistration.getPageSize() != null ? rmResourceRegistration.getPageSize() : 10;
|
||||
|
||||
// 判断是否有查询条件
|
||||
boolean hasQueryParam = queryParam != null && !queryParam.trim().isEmpty();
|
||||
String queryValue = hasQueryParam ? queryParam.trim().toLowerCase() : null;
|
||||
|
||||
// 情况1: 无查询参数且无特殊排序,使用数据库分页
|
||||
if (!hasQueryParam && (bandwidthResultSort == null || bandwidthResultSort == 3)) {
|
||||
PageDomain pageDomain = new PageDomain();
|
||||
pageDomain.setPageNum(rmResourceRegistration.getPageNum());
|
||||
pageDomain.setPageSize(rmResourceRegistration.getPageSize());
|
||||
pageDomain.setPageNum(pageNum);
|
||||
pageDomain.setPageSize(pageSize);
|
||||
startPage(pageDomain);
|
||||
|
||||
List<RmResourceRegistration> list = rmResourceRegistrationMapper.getRegistrationTableInfoList(rmResourceRegistration);
|
||||
|
||||
// 只处理当前页的数据
|
||||
processCurrentPageData(list);
|
||||
|
||||
resultMap.put("list", list);
|
||||
return resultMap;
|
||||
}
|
||||
List<RmResourceRegistration> rmResourceRegistrationList = rmResourceRegistrationMapper.getRegistrationTableInfoList(rmResourceRegistration);
|
||||
for (RmResourceRegistration resourceRegistration : rmResourceRegistrationList) {
|
||||
if(resourceRegistration.getClientId() != null){
|
||||
// 网卡信息
|
||||
setNetWorkMsg(resourceRegistration);
|
||||
// set昨日95值
|
||||
setBandwidthYestoday(resourceRegistration);
|
||||
|
||||
// 情况2: 有查询参数或需要排序,全量查询+内存处理
|
||||
List<RmResourceRegistration> allData = rmResourceRegistrationMapper.getRegistrationTableInfoList(rmResourceRegistration);
|
||||
|
||||
// 1. 过滤
|
||||
List<RmResourceRegistration> filteredList = allData;
|
||||
if (hasQueryParam) {
|
||||
filteredList = allData.stream()
|
||||
.filter(item -> item != null && quickMatches(item, queryValue))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
// 2. 排序
|
||||
if (bandwidthResultSort != null && bandwidthResultSort != 3) {
|
||||
sortList(filteredList, bandwidthResultSort);
|
||||
}
|
||||
|
||||
// 3. 内存分页
|
||||
int total = filteredList.size();
|
||||
int fromIndex = Math.min((pageNum - 1) * pageSize, total);
|
||||
int toIndex = Math.min(fromIndex + pageSize, total);
|
||||
|
||||
// 注意:这里要用copy,因为后续要修改数据
|
||||
List<RmResourceRegistration> pageList = applyPagination(filteredList, rmResourceRegistration.getPageNum(), rmResourceRegistration.getPageSize());
|
||||
List<RmResourceRegistration> currentPageData = new ArrayList<>(pageList);
|
||||
|
||||
// 4. 只处理当前页数据
|
||||
processCurrentPageData(currentPageData);
|
||||
|
||||
resultMap.put("list", currentPageData);
|
||||
resultMap.put("total", total);
|
||||
|
||||
log.info("查询完成,总耗时: {}ms, 总条数: {}, 处理条数: {}",
|
||||
System.currentTimeMillis() - startTime, total, currentPageData.size());
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 只处理当前页的数据
|
||||
*/
|
||||
private void processCurrentPageData(List<RmResourceRegistration> pageList) {
|
||||
if (CollectionUtils.isEmpty(pageList)) {
|
||||
return;
|
||||
}
|
||||
|
||||
long startTime = System.currentTimeMillis();
|
||||
|
||||
for (RmResourceRegistration item : pageList) {
|
||||
if (item.getClientId() != null) {
|
||||
setNetWorkMsg(item);
|
||||
setBandwidthYestoday(item);
|
||||
}
|
||||
}
|
||||
if(rmResourceRegistration.getQueryParam() != null && !rmResourceRegistration.getQueryParam().trim().isEmpty()){
|
||||
String queryValue = rmResourceRegistration.getQueryParam().trim().toLowerCase(); // 转为小写便于模糊匹配
|
||||
|
||||
// 从rmResourceRegistrationList列表中筛选符合条件的数据
|
||||
List<RmResourceRegistration> filteredList = rmResourceRegistrationList.stream()
|
||||
.filter(item -> item != null)
|
||||
.filter(item -> {
|
||||
// 如果查询值为空,返回所有数据
|
||||
if (queryValue.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// 检查公网IP (IP1-3和管理网)
|
||||
return (item.getIp1PublicIp() != null && item.getIp1PublicIp().toLowerCase().contains(queryValue)) ||
|
||||
(item.getIp2PublicIp() != null && item.getIp2PublicIp().toLowerCase().contains(queryValue)) ||
|
||||
(item.getIp3PublicIp() != null && item.getIp3PublicIp().toLowerCase().contains(queryValue)) ||
|
||||
(item.getMgmtPublicIp() != null && item.getMgmtPublicIp().toLowerCase().contains(queryValue)) ||
|
||||
|
||||
// 检查私网IP (IP1-3和管理网)
|
||||
(item.getIp1Ipv4Address() != null && item.getIp1Ipv4Address().toLowerCase().contains(queryValue)) ||
|
||||
(item.getIp2Ipv4Address() != null && item.getIp2Ipv4Address().toLowerCase().contains(queryValue)) ||
|
||||
(item.getIp3Ipv4Address() != null && item.getIp3Ipv4Address().toLowerCase().contains(queryValue)) ||
|
||||
(item.getMgmtIpv4Address() != null && item.getMgmtIpv4Address().toLowerCase().contains(queryValue)) ||
|
||||
|
||||
// 检查设备SN
|
||||
(item.getHardwareSn() != null && item.getHardwareSn().toLowerCase().contains(queryValue)) ||
|
||||
(item.getClientId() != null && item.getClientId().toLowerCase().contains(queryValue));
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
|
||||
List<RmResourceRegistration> pageInfo = applyPagination(filteredList, rmResourceRegistration.getPageNum(), rmResourceRegistration.getPageSize());
|
||||
resultMap.put("list", pageInfo);
|
||||
resultMap.put("total", filteredList.size());
|
||||
return resultMap;
|
||||
long cost = System.currentTimeMillis() - startTime;
|
||||
if (cost > 1000) {
|
||||
log.info("处理{}条数据耗时较长: {}ms", pageList.size(), cost);
|
||||
} else if (cost > 100) {
|
||||
log.info("处理{}条数据耗时: {}ms", pageList.size(), cost);
|
||||
} else {
|
||||
resultMap.put("list", rmResourceRegistrationList);
|
||||
log.info("处理{}条数据耗时: {}ms", pageList.size(), cost);
|
||||
}
|
||||
return resultMap;
|
||||
}
|
||||
/**
|
||||
* 查询资源注册列表
|
||||
*
|
||||
*
|
||||
* @param rmResourceRegistration 资源注册
|
||||
* @return 资源注册
|
||||
*/
|
||||
@Override
|
||||
public List<RmResourceRegistration> selectRmResourceRegistrationList(RmResourceRegistration rmResourceRegistration)
|
||||
{
|
||||
List<RmResourceRegistration> rmResourceRegistrationList = rmResourceRegistrationMapper.getRegistrationTableInfoList(rmResourceRegistration);
|
||||
for (RmResourceRegistration resourceRegistration : rmResourceRegistrationList) {
|
||||
if(resourceRegistration.getClientId() != null){
|
||||
// 网卡信息
|
||||
setNetWorkMsg(resourceRegistration);
|
||||
public List<RmResourceRegistration> selectRmResourceRegistrationList(RmResourceRegistration rmResourceRegistration) {
|
||||
List<RmResourceRegistration> allData = rmResourceRegistrationMapper.getRegistrationTableInfoList(rmResourceRegistration);
|
||||
|
||||
// 获取参数
|
||||
String queryParam = rmResourceRegistration.getQueryParam();
|
||||
Integer bandwidthResultSort = rmResourceRegistration.getBandwidthResultSort();
|
||||
boolean hasQueryParam = queryParam != null && !queryParam.trim().isEmpty();
|
||||
String queryValue = hasQueryParam ? queryParam.trim().toLowerCase() : null;
|
||||
|
||||
// 过滤
|
||||
List<RmResourceRegistration> filteredList = allData;
|
||||
if (hasQueryParam) {
|
||||
filteredList = allData.stream()
|
||||
.filter(item -> item != null && quickMatches(item, queryValue))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
// 排序
|
||||
if (bandwidthResultSort != null && bandwidthResultSort != 3) {
|
||||
sortList(filteredList, bandwidthResultSort);
|
||||
}
|
||||
|
||||
// 处理全部数据
|
||||
for (RmResourceRegistration item : filteredList) {
|
||||
if (item.getClientId() != null) {
|
||||
setNetWorkMsg(item);
|
||||
setBandwidthYestoday(item);
|
||||
}
|
||||
}
|
||||
if(rmResourceRegistration.getQueryParam() != null){
|
||||
String queryValue = rmResourceRegistration.getQueryParam().trim();
|
||||
// 筛选公网IP私网IP设备SN相等的数据
|
||||
// 从rmResourceRegistrationList列表中筛选符合条件的数据
|
||||
List<RmResourceRegistration> filteredList = rmResourceRegistrationList.stream()
|
||||
.filter(item -> item != null)
|
||||
.filter(item ->
|
||||
// 检查公网IP (IP1-3和管理网)
|
||||
queryValue.equals(item.getIp1PublicIp()) ||
|
||||
queryValue.equals(item.getIp2PublicIp()) ||
|
||||
queryValue.equals(item.getIp3PublicIp()) ||
|
||||
queryValue.equals(item.getMgmtPublicIp()) ||
|
||||
|
||||
// 检查私网IP (IP1-3和管理网)
|
||||
queryValue.equals(item.getIp1Ipv4Address()) ||
|
||||
queryValue.equals(item.getIp2Ipv4Address()) ||
|
||||
queryValue.equals(item.getIp3Ipv4Address()) ||
|
||||
queryValue.equals(item.getMgmtIpv4Address()) ||
|
||||
return filteredList;
|
||||
}
|
||||
|
||||
// 检查设备SN
|
||||
queryValue.equals(item.getHardwareSn()) ||
|
||||
queryValue.equals(item.getClientId())
|
||||
)
|
||||
.collect(Collectors.toList());
|
||||
return filteredList;
|
||||
/**
|
||||
* 快速匹配方法
|
||||
*/
|
||||
private boolean quickMatches(RmResourceRegistration item, String queryValue) {
|
||||
if (item == null || queryValue == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 优化检查顺序,先检查最可能匹配的字段
|
||||
String clientId = item.getClientId();
|
||||
String hardwareSn = item.getHardwareSn();
|
||||
|
||||
if ((clientId != null && clientId.toLowerCase().contains(queryValue)) ||
|
||||
(hardwareSn != null && hardwareSn.toLowerCase().contains(queryValue))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// 检查IP地址
|
||||
return containsValue(item.getIp1PublicIp(), queryValue) ||
|
||||
containsValue(item.getIp2PublicIp(), queryValue) ||
|
||||
containsValue(item.getIp3PublicIp(), queryValue) ||
|
||||
containsValue(item.getMgmtPublicIp(), queryValue) ||
|
||||
containsValue(item.getIp1Ipv4Address(), queryValue) ||
|
||||
containsValue(item.getIp2Ipv4Address(), queryValue) ||
|
||||
containsValue(item.getIp3Ipv4Address(), queryValue) ||
|
||||
containsValue(item.getMgmtIpv4Address(), queryValue) ||
|
||||
containsValue(item.getIp1Ipv6Address(), queryValue) ||
|
||||
containsValue(item.getIp2Ipv6Address(), queryValue) ||
|
||||
containsValue(item.getIp3Ipv6Address(), queryValue) ||
|
||||
containsValue(item.getMgmtIpv6Address(), queryValue);
|
||||
}
|
||||
|
||||
private boolean containsValue(String value, String queryValue) {
|
||||
return value != null && value.toLowerCase().contains(queryValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* 排序方法
|
||||
*/
|
||||
private void sortList(List<RmResourceRegistration> list, Integer sortType) {
|
||||
if (CollectionUtils.isEmpty(list) || sortType == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Comparator<RmResourceRegistration> comparator = null;
|
||||
|
||||
if (sortType == 1) {
|
||||
comparator = Comparator.comparing(
|
||||
RmResourceRegistration::getBandwidthResult,
|
||||
Comparator.nullsLast(Comparator.naturalOrder())
|
||||
);
|
||||
} else if (sortType == 2) {
|
||||
comparator = Comparator.comparing(
|
||||
RmResourceRegistration::getBandwidthResult,
|
||||
Comparator.nullsLast(Comparator.reverseOrder())
|
||||
);
|
||||
}
|
||||
|
||||
if (comparator != null) {
|
||||
list.sort(comparator);
|
||||
}
|
||||
return rmResourceRegistrationList;
|
||||
}
|
||||
/**
|
||||
* 内存分页
|
||||
@@ -200,6 +294,159 @@ public class RmResourceRegistrationServiceImpl implements IRmResourceRegistratio
|
||||
int toIndex = Math.min(fromIndex + pageSize, list.size());
|
||||
return list.subList(fromIndex, toIndex);
|
||||
}
|
||||
/**
|
||||
* 批量处理网络信息
|
||||
*/
|
||||
private void batchSetNetWorkMsg(List<RmResourceRegistration> pageList) {
|
||||
if (CollectionUtils.isEmpty(pageList)) {
|
||||
return;
|
||||
}
|
||||
|
||||
long startTime = System.currentTimeMillis();
|
||||
|
||||
// 收集所有需要查询的clientId,用逗号分隔
|
||||
String clientIdsStr = pageList.stream()
|
||||
.map(RmResourceRegistration::getClientId)
|
||||
.filter(Objects::nonNull)
|
||||
.distinct()
|
||||
.collect(Collectors.joining(","));
|
||||
|
||||
if (StringUtils.isBlank(clientIdsStr)) {
|
||||
return;
|
||||
}
|
||||
|
||||
log.debug("批量查询网络信息,clientIds: {}", clientIdsStr);
|
||||
|
||||
try {
|
||||
// 使用批量查询接口
|
||||
RmNetworkInterfaceRemote queryParam = new RmNetworkInterfaceRemote();
|
||||
queryParam.setClientIds(clientIdsStr); // 这里是逗号分隔的字符串
|
||||
queryParam.setNewFlag(1);
|
||||
|
||||
R<List<RmNetworkInterfaceRemote>> result = remoteRocketMqService.getNetworkInterfaceList(queryParam, SecurityConstants.INNER);
|
||||
|
||||
if (result == null || result.getData() == null || result.getData().isEmpty()) {
|
||||
log.warn("批量查询网络信息返回为空,clientIds: {}", clientIdsStr);
|
||||
// 回退到单条查询
|
||||
fallbackSetNetworkInfo(pageList);
|
||||
return;
|
||||
}
|
||||
|
||||
List<RmNetworkInterfaceRemote> networkList = result.getData();
|
||||
|
||||
// 按clientId分组
|
||||
Map<String, List<RmNetworkInterfaceRemote>> networkMap = networkList.stream()
|
||||
.filter(Objects::nonNull)
|
||||
.filter(item -> item.getClientId() != null)
|
||||
.collect(Collectors.groupingBy(RmNetworkInterfaceRemote::getClientId));
|
||||
|
||||
// 批量设置
|
||||
for (RmResourceRegistration registration : pageList) {
|
||||
String clientId = registration.getClientId();
|
||||
if (clientId != null) {
|
||||
List<RmNetworkInterfaceRemote> clientNetworks = networkMap.get(clientId);
|
||||
if (clientNetworks != null && !clientNetworks.isEmpty()) {
|
||||
// 调用原有的setNetWorkMsg方法
|
||||
setNetWorkMsgWithNetworkList(registration, clientNetworks);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
log.debug("批量处理网络信息完成,耗时: {}ms, 处理{}条记录, 返回{}条网络信息",
|
||||
System.currentTimeMillis() - startTime, pageList.size(), networkList.size());
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("批量查询网络信息异常", e);
|
||||
// 回退到单条查询
|
||||
fallbackSetNetworkInfo(pageList);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 使用批量查询的结果设置网络信息
|
||||
*/
|
||||
private void setNetWorkMsgWithNetworkList(RmResourceRegistration registration, List<RmNetworkInterfaceRemote> networkList) {
|
||||
if (registration == null || CollectionUtils.isEmpty(networkList)) {
|
||||
return;
|
||||
}
|
||||
|
||||
int businessIpCount = 1;
|
||||
|
||||
for (RmNetworkInterfaceRemote network : networkList) {
|
||||
if ("1".equals(network.getBindIp()) || "3".equals(network.getBindIp())) {
|
||||
// 业务IP处理
|
||||
if (businessIpCount > 3) {
|
||||
continue; // 最多只处理3个业务IP
|
||||
}
|
||||
|
||||
// 设置业务IP字段
|
||||
switch (businessIpCount) {
|
||||
case 1:
|
||||
registration.setIp1Isp(network.getIsp());
|
||||
registration.setIp1Province(network.getProvince());
|
||||
registration.setIp1City(network.getCity());
|
||||
registration.setIp1PublicIp(network.getPublicIp());
|
||||
registration.setIp1InterfaceName(network.getInterfaceName());
|
||||
registration.setIp1MacAddress(network.getMacAddress());
|
||||
registration.setIp1InterfaceType(network.getInterfaceType());
|
||||
registration.setIp1Ipv4Address(network.getIpv4Address());
|
||||
registration.setIp1Ipv6Address(network.getIpv6Address());
|
||||
registration.setIp1Gateway(network.getGateway());
|
||||
break;
|
||||
case 2:
|
||||
registration.setIp2Isp(network.getIsp());
|
||||
registration.setIp2Province(network.getProvince());
|
||||
registration.setIp2City(network.getCity());
|
||||
registration.setIp2PublicIp(network.getPublicIp());
|
||||
registration.setIp2InterfaceName(network.getInterfaceName());
|
||||
registration.setIp2MacAddress(network.getMacAddress());
|
||||
registration.setIp2InterfaceType(network.getInterfaceType());
|
||||
registration.setIp2Ipv4Address(network.getIpv4Address());
|
||||
registration.setIp2Ipv6Address(network.getIpv6Address());
|
||||
registration.setIp2Gateway(network.getGateway());
|
||||
break;
|
||||
case 3:
|
||||
registration.setIp3Isp(network.getIsp());
|
||||
registration.setIp3Province(network.getProvince());
|
||||
registration.setIp3City(network.getCity());
|
||||
registration.setIp3PublicIp(network.getPublicIp());
|
||||
registration.setIp3InterfaceName(network.getInterfaceName());
|
||||
registration.setIp3MacAddress(network.getMacAddress());
|
||||
registration.setIp3InterfaceType(network.getInterfaceType());
|
||||
registration.setIp3Ipv4Address(network.getIpv4Address());
|
||||
registration.setIp3Ipv6Address(network.getIpv6Address());
|
||||
registration.setIp3Gateway(network.getGateway());
|
||||
break;
|
||||
}
|
||||
|
||||
businessIpCount++;
|
||||
}
|
||||
if ("2".equals(network.getBindIp()) || "3".equals(network.getBindIp())) {
|
||||
// 管理网IP处理
|
||||
registration.setMgmtIsp(network.getIsp());
|
||||
registration.setMgmtProvince(network.getProvince());
|
||||
registration.setMgmtCity(network.getCity());
|
||||
registration.setMgmtPublicIp(network.getPublicIp());
|
||||
registration.setMgmtInterfaceName(network.getInterfaceName());
|
||||
registration.setMgmtMacAddress(network.getMacAddress());
|
||||
registration.setMgmtInterfaceType(network.getInterfaceType());
|
||||
registration.setMgmtIpv4Address(network.getIpv4Address());
|
||||
registration.setMgmtIpv6Address(network.getIpv6Address());
|
||||
registration.setMgmtGateway(network.getGateway());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 回退到单条查询
|
||||
*/
|
||||
private void fallbackSetNetworkInfo(List<RmResourceRegistration> pageList) {
|
||||
log.warn("批量查询失败,回退到单条查询");
|
||||
for (RmResourceRegistration registration : pageList) {
|
||||
if (registration.getClientId() != null) {
|
||||
setNetWorkMsg(registration);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 网卡信息赋值
|
||||
@@ -246,6 +493,7 @@ public class RmResourceRegistrationServiceImpl implements IRmResourceRegistratio
|
||||
registration.setIp1MacAddress(network.getMacAddress());
|
||||
registration.setIp1InterfaceType(network.getInterfaceType());
|
||||
registration.setIp1Ipv4Address(network.getIpv4Address());
|
||||
registration.setIp1Ipv6Address(network.getIpv6Address());
|
||||
registration.setIp1Gateway(network.getGateway());
|
||||
break;
|
||||
case 2:
|
||||
@@ -257,6 +505,7 @@ public class RmResourceRegistrationServiceImpl implements IRmResourceRegistratio
|
||||
registration.setIp2MacAddress(network.getMacAddress());
|
||||
registration.setIp2InterfaceType(network.getInterfaceType());
|
||||
registration.setIp2Ipv4Address(network.getIpv4Address());
|
||||
registration.setIp2Ipv6Address(network.getIpv6Address());
|
||||
registration.setIp2Gateway(network.getGateway());
|
||||
break;
|
||||
case 3:
|
||||
@@ -268,6 +517,7 @@ public class RmResourceRegistrationServiceImpl implements IRmResourceRegistratio
|
||||
registration.setIp3MacAddress(network.getMacAddress());
|
||||
registration.setIp3InterfaceType(network.getInterfaceType());
|
||||
registration.setIp3Ipv4Address(network.getIpv4Address());
|
||||
registration.setIp3Ipv6Address(network.getIpv6Address());
|
||||
registration.setIp3Gateway(network.getGateway());
|
||||
break;
|
||||
}
|
||||
@@ -284,6 +534,7 @@ public class RmResourceRegistrationServiceImpl implements IRmResourceRegistratio
|
||||
registration.setMgmtMacAddress(network.getMacAddress());
|
||||
registration.setMgmtInterfaceType(network.getInterfaceType());
|
||||
registration.setMgmtIpv4Address(network.getIpv4Address());
|
||||
registration.setMgmtIpv6Address(network.getIpv6Address());
|
||||
registration.setMgmtGateway(network.getGateway());
|
||||
}
|
||||
}
|
||||
@@ -315,7 +566,18 @@ public class RmResourceRegistrationServiceImpl implements IRmResourceRegistratio
|
||||
List<EpsNodeBandwidth> nodeBandwidthList = epsNodeBandwidthMapper.selectEpsNodeBandwidthList(epsNodeBandwidth);
|
||||
if(nodeBandwidthList != null && !nodeBandwidthList.isEmpty()){
|
||||
EpsNodeBandwidth nodeBandwidth = nodeBandwidthList.get(0);
|
||||
registration.setBandwidthResult(nodeBandwidth.getBandwidthResult());
|
||||
BigDecimal bandwidthResult = nodeBandwidth.getBandwidthResult();
|
||||
registration.setBandwidthResult(bandwidthResult);
|
||||
BigDecimal reportedBandwidth = registration.getReportedBandwidth();
|
||||
if(reportedBandwidth != null){
|
||||
if(reportedBandwidth.compareTo(BigDecimal.ZERO) == 0){
|
||||
registration.setBandwidthRate("0%");
|
||||
}else{
|
||||
// 计算日95带宽值利用率
|
||||
BigDecimal bandwidthRate = bandwidthResult.multiply(new BigDecimal(100)).divide(reportedBandwidth, 1, RoundingMode.HALF_UP);
|
||||
registration.setBandwidthRate(bandwidthRate + "%");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
@@ -854,5 +1116,13 @@ public class RmResourceRegistrationServiceImpl implements IRmResourceRegistratio
|
||||
int rows = rmResourceRegistrationMapper.updateRemark(rmResourceRegistration);
|
||||
return rows;
|
||||
}
|
||||
@Override
|
||||
public int addReportedBandwidth(RmResourceRegistration rmResourceRegistration) {
|
||||
if(rmResourceRegistration.getId() == null){
|
||||
throw new RuntimeException("id不可为null");
|
||||
}
|
||||
int rows = rmResourceRegistrationMapper.addReportedBandwidth(rmResourceRegistration);
|
||||
return rows;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+17
-14
@@ -430,32 +430,35 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
|
||||
<select id="getTrafficListByClientIds" resultType="EpsInitialTrafficData">
|
||||
SELECT
|
||||
CAST(sum(ifnull(in_speed,0)) AS DECIMAL(20,0)) AS inSpeed,
|
||||
CAST(sum(ifnull(out_speed,0)) AS DECIMAL(20,0)) AS outSpeed,
|
||||
CAST(sum(ifnull(ipv4_in_speed,0)) AS DECIMAL(20,0)) AS ipv4InSpeed,
|
||||
CAST(sum(ifnull(ipv4_out_speed,0)) AS DECIMAL(20,0)) AS ipv4OutSpeed,
|
||||
CAST(sum(ifnull(ipv6_in_speed,0)) AS DECIMAL(20,0)) AS ipv6InSpeed,
|
||||
CAST(sum(ifnull(ipv6_out_speed,0)) AS DECIMAL(20,0)) AS ipv6OutSpeed,
|
||||
create_time AS createTime
|
||||
FROM ${tableName}
|
||||
CAST(sum(ifnull(a.in_speed,0)) AS DECIMAL(20,0)) AS inSpeed,
|
||||
CAST(sum(ifnull(a.out_speed,0)) AS DECIMAL(20,0)) AS outSpeed,
|
||||
CAST(sum(ifnull(a.ipv4_in_speed,0)) AS DECIMAL(20,0)) AS ipv4InSpeed,
|
||||
CAST(sum(ifnull(a.ipv4_out_speed,0)) AS DECIMAL(20,0)) AS ipv4OutSpeed,
|
||||
CAST(sum(ifnull(a.ipv6_in_speed,0)) AS DECIMAL(20,0)) AS ipv6InSpeed,
|
||||
CAST(sum(ifnull(a.ipv6_out_speed,0)) AS DECIMAL(20,0)) AS ipv6OutSpeed,
|
||||
a.create_time AS createTime
|
||||
FROM ${tableName} a
|
||||
INNER JOIN rm_network_interface b ON a.client_id = b.client_id and a.mac = b.mac_address
|
||||
AND (b.bind_ip = 1 OR b.bind_ip = 3)
|
||||
AND b.new_flag = 1
|
||||
<where>
|
||||
<if test="businessId != '' and businessId != null">
|
||||
and business_id = #{businessId}
|
||||
and a.business_id = #{businessId}
|
||||
</if>
|
||||
<if test="startTime != null">
|
||||
and create_time >= #{startTime}
|
||||
and a.create_time >= #{startTime}
|
||||
</if>
|
||||
<if test="endTime != null">
|
||||
and create_time <= #{endTime}
|
||||
and a.create_time <= #{endTime}
|
||||
</if>
|
||||
<if test="clientIds != null">
|
||||
and client_id in
|
||||
and a.client_id in
|
||||
<foreach collection="clientIds.split(',')" item="clientId" open="(" separator="," close=")">
|
||||
#{clientId}
|
||||
</foreach>
|
||||
</if>
|
||||
</where>
|
||||
group by create_time
|
||||
ORDER BY out_speed desc
|
||||
group by a.create_time
|
||||
ORDER BY outSpeed desc
|
||||
</select>
|
||||
</mapper>
|
||||
+2
-2
@@ -320,8 +320,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="calculationMode != null and calculationMode != ''"> and calculation_mode = #{calculationMode}</if>
|
||||
<if test="bandwidthType != null and bandwidthType != ''"> and bandwidth_type = #{bandwidthType}</if>
|
||||
<if test="resourceType != null and resourceType != ''"> and resource_type = #{resourceType}</if>
|
||||
<if test="startTime != null and startTime != ''"> and create_time >= #{startTime}</if>
|
||||
<if test="endTime != null and endTime != ''"> and create_time <= #{endTime}</if>
|
||||
<if test="startTime != null and startTime != ''"> and create_time >= left(#{startTime},10)</if>
|
||||
<if test="endTime != null and endTime != ''"> and create_time <= left(#{endTime},10)</if>
|
||||
<if test="clientIds != '' and clientIds != null">
|
||||
and client_id in
|
||||
<foreach collection="clientIds.split(',')" item="clientId" open="(" separator="," close=")">
|
||||
|
||||
+11
-1
@@ -23,10 +23,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<result property="remark" column="remark" />
|
||||
<result property="createBy" column="create_by" />
|
||||
<result property="updateBy" column="update_by" />
|
||||
<result property="reportedBandwidth" column="reported_bandwidth" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectRmResourceRegistrationVo">
|
||||
select id, client_id, hardware_sn, business_name, logical_node_id, multi_public_ip_status, registration_status, online_status, resource_type, agent_version, create_time, update_time, heartbeat_count, heartbeat_interval, onboard_time, remark, create_by, update_by from rm_resource_registration
|
||||
select id, client_id, hardware_sn, business_name, logical_node_id, multi_public_ip_status, registration_status, online_status, resource_type, agent_version, create_time, update_time, heartbeat_count, heartbeat_interval, onboard_time, remark, create_by, update_by, reported_bandwidth from rm_resource_registration
|
||||
</sql>
|
||||
|
||||
<select id="selectRmResourceRegistrationList" parameterType="RmResourceRegistration" resultMap="RmResourceRegistrationResult">
|
||||
@@ -73,6 +74,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="remark != null">remark,</if>
|
||||
<if test="createBy != null">create_by,</if>
|
||||
<if test="updateBy != null">update_by,</if>
|
||||
<if test="reportedBandwidth != null">reported_bandwidth,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="clientId != null">#{clientId},</if>
|
||||
@@ -92,6 +94,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="remark != null">#{remark},</if>
|
||||
<if test="createBy != null">#{createBy},</if>
|
||||
<if test="updateBy != null">#{updateBy},</if>
|
||||
<if test="reportedBandwidth != null">#{reportedBandwidth},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
@@ -115,6 +118,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="remark != null">remark = #{remark},</if>
|
||||
<if test="createBy != null">create_by = #{createBy},</if>
|
||||
<if test="updateBy != null">update_by = #{updateBy},</if>
|
||||
<if test="reportedBandwidth != null">reported_bandwidth = #{reportedBandwidth},</if>
|
||||
</trim>
|
||||
where id = #{id}
|
||||
</update>
|
||||
@@ -153,6 +157,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="remark != null">remark = #{remark},</if>
|
||||
<if test="createBy != null">create_by = #{createBy},</if>
|
||||
<if test="updateBy != null">update_by = #{updateBy},</if>
|
||||
<if test="reportedBandwidth != null">reported_bandwidth = #{reportedBandwidth},</if>
|
||||
</trim>
|
||||
<where>
|
||||
<choose>
|
||||
@@ -204,6 +209,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
a.heartbeat_interval as heartbeatInterval,
|
||||
a.onboard_time as onboardTime,
|
||||
a.remark as remark,
|
||||
a.reported_bandwidth as reportedBandwidth,
|
||||
b.machine_code as machineCode
|
||||
from rm_resource_registration a
|
||||
left join rm_registration_machine b on a.client_id = b.client_id
|
||||
@@ -240,4 +246,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
#{clientId}
|
||||
</foreach>
|
||||
</update>
|
||||
<update id="addReportedBandwidth" parameterType="RmResourceRegistration">
|
||||
update rm_resource_registration set reported_bandwidth = #{reportedBandwidth}
|
||||
where id =#{id}
|
||||
</update>
|
||||
</mapper>
|
||||
+18
@@ -118,6 +118,24 @@ public class InitialBandwidthTrafficController extends BaseController
|
||||
Map<String, Object> echartsData = initialBandwidthTrafficService.netInterfaceTrafficEcharts(initialBandwidthTraffic);
|
||||
return success(echartsData);
|
||||
}
|
||||
/**
|
||||
* 查询eth0 IPV4流量信息并封装为多折线ECharts图表数据
|
||||
*/
|
||||
@RequiresPermissions("rocketmq:traffic:list")
|
||||
@PostMapping("/netInterfaceIpv4TrafficEcharts")
|
||||
public AjaxResult netInterfaceIpv4TrafficEcharts(@RequestBody InitialBandwidthTraffic initialBandwidthTraffic) {
|
||||
Map<String, Object> echartsData = initialBandwidthTrafficService.netInterfaceIpv4TrafficEcharts(initialBandwidthTraffic);
|
||||
return success(echartsData);
|
||||
}
|
||||
/**
|
||||
* 查询eth0 IPV6流量信息并封装为多折线ECharts图表数据
|
||||
*/
|
||||
@RequiresPermissions("rocketmq:traffic:list")
|
||||
@PostMapping("/netInterfaceIpv6TrafficEcharts")
|
||||
public AjaxResult netInterfaceIpv6TrafficEcharts(@RequestBody InitialBandwidthTraffic initialBandwidthTraffic) {
|
||||
Map<String, Object> echartsData = initialBandwidthTrafficService.netInterfaceIpv6TrafficEcharts(initialBandwidthTraffic);
|
||||
return success(echartsData);
|
||||
}
|
||||
|
||||
/**
|
||||
* eth0丢包数
|
||||
|
||||
@@ -53,6 +53,8 @@ public class RmNetworkInterface extends BaseEntity
|
||||
/** IPv4地址 */
|
||||
@Excel(name = "IPv4地址")
|
||||
private String ipv4Address;
|
||||
/** IPv6地址 */
|
||||
private String ipv6Address;
|
||||
|
||||
/** 网关 */
|
||||
@Excel(name = "网关")
|
||||
|
||||
@@ -14,6 +14,7 @@ import com.tongran.rocketmq.domain.vo.RspVo;
|
||||
import com.tongran.rocketmq.enums.AlarmTypeEnum;
|
||||
import com.tongran.rocketmq.enums.PushMethodEnum;
|
||||
import com.tongran.rocketmq.service.*;
|
||||
import com.tongran.rocketmq.snmp.scheduler.MultiSwitchCollectionScheduler;
|
||||
import com.tongran.rocketmq.utils.DataProcessUtil;
|
||||
import com.tongran.rocketmq.utils.JsonDataParser;
|
||||
import com.tongran.rocketmq.utils.WeChatWorkBot;
|
||||
@@ -97,6 +98,8 @@ public class MessageHandler {
|
||||
private IRmAlarmLogService rmAlarmLogService;
|
||||
@Autowired
|
||||
private IRmAlarmPushConfigService rmAlarmPushConfigService;
|
||||
@Autowired
|
||||
private MultiSwitchCollectionScheduler multiSwitchCollectionScheduler;
|
||||
|
||||
|
||||
/**
|
||||
@@ -130,211 +133,8 @@ public class MessageHandler {
|
||||
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); // 去除毫秒
|
||||
List<NetworkInfo> networkInfoList = registerMsg.getNetworkInfo();
|
||||
if(!networkInfoList.isEmpty()){
|
||||
if(networkInfoList.size()==1){
|
||||
NetworkInfo networkInfo = networkInfoList.get(0);
|
||||
// 查询该网卡信息是否存在
|
||||
RmNetworkInterface queryParam = new RmNetworkInterface();
|
||||
queryParam.setClientId(clientId);
|
||||
queryParam.setMacAddress(networkInfo.getMac());
|
||||
queryParam.setNewFlag(1);
|
||||
List<RmNetworkInterface> exits = rmNetworkInterfaceService.selectRmNetworkInterfaceList(queryParam);
|
||||
if(exits.isEmpty()){
|
||||
// 保存网卡信息
|
||||
RmNetworkInterface insertData = new RmNetworkInterface();
|
||||
// 业务ip和管理网ip
|
||||
insertData.setBindIp("3");
|
||||
insertData.setClientId(clientId);
|
||||
insertData.setIsp(networkInfo.getCarrier());
|
||||
insertData.setCity(networkInfo.getCity());
|
||||
insertData.setGateway(networkInfo.getGateway());
|
||||
insertData.setInterfaceName(networkInfo.getName());
|
||||
insertData.setIpv4Address(networkInfo.getIpv4());
|
||||
insertData.setMacAddress(networkInfo.getMac());
|
||||
insertData.setProvince(networkInfo.getProvince());
|
||||
insertData.setPublicIp(networkInfo.getPublicIp());
|
||||
insertData.setInterfaceType(networkInfo.getType());
|
||||
insertData.setCreateTime(createTime);
|
||||
rmNetworkInterfaceService.insertRmNetworkInterface(insertData);
|
||||
}else{
|
||||
RmNetworkInterface oldInterfaceMsg = exits.get(0);
|
||||
if(!StringUtils.equals(networkInfo.getName(),oldInterfaceMsg.getInterfaceName())
|
||||
|| !StringUtils.equals(networkInfo.getGateway(),oldInterfaceMsg.getGateway())){
|
||||
// 查询该网卡信息是否旧数据
|
||||
RmNetworkInterface query = new RmNetworkInterface();
|
||||
query.setMacAddress(oldInterfaceMsg.getMacAddress());
|
||||
query.setClientId(clientId);
|
||||
query.setNewFlag(999);
|
||||
List<RmNetworkInterface> oldExits = rmNetworkInterfaceService.selectRmNetworkInterfaceList(query);
|
||||
if(!oldExits.isEmpty()){
|
||||
// 先删除旧数据
|
||||
oldExits.forEach(oldMsg ->{
|
||||
rmNetworkInterfaceService.deleteRmNetworkInterfaceById(oldMsg.getId());
|
||||
});
|
||||
}
|
||||
// 先将已存在的改为旧数据
|
||||
RmNetworkInterface oldData = new RmNetworkInterface();
|
||||
oldData.setNewFlag(0);
|
||||
oldData.setClientId(clientId);
|
||||
oldData.setMacAddress(oldInterfaceMsg.getMacAddress());
|
||||
rmNetworkInterfaceService.updateRmNetworkInterfaceByMac(oldData);
|
||||
RmNetworkInterface insertData = new RmNetworkInterface();
|
||||
insertData.setClientId(clientId);
|
||||
insertData.setIsp(networkInfo.getCarrier());
|
||||
insertData.setCity(networkInfo.getCity());
|
||||
insertData.setGateway(networkInfo.getGateway());
|
||||
insertData.setInterfaceName(networkInfo.getName());
|
||||
insertData.setIpv4Address(networkInfo.getIpv4());
|
||||
insertData.setMacAddress(networkInfo.getMac());
|
||||
insertData.setProvince(networkInfo.getProvince());
|
||||
insertData.setPublicIp(networkInfo.getPublicIp());
|
||||
insertData.setInterfaceType(networkInfo.getType());
|
||||
rmNetworkInterfaceService.insertRmNetworkInterface(insertData);
|
||||
}else {
|
||||
RmNetworkInterface updateData = new RmNetworkInterface();
|
||||
// 检查其他字段是否需要更新
|
||||
boolean needUpdate = false;
|
||||
// 逐个字段比较是否需要更新
|
||||
if (!StringUtils.equals(networkInfo.getCity(), oldInterfaceMsg.getCity())) {
|
||||
updateData.setCity(networkInfo.getCity());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (!StringUtils.equals(networkInfo.getIpv4(), oldInterfaceMsg.getIpv4Address())) {
|
||||
updateData.setIpv4Address(networkInfo.getIpv4());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (!StringUtils.equals(networkInfo.getProvince(), oldInterfaceMsg.getProvince())) {
|
||||
updateData.setProvince(networkInfo.getProvince());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (!StringUtils.equals(networkInfo.getPublicIp(), oldInterfaceMsg.getPublicIp())) {
|
||||
updateData.setPublicIp(networkInfo.getPublicIp());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (!StringUtils.equals(networkInfo.getCarrier(), oldInterfaceMsg.getIsp())) {
|
||||
updateData.setIsp(networkInfo.getCarrier());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (!StringUtils.equals(networkInfo.getType(), oldInterfaceMsg.getInterfaceType())) {
|
||||
updateData.setInterfaceType(networkInfo.getType());
|
||||
needUpdate = true;
|
||||
}
|
||||
// 只有有字段变化时才执行更新
|
||||
if (needUpdate) {
|
||||
updateData.setClientId(clientId);
|
||||
updateData.setMacAddress(oldInterfaceMsg.getMacAddress());
|
||||
rmNetworkInterfaceService.updateRmNetworkInterfaceByMac(updateData);
|
||||
}
|
||||
}
|
||||
}
|
||||
}else{
|
||||
for (NetworkInfo networkInfo : networkInfoList) {
|
||||
// 查询该网卡信息是否存在
|
||||
RmNetworkInterface queryParam = new RmNetworkInterface();
|
||||
queryParam.setClientId(clientId);
|
||||
queryParam.setMacAddress(networkInfo.getMac());
|
||||
List<RmNetworkInterface> exits = rmNetworkInterfaceService.selectRmNetworkInterfaceList(queryParam);
|
||||
if(exits.isEmpty()){
|
||||
// 保存网卡信息
|
||||
RmNetworkInterface insertData = new RmNetworkInterface();
|
||||
// 业务ip和管理网ip
|
||||
insertData.setClientId(clientId);
|
||||
insertData.setIsp(networkInfo.getCarrier());
|
||||
insertData.setCity(networkInfo.getCity());
|
||||
insertData.setGateway(networkInfo.getGateway());
|
||||
insertData.setInterfaceName(networkInfo.getName());
|
||||
insertData.setIpv4Address(networkInfo.getIpv4());
|
||||
insertData.setMacAddress(networkInfo.getMac());
|
||||
insertData.setProvince(networkInfo.getProvince());
|
||||
insertData.setPublicIp(networkInfo.getPublicIp());
|
||||
insertData.setInterfaceType(networkInfo.getType());
|
||||
insertData.setCreateTime(createTime);
|
||||
rmNetworkInterfaceService.insertRmNetworkInterface(insertData);
|
||||
}else{
|
||||
RmNetworkInterface oldInterfaceMsg = exits.get(0);
|
||||
if(!StringUtils.equals(networkInfo.getName(),oldInterfaceMsg.getInterfaceName())
|
||||
|| !StringUtils.equals(networkInfo.getGateway(),oldInterfaceMsg.getGateway())){
|
||||
// 查询该网卡信息是否旧数据
|
||||
RmNetworkInterface query = new RmNetworkInterface();
|
||||
query.setClientId(clientId);
|
||||
query.setMacAddress(networkInfo.getMac());
|
||||
query.setNewFlag(999);
|
||||
List<RmNetworkInterface> oldExits = rmNetworkInterfaceService.selectRmNetworkInterfaceList(query);
|
||||
if(!oldExits.isEmpty()){
|
||||
// 先删除旧数据
|
||||
oldExits.forEach(oldMsg ->{
|
||||
rmNetworkInterfaceService.deleteRmNetworkInterfaceById(oldMsg.getId());
|
||||
});
|
||||
}
|
||||
// 先将已存在的改为旧数据
|
||||
RmNetworkInterface oldData = new RmNetworkInterface();
|
||||
oldData.setNewFlag(0);
|
||||
oldData.setClientId(clientId);
|
||||
oldData.setMacAddress(oldInterfaceMsg.getMacAddress());
|
||||
rmNetworkInterfaceService.updateRmNetworkInterfaceByMac(oldData);
|
||||
RmNetworkInterface insertData = new RmNetworkInterface();
|
||||
insertData.setClientId(clientId);
|
||||
insertData.setIsp(networkInfo.getCarrier());
|
||||
insertData.setCity(networkInfo.getCity());
|
||||
insertData.setGateway(networkInfo.getGateway());
|
||||
insertData.setInterfaceName(networkInfo.getName());
|
||||
insertData.setIpv4Address(networkInfo.getIpv4());
|
||||
insertData.setMacAddress(networkInfo.getMac());
|
||||
insertData.setProvince(networkInfo.getProvince());
|
||||
insertData.setPublicIp(networkInfo.getPublicIp());
|
||||
insertData.setInterfaceType(networkInfo.getType());
|
||||
rmNetworkInterfaceService.insertRmNetworkInterface(insertData);
|
||||
}else {
|
||||
RmNetworkInterface updateData = new RmNetworkInterface();
|
||||
// 检查其他字段是否需要更新
|
||||
boolean needUpdate = false;
|
||||
// 逐个字段比较是否需要更新
|
||||
if (!StringUtils.equals(networkInfo.getCity(), oldInterfaceMsg.getCity())) {
|
||||
updateData.setCity(networkInfo.getCity());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (!StringUtils.equals(networkInfo.getIpv4(), oldInterfaceMsg.getIpv4Address())) {
|
||||
updateData.setIpv4Address(networkInfo.getIpv4());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (!StringUtils.equals(networkInfo.getProvince(), oldInterfaceMsg.getProvince())) {
|
||||
updateData.setProvince(networkInfo.getProvince());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (!StringUtils.equals(networkInfo.getPublicIp(), oldInterfaceMsg.getPublicIp())) {
|
||||
updateData.setPublicIp(networkInfo.getPublicIp());
|
||||
needUpdate = true;
|
||||
updateData.setBindIp("0");
|
||||
// 修改绑定公网ip状态
|
||||
RmResourceRegistrationRemote updateParam = new RmResourceRegistrationRemote();
|
||||
updateParam.setClientId(clientId);
|
||||
updateParam.setMultiPublicIpStatus("0");
|
||||
remoteRevenueConfigService.updateStatusByResource(updateParam, SecurityConstants.INNER);
|
||||
}
|
||||
if (!StringUtils.equals(networkInfo.getCarrier(), oldInterfaceMsg.getIsp())) {
|
||||
updateData.setIsp(networkInfo.getCarrier());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (!StringUtils.equals(networkInfo.getType(), oldInterfaceMsg.getInterfaceType())) {
|
||||
updateData.setInterfaceType(networkInfo.getType());
|
||||
needUpdate = true;
|
||||
}
|
||||
// 只有有字段变化时才执行更新
|
||||
if (needUpdate) {
|
||||
updateData.setClientId(clientId);
|
||||
updateData.setMacAddress(oldInterfaceMsg.getMacAddress());
|
||||
rmNetworkInterfaceService.updateRmNetworkInterfaceByMac(updateData);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// 处理网卡信息
|
||||
processNetworkInterfaces(registerMsg, clientId, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -386,212 +186,8 @@ public class MessageHandler {
|
||||
rmAgentManagementService.insertRmAgentManagement(insertAgentUpdateData);
|
||||
}
|
||||
}
|
||||
// 时间戳转换
|
||||
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()){
|
||||
if(networkInfoList.size()==1){
|
||||
NetworkInfo networkInfo = networkInfoList.get(0);
|
||||
// 查询该网卡信息是否存在
|
||||
RmNetworkInterface queryParam = new RmNetworkInterface();
|
||||
queryParam.setClientId(clientId);
|
||||
queryParam.setMacAddress(networkInfo.getMac());
|
||||
queryParam.setNewFlag(1);
|
||||
List<RmNetworkInterface> exits = rmNetworkInterfaceService.selectRmNetworkInterfaceList(queryParam);
|
||||
if(exits.isEmpty()){
|
||||
// 保存网卡信息
|
||||
RmNetworkInterface insertData = new RmNetworkInterface();
|
||||
// 业务ip和管理网ip
|
||||
insertData.setBindIp("3");
|
||||
insertData.setClientId(clientId);
|
||||
insertData.setIsp(networkInfo.getCarrier());
|
||||
insertData.setCity(networkInfo.getCity());
|
||||
insertData.setGateway(networkInfo.getGateway());
|
||||
insertData.setInterfaceName(networkInfo.getName());
|
||||
insertData.setIpv4Address(networkInfo.getIpv4());
|
||||
insertData.setMacAddress(networkInfo.getMac());
|
||||
insertData.setProvince(networkInfo.getProvince());
|
||||
insertData.setPublicIp(networkInfo.getPublicIp());
|
||||
insertData.setInterfaceType(networkInfo.getType());
|
||||
insertData.setCreateTime(createTime);
|
||||
rmNetworkInterfaceService.insertRmNetworkInterface(insertData);
|
||||
}else{
|
||||
RmNetworkInterface oldInterfaceMsg = exits.get(0);
|
||||
if(!StringUtils.equals(networkInfo.getName(),oldInterfaceMsg.getInterfaceName())
|
||||
|| !StringUtils.equals(networkInfo.getGateway(),oldInterfaceMsg.getGateway())){
|
||||
// 查询该网卡信息是否旧数据
|
||||
RmNetworkInterface query = new RmNetworkInterface();
|
||||
query.setClientId(clientId);
|
||||
query.setMacAddress(oldInterfaceMsg.getMacAddress());
|
||||
query.setNewFlag(999);
|
||||
List<RmNetworkInterface> oldExits = rmNetworkInterfaceService.selectRmNetworkInterfaceList(query);
|
||||
if(!oldExits.isEmpty()){
|
||||
// 先删除旧数据
|
||||
oldExits.forEach(oldMsg ->{
|
||||
rmNetworkInterfaceService.deleteRmNetworkInterfaceById(oldMsg.getId());
|
||||
});
|
||||
}
|
||||
// 先将已存在的改为旧数据
|
||||
RmNetworkInterface oldData = new RmNetworkInterface();
|
||||
oldData.setNewFlag(0);
|
||||
oldData.setMacAddress(oldInterfaceMsg.getMacAddress());
|
||||
oldData.setClientId(clientId);
|
||||
rmNetworkInterfaceService.updateRmNetworkInterfaceByMac(oldData);
|
||||
RmNetworkInterface insertData = new RmNetworkInterface();
|
||||
insertData.setClientId(clientId);
|
||||
insertData.setIsp(networkInfo.getCarrier());
|
||||
insertData.setCity(networkInfo.getCity());
|
||||
insertData.setGateway(networkInfo.getGateway());
|
||||
insertData.setInterfaceName(networkInfo.getName());
|
||||
insertData.setIpv4Address(networkInfo.getIpv4());
|
||||
insertData.setMacAddress(networkInfo.getMac());
|
||||
insertData.setProvince(networkInfo.getProvince());
|
||||
insertData.setPublicIp(networkInfo.getPublicIp());
|
||||
insertData.setInterfaceType(networkInfo.getType());
|
||||
rmNetworkInterfaceService.insertRmNetworkInterface(insertData);
|
||||
}else {
|
||||
RmNetworkInterface updateData = new RmNetworkInterface();
|
||||
// 检查其他字段是否需要更新
|
||||
boolean needUpdate = false;
|
||||
// 逐个字段比较是否需要更新
|
||||
if (!StringUtils.equals(networkInfo.getCity(), oldInterfaceMsg.getCity())) {
|
||||
updateData.setCity(networkInfo.getCity());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (!StringUtils.equals(networkInfo.getIpv4(), oldInterfaceMsg.getIpv4Address())) {
|
||||
updateData.setIpv4Address(networkInfo.getIpv4());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (!StringUtils.equals(networkInfo.getProvince(), oldInterfaceMsg.getProvince())) {
|
||||
updateData.setProvince(networkInfo.getProvince());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (!StringUtils.equals(networkInfo.getPublicIp(), oldInterfaceMsg.getPublicIp())) {
|
||||
updateData.setPublicIp(networkInfo.getPublicIp());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (!StringUtils.equals(networkInfo.getCarrier(), oldInterfaceMsg.getIsp())) {
|
||||
updateData.setIsp(networkInfo.getCarrier());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (!StringUtils.equals(networkInfo.getType(), oldInterfaceMsg.getInterfaceType())) {
|
||||
updateData.setInterfaceType(networkInfo.getType());
|
||||
needUpdate = true;
|
||||
}
|
||||
// 只有有字段变化时才执行更新
|
||||
if (needUpdate) {
|
||||
updateData.setClientId(clientId);
|
||||
updateData.setMacAddress(oldInterfaceMsg.getMacAddress());
|
||||
rmNetworkInterfaceService.updateRmNetworkInterfaceByMac(updateData);
|
||||
}
|
||||
}
|
||||
}
|
||||
}else{
|
||||
for (NetworkInfo networkInfo : networkInfoList) {
|
||||
// 查询该网卡信息是否存在
|
||||
RmNetworkInterface queryParam = new RmNetworkInterface();
|
||||
queryParam.setMacAddress(networkInfo.getMac());
|
||||
queryParam.setClientId(clientId);
|
||||
List<RmNetworkInterface> exits = rmNetworkInterfaceService.selectRmNetworkInterfaceList(queryParam);
|
||||
if(exits.isEmpty()){
|
||||
// 保存网卡信息
|
||||
RmNetworkInterface insertData = new RmNetworkInterface();
|
||||
// 业务ip和管理网ip
|
||||
insertData.setClientId(clientId);
|
||||
insertData.setIsp(networkInfo.getCarrier());
|
||||
insertData.setCity(networkInfo.getCity());
|
||||
insertData.setGateway(networkInfo.getGateway());
|
||||
insertData.setInterfaceName(networkInfo.getName());
|
||||
insertData.setIpv4Address(networkInfo.getIpv4());
|
||||
insertData.setMacAddress(networkInfo.getMac());
|
||||
insertData.setProvince(networkInfo.getProvince());
|
||||
insertData.setPublicIp(networkInfo.getPublicIp());
|
||||
insertData.setInterfaceType(networkInfo.getType());
|
||||
insertData.setCreateTime(createTime);
|
||||
rmNetworkInterfaceService.insertRmNetworkInterface(insertData);
|
||||
}else{
|
||||
RmNetworkInterface oldInterfaceMsg = exits.get(0);
|
||||
if(!StringUtils.equals(networkInfo.getName(),oldInterfaceMsg.getInterfaceName())
|
||||
|| !StringUtils.equals(networkInfo.getGateway(),oldInterfaceMsg.getGateway())){
|
||||
// 查询该网卡信息是否旧数据
|
||||
RmNetworkInterface query = new RmNetworkInterface();
|
||||
query.setClientId(clientId);
|
||||
query.setMacAddress(oldInterfaceMsg.getMacAddress());
|
||||
query.setNewFlag(999);
|
||||
List<RmNetworkInterface> oldExits = rmNetworkInterfaceService.selectRmNetworkInterfaceList(query);
|
||||
if(!oldExits.isEmpty()){
|
||||
// 先删除旧数据
|
||||
oldExits.forEach(oldMsg ->{
|
||||
rmNetworkInterfaceService.deleteRmNetworkInterfaceById(oldMsg.getId());
|
||||
});
|
||||
}
|
||||
// 先将已存在的改为旧数据
|
||||
RmNetworkInterface oldData = new RmNetworkInterface();
|
||||
oldData.setNewFlag(0);
|
||||
oldData.setClientId(clientId);
|
||||
oldData.setMacAddress(oldInterfaceMsg.getMacAddress());
|
||||
rmNetworkInterfaceService.updateRmNetworkInterfaceByMac(oldData);
|
||||
RmNetworkInterface insertData = new RmNetworkInterface();
|
||||
insertData.setClientId(clientId);
|
||||
insertData.setIsp(networkInfo.getCarrier());
|
||||
insertData.setCity(networkInfo.getCity());
|
||||
insertData.setGateway(networkInfo.getGateway());
|
||||
insertData.setInterfaceName(networkInfo.getName());
|
||||
insertData.setIpv4Address(networkInfo.getIpv4());
|
||||
insertData.setMacAddress(networkInfo.getMac());
|
||||
insertData.setProvince(networkInfo.getProvince());
|
||||
insertData.setPublicIp(networkInfo.getPublicIp());
|
||||
insertData.setInterfaceType(networkInfo.getType());
|
||||
rmNetworkInterfaceService.insertRmNetworkInterface(insertData);
|
||||
}else {
|
||||
RmNetworkInterface updateData = new RmNetworkInterface();
|
||||
// 检查其他字段是否需要更新
|
||||
boolean needUpdate = false;
|
||||
// 逐个字段比较是否需要更新
|
||||
if (!StringUtils.equals(networkInfo.getCity(), oldInterfaceMsg.getCity())) {
|
||||
updateData.setCity(networkInfo.getCity());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (!StringUtils.equals(networkInfo.getIpv4(), oldInterfaceMsg.getIpv4Address())) {
|
||||
updateData.setIpv4Address(networkInfo.getIpv4());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (!StringUtils.equals(networkInfo.getProvince(), oldInterfaceMsg.getProvince())) {
|
||||
updateData.setProvince(networkInfo.getProvince());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (!StringUtils.equals(networkInfo.getPublicIp(), oldInterfaceMsg.getPublicIp())) {
|
||||
updateData.setPublicIp(networkInfo.getPublicIp());
|
||||
needUpdate = true;
|
||||
updateData.setBindIp("0");
|
||||
// 修改绑定公网ip状态
|
||||
RmResourceRegistrationRemote updateParam = new RmResourceRegistrationRemote();
|
||||
updateParam.setClientId(clientId);
|
||||
updateParam.setMultiPublicIpStatus("0");
|
||||
remoteRevenueConfigService.updateStatusByResource(updateParam, SecurityConstants.INNER);
|
||||
}
|
||||
if (!StringUtils.equals(networkInfo.getCarrier(), oldInterfaceMsg.getIsp())) {
|
||||
updateData.setIsp(networkInfo.getCarrier());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (!StringUtils.equals(networkInfo.getType(), oldInterfaceMsg.getInterfaceType())) {
|
||||
updateData.setInterfaceType(networkInfo.getType());
|
||||
needUpdate = true;
|
||||
}
|
||||
// 只有有字段变化时才执行更新
|
||||
if (needUpdate) {
|
||||
updateData.setClientId(clientId);
|
||||
updateData.setMacAddress(oldInterfaceMsg.getMacAddress());
|
||||
rmNetworkInterfaceService.updateRmNetworkInterfaceByMac(updateData);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// 处理网卡信息
|
||||
processNetworkInterfaces(registerMsg, clientId, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1420,4 +1016,158 @@ public class MessageHandler {
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 公共方法:处理网卡信息
|
||||
* @param registerMsg 注册消息
|
||||
* @param clientId 客户端ID
|
||||
* @param isRegister 是否为注册消息
|
||||
*/
|
||||
private void processNetworkInterfaces(RegisterMsgVo registerMsg, String clientId, boolean isRegister) {
|
||||
// 时间戳转换
|
||||
long timestamp = registerMsg.getTimestamp();
|
||||
long millis = timestamp * 1000;
|
||||
Date createTime = new Date(millis / 1000 * 1000);
|
||||
|
||||
List<NetworkInfo> networkInfoList = registerMsg.getNetworkInfo();
|
||||
if(networkInfoList.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
boolean isSingleInterface = networkInfoList.size() == 1;
|
||||
|
||||
for (NetworkInfo networkInfo : networkInfoList) {
|
||||
// 查询该网卡信息是否存在
|
||||
RmNetworkInterface queryParam = new RmNetworkInterface();
|
||||
queryParam.setClientId(clientId);
|
||||
queryParam.setMacAddress(networkInfo.getMac());
|
||||
queryParam.setNewFlag(1);
|
||||
List<RmNetworkInterface> exits = rmNetworkInterfaceService.selectRmNetworkInterfaceList(queryParam);
|
||||
|
||||
if(exits.isEmpty()) {
|
||||
// 新增网卡信息
|
||||
RmNetworkInterface insertData = new RmNetworkInterface();
|
||||
setNetworkInterfaceData(insertData, networkInfo, clientId);
|
||||
insertData.setCreateTime(createTime);
|
||||
// 设置bindIp
|
||||
if (isSingleInterface) {
|
||||
insertData.setBindIp("3");
|
||||
}
|
||||
rmNetworkInterfaceService.insertRmNetworkInterface(insertData);
|
||||
} else {
|
||||
// 更新网卡信息
|
||||
RmNetworkInterface oldInterfaceMsg = exits.get(0);
|
||||
|
||||
// 判断是否需要创建新记录
|
||||
boolean needCreateNew = !StringUtils.equals(networkInfo.getName(), oldInterfaceMsg.getInterfaceName())
|
||||
|| !StringUtils.equals(networkInfo.getGateway(), oldInterfaceMsg.getGateway());
|
||||
|
||||
if(needCreateNew) {
|
||||
// 清理旧的历史数据
|
||||
cleanOldRecords(clientId, networkInfo.getMac());
|
||||
|
||||
// 将已存在的记录标记为旧数据
|
||||
RmNetworkInterface oldData = new RmNetworkInterface();
|
||||
oldData.setNewFlag(0);
|
||||
oldData.setClientId(clientId);
|
||||
oldData.setMacAddress(oldInterfaceMsg.getMacAddress());
|
||||
rmNetworkInterfaceService.updateRmNetworkInterfaceByMac(oldData);
|
||||
|
||||
// 创建新记录
|
||||
RmNetworkInterface insertData = new RmNetworkInterface();
|
||||
setNetworkInterfaceData(insertData, networkInfo, clientId);
|
||||
rmNetworkInterfaceService.insertRmNetworkInterface(insertData);
|
||||
} else {
|
||||
// 更新现有记录
|
||||
updateNetworkInterface(networkInfo, clientId, oldInterfaceMsg, isSingleInterface, isRegister);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置网卡信息公共字段
|
||||
*/
|
||||
private void setNetworkInterfaceData(RmNetworkInterface networkInterface, NetworkInfo networkInfo, String clientId) {
|
||||
networkInterface.setClientId(clientId);
|
||||
networkInterface.setIsp(networkInfo.getCarrier());
|
||||
networkInterface.setCity(networkInfo.getCity());
|
||||
networkInterface.setGateway(networkInfo.getGateway());
|
||||
networkInterface.setInterfaceName(networkInfo.getName());
|
||||
networkInterface.setIpv4Address(networkInfo.getIpv4());
|
||||
networkInterface.setIpv6Address(networkInfo.getIpv6());
|
||||
networkInterface.setMacAddress(networkInfo.getMac());
|
||||
networkInterface.setProvince(networkInfo.getProvince());
|
||||
networkInterface.setPublicIp(networkInfo.getPublicIp());
|
||||
networkInterface.setInterfaceType(networkInfo.getType());
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理旧记录
|
||||
*/
|
||||
private void cleanOldRecords(String clientId, String macAddress) {
|
||||
RmNetworkInterface query = new RmNetworkInterface();
|
||||
query.setClientId(clientId);
|
||||
query.setMacAddress(macAddress);
|
||||
query.setNewFlag(999);
|
||||
List<RmNetworkInterface> oldExits = rmNetworkInterfaceService.selectRmNetworkInterfaceList(query);
|
||||
if(!oldExits.isEmpty()) {
|
||||
oldExits.forEach(oldMsg -> {
|
||||
rmNetworkInterfaceService.deleteRmNetworkInterfaceById(oldMsg.getId());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新网卡信息
|
||||
*/
|
||||
private void updateNetworkInterface(NetworkInfo networkInfo, String clientId,
|
||||
RmNetworkInterface oldInterfaceMsg, boolean isSingleInterface, boolean isRegister) {
|
||||
RmNetworkInterface updateData = new RmNetworkInterface();
|
||||
boolean needUpdate = false;
|
||||
|
||||
// 逐个字段比较是否需要更新
|
||||
if (!StringUtils.equals(networkInfo.getCity(), oldInterfaceMsg.getCity())) {
|
||||
updateData.setCity(networkInfo.getCity());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (!StringUtils.equals(networkInfo.getIpv4(), oldInterfaceMsg.getIpv4Address())) {
|
||||
updateData.setIpv4Address(networkInfo.getIpv4());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (!StringUtils.equals(networkInfo.getIpv6(), oldInterfaceMsg.getIpv6Address())) {
|
||||
updateData.setIpv6Address(networkInfo.getIpv6());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (!StringUtils.equals(networkInfo.getProvince(), oldInterfaceMsg.getProvince())) {
|
||||
updateData.setProvince(networkInfo.getProvince());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (!StringUtils.equals(networkInfo.getPublicIp(), oldInterfaceMsg.getPublicIp())) {
|
||||
updateData.setPublicIp(networkInfo.getPublicIp());
|
||||
needUpdate = true;
|
||||
// 特殊处理:非注册消息且多网卡时,更新公网IP状态
|
||||
if (!isSingleInterface && !isRegister) {
|
||||
updateData.setBindIp("0");
|
||||
RmResourceRegistrationRemote updateParam = new RmResourceRegistrationRemote();
|
||||
updateParam.setClientId(clientId);
|
||||
updateParam.setMultiPublicIpStatus("0");
|
||||
remoteRevenueConfigService.updateStatusByResource(updateParam, SecurityConstants.INNER);
|
||||
}
|
||||
}
|
||||
if (!StringUtils.equals(networkInfo.getCarrier(), oldInterfaceMsg.getIsp())) {
|
||||
updateData.setIsp(networkInfo.getCarrier());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (!StringUtils.equals(networkInfo.getType(), oldInterfaceMsg.getInterfaceType())) {
|
||||
updateData.setInterfaceType(networkInfo.getType());
|
||||
needUpdate = true;
|
||||
}
|
||||
|
||||
// 只有有字段变化时才执行更新
|
||||
if (needUpdate) {
|
||||
updateData.setClientId(clientId);
|
||||
updateData.setMacAddress(oldInterfaceMsg.getMacAddress());
|
||||
rmNetworkInterfaceService.updateRmNetworkInterfaceByMac(updateData);
|
||||
}
|
||||
}
|
||||
}
|
||||
+14
@@ -91,4 +91,18 @@ public interface IInitialBandwidthTrafficService
|
||||
* @return
|
||||
*/
|
||||
Map<String, Object> netInterfaceDroppedEcharts(InitialBandwidthTraffic initialBandwidthTraffic);
|
||||
|
||||
/**
|
||||
* 查询eth0 IPV4流量信息并封装为多折线ECharts图表数据
|
||||
* @param initialBandwidthTraffic
|
||||
* @return
|
||||
*/
|
||||
Map<String, Object> netInterfaceIpv4TrafficEcharts(InitialBandwidthTraffic initialBandwidthTraffic);
|
||||
|
||||
/**
|
||||
* 查询eth0 IPV6流量信息并封装为多折线ECharts图表数据
|
||||
* @param initialBandwidthTraffic
|
||||
* @return
|
||||
*/
|
||||
Map<String, Object> netInterfaceIpv6TrafficEcharts(InitialBandwidthTraffic initialBandwidthTraffic);
|
||||
}
|
||||
|
||||
+64
@@ -280,4 +280,68 @@ public class InitialBandwidthTrafficServiceImpl implements IInitialBandwidthTraf
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> netInterfaceIpv4TrafficEcharts(InitialBandwidthTraffic initialBandwidthTraffic) {
|
||||
// 流量信息
|
||||
List<InitialBandwidthTraffic> list = getListByTableName(initialBandwidthTraffic);
|
||||
try {
|
||||
String unit = SpeedUtils.calculateUnitWithStringTraffic(list, "ipv4InSpeed", "ipv4OutSpeed");
|
||||
if(initialBandwidthTraffic.getUnit() != null){
|
||||
unit = initialBandwidthTraffic.getUnit();
|
||||
}
|
||||
BigDecimal divisor = SpeedUtils.getDivisor(unit);
|
||||
Map<String, Function<InitialBandwidthTraffic, ?>> extractors = new LinkedHashMap<>();
|
||||
extractors.put("netInSpeedData", info ->
|
||||
info != null && info.getIpv4InSpeed() != null ?
|
||||
new BigDecimal(info.getIpv4InSpeed()).divide(divisor, 2, RoundingMode.HALF_UP) :
|
||||
0);
|
||||
|
||||
extractors.put("netOutSpeedData", info ->
|
||||
info != null && info.getIpv4OutSpeed() != null ?
|
||||
new BigDecimal(info.getIpv4OutSpeed()).divide(divisor, 2, RoundingMode.HALF_UP) :
|
||||
0);
|
||||
Map<String, Object> resultMap = EchartsDataUtils.buildEchartsDataAutoPadding(
|
||||
list, InitialBandwidthTraffic::getCreateTime, extractors,
|
||||
initialBandwidthTraffic.getStartTime(), initialBandwidthTraffic.getEndTime()
|
||||
);
|
||||
resultMap.put("unit", unit);
|
||||
return resultMap;
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
return new HashMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> netInterfaceIpv6TrafficEcharts(InitialBandwidthTraffic initialBandwidthTraffic) {
|
||||
// 流量信息
|
||||
List<InitialBandwidthTraffic> list = getListByTableName(initialBandwidthTraffic);
|
||||
try {
|
||||
String unit = SpeedUtils.calculateUnitWithStringTraffic(list, "ipv6InSpeed", "ipv6OutSpeed");
|
||||
if(initialBandwidthTraffic.getUnit() != null){
|
||||
unit = initialBandwidthTraffic.getUnit();
|
||||
}
|
||||
BigDecimal divisor = SpeedUtils.getDivisor(unit);
|
||||
Map<String, Function<InitialBandwidthTraffic, ?>> extractors = new LinkedHashMap<>();
|
||||
extractors.put("netInSpeedData", info ->
|
||||
info != null && info.getIpv6InSpeed() != null ?
|
||||
new BigDecimal(info.getIpv6InSpeed()).divide(divisor, 2, RoundingMode.HALF_UP) :
|
||||
0);
|
||||
|
||||
extractors.put("netOutSpeedData", info ->
|
||||
info != null && info.getIpv6OutSpeed() != null ?
|
||||
new BigDecimal(info.getIpv6OutSpeed()).divide(divisor, 2, RoundingMode.HALF_UP) :
|
||||
0);
|
||||
Map<String, Object> resultMap = EchartsDataUtils.buildEchartsDataAutoPadding(
|
||||
list, InitialBandwidthTraffic::getCreateTime, extractors,
|
||||
initialBandwidthTraffic.getStartTime(), initialBandwidthTraffic.getEndTime()
|
||||
);
|
||||
resultMap.put("unit", unit);
|
||||
return resultMap;
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
return new HashMap<>();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+59
-12
@@ -22,6 +22,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<result property="clientId" column="client_id"/>
|
||||
<result property="speed" column="speed"/>
|
||||
<result property="duplex" column="duplex"/>
|
||||
|
||||
</resultMap>
|
||||
<sql id="selectInitialBandwidthTrafficVo"> select id, name, mac, status, type, ipV4, in_dropped, out_dropped, in_speed, out_speed, create_time, update_time, create_by, update_by, client_id from initial_bandwidth_traffic </sql>
|
||||
<select id="selectInitialBandwidthTrafficList" parameterType="InitialBandwidthTraffic" resultMap="InitialBandwidthTrafficResult">
|
||||
@@ -143,12 +144,35 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
<select id="getNetInterfaceDetailsMsg" parameterType="InitialBandwidthTraffic" resultMap="InitialBandwidthTrafficResult">
|
||||
select id, `name`, mac, status, `type`, ipV4, in_dropped, out_dropped, in_speed, out_speed,
|
||||
total_in_speed, total_out_speed, create_time, update_time, create_by, update_by,
|
||||
client_id, duplex, speed,
|
||||
ipv4_in_speed, ipv4_out_speed, ipv6_in_speed, ipv6_out_speed,
|
||||
total_ipv4_in_speed, total_ipv4_out_speed, total_ipv6_in_speed, total_ipv6_out_speed,
|
||||
<select id="getNetInterfaceDetailsMsg" parameterType="InitialBandwidthTraffic" resultType="InitialBandwidthTraffic">
|
||||
select
|
||||
id,
|
||||
`name`,
|
||||
mac,
|
||||
status,
|
||||
`type`,
|
||||
ipV4,
|
||||
in_dropped as inDropped,
|
||||
out_dropped as outDropped,
|
||||
in_speed as inSpeed,
|
||||
out_speed as outSpeed,
|
||||
total_in_speed as totalInSpeed,
|
||||
total_out_speed as totalOutSpeed,
|
||||
create_time as createTime,
|
||||
update_time as updateTime,
|
||||
create_by as createBy,
|
||||
update_by as updateBy,
|
||||
client_id as clientId,
|
||||
duplex,
|
||||
speed,
|
||||
ipv4_in_speed as ipv4InSpeed,
|
||||
ipv4_out_speed as ipv4OutSpeed,
|
||||
ipv6_in_speed as ipv6InSpeed,
|
||||
ipv6_out_speed as ipv6OutSpeed,
|
||||
total_ipv4_in_speed as totalIpv4InSpeed,
|
||||
total_ipv4_out_speed as totalIpv4OutSpeed,
|
||||
total_ipv6_in_speed as totalIpv6InSpeed,
|
||||
total_ipv6_out_speed as totalIpv6OutSpeed,
|
||||
ipV6
|
||||
from ${tableName}
|
||||
<where>
|
||||
@@ -159,12 +183,35 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
limit 1
|
||||
</select>
|
||||
|
||||
<select id="getNetTrafficList" parameterType="InitialBandwidthTraffic" resultMap="InitialBandwidthTrafficResult">
|
||||
select id, `name`, mac, status, `type`, ipV4, in_dropped, out_dropped, in_speed, out_speed,
|
||||
total_in_speed, total_out_speed, create_time, update_time, create_by, update_by,
|
||||
client_id, duplex, speed,
|
||||
ipv4_in_speed, ipv4_out_speed, ipv6_in_speed, ipv6_out_speed,
|
||||
total_ipv4_in_speed, total_ipv4_out_speed, total_ipv6_in_speed, total_ipv6_out_speed,
|
||||
<select id="getNetTrafficList" parameterType="InitialBandwidthTraffic" resultType="InitialBandwidthTraffic">
|
||||
select
|
||||
id,
|
||||
`name`,
|
||||
mac,
|
||||
status,
|
||||
`type`,
|
||||
ipV4,
|
||||
in_dropped as inDropped,
|
||||
out_dropped as outDropped,
|
||||
in_speed as inSpeed,
|
||||
out_speed as outSpeed,
|
||||
total_in_speed as totalInSpeed,
|
||||
total_out_speed as totalOutSpeed,
|
||||
create_time as createTime,
|
||||
update_time as updateTime,
|
||||
create_by as createBy,
|
||||
update_by as updateBy,
|
||||
client_id as clientId,
|
||||
duplex,
|
||||
speed,
|
||||
ipv4_in_speed as ipv4InSpeed,
|
||||
ipv4_out_speed as ipv4OutSpeed,
|
||||
ipv6_in_speed as ipv6InSpeed,
|
||||
ipv6_out_speed as ipv6OutSpeed,
|
||||
total_ipv4_in_speed as totalIpv4InSpeed,
|
||||
total_ipv4_out_speed as totalIpv4OutSpeed,
|
||||
total_ipv6_in_speed as totalIpv6InSpeed,
|
||||
total_ipv6_out_speed as totalIpv6OutSpeed,
|
||||
ipV6
|
||||
from ${tableName}
|
||||
<where>
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
<result property="macAddress" column="mac_address" />
|
||||
<result property="interfaceType" column="interface_type" />
|
||||
<result property="ipv4Address" column="ipv4_address" />
|
||||
<result property="ipv6Address" column="ipv6_address" />
|
||||
<result property="gateway" column="gateway" />
|
||||
<result property="createTime" column="create_time" />
|
||||
<result property="updateTime" column="update_time" />
|
||||
@@ -25,7 +26,7 @@
|
||||
</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
|
||||
select id, client_id, isp, province, city, public_ip, interface_name, mac_address, interface_type, ipv4_address, ipv6_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">
|
||||
@@ -70,6 +71,7 @@
|
||||
<if test="macAddress != null">mac_address,</if>
|
||||
<if test="interfaceType != null">interface_type,</if>
|
||||
<if test="ipv4Address != null">ipv4_address,</if>
|
||||
<if test="ipv6Address != null">ipv6_address,</if>
|
||||
<if test="gateway != null">gateway,</if>
|
||||
<if test="createTime != null">create_time,</if>
|
||||
<if test="updateTime != null">update_time,</if>
|
||||
@@ -88,6 +90,7 @@
|
||||
<if test="macAddress != null">#{macAddress},</if>
|
||||
<if test="interfaceType != null">#{interfaceType},</if>
|
||||
<if test="ipv4Address != null">#{ipv4Address},</if>
|
||||
<if test="ipv6Address != null">#{ipv6Address},</if>
|
||||
<if test="gateway != null">#{gateway},</if>
|
||||
<if test="createTime != null">#{createTime},</if>
|
||||
<if test="updateTime != null">#{updateTime},</if>
|
||||
@@ -110,6 +113,7 @@
|
||||
<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="ipv6Address != null">ipv6_address = #{ipv6Address},</if>
|
||||
<if test="gateway != null">gateway = #{gateway},</if>
|
||||
<if test="createTime != null">create_time = #{createTime},</if>
|
||||
<if test="updateTime != null">update_time = #{updateTime},</if>
|
||||
@@ -142,6 +146,7 @@
|
||||
<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="ipv6Address != null">ipv6_address = #{ipv6Address},</if>
|
||||
<if test="gateway != null">gateway = #{gateway},</if>
|
||||
<if test="createTime != null">create_time = #{createTime},</if>
|
||||
<if test="updateTime != null">update_time = #{updateTime},</if>
|
||||
|
||||
Reference in New Issue
Block a user