1、新增业务进程与名称对应表。

2、新增业务流量查询逻辑。
This commit is contained in:
gaoyutao
2026-03-18 18:06:11 +08:00
parent fb27c1c0e0
commit 2e3b2af397
13 changed files with 721 additions and 20 deletions
@@ -150,7 +150,7 @@ public class SpeedUtils {
}
}
public static String calculateUnit(List<?> list,
String inSpeedField, String outSpeedField)
String inSpeedField, String outSpeedField)
throws NoSuchFieldException, IllegalAccessException {
if (list == null || list.isEmpty()) {
@@ -159,10 +159,6 @@ public class SpeedUtils {
BigDecimal totalInSpeedBit = BigDecimal.ZERO;
BigDecimal totalOutSpeedBit = BigDecimal.ZERO;
BigDecimal maxInSpeedGb = BigDecimal.ZERO;
BigDecimal maxOutSpeedGb = BigDecimal.ZERO;
BigDecimal lastInSpeedGb = BigDecimal.ZERO;
BigDecimal lastOutSpeedGb = BigDecimal.ZERO;
final BigDecimal GB_DIVISOR = new BigDecimal("1000000000");
@@ -175,8 +171,9 @@ public class SpeedUtils {
inField.setAccessible(true);
outField.setAccessible(true);
BigDecimal inSpeedBit = (BigDecimal) inField.get(obj) == null ? BigDecimal.ZERO : (BigDecimal) inField.get(obj);
BigDecimal outSpeedBit = (BigDecimal) outField.get(obj) == null ? BigDecimal.ZERO : (BigDecimal) outField.get(obj);
// 安全地获取字段值并转换为BigDecimal
BigDecimal inSpeedBit = convertToBigDecimal(inField.get(obj));
BigDecimal outSpeedBit = convertToBigDecimal(outField.get(obj));
// 累加bit值(用于计算平均值)
totalInSpeedBit = totalInSpeedBit.add(inSpeedBit);
@@ -188,24 +185,53 @@ public class SpeedUtils {
// 计算Gb平均值
BigDecimal size = new BigDecimal(list.size());
BigDecimal avgInSpeedGb = totalInSpeedBit.divide(size, 2, RoundingMode.HALF_UP);
BigDecimal avgOutSpeedGb = totalOutSpeedBit.divide(size, 2, RoundingMode.HALF_UP);
BigDecimal avgInSpeedBit = totalInSpeedBit.divide(size, 2, RoundingMode.HALF_UP);
BigDecimal avgOutSpeedBit = totalOutSpeedBit.divide(size, 2, RoundingMode.HALF_UP);
// 基于平均值的较大值确定推荐单位
BigDecimal maxAvgBit = avgInSpeedGb.compareTo(avgOutSpeedGb) > 0 ?
avgInSpeedGb : avgOutSpeedGb;
BigDecimal maxAvgBit = avgInSpeedBit.compareTo(avgOutSpeedBit) > 0 ?
avgInSpeedBit : avgOutSpeedBit;
String recommendedUnit;
if (maxAvgBit.compareTo(new BigDecimal("1000000000")) >= 0) {
recommendedUnit = "Gb";
} else if (maxAvgBit.compareTo(new BigDecimal("1000000")) >= 0) {
recommendedUnit = "Mb";
} else{
} else {
recommendedUnit = "Kb";
}
return recommendedUnit;
}
/**
* 安全地将不同类型转换为BigDecimal
*/
private static BigDecimal convertToBigDecimal(Object value) {
if (value == null) {
return BigDecimal.ZERO;
}
try {
if (value instanceof BigDecimal) {
return (BigDecimal) value;
} else if (value instanceof String) {
String strValue = ((String) value).trim();
if (strValue.isEmpty()) {
return BigDecimal.ZERO;
}
return new BigDecimal(strValue);
} else if (value instanceof Number) {
return new BigDecimal(value.toString());
} else {
// 尝试转换为字符串再解析
return new BigDecimal(value.toString());
}
} catch (Exception e) {
// 转换失败时返回0
return BigDecimal.ZERO;
}
}
/**
* 计算String类型(存储数字)的速度统计结果
* @param list 数据列表
@@ -318,7 +318,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
`total_in_speed` varchar(50) DEFAULT NULL COMMENT '累计接收字总节数',
`total_out_speed` varchar(50) DEFAULT NULL COMMENT '累计发送总字节数',
PRIMARY KEY (`id`),
UNIQUE INDEX `uk_client_mac_name_time`(`client_id`, `mac`, `name`, `create_time`)
UNIQUE INDEX `uk_client_mac_name_time`(`client_id`,`process_name`, `create_time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='网络业务流量监控表';
</update>
<!-- 单条插入语句 -->
@@ -0,0 +1,91 @@
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.log.annotation.Log;
import com.tongran.common.log.enums.BusinessType;
import com.tongran.common.security.annotation.RequiresPermissions;
import com.tongran.rocketmq.domain.AllBusinessNetName;
import com.tongran.rocketmq.service.IAllBusinessNetNameService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
* 业务进程对照Controller
*
* @author gyt
* @date 2026-03-18
*/
@RestController
@RequestMapping("/allBusinessNetName")
@RequiresPermissions("rocketmq:traffic")
public class AllBusinessNetNameController extends BaseController
{
@Autowired
private IAllBusinessNetNameService allBusinessNetNameService;
/**
* 查询业务进程对照列表
*/
@GetMapping("/list")
public AjaxResult list(AllBusinessNetName allBusinessNetName)
{
List<AllBusinessNetName> list = allBusinessNetNameService.selectAllBusinessNetNameList(allBusinessNetName);
return success(list);
}
/**
* 导出业务进程对照列表
*/
@Log(title = "业务进程对照", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, AllBusinessNetName allBusinessNetName)
{
List<AllBusinessNetName> list = allBusinessNetNameService.selectAllBusinessNetNameList(allBusinessNetName);
ExcelUtil<AllBusinessNetName> util = new ExcelUtil<AllBusinessNetName>(AllBusinessNetName.class);
util.exportExcel(response, list, "业务进程对照数据");
}
/**
* 获取业务进程对照详细信息
*/
@GetMapping(value = "/{id}")
public AjaxResult getInfo(@PathVariable("id") Long id)
{
return success(allBusinessNetNameService.selectAllBusinessNetNameById(id));
}
/**
* 新增业务进程对照
*/
@Log(title = "业务进程对照", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody AllBusinessNetName allBusinessNetName)
{
return toAjax(allBusinessNetNameService.insertAllBusinessNetName(allBusinessNetName));
}
/**
* 修改业务进程对照
*/
@Log(title = "业务进程对照", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody AllBusinessNetName allBusinessNetName)
{
return toAjax(allBusinessNetNameService.updateAllBusinessNetName(allBusinessNetName));
}
/**
* 删除业务进程对照
*/
@Log(title = "业务进程对照", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable Long[] ids)
{
return toAjax(allBusinessNetNameService.deleteAllBusinessNetNameByIds(ids));
}
}
@@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;
/**
* 网络业务流量监控Controller
@@ -90,4 +91,10 @@ public class InitialNetBusinessTrafficController extends BaseController
{
return toAjax(initialNetBusinessTrafficService.deleteInitialNetBusinessTrafficByIds(ids));
}
@PostMapping("/businessTrafficEcharts")
public AjaxResult businessTrafficEcharts(@RequestBody InitialNetBusinessTraffic initialNetBusinessTraffic) {
Map<String, Object> echartsData = initialNetBusinessTrafficService.businessTrafficEcharts(initialNetBusinessTraffic);
return success(echartsData);
}
}
@@ -0,0 +1,29 @@
package com.tongran.rocketmq.domain;
import com.tongran.common.core.annotation.Excel;
import com.tongran.common.core.web.domain.BaseEntity;
import lombok.Data;
/**
* 业务进程对照对象 all_business_net_name
*
* @author gyt
* @date 2026-03-18
*/
@Data
public class AllBusinessNetName extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** 主键ID */
private Long id;
/** 客户端标识 */
@Excel(name = "客户端标识")
private String clientId;
/** 进程名称 */
@Excel(name = "进程名称")
private String processName;
}
@@ -111,4 +111,6 @@ public class InitialBandwidthTraffic extends BaseEntity
private Map<String, List<String>> clientInterfaces;
/** 是否最后一次 */
private boolean lastTrafficFlag;
/** 业务名 */
private String businessName;
}
@@ -0,0 +1,61 @@
package com.tongran.rocketmq.mapper;
import java.util.List;
import com.tongran.rocketmq.domain.AllBusinessNetName;
/**
* 业务进程对照Mapper接口
*
* @author gyt
* @date 2026-03-18
*/
public interface AllBusinessNetNameMapper
{
/**
* 查询业务进程对照
*
* @param id 业务进程对照主键
* @return 业务进程对照
*/
public AllBusinessNetName selectAllBusinessNetNameById(Long id);
/**
* 查询业务进程对照列表
*
* @param allBusinessNetName 业务进程对照
* @return 业务进程对照集合
*/
public List<AllBusinessNetName> selectAllBusinessNetNameList(AllBusinessNetName allBusinessNetName);
/**
* 新增业务进程对照
*
* @param allBusinessNetName 业务进程对照
* @return 结果
*/
public int insertAllBusinessNetName(AllBusinessNetName allBusinessNetName);
/**
* 修改业务进程对照
*
* @param allBusinessNetName 业务进程对照
* @return 结果
*/
public int updateAllBusinessNetName(AllBusinessNetName allBusinessNetName);
/**
* 删除业务进程对照
*
* @param id 业务进程对照主键
* @return 结果
*/
public int deleteAllBusinessNetNameById(Long id);
/**
* 批量删除业务进程对照
*
* @param ids 需要删除的数据主键集合
* @return 结果
*/
public int deleteAllBusinessNetNameByIds(Long[] ids);
}
@@ -0,0 +1,61 @@
package com.tongran.rocketmq.service;
import java.util.List;
import com.tongran.rocketmq.domain.AllBusinessNetName;
/**
* 业务进程对照Service接口
*
* @author gyt
* @date 2026-03-18
*/
public interface IAllBusinessNetNameService
{
/**
* 查询业务进程对照
*
* @param id 业务进程对照主键
* @return 业务进程对照
*/
public AllBusinessNetName selectAllBusinessNetNameById(Long id);
/**
* 查询业务进程对照列表
*
* @param allBusinessNetName 业务进程对照
* @return 业务进程对照集合
*/
public List<AllBusinessNetName> selectAllBusinessNetNameList(AllBusinessNetName allBusinessNetName);
/**
* 新增业务进程对照
*
* @param allBusinessNetName 业务进程对照
* @return 结果
*/
public int insertAllBusinessNetName(AllBusinessNetName allBusinessNetName);
/**
* 修改业务进程对照
*
* @param allBusinessNetName 业务进程对照
* @return 结果
*/
public int updateAllBusinessNetName(AllBusinessNetName allBusinessNetName);
/**
* 批量删除业务进程对照
*
* @param ids 需要删除的业务进程对照主键集合
* @return 结果
*/
public int deleteAllBusinessNetNameByIds(Long[] ids);
/**
* 删除业务进程对照信息
*
* @param id 业务进程对照主键
* @return 结果
*/
public int deleteAllBusinessNetNameById(Long id);
}
@@ -3,6 +3,7 @@ package com.tongran.rocketmq.service;
import com.tongran.rocketmq.domain.InitialNetBusinessTraffic;
import java.util.List;
import java.util.Map;
/**
* 网络业务流量监控Service接口
@@ -61,4 +62,6 @@ public interface IInitialNetBusinessTrafficService
public int deleteInitialNetBusinessTrafficById(Long id);
void batchInsertBusinessTraffic(InitialNetBusinessTraffic data);
void batchInsertBusinessRecoverTraffic(InitialNetBusinessTraffic data);
Map<String, Object> businessTrafficEcharts(InitialNetBusinessTraffic initialNetBusinessTraffic);
}
@@ -0,0 +1,96 @@
package com.tongran.rocketmq.service.impl;
import java.util.List;
import com.tongran.common.core.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.tongran.rocketmq.mapper.AllBusinessNetNameMapper;
import com.tongran.rocketmq.domain.AllBusinessNetName;
import com.tongran.rocketmq.service.IAllBusinessNetNameService;
/**
* 业务进程对照Service业务层处理
*
* @author gyt
* @date 2026-03-18
*/
@Service
public class AllBusinessNetNameServiceImpl implements IAllBusinessNetNameService
{
@Autowired
private AllBusinessNetNameMapper allBusinessNetNameMapper;
/**
* 查询业务进程对照
*
* @param id 业务进程对照主键
* @return 业务进程对照
*/
@Override
public AllBusinessNetName selectAllBusinessNetNameById(Long id)
{
return allBusinessNetNameMapper.selectAllBusinessNetNameById(id);
}
/**
* 查询业务进程对照列表
*
* @param allBusinessNetName 业务进程对照
* @return 业务进程对照
*/
@Override
public List<AllBusinessNetName> selectAllBusinessNetNameList(AllBusinessNetName allBusinessNetName)
{
return allBusinessNetNameMapper.selectAllBusinessNetNameList(allBusinessNetName);
}
/**
* 新增业务进程对照
*
* @param allBusinessNetName 业务进程对照
* @return 结果
*/
@Override
public int insertAllBusinessNetName(AllBusinessNetName allBusinessNetName)
{
allBusinessNetName.setCreateTime(DateUtils.getNowDate());
return allBusinessNetNameMapper.insertAllBusinessNetName(allBusinessNetName);
}
/**
* 修改业务进程对照
*
* @param allBusinessNetName 业务进程对照
* @return 结果
*/
@Override
public int updateAllBusinessNetName(AllBusinessNetName allBusinessNetName)
{
allBusinessNetName.setUpdateTime(DateUtils.getNowDate());
return allBusinessNetNameMapper.updateAllBusinessNetName(allBusinessNetName);
}
/**
* 批量删除业务进程对照
*
* @param ids 需要删除的业务进程对照主键
* @return 结果
*/
@Override
public int deleteAllBusinessNetNameByIds(Long[] ids)
{
return allBusinessNetNameMapper.deleteAllBusinessNetNameByIds(ids);
}
/**
* 删除业务进程对照信息
*
* @param id 业务进程对照主键
* @return 结果
*/
@Override
public int deleteAllBusinessNetNameById(Long id)
{
return allBusinessNetNameMapper.deleteAllBusinessNetNameById(id);
}
}
@@ -7,10 +7,7 @@ import com.tongran.rocketmq.domain.*;
import com.tongran.rocketmq.enums.AlarmTypeEnum;
import com.tongran.rocketmq.enums.ConditionItemEnum;
import com.tongran.rocketmq.mapper.*;
import com.tongran.rocketmq.service.IInitialBandwidthTrafficService;
import com.tongran.rocketmq.service.IInitialDiskInfoService;
import com.tongran.rocketmq.service.IRmAlarmLogService;
import com.tongran.rocketmq.service.IRmNetworkInterfaceService;
import com.tongran.rocketmq.service.*;
import com.tongran.rocketmq.utils.SendAlarmPushUtil;
import com.tongran.rocketmq.utils.TableRouterUtil;
import com.tongran.system.api.RemoteRevenueConfigService;
@@ -23,6 +20,7 @@ import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.*;
@@ -59,6 +57,10 @@ public class InitialBandwidthTrafficServiceImpl implements IInitialBandwidthTraf
private IRmNetworkInterfaceService rmNetworkInterfaceService;
@Autowired
private RemoteRevenueConfigService remoteRevenueConfigService;
@Autowired
private IInitialNetBusinessTrafficService initialNetBusinessTrafficService;
@Autowired
private IAllBusinessNetNameService allBusinessNetNameService;
/**
* 查询初始带宽流量
@@ -583,6 +585,120 @@ public class InitialBandwidthTrafficServiceImpl implements IInitialBandwidthTraf
resultMap.put("yData", yData);
}
try {
// 根据业务名称查询业务进程名
String businessName = initialBandwidthTraffic.getBusinessName();
if(businessName != null){
List<AllBusinessNetName> allBusinessNetNameList = allBusinessNetNameService.selectAllBusinessNetNameList(new AllBusinessNetName());
// 第一步:过滤
List<AllBusinessNetName> filteredList = allBusinessNetNameList.stream()
.filter(item -> businessName.contains(item.getRemark()))
.collect(Collectors.toList());
// 第二步:根据processName去重
Map<String, AllBusinessNetName> uniqueMap = new LinkedHashMap<>();
for (AllBusinessNetName item : filteredList) {
uniqueMap.putIfAbsent(item.getProcessName(), item);
}
List<AllBusinessNetName> result = new ArrayList<>(uniqueMap.values());
// 用于存储所有业务的单位,用于后续统一单位处理
Map<String, String> businessUnits = new HashMap<>();
// 用于存储业务的显示名称
Map<String, String> businessDisplayNames = new HashMap<>();
for (AllBusinessNetName allBusinessNetName : result) {
// 构建业务流量查询对象
InitialNetBusinessTraffic businessTrafficQuery = new InitialNetBusinessTraffic();
businessTrafficQuery.setClientId(initialBandwidthTraffic.getClientId());
businessTrafficQuery.setProcessName(allBusinessNetName.getProcessName());
businessTrafficQuery.setStartTime(initialBandwidthTraffic.getStartTime());
businessTrafficQuery.setEndTime(initialBandwidthTraffic.getEndTime());
// 获取业务流量图表数据
Map<String, Object> businessResult = initialNetBusinessTrafficService.businessTrafficEcharts(businessTrafficQuery);
if (businessResult != null && !businessResult.isEmpty()) {
// 获取业务名称作为前缀标识
String businessPrefix = allBusinessNetName.getProcessName();
// 如果进程名包含特殊字符,可以进一步处理为合法的key
businessPrefix = businessPrefix.replaceAll("[^a-zA-Z0-9]", "_");
// 获取业务流量的y轴数据
Map<String, Object> businessYData = (Map<String, Object>) businessResult.get("yData");
if (businessYData != null && !businessYData.isEmpty()) {
// 获取主Map的yData
Map<String, Object> mainYData = (Map<String, Object>) resultMap.get("yData");
// 将业务流量数据合并到主yData中
for (Map.Entry<String, Object> entry : businessYData.entrySet()) {
String businessKey = entry.getKey();
Object businessValue = entry.getValue();
// 添加业务前缀避免key冲突,格式:business_{进程名}_{数据类型}
String newKey = "business_" + businessPrefix + "_" + businessKey;
mainYData.put(newKey, businessValue);
}
resultMap.put("yData", mainYData);
}
// 获取业务流量的单位
String businessUnit = (String) businessResult.get("unit");
businessUnits.put(businessPrefix, businessUnit);
// 构建业务的显示名称
String displayName = allBusinessNetName.getProcessName();
if (allBusinessNetName.getRemark() != null && !allBusinessNetName.getRemark().isEmpty()) {
displayName = allBusinessNetName.getRemark() + "(" + allBusinessNetName.getProcessName() + ")";
}
businessDisplayNames.put(businessPrefix, displayName);
}
}
// 在所有业务数据处理完成后,统一进行单位转换
if (!businessUnits.isEmpty()) {
// 检查是否有业务的单位与主单位不一致
boolean needUnitConversion = false;
for (String businessUnit : businessUnits.values()) {
if (!unit.equals(businessUnit)) {
needUnitConversion = true;
break;
}
}
// 如果需要单位转换,统一处理
if (needUnitConversion) {
convertAllBusinessDataUnit(resultMap, businessUnits, unit);
}
// 单位转换完成后,添加业务流量的展示关系(不再包含单位信息)
for (Map.Entry<String, String> entry : businessDisplayNames.entrySet()) {
String businessPrefix = entry.getKey();
String displayName = entry.getValue();
showRealation.put("business_" + businessPrefix + "_netInSpeedData",
displayName + " 入站流量");
showRealation.put("business_" + businessPrefix + "_netOutSpeedData",
displayName + " 出站流量");
showRealation.put("business_" + businessPrefix + "_netIpv4InSpeedData",
displayName + " IPv4入站流量");
showRealation.put("business_" + businessPrefix + "_netIpv4OutSpeedData",
displayName + " IPv4出站流量");
showRealation.put("business_" + businessPrefix + "_netIpv6InSpeedData",
displayName + " IPv6入站流量");
showRealation.put("business_" + businessPrefix + "_netIpv6OutSpeedData",
displayName + " IPv6出站流量");
}
}
}
} catch (Exception e) {
// 业务流量数据获取失败,记录日志但不影响主流程
System.err.println("获取业务流量数据失败: " + e.getMessage());
e.printStackTrace();
}
if(!showRealation.isEmpty() && hasSubInterface){
showRealation.put("totalNetInTraffic", name+"总入站流量" + " IPv4: "+ipv4);
showRealation.put("totalNetOutTraffic", name+"总出站流量" + " IPv4: "+ipv4);
@@ -597,6 +713,82 @@ public class InitialBandwidthTrafficServiceImpl implements IInitialBandwidthTraf
return new HashMap<>();
}
}
/**
* 统一转换所有业务数据的单位
*/
private void convertAllBusinessDataUnit(Map<String, Object> resultMap,
Map<String, String> businessUnits,
String targetUnit) {
try {
// 获取主Map的yData
Map<String, Object> mainYData = (Map<String, Object>) resultMap.get("yData");
if (mainYData == null || mainYData.isEmpty()) {
return;
}
// 为每个业务计算转换因子
Map<String, BigDecimal> conversionFactors = new HashMap<>();
for (Map.Entry<String, String> entry : businessUnits.entrySet()) {
String businessPrefix = entry.getKey();
String fromUnit = entry.getValue();
if (!targetUnit.equals(fromUnit)) {
BigDecimal fromDivisor = SpeedUtils.getDivisor(fromUnit);
BigDecimal toDivisor = SpeedUtils.getDivisor(targetUnit);
BigDecimal conversionFactor = fromDivisor.divide(toDivisor, 10, RoundingMode.HALF_UP);
conversionFactors.put(businessPrefix, conversionFactor);
}
}
// 遍历所有业务流量相关的数据项进行转换
for (Map.Entry<String, Object> entry : mainYData.entrySet()) {
String key = entry.getKey();
// 检查是否是业务数据
if (key.startsWith("business_")) {
// 提取业务前缀
String[] keyParts = key.split("_");
if (keyParts.length >= 3) {
String businessPrefix = keyParts[1];
// 如果该业务需要转换
if (conversionFactors.containsKey(businessPrefix)) {
BigDecimal conversionFactor = conversionFactors.get(businessPrefix);
Object value = entry.getValue();
if (value instanceof List) {
List<BigDecimal> dataList = (List<BigDecimal>) value;
List<BigDecimal> convertedList = new ArrayList<>();
for (BigDecimal dataPoint : dataList) {
if (dataPoint != null) {
// 应用转换因子
BigDecimal converted = dataPoint.multiply(conversionFactor)
.setScale(2, RoundingMode.HALF_UP);
convertedList.add(converted);
} else {
convertedList.add(null);
}
}
// 更新转换后的数据
entry.setValue(convertedList);
}
}
}
}
}
// 更新单位为统一单位
resultMap.put("unit", targetUnit);
System.out.println("所有业务数据单位已统一转换为: " + targetUnit);
} catch (Exception e) {
System.err.println("业务流量单位统一转换失败: " + e.getMessage());
}
}
// 安全转换方法(处理可能的NumberFormatException
private Double safeConvertToKB(String byteValue) {
try {
@@ -1,11 +1,12 @@
package com.tongran.rocketmq.service.impl;
import com.tongran.common.core.utils.DateUtils;
import com.tongran.common.core.utils.EchartsDataUtils;
import com.tongran.common.core.utils.SpeedUtils;
import com.tongran.common.core.utils.TableSubUtil;
import com.tongran.rocketmq.domain.InitialNetBusinessTraffic;
import com.tongran.rocketmq.mapper.InitialNetBusinessTrafficMapper;
import com.tongran.rocketmq.service.IInitialNetBusinessTrafficService;
import com.tongran.rocketmq.utils.TableRouterUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
@@ -13,7 +14,10 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
@@ -211,9 +215,56 @@ public class InitialNetBusinessTrafficServiceImpl implements IInitialNetBusiness
});
}
@Override
public Map<String, Object> businessTrafficEcharts(InitialNetBusinessTraffic initialNetBusinessTraffic) {
List<InitialNetBusinessTraffic> list = getListByTableName(initialNetBusinessTraffic);
try {
String unit = SpeedUtils.calculateUnit(list, "inSpeed", "outSpeed");
if(initialNetBusinessTraffic.getUnit() != null){
unit = initialNetBusinessTraffic.getUnit();
}
BigDecimal divisor = SpeedUtils.getDivisor(unit);
Map<String, Function<InitialNetBusinessTraffic, ?>> extractors = new LinkedHashMap<>();
extractors.put("netInSpeedData", info ->
info != null && info.getInSpeed() != null ?
new BigDecimal(info.getInSpeed()).divide(divisor, 2, RoundingMode.HALF_UP) :
null);
extractors.put("netOutSpeedData", info ->
info != null && info.getOutSpeed() != null ?
new BigDecimal(info.getOutSpeed()).divide(divisor, 2, RoundingMode.HALF_UP) :
null);
extractors.put("netIpv4InSpeedData", info ->
info != null && info.getIpv4InSpeed() != null ?
new BigDecimal(info.getIpv4InSpeed()).divide(divisor, 2, RoundingMode.HALF_UP) :
null);
extractors.put("netIpv4OutSpeedData", info ->
info != null && info.getIpv4OutSpeed() != null ?
new BigDecimal(info.getIpv4OutSpeed()).divide(divisor, 2, RoundingMode.HALF_UP) :
null);
extractors.put("netIpv6InSpeedData", info ->
info != null && info.getIpv6InSpeed() != null ?
new BigDecimal(info.getIpv6InSpeed()).divide(divisor, 2, RoundingMode.HALF_UP) :
null);
extractors.put("netIpv6OutSpeedData", info ->
info != null && info.getIpv6OutSpeed() != null ?
new BigDecimal(info.getIpv6OutSpeed()).divide(divisor, 2, RoundingMode.HALF_UP) :
null);
Map<String, Object> resultMap = EchartsDataUtils.buildEchartsDataAutoPadding(
list, InitialNetBusinessTraffic::getCreateTime, extractors,
initialNetBusinessTraffic.getStartTime(), initialNetBusinessTraffic.getEndTime()
);
resultMap.put("unit", unit);
return resultMap;
} catch (Exception e){
e.printStackTrace();
}
return new HashMap<>();
}
public List<InitialNetBusinessTraffic> getListByTableName(InitialNetBusinessTraffic initialNetBusinessTraffic){
// 获取涉及的表名
Set<String> tableNames = TableRouterUtil.getTableNamesBetween(initialNetBusinessTraffic.getStartTime(), initialNetBusinessTraffic.getEndTime());
Set<String> tableNames = TableSubUtil.getTableNamesBetween(initialNetBusinessTraffic.getStartTime(), initialNetBusinessTraffic.getEndTime(),"initial_net_business_traffic");
// 并行查询各表
List<InitialNetBusinessTraffic> list = tableNames.parallelStream()
.flatMap(tableName -> {
@@ -222,7 +273,7 @@ public class InitialNetBusinessTrafficServiceImpl implements IInitialNetBusiness
condition.setStartTime(initialNetBusinessTraffic.getStartTime());
condition.setEndTime(initialNetBusinessTraffic.getEndTime());
condition.setClientId(initialNetBusinessTraffic.getClientId());
condition.setName(initialNetBusinessTraffic.getName());
condition.setProcessName(initialNetBusinessTraffic.getProcessName());
return initialNetBusinessTrafficMapper.getNetBusinessTrafficList(condition).stream();
})
.collect(Collectors.toList());
@@ -0,0 +1,82 @@
<?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.rocketmq.mapper.AllBusinessNetNameMapper">
<resultMap type="AllBusinessNetName" id="AllBusinessNetNameResult">
<result property="id" column="id" />
<result property="clientId" column="client_id" />
<result property="processName" column="process_name" />
<result property="remark" column="remark" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
</resultMap>
<sql id="selectAllBusinessNetNameVo">
select id, client_id, process_name, remark, create_by, create_time, update_by, update_time from all_business_net_name
</sql>
<select id="selectAllBusinessNetNameList" parameterType="AllBusinessNetName" resultMap="AllBusinessNetNameResult">
<include refid="selectAllBusinessNetNameVo"/>
<where>
<if test="clientId != null and clientId != ''"> and client_id = #{clientId}</if>
<if test="processName != null and processName != ''"> and process_name like concat('%', #{processName}, '%')</if>
<if test="remark != null and remark != ''"> and remark like concat('%', #{remark}, '%')</if>
</where>
</select>
<select id="selectAllBusinessNetNameById" parameterType="Long" resultMap="AllBusinessNetNameResult">
<include refid="selectAllBusinessNetNameVo"/>
where id = #{id}
</select>
<insert id="insertAllBusinessNetName" parameterType="AllBusinessNetName" useGeneratedKeys="true" keyProperty="id">
insert into all_business_net_name
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="clientId != null">client_id,</if>
<if test="processName != null">process_name,</if>
<if test="remark != null">remark,</if>
<if test="createBy != null">create_by,</if>
<if test="createTime != null">create_time,</if>
<if test="updateBy != null">update_by,</if>
<if test="updateTime != null">update_time,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="clientId != null">#{clientId},</if>
<if test="processName != null">#{processName},</if>
<if test="remark != null">#{remark},</if>
<if test="createBy != null">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
<if test="updateBy != null">#{updateBy},</if>
<if test="updateTime != null">#{updateTime},</if>
</trim>
</insert>
<update id="updateAllBusinessNetName" parameterType="AllBusinessNetName">
update all_business_net_name
<trim prefix="SET" suffixOverrides=",">
<if test="clientId != null">client_id = #{clientId},</if>
<if test="processName != null">process_name = #{processName},</if>
<if test="remark != null">remark = #{remark},</if>
<if test="createBy != null">create_by = #{createBy},</if>
<if test="createTime != null">create_time = #{createTime},</if>
<if test="updateBy != null">update_by = #{updateBy},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
</trim>
where id = #{id}
</update>
<delete id="deleteAllBusinessNetNameById" parameterType="Long">
delete from all_business_net_name where id = #{id}
</delete>
<delete id="deleteAllBusinessNetNameByIds" parameterType="String">
delete from all_business_net_name where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
</mapper>