增加计算单位可选方法.
优化图形分析根据可选时间补0逻辑,完成度70%。 优化业务自定义95值计算功能修改相关数据方法。
This commit is contained in:
+2
@@ -120,6 +120,8 @@ public class EpsInitialTrafficData extends BaseEntity {
|
||||
private String calculationMode;
|
||||
/** 95值 */
|
||||
private BigDecimal percentile95;
|
||||
/** 单位 */
|
||||
private String unit;
|
||||
|
||||
|
||||
}
|
||||
+2
@@ -124,4 +124,6 @@ public class InitialSwitchInfoDetails extends BaseEntity
|
||||
private String interfaceNameRemark;
|
||||
/** 95值 */
|
||||
private BigDecimal percentile95;
|
||||
/** 单位 */
|
||||
private String unit;
|
||||
}
|
||||
|
||||
+44
-33
@@ -496,9 +496,11 @@ public class EpsInitialTrafficDataServiceImpl implements EpsInitialTrafficDataSe
|
||||
joiner.add("【" + businessName + "】");
|
||||
}
|
||||
String name = joiner.toString();
|
||||
resultMap.put("name", name);
|
||||
resultMap.put("timeRange", timeRange);
|
||||
resultList.add(resultMap);
|
||||
if(resultMap != null){
|
||||
resultMap.put("name", name);
|
||||
resultMap.put("timeRange", timeRange);
|
||||
resultList.add(resultMap);
|
||||
}
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -574,9 +576,11 @@ public class EpsInitialTrafficDataServiceImpl implements EpsInitialTrafficDataSe
|
||||
joiner.add("【" + businessName + "】");
|
||||
}
|
||||
String name = joiner.toString();
|
||||
resultMap.put("name", name);
|
||||
resultMap.put("timeRange", timeRange);
|
||||
resultList.add(resultMap);
|
||||
if(resultMap != null){
|
||||
resultMap.put("name", name);
|
||||
resultMap.put("timeRange", timeRange);
|
||||
resultList.add(resultMap);
|
||||
}
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -592,34 +596,41 @@ public class EpsInitialTrafficDataServiceImpl implements EpsInitialTrafficDataSe
|
||||
*/
|
||||
public Map<String, Object> serverNetSpeedEcharts(EpsInitialTrafficData epsInitialTrafficData, BigDecimal percentile95) {
|
||||
List<EpsInitialTrafficData> list = getTrafficListByClientIds(epsInitialTrafficData);
|
||||
if(!list.isEmpty()){
|
||||
try {
|
||||
list.forEach(data -> data.setPercentile95(SpeedUtils.mbitToBit(percentile95)));
|
||||
SpeedUtils.SpeedResult result = SpeedUtils.calculateWithStringTraffic(list, "inSpeed", "outSpeed");
|
||||
BigDecimal divisor = SpeedUtils.getDivisor(result.getRecommendedUnit());
|
||||
Map<String, Function<EpsInitialTrafficData, ?>> extractors = new LinkedHashMap<>();
|
||||
|
||||
extractors.put("netOutSpeedData", info ->
|
||||
info != null && info.getOutSpeed() != null ?
|
||||
new BigDecimal(info.getOutSpeed()).divide(divisor, 2, RoundingMode.HALF_UP) :
|
||||
0);
|
||||
extractors.put("netMachineFlowData", info ->
|
||||
info != null && info.getMachineFlow() != null ?
|
||||
new BigDecimal(info.getMachineFlow()).divide(divisor, 2, RoundingMode.HALF_UP) :
|
||||
0);
|
||||
extractors.put("percentile95", info ->
|
||||
info != null && info.getPercentile95() != null ?
|
||||
info.getPercentile95().divide(divisor, 2, RoundingMode.HALF_UP) :
|
||||
0);
|
||||
Map<String, Object> resultMap = EchartsDataUtils.buildEchartsData(list, EpsInitialTrafficData::getCreateTime, extractors);
|
||||
resultMap.put("other", result);
|
||||
resultMap.put("95value", percentile95);
|
||||
return resultMap;
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
if(list == null){
|
||||
list = new ArrayList<>();
|
||||
}
|
||||
return new HashMap<>();
|
||||
try {
|
||||
list.forEach(data -> data.setPercentile95(SpeedUtils.mbitToBit(percentile95)));
|
||||
SpeedUtils.SpeedResult result = SpeedUtils.calculateWithStringTraffic(list, "inSpeed", "outSpeed");
|
||||
String unit = result.getRecommendedUnit();
|
||||
if(epsInitialTrafficData.getUnit() != null){
|
||||
unit = epsInitialTrafficData.getUnit();
|
||||
}
|
||||
BigDecimal divisor = SpeedUtils.getDivisor(unit);
|
||||
Map<String, Function<EpsInitialTrafficData, ?>> extractors = new LinkedHashMap<>();
|
||||
|
||||
extractors.put("netOutSpeedData", info ->
|
||||
info != null && info.getOutSpeed() != null ?
|
||||
new BigDecimal(info.getOutSpeed()).divide(divisor, 2, RoundingMode.HALF_UP) :
|
||||
0);
|
||||
extractors.put("netMachineFlowData", info ->
|
||||
info != null && info.getMachineFlow() != null ?
|
||||
new BigDecimal(info.getMachineFlow()).divide(divisor, 2, RoundingMode.HALF_UP) :
|
||||
0);
|
||||
extractors.put("percentile95", info ->
|
||||
info != null && info.getPercentile95() != null ?
|
||||
info.getPercentile95().divide(divisor, 2, RoundingMode.HALF_UP) :
|
||||
0);
|
||||
Map<String, Object> resultMap = EchartsDataUtils.buildEchartsDataAutoPadding(
|
||||
list, EpsInitialTrafficData::getCreateTime, extractors, epsInitialTrafficData.getStartTime(), epsInitialTrafficData.getEndTime()
|
||||
);
|
||||
resultMap.put("other", result);
|
||||
resultMap.put("95value", percentile95);
|
||||
return resultMap;
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* 提取公共方法
|
||||
|
||||
+36
-5
@@ -85,6 +85,14 @@ public class EpsTaskStatisticsServiceImpl implements IEpsTaskStatisticsService
|
||||
timeRange = startTime + "~" + endTime;
|
||||
}
|
||||
taskStatistics.setTimeRange(timeRange);
|
||||
// 处理包含资源
|
||||
String resources = taskStatistics.getIncludedResources();
|
||||
String result = Arrays.stream(resources.split(","))
|
||||
.map(msg -> msg.split(";"))
|
||||
.filter(resource -> resource.length >= 4)
|
||||
.map(resource -> "[" + resource[3] + "].[" + resource[2] + "]")
|
||||
.collect(Collectors.joining("\n"));
|
||||
taskStatistics.setIncludedResources(result);
|
||||
}
|
||||
return epsTaskStatisticsList;
|
||||
}
|
||||
@@ -437,15 +445,38 @@ public class EpsTaskStatisticsServiceImpl implements IEpsTaskStatisticsService
|
||||
Long taskId = epsTaskStatistics.getId();
|
||||
EpsTaskStatistics taskMsg = epsTaskStatisticsMapper.selectEpsTaskStatisticsById(taskId);
|
||||
if(StringUtils.equals("1", taskMsg.getResourceType())){
|
||||
EpsInitialTrafficData epsInitialTrafficData = new EpsInitialTrafficData();
|
||||
epsInitialTrafficData.setOutSpeed(epsTaskStatistics.getNeedSpeed().toString());
|
||||
epsInitialTrafficData.setCreateTime(DateUtils.parseDate(epsTaskStatistics.getNeedTime()));
|
||||
trafficRedisHashUtil.updateItemInHash(taskId.toString(), epsInitialTrafficData, epsTaskStatistics.getNeedTime());
|
||||
trafficRedisHashUtil.updateItemPropertyInHash(taskId.toString(), epsTaskStatistics.getNeedTime(),
|
||||
item -> {
|
||||
if (item instanceof EpsInitialTrafficData) {
|
||||
EpsInitialTrafficData trafficItem = (EpsInitialTrafficData) item;
|
||||
trafficItem.setOutSpeed(epsTaskStatistics.getNeedSpeed().toString()); // 只修改outSpeed属性
|
||||
}
|
||||
},
|
||||
Comparator.comparing(
|
||||
(EpsInitialTrafficData item) -> {
|
||||
String speed = item.getOutSpeed();
|
||||
return speed != null ? Double.parseDouble(speed) : 0.0;
|
||||
},
|
||||
Comparator.reverseOrder() // 倒序
|
||||
)
|
||||
);
|
||||
}else{
|
||||
InitialSwitchInfoDetails initialSwitchInfoDetails = new InitialSwitchInfoDetails();
|
||||
initialSwitchInfoDetails.setMaxSpeed(epsTaskStatistics.getNeedSpeed());
|
||||
initialSwitchInfoDetails.setCreateTime(DateUtils.parseDate(epsTaskStatistics.getNeedTime()));
|
||||
trafficRedisHashUtil.updateItemInHash(taskId.toString(), initialSwitchInfoDetails, epsTaskStatistics.getNeedTime());
|
||||
trafficRedisHashUtil.updateItemPropertyInHash(taskId.toString(), epsTaskStatistics.getNeedTime(),
|
||||
item -> {
|
||||
if (item instanceof InitialSwitchInfoDetails) {
|
||||
InitialSwitchInfoDetails trafficItem = (InitialSwitchInfoDetails) item;
|
||||
trafficItem.setMaxSpeed(epsTaskStatistics.getNeedSpeed()); // 只修改outSpeed属性
|
||||
}
|
||||
},
|
||||
Comparator.comparing(
|
||||
(InitialSwitchInfoDetails item) ->
|
||||
item.getMaxSpeed() != null ? item.getMaxSpeed() : BigDecimal.ZERO,
|
||||
Comparator.reverseOrder() // 倒序
|
||||
)
|
||||
);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
+16
-8
@@ -803,9 +803,11 @@ public class InitialSwitchInfoDetailsServiceImpl implements IInitialSwitchInfoDe
|
||||
joiner.add("【" + businessName + "】");
|
||||
}
|
||||
String name = joiner.toString();
|
||||
resultMap.put("name", name);
|
||||
resultMap.put("timeRange", timeRange);
|
||||
resultList.add(resultMap);
|
||||
if(resultMap != null){
|
||||
resultMap.put("name", name);
|
||||
resultMap.put("timeRange", timeRange);
|
||||
resultList.add(resultMap);
|
||||
}
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -900,9 +902,11 @@ public class InitialSwitchInfoDetailsServiceImpl implements IInitialSwitchInfoDe
|
||||
joiner.add("【" + businessName + "】");
|
||||
}
|
||||
String name = joiner.toString();
|
||||
resultMap.put("name", name);
|
||||
resultMap.put("timeRange", timeRange);
|
||||
resultList.add(resultMap);
|
||||
if(resultMap != null){
|
||||
resultMap.put("name", name);
|
||||
resultMap.put("timeRange", timeRange);
|
||||
resultList.add(resultMap);
|
||||
}
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -922,7 +926,11 @@ public class InitialSwitchInfoDetailsServiceImpl implements IInitialSwitchInfoDe
|
||||
try {
|
||||
list.forEach(data -> data.setPercentile95(SpeedUtils.mbitToBit(percentile95)));
|
||||
SpeedUtils.SpeedResult result = SpeedUtils.calculateWithAverageBasedUnit(list, "inSpeed", "outSpeed");
|
||||
BigDecimal divisor = SpeedUtils.getDivisor(result.getRecommendedUnit());
|
||||
String unit = result.getRecommendedUnit();
|
||||
if(initialSwitchInfoDetails.getUnit() != null){
|
||||
unit = initialSwitchInfoDetails.getUnit();
|
||||
}
|
||||
BigDecimal divisor = SpeedUtils.getDivisor(unit);
|
||||
Map<String, Function<InitialSwitchInfoDetails, ?>> extractors = new LinkedHashMap<>();
|
||||
extractors.put("netInSpeedData", info ->
|
||||
info != null && info.getInSpeed() != null ?
|
||||
@@ -944,6 +952,6 @@ public class InitialSwitchInfoDetailsServiceImpl implements IInitialSwitchInfoDe
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
return new HashMap<>();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import java.util.regex.Pattern;
|
||||
|
||||
public class CalculateUtil {
|
||||
|
||||
private static final Pattern SPEED_PATTERN = Pattern.compile("(\\d+\\.?\\d*)\\s*(\\S*)");
|
||||
private static final Pattern SPEED_PATTERN = Pattern.compile("^\\s*([-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(?:[eE][-+]?\\d+)?)\\s*([a-zA-Z/]*)?\\s*$");
|
||||
/**
|
||||
* 单位换算
|
||||
* @param speedWithUnit
|
||||
|
||||
+32
@@ -77,6 +77,38 @@ public class TrafficRedisHashUtil {
|
||||
saveListToHash(taskId, dataList);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 修改列表中某条数据的特定属性值,并重新排序
|
||||
* @param taskId 任务ID
|
||||
* @param createTime 用于匹配的时间
|
||||
* @param propertyUpdater 属性修改器
|
||||
* @param comparator 排序比较器(用于重新排序)
|
||||
*/
|
||||
public <T> void updateItemPropertyInHash(String taskId, String createTime,
|
||||
java.util.function.Consumer<T> propertyUpdater,
|
||||
java.util.Comparator<T> comparator) {
|
||||
List<T> dataList = (List<T>) getListFromHash(taskId);
|
||||
|
||||
if (dataList != null) {
|
||||
boolean modified = false;
|
||||
for (int i = 0; i < dataList.size(); i++) {
|
||||
T item = dataList.get(i);
|
||||
String itemCreateTime = getCreateTimeFromObject(item);
|
||||
if (itemCreateTime != null && itemCreateTime.equals(createTime)) {
|
||||
// 只修改匹配项的属性
|
||||
propertyUpdater.accept(item);
|
||||
modified = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (modified) {
|
||||
// 重新排序(从大到小)
|
||||
dataList.sort(comparator);
|
||||
saveListToHash(taskId, dataList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新Hash中的特定项(使用自定义匹配器)
|
||||
|
||||
+3
@@ -76,6 +76,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<when test="userId != null">
|
||||
and user_id = #{userId}
|
||||
</when>
|
||||
<when test="pageRoute != null">
|
||||
and page_route = #{pageRoute}
|
||||
</when>
|
||||
<otherwise>
|
||||
and 1=0 <!-- 如果两个条件都不满足,则不更新任何记录 -->
|
||||
</otherwise>
|
||||
|
||||
Reference in New Issue
Block a user