修复时间戳与数据表入库时间差1秒问题,开发重新计算接口,交换机详情增加业务代码,业务名称,修复各个表业务信息不匹配问题
This commit is contained in:
+1
-1
@@ -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());
|
||||
|
||||
|
||||
+11
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+4
@@ -76,6 +76,10 @@ public class InitialSwitchInfoDetails extends BaseEntity
|
||||
/** 交换机硬件SN */
|
||||
@Excel(name = "交换机硬件SN")
|
||||
private String switchSn;
|
||||
/** 业务代码 */
|
||||
private String businessCode;
|
||||
/** 业务名称 */
|
||||
private String businessName;
|
||||
/** 数据集合 */
|
||||
private List<InitialSwitchInfoDetails> dataList;
|
||||
|
||||
|
||||
+6
@@ -72,4 +72,10 @@ public interface IInitialSwitchInfoDetailsService
|
||||
* @return 流量数据列表
|
||||
*/
|
||||
void calculateSwitch95BandwidthDaily(InitialSwitchInfoDetails queryParam, String dailyStartTime, String dailyEndTime);
|
||||
|
||||
/**
|
||||
* 重新计算交换机95带宽值
|
||||
* @param id
|
||||
*/
|
||||
void recalculateSwitch95Bandwidth(Long id);
|
||||
}
|
||||
|
||||
+11
-2
@@ -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<EpsNodeBandwidth> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -197,7 +197,7 @@ public class EpsNodeBandwidthServiceImpl implements IEpsNodeBandwidthService
|
||||
revenueConfig.setHardwareSn(epsNodeBandwidth.getHardwareSn());
|
||||
List<EpsServerRevenueConfig> 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 &&
|
||||
|
||||
+108
-5
@@ -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<EpsServerRevenueConfig> 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<EpsServerRevenueConfig> 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<InitialSwitchInfoDetails> dataList = initialSwitchInfoDetailsMapper
|
||||
.selectInitialSwitchInfoDetailsList(switchInfoDetails);
|
||||
// 1. 提取并转换带宽值
|
||||
List<BigDecimal> 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<EpsNodeBandwidth> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user