From 8aaa60d7efc7affd6803569e4bb44e0eee764827 Mon Sep 17 00:00:00 2001 From: gaoyutao Date: Thu, 4 Sep 2025 23:18:08 +0800 Subject: [PATCH] =?UTF-8?q?=E6=BA=90=E6=95=B0=E6=8D=AE=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=EF=BC=8C=E8=A7=A3=E5=86=B3=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E5=90=8D=E7=A7=B0=E8=A1=A8=E6=95=B0=E6=8D=AE=E9=87=8D=E5=A4=8D?= =?UTF-8?q?bug,=E5=A2=9E=E5=8A=A0=E8=B5=84=E6=BA=90=E5=90=8D=E7=A7=B0?= =?UTF-8?q?=E5=90=8C=E6=AD=A5=E4=BF=AE=E6=94=B9=E9=80=BB=E8=BE=91=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../EpsNodeBandwidthController.java | 10 + .../EpsServerRevenueConfigController.java | 2 +- .../ruoyi/system/domain/EpsNodeBandwidth.java | 3 + .../system/mapper/EpsNodeBandwidthMapper.java | 2 + .../mapper/EpsServerRevenueConfigMapper.java | 2 + .../mapper/RmEpsTopologyManagementMapper.java | 2 + .../impl/EpsNodeBandwidthServiceImpl.java | 21 +- .../EpsServerRevenueConfigServiceImpl.java | 117 ++++++---- .../InitialSwitchInfoDetailsServiceImpl.java | 147 +++++++------ .../RmResourceRegistrationServiceImpl.java | 34 ++- .../mapper/system/AllInterfaceNameMapper.xml | 20 +- .../mapper/system/EpsNodeBandwidthMapper.xml | 14 +- .../system/EpsServerRevenueConfigMapper.xml | 7 + .../system/RmEpsTopologyManagementMapper.xml | 8 + .../controller/InitialCpuInfoController.java | 35 ++- .../controller/InitialDiskInfoController.java | 35 ++- .../InitialDockerInfoController.java | 35 ++- .../InitialMemoryInfoController.java | 35 ++- .../InitialMountPointInfoController.java | 35 ++- .../InitialSystemInfoController.java | 35 ++- .../ruoyi/rocketmq/domain/InitialCpuInfo.java | 206 ++---------------- .../rocketmq/domain/InitialDiskInfo.java | 134 +----------- .../rocketmq/domain/NetInterfaceInfo.java | 22 -- .../mapper/rocketmq/InitialCpuInfoMapper.xml | 1 + .../mapper/rocketmq/InitialDiskInfoMapper.xml | 1 + .../rocketmq/InitialDockerInfoMapper.xml | 1 + .../rocketmq/InitialMemoryInfoMapper.xml | 1 + .../rocketmq/InitialMountPointInfoMapper.xml | 1 + .../rocketmq/InitialSystemInfoMapper.xml | 1 + 29 files changed, 396 insertions(+), 571 deletions(-) delete mode 100644 ruoyi-rocketmq/src/main/java/com/ruoyi/rocketmq/domain/NetInterfaceInfo.java diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/EpsNodeBandwidthController.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/EpsNodeBandwidthController.java index a7d6af1..fcf2f6a 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/EpsNodeBandwidthController.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/EpsNodeBandwidthController.java @@ -25,6 +25,7 @@ import org.springframework.web.bind.annotation.*; import org.webjars.NotFoundException; import javax.servlet.http.HttpServletResponse; +import java.math.BigDecimal; import java.time.ZoneId; import java.time.format.DateTimeFormatter; import java.time.temporal.ChronoUnit; @@ -197,6 +198,15 @@ public class EpsNodeBandwidthController extends BaseController if ("1".equals(resourceType)) { // 处理服务器流量数据 PageInfo pageInfo = epsNodeBandwidthService.relatedData(epsNodeBandwidth, dailyStartTime, dailyEndTime);; + for (EpsInitialTrafficData epsInitialTrafficData : pageInfo.getList()) { + if("2".equals(epsInitialTrafficData.getRevenueMethod())){ + BigDecimal packageBandwidth = epsInitialTrafficData.getPackageBandwidth(); + BigDecimal outSpeed = (packageBandwidth != null) + ? packageBandwidth.multiply(new BigDecimal("1000000")) + : BigDecimal.ZERO; + epsInitialTrafficData.setOutSpeed(outSpeed.toString()); + } + } return getDataTable(pageInfo.getList(), pageInfo.getTotal()); } else{ // 4. 设置分页参数 diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/EpsServerRevenueConfigController.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/EpsServerRevenueConfigController.java index ec3f26a..66d049c 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/EpsServerRevenueConfigController.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/EpsServerRevenueConfigController.java @@ -36,7 +36,7 @@ public class EpsServerRevenueConfigController extends BaseController */ @RequiresPermissions("system:config:list") @PostMapping("/list") - public TableDataInfo list(EpsServerRevenueConfig epsServerRevenueConfig) + public TableDataInfo list(@RequestBody EpsServerRevenueConfig epsServerRevenueConfig) { PageDomain pageDomain = new PageDomain(); pageDomain.setPageNum(epsServerRevenueConfig.getPageNum()); diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/EpsNodeBandwidth.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/EpsNodeBandwidth.java index 203f2f7..f027201 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/EpsNodeBandwidth.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/EpsNodeBandwidth.java @@ -129,6 +129,9 @@ public class EpsNodeBandwidth extends BaseEntity private String monthTime; /** 备注 */ private String remark1; + /** 创建时间 */ + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date createDatetime; private List nodeNames; diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/EpsNodeBandwidthMapper.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/EpsNodeBandwidthMapper.java index 9d0c097..c8604d4 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/EpsNodeBandwidthMapper.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/EpsNodeBandwidthMapper.java @@ -81,4 +81,6 @@ public interface EpsNodeBandwidthMapper * @return 节点带宽信息 */ public int countByAvgMsg(EpsNodeBandwidth epsNodeBandwidth); + + int updateEpsNodeBandwidthByServerSn(EpsNodeBandwidth epsNodeBandwidth); } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/EpsServerRevenueConfigMapper.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/EpsServerRevenueConfigMapper.java index 7c1baa0..a4f4815 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/EpsServerRevenueConfigMapper.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/EpsServerRevenueConfigMapper.java @@ -77,4 +77,6 @@ public interface EpsServerRevenueConfigMapper * @return 服务器收益方式配置 */ public Map getNodeMsgByIp(@Param("ipAddress") String ipAddress); + + int updateEpsServerRevenueConfigByServerSn(EpsServerRevenueConfig epsServerRevenueConfig); } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/RmEpsTopologyManagementMapper.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/RmEpsTopologyManagementMapper.java index 20fd4f3..6789044 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/RmEpsTopologyManagementMapper.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/RmEpsTopologyManagementMapper.java @@ -59,4 +59,6 @@ public interface RmEpsTopologyManagementMapper * @return 结果 */ public int deleteRmEpsTopologyManagementByIds(Long[] ids); + + int updateRmEpsTopologyManagementByServerSn(RmEpsTopologyManagement rmEpsTopologyManagement); } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/EpsNodeBandwidthServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/EpsNodeBandwidthServiceImpl.java index 0ca1770..54810c9 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/EpsNodeBandwidthServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/EpsNodeBandwidthServiceImpl.java @@ -167,7 +167,6 @@ public class EpsNodeBandwidthServiceImpl implements IEpsNodeBandwidthService return 0; } - // 3. 获取计算数据(防止空指针) EpsNodeBandwidth calculatedData = epsNodeBandwidthMapper.calculateAvg(epsNodeBandwidth); if (calculatedData == null) { @@ -182,8 +181,12 @@ public class EpsNodeBandwidthServiceImpl implements IEpsNodeBandwidthService // 5. 计算当月天数 LocalDate monthTime; try { - monthTime = LocalDate.parse(epsNodeBandwidth.getMonthTime() == null - ? epsNodeBandwidth.getStartTime().substring(0,10) : epsNodeBandwidth.getMonthTime()); + String monthStr = epsNodeBandwidth.getMonthTime() == null + ? epsNodeBandwidth.getStartTime().substring(0, 7) + : epsNodeBandwidth.getMonthTime(); + + YearMonth yearMonth = YearMonth.parse(monthStr); + monthTime = yearMonth.atDay(1); // 转换为当月第一天 } catch (Exception e) { log.error("月份时间格式错误: {}", epsNodeBandwidth.getMonthTime() == null ? epsNodeBandwidth.getStartTime() : epsNodeBandwidth.getMonthTime(), e); @@ -224,7 +227,11 @@ public class EpsNodeBandwidthServiceImpl implements IEpsNodeBandwidthService epsNodeBandwidth.setId(existingRecords.get(0).getId()); epsNodeBandwidth.setUpdateTime(DateUtils.getNowDate()); }else{ - epsNodeBandwidth.setCreateTime(DateUtils.parseDate(epsNodeBandwidth.getStartTime())); + if(epsNodeBandwidth.getStartTime() == null){ + epsNodeBandwidth.setCreateTime(DateUtils.parseDate(monthTime)); + }else{ + epsNodeBandwidth.setCreateTime(DateUtils.parseDate(epsNodeBandwidth.getStartTime())); + } } // 有效-月均日95值 BigDecimal effectiveAvg = sumEffectiveBandwidth95Daily.divide(BigDecimal.valueOf(daysInMonth), 2, RoundingMode.HALF_UP); @@ -242,7 +249,11 @@ public class EpsNodeBandwidthServiceImpl implements IEpsNodeBandwidthService epsNodeBandwidth.setId(existingRecords.get(0).getId()); epsNodeBandwidth.setUpdateTime(DateUtils.getNowDate()); }else{ - epsNodeBandwidth.setCreateTime(DateUtils.parseDate(epsNodeBandwidth.getStartTime())); + if(epsNodeBandwidth.getStartTime() == null){ + epsNodeBandwidth.setCreateTime(DateUtils.parseDate(monthTime)); + }else{ + epsNodeBandwidth.setCreateTime(DateUtils.parseDate(epsNodeBandwidth.getStartTime())); + } } // 月均日95值 BigDecimal avgMonthly = sum95Daily.divide(BigDecimal.valueOf(daysInMonth), 2, RoundingMode.HALF_UP); diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/EpsServerRevenueConfigServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/EpsServerRevenueConfigServiceImpl.java index 49aca1d..e4d79c2 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/EpsServerRevenueConfigServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/EpsServerRevenueConfigServiceImpl.java @@ -15,12 +15,11 @@ import com.ruoyi.system.service.EpsInitialTrafficDataService; import com.ruoyi.system.service.IEpsServerRevenueConfigService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.dao.DuplicateKeyException; import org.springframework.stereotype.Service; import java.math.BigDecimal; import java.util.*; -import java.util.function.Function; -import java.util.stream.Collectors; /** * 服务器收益方式配置Service业务层处理 @@ -176,7 +175,11 @@ public class EpsServerRevenueConfigServiceImpl implements IEpsServerRevenueConfi for (EpsInitialTrafficData initialTrafficData : dataList) { // 根据ip查询节点名称 String ip = initialTrafficData.getIpV4() == null ? "" : initialTrafficData.getIpV4(); + String mac = initialTrafficData.getMac() == null ? "" : initialTrafficData.getMac(); Map nodeMsg = epsServerRevenueConfigMapper.getNodeMsgByIp(ip); + if(nodeMsg == null){ + nodeMsg = epsServerRevenueConfigMapper.getNodeMsgByIp(mac); + } // 赋值 if(nodeMsg != null){ initialTrafficData.setServiceSn(getNullableString(nodeMsg, "hardwareSn")); @@ -221,67 +224,97 @@ public class EpsServerRevenueConfigServiceImpl implements IEpsServerRevenueConfi * 批量处理接口名称 */ private void processInterfaceNames(List trafficDataList) { - // 收集所有需要检查的接口名称 - Set interfaceNames = trafficDataList.stream() - .map(EpsInitialTrafficData::getName) - .filter(StringUtils::isNotBlank) - .collect(Collectors.toSet()); - - if (interfaceNames.isEmpty()) { - return; - } - - // 批量查询已存在的接口名称 - AllInterfaceName allInterfaceName = new AllInterfaceName(); - if(!trafficDataList.isEmpty()){ - allInterfaceName.setClientId(trafficDataList.get(0).getClientId()); - allInterfaceName.setInterfaceNames(interfaceNames); - } - List existingNames = allInterfaceNameMapper.selectByNames(allInterfaceName); - // 转为 Map<接口名称, 数据库记录> 便于快速查找 - Map existingNameMap = existingNames.stream() - .collect(Collectors.toMap( - item -> item.getClientId() + "|" + item.getInterfaceName(), // 关键修改点 - Function.identity(), - (oldValue, newValue) -> oldValue // 重复时保留旧记录 - )); // 分类处理:新增列表 vs 更新列表 List namesToInsert = new ArrayList<>(); List namesToUpdate = new ArrayList<>(); + // 用于去重的临时集合,防止同一批数据中的重复 + Set processedKeys = new HashSet<>(); + trafficDataList.forEach(data -> { String name = data.getName(); - if (StringUtils.isBlank(name)) { + String ip = data.getMac(); + String clientId = data.getClientId(); + if (StringUtils.isBlank(name) || StringUtils.isBlank(ip) || StringUtils.isBlank(clientId)) { return; } - // 构造新记录(需更新的字段) + // 生成唯一键,防止同一批数据中的重复处理 + String uniqueKey = name + "|" + clientId + "|" + ip; + if (processedKeys.contains(uniqueKey)) { + return; + } + processedKeys.add(uniqueKey); + + // 构造新记录 AllInterfaceName newRecord = new AllInterfaceName(); newRecord.setInterfaceName(name); newRecord.setClientId(data.getClientId()); - newRecord.setResourceType("1"); // 固定值 + newRecord.setResourceType("1"); newRecord.setDeviceSn(data.getServiceSn()); newRecord.setNodeName(data.getNodeName()); newRecord.setBusinessCode(data.getBusinessId()); newRecord.setBusinessName(data.getBusinessName()); - newRecord.setServerIp(data.getIpV4()); - // 判断是否需要更新 - String compositeKey = data.getClientId() + "|" + name; - if (existingNameMap.containsKey(compositeKey)) { - AllInterfaceName oldRecord = existingNameMap.get(compositeKey); - if (isRecordChanged(oldRecord, newRecord)) { - newRecord.setId(oldRecord.getId()); // 保留原ID - namesToUpdate.add(newRecord); + newRecord.setServerIp(data.getMac()); + + List existingNames = allInterfaceNameMapper.selectByNames(newRecord); + + if (!existingNames.isEmpty()) { + for (AllInterfaceName existingName : existingNames) { + if (isRecordChanged(existingName, newRecord)) { + newRecord.setId(existingName.getId()); + newRecord.setUpdateTime(DateUtils.getNowDate()); + + // 检查是否已经存在于更新列表中 + boolean alreadyInUpdateList = namesToUpdate.stream() + .anyMatch(item -> item.getId() != null && item.getId().equals(existingName.getId())); + if (!alreadyInUpdateList) { + namesToUpdate.add(newRecord); + } + } } } else { - namesToInsert.add(newRecord); + newRecord.setCreateTime(DateUtils.getNowDate()); + newRecord.setUpdateTime(DateUtils.getNowDate()); + + // 检查namesToInsert中是否已有相同记录 + boolean alreadyInInsertList = namesToInsert.stream() + .anyMatch(item -> item.getInterfaceName().equals(name) + && item.getClientId().equals(clientId) + && item.getServerIp().equals(ip)); + + if (!alreadyInInsertList) { + namesToInsert.add(newRecord); + } } }); // 批量操作数据库 if (!namesToInsert.isEmpty()) { - allInterfaceNameMapper.batchInsert(namesToInsert); - log.info("新增接口名称数量:{}", namesToInsert.size()); + try { + allInterfaceNameMapper.batchInsert(namesToInsert); + log.info("新增接口名称数量:{}", namesToInsert.size()); + } catch (DuplicateKeyException e) { + // 如果批量插入出现重复,转为逐条插入(带异常处理) + log.warn("批量插入出现重复,转为逐条处理"); + namesToInsert.forEach(record -> { + try { + allInterfaceNameMapper.insertAllInterfaceName(record); + } catch (DuplicateKeyException ex) { + // 重复记录转为更新 + AllInterfaceName query = new AllInterfaceName(); + query.setInterfaceName(record.getInterfaceName()); + query.setClientId(record.getClientId()); + query.setServerIp(record.getServerIp()); + + List existing = allInterfaceNameMapper.selectByNames(query); + if (!existing.isEmpty()) { + record.setId(existing.get(0).getId()); + allInterfaceNameMapper.updateAllInterfaceName(record); + } + } + }); + } } if (!namesToUpdate.isEmpty()) { @@ -289,10 +322,10 @@ public class EpsServerRevenueConfigServiceImpl implements IEpsServerRevenueConfi log.info("更新接口名称数量:{}", namesToUpdate.size()); } } + // 辅助方法:检查记录是否有变化 private boolean isRecordChanged(AllInterfaceName oldRecord, AllInterfaceName newRecord) { - return !Objects.equals(oldRecord.getClientId(), newRecord.getClientId()) || - !Objects.equals(oldRecord.getDeviceSn(), newRecord.getDeviceSn()) || + return !Objects.equals(oldRecord.getDeviceSn(), newRecord.getDeviceSn()) || !Objects.equals(oldRecord.getNodeName(), newRecord.getNodeName()) || !Objects.equals(oldRecord.getBusinessCode(), newRecord.getBusinessCode()) || !Objects.equals(oldRecord.getBusinessName(), newRecord.getBusinessName()) || diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/InitialSwitchInfoDetailsServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/InitialSwitchInfoDetailsServiceImpl.java index aa9def6..43d09a1 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/InitialSwitchInfoDetailsServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/InitialSwitchInfoDetailsServiceImpl.java @@ -9,13 +9,14 @@ import com.ruoyi.system.service.IInitialSwitchInfoDetailsService; import com.ruoyi.system.util.CalculateUtil; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.dao.DuplicateKeyException; import org.springframework.stereotype.Service; import java.math.BigDecimal; import java.math.RoundingMode; -import java.time.format.DateTimeFormatter; -import java.util.*; -import java.util.function.Function; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; import java.util.stream.Collectors; /** @@ -28,7 +29,6 @@ import java.util.stream.Collectors; @Slf4j public class InitialSwitchInfoDetailsServiceImpl implements IInitialSwitchInfoDetailsService { - private static final DateTimeFormatter TIME_FORMAT = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); @Autowired private InitialSwitchInfoDetailsMapper initialSwitchInfoDetailsMapper; @Autowired @@ -134,31 +134,37 @@ public class InitialSwitchInfoDetailsServiceImpl implements IInitialSwitchInfoDe List managements = rmEpsTopologyManagementMapper.selectRmEpsTopologyManagementList(rmEpsTopologyManagement); // 赋值 if(!managements.isEmpty()){ - RmEpsTopologyManagement management = managements.get(0); - details.setSwitchSn(management.getSwitchSn()); - details.setSwitchName(management.getSwitchName()); - 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 businessList = epsServerRevenueConfigMapper.selectEpsServerRevenueConfigList(epsServerRevenueConfig); - if(!businessList.isEmpty()){ - EpsServerRevenueConfig revenueConfig = businessList.get(0); - details.setBusinessName(revenueConfig.getBusinessName()); - details.setBusinessCode(revenueConfig.getBusinessCode()); + for (RmEpsTopologyManagement management : managements) { + if("1".equals(management.getConnectedDeviceType())){ + details.setOutSpeed(null); + }else{ + details.setInSpeed(null); } - }else { - details.setBusinessCode(null); - details.setBusinessName(null); + details.setSwitchSn(management.getSwitchSn()); + details.setSwitchName(management.getSwitchName()); + 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 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); + batchList.add(details); } } - // id自增 - details.setId(null); - batchList.add(details); } } initialSwitchInfoDetails.setDataList(batchList); @@ -183,38 +189,23 @@ public class InitialSwitchInfoDetailsServiceImpl implements IInitialSwitchInfoDe * 批量处理接口名称 */ private void processSwitchInterfaceNames(List initialSwitchInfoDetails) { - // 收集所有需要检查的接口名称 - Set interfaceNames = initialSwitchInfoDetails.stream() - .map(InitialSwitchInfoDetails::getName) - .filter(StringUtils::isNotBlank) - .collect(Collectors.toSet()); - - if (interfaceNames.isEmpty()) { - return; - } - AllInterfaceName allInterfaceName = new AllInterfaceName(); - if(!initialSwitchInfoDetails.isEmpty()){ - allInterfaceName.setClientId(initialSwitchInfoDetails.get(0).getClientId()); - allInterfaceName.setInterfaceNames(interfaceNames); - } - // 批量查询已存在的接口名称 - List existingNames = allInterfaceNameMapper.selectByNames(allInterfaceName); - Map existingNameMap = existingNames.stream() - .collect(Collectors.toMap( - item -> item.getClientId() + "|" + item.getInterfaceName(), // 关键修改点 - Function.identity(), - (oldValue, newValue) -> oldValue // 重复时保留旧记录 - )); // 分类处理:新增列表 vs 更新列表 List namesToInsert = new ArrayList<>(); List namesToUpdate = new ArrayList<>(); initialSwitchInfoDetails.forEach(data -> { String name = data.getName(); - if (StringUtils.isBlank(name)) { + String ip = data.getSwitchIp(); + String clientId = data.getClientId(); + if (StringUtils.isBlank(name) || StringUtils.isBlank(ip) || StringUtils.isBlank(clientId)) { return; } - + AllInterfaceName allInterfaceName = new AllInterfaceName(); + allInterfaceName.setClientId(clientId); + allInterfaceName.setSwitchIp(ip); + allInterfaceName.setInterfaceName(name); + allInterfaceName.setResourceType("2"); + List existingNames = allInterfaceNameMapper.selectByNames(allInterfaceName); AllInterfaceName record = new AllInterfaceName(); record.setInterfaceName(name); record.setClientId(data.getClientId()); @@ -241,22 +232,57 @@ public class InitialSwitchInfoDetailsServiceImpl implements IInitialSwitchInfoDe record.setBusinessName(null); } // 判断是否需要更新 - String compositeKey = data.getClientId() + "|" + name; - if (existingNameMap.containsKey(compositeKey)) { - AllInterfaceName existingRecord = existingNameMap.get(compositeKey); - if (isRecordChanged(existingRecord, record)) { - record.setId(existingRecord.getId()); // 保留原ID - namesToUpdate.add(record); + if (!existingNames.isEmpty()) { + for (AllInterfaceName existingName : existingNames) { + if(isRecordChanged(existingName,record)){ + record.setId(existingName.getId()); // 保留原ID + // 检查是否已经存在于更新列表中 + boolean alreadyInUpdateList = namesToUpdate.stream() + .anyMatch(item -> item.getId() != null && item.getId().equals(existingName.getId())); + if (!alreadyInUpdateList) { + namesToUpdate.add(record); + } + } } } else { - namesToInsert.add(record); + // 检查namesToInsert中是否已有相同记录 + boolean alreadyInInsertList = namesToInsert.stream() + .anyMatch(item -> item.getInterfaceName().equals(name) + && item.getClientId().equals(clientId) + && item.getSwitchIp().equals(ip)); + + if (!alreadyInInsertList) { + namesToInsert.add(record); + } } }); // 批量操作数据库 if (!namesToInsert.isEmpty()) { - allInterfaceNameMapper.batchInsert(namesToInsert); - log.info("新增接口名称数量:{}", namesToInsert.size()); + try { + allInterfaceNameMapper.batchInsert(namesToInsert); + log.info("新增接口名称数量:{}", namesToInsert.size()); + } catch (DuplicateKeyException e) { + // 如果批量插入出现重复,转为逐条插入(带异常处理) + log.warn("批量插入出现重复,转为逐条处理"); + namesToInsert.forEach(record -> { + try { + allInterfaceNameMapper.insertAllInterfaceName(record); + } catch (DuplicateKeyException ex) { + // 重复记录转为更新 + AllInterfaceName query = new AllInterfaceName(); + query.setInterfaceName(record.getInterfaceName()); + query.setClientId(record.getClientId()); + query.setServerIp(record.getServerIp()); + + List existing = allInterfaceNameMapper.selectByNames(query); + if (!existing.isEmpty()) { + record.setId(existing.get(0).getId()); + allInterfaceNameMapper.updateAllInterfaceName(record); + } + } + }); + } } if (!namesToUpdate.isEmpty()) { @@ -267,8 +293,7 @@ public class InitialSwitchInfoDetailsServiceImpl implements IInitialSwitchInfoDe // 辅助方法:检查记录是否有变化 private boolean isRecordChanged(AllInterfaceName oldRecord, AllInterfaceName newRecord) { - return !Objects.equals(oldRecord.getClientId(), newRecord.getClientId()) || - !Objects.equals(oldRecord.getDeviceSn(), newRecord.getDeviceSn()) || + return !Objects.equals(oldRecord.getDeviceSn(), newRecord.getDeviceSn()) || !Objects.equals(oldRecord.getNodeName(), newRecord.getNodeName()) || !Objects.equals(oldRecord.getServerPort(), newRecord.getServerPort()) || !Objects.equals(oldRecord.getInterfaceDeviceType(), newRecord.getInterfaceDeviceType()) || diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/RmResourceRegistrationServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/RmResourceRegistrationServiceImpl.java index 78c6c8a..faeeddf 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/RmResourceRegistrationServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/RmResourceRegistrationServiceImpl.java @@ -2,9 +2,13 @@ package com.ruoyi.system.service.impl; import com.ruoyi.common.core.utils.DateUtils; import com.ruoyi.common.security.utils.SecurityUtils; +import com.ruoyi.system.domain.EpsNodeBandwidth; import com.ruoyi.system.domain.EpsServerRevenueConfig; +import com.ruoyi.system.domain.RmEpsTopologyManagement; import com.ruoyi.system.domain.RmResourceRegistration; +import com.ruoyi.system.mapper.EpsNodeBandwidthMapper; import com.ruoyi.system.mapper.EpsServerRevenueConfigMapper; +import com.ruoyi.system.mapper.RmEpsTopologyManagementMapper; import com.ruoyi.system.mapper.RmResourceRegistrationMapper; import com.ruoyi.system.service.IRmResourceRegistrationService; import org.springframework.beans.factory.annotation.Autowired; @@ -26,6 +30,10 @@ public class RmResourceRegistrationServiceImpl implements IRmResourceRegistratio private RmResourceRegistrationMapper rmResourceRegistrationMapper; @Autowired private EpsServerRevenueConfigMapper epsServerRevenueConfigMapper; + @Autowired + private RmEpsTopologyManagementMapper rmEpsTopologyManagementMapper; + @Autowired + private EpsNodeBandwidthMapper epsNodeBandwidthMapper; /** * 查询资源注册 @@ -84,12 +92,34 @@ public class RmResourceRegistrationServiceImpl implements IRmResourceRegistratio rmResourceRegistration.setUpdateTime(DateUtils.getNowDate()); rmResourceRegistration.setUpdaterId(SecurityUtils.getUserId()); rmResourceRegistration.setUpdaterName(SecurityUtils.getUsername()); + // 拿到需要修改的id + Long id = rmResourceRegistration.getId(); + // 根据id查询sn信息 + RmResourceRegistration resourceRegistration = rmResourceRegistrationMapper.selectRmResourceRegistrationById(id); + // sn + String hardwareSn = resourceRegistration.getHardwareSn(); + // 如果资源名称有修改,同步修改其他表的资源名称 + if (!resourceRegistration.getResourceName().equals(rmResourceRegistration.getResourceName())){ + // 拓扑管理配置 + RmEpsTopologyManagement rmEpsTopologyManagement = new RmEpsTopologyManagement(); + rmEpsTopologyManagement.setServerSn(hardwareSn); + rmEpsTopologyManagement.setServerName(rmResourceRegistration.getResourceName()); + rmEpsTopologyManagementMapper.updateRmEpsTopologyManagementByServerSn(rmEpsTopologyManagement); + // 服务器收益配置表 + EpsServerRevenueConfig epsServerRevenueConfig = new EpsServerRevenueConfig(); + epsServerRevenueConfig.setHardwareSn(hardwareSn); + epsServerRevenueConfig.setNodeName(rmResourceRegistration.getResourceName()); + epsServerRevenueConfigMapper.updateEpsServerRevenueConfigByServerSn(epsServerRevenueConfig); + // 95收益信息表 + EpsNodeBandwidth epsNodeBandwidth = new EpsNodeBandwidth(); + epsNodeBandwidth.setHardwareSn(hardwareSn); + epsNodeBandwidth.setNodeName(rmResourceRegistration.getResourceName()); + epsNodeBandwidthMapper.updateEpsNodeBandwidthByServerSn(epsNodeBandwidth); + } // 禁止修改sn序列号 rmResourceRegistration.setHardwareSn(null); // 已注册状态修改--仅可修改资源名称,描述 if ("1".equals(rmResourceRegistration.getRegistrationStatus())){ - // 拿到需要修改的id - Long id = rmResourceRegistration.getId(); // 拿到需要修改的资源名称 String resourceName = rmResourceRegistration.getResourceName(); // 拿到需要修改的描述 diff --git a/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/AllInterfaceNameMapper.xml b/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/AllInterfaceNameMapper.xml index 3b8b231..c2b4dec 100644 --- a/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/AllInterfaceNameMapper.xml +++ b/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/AllInterfaceNameMapper.xml @@ -148,12 +148,20 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" server_ip AS serverIp FROM all_interface_name - WHERE - client_id = #{clientId} and - interface_name IN - - #{name} - + + and client_id = #{clientId} + and interface_name = #{interfaceName} + and device_sn = #{deviceSn} + and node_name = #{nodeName} + and business_code = #{businessCode} + and resource_type = #{resourceType} + and switch_name = #{switchName} + and interface_device_type = #{interfaceDeviceType} + and server_port = #{serverPort} + and switch_sn = #{switchSn} + and switch_ip = #{switchIp} + and server_ip = #{serverIp} + diff --git a/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/EpsNodeBandwidthMapper.xml b/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/EpsNodeBandwidthMapper.xml index f004810..50ac953 100644 --- a/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/EpsNodeBandwidthMapper.xml +++ b/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/EpsNodeBandwidthMapper.xml @@ -32,10 +32,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + - select id, node_name, hardware_sn, bandwidth_type, bandwidth_result, bandwidth_95_daily, bandwidth_95_monthly, avg_monthly_bandwidth_95, package_bandwidth_daily, customer_id, customer_name, service_number, uplink_switch, create_time, update_time, creator_id, creator_name, switch_sn, interface_name, resource_type, interface_link_device_type, effective_bandwidth_95_daily, effective_bandwidth_95_monthly, effective_avg_monthly_bandwidth_95, business_name, business_id, remark1 from eps_node_bandwidth + select id, node_name, hardware_sn, bandwidth_type, bandwidth_result, bandwidth_95_daily, bandwidth_95_monthly, avg_monthly_bandwidth_95, package_bandwidth_daily, customer_id, customer_name, service_number, uplink_switch, create_time, update_time, creator_id, creator_name, switch_sn, interface_name, resource_type, interface_link_device_type, effective_bandwidth_95_daily, effective_bandwidth_95_monthly, effective_avg_monthly_bandwidth_95, business_name, business_id, remark1, create_datetime from eps_node_bandwidth