1、优化agent本地存储流量文件删除逻辑。
2、开发tcpdump探测策略下发接口。 3、开发tcpdump探测接口。 4、开发出省流量计算统计接口。
This commit is contained in:
+12
-3
@@ -420,9 +420,18 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
FROM ${tableName} a
|
FROM ${tableName} a
|
||||||
<!-- 动态关联表 -->
|
<!-- 动态关联表 -->
|
||||||
<if test="mac == null or mac == ''">
|
<if test="mac == null or mac == ''">
|
||||||
INNER JOIN rm_network_interface b ON a.client_id = b.client_id and a.mac = b.mac_address
|
INNER JOIN (
|
||||||
AND (b.bind_ip = 1 OR b.bind_ip = 3)
|
SELECT
|
||||||
AND b.new_flag = 1
|
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
|
||||||
</if>
|
</if>
|
||||||
<where>
|
<where>
|
||||||
<if test="serviceSn != '' and serviceSn != null">
|
<if test="serviceSn != '' and serviceSn != null">
|
||||||
|
|||||||
+8
-66
@@ -1,18 +1,16 @@
|
|||||||
package com.tongran.rocketmq.controller;
|
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.controller.BaseController;
|
||||||
import com.tongran.common.core.web.domain.AjaxResult;
|
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.common.security.annotation.RequiresPermissions;
|
||||||
import com.tongran.rocketmq.domain.RmOutboundTrafficStatistics;
|
import com.tongran.rocketmq.domain.RmOutboundTrafficStatistics;
|
||||||
import com.tongran.rocketmq.service.IRmOutboundTrafficStatisticsService;
|
import com.tongran.rocketmq.service.IRmOutboundTrafficStatisticsService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
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;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -23,6 +21,7 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/rmOutboundTrafficStatistics")
|
@RequestMapping("/rmOutboundTrafficStatistics")
|
||||||
|
@RequiresPermissions("rocketmq:traffic")
|
||||||
public class RmOutboundTrafficStatisticsController extends BaseController
|
public class RmOutboundTrafficStatisticsController extends BaseController
|
||||||
{
|
{
|
||||||
@Autowired
|
@Autowired
|
||||||
@@ -31,68 +30,11 @@ public class RmOutboundTrafficStatisticsController extends BaseController
|
|||||||
/**
|
/**
|
||||||
* 查询出省流量统计列表
|
* 查询出省流量统计列表
|
||||||
*/
|
*/
|
||||||
@RequiresPermissions("rocketmq:rmOutboundTrafficStatistics:list")
|
@PostMapping("/list")
|
||||||
@GetMapping("/list")
|
public AjaxResult list(@RequestBody RmOutboundTrafficStatistics rmOutboundTrafficStatistics)
|
||||||
public TableDataInfo list(RmOutboundTrafficStatistics rmOutboundTrafficStatistics)
|
|
||||||
{
|
|
||||||
startPage();
|
|
||||||
List<RmOutboundTrafficStatistics> 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)
|
|
||||||
{
|
{
|
||||||
List<RmOutboundTrafficStatistics> list = rmOutboundTrafficStatisticsService.selectRmOutboundTrafficStatisticsList(rmOutboundTrafficStatistics);
|
List<RmOutboundTrafficStatistics> list = rmOutboundTrafficStatisticsService.selectRmOutboundTrafficStatisticsList(rmOutboundTrafficStatistics);
|
||||||
ExcelUtil<RmOutboundTrafficStatistics> util = new ExcelUtil<RmOutboundTrafficStatistics>(RmOutboundTrafficStatistics.class);
|
return success(list);
|
||||||
util.exportExcel(response, 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));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,4 @@ public class DeviceMessage {
|
|||||||
private String clientId;
|
private String clientId;
|
||||||
private String dataType;
|
private String dataType;
|
||||||
private String data;
|
private String data;
|
||||||
/** 最后一次标志 */
|
|
||||||
private boolean lastTrafficFlag;
|
|
||||||
}
|
}
|
||||||
+2
@@ -109,4 +109,6 @@ public class InitialBandwidthTraffic extends BaseEntity
|
|||||||
private Double pingDropped;
|
private Double pingDropped;
|
||||||
/** 多个clientId */
|
/** 多个clientId */
|
||||||
private Map<String, List<String>> clientInterfaces;
|
private Map<String, List<String>> clientInterfaces;
|
||||||
|
/** 是否最后一次 */
|
||||||
|
private boolean lastTrafficFlag;
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-44
@@ -1,9 +1,8 @@
|
|||||||
package com.tongran.rocketmq.domain;
|
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.annotation.Excel;
|
||||||
import com.tongran.common.core.web.domain.BaseEntity;
|
import com.tongran.common.core.web.domain.BaseEntity;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 出省流量统计对象 rm_outbound_traffic_statistics
|
* 出省流量统计对象 rm_outbound_traffic_statistics
|
||||||
@@ -11,6 +10,7 @@ import com.tongran.common.core.web.domain.BaseEntity;
|
|||||||
* @author tongran
|
* @author tongran
|
||||||
* @date 2026-01-21
|
* @date 2026-01-21
|
||||||
*/
|
*/
|
||||||
|
@Data
|
||||||
public class RmOutboundTrafficStatistics extends BaseEntity
|
public class RmOutboundTrafficStatistics extends BaseEntity
|
||||||
{
|
{
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
@@ -26,46 +26,4 @@ public class RmOutboundTrafficStatistics extends BaseEntity
|
|||||||
@Excel(name = "出省流量统计详情")
|
@Excel(name = "出省流量统计详情")
|
||||||
private String description;
|
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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
package com.tongran.rocketmq.domain;
|
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.annotation.Excel;
|
||||||
import com.tongran.common.core.web.domain.BaseEntity;
|
import com.tongran.common.core.web.domain.BaseEntity;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* tcpdump探测策略对象 rm_tcpdump_config
|
* tcpdump探测策略对象 rm_tcpdump_config
|
||||||
@@ -11,6 +10,7 @@ import com.tongran.common.core.web.domain.BaseEntity;
|
|||||||
* @author tongran
|
* @author tongran
|
||||||
* @date 2026-01-21
|
* @date 2026-01-21
|
||||||
*/
|
*/
|
||||||
|
@Data
|
||||||
public class RmTcpdumpConfig extends BaseEntity
|
public class RmTcpdumpConfig extends BaseEntity
|
||||||
{
|
{
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
@@ -30,72 +30,8 @@ public class RmTcpdumpConfig extends BaseEntity
|
|||||||
@Excel(name = "探测频率")
|
@Excel(name = "探测频率")
|
||||||
private String frequency;
|
private String frequency;
|
||||||
|
|
||||||
/** 探测时间列表(多个时间用;分隔) */
|
/** 探测时间列表(多个时间用,分隔) */
|
||||||
@Excel(name = "探测时间列表(多个时间用;分隔)")
|
@Excel(name = "探测时间列表(多个时间用,分隔)")
|
||||||
private String detectTimes;
|
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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,5 +7,5 @@ public class TcpdumpVo {
|
|||||||
/** ip地址 */
|
/** ip地址 */
|
||||||
private String ip;
|
private String ip;
|
||||||
/** 出现次数 */
|
/** 出现次数 */
|
||||||
private Integer count;
|
private Double count;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ import javax.annotation.PostConstruct;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.math.RoundingMode;
|
import java.math.RoundingMode;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
@@ -126,6 +127,8 @@ public class MessageHandler {
|
|||||||
private ProducerMode producerMode;
|
private ProducerMode producerMode;
|
||||||
@Autowired
|
@Autowired
|
||||||
private RedissonClient redissonClient;
|
private RedissonClient redissonClient;
|
||||||
|
@Autowired
|
||||||
|
private IRmOutboundTrafficStatisticsService rmOutboundTrafficStatisticsService;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -158,26 +161,116 @@ public class MessageHandler {
|
|||||||
private void handleTcpdumpResultMessage(DeviceMessage message) {
|
private void handleTcpdumpResultMessage(DeviceMessage message) {
|
||||||
List<TcpdumpVo> tcpdumpVoList = JsonDataParser.parseJsonData(message.getData(), TcpdumpVo.class);
|
List<TcpdumpVo> tcpdumpVoList = JsonDataParser.parseJsonData(message.getData(), TcpdumpVo.class);
|
||||||
if(tcpdumpVoList != null && !tcpdumpVoList.isEmpty()){
|
if(tcpdumpVoList != null && !tcpdumpVoList.isEmpty()){
|
||||||
for (TcpdumpVo tcpdumpVo : tcpdumpVoList) {
|
String localProvince = "";
|
||||||
String ip = tcpdumpVo.getIp();
|
// 根据clientId查询省份信息
|
||||||
Integer count = tcpdumpVo.getCount();
|
RmNetworkInterface networkInterfaceQuery = new RmNetworkInterface();
|
||||||
String type = checkIPVersion(ip);
|
networkInterfaceQuery.setClientId(message.getClientId());
|
||||||
// 查询IP地址归属地信息
|
networkInterfaceQuery.setNewFlag(1);
|
||||||
Map<String, String> locationInfo = queryIpLocation(ip);
|
List<RmNetworkInterface> networkInfoList = rmNetworkInterfaceService.selectRmNetworkInterfaceList(networkInterfaceQuery);
|
||||||
if (locationInfo != null) {
|
if(networkInfoList != null && !networkInfoList.isEmpty()){
|
||||||
String operator = locationInfo.get("operator"); // 运营商
|
for (RmNetworkInterface rmNetworkInterface : networkInfoList) {
|
||||||
String province = locationInfo.get("province"); // 省份
|
if(rmNetworkInterface.getProvince() != null){
|
||||||
|
localProvince = rmNetworkInterface.getProvince();
|
||||||
System.out.println("IP: " + ip +
|
break;
|
||||||
", 运营商: " + operator +
|
}
|
||||||
", 省份: " + province +
|
|
||||||
", 抓包数量: " + count);
|
|
||||||
|
|
||||||
// 设置到对象中(如果TcpdumpVo有这些字段)
|
|
||||||
// tcpdumpVo.setOperator(operator);
|
|
||||||
// tcpdumpVo.setProvince(province);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 计算总数量
|
||||||
|
Double totalCount = 0.0;
|
||||||
|
for (TcpdumpVo tcpdumpVo : tcpdumpVoList) {
|
||||||
|
totalCount += tcpdumpVo.getCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 分别统计IPv4和IPv6
|
||||||
|
Map<String, List<TcpdumpVo>> 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<String, Double> v4StatMap = new HashMap<>();
|
||||||
|
for (TcpdumpVo tcpdumpVo : ipTypeMap.get("IPv4")) {
|
||||||
|
Map<String, String> 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<Map.Entry<String, Double>> sortedV4List = new ArrayList<>(v4StatMap.entrySet());
|
||||||
|
sortedV4List.sort((a, b) -> b.getValue().compareTo(a.getValue())); // 降序排序
|
||||||
|
|
||||||
|
for (Map.Entry<String, Double> 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<String, Double> v6StatMap = new HashMap<>();
|
||||||
|
for (TcpdumpVo tcpdumpVo : ipTypeMap.get("IPv6")) {
|
||||||
|
Map<String, String> 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<Map.Entry<String, Double>> sortedV6List = new ArrayList<>(v6StatMap.entrySet());
|
||||||
|
sortedV6List.sort((a, b) -> b.getValue().compareTo(a.getValue())); // 降序排序
|
||||||
|
|
||||||
|
for (Map.Entry<String, Double> 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
|
* @param message
|
||||||
*/
|
*/
|
||||||
private void processNetRecoverMessageInternal(DeviceMessage message) {
|
private void processNetRecoverMessageInternal(DeviceMessage message) {
|
||||||
@@ -617,9 +710,10 @@ public class MessageHandler {
|
|||||||
String clientId = message.getClientId();
|
String clientId = message.getClientId();
|
||||||
// 时间戳转换
|
// 时间戳转换
|
||||||
long timestamp = interfaces.get(0).getTimestamp();
|
long timestamp = interfaces.get(0).getTimestamp();
|
||||||
|
boolean lasttrafficFlag = interfaces.get(0).isLastTrafficFlag();
|
||||||
// 时间戳存储到redis
|
// 时间戳存储到redis
|
||||||
storeTimestampToRedis(clientId, timestamp);
|
storeTimestampToRedis(clientId, timestamp);
|
||||||
if(message.isLastTrafficFlag()){
|
if(lasttrafficFlag){
|
||||||
// 把redis中存储的时间戳提取出来,删除redis中的时间戳
|
// 把redis中存储的时间戳提取出来,删除redis中的时间戳
|
||||||
processExitsTraffic(clientId);
|
processExitsTraffic(clientId);
|
||||||
}
|
}
|
||||||
|
|||||||
+1
@@ -24,6 +24,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
<if test="clientId != null and clientId != ''"> and client_id = #{clientId}</if>
|
<if test="clientId != null and clientId != ''"> and client_id = #{clientId}</if>
|
||||||
<if test="description != null and description != ''"> and description = #{description}</if>
|
<if test="description != null and description != ''"> and description = #{description}</if>
|
||||||
</where>
|
</where>
|
||||||
|
order by create_time desc
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="selectRmOutboundTrafficStatisticsById" parameterType="Long" resultMap="RmOutboundTrafficStatisticsResult">
|
<select id="selectRmOutboundTrafficStatisticsById" parameterType="Long" resultMap="RmOutboundTrafficStatisticsResult">
|
||||||
|
|||||||
Reference in New Issue
Block a user