修改入库bug 资源管理模块bug

This commit is contained in:
gaoyutao
2025-09-02 19:54:54 +08:00
parent 05e57a2fe7
commit 4dd9324dba
24 changed files with 315 additions and 724 deletions
@@ -54,14 +54,6 @@ public class RmResourceRegistrationController extends BaseController
public void export(HttpServletResponse response, RmResourceRegistration rmResourceRegistration)
{
List<RmResourceRegistration> list = rmResourceRegistrationService.selectRmResourceRegistrationList(rmResourceRegistration);
for (RmResourceRegistration resourceRegistration : list) {
// 根据端口类型导出端口名称
if("1".equals(resourceRegistration.getResourcePort())){
resourceRegistration.setResourcePort("162(SNMP)");
}else{
resourceRegistration.setResourcePort(resourceRegistration.getOtherPortName());
}
}
ExcelUtil<RmResourceRegistration> util = new ExcelUtil<RmResourceRegistration>(RmResourceRegistration.class);
util.showColumn(rmResourceRegistration.getProperties());
util.exportExcel(response, list, "资源注册数据");
@@ -4,6 +4,8 @@ import com.ruoyi.common.core.annotation.Excel;
import com.ruoyi.common.core.web.domain.BaseEntity;
import lombok.Data;
import java.util.Set;
/**
* 所有接口名称对象 all_interface_name
*
@@ -62,4 +64,14 @@ public class AllInterfaceName extends BaseEntity
@Excel(name = "交换机硬件SN")
private String switchSn;
/** 接口名称集合 */
private Set<String> interfaceNames;
/** 交换机ip */
@Excel(name = "交换机ip")
private String switchIp;
/** 服务器ip */
@Excel(name = "服务器ip")
private String serverIp;
}
@@ -62,4 +62,6 @@ public class EpsServerRevenueConfig extends BaseEntity
private String endTime;
/** 业务是否有变化 */
private String changed;
/** 服务器ip */
private String serverIp;
}
@@ -93,4 +93,7 @@ public class InitialSwitchInfoDetails extends BaseEntity
private String bandwidthType;
/** 日或月 */
private String dayOrMonth;
/** 交换机ip */
private String switchIp;
}
@@ -3,8 +3,7 @@ package com.ruoyi.system.domain;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.common.core.annotation.Excel;
import com.ruoyi.common.core.web.domain.BaseEntity;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import lombok.Data;
import java.util.Date;
@@ -14,6 +13,7 @@ import java.util.Date;
* @author gyt
* @date 2025-08-12
*/
@Data
public class RmEpsTopologyManagement extends BaseEntity
{
private static final long serialVersionUID = 1L;
@@ -71,166 +71,6 @@ public class RmEpsTopologyManagement extends BaseEntity
/** 修改人名称 */
private String updaterName;
@Override
public Date getCreateTime() {
return createTime;
}
@Override
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
@Override
public Date getUpdateTime() {
return updateTime;
}
@Override
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
public void setId(Long id)
{
this.id = id;
}
public Long getId()
{
return id;
}
public void setSwitchName(String switchName)
{
this.switchName = switchName;
}
public String getSwitchName()
{
return switchName;
}
public void setSwitchSn(String switchSn)
{
this.switchSn = switchSn;
}
public String getSwitchSn()
{
return switchSn;
}
public void setInterfaceName(String interfaceName)
{
this.interfaceName = interfaceName;
}
public String getInterfaceName()
{
return interfaceName;
}
public void setConnectedDeviceType(String connectedDeviceType)
{
this.connectedDeviceType = connectedDeviceType;
}
public String getConnectedDeviceType()
{
return connectedDeviceType;
}
public void setServerName(String serverName)
{
this.serverName = serverName;
}
public String getServerName()
{
return serverName;
}
public void setServerSn(String serverSn)
{
this.serverSn = serverSn;
}
public String getServerSn()
{
return serverSn;
}
public void setServerPort(String serverPort)
{
this.serverPort = serverPort;
}
public String getServerPort()
{
return serverPort;
}
public void setCreatorId(Long creatorId)
{
this.creatorId = creatorId;
}
public Long getCreatorId()
{
return creatorId;
}
public void setCreatorName(String creatorName)
{
this.creatorName = creatorName;
}
public String getCreatorName()
{
return creatorName;
}
public void setUpdaterId(Long updaterId)
{
this.updaterId = updaterId;
}
public Long getUpdaterId()
{
return updaterId;
}
public void setUpdaterName(String updaterName)
{
this.updaterName = updaterName;
}
public String getUpdaterName()
{
return updaterName;
}
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("id", getId())
.append("switchName", getSwitchName())
.append("switchSn", getSwitchSn())
.append("interfaceName", getInterfaceName())
.append("connectedDeviceType", getConnectedDeviceType())
.append("serverName", getServerName())
.append("serverSn", getServerSn())
.append("serverPort", getServerPort())
.append("createTime", getCreateTime())
.append("updateTime", getUpdateTime())
.append("creatorId", getCreatorId())
.append("creatorName", getCreatorName())
.append("updaterId", getUpdaterId())
.append("updaterName", getUpdaterName())
.toString();
}
/** 交换机ip */
private String switchIpAddress;
}
@@ -1,9 +1,8 @@
package com.ruoyi.system.domain;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.core.annotation.Excel;
import com.ruoyi.common.core.web.domain.BaseEntity;
import lombok.Data;
/**
* 资源注册对象 rm_resource_registration
@@ -11,6 +10,7 @@ import com.ruoyi.common.core.web.domain.BaseEntity;
* @author gyt
* @date 2025-08-12
*/
@Data
public class RmResourceRegistration extends BaseEntity
{
private static final long serialVersionUID = 1L;
@@ -42,19 +42,32 @@ public class RmResourceRegistration extends BaseEntity
/**其他端口名称 */
private String otherPortName;
/** agent版本 */
@Excel(name = "agent版本")
private String agentVersion;
/** 协议 1.TCP,2.UDP */
@Excel(name = "协议",readConverterExp = "1=TCP,2=UDP")
private String protocol;
/** SNMP探测 0=否,1=是 */
@Excel(name = "",readConverterExp = "0=否,1=是")
private String snmpDetect;
/** 版本(1.SNMPv2,2.SNMPv3) */
@Excel(name = "版本",readConverterExp = "1=SNMPv2,2=SNMPv3")
@Excel(name = "SNMP版本",readConverterExp = "1=华为SNMPv2c,2=华为SNMPv3")
private String resourceVersion;
/** 读写权限(1.RW,2.ReadOnly) */
@Excel(name = "读写权限",readConverterExp = "1=RW,2=ReadOnly")
@Excel(name = "读写权限",readConverterExp = "1=只读,2=可读可写")
private String rwPermission;
/** 团体名称 */
@Excel(name = "团体名称")
private String teamName;
/** SNMP采集地址 */
@Excel(name = "SNMP采集地址")
private String snmpCollectAddr;
/** 安全级别(1.authPriv、2.authNoPriv3.noAuthNoPriv) */
@Excel(name = "安全级别",readConverterExp = "1=authPriv,2=authNoPriv,3=noAuthNoPriv")
@@ -106,271 +119,4 @@ public class RmResourceRegistration extends BaseEntity
/** 修改人名称 */
private String updaterName;
public String getOtherPortName() {
return otherPortName;
}
public void setOtherPortName(String otherPortName) {
this.otherPortName = otherPortName;
}
public void setId(Long id)
{
this.id = id;
}
public Long getId()
{
return id;
}
public void setHardwareSn(String hardwareSn)
{
this.hardwareSn = hardwareSn;
}
public String getHardwareSn()
{
return hardwareSn;
}
public void setResourceType(String resourceType)
{
this.resourceType = resourceType;
}
public String getResourceType()
{
return resourceType;
}
public void setResourceName(String resourceName)
{
this.resourceName = resourceName;
}
public String getResourceName()
{
return resourceName;
}
public void setIpAddress(String ipAddress)
{
this.ipAddress = ipAddress;
}
public String getIpAddress()
{
return ipAddress;
}
public void setResourcePort(String resourcePort)
{
this.resourcePort = resourcePort;
}
public String getResourcePort()
{
return resourcePort;
}
public void setProtocol(String protocol)
{
this.protocol = protocol;
}
public String getProtocol()
{
return protocol;
}
public void setResourceVersion(String resourceVersion)
{
this.resourceVersion = resourceVersion;
}
public String getResourceVersion()
{
return resourceVersion;
}
public void setRwPermission(String rwPermission)
{
this.rwPermission = rwPermission;
}
public String getRwPermission()
{
return rwPermission;
}
public void setSecurityLevel(String securityLevel)
{
this.securityLevel = securityLevel;
}
public String getSecurityLevel()
{
return securityLevel;
}
public void setEncryption(String encryption)
{
this.encryption = encryption;
}
public String getEncryption()
{
return encryption;
}
public void setResourcePwd(String resourcePwd)
{
this.resourcePwd = resourcePwd;
}
public String getResourcePwd()
{
return resourcePwd;
}
public void setRegistrationStatus(String registrationStatus)
{
this.registrationStatus = registrationStatus;
}
public String getRegistrationStatus()
{
return registrationStatus;
}
public void setOnlineStatus(String onlineStatus)
{
this.onlineStatus = onlineStatus;
}
public String getOnlineStatus()
{
return onlineStatus;
}
public void setDescription(String description)
{
this.description = description;
}
public String getDescription()
{
return description;
}
public void setCustomerId(Long customerId)
{
this.customerId = customerId;
}
public Long getCustomerId()
{
return customerId;
}
public void setCustomerName(String customerName)
{
this.customerName = customerName;
}
public String getCustomerName()
{
return customerName;
}
public void setServiceNumber(String serviceNumber)
{
this.serviceNumber = serviceNumber;
}
public String getServiceNumber()
{
return serviceNumber;
}
public void setCreatorId(Long creatorId)
{
this.creatorId = creatorId;
}
public Long getCreatorId()
{
return creatorId;
}
public void setCreatorName(String creatorName)
{
this.creatorName = creatorName;
}
public String getCreatorName()
{
return creatorName;
}
public void setUpdaterId(Long updaterId)
{
this.updaterId = updaterId;
}
public Long getUpdaterId()
{
return updaterId;
}
public void setUpdaterName(String updaterName)
{
this.updaterName = updaterName;
}
public String getUpdaterName()
{
return updaterName;
}
public String getResourceUserName() {
return resourceUserName;
}
public void setResourceUserName(String resourceUserName) {
this.resourceUserName = resourceUserName;
}
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("id", getId())
.append("hardwareSn", getHardwareSn())
.append("resourceType", getResourceType())
.append("resourceName", getResourceName())
.append("ipAddress", getIpAddress())
.append("resourcePort", getResourcePort())
.append("otherPortName", getOtherPortName())
.append("protocol", getProtocol())
.append("resourceVersion", getResourceVersion())
.append("rwPermission", getRwPermission())
.append("securityLevel", getSecurityLevel())
.append("encryption", getEncryption())
.append("resourcePwd", getResourcePwd())
.append("resourceUserName", getResourceName())
.append("registrationStatus", getRegistrationStatus())
.append("onlineStatus", getOnlineStatus())
.append("description", getDescription())
.append("customerId", getCustomerId())
.append("customerName", getCustomerName())
.append("serviceNumber", getServiceNumber())
.append("createTime", getCreateTime())
.append("updateTime", getUpdateTime())
.append("creatorId", getCreatorId())
.append("creatorName", getCreatorName())
.append("updaterId", getUpdaterId())
.append("updaterName", getUpdaterName())
.toString();
}
}
@@ -4,7 +4,6 @@ import com.ruoyi.system.domain.AllInterfaceName;
import org.springframework.data.repository.query.Param;
import java.util.List;
import java.util.Set;
/**
* 所有接口名称Mapper接口
@@ -64,10 +63,10 @@ public interface AllInterfaceNameMapper
/**
* 根据接口名称查询表中是否存在信息
* @param names
* @param interfaceName
* @return
*/
List<AllInterfaceName> selectByNames(Set<String> names);
List<AllInterfaceName> selectByNames(AllInterfaceName interfaceName);
/**
* 批量插入接口名称
@@ -179,12 +179,12 @@ public class EpsServerRevenueConfigServiceImpl implements IEpsServerRevenueConfi
Map nodeMsg = epsServerRevenueConfigMapper.getNodeMsgByIp(ip);
// 赋值
if(nodeMsg != null){
initialTrafficData.setServiceSn(nodeMsg.get("hardwareSn") + "");
initialTrafficData.setNodeName(nodeMsg.get("resourceName") + "");
initialTrafficData.setRevenueMethod(nodeMsg.get("revenueMethod") + "");
initialTrafficData.setBusinessId(nodeMsg.get("businessCode") + "");
initialTrafficData.setBusinessName(nodeMsg.get("businessName") + "");
if("2".equals(String.valueOf(nodeMsg.get("revenueMethod")))
initialTrafficData.setServiceSn(getNullableString(nodeMsg, "hardwareSn"));
initialTrafficData.setNodeName(getNullableString(nodeMsg, "resourceName"));
initialTrafficData.setRevenueMethod(getNullableString(nodeMsg, "revenueMethod"));
initialTrafficData.setBusinessId(getNullableString(nodeMsg, "businessCode"));
initialTrafficData.setBusinessName(getNullableString(nodeMsg, "businessName"));
if("2".equals(nodeMsg.get("revenueMethod") + "")
&& nodeMsg.containsKey("packageBandwidth")){
Object bandwidth = nodeMsg.get("packageBandwidth");
if (bandwidth instanceof BigDecimal) {
@@ -210,6 +210,13 @@ public class EpsServerRevenueConfigServiceImpl implements IEpsServerRevenueConfi
return R.fail("数据保存失败:" + e.getMessage());
}
}
private static String getNullableString(Map<String, Object> map, String key) {
Object value = map.get(key);
return value != null ? value.toString() : null;
}
private String getCompositeKey(String clientId, String interfaceName) {
return clientId + "|" + interfaceName;
}
/**
* 批量处理接口名称
*/
@@ -225,11 +232,19 @@ public class EpsServerRevenueConfigServiceImpl implements IEpsServerRevenueConfi
}
// 批量查询已存在的接口名称
List<AllInterfaceName> existingNames = allInterfaceNameMapper.selectByNames(interfaceNames);
AllInterfaceName allInterfaceName = new AllInterfaceName();
if(!trafficDataList.isEmpty()){
allInterfaceName.setClientId(trafficDataList.get(0).getClientId());
allInterfaceName.setInterfaceNames(interfaceNames);
}
List<AllInterfaceName> existingNames = allInterfaceNameMapper.selectByNames(allInterfaceName);
// 转为 Map<接口名称, 数据库记录> 便于快速查找
Map<String, AllInterfaceName> existingNameMap = existingNames.stream()
.collect(Collectors.toMap(AllInterfaceName::getInterfaceName, Function.identity()));
.collect(Collectors.toMap(
item -> item.getClientId() + "|" + item.getInterfaceName(), // 关键修改点
Function.identity(),
(oldValue, newValue) -> oldValue // 重复时保留旧记录
));
// 分类处理:新增列表 vs 更新列表
List<AllInterfaceName> namesToInsert = new ArrayList<>();
List<AllInterfaceName> namesToUpdate = new ArrayList<>();
@@ -249,10 +264,11 @@ public class EpsServerRevenueConfigServiceImpl implements IEpsServerRevenueConfi
newRecord.setNodeName(data.getNodeName());
newRecord.setBusinessCode(data.getBusinessId());
newRecord.setBusinessName(data.getBusinessName());
newRecord.setServerIp(data.getIpV4());
// 判断是否需要更新
if (existingNameMap.containsKey(name)) {
AllInterfaceName oldRecord = existingNameMap.get(name);
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);
@@ -279,7 +295,8 @@ public class EpsServerRevenueConfigServiceImpl implements IEpsServerRevenueConfi
!Objects.equals(oldRecord.getDeviceSn(), newRecord.getDeviceSn()) ||
!Objects.equals(oldRecord.getNodeName(), newRecord.getNodeName()) ||
!Objects.equals(oldRecord.getBusinessCode(), newRecord.getBusinessCode()) ||
!Objects.equals(oldRecord.getBusinessName(), newRecord.getBusinessName());
!Objects.equals(oldRecord.getBusinessName(), newRecord.getBusinessName()) ||
!Objects.equals(oldRecord.getServerIp(), newRecord.getServerIp());
}
/**
* 批量删除服务器收益方式配置
@@ -127,8 +127,10 @@ public class InitialSwitchInfoDetailsServiceImpl implements IInitialSwitchInfoDe
for (InitialSwitchInfoDetails details : dataList) {
// 根据接口名称查询交换机信息
String interfaceName = details.getName();
String switchIp = details.getSwitchIp();
RmEpsTopologyManagement rmEpsTopologyManagement = new RmEpsTopologyManagement();
rmEpsTopologyManagement.setInterfaceName(interfaceName);
rmEpsTopologyManagement.setSwitchIpAddress(switchIp);
List<RmEpsTopologyManagement> managements = rmEpsTopologyManagementMapper.selectRmEpsTopologyManagementList(rmEpsTopologyManagement);
// 赋值
if(!managements.isEmpty()){
@@ -190,12 +192,19 @@ public class InitialSwitchInfoDetailsServiceImpl implements IInitialSwitchInfoDe
if (interfaceNames.isEmpty()) {
return;
}
AllInterfaceName allInterfaceName = new AllInterfaceName();
if(!initialSwitchInfoDetails.isEmpty()){
allInterfaceName.setClientId(initialSwitchInfoDetails.get(0).getClientId());
allInterfaceName.setInterfaceNames(interfaceNames);
}
// 批量查询已存在的接口名称
List<AllInterfaceName> existingNames = allInterfaceNameMapper.selectByNames(interfaceNames);
List<AllInterfaceName> existingNames = allInterfaceNameMapper.selectByNames(allInterfaceName);
Map<String, AllInterfaceName> existingNameMap = existingNames.stream()
.collect(Collectors.toMap(AllInterfaceName::getInterfaceName, Function.identity()));
.collect(Collectors.toMap(
item -> item.getClientId() + "|" + item.getInterfaceName(), // 关键修改点
Function.identity(),
(oldValue, newValue) -> oldValue // 重复时保留旧记录
));
// 分类处理:新增列表 vs 更新列表
List<AllInterfaceName> namesToInsert = new ArrayList<>();
List<AllInterfaceName> namesToUpdate = new ArrayList<>();
@@ -216,6 +225,7 @@ public class InitialSwitchInfoDetailsServiceImpl implements IInitialSwitchInfoDe
record.setInterfaceDeviceType(data.getInterfaceDeviceType());
record.setSwitchName(data.getSwitchName());
record.setSwitchSn(data.getSwitchSn());
record.setSwitchIp(data.getSwitchIp());
// 根据服务器sn查询业务
if(data.getServerSn() != null){
EpsServerRevenueConfig epsServerRevenueConfig = new EpsServerRevenueConfig();
@@ -231,8 +241,9 @@ public class InitialSwitchInfoDetailsServiceImpl implements IInitialSwitchInfoDe
record.setBusinessName(null);
}
// 判断是否需要更新
if (existingNameMap.containsKey(name)) {
AllInterfaceName existingRecord = existingNameMap.get(name);
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);
@@ -264,7 +275,8 @@ public class InitialSwitchInfoDetailsServiceImpl implements IInitialSwitchInfoDe
!Objects.equals(oldRecord.getSwitchName(), newRecord.getSwitchName()) ||
!Objects.equals(oldRecord.getBusinessCode(), newRecord.getBusinessCode()) ||
!Objects.equals(oldRecord.getBusinessName(), newRecord.getBusinessName()) ||
!Objects.equals(oldRecord.getSwitchSn(), newRecord.getSwitchSn());
!Objects.equals(oldRecord.getSwitchSn(), newRecord.getSwitchSn()) ||
!Objects.equals(oldRecord.getSwitchIp(), newRecord.getSwitchIp());
}
public void calculateSwitch95BandwidthDaily(InitialSwitchInfoDetails queryParam, String dailyStartTime, String dailyEndTime) {
@@ -126,6 +126,7 @@ public class RmResourceRegistrationServiceImpl implements IRmResourceRegistratio
epsServerRevenueConfig.setNodeName(rmResourceRegistration.getResourceName());
epsServerRevenueConfig.setCreateTime(DateUtils.getNowDate());
epsServerRevenueConfig.setRegistrationStatus(rmResourceRegistration.getRegistrationStatus());
epsServerRevenueConfig.setServerIp(rmResourceRegistration.getIpAddress());
// 新增前判断是否存在
EpsServerRevenueConfig exits = epsServerRevenueConfigMapper.countBySn(epsServerRevenueConfig.getHardwareSn());
if(exits != null){