From 506fd1dcc1a767d6a441c98b0d87a2e56f868400 Mon Sep 17 00:00:00 2001 From: gaoyutao Date: Fri, 29 Aug 2025 19:17:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=97=B6=E9=97=B4=E6=88=B3?= =?UTF-8?q?=E4=B8=8E=E6=95=B0=E6=8D=AE=E8=A1=A8=E5=85=A5=E5=BA=93=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E5=B7=AE1=E7=A7=92=E9=97=AE=E9=A2=98=EF=BC=8C?= =?UTF-8?q?=E5=BC=80=E5=8F=91=E9=87=8D=E6=96=B0=E8=AE=A1=E7=AE=97=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=EF=BC=8C=E4=BA=A4=E6=8D=A2=E6=9C=BA=E8=AF=A6=E6=83=85?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=B8=9A=E5=8A=A1=E4=BB=A3=E7=A0=81=EF=BC=8C?= =?UTF-8?q?=E4=B8=9A=E5=8A=A1=E5=90=8D=E7=A7=B0=EF=BC=8C=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E5=90=84=E4=B8=AA=E8=A1=A8=E4=B8=9A=E5=8A=A1=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E4=B8=8D=E5=8C=B9=E9=85=8D=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/core/web/domain/BaseEntity.java | 6 +- .../system/config/TableScheduleConfig.java | 2 +- .../InitialSwitchInfoDetailsController.java | 11 + .../domain/InitialSwitchInfoDetails.java | 4 + .../IInitialSwitchInfoDetailsService.java | 6 + .../EpsInitialTrafficDataServiceImpl.java | 13 +- .../impl/EpsNodeBandwidthServiceImpl.java | 2 +- .../InitialSwitchInfoDetailsServiceImpl.java | 113 ++++++++- .../mapper/system/AllInterfaceNameMapper.xml | 7 +- .../system/EpsInitialTrafficDataMapper.xml | 4 +- .../system/InitialSwitchInfoDetailsMapper.xml | 232 +++++++++++------- .../rocketmq/consumer/RocketMsgListener.java | 62 +++-- .../InitialBandwidthTrafficMapper.xml | 8 +- 13 files changed, 341 insertions(+), 129 deletions(-) diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/web/domain/BaseEntity.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/web/domain/BaseEntity.java index d1c9fe9..4b386eb 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/web/domain/BaseEntity.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/web/domain/BaseEntity.java @@ -49,7 +49,7 @@ public class BaseEntity implements Serializable */ private String[] properties; /** 时间戳 */ - private String timestamp; + private long timestamp; /** 请求参数 */ @JsonInclude(JsonInclude.Include.NON_EMPTY) @@ -153,11 +153,11 @@ public class BaseEntity implements Serializable this.params = params; } - public String getTimestamp() { + public long getTimestamp() { return timestamp; } - public void setTimestamp(String timestamp) { + public void setTimestamp(long timestamp) { this.timestamp = timestamp; } } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/config/TableScheduleConfig.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/config/TableScheduleConfig.java index eaf85dc..31791cd 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/config/TableScheduleConfig.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/config/TableScheduleConfig.java @@ -69,7 +69,7 @@ public class TableScheduleConfig { @Scheduled(cron = "0 0 0 1 * ?", zone = "Asia/Shanghai") public void calculateMonthlyBandwidthTasks() { // 获取上个月的日期范围 - LocalDate lastMonth = LocalDate.now(ZoneId.of("Asia/Shanghai")).minusMonths(0); + LocalDate lastMonth = LocalDate.now(ZoneId.of("Asia/Shanghai")).minusMonths(1); LocalDate firstDayOfMonth = lastMonth.withDayOfMonth(1); LocalDate lastDayOfMonth = lastMonth.withDayOfMonth(lastMonth.lengthOfMonth()); diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/InitialSwitchInfoDetailsController.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/InitialSwitchInfoDetailsController.java index 5531120..c7135dc 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/InitialSwitchInfoDetailsController.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/InitialSwitchInfoDetailsController.java @@ -106,4 +106,15 @@ public class InitialSwitchInfoDetailsController extends BaseController { return initialSwitchInfoDetailsService.autoSaveSwitchTraffic(initialSwitchInfoDetails); } + /** + * 获取交换机监控信息详细信息 + */ + @RequiresPermissions("system:switchInfoDetails:query") + @GetMapping(value = "recalculateSwitch/{id}") + public AjaxResult recalculateSwitch(@PathVariable("id") Long id) + { + initialSwitchInfoDetailsService.recalculateSwitch95Bandwidth(id); + return success(); + } + } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/InitialSwitchInfoDetails.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/InitialSwitchInfoDetails.java index e048161..22db930 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/InitialSwitchInfoDetails.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/InitialSwitchInfoDetails.java @@ -76,6 +76,10 @@ public class InitialSwitchInfoDetails extends BaseEntity /** 交换机硬件SN */ @Excel(name = "交换机硬件SN") private String switchSn; + /** 业务代码 */ + private String businessCode; + /** 业务名称 */ + private String businessName; /** 数据集合 */ private List dataList; diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/IInitialSwitchInfoDetailsService.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/IInitialSwitchInfoDetailsService.java index 1535d2a..da4c9d1 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/IInitialSwitchInfoDetailsService.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/IInitialSwitchInfoDetailsService.java @@ -72,4 +72,10 @@ public interface IInitialSwitchInfoDetailsService * @return 流量数据列表 */ void calculateSwitch95BandwidthDaily(InitialSwitchInfoDetails queryParam, String dailyStartTime, String dailyEndTime); + + /** + * 重新计算交换机95带宽值 + * @param id + */ + void recalculateSwitch95Bandwidth(Long id); } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/EpsInitialTrafficDataServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/EpsInitialTrafficDataServiceImpl.java index ec61a4b..989499e 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/EpsInitialTrafficDataServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/EpsInitialTrafficDataServiceImpl.java @@ -377,8 +377,10 @@ public class EpsInitialTrafficDataServiceImpl implements EpsInitialTrafficDataSe bandwidth.setBusinessName(data.getBusinessName()); bandwidth.setResourceType(data.getResourceType()); bandwidth.setBandwidthType(data.getBandwidthType()); - bandwidth.setBandwidthResult(result); bandwidth.setCreateTime(DateUtils.parseDate(dateTime)); + // 查询此条数据是否存在 + List exitsList = epsNodeBandwidthMapper.selectEpsNodeBandwidthList(bandwidth); + bandwidth.setBandwidthResult(result); switch (data.getBandwidthType()){ case "1": bandwidth.setBandwidth95Daily(result); @@ -404,6 +406,13 @@ public class EpsInitialTrafficDataServiceImpl implements EpsInitialTrafficDataSe default: throw new IllegalArgumentException("Unknown bandwidthType: " + data.getBandwidthType()); } - epsNodeBandwidthMapper.insertEpsNodeBandwidth(bandwidth); + if(!exitsList.isEmpty()){ + bandwidth.setUpdateTime(DateUtils.getNowDate()); + bandwidth.setId(exitsList.get(0).getId()); + epsNodeBandwidthMapper.updateEpsNodeBandwidth(bandwidth); + }else{ + bandwidth.setUpdateTime(DateUtils.getNowDate()); + epsNodeBandwidthMapper.insertEpsNodeBandwidth(bandwidth); + } } } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/EpsNodeBandwidthServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/EpsNodeBandwidthServiceImpl.java index 2483d58..298590d 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/EpsNodeBandwidthServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/EpsNodeBandwidthServiceImpl.java @@ -197,7 +197,7 @@ public class EpsNodeBandwidthServiceImpl implements IEpsNodeBandwidthService revenueConfig.setHardwareSn(epsNodeBandwidth.getHardwareSn()); List changedList = epsServerRevenueConfigMapper.selectEpsServerRevenueConfigList(revenueConfig); - if (!changedList.isEmpty()) { + if (!changedList.isEmpty() && changedList.size() == 1) { EpsServerRevenueConfig epsServerRevenueConfig = changedList.get(0); if (epsServerRevenueConfig.getUpdateTime() != null && epsNodeBandwidth.getStartTime() != null && diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/InitialSwitchInfoDetailsServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/InitialSwitchInfoDetailsServiceImpl.java index 62b33d4..28aaf8d 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/InitialSwitchInfoDetailsServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/InitialSwitchInfoDetailsServiceImpl.java @@ -13,6 +13,10 @@ import org.springframework.stereotype.Service; import java.math.BigDecimal; import java.math.RoundingMode; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; import java.util.*; import java.util.function.Function; import java.util.stream.Collectors; @@ -25,8 +29,9 @@ import java.util.stream.Collectors; */ @Service @Slf4j -public class InitialSwitchInfoDetailsServiceImpl implements IInitialSwitchInfoDetailsService +public class InitialSwitchInfoDetailsServiceImpl implements IInitialSwitchInfoDetailsService { + private static final DateTimeFormatter TIME_FORMAT = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); @Autowired private InitialSwitchInfoDetailsMapper initialSwitchInfoDetailsMapper; @Autowired @@ -136,6 +141,21 @@ public class InitialSwitchInfoDetailsServiceImpl implements IInitialSwitchInfoDe details.setInterfaceDeviceType(management.getConnectedDeviceType()); details.setServerName(management.getServerName()); details.setServerPort(management.getServerPort()); + details.setServerSn(management.getServerSn()); + // 根据服务器sn查询业务 + if(management.getServerSn() != null){ + EpsServerRevenueConfig epsServerRevenueConfig = new EpsServerRevenueConfig(); + epsServerRevenueConfig.setHardwareSn(management.getServerSn()); + List businessList = epsServerRevenueConfigMapper.selectEpsServerRevenueConfigList(epsServerRevenueConfig); + if(!businessList.isEmpty()){ + EpsServerRevenueConfig revenueConfig = businessList.get(0); + details.setBusinessName(revenueConfig.getBusinessName()); + details.setBusinessCode(revenueConfig.getBusinessCode()); + } + }else { + details.setBusinessCode(null); + details.setBusinessName(null); + } } // id自增 details.setId(null); @@ -199,7 +219,20 @@ public class InitialSwitchInfoDetailsServiceImpl implements IInitialSwitchInfoDe record.setInterfaceDeviceType(data.getInterfaceDeviceType()); record.setSwitchName(data.getSwitchName()); record.setSwitchSn(data.getSwitchSn()); - + // 根据服务器sn查询业务 + if(data.getServerSn() != null){ + EpsServerRevenueConfig epsServerRevenueConfig = new EpsServerRevenueConfig(); + epsServerRevenueConfig.setHardwareSn(data.getServerSn()); + List businessList = epsServerRevenueConfigMapper.selectEpsServerRevenueConfigList(epsServerRevenueConfig); + if(!businessList.isEmpty()){ + EpsServerRevenueConfig revenueConfig = businessList.get(0); + record.setBusinessName(revenueConfig.getBusinessName()); + record.setBusinessCode(revenueConfig.getBusinessCode()); + } + }else { + record.setBusinessCode(null); + record.setBusinessName(null); + } // 判断是否需要更新 if (existingNameMap.containsKey(name)) { AllInterfaceName existingRecord = existingNameMap.get(name); @@ -232,6 +265,8 @@ public class InitialSwitchInfoDetailsServiceImpl implements IInitialSwitchInfoDe !Objects.equals(oldRecord.getServerPort(), newRecord.getServerPort()) || !Objects.equals(oldRecord.getInterfaceDeviceType(), newRecord.getInterfaceDeviceType()) || !Objects.equals(oldRecord.getSwitchName(), newRecord.getSwitchName()) || + !Objects.equals(oldRecord.getBusinessCode(), newRecord.getBusinessCode()) || + !Objects.equals(oldRecord.getBusinessName(), newRecord.getBusinessName()) || !Objects.equals(oldRecord.getSwitchSn(), newRecord.getSwitchSn()); } @@ -247,6 +282,63 @@ public class InitialSwitchInfoDetailsServiceImpl implements IInitialSwitchInfoDe }); } + /** + * 重新计算交换机95带宽值 + * @param id + */ + @Override + public void recalculateSwitch95Bandwidth(Long id) { + // 获取需要重新计算的信息 + EpsNodeBandwidth epsNodeBandwidth = epsNodeBandwidthMapper.selectEpsNodeBandwidthById(id); + // 将Date转换为LocalDateTime + LocalDateTime createDateTime = epsNodeBandwidth.getCreateTime().toInstant() + .atZone(ZoneId.systemDefault()) + .toLocalDateTime(); + // 获取当天的开始时间(00:00:00) + String dailyStartTime = createDateTime.with(LocalTime.MIN) + .format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); + + // 获取当天的结束时间(23:59:59) + String dailyEndTime = createDateTime.with(LocalTime.MAX) + .withNano(0) // 去除纳秒部分 + .format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); + InitialSwitchInfoDetails switchInfoDetails = new InitialSwitchInfoDetails(); + switchInfoDetails.setStartTime(dailyStartTime); + switchInfoDetails.setEndTime(dailyEndTime); + switchInfoDetails.setSwitchSn(epsNodeBandwidth.getSwitchSn()); + switchInfoDetails.setSwitchName(epsNodeBandwidth.getUplinkSwitch()); + switchInfoDetails.setServerSn(epsNodeBandwidth.getHardwareSn()); + switchInfoDetails.setInterfaceDeviceType(epsNodeBandwidth.getInterfaceLinkDeviceType()); + switchInfoDetails.setName(epsNodeBandwidth.getInterfaceName()); + switchInfoDetails.setBusinessCode(epsNodeBandwidth.getBusinessId()); + switchInfoDetails.setBusinessName(epsNodeBandwidth.getBusinessName()); + List dataList = initialSwitchInfoDetailsMapper + .selectInitialSwitchInfoDetailsList(switchInfoDetails); + // 1. 提取并转换带宽值 + List speedsInMbps = dataList.stream() + .map(data -> { + // 根据 interfaceDeviceType 选择 inSpeed 或 outSpeed + String speed = ("1".equals(data.getInterfaceDeviceType())) ? + data.getInSpeed() + "" : data.getOutSpeed() + ""; + // 如果 speed 是纯数字,补充单位 "B/S"(Bytes/s) + if (speed.matches("^\\d+(\\.\\d+)?$")) { + speed += " B/S"; + } + return CalculateUtil.parseSpeedToMbps(speed); + }) + .sorted() + .collect(Collectors.toList()); + + // 2. 计算95百分位 + BigDecimal percentile95 = CalculateUtil.calculatePercentile(speedsInMbps, 0.95); + + // 3. 保存结果 + InitialSwitchInfoDetails switchInfo = dataList.get(0); + switchInfo.setResourceType("2"); + switchInfo.setBandwidthType(epsNodeBandwidth.getBandwidthType()); + saveSwitchBandwidthResult(switchInfo, percentile95, dailyStartTime); + } + /** * 处理单个交换机的带宽计算 */ @@ -435,16 +527,20 @@ public class InitialSwitchInfoDetailsServiceImpl implements IInitialSwitchInfoDe BigDecimal result, String dateTime) { EpsNodeBandwidth bandwidth = new EpsNodeBandwidth(); + bandwidth.setBusinessName(data.getBusinessName()); + bandwidth.setBusinessId(data.getBusinessCode()); bandwidth.setHardwareSn(data.getServerSn()); bandwidth.setSwitchSn(data.getSwitchSn()); bandwidth.setNodeName(data.getServerName()); bandwidth.setUplinkSwitch(data.getSwitchName()); bandwidth.setInterfaceName(data.getName()); - bandwidth.setBandwidthResult(result); bandwidth.setResourceType(data.getResourceType()); bandwidth.setBandwidthType(data.getBandwidthType()); - bandwidth.setBandwidthResult(result); + bandwidth.setInterfaceLinkDeviceType(data.getInterfaceDeviceType()); bandwidth.setCreateTime(DateUtils.parseDate(dateTime)); + // 查询此条数据是否存在 + List exitsList = epsNodeBandwidthMapper.selectEpsNodeBandwidthList(bandwidth); + bandwidth.setBandwidthResult(result); switch (data.getBandwidthType()){ case "1": bandwidth.setBandwidth95Daily(result); @@ -470,6 +566,13 @@ public class InitialSwitchInfoDetailsServiceImpl implements IInitialSwitchInfoDe default: throw new IllegalArgumentException("Unknown bandwidthType: " + data.getBandwidthType()); } - epsNodeBandwidthMapper.insertEpsNodeBandwidth(bandwidth); + if(!exitsList.isEmpty()){ + bandwidth.setUpdateTime(DateUtils.getNowDate()); + bandwidth.setId(exitsList.get(0).getId()); + epsNodeBandwidthMapper.updateEpsNodeBandwidth(bandwidth); + }else{ + bandwidth.setUpdateTime(DateUtils.getNowDate()); + epsNodeBandwidthMapper.insertEpsNodeBandwidth(bandwidth); + } } } diff --git a/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/AllInterfaceNameMapper.xml b/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/AllInterfaceNameMapper.xml index a67c4a8..f0f8cbd 100644 --- a/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/AllInterfaceNameMapper.xml +++ b/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/AllInterfaceNameMapper.xml @@ -189,13 +189,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" group by switch_sn - - + + + UPDATE all_interface_name SET business_code = #{item.businessCode}, business_name = #{item.businessName}, - update_time = now(), + update_time = NOW(), client_id = #{item.clientId}, device_sn = #{item.deviceSn}, node_name = #{item.nodeName}, diff --git a/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/EpsInitialTrafficDataMapper.xml b/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/EpsInitialTrafficDataMapper.xml index f22d026..e210fe4 100644 --- a/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/EpsInitialTrafficDataMapper.xml +++ b/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/EpsInitialTrafficDataMapper.xml @@ -22,7 +22,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" node_name varchar(200) COMMENT '服务器名称', revenue_method varchar(10) COMMENT '收益方式(1.流量,2包端)', package_bandwidth DECIMAL(10,2) COMMENT '包端带宽值', - create_time DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + create_time DATETIME COMMENT '创建时间', update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间', create_by VARCHAR(50) COMMENT '创建人', update_by VARCHAR(50) COMMENT '修改人', @@ -45,7 +45,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" `out_dropped` DECIMAL(5,2) COMMENT '出站丢包率(%)', `in_speed` VARCHAR(20) COMMENT '接收带宽(Mbps)', `out_speed` VARCHAR(20) COMMENT '发送带宽(Mbps)', - create_time DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + create_time DATETIME COMMENT '创建时间', update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间', create_by VARCHAR(50) COMMENT '创建人', update_by VARCHAR(50) COMMENT '修改人', diff --git a/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/InitialSwitchInfoDetailsMapper.xml b/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/InitialSwitchInfoDetailsMapper.xml index c54c5b1..620d7ed 100644 --- a/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/InitialSwitchInfoDetailsMapper.xml +++ b/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/InitialSwitchInfoDetailsMapper.xml @@ -3,133 +3,175 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> - - + + - - - - - - - - - - + + + + + + + + + + + + - - - - - + + + + + + + + + + + - - select id, client_id, name, in_bytes, out_bytes, status, type, in_speed, out_speed, create_by, update_by, create_time, update_time, switch_name, interface_device_type, server_name, server_port, server_sn, switch_sn from initial_switch_info_details + + select id, node_name, hardware_sn, bandwidth_type, bandwidth_result, bandwidth_95_daily, bandwidth_95_monthly, avg_monthly_bandwidth_95, package_bandwidth_daily, customer_id, customer_name, service_number, uplink_switch, create_time, update_time, creator_id, creator_name, switch_sn, interface_name, resource_type, interface_link_device_type, effective_bandwidth_95_daily, effective_bandwidth_95_monthly, effective_avg_monthly_bandwidth_95, business_name, business_id, remark1 from eps_node_bandwidth - + + + and node_name like concat('%', #{nodeName}, '%') + and hardware_sn = #{hardwareSn} + and bandwidth_type = #{bandwidthType} + and bandwidth_result = #{bandwidthResult} + and bandwidth_95_daily = #{bandwidth95Daily} + and bandwidth_95_monthly = #{bandwidth95Monthly} + and avg_monthly_bandwidth_95 = #{avgMonthlyBandwidth95} + and package_bandwidth_daily = #{packageBandwidthDaily} + and customer_id = #{customerId} + and customer_name like concat('%', #{customerName}, '%') + and service_number = #{serviceNumber} + and uplink_switch like concat('%', #{uplinkSwitch}, '%') + and creator_id = #{creatorId} + and creator_name like concat('%', #{creatorName}, '%') and switch_sn = #{switchSn} + and interface_name like concat('%', #{interfaceName}, '%') + and resource_type = #{resourceType} + and interface_link_device_type = #{interfaceLinkDeviceType} + and effective_bandwidth_95_daily = #{effectiveBandwidth95Daily} + and effective_bandwidth_95_monthly = #{effectiveBandwidth95Monthly} + and effective_avg_monthly_bandwidth_95 = #{effectiveAvgMonthlyBandwidth95} + and business_name like concat('%', #{businessName}, '%') + and business_id = #{businessId} + and remark1 = #{remark1} - - + where id = #{id} - - insert into initial_switch_info_details + + insert into eps_node_bandwidth - client_id, - name, - in_bytes, - out_bytes, - status, - type, - in_speed, - out_speed, - create_by, - update_by, + node_name, + hardware_sn, + bandwidth_type, + bandwidth_result, + bandwidth_95_daily, + bandwidth_95_monthly, + avg_monthly_bandwidth_95, + package_bandwidth_daily, + customer_id, + customer_name, + service_number, + uplink_switch, create_time, update_time, - switch_name, - interface_device_type, - server_name, - server_port, - server_sn, + creator_id, + creator_name, switch_sn, - + interface_name, + resource_type, + interface_link_device_type, + effective_bandwidth_95_daily, + effective_bandwidth_95_monthly, + effective_avg_monthly_bandwidth_95, + business_name, + business_id, + remark1, + - #{clientId}, - #{name}, - #{inBytes}, - #{outBytes}, - #{status}, - #{type}, - #{inSpeed}, - #{outSpeed}, - #{createBy}, - #{updateBy}, + #{nodeName}, + #{hardwareSn}, + #{bandwidthType}, + #{bandwidthResult}, + #{bandwidth95Daily}, + #{bandwidth95Monthly}, + #{avgMonthlyBandwidth95}, + #{packageBandwidthDaily}, + #{customerId}, + #{customerName}, + #{serviceNumber}, + #{uplinkSwitch}, #{createTime}, #{updateTime}, - #{switchName}, - #{interfaceDeviceType}, - #{serverName}, - #{serverPort}, - #{serverSn}, + #{creatorId}, + #{creatorName}, #{switchSn}, - + #{interfaceName}, + #{resourceType}, + #{interfaceLinkDeviceType}, + #{effectiveBandwidth95Daily}, + #{effectiveBandwidth95Monthly}, + #{effectiveAvgMonthlyBandwidth95}, + #{businessName}, + #{businessId}, + #{remark1}, + - - update initial_switch_info_details + + update eps_node_bandwidth - client_id = #{clientId}, - name = #{name}, - in_bytes = #{inBytes}, - out_bytes = #{outBytes}, - status = #{status}, - type = #{type}, - in_speed = #{inSpeed}, - out_speed = #{outSpeed}, - create_by = #{createBy}, - update_by = #{updateBy}, + node_name = #{nodeName}, + hardware_sn = #{hardwareSn}, + bandwidth_type = #{bandwidthType}, + bandwidth_result = #{bandwidthResult}, + bandwidth_95_daily = #{bandwidth95Daily}, + bandwidth_95_monthly = #{bandwidth95Monthly}, + avg_monthly_bandwidth_95 = #{avgMonthlyBandwidth95}, + package_bandwidth_daily = #{packageBandwidthDaily}, + customer_id = #{customerId}, + customer_name = #{customerName}, + service_number = #{serviceNumber}, + uplink_switch = #{uplinkSwitch}, create_time = #{createTime}, update_time = #{updateTime}, - switch_name = #{switchName}, - interface_device_type = #{interfaceDeviceType}, - server_name = #{serverName}, - server_port = #{serverPort}, - server_sn = #{serverSn}, + creator_id = #{creatorId}, + creator_name = #{creatorName}, switch_sn = #{switchSn}, + interface_name = #{interfaceName}, + resource_type = #{resourceType}, + interface_link_device_type = #{interfaceLinkDeviceType}, + effective_bandwidth_95_daily = #{effectiveBandwidth95Daily}, + effective_bandwidth_95_monthly = #{effectiveBandwidth95Monthly}, + effective_avg_monthly_bandwidth_95 = #{effectiveAvgMonthlyBandwidth95}, + business_name = #{businessName}, + business_id = #{businessId}, + remark1 = #{remark1}, where id = #{id} - - delete from initial_switch_info_details where id = #{id} + + delete from eps_node_bandwidth where id = #{id} - - delete from initial_switch_info_details where id in + + delete from eps_node_bandwidth where id in #{id} @@ -176,6 +218,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" server_port, server_sn, switch_sn, + business_code, + business_name, create_by, update_by, create_time, @@ -198,6 +242,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{item.serverPort}, #{item.serverSn}, #{item.switchSn}, + #{item.businessCode}, + #{item.businessName}, #{item.createBy}, #{item.updateBy}, diff --git a/ruoyi-rocketmq/src/main/java/com/ruoyi/rocketmq/consumer/RocketMsgListener.java b/ruoyi-rocketmq/src/main/java/com/ruoyi/rocketmq/consumer/RocketMsgListener.java index 293923f..c7e64c8 100644 --- a/ruoyi-rocketmq/src/main/java/com/ruoyi/rocketmq/consumer/RocketMsgListener.java +++ b/ruoyi-rocketmq/src/main/java/com/ruoyi/rocketmq/consumer/RocketMsgListener.java @@ -23,6 +23,7 @@ import org.springframework.util.CollectionUtils; import java.io.UnsupportedEncodingException; import java.math.BigDecimal; import java.math.RoundingMode; +import java.util.Date; import java.util.List; import java.util.Map; import java.util.function.Function; @@ -94,9 +95,6 @@ public class RocketMsgListener implements MessageListenerConcurrently { if (MessageCodeEnum.AGENT_MESSAGE_TOPIC.getCode().equals(topic)) { // 拿到信息 DeviceMessage message = JSON.parseObject(body, DeviceMessage.class); - String duringTime = DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss",message.getReceiveTime()); - message.setDuringTime(duringTime); - message.setReceiveTime(DateUtils.dateTime("yyyy-MM-dd HH:mm:ss",duringTime)); switch (message.getDataType()){ case "NET": handleNetMessage(message); @@ -164,18 +162,23 @@ public class RocketMsgListener implements MessageListenerConcurrently { private void handleNetMessage(DeviceMessage message) { List interfaces = JsonDataParser.parseJsonData(message.getData(), InitialBandwidthTraffic.class); if(!interfaces.isEmpty()){ + // 时间戳转换 + long timestamp = interfaces.get(0).getTimestamp(); + long millis = timestamp < 1_000_000_000L ? timestamp * 1000 : timestamp; + Date createTime = new Date(millis / 1000 * 1000); // 去除毫秒 + String timeStr = DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss",createTime); InitialBandwidthTraffic data = new InitialBandwidthTraffic(); interfaces.forEach(iface -> { iface.setClientId(message.getClientId()); - iface.setCreateTime(message.getReceiveTime()); + iface.setCreateTime(createTime); }); // 批量入库集合 data.setList(interfaces); // 初始流量数据入库 initialBandwidthTrafficService.batchInsert(data); EpsInitialTrafficDataRemote epsInitialTrafficDataRemote = new EpsInitialTrafficDataRemote(); - epsInitialTrafficDataRemote.setStartTime(message.getDuringTime()); - epsInitialTrafficDataRemote.setEndTime(message.getDuringTime()); + epsInitialTrafficDataRemote.setStartTime(timeStr); + epsInitialTrafficDataRemote.setEndTime(timeStr); // 复制到业务初始库 remoteRevenueConfigService.autoSaveServiceTrafficData(epsInitialTrafficDataRemote, SecurityConstants.INNER); }else{ @@ -189,9 +192,13 @@ public class RocketMsgListener implements MessageListenerConcurrently { private void handleDockerMessage(DeviceMessage message) { List dockers = JsonDataParser.parseJsonData(message.getData(), InitialDockerInfo.class); if(!dockers.isEmpty()){ + // 时间戳转换 + long timestamp = dockers.get(0).getTimestamp(); + long millis = timestamp < 1_000_000_000L ? timestamp * 1000 : timestamp; + Date createTime = new Date(millis / 1000 * 1000); // 去除毫秒 dockers.forEach(iface -> { iface.setClientId(message.getClientId()); - iface.setCreateTime(message.getReceiveTime()); + iface.setCreateTime(createTime); }); // 初始容器数据入库 initialDockerInfoService.batchInsertInitialDockerInfo(dockers); @@ -205,10 +212,14 @@ public class RocketMsgListener implements MessageListenerConcurrently { */ private void handleCpuMessage(DeviceMessage message) { List cpus = JsonDataParser.parseJsonData(message.getData(),InitialCpuInfo.class); + // 时间戳转换 + long timestamp = cpus.get(0).getTimestamp(); + long millis = timestamp < 1_000_000_000L ? timestamp * 1000 : timestamp; + Date createTime = new Date(millis / 1000 * 1000); // 去除毫秒 if(!cpus.isEmpty()){ cpus.forEach(iface -> { iface.setClientId(message.getClientId()); - iface.setCreateTime(message.getReceiveTime()); + iface.setCreateTime(createTime); }); // 初始CPU数据入库 initialCpuInfoService.batchInsertInitialCpuInfo(cpus); @@ -222,10 +233,14 @@ public class RocketMsgListener implements MessageListenerConcurrently { */ private void handleDiskMessage(DeviceMessage message) { List disks = JsonDataParser.parseJsonData(message.getData(), InitialDiskInfo.class); + // 时间戳转换 + long timestamp = disks.get(0).getTimestamp(); + long millis = timestamp < 1_000_000_000L ? timestamp * 1000 : timestamp; + Date createTime = new Date(millis / 1000 * 1000); // 去除毫秒 if(!disks.isEmpty()){ disks.forEach(iface -> { iface.setClientId(message.getClientId()); - iface.setCreateTime(message.getReceiveTime()); + iface.setCreateTime(createTime); }); // 初始磁盘数据入库 initialDiskInfoService.batchInsertInitialDiskInfo(disks); @@ -240,9 +255,13 @@ public class RocketMsgListener implements MessageListenerConcurrently { private void handleMemoryMessage(DeviceMessage message) { List memorys = JsonDataParser.parseJsonData(message.getData(), InitialMemoryInfo.class); if(!memorys.isEmpty()){ + // 时间戳转换 + long timestamp = memorys.get(0).getTimestamp(); + long millis = timestamp < 1_000_000_000L ? timestamp * 1000 : timestamp; + Date createTime = new Date(millis / 1000 * 1000); // 去除毫秒 memorys.forEach(iface -> { iface.setClientId(message.getClientId()); - iface.setCreateTime(message.getReceiveTime()); + iface.setCreateTime(createTime); }); // 初始内存数据入库 initialMemoryInfoService.batchInsertInitialMemoryInfo(memorys); @@ -257,9 +276,13 @@ public class RocketMsgListener implements MessageListenerConcurrently { private void handleMountPointMessage(DeviceMessage message) { List mountPointInfos = JsonDataParser.parseJsonData(message.getData(), InitialMountPointInfo.class); if(!mountPointInfos.isEmpty()){ + // 时间戳转换 + long timestamp = mountPointInfos.get(0).getTimestamp(); + long millis = timestamp < 1_000_000_000L ? timestamp * 1000 : timestamp; + Date createTime = new Date(millis / 1000 * 1000); // 去除毫秒 mountPointInfos.forEach(iface -> { iface.setClientId(message.getClientId()); - iface.setCreateTime(message.getReceiveTime()); + iface.setCreateTime(createTime); }); // 初始挂载点数据入库 initialMountPointInfoService.batchInsertInitialMountPointInfo(mountPointInfos); @@ -274,6 +297,11 @@ public class RocketMsgListener implements MessageListenerConcurrently { private void handleSwitchMessage(DeviceMessage message) { List switchInfos = JsonDataParser.parseJsonData(message.getData(), InitialSwitchInfo.class); if(!switchInfos.isEmpty()){ + // 时间戳转换 + long timestamp = switchInfos.get(0).getTimestamp(); + long millis = timestamp < 1_000_000_000L ? timestamp * 1000 : timestamp; + Date createTime = new Date(millis / 1000 * 1000); // 去除毫秒 + String timeStr = DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss",createTime); // 查询临时表信息,计算实际流量值 InitialSwitchInfoTemp temp = new InitialSwitchInfoTemp(); temp.setClientId(message.getClientId()); @@ -293,7 +321,7 @@ public class RocketMsgListener implements MessageListenerConcurrently { // 3. 计算速度 switchInfos.forEach(switchInfo -> { switchInfo.setClientId(message.getClientId()); - switchInfo.setCreateTime(message.getReceiveTime()); + switchInfo.setCreateTime(createTime); InitialSwitchInfoTemp tempInfo = tempMap.get(switchInfo.getName()); if (tempInfo != null) { // 计算inSpeed @@ -319,8 +347,8 @@ public class RocketMsgListener implements MessageListenerConcurrently { // 业务表入库 InitialSwitchInfoDetailsRemote detailsRemote = new InitialSwitchInfoDetailsRemote(); detailsRemote.setClientId(message.getClientId()); - detailsRemote.setStartTime(message.getDuringTime()); - detailsRemote.setEndTime(message.getDuringTime()); + detailsRemote.setStartTime(timeStr); + detailsRemote.setEndTime(timeStr); remoteRevenueConfigService.autoSaveSwitchTraffic(detailsRemote, SecurityConstants.INNER); }else{ throw new RuntimeException("交换机data数据为空"); @@ -333,9 +361,13 @@ public class RocketMsgListener implements MessageListenerConcurrently { private void handleSystemMessage(DeviceMessage message) { List systemInfos = JsonDataParser.parseJsonData(message.getData(), InitialSystemInfo.class); if(!systemInfos.isEmpty()){ + // 时间戳转换 + long timestamp = systemInfos.get(0).getTimestamp(); + long millis = timestamp < 1_000_000_000L ? timestamp * 1000 : timestamp; + Date createTime = new Date(millis / 1000 * 1000); // 去除毫秒 systemInfos.forEach(iface -> { iface.setClientId(message.getClientId()); - iface.setCreateTime(message.getReceiveTime()); + iface.setCreateTime(createTime); }); // 初始系统数据入库 initialSystemInfoService.batchInsertInitialSystemInfo(systemInfos); diff --git a/ruoyi-rocketmq/src/main/resources/mapper/rocketmq/InitialBandwidthTrafficMapper.xml b/ruoyi-rocketmq/src/main/resources/mapper/rocketmq/InitialBandwidthTrafficMapper.xml index 98fb37b..83f78aa 100644 --- a/ruoyi-rocketmq/src/main/resources/mapper/rocketmq/InitialBandwidthTrafficMapper.xml +++ b/ruoyi-rocketmq/src/main/resources/mapper/rocketmq/InitialBandwidthTrafficMapper.xml @@ -105,21 +105,21 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" INSERT INTO ${tableName} ( `name`, `mac`, `status`, `type`, ipV4, `in_dropped`, `out_dropped`, - `in_speed`, `out_speed`, create_by, update_by, client_id + `in_speed`, `out_speed`, create_by, update_by, client_id, create_time ) VALUES ( #{name}, #{mac}, #{status}, #{type}, #{ipV4}, #{inDropped}, #{outDropped}, - #{inSpeed}, #{outSpeed}, #{createBy}, #{updateBy}, #{clientId} + #{inSpeed}, #{outSpeed}, #{createBy}, #{updateBy}, #{clientId}, #{createTime} ) INSERT INTO ${tableName} ( `name`, `mac`, `status`, `type`, ipV4, `in_dropped`, `out_dropped`, - `in_speed`, `out_speed`,create_by, update_by, client_id + `in_speed`, `out_speed`,create_by, update_by, client_id, create_time ) VALUES ( #{item.name}, #{item.mac}, #{item.status}, #{item.type}, #{item.ipV4}, #{item.inDropped}, #{item.outDropped}, - #{item.inSpeed}, #{item.outSpeed}, #{item.createBy}, #{item.updateBy}, #{item.clientId} + #{item.inSpeed}, #{item.outSpeed}, #{item.createBy}, #{item.updateBy}, #{item.clientId}, #{item.createTime} )