diff --git a/tongran-modules/tongran-system/src/main/resources/mapper/system/EpsInitialTrafficDataMapper.xml b/tongran-modules/tongran-system/src/main/resources/mapper/system/EpsInitialTrafficDataMapper.xml
index 1cffb3c..6498807 100644
--- a/tongran-modules/tongran-system/src/main/resources/mapper/system/EpsInitialTrafficDataMapper.xml
+++ b/tongran-modules/tongran-system/src/main/resources/mapper/system/EpsInitialTrafficDataMapper.xml
@@ -420,9 +420,18 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
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
+ INNER JOIN (
+ SELECT
+ a.client_id,ifnull(b.mac_address,a.mac_address) mac_address
+ FROM rm_network_interface a
+ LEFT JOIN rm_network_interface_child b on b.ipv4_address!='' and b.ipv4_address!='N/A'
+ and a.client_id = b.client_id
+ AND a.interface_name = b.parent_interface
+ where
+ (a.bind_ip = 1 OR a.bind_ip = 3)
+ AND a.new_flag = 1 and a.client_id = #{clientId}
+ ) b
+ ON a.client_id = b.client_id and a.mac = b.mac_address
diff --git a/tongran-rocketmq/src/main/java/com/tongran/rocketmq/controller/RmOutboundTrafficStatisticsController.java b/tongran-rocketmq/src/main/java/com/tongran/rocketmq/controller/RmOutboundTrafficStatisticsController.java
index 30d6c17..a5d0629 100644
--- a/tongran-rocketmq/src/main/java/com/tongran/rocketmq/controller/RmOutboundTrafficStatisticsController.java
+++ b/tongran-rocketmq/src/main/java/com/tongran/rocketmq/controller/RmOutboundTrafficStatisticsController.java
@@ -1,18 +1,16 @@
package com.tongran.rocketmq.controller;
-import com.tongran.common.core.utils.poi.ExcelUtil;
import com.tongran.common.core.web.controller.BaseController;
import com.tongran.common.core.web.domain.AjaxResult;
-import com.tongran.common.core.web.page.TableDataInfo;
-import com.tongran.common.log.annotation.Log;
-import com.tongran.common.log.enums.BusinessType;
import com.tongran.common.security.annotation.RequiresPermissions;
import com.tongran.rocketmq.domain.RmOutboundTrafficStatistics;
import com.tongran.rocketmq.service.IRmOutboundTrafficStatisticsService;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.*;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
-import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
@@ -23,6 +21,7 @@ import java.util.List;
*/
@RestController
@RequestMapping("/rmOutboundTrafficStatistics")
+@RequiresPermissions("rocketmq:traffic")
public class RmOutboundTrafficStatisticsController extends BaseController
{
@Autowired
@@ -31,68 +30,11 @@ public class RmOutboundTrafficStatisticsController extends BaseController
/**
* 查询出省流量统计列表
*/
- @RequiresPermissions("rocketmq:rmOutboundTrafficStatistics:list")
- @GetMapping("/list")
- public TableDataInfo list(RmOutboundTrafficStatistics rmOutboundTrafficStatistics)
- {
- startPage();
- List list = rmOutboundTrafficStatisticsService.selectRmOutboundTrafficStatisticsList(rmOutboundTrafficStatistics);
- return getDataTable(list);
- }
-
- /**
- * 导出出省流量统计列表
- */
- @RequiresPermissions("rocketmq:rmOutboundTrafficStatistics:export")
- @Log(title = "出省流量统计", businessType = BusinessType.EXPORT)
- @PostMapping("/export")
- public void export(HttpServletResponse response, RmOutboundTrafficStatistics rmOutboundTrafficStatistics)
+ @PostMapping("/list")
+ public AjaxResult list(@RequestBody RmOutboundTrafficStatistics rmOutboundTrafficStatistics)
{
List list = rmOutboundTrafficStatisticsService.selectRmOutboundTrafficStatisticsList(rmOutboundTrafficStatistics);
- ExcelUtil util = new ExcelUtil(RmOutboundTrafficStatistics.class);
- util.exportExcel(response, list, "出省流量统计数据");
+ return success(list);
}
- /**
- * 获取出省流量统计详细信息
- */
- @RequiresPermissions("rocketmq:rmOutboundTrafficStatistics:query")
- @GetMapping(value = "/{id}")
- public AjaxResult getInfo(@PathVariable("id") Long id)
- {
- return success(rmOutboundTrafficStatisticsService.selectRmOutboundTrafficStatisticsById(id));
- }
-
- /**
- * 新增出省流量统计
- */
- @RequiresPermissions("rocketmq:rmOutboundTrafficStatistics:add")
- @Log(title = "出省流量统计", businessType = BusinessType.INSERT)
- @PostMapping
- public AjaxResult add(@RequestBody RmOutboundTrafficStatistics rmOutboundTrafficStatistics)
- {
- return toAjax(rmOutboundTrafficStatisticsService.insertRmOutboundTrafficStatistics(rmOutboundTrafficStatistics));
- }
-
- /**
- * 修改出省流量统计
- */
- @RequiresPermissions("rocketmq:rmOutboundTrafficStatistics:edit")
- @Log(title = "出省流量统计", businessType = BusinessType.UPDATE)
- @PutMapping
- public AjaxResult edit(@RequestBody RmOutboundTrafficStatistics rmOutboundTrafficStatistics)
- {
- return toAjax(rmOutboundTrafficStatisticsService.updateRmOutboundTrafficStatistics(rmOutboundTrafficStatistics));
- }
-
- /**
- * 删除出省流量统计
- */
- @RequiresPermissions("rocketmq:rmOutboundTrafficStatistics:remove")
- @Log(title = "出省流量统计", businessType = BusinessType.DELETE)
- @DeleteMapping("/{ids}")
- public AjaxResult remove(@PathVariable Long[] ids)
- {
- return toAjax(rmOutboundTrafficStatisticsService.deleteRmOutboundTrafficStatisticsByIds(ids));
- }
}
diff --git a/tongran-rocketmq/src/main/java/com/tongran/rocketmq/domain/DeviceMessage.java b/tongran-rocketmq/src/main/java/com/tongran/rocketmq/domain/DeviceMessage.java
index 3807875..35ca2c2 100644
--- a/tongran-rocketmq/src/main/java/com/tongran/rocketmq/domain/DeviceMessage.java
+++ b/tongran-rocketmq/src/main/java/com/tongran/rocketmq/domain/DeviceMessage.java
@@ -9,6 +9,4 @@ public class DeviceMessage {
private String clientId;
private String dataType;
private String data;
- /** 最后一次标志 */
- private boolean lastTrafficFlag;
}
\ No newline at end of file
diff --git a/tongran-rocketmq/src/main/java/com/tongran/rocketmq/domain/InitialBandwidthTraffic.java b/tongran-rocketmq/src/main/java/com/tongran/rocketmq/domain/InitialBandwidthTraffic.java
index 5e84399..6d9903f 100644
--- a/tongran-rocketmq/src/main/java/com/tongran/rocketmq/domain/InitialBandwidthTraffic.java
+++ b/tongran-rocketmq/src/main/java/com/tongran/rocketmq/domain/InitialBandwidthTraffic.java
@@ -109,4 +109,6 @@ public class InitialBandwidthTraffic extends BaseEntity
private Double pingDropped;
/** 多个clientId */
private Map> clientInterfaces;
+ /** 是否最后一次 */
+ private boolean lastTrafficFlag;
}
diff --git a/tongran-rocketmq/src/main/java/com/tongran/rocketmq/domain/RmOutboundTrafficStatistics.java b/tongran-rocketmq/src/main/java/com/tongran/rocketmq/domain/RmOutboundTrafficStatistics.java
index 0cdf123..8564d98 100644
--- a/tongran-rocketmq/src/main/java/com/tongran/rocketmq/domain/RmOutboundTrafficStatistics.java
+++ b/tongran-rocketmq/src/main/java/com/tongran/rocketmq/domain/RmOutboundTrafficStatistics.java
@@ -1,9 +1,8 @@
package com.tongran.rocketmq.domain;
-import org.apache.commons.lang3.builder.ToStringBuilder;
-import org.apache.commons.lang3.builder.ToStringStyle;
import com.tongran.common.core.annotation.Excel;
import com.tongran.common.core.web.domain.BaseEntity;
+import lombok.Data;
/**
* 出省流量统计对象 rm_outbound_traffic_statistics
@@ -11,6 +10,7 @@ import com.tongran.common.core.web.domain.BaseEntity;
* @author tongran
* @date 2026-01-21
*/
+@Data
public class RmOutboundTrafficStatistics extends BaseEntity
{
private static final long serialVersionUID = 1L;
@@ -26,46 +26,4 @@ public class RmOutboundTrafficStatistics extends BaseEntity
@Excel(name = "出省流量统计详情")
private String description;
- public void setId(Long id)
- {
- this.id = id;
- }
-
- public Long getId()
- {
- return id;
- }
-
- public void setClientId(String clientId)
- {
- this.clientId = clientId;
- }
-
- public String getClientId()
- {
- return clientId;
- }
-
- public void setDescription(String description)
- {
- this.description = description;
- }
-
- public String getDescription()
- {
- return description;
- }
-
- @Override
- public String toString() {
- return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
- .append("id", getId())
- .append("clientId", getClientId())
- .append("description", getDescription())
- .append("createTime", getCreateTime())
- .append("updateTime", getUpdateTime())
- .append("createBy", getCreateBy())
- .append("updateBy", getUpdateBy())
- .toString();
- }
}
diff --git a/tongran-rocketmq/src/main/java/com/tongran/rocketmq/domain/RmTcpdumpConfig.java b/tongran-rocketmq/src/main/java/com/tongran/rocketmq/domain/RmTcpdumpConfig.java
index 02e5846..13b713f 100644
--- a/tongran-rocketmq/src/main/java/com/tongran/rocketmq/domain/RmTcpdumpConfig.java
+++ b/tongran-rocketmq/src/main/java/com/tongran/rocketmq/domain/RmTcpdumpConfig.java
@@ -1,9 +1,8 @@
package com.tongran.rocketmq.domain;
-import org.apache.commons.lang3.builder.ToStringBuilder;
-import org.apache.commons.lang3.builder.ToStringStyle;
import com.tongran.common.core.annotation.Excel;
import com.tongran.common.core.web.domain.BaseEntity;
+import lombok.Data;
/**
* tcpdump探测策略对象 rm_tcpdump_config
@@ -11,6 +10,7 @@ import com.tongran.common.core.web.domain.BaseEntity;
* @author tongran
* @date 2026-01-21
*/
+@Data
public class RmTcpdumpConfig extends BaseEntity
{
private static final long serialVersionUID = 1L;
@@ -30,72 +30,8 @@ public class RmTcpdumpConfig extends BaseEntity
@Excel(name = "探测频率")
private String frequency;
- /** 探测时间列表(多个时间用;分隔) */
- @Excel(name = "探测时间列表(多个时间用;分隔)")
+ /** 探测时间列表(多个时间用,分隔) */
+ @Excel(name = "探测时间列表(多个时间用,分隔)")
private String detectTimes;
- public void setId(Long id)
- {
- this.id = id;
- }
-
- public Long getId()
- {
- return id;
- }
-
- public void setClientId(String clientId)
- {
- this.clientId = clientId;
- }
-
- public String getClientId()
- {
- return clientId;
- }
-
- public void setDetectFlag(Integer detectFlag)
- {
- this.detectFlag = detectFlag;
- }
-
- public Integer getDetectFlag()
- {
- return detectFlag;
- }
-
- public void setFrequency(String frequency)
- {
- this.frequency = frequency;
- }
-
- public String getFrequency()
- {
- return frequency;
- }
-
- public void setDetectTimes(String detectTimes)
- {
- this.detectTimes = detectTimes;
- }
-
- public String getDetectTimes()
- {
- return detectTimes;
- }
-
- @Override
- public String toString() {
- return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
- .append("id", getId())
- .append("clientId", getClientId())
- .append("detectFlag", getDetectFlag())
- .append("frequency", getFrequency())
- .append("detectTimes", getDetectTimes())
- .append("createTime", getCreateTime())
- .append("updateTime", getUpdateTime())
- .append("createBy", getCreateBy())
- .append("updateBy", getUpdateBy())
- .toString();
- }
}
diff --git a/tongran-rocketmq/src/main/java/com/tongran/rocketmq/domain/vo/TcpdumpVo.java b/tongran-rocketmq/src/main/java/com/tongran/rocketmq/domain/vo/TcpdumpVo.java
index cfed817..ce48924 100644
--- a/tongran-rocketmq/src/main/java/com/tongran/rocketmq/domain/vo/TcpdumpVo.java
+++ b/tongran-rocketmq/src/main/java/com/tongran/rocketmq/domain/vo/TcpdumpVo.java
@@ -7,5 +7,5 @@ public class TcpdumpVo {
/** ip地址 */
private String ip;
/** 出现次数 */
- private Integer count;
+ private Double count;
}
diff --git a/tongran-rocketmq/src/main/java/com/tongran/rocketmq/handler/MessageHandler.java b/tongran-rocketmq/src/main/java/com/tongran/rocketmq/handler/MessageHandler.java
index d00adbb..8e76b40 100644
--- a/tongran-rocketmq/src/main/java/com/tongran/rocketmq/handler/MessageHandler.java
+++ b/tongran-rocketmq/src/main/java/com/tongran/rocketmq/handler/MessageHandler.java
@@ -44,6 +44,7 @@ import javax.annotation.PostConstruct;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
+import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
@@ -126,6 +127,8 @@ public class MessageHandler {
private ProducerMode producerMode;
@Autowired
private RedissonClient redissonClient;
+ @Autowired
+ private IRmOutboundTrafficStatisticsService rmOutboundTrafficStatisticsService;
/**
@@ -158,26 +161,116 @@ public class MessageHandler {
private void handleTcpdumpResultMessage(DeviceMessage message) {
List tcpdumpVoList = JsonDataParser.parseJsonData(message.getData(), TcpdumpVo.class);
if(tcpdumpVoList != null && !tcpdumpVoList.isEmpty()){
- for (TcpdumpVo tcpdumpVo : tcpdumpVoList) {
- String ip = tcpdumpVo.getIp();
- Integer count = tcpdumpVo.getCount();
- String type = checkIPVersion(ip);
- // 查询IP地址归属地信息
- Map locationInfo = queryIpLocation(ip);
- if (locationInfo != null) {
- String operator = locationInfo.get("operator"); // 运营商
- String province = locationInfo.get("province"); // 省份
-
- System.out.println("IP: " + ip +
- ", 运营商: " + operator +
- ", 省份: " + province +
- ", 抓包数量: " + count);
-
- // 设置到对象中(如果TcpdumpVo有这些字段)
- // tcpdumpVo.setOperator(operator);
- // tcpdumpVo.setProvince(province);
+ String localProvince = "";
+ // 根据clientId查询省份信息
+ RmNetworkInterface networkInterfaceQuery = new RmNetworkInterface();
+ networkInterfaceQuery.setClientId(message.getClientId());
+ networkInterfaceQuery.setNewFlag(1);
+ List networkInfoList = rmNetworkInterfaceService.selectRmNetworkInterfaceList(networkInterfaceQuery);
+ if(networkInfoList != null && !networkInfoList.isEmpty()){
+ for (RmNetworkInterface rmNetworkInterface : networkInfoList) {
+ if(rmNetworkInterface.getProvince() != null){
+ localProvince = rmNetworkInterface.getProvince();
+ break;
+ }
}
}
+
+ // 计算总数量
+ Double totalCount = 0.0;
+ for (TcpdumpVo tcpdumpVo : tcpdumpVoList) {
+ totalCount += tcpdumpVo.getCount();
+ }
+
+ // 分别统计IPv4和IPv6
+ Map> ipTypeMap = new HashMap<>();
+ ipTypeMap.put("IPv4", new ArrayList<>());
+ ipTypeMap.put("IPv6", new ArrayList<>());
+
+ // 按类型分类
+ for (TcpdumpVo tcpdumpVo : tcpdumpVoList) {
+ String ip = tcpdumpVo.getIp();
+ String type = checkIPVersion(ip);
+ if ("IPv4".equals(type)) {
+ ipTypeMap.get("IPv4").add(tcpdumpVo);
+ } else if ("IPv6".equals(type)) {
+ ipTypeMap.get("IPv6").add(tcpdumpVo);
+ }
+ }
+
+ // 构建content内容 - 根据图片格式
+ StringBuilder content = new StringBuilder();
+
+ // 添加时间戳 - 根据图片格式
+ content.append("时间:").append(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())).append("\n");
+
+ // 处理IPv4统计
+ if (!ipTypeMap.get("IPv4").isEmpty()) {
+ content.append("##### V4 统计 ##### ##\n");
+
+ // 按省份运营商分组统计(过滤本地省份)
+ Map v4StatMap = new HashMap<>();
+ for (TcpdumpVo tcpdumpVo : ipTypeMap.get("IPv4")) {
+ Map locationInfo = queryIpLocation(tcpdumpVo.getIp());
+ if (locationInfo != null) {
+ String operator = locationInfo.get("operator");
+ String province = locationInfo.get("province");
+
+ // 过滤本地省份和空值
+ if (province != null && operator != null && !localProvince.equals(province)) {
+ String key = province + operator; // 根据图片格式,省份和运营商之间没有空格
+ double currentCount = v4StatMap.getOrDefault(key, 0.0);
+ v4StatMap.put(key, currentCount + tcpdumpVo.getCount());
+ }
+ }
+ }
+
+ // 计算百分比并排序
+ List> sortedV4List = new ArrayList<>(v4StatMap.entrySet());
+ sortedV4List.sort((a, b) -> b.getValue().compareTo(a.getValue())); // 降序排序
+
+ for (Map.Entry entry : sortedV4List) {
+ BigDecimal percentage = new BigDecimal(entry.getValue() / totalCount * 100)
+ .setScale(2, RoundingMode.HALF_UP);
+ content.append(entry.getKey()).append(": ").append(percentage).append("%\n");
+ }
+ }
+
+ // 处理IPv6统计
+ if (!ipTypeMap.get("IPv6").isEmpty()) {
+ content.append("##### V6 统计 ##### ##\n");
+
+ // 按省份运营商分组统计(过滤本地省份)
+ Map v6StatMap = new HashMap<>();
+ for (TcpdumpVo tcpdumpVo : ipTypeMap.get("IPv6")) {
+ Map locationInfo = queryIpLocation(tcpdumpVo.getIp());
+ if (locationInfo != null) {
+ String operator = locationInfo.get("operator");
+ String province = locationInfo.get("province");
+
+ // 过滤本地省份和空值
+ if (province != null && operator != null && !localProvince.equals(province)) {
+ String key = province + operator; // 根据图片格式,省份和运营商之间没有空格
+ double currentCount = v6StatMap.getOrDefault(key, 0.0);
+ v6StatMap.put(key, currentCount + tcpdumpVo.getCount());
+ }
+ }
+ }
+
+ // 计算百分比并排序
+ List> sortedV6List = new ArrayList<>(v6StatMap.entrySet());
+ sortedV6List.sort((a, b) -> b.getValue().compareTo(a.getValue())); // 降序排序
+
+ for (Map.Entry entry : sortedV6List) {
+ BigDecimal percentage = new BigDecimal(entry.getValue() / totalCount * 100)
+ .setScale(2, RoundingMode.HALF_UP);
+ content.append(entry.getKey()).append(": ").append(percentage).append("%\n");
+ }
+ }
+ RmOutboundTrafficStatistics insertData = new RmOutboundTrafficStatistics();
+ insertData.setClientId(message.getClientId());
+ insertData.setDescription(content.toString());
+ rmOutboundTrafficStatisticsService.insertRmOutboundTrafficStatistics(insertData);
}
}
@@ -608,7 +701,7 @@ public class MessageHandler {
}
}
/**
- * 网络流量数据入库
+ * 网络重试流量数据入库
* @param message
*/
private void processNetRecoverMessageInternal(DeviceMessage message) {
@@ -617,9 +710,10 @@ public class MessageHandler {
String clientId = message.getClientId();
// 时间戳转换
long timestamp = interfaces.get(0).getTimestamp();
+ boolean lasttrafficFlag = interfaces.get(0).isLastTrafficFlag();
// 时间戳存储到redis
storeTimestampToRedis(clientId, timestamp);
- if(message.isLastTrafficFlag()){
+ if(lasttrafficFlag){
// 把redis中存储的时间戳提取出来,删除redis中的时间戳
processExitsTraffic(clientId);
}
diff --git a/tongran-rocketmq/src/main/resources/mapper/rocketmq/RmOutboundTrafficStatisticsMapper.xml b/tongran-rocketmq/src/main/resources/mapper/rocketmq/RmOutboundTrafficStatisticsMapper.xml
index 0b149d4..e1900fd 100644
--- a/tongran-rocketmq/src/main/resources/mapper/rocketmq/RmOutboundTrafficStatisticsMapper.xml
+++ b/tongran-rocketmq/src/main/resources/mapper/rocketmq/RmOutboundTrafficStatisticsMapper.xml
@@ -24,6 +24,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
and client_id = #{clientId}
and description = #{description}
+ order by create_time desc