diff --git a/ruoyi-auth/src/main/resources/bootstrap.yml b/ruoyi-auth/src/main/resources/bootstrap.yml index 43c2e63..edcb3cf 100644 --- a/ruoyi-auth/src/main/resources/bootstrap.yml +++ b/ruoyi-auth/src/main/resources/bootstrap.yml @@ -13,11 +13,17 @@ spring: cloud: nacos: discovery: - # 服务注册地址 server-addr: 127.0.0.1:8848 + # 服务注册地址 +# server-addr: 172.16.15.103:8848 +# username: ${spring.cloud.nacos.config.username} +# password: ${spring.cloud.nacos.config.password} config: # 配置中心地址 server-addr: 127.0.0.1:8848 +# server-addr: 172.16.15.103:8848 +# username: nacos +# password: nacos # 配置文件格式 file-extension: yml # 共享配置 diff --git a/ruoyi-gateway/src/main/java/com/ruoyi/gateway/config/CorsConfig.java b/ruoyi-gateway/src/main/java/com/ruoyi/gateway/config/CorsConfig.java new file mode 100644 index 0000000..d7da653 --- /dev/null +++ b/ruoyi-gateway/src/main/java/com/ruoyi/gateway/config/CorsConfig.java @@ -0,0 +1,54 @@ +package com.ruoyi.gateway.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.server.reactive.ServerHttpRequest; +import org.springframework.http.server.reactive.ServerHttpResponse; +import org.springframework.web.cors.reactive.CorsUtils; +import org.springframework.web.server.ServerWebExchange; +import org.springframework.web.server.WebFilter; +import org.springframework.web.server.WebFilterChain; +import reactor.core.publisher.Mono; + +/** + * 跨域配置 + * + * @author ruoyi + */ +@Configuration +public class CorsConfig +{ + private static final String ALLOWED_HEADERS = "*"; + private static final String ALLOWED_METHODS = "GET,POST,PUT,DELETE,OPTIONS,HEAD"; + private static final String ALLOWED_ORIGIN = "*"; + private static final String ALLOWED_EXPOSE = "*"; + private static final String MAX_AGE = "18000L"; + + @Bean + public WebFilter corsFilter() + { + return (ServerWebExchange ctx, WebFilterChain chain) -> { + ServerHttpRequest request = ctx.getRequest(); + if (CorsUtils.isCorsRequest(request)) + { + ServerHttpResponse response = ctx.getResponse(); + HttpHeaders headers = response.getHeaders(); + headers.add("Access-Control-Allow-Headers", ALLOWED_HEADERS); + headers.add("Access-Control-Allow-Methods", ALLOWED_METHODS); + headers.add("Access-Control-Allow-Origin", ALLOWED_ORIGIN); + headers.add("Access-Control-Expose-Headers", ALLOWED_EXPOSE); + headers.add("Access-Control-Max-Age", MAX_AGE); + headers.add("Access-Control-Allow-Credentials", "true"); + if (request.getMethod() == HttpMethod.OPTIONS) + { + response.setStatusCode(HttpStatus.OK); + return Mono.empty(); + } + } + return chain.filter(ctx); + }; + } +} \ No newline at end of file diff --git a/ruoyi-gateway/src/main/resources/bootstrap.yml b/ruoyi-gateway/src/main/resources/bootstrap.yml index bc2cc57..1e8693b 100644 --- a/ruoyi-gateway/src/main/resources/bootstrap.yml +++ b/ruoyi-gateway/src/main/resources/bootstrap.yml @@ -13,11 +13,17 @@ spring: cloud: nacos: discovery: - # 服务注册地址 server-addr: 127.0.0.1:8848 + # 服务注册地址 +# server-addr: 172.16.15.103:8848 +# username: ${spring.cloud.nacos.config.username} +# password: ${spring.cloud.nacos.config.password} config: # 配置中心地址 server-addr: 127.0.0.1:8848 +# server-addr: 172.16.15.103:8848 +# username: nacos +# password: nacos # 配置文件格式 file-extension: yml # 共享配置 diff --git a/ruoyi-modules/ruoyi-gen/src/main/resources/bootstrap.yml b/ruoyi-modules/ruoyi-gen/src/main/resources/bootstrap.yml index 64b9d91..15c683d 100644 --- a/ruoyi-modules/ruoyi-gen/src/main/resources/bootstrap.yml +++ b/ruoyi-modules/ruoyi-gen/src/main/resources/bootstrap.yml @@ -13,11 +13,17 @@ spring: cloud: nacos: discovery: + server-addr: 127.0.0.1:8848 # 服务注册地址 - server-addr: 127.0.0.1:8848 +# server-addr: 172.16.15.103:8848 +# username: ${spring.cloud.nacos.config.username} +# password: ${spring.cloud.nacos.config.password} config: - # 配置中心地址 server-addr: 127.0.0.1:8848 + # 配置中心地址 +# server-addr: 172.16.15.103:8848 +# username: nacos +# password: nacos # 配置文件格式 file-extension: yml # 共享配置 diff --git a/ruoyi-modules/ruoyi-job/src/main/resources/bootstrap.yml b/ruoyi-modules/ruoyi-job/src/main/resources/bootstrap.yml index 817a429..d9ca211 100644 --- a/ruoyi-modules/ruoyi-job/src/main/resources/bootstrap.yml +++ b/ruoyi-modules/ruoyi-job/src/main/resources/bootstrap.yml @@ -14,10 +14,14 @@ spring: nacos: discovery: # 服务注册地址 - server-addr: 127.0.0.1:8848 + server-addr: 172.16.15.103:8848 + username: ${spring.cloud.nacos.config.username} + password: ${spring.cloud.nacos.config.password} config: # 配置中心地址 - server-addr: 127.0.0.1:8848 + server-addr: 172.16.15.103:8848 + username: nacos + password: nacos # 配置文件格式 file-extension: yml # 共享配置 diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/config/TableScheduleConfig.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/config/TableScheduleConfig.java index bcbdeaa..3eecbb7 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/config/TableScheduleConfig.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/config/TableScheduleConfig.java @@ -30,6 +30,8 @@ public class TableScheduleConfig { public void calculate95BandwidthDaily() { EpsInitialTrafficData queryParam = new EpsInitialTrafficData(); epsInitialTrafficDataService.calculate95BandwidthDaily(queryParam); + // 有效-95带宽值/日 + epsInitialTrafficDataService.calculateBusiness95BandwidthDaily(queryParam); InitialSwitchInfoDetails initialSwitchInfoDetails = new InitialSwitchInfoDetails(); epsInitialTrafficDataService.calculateSwitch95BandwidthDaily(initialSwitchInfoDetails); } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/EpsMethodChangeRecord.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/EpsMethodChangeRecord.java index 2411fde..b9d8dd3 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/EpsMethodChangeRecord.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/EpsMethodChangeRecord.java @@ -1,9 +1,10 @@ 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; + +import java.math.BigDecimal; /** * 收益方式修改记录对象 eps_method_change_record @@ -11,6 +12,7 @@ import com.ruoyi.common.core.web.domain.BaseEntity; * @author gyt * @date 2025-08-15 */ +@Data public class EpsMethodChangeRecord extends BaseEntity { private static final long serialVersionUID = 1L; @@ -33,68 +35,23 @@ public class EpsMethodChangeRecord extends BaseEntity /** 创建人 */ @Excel(name = "修改人") private String creatBy; + /** 收益方式(1.流量,2包端) */ + private String revenueMethod; - public void setId(Long id) - { - this.id = id; - } + /** 流量网口 */ + private String trafficPort; - public Long getId() - { - return id; - } + /** 包端带宽值 */ + private BigDecimal packageBandwidth; - public void setNodeName(String nodeName) - { - this.nodeName = nodeName; - } + /** 业务名称 */ + private String businessName; - public String getNodeName() - { - return nodeName; - } + /** 业务代码(12位) */ + private String businessCode; + /** 开始时间 */ + private String startTime; + /** 结束时间 */ + private String endTime; - public void setChangeContent(String changeContent) - { - this.changeContent = changeContent; - } - - public String getChangeContent() - { - return changeContent; - } - - public void setHardwareSn(String hardwareSn) - { - this.hardwareSn = hardwareSn; - } - - public String getHardwareSn() - { - return hardwareSn; - } - - public void setCreatBy(String creatBy) - { - this.creatBy = creatBy; - } - - public String getCreatBy() - { - return creatBy; - } - - @Override - public String toString() { - return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) - .append("id", getId()) - .append("nodeName", getNodeName()) - .append("changeContent", getChangeContent()) - .append("hardwareSn", getHardwareSn()) - .append("createTime", getCreateTime()) - .append("creatBy", getCreatBy()) - .append("updateTime", getUpdateTime()) - .append("updateBy", getUpdateBy()) - .toString(); - } } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/EpsServerRevenueConfig.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/EpsServerRevenueConfig.java index 84aa3fa..c161e81 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/EpsServerRevenueConfig.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/EpsServerRevenueConfig.java @@ -60,4 +60,6 @@ public class EpsServerRevenueConfig extends BaseEntity private String startTime; /** 结束时间 */ private String endTime; + /** 业务是否有变化 */ + private String changed; } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/AllInterfaceNameMapper.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/AllInterfaceNameMapper.java index 77299e7..bab602c 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/AllInterfaceNameMapper.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/AllInterfaceNameMapper.java @@ -87,4 +87,10 @@ public interface AllInterfaceNameMapper * @return */ List getAllSwitchSn(AllInterfaceName interfaceName); + + /** + * 批量编辑 + * @param records + */ + void batchUpdate(List records); } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/EpsInitialTrafficDataService.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/EpsInitialTrafficDataService.java index 6f9a6db..32b2fbc 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/EpsInitialTrafficDataService.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/EpsInitialTrafficDataService.java @@ -40,6 +40,12 @@ public interface EpsInitialTrafficDataService { * @return 初始流量数据列表 */ List getAllTraficMsg(EpsInitialTrafficData queryParam); + /** + * 计算95带宽值-有效/日 + * @param queryParam 查询参数实体 + * @return 流量数据列表 + */ + void calculateBusiness95BandwidthDaily(EpsInitialTrafficData queryParam); /** * 计算95带宽值 * @param queryParam 查询参数实体 diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/EpsInitialTrafficDataServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/EpsInitialTrafficDataServiceImpl.java index 36dc13b..a5625c9 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/EpsInitialTrafficDataServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/EpsInitialTrafficDataServiceImpl.java @@ -1,14 +1,8 @@ package com.ruoyi.system.service.impl; import com.ruoyi.common.core.utils.DateUtils; -import com.ruoyi.system.domain.AllInterfaceName; -import com.ruoyi.system.domain.EpsInitialTrafficData; -import com.ruoyi.system.domain.EpsNodeBandwidth; -import com.ruoyi.system.domain.InitialSwitchInfoDetails; -import com.ruoyi.system.mapper.AllInterfaceNameMapper; -import com.ruoyi.system.mapper.EpsInitialTrafficDataMapper; -import com.ruoyi.system.mapper.EpsNodeBandwidthMapper; -import com.ruoyi.system.mapper.InitialSwitchInfoDetailsMapper; +import com.ruoyi.system.domain.*; +import com.ruoyi.system.mapper.*; import com.ruoyi.system.service.EpsInitialTrafficDataService; import com.ruoyi.system.util.TableRouterUtil; import lombok.extern.slf4j.Slf4j; @@ -22,6 +16,8 @@ import java.math.RoundingMode; import java.text.SimpleDateFormat; import java.time.LocalDate; import java.time.LocalDateTime; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; import java.util.*; import java.util.function.Consumer; import java.util.regex.Matcher; @@ -34,6 +30,8 @@ public class EpsInitialTrafficDataServiceImpl implements EpsInitialTrafficDataSe private static final Pattern SPEED_PATTERN = Pattern.compile("(\\d+\\.?\\d*)\\s*(\\S*)"); + + private static final DateTimeFormatter TIME_FORMAT = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); @Autowired private EpsInitialTrafficDataMapper epsInitialTrafficDataMapper; @Autowired @@ -42,6 +40,10 @@ public class EpsInitialTrafficDataServiceImpl implements EpsInitialTrafficDataSe private AllInterfaceNameMapper allInterfaceNameMapper; @Autowired private InitialSwitchInfoDetailsMapper initialSwitchInfoDetailsMapper; + @Autowired + private EpsServerRevenueConfigMapper epsServerRevenueConfigMapper; + @Autowired + private EpsMethodChangeRecordMapper epsMethodChangeRecordMapper; @Override public void createNextMonthTables() { LocalDate nextMonth = LocalDate.now().plusMonths(1); @@ -197,60 +199,148 @@ public class EpsInitialTrafficDataServiceImpl implements EpsInitialTrafficDataSe .collect(Collectors.toList()); } + /** + * 有业务变动的 计算有效95带宽值/日 + * @param queryParam + */ @Override - public void calculate95BandwidthDaily(EpsInitialTrafficData queryParam) { - Date now = DateUtils.getNowDate(); - Calendar calendar = Calendar.getInstance(); - calendar.add(Calendar.HOUR_OF_DAY, -24); - Date startDate = calendar.getTime(); - // 格式化时间 - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - String startTime = sdf.format(startDate); - String endTime = sdf.format(now); + public void calculateBusiness95BandwidthDaily(EpsInitialTrafficData queryParam) { + // 1. 获取所有设备SN列表 + List snList = allInterfaceNameMapper.getAllDeviceSn(new AllInterfaceName()); + + // 2. 获取昨天的日期范围(北京时间) + LocalDate yesterday = LocalDate.now(ZoneId.of("Asia/Shanghai")).minusDays(1); + String dailyStartTime = yesterday.atStartOfDay().format(TIME_FORMAT); // 00:00:00 + String dailyEndTime = yesterday.atTime(23, 59, 59).format(TIME_FORMAT); // 23:59:59 + + // 3. 遍历每个设备 + for (AllInterfaceName interfaceName : snList) { + queryParam.setServiceSn(interfaceName.getDeviceSn()); + + // 4. 检查设备是否有业务变更 + EpsServerRevenueConfig revenueConfig = new EpsServerRevenueConfig(); + revenueConfig.setHardwareSn(interfaceName.getDeviceSn()); + List changedList = epsServerRevenueConfigMapper.selectEpsServerRevenueConfigList(revenueConfig); + + if (!changedList.isEmpty() && + "1".equals(changedList.get(0).getChanged()) && + "1".equals(changedList.get(0).getRevenueMethod())) { + + // 5. 获取业务变更记录(按时间降序) + EpsMethodChangeRecord changeQuery = new EpsMethodChangeRecord(); + changeQuery.setHardwareSn(interfaceName.getDeviceSn()); + changeQuery.setStartTime(dailyStartTime); + changeQuery.setEndTime(dailyEndTime); + List records = epsMethodChangeRecordMapper + .selectEpsMethodChangeRecordList(changeQuery); + + if (!records.isEmpty()) { + // 确保按时间降序排列 + records.sort((r1, r2) -> r2.getCreateTime().compareTo(r1.getCreateTime())); + + // 6. 计算各时间段95值 + calculateTimeSegments95(queryParam, records, dailyStartTime, dailyEndTime); + } + } + } + } + + /** + * 计算设备各时间段的95带宽值 + */ + private void calculateTimeSegments95(EpsInitialTrafficData queryParam, + List records, + String dailyStartTime, + String dailyEndTime) { + // 1. 处理变更时间段(从最新到最早) + String endTime = records.get(0).getCreateTime() + ""; + for (int i = 1; i < records.size(); i++) { + String startTime = records.get(i).getCreateTime() + ""; + calculateSegment95(queryParam, startTime, endTime); + endTime = startTime; // 移动时间窗口 + } + + // 2. 处理最早变更前的时间段(昨天00:00:00 ~ 最早变更时间) + String earliestChangeTime = records.get(records.size()-1).getCreateTime() + ""; + calculateSegment95(queryParam, dailyStartTime, earliestChangeTime); + + // 3. 处理最后变更后的时间段(最新变更时间 ~ 昨天23:59:59) + calculateSegment95(queryParam, endTime, dailyEndTime); + } + + /** + * 计算单个时间段的95带宽值 + */ + private void calculateSegment95(EpsInitialTrafficData queryParam, String startTime, String endTime) { queryParam.setStartTime(startTime); queryParam.setEndTime(endTime); + List dataList = query(queryParam); + if (!dataList.isEmpty()) { + calculate95BandwidthDaily(dataList); + } + } + @Override + public void calculate95BandwidthDaily(EpsInitialTrafficData queryParam) { + // 1. 获取昨天的日期(北京时间) + LocalDate yesterday = LocalDate.now(ZoneId.of("Asia/Shanghai")).minusDays(1); + // 2. 定义时间范围字符串 + String startTimeStr = yesterday.atStartOfDay().format(TIME_FORMAT); // 00:00:00 + String endTimeStr = yesterday.atTime(23, 59, 59).format(TIME_FORMAT); // 23:59:59 + queryParam.setStartTime(startTimeStr); + queryParam.setEndTime(endTimeStr); queryParam.setRevenueMethod("1"); // 查询所有的服务器sn AllInterfaceName allInterfaceName = new AllInterfaceName(); List snList = allInterfaceNameMapper.getAllDeviceSn(allInterfaceName); for (AllInterfaceName interfaceName : snList) { queryParam.setServiceSn(interfaceName.getDeviceSn()); - // 查询原始数据 - List dataList = query(queryParam); - if(!dataList.isEmpty()){ - // 1. 提取 outSpeed 并转换为 Mbps - List speedsInMbps = dataList.stream() - .map(data -> parseSpeedToMbps(data.getOutSpeed())) - .sorted() - .collect(Collectors.toList()); + // 4. 检查设备是否有业务变更 + EpsServerRevenueConfig revenueConfig = new EpsServerRevenueConfig(); + revenueConfig.setHardwareSn(interfaceName.getDeviceSn()); + List changedList = epsServerRevenueConfigMapper.selectEpsServerRevenueConfigList(revenueConfig); - // 2. 计算 95% 位置(向上取整) - int total = speedsInMbps.size(); - int position = (int) Math.ceil(0.95 * total) - 1; // 转换为 0-based 索引 - if (position < 0){ - position = 0; - } - if (position >= total){ - position = total - 1; - } + if (!changedList.isEmpty() && + "1".equals(changedList.get(0).getChanged()) && + "1".equals(changedList.get(0).getRevenueMethod())) { - // 3. 获取 95 值并四舍五入到两位小数 - BigDecimal percentile95 = speedsInMbps.get(position); - BigDecimal dailyResult = percentile95.setScale(2, RoundingMode.HALF_UP); - // 服务器信息 - EpsInitialTrafficData epsInitialTrafficData = dataList.get(0); - // 落入带宽计算结果表 - EpsNodeBandwidth bandwidth = new EpsNodeBandwidth(); - bandwidth.setHardwareSn(epsInitialTrafficData.getServiceSn()); - bandwidth.setNodeName(epsInitialTrafficData.getNodeName()); - bandwidth.setBusinessId(epsInitialTrafficData.getBusinessId()); - bandwidth.setBusinessName(epsInitialTrafficData.getBusinessName()); - bandwidth.setResourceType("1"); - bandwidth.setBandwidthType("1"); - bandwidth.setBandwidthResult(dailyResult); - bandwidth.setBandwidth95Daily(dailyResult); - bandwidth.setCreateTime(startDate); - epsNodeBandwidthMapper.insertEpsNodeBandwidth(bandwidth); + }else{ + // 查询原始数据 + List dataList = query(queryParam); + if(!dataList.isEmpty()){ + // 1. 提取 outSpeed 并转换为 Mbps + List speedsInMbps = dataList.stream() + .map(data -> parseSpeedToMbps(data.getOutSpeed())) + .sorted() + .collect(Collectors.toList()); + + // 2. 计算 95% 位置(向上取整) + int total = speedsInMbps.size(); + int position = (int) Math.ceil(0.95 * total) - 1; // 转换为 0-based 索引 + if (position < 0){ + position = 0; + } + if (position >= total){ + position = total - 1; + } + + // 3. 获取 95 值并四舍五入到两位小数 + BigDecimal percentile95 = speedsInMbps.get(position); + BigDecimal dailyResult = percentile95.setScale(2, RoundingMode.HALF_UP); + // 服务器信息 + EpsInitialTrafficData epsInitialTrafficData = dataList.get(0); + // 落入带宽计算结果表 + EpsNodeBandwidth bandwidth = new EpsNodeBandwidth(); + bandwidth.setHardwareSn(epsInitialTrafficData.getServiceSn()); + bandwidth.setNodeName(epsInitialTrafficData.getNodeName()); + bandwidth.setBusinessId(epsInitialTrafficData.getBusinessId()); + bandwidth.setBusinessName(epsInitialTrafficData.getBusinessName()); + bandwidth.setResourceType("1"); + bandwidth.setBandwidthType("1"); + bandwidth.setBandwidthResult(dailyResult); + bandwidth.setBandwidth95Daily(dailyResult); + bandwidth.setCreateTime(DateUtils.parseDate(startTimeStr)); + epsNodeBandwidthMapper.insertEpsNodeBandwidth(bandwidth); + } } } } @@ -318,6 +408,45 @@ public class EpsInitialTrafficDataServiceImpl implements EpsInitialTrafficDataSe } + /** + * 计算有效-日95带宽值 + * @param dataList + */ + private void calculate95BandwidthDaily(List dataList){ + // 1. 提取 outSpeed 并转换为 Mbps + List speedsInMbps = dataList.stream() + .map(data -> parseSpeedToMbps(data.getOutSpeed())) + .sorted() + .collect(Collectors.toList()); + + // 2. 计算 95% 位置(向上取整) + int total = speedsInMbps.size(); + int position = (int) Math.ceil(0.95 * total) - 1; // 转换为 0-based 索引 + if (position < 0){ + position = 0; + } + if (position >= total){ + position = total - 1; + } + + // 3. 获取 95 值并四舍五入到两位小数 + BigDecimal percentile95 = speedsInMbps.get(position); + BigDecimal dailyResult = percentile95.setScale(2, RoundingMode.HALF_UP); + // 服务器信息 + EpsInitialTrafficData epsInitialTrafficData = dataList.get(0); + // 落入带宽计算结果表 + EpsNodeBandwidth bandwidth = new EpsNodeBandwidth(); + bandwidth.setHardwareSn(epsInitialTrafficData.getServiceSn()); + bandwidth.setNodeName(epsInitialTrafficData.getNodeName()); + bandwidth.setBusinessId(epsInitialTrafficData.getBusinessId()); + bandwidth.setBusinessName(epsInitialTrafficData.getBusinessName()); + bandwidth.setResourceType("1"); + bandwidth.setBandwidthType("5"); + bandwidth.setBandwidthResult(dailyResult); + bandwidth.setEffectiveBandwidth95Daily(dailyResult); + bandwidth.setCreateTime(DateUtils.parseDate(epsInitialTrafficData.getStartTime())); + epsNodeBandwidthMapper.insertEpsNodeBandwidth(bandwidth); + } /** * 单位换算 * @param speedWithUnit 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 e47aa9b..3a23eb8 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 @@ -17,10 +17,8 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; +import java.util.function.Function; import java.util.stream.Collectors; /** @@ -94,6 +92,11 @@ public class EpsServerRevenueConfigServiceImpl implements IEpsServerRevenueConfi String revenueMethod = getMethodName(serverRevenueConfig.getRevenueMethod()); //现在的收益方式 String nowRevenueMethod = getMethodName(epsServerRevenueConfig.getRevenueMethod()); + if(serverRevenueConfig.getBusinessCode() != null){ + if(!serverRevenueConfig.getBusinessCode().equals(epsServerRevenueConfig.getBusinessCode())){ + epsServerRevenueConfig.setChanged("1"); + } + } // 修改条数 int rows = epsServerRevenueConfigMapper.updateEpsServerRevenueConfig(epsServerRevenueConfig); if(rows>=0){ @@ -128,6 +131,11 @@ public class EpsServerRevenueConfigServiceImpl implements IEpsServerRevenueConfi ",带宽值设置为"+epsServerRevenueConfig.getPackageBandwidth()+"Mbps,"+"业务为"+epsServerRevenueConfig.getBusinessName(); } changeRecord.setChangeContent(content); + changeRecord.setBusinessCode(epsServerRevenueConfig.getBusinessCode()); + changeRecord.setBusinessName(epsServerRevenueConfig.getBusinessName()); + changeRecord.setRevenueMethod(epsServerRevenueConfig.getRevenueMethod()); + changeRecord.setPackageBandwidth(epsServerRevenueConfig.getPackageBandwidth()); + changeRecord.setTrafficPort(epsServerRevenueConfig.getTrafficPort()); // 添加操作记录 epsMethodChangeRecordMapper.insertEpsMethodChangeRecord(changeRecord); } @@ -210,31 +218,60 @@ public class EpsServerRevenueConfigServiceImpl implements IEpsServerRevenueConfi // 批量查询已存在的接口名称 List existingNames = allInterfaceNameMapper.selectByNames(interfaceNames); - Set existingNameSet = existingNames.stream() - .map(AllInterfaceName::getInterfaceName) - .collect(Collectors.toSet()); + // 转为 Map<接口名称, 数据库记录> 便于快速查找 + Map existingNameMap = existingNames.stream() + .collect(Collectors.toMap(AllInterfaceName::getInterfaceName, Function.identity())); - // 筛选出需要新增的接口名称 - List newNames = trafficDataList.stream() - .filter(data -> !existingNameSet.contains(data.getName())) - .map(data -> { - AllInterfaceName name = new AllInterfaceName(); - name.setInterfaceName(data.getName()); - name.setClientId(data.getClientId()); - name.setResourceType("1"); - name.setDeviceSn(data.getServiceSn()); - name.setNodeName(data.getNodeName()); - name.setBusinessCode(data.getBusinessId()); - name.setBusinessName(data.getBusinessName()); - return name; - }) - .collect(Collectors.toList()); + // 分类处理:新增列表 vs 更新列表 + List namesToInsert = new ArrayList<>(); + List namesToUpdate = new ArrayList<>(); - // 批量插入新接口名称 - if (!newNames.isEmpty()) { - allInterfaceNameMapper.batchInsert(newNames); - log.info("接口名称表-新增接口名称数量:{}", newNames.size()); + trafficDataList.forEach(data -> { + String name = data.getName(); + if (StringUtils.isBlank(name)) { + return; + } + + // 构造新记录(需更新的字段) + AllInterfaceName newRecord = new AllInterfaceName(); + newRecord.setInterfaceName(name); + newRecord.setClientId(data.getClientId()); + newRecord.setResourceType("1"); // 固定值 + newRecord.setDeviceSn(data.getServiceSn()); + newRecord.setNodeName(data.getNodeName()); + newRecord.setBusinessCode(data.getBusinessId()); + newRecord.setBusinessName(data.getBusinessName()); + + // 判断是否需要更新 + if (existingNameMap.containsKey(name)) { + AllInterfaceName oldRecord = existingNameMap.get(name); + if (isRecordChanged(oldRecord, newRecord)) { + newRecord.setId(oldRecord.getId()); // 保留原ID + namesToUpdate.add(newRecord); + } + } else { + namesToInsert.add(newRecord); + } + }); + + // 批量操作数据库 + if (!namesToInsert.isEmpty()) { + allInterfaceNameMapper.batchInsert(namesToInsert); + log.info("新增接口名称数量:{}", namesToInsert.size()); } + + if (!namesToUpdate.isEmpty()) { + allInterfaceNameMapper.batchUpdate(namesToUpdate); + log.info("更新接口名称数量:{}", namesToUpdate.size()); + } + } + // 辅助方法:检查记录是否有变化 + private boolean isRecordChanged(AllInterfaceName oldRecord, AllInterfaceName newRecord) { + return !Objects.equals(oldRecord.getClientId(), newRecord.getClientId()) || + !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 bec3d32..543bf99 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 @@ -14,9 +14,8 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import java.util.ArrayList; -import java.util.List; -import java.util.Set; +import java.util.*; +import java.util.function.Function; import java.util.stream.Collectors; /** @@ -172,32 +171,62 @@ public class InitialSwitchInfoDetailsServiceImpl implements IInitialSwitchInfoDe // 批量查询已存在的接口名称 List existingNames = allInterfaceNameMapper.selectByNames(interfaceNames); - Set existingNameSet = existingNames.stream() - .map(AllInterfaceName::getInterfaceName) - .collect(Collectors.toSet()); + Map existingNameMap = existingNames.stream() + .collect(Collectors.toMap(AllInterfaceName::getInterfaceName, Function.identity())); - // 筛选出需要新增的接口名称 - List newNames = initialSwitchInfoDetails.stream() - .filter(data -> !existingNameSet.contains(data.getName())) - .map(data -> { - AllInterfaceName name = new AllInterfaceName(); - name.setInterfaceName(data.getName()); - name.setClientId(data.getClientId()); - name.setResourceType("2"); - name.setDeviceSn(data.getServerSn()); - name.setNodeName(data.getServerName()); - name.setServerPort(data.getServerPort()); - name.setInterfaceDeviceType(data.getInterfaceDeviceType()); - name.setSwitchName(data.getSwitchName()); - name.setSwitchSn(data.getSwitchSn()); - return name; - }) - .collect(Collectors.toList()); + // 分类处理:新增列表 vs 更新列表 + List namesToInsert = new ArrayList<>(); + List namesToUpdate = new ArrayList<>(); - // 批量插入新接口名称 - if (!newNames.isEmpty()) { - allInterfaceNameMapper.batchInsert(newNames); - log.info("接口名称表-新增交换机接口名称数量:{}", newNames.size()); + initialSwitchInfoDetails.forEach(data -> { + String name = data.getName(); + if (StringUtils.isBlank(name)) { + return; + } + + AllInterfaceName record = new AllInterfaceName(); + record.setInterfaceName(name); + record.setClientId(data.getClientId()); + record.setResourceType("2"); + record.setDeviceSn(data.getServerSn()); + record.setNodeName(data.getServerName()); + record.setServerPort(data.getServerPort()); + record.setInterfaceDeviceType(data.getInterfaceDeviceType()); + record.setSwitchName(data.getSwitchName()); + record.setSwitchSn(data.getSwitchSn()); + + // 判断是否需要更新 + if (existingNameMap.containsKey(name)) { + AllInterfaceName existingRecord = existingNameMap.get(name); + if (isRecordChanged(existingRecord, record)) { + record.setId(existingRecord.getId()); // 保留原ID + namesToUpdate.add(record); + } + } else { + namesToInsert.add(record); + } + }); + + // 批量操作数据库 + if (!namesToInsert.isEmpty()) { + allInterfaceNameMapper.batchInsert(namesToInsert); + log.info("新增接口名称数量:{}", namesToInsert.size()); + } + + if (!namesToUpdate.isEmpty()) { + allInterfaceNameMapper.batchUpdate(namesToUpdate); + log.info("更新接口名称数量:{}", namesToUpdate.size()); } } + + // 辅助方法:检查记录是否有变化 + private boolean isRecordChanged(AllInterfaceName oldRecord, AllInterfaceName newRecord) { + return !Objects.equals(oldRecord.getClientId(), newRecord.getClientId()) || + !Objects.equals(oldRecord.getDeviceSn(), newRecord.getDeviceSn()) || + !Objects.equals(oldRecord.getNodeName(), newRecord.getNodeName()) || + !Objects.equals(oldRecord.getServerPort(), newRecord.getServerPort()) || + !Objects.equals(oldRecord.getInterfaceDeviceType(), newRecord.getInterfaceDeviceType()) || + !Objects.equals(oldRecord.getSwitchName(), newRecord.getSwitchName()) || + !Objects.equals(oldRecord.getSwitchSn(), newRecord.getSwitchSn()); + } } diff --git a/ruoyi-modules/ruoyi-system/src/main/resources/bootstrap.yml b/ruoyi-modules/ruoyi-system/src/main/resources/bootstrap.yml index ca94b42..9471621 100644 --- a/ruoyi-modules/ruoyi-system/src/main/resources/bootstrap.yml +++ b/ruoyi-modules/ruoyi-system/src/main/resources/bootstrap.yml @@ -13,11 +13,17 @@ spring: cloud: nacos: discovery: - # 服务注册地址 server-addr: 127.0.0.1:8848 + # 服务注册地址 +# server-addr: 172.16.15.103:8848 +# username: ${spring.cloud.nacos.config.username} +# password: ${spring.cloud.nacos.config.password} config: - # 配置中心地址 server-addr: 127.0.0.1:8848 + # 配置中心地址 +# server-addr: 172.16.15.103:8848 +# username: nacos +# password: nacos # 配置文件格式 file-extension: yml # 共享配置 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 89d8096..a67c4a8 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 @@ -189,4 +189,21 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" group by switch_sn + + + UPDATE all_interface_name + SET + business_code = #{item.businessCode}, + business_name = #{item.businessName}, + update_time = now(), + client_id = #{item.clientId}, + device_sn = #{item.deviceSn}, + node_name = #{item.nodeName}, + server_port = #{item.serverPort}, + interface_device_type = #{item.interfaceDeviceType}, + switch_name = #{item.switchName}, + switch_sn = #{item.switchSn} + WHERE id = #{item.id} + + \ No newline at end of file diff --git a/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/EpsMethodChangeRecordMapper.xml b/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/EpsMethodChangeRecordMapper.xml index ca8e619..b6532f4 100644 --- a/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/EpsMethodChangeRecordMapper.xml +++ b/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/EpsMethodChangeRecordMapper.xml @@ -3,7 +3,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> - + @@ -13,22 +13,35 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + + + + - select id, node_name, change_content, hardware_sn, create_time, creat_by, update_time, update_by from eps_method_change_record + select id, node_name, change_content, hardware_sn, create_time, creat_by, update_time, update_by, revenue_method, traffic_port, package_bandwidth, business_name, business_code from eps_method_change_record - + @@ -37,6 +38,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and package_bandwidth = #{packageBandwidth} and business_name like concat('%', #{businessName}, '%') and business_code = #{businessCode} + and changed = #{changed} @@ -67,6 +69,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" create_by, update_by, create_time, + changed, #{id}, @@ -83,6 +86,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{createBy}, #{updateBy}, #{createTime}, + #{changed}, @@ -102,6 +106,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" create_by = #{createBy}, update_by = #{updateBy}, create_time = #{createTime}, + changed = #{changed}, where id = #{id} diff --git a/ruoyi-rocketmq/src/main/resources/bootstrap.yml b/ruoyi-rocketmq/src/main/resources/bootstrap.yml index 2abf4f3..e6a6bbb 100644 --- a/ruoyi-rocketmq/src/main/resources/bootstrap.yml +++ b/ruoyi-rocketmq/src/main/resources/bootstrap.yml @@ -15,9 +15,15 @@ spring: discovery: # 服务注册地址 server-addr: 127.0.0.1:8848 +# server-addr: 172.16.15.103:8848 +# username: ${spring.cloud.nacos.config.username} +# password: ${spring.cloud.nacos.config.password} config: # 配置中心地址 server-addr: 127.0.0.1:8848 +# server-addr: 172.16.15.103:8848 +# username: nacos +# password: nacos # 配置文件格式 file-extension: yml # 共享配置 diff --git a/ruoyi-visual/ruoyi-monitor/src/main/resources/bootstrap.yml b/ruoyi-visual/ruoyi-monitor/src/main/resources/bootstrap.yml index 3df3fdf..34e7dab 100644 --- a/ruoyi-visual/ruoyi-monitor/src/main/resources/bootstrap.yml +++ b/ruoyi-visual/ruoyi-monitor/src/main/resources/bootstrap.yml @@ -14,10 +14,14 @@ spring: nacos: discovery: # 服务注册地址 - server-addr: 127.0.0.1:8848 + server-addr: 172.16.15.103:8848 + username: ${spring.cloud.nacos.config.username} + password: ${spring.cloud.nacos.config.password} config: # 配置中心地址 - server-addr: 127.0.0.1:8848 + server-addr: 172.16.15.103:8848 + username: nacos + password: nacos # 配置文件格式 file-extension: yml # 共享配置