完善初始流量数据库读取mq入库

This commit is contained in:
gaoyutao
2025-08-22 18:13:10 +08:00
parent 34049d1c78
commit 259398bfcc
19 changed files with 334 additions and 264 deletions

View File

@@ -0,0 +1,60 @@
package com.ruoyi.system.api;
import com.ruoyi.common.core.constant.SecurityConstants;
import com.ruoyi.common.core.constant.ServiceNameConstants;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.system.api.domain.EpsInitialTrafficDataRemote;
import com.ruoyi.system.api.domain.NodeBandwidth;
import com.ruoyi.system.api.factory.RemoteRevenueConfigFallbackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
/**
* 用户服务
*
* @author ruoyi
*/
@FeignClient(contextId = "remoteRevenueConfigService", value = ServiceNameConstants.SYSTEM_SERVICE, fallbackFactory = RemoteRevenueConfigFallbackFactory.class)
public interface RemoteRevenueConfigService
{
/**
* @param nodeBandwidth 服务器带宽收益
* @param source 请求来源
* @return 结果
*/
@PostMapping("/bandwidth/list")
public R<NodeBandwidth> getBandwidth(@RequestBody NodeBandwidth nodeBandwidth, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
/**
* @param nodeBandwidth 服务器带宽收益
* @param source 请求来源
* @return 结果
*/
@PostMapping("/bandwidth")
public R<Boolean> saveBandwidth(@RequestBody NodeBandwidth nodeBandwidth, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
/**
* 查询流量数据POST方式
* @param queryParam 查询参数实体
* source 请求来源
* @return 流量数据列表
*/
@PostMapping("/query")
public R<EpsInitialTrafficDataRemote> query(@RequestBody EpsInitialTrafficDataRemote queryParam, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
/**
* 批量保存流量数据
* @param queryParam 流量数据列表
* @return 操作结果
*/
@PostMapping("/batch")
public R<Boolean> batchInitialTraffic(@RequestBody EpsInitialTrafficDataRemote queryParam, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
/**
* 保存流量数据
* @param queryParam 流量数据列表
* @return 操作结果
*/
@PostMapping("/revenueConfig/autoSaveServiceTrafficData")
public R<String> autoSaveServiceTrafficData(@RequestBody EpsInitialTrafficDataRemote queryParam, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
}

View File

@@ -54,5 +54,9 @@ public class EpsInitialTrafficDataRemote extends BaseEntity {
/** 注册状态 */ /** 注册状态 */
@Excel(name = "注册状态") @Excel(name = "注册状态")
private String registrationStatus; private String registrationStatus;
/** 开始时间 */
private String startTime;
/** 结束时间 */
private String endTime;
} }

View File

@@ -0,0 +1,53 @@
package com.ruoyi.system.api.factory;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.system.api.RemoteRevenueConfigService;
import com.ruoyi.system.api.domain.EpsInitialTrafficDataRemote;
import com.ruoyi.system.api.domain.NodeBandwidth;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
/**
* 用户服务降级处理
*
* @author ruoyi
*/
@Component
public class RemoteRevenueConfigFallbackFactory implements FallbackFactory<RemoteRevenueConfigService>
{
private static final Logger log = LoggerFactory.getLogger(RemoteRevenueConfigFallbackFactory.class);
@Override
public RemoteRevenueConfigService create(Throwable throwable)
{
log.error("流量业务服务调用失败:{}", throwable.getMessage());
return new RemoteRevenueConfigService()
{
@Override
public R<NodeBandwidth> getBandwidth(NodeBandwidth nodeBandwidth, String source) {
return R.fail("获取服务器带宽失败:" + throwable.getMessage());
}
@Override
public R<Boolean> saveBandwidth(NodeBandwidth nodeBandwidth, String source) {
return R.fail("新增服务器带宽失败:" + throwable.getMessage());
}
@Override
public R<EpsInitialTrafficDataRemote> query(EpsInitialTrafficDataRemote queryParam, String source) {
return R.fail("获取初始流量数据失败:" + throwable.getMessage());
}
@Override
public R<Boolean> batchInitialTraffic(EpsInitialTrafficDataRemote queryParam, String source) {
return R.fail("新增初始流量数据失败:" + throwable.getMessage());
}
@Override
public R<String> autoSaveServiceTrafficData(EpsInitialTrafficDataRemote queryParam, String source) {
return R.fail("保存流量数据失败:" + throwable.getMessage());
}
};
}
}

View File

@@ -1,3 +1,4 @@
com.ruoyi.system.api.factory.RemoteUserFallbackFactory com.ruoyi.system.api.factory.RemoteUserFallbackFactory
com.ruoyi.system.api.factory.RemoteLogFallbackFactory com.ruoyi.system.api.factory.RemoteLogFallbackFactory
com.ruoyi.system.api.factory.RemoteFileFallbackFactory com.ruoyi.system.api.factory.RemoteFileFallbackFactory
com.ruoyi.system.api.factory.RemoteRevenueConfigFallbackFactory

View File

@@ -1,5 +1,6 @@
package com.ruoyi.system.controller; package com.ruoyi.system.controller;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.utils.poi.ExcelUtil; import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController; import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult; import com.ruoyi.common.core.web.domain.AjaxResult;
@@ -77,9 +78,9 @@ public class EpsServerRevenueConfigController extends BaseController
@Log(title = "流量相关数据入库", businessType = BusinessType.EXPORT) @Log(title = "流量相关数据入库", businessType = BusinessType.EXPORT)
@InnerAuth @InnerAuth
@PostMapping("/autoSaveServiceTrafficData") @PostMapping("/autoSaveServiceTrafficData")
public void autoSaveServiceTrafficData(@RequestBody EpsServerRevenueConfig epsServerRevenueConfig) public R<String> autoSaveServiceTrafficData(@RequestBody EpsServerRevenueConfig epsServerRevenueConfig)
{ {
epsServerRevenueConfigService.autoSaveServiceTrafficData(epsServerRevenueConfig); return epsServerRevenueConfigService.autoSaveServiceTrafficData(epsServerRevenueConfig);
} }
} }

View File

@@ -6,6 +6,7 @@ import lombok.Data;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.Date;
import java.util.List; import java.util.List;
/** /**
@@ -23,39 +24,39 @@ public class EpsInitialTrafficData {
/** 接口名称 */ /** 接口名称 */
@Excel(name = "接口名称") @Excel(name = "接口名称")
private String interfaceName; private String name;
/** MAC地址 */ /** MAC地址 */
@Excel(name = "MAC地址") @Excel(name = "MAC地址")
private String macAddress; private String mac;
/** 运行状态 */ /** 运行状态 */
@Excel(name = "运行状态") @Excel(name = "运行状态")
private String operationStatus; private String status;
/** 接口类型 */ /** 接口类型 */
@Excel(name = "接口类型") @Excel(name = "接口类型")
private String interfaceType; private String type;
/** IPv4地址 */ /** IPv4地址 */
@Excel(name = "IPv4地址") @Excel(name = "IPv4地址")
private String ipv4Address; private String ipV4;
/** 入站丢包率(%) */ /** 入站丢包率(%) */
@Excel(name = "入站丢包率(%)") @Excel(name = "入站丢包率(%)")
private BigDecimal inboundPacketLoss; private BigDecimal inDropped;
/** 出站丢包率(%) */ /** 出站丢包率(%) */
@Excel(name = "出站丢包率(%)") @Excel(name = "出站丢包率(%)")
private BigDecimal outboundPacketLoss; private BigDecimal outDropped;
/** 接收带宽(Mbps) */ /** 接收带宽(Mbps) */
@Excel(name = "接收带宽(Mbps)") @Excel(name = "接收带宽(Mbps)")
private BigDecimal receiveBandwidth; private String inSpeed;
/** 发送带宽(Mbps) */ /** 发送带宽(Mbps) */
@Excel(name = "发送带宽(Mbps)") @Excel(name = "发送带宽(Mbps)")
private BigDecimal sendBandwidth; private String outSpeed;
/** 业务代码 */ /** 业务代码 */
@Excel(name = "业务代码") @Excel(name = "业务代码")
@@ -93,18 +94,37 @@ public class EpsInitialTrafficData {
private String clientId; private String clientId;
/** 流量统计开始时间 */ /** 流量统计开始时间 */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") private String startTime;
private LocalDateTime startTime;
/** 流量统计结束时间 */ /** 流量统计结束时间 */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") private String endTime;
private LocalDateTime endTime;
/** 数据创建时间 */ /** 数据创建时间 */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime createTime; private LocalDateTime createTime;
/** 创建者 */
private String createBy;
/** 更新者 */
private String updateBy;
/** 更新时间 */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date updateTime;
/** 当前记录起始索引 */
private Integer pageNum;
/** 每页显示记录数 */
private Integer pageSize;
/**
* 选中的属性名称
*/
private String[] properties;
} }

View File

@@ -1,10 +1,10 @@
package com.ruoyi.system.domain; package com.ruoyi.system.domain;
import java.math.BigDecimal;
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.annotation.Excel;
import com.ruoyi.common.core.web.domain.BaseEntity; import com.ruoyi.common.core.web.domain.BaseEntity;
import lombok.Data;
import java.math.BigDecimal;
/** /**
* 服务器收益方式配置对象 eps_server_revenue_config * 服务器收益方式配置对象 eps_server_revenue_config
@@ -12,6 +12,7 @@ import com.ruoyi.common.core.web.domain.BaseEntity;
* @author gyt * @author gyt
* @date 2025-08-19 * @date 2025-08-19
*/ */
@Data
public class EpsServerRevenueConfig extends BaseEntity public class EpsServerRevenueConfig extends BaseEntity
{ {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@@ -55,123 +56,8 @@ public class EpsServerRevenueConfig extends BaseEntity
@Excel(name = "注册状态") @Excel(name = "注册状态")
private String registrationStatus; private String registrationStatus;
public void setId(Long id) /** 开始时间 */
{ private String startTime;
this.id = id; /** 结束时间 */
} private String endTime;
public Long getId()
{
return id;
}
public void setNodeName(String nodeName)
{
this.nodeName = nodeName;
}
public String getNodeName()
{
return nodeName;
}
public void setRevenueMethod(String revenueMethod)
{
this.revenueMethod = revenueMethod;
}
public String getRevenueMethod()
{
return revenueMethod;
}
public void setHardwareSn(String hardwareSn)
{
this.hardwareSn = hardwareSn;
}
public String getHardwareSn()
{
return hardwareSn;
}
public void setTrafficPort(String trafficPort)
{
this.trafficPort = trafficPort;
}
public String getTrafficPort()
{
return trafficPort;
}
public void setBandwidth95(BigDecimal bandwidth95)
{
this.bandwidth95 = bandwidth95;
}
public BigDecimal getBandwidth95()
{
return bandwidth95;
}
public void setPackageBandwidth(BigDecimal packageBandwidth)
{
this.packageBandwidth = packageBandwidth;
}
public BigDecimal getPackageBandwidth()
{
return packageBandwidth;
}
public void setBusinessName(String businessName)
{
this.businessName = businessName;
}
public String getBusinessName()
{
return businessName;
}
public void setBusinessCode(String businessCode)
{
this.businessCode = businessCode;
}
public String getBusinessCode()
{
return businessCode;
}
public void setRegistrationStatus(String registrationStatus)
{
this.registrationStatus = registrationStatus;
}
public String getRegistrationStatus()
{
return registrationStatus;
}
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("id", getId())
.append("nodeName", getNodeName())
.append("revenueMethod", getRevenueMethod())
.append("hardwareSn", getHardwareSn())
.append("trafficPort", getTrafficPort())
.append("bandwidth95", getBandwidth95())
.append("packageBandwidth", getPackageBandwidth())
.append("updateTime", getUpdateTime())
.append("businessName", getBusinessName())
.append("businessCode", getBusinessCode())
.append("registrationStatus", getRegistrationStatus())
.append("createBy", getCreateBy())
.append("updateBy", getUpdateBy())
.append("createTime", getCreateTime())
.toString();
}
} }

View File

@@ -68,7 +68,7 @@ public interface EpsServerRevenueConfigMapper
* @param hardwareSn 服务器sn * @param hardwareSn 服务器sn
* @return 数据条数 * @return 数据条数
*/ */
public int countBySn(@Param("hardwareSn") String hardwareSn); public EpsServerRevenueConfig countBySn(@Param("hardwareSn") String hardwareSn);
/** /**
* 查询服务器信息 * 查询服务器信息

View File

@@ -1,5 +1,6 @@
package com.ruoyi.system.service; package com.ruoyi.system.service;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.system.domain.EpsServerRevenueConfig; import com.ruoyi.system.domain.EpsServerRevenueConfig;
import java.util.List; import java.util.List;
@@ -62,8 +63,7 @@ public interface IEpsServerRevenueConfigService
/** /**
* 保存业务相关流量表 * 保存业务相关流量表
* 每5分钟自动执行
* @param epsServerRevenueConfig * @param epsServerRevenueConfig
*/ */
void autoSaveServiceTrafficData(EpsServerRevenueConfig epsServerRevenueConfig); R<String> autoSaveServiceTrafficData(EpsServerRevenueConfig epsServerRevenueConfig);
} }

View File

@@ -168,7 +168,7 @@ public class EpsInitialTrafficDataServiceImpl implements EpsInitialTrafficDataSe
// 获取涉及的表名 // 获取涉及的表名
Set<String> tableNames = TableRouterUtil.getTableNamesBetweenInitial(queryParam.getStartTime(), queryParam.getEndTime()); Set<String> tableNames = TableRouterUtil.getTableNamesBetweenInitial(queryParam.getStartTime(), queryParam.getEndTime());
log.error("initial表名{}",tableNames);
// 并行查询各表 // 并行查询各表
return tableNames.parallelStream() return tableNames.parallelStream()
.flatMap(tableName -> { .flatMap(tableName -> {
@@ -176,7 +176,7 @@ public class EpsInitialTrafficDataServiceImpl implements EpsInitialTrafficDataSe
condition.setTableName(tableName); condition.setTableName(tableName);
condition.setStartTime(queryParam.getStartTime()); condition.setStartTime(queryParam.getStartTime());
condition.setEndTime(queryParam.getEndTime()); condition.setEndTime(queryParam.getEndTime());
condition.setInterfaceName(queryParam.getInterfaceName()); condition.setName(queryParam.getName());
return epsInitialTrafficDataMapper.getAllTraficMsg(condition).stream(); return epsInitialTrafficDataMapper.getAllTraficMsg(condition).stream();
}) })
.collect(Collectors.toList()); .collect(Collectors.toList());

View File

@@ -187,16 +187,16 @@ public class EpsNodeBandwidthServiceImpl implements IEpsNodeBandwidthService
case "1": case "1":
case "3": case "3":
case "5": // 日带宽 case "5": // 日带宽
data.setStartTime(baseTime.with(LocalTime.MIN)); // 00:00:00 data.setStartTime(baseTime.with(LocalTime.MIN) + ""); // 00:00:00
data.setEndTime(baseTime.with(LocalTime.MAX).withNano(0)); // 23:59:59 data.setEndTime(baseTime.with(LocalTime.MAX).withNano(0) + ""); // 23:59:59
break; break;
case "2": case "2":
case "4": case "4":
case "6": case "6":
case "7": // 月带宽 case "7": // 月带宽
YearMonth month = YearMonth.from(baseTime); YearMonth month = YearMonth.from(baseTime);
data.setStartTime(month.atDay(1).atStartOfDay()); // 当月第一天 00:00:00 data.setStartTime(month.atDay(1).atStartOfDay() + ""); // 当月第一天 00:00:00
data.setEndTime(month.atEndOfMonth().atTime(23, 59, 59)); // 当月最后一天 23:59:59 data.setEndTime(month.atEndOfMonth().atTime(23, 59, 59) + ""); // 当月最后一天 23:59:59
break; break;
default: default:
throw new IllegalArgumentException("不支持的带宽类型: " + bandwidthType); throw new IllegalArgumentException("不支持的带宽类型: " + bandwidthType);

View File

@@ -1,5 +1,6 @@
package com.ruoyi.system.service.impl; package com.ruoyi.system.service.impl;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.utils.DateUtils; import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.security.utils.SecurityUtils; import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.system.domain.EpsInitialTrafficData; import com.ruoyi.system.domain.EpsInitialTrafficData;
@@ -8,10 +9,11 @@ import com.ruoyi.system.domain.EpsServerRevenueConfig;
import com.ruoyi.system.mapper.EpsServerRevenueConfigMapper; import com.ruoyi.system.mapper.EpsServerRevenueConfigMapper;
import com.ruoyi.system.service.EpsInitialTrafficDataService; import com.ruoyi.system.service.EpsInitialTrafficDataService;
import com.ruoyi.system.service.IEpsServerRevenueConfigService; import com.ruoyi.system.service.IEpsServerRevenueConfigService;
import com.ruoyi.system.util.DateUtil; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -22,6 +24,7 @@ import java.util.Map;
* @date 2025-08-19 * @date 2025-08-19
*/ */
@Service @Service
@Slf4j
public class EpsServerRevenueConfigServiceImpl implements IEpsServerRevenueConfigService public class EpsServerRevenueConfigServiceImpl implements IEpsServerRevenueConfigService
{ {
@Autowired @Autowired
@@ -124,17 +127,17 @@ public class EpsServerRevenueConfigServiceImpl implements IEpsServerRevenueConfi
* @param epsServerRevenueConfig * @param epsServerRevenueConfig
*/ */
private void saveServiceTrafficData(EpsServerRevenueConfig epsServerRevenueConfig) { private void saveServiceTrafficData(EpsServerRevenueConfig epsServerRevenueConfig) {
// 查询初始流量数据 // 初始流量数据
EpsInitialTrafficData epsInitialTrafficData = new EpsInitialTrafficData(); EpsInitialTrafficData epsInitialTrafficData = new EpsInitialTrafficData();
epsInitialTrafficData.setServiceSn(epsServerRevenueConfig.getHardwareSn()); epsInitialTrafficData.setServiceSn(epsServerRevenueConfig.getHardwareSn());
epsInitialTrafficData.setBusinessId(epsServerRevenueConfig.getBusinessCode()); epsInitialTrafficData.setBusinessId(epsServerRevenueConfig.getBusinessCode());
epsInitialTrafficData.setBusinessName(epsServerRevenueConfig.getBusinessName()); epsInitialTrafficData.setBusinessName(epsServerRevenueConfig.getBusinessName());
epsInitialTrafficData.setInterfaceName(epsServerRevenueConfig.getTrafficPort()); epsInitialTrafficData.setName(epsServerRevenueConfig.getTrafficPort());
epsInitialTrafficData.setPackageBandwidth(epsServerRevenueConfig.getPackageBandwidth()); epsInitialTrafficData.setPackageBandwidth(epsServerRevenueConfig.getPackageBandwidth());
epsInitialTrafficData.setRevenueMethod(epsServerRevenueConfig.getRevenueMethod()); epsInitialTrafficData.setRevenueMethod(epsServerRevenueConfig.getRevenueMethod());
epsInitialTrafficData.setNodeName(epsServerRevenueConfig.getNodeName()); epsInitialTrafficData.setNodeName(epsServerRevenueConfig.getNodeName());
epsInitialTrafficData.setStartTime(DateUtil.dateToLocalDateTime(epsServerRevenueConfig.getCreateTime())); epsInitialTrafficData.setStartTime(epsServerRevenueConfig.getCreateTime() + "");
epsInitialTrafficData.setEndTime(DateUtil.dateToLocalDateTime(epsServerRevenueConfig.getCreateTime())); epsInitialTrafficData.setEndTime(epsServerRevenueConfig.getCreateTime() + "");
epsInitialTrafficDataService.save(epsInitialTrafficData); epsInitialTrafficDataService.save(epsInitialTrafficData);
} }
@@ -144,26 +147,39 @@ public class EpsServerRevenueConfigServiceImpl implements IEpsServerRevenueConfi
* @param epsServerRevenueConfig * @param epsServerRevenueConfig
*/ */
@Override @Override
public void autoSaveServiceTrafficData(EpsServerRevenueConfig epsServerRevenueConfig) { public R<String> autoSaveServiceTrafficData(EpsServerRevenueConfig epsServerRevenueConfig) {
// 查询初始流量数据 // 查询初始流量数据
EpsInitialTrafficData epsInitialTrafficData = new EpsInitialTrafficData(); EpsInitialTrafficData epsInitialTrafficData = new EpsInitialTrafficData();
epsInitialTrafficData.setStartTime(DateUtil.dateToLocalDateTime(epsServerRevenueConfig.getCreateTime())); epsInitialTrafficData.setStartTime(epsServerRevenueConfig.getStartTime());
epsInitialTrafficData.setEndTime(DateUtil.dateToLocalDateTime(epsServerRevenueConfig.getCreateTime())); epsInitialTrafficData.setEndTime(epsServerRevenueConfig.getEndTime());
List<EpsInitialTrafficData> dataList = epsInitialTrafficDataService.getAllTraficMsg(epsInitialTrafficData); List<EpsInitialTrafficData> dataList = epsInitialTrafficDataService.getAllTraficMsg(epsInitialTrafficData);
List<EpsInitialTrafficData> batchList = new ArrayList<>();
for (EpsInitialTrafficData initialTrafficData : dataList) { for (EpsInitialTrafficData initialTrafficData : dataList) {
// 根据ip查询节点名称 // 根据ip查询节点名称
String ip = initialTrafficData.getIpv4Address(); String ip = initialTrafficData.getIpV4() == null ? "" : initialTrafficData.getIpV4();
Map nodeMsg = epsServerRevenueConfigMapper.getNodeMsgByIp(ip); Map nodeMsg = epsServerRevenueConfigMapper.getNodeMsgByIp(ip);
// 赋值 // 赋值
initialTrafficData.setServiceSn(nodeMsg.get("hardwareSn") + ""); if(nodeMsg != null){
initialTrafficData.setNodeName(nodeMsg.get("resourceName") + ""); initialTrafficData.setServiceSn(nodeMsg.get("hardwareSn") + "");
initialTrafficData.setRevenueMethod(nodeMsg.get("revenueMethod") + ""); initialTrafficData.setNodeName(nodeMsg.get("resourceName") + "");
initialTrafficData.setBusinessId(nodeMsg.get("businessCode") + ""); initialTrafficData.setRevenueMethod(nodeMsg.get("revenueMethod") + "");
initialTrafficData.setBusinessName(nodeMsg.get("businessName") + ""); initialTrafficData.setBusinessId(nodeMsg.get("businessCode") + "");
initialTrafficData.setStartTime(initialTrafficData.getCreateTime()); initialTrafficData.setBusinessName(nodeMsg.get("businessName") + "");
initialTrafficData.setEndTime(initialTrafficData.getCreateTime()); }
// 流量相关数据入库 // id自增
epsInitialTrafficDataService.save(initialTrafficData); initialTrafficData.setId(null);
batchList.add(initialTrafficData);
}
epsInitialTrafficData.setDataList(batchList);
// 流量相关数据入库
try {
epsInitialTrafficDataService.saveBatch(epsInitialTrafficData);
log.info("流量数据批量入库成功,数据量:{}", batchList.size());
return R.ok("数据保存成功");
} catch (Exception e) {
log.error("流量数据入库失败,数据量:{},错误原因:{}",
batchList.size(), e.getMessage(), e);
return R.fail("数据保存失败:" + e.getMessage());
} }
} }
/** /**

View File

@@ -125,10 +125,12 @@ public class RmResourceRegistrationServiceImpl implements IRmResourceRegistratio
epsServerRevenueConfig.setHardwareSn(rmResourceRegistration.getHardwareSn()); epsServerRevenueConfig.setHardwareSn(rmResourceRegistration.getHardwareSn());
epsServerRevenueConfig.setNodeName(rmResourceRegistration.getResourceName()); epsServerRevenueConfig.setNodeName(rmResourceRegistration.getResourceName());
epsServerRevenueConfig.setCreateTime(DateUtils.getNowDate()); epsServerRevenueConfig.setCreateTime(DateUtils.getNowDate());
epsServerRevenueConfig.setRegistrationStatus(rmResourceRegistration.getRegistrationStatus());
// 新增前判断是否存在 // 新增前判断是否存在
int exits = epsServerRevenueConfigMapper.countBySn(epsServerRevenueConfig.getHardwareSn()); EpsServerRevenueConfig exits = epsServerRevenueConfigMapper.countBySn(epsServerRevenueConfig.getHardwareSn());
if(exits>0){ if(exits != null){
// 存在 修改 // 存在 修改
epsServerRevenueConfig.setId(exits.getId());
epsServerRevenueConfigMapper.updateEpsServerRevenueConfig(epsServerRevenueConfig); epsServerRevenueConfigMapper.updateEpsServerRevenueConfig(epsServerRevenueConfig);
}else{ }else{
// 不存在 新增 // 不存在 新增

View File

@@ -19,7 +19,8 @@ public class TableRouterUtil {
// 日期格式 // 日期格式
private static final DateTimeFormatter YEAR_MONTH_FORMAT = private static final DateTimeFormatter YEAR_MONTH_FORMAT =
DateTimeFormatter.ofPattern("yyyy_MM"); DateTimeFormatter.ofPattern("yyyy_MM");
private static final DateTimeFormatter DATE_TIME_FORMATTER =
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
/** /**
* 根据创建时间获取表名 * 根据创建时间获取表名
* @param createTime 记录创建时间 * @param createTime 记录创建时间
@@ -60,17 +61,19 @@ public class TableRouterUtil {
/** /**
* 获取时间范围内涉及的所有表名 * 获取时间范围内涉及的所有表名
* @param startTime 开始时间(包含) * @param startTime 开始时间 (格式: "yyyy-MM-dd HH:mm:ss")
* @param endTime 结束时间(包含) * @param endTime 结束时间 (格式: "yyyy-MM-dd HH:mm:ss")
* @return 按时间顺序排列的表名集合 * @return 按时间顺序排列的表名集合
*/ */
public static Set<String> getTableNamesBetween(LocalDateTime startTime, LocalDateTime endTime) { public static Set<String> getTableNamesBetween(String startTime, String endTime) {
validateTimeRange(startTime, endTime); LocalDateTime start = parseDateTime(startTime);
LocalDateTime end = parseDateTime(endTime);
validateTimeRange(start, end);
Set<String> tableNames = new LinkedHashSet<>(); Set<String> tableNames = new LinkedHashSet<>();
LocalDateTime current = startTime.withHour(0).withMinute(0).withSecond(0); LocalDateTime current = start.withHour(0).withMinute(0).withSecond(0);
while (!current.isAfter(endTime)) { while (!current.isAfter(end)) {
tableNames.add(getTableName(current)); tableNames.add(getTableName(current));
current = current.plusDays(1); current = current.plusDays(1);
} }
@@ -78,25 +81,37 @@ public class TableRouterUtil {
return tableNames; return tableNames;
} }
/** /**
* 获取时间范围内涉及的所有表名 * 获取时间范围内涉及的所有初始表名
* @param startTime 开始时间(包含) * @param startTime 开始时间 (格式: "yyyy-MM-dd HH:mm:ss")
* @param endTime 结束时间(包含) * @param endTime 结束时间 (格式: "yyyy-MM-dd HH:mm:ss")
* @return 按时间顺序排列的表名集合 * @return 按时间顺序排列的表名集合
*/ */
public static Set<String> getTableNamesBetweenInitial(LocalDateTime startTime, LocalDateTime endTime) { public static Set<String> getTableNamesBetweenInitial(String startTime, String endTime) {
validateTimeRange(startTime, endTime); LocalDateTime start = parseDateTime(startTime);
LocalDateTime end = parseDateTime(endTime);
validateTimeRange(start, end);
Set<String> tableNames = new LinkedHashSet<>(); Set<String> tableNames = new LinkedHashSet<>();
LocalDateTime current = startTime.withHour(0).withMinute(0).withSecond(0); LocalDateTime current = start.withHour(0).withMinute(0).withSecond(0);
while (!current.isAfter(endTime)) { while (!current.isAfter(end)) {
tableNames.add(getInitialTableName(current)); tableNames.add(getInitialTableName(current));
current = current.plusDays(1); current = current.plusDays(1);
} }
return tableNames; return tableNames;
} }
// 解析字符串为LocalDateTime
private static LocalDateTime parseDateTime(String dateTimeStr) {
if (dateTimeStr == null || dateTimeStr.trim().isEmpty()) {
throw new IllegalArgumentException("时间字符串不能为空");
}
try {
return LocalDateTime.parse(dateTimeStr, DATE_TIME_FORMATTER);
} catch (Exception e) {
throw new IllegalArgumentException("时间格式必须为: yyyy-MM-dd HH:mm:ss", e);
}
}
// 获取日期区间 // 获取日期区间
private static String getDayRange(int day) { private static String getDayRange(int day) {

View File

@@ -54,18 +54,18 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
INDEX idx_name_time (`name`,create_time) INDEX idx_name_time (`name`,create_time)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='初始带宽流量表'; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='初始带宽流量表';
</update> </update>
<!-- 单条插入 --> <!-- 单条插入语句 -->
<insert id="insert"> <insert id="insert">
INSERT INTO ${tableName} ( INSERT INTO ${tableName} (
interface_name, `name`,
mac_address, `mac`,
operation_status, `status`,
interface_type, `type`,
ipv4_address, ipV4,
inbound_packet_loss, `in_dropped`,
outbound_packet_loss, `out_dropped`,
receive_bandwidth, `in_speed`,
send_bandwidth, `out_speed`,
business_id, business_id,
business_name, business_name,
service_sn, service_sn,
@@ -76,15 +76,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
update_by, update_by,
client_id client_id
) VALUES ( ) VALUES (
#{interfaceName}, #{name},
#{macAddress}, #{mac},
#{operationStatus}, #{status},
#{interfaceType}, #{type},
#{ipv4Address}, #{ipV4},
#{inboundPacketLoss}, #{inDropped},
#{outboundPacketLoss}, #{outDropped},
#{receiveBandwidth}, #{inSpeed},
#{sendBandwidth}, #{outSpeed},
#{businessId}, #{businessId},
#{businessName}, #{businessName},
#{serviceSn}, #{serviceSn},
@@ -97,19 +97,19 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
) )
</insert> </insert>
<!-- 批量插入 --> <!-- 批量插入语句 -->
<insert id="batchInsert"> <insert id="batchInsert">
INSERT INTO ${tableName} ( INSERT INTO ${tableName} (
id, id,
interface_name, `name`,
mac_address, `mac`,
operation_status, `status`,
interface_type, `type`,
ipv4_address, ipV4,
inbound_packet_loss, `in_dropped`,
outbound_packet_loss, `out_dropped`,
receive_bandwidth, `in_speed`,
send_bandwidth, `out_speed`,
business_id, business_id,
business_name, business_name,
service_sn, service_sn,
@@ -122,19 +122,19 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
update_by, update_by,
client_id client_id
) VALUES ) VALUES
<foreach collection="list" item="data" separator=","> <foreach collection="dataList" item="data" separator=",">
( (
#{data.id,jdbcType=BIGINT}, #{data.id,jdbcType=BIGINT},
#{data.interfaceName,jdbcType=VARCHAR}, #{data.name,jdbcType=VARCHAR},
#{data.macAddress,jdbcType=CHAR}, #{data.mac,jdbcType=VARCHAR},
#{data.operationStatus,jdbcType=VARCHAR}, #{data.status,jdbcType=VARCHAR},
#{data.interfaceType,jdbcType=VARCHAR}, #{data.type,jdbcType=VARCHAR},
#{data.ipv4Address,jdbcType=VARCHAR}, #{data.ipV4,jdbcType=VARCHAR},
#{data.inboundPacketLoss,jdbcType=DECIMAL}, #{data.inDropped,jdbcType=DECIMAL},
#{data.outboundPacketLoss,jdbcType=DECIMAL}, #{data.outDropped,jdbcType=DECIMAL},
#{data.receiveBandwidth,jdbcType=DECIMAL}, #{data.inSpeed,jdbcType=VARCHAR},
#{data.sendBandwidth,jdbcType=DECIMAL}, #{data.outSpeed,jdbcType=VARCHAR},
#{data.businessId,jdbcType=CHAR}, #{data.businessId,jdbcType=VARCHAR},
#{data.businessName,jdbcType=VARCHAR}, #{data.businessName,jdbcType=VARCHAR},
#{data.serviceSn,jdbcType=VARCHAR}, #{data.serviceSn,jdbcType=VARCHAR},
#{data.nodeName,jdbcType=VARCHAR}, #{data.nodeName,jdbcType=VARCHAR},
@@ -153,15 +153,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectByCondition" resultType="EpsInitialTrafficData"> <select id="selectByCondition" resultType="EpsInitialTrafficData">
SELECT SELECT
id, id,
`name` AS interfaceName, `name` AS name,
`mac` AS macAddress, `mac` AS mac,
`status` AS operationStatus, `status` AS status,
`type` AS interfaceType, `type` AS type,
`ipV4` AS ipv4Address, `ipV4` AS ipV4,
`in_dropped` AS inboundPacketLoss, `in_dropped` AS inDropped,
`out_dropped` AS outboundPacketLoss, `out_dropped` AS outDropped,
`in_speed` AS receiveBandwidth, `in_speed` AS inSpeed,
`out_speed` AS sendBandwidth, `out_speed` AS outSpeed,
business_id AS businessId, business_id AS businessId,
business_name AS businessName, business_name AS businessName,
service_sn AS serviceSn, service_sn AS serviceSn,
@@ -193,15 +193,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="getAllTraficMsg" resultType="EpsInitialTrafficData"> <select id="getAllTraficMsg" resultType="EpsInitialTrafficData">
SELECT SELECT
id, id,
`name` AS interfaceName, `name` AS name,
`mac` AS macAddress, `mac` AS mac,
`status` AS operationStatus, `status` AS status,
`type` AS interfaceType, `type` AS type,
`ipV4` AS ipv4Address, `ipV4` AS ipV4,
`in_dropped` AS inboundPacketLoss, `in_dropped` AS inDropped,
`out_dropped` AS outboundPacketLoss, `out_dropped` AS outDropped,
`in_speed` AS receiveBandwidth, `in_speed` AS inSpeed,
`out_speed` AS sendBandwidth, `out_speed` AS outSpeed,
create_time AS createTime, create_time AS createTime,
update_time AS updateTime, update_time AS updateTime,
create_by AS createBy, create_by AS createBy,

View File

@@ -46,7 +46,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select> </select>
<select id="countBySn" parameterType="String"> <select id="countBySn" parameterType="String">
select count(1) from eps_server_revenue_config <include refid="selectEpsServerRevenueConfigVo"/>
where hardware_sn = #{hardwareSn} where hardware_sn = #{hardwareSn}
</select> </select>
@@ -132,7 +132,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
rrr.hardware_sn = esrc.hardware_sn rrr.hardware_sn = esrc.hardware_sn
<where> <where>
and rrr.registration_status = '1' and rrr.registration_status = '1'
<if test="ipAddress != null and ipAddress != ''"> and rrr.ip_address = #{ipAddress}</if> and rrr.ip_address = #{ipAddress}
</where> </where>
</select> </select>
</mapper> </mapper>

View File

@@ -64,6 +64,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="updaterId != null "> and updater_id = #{updaterId}</if> <if test="updaterId != null "> and updater_id = #{updaterId}</if>
<if test="updaterName != null and updaterName != ''"> and updater_name like concat('%', #{updaterName}, '%')</if> <if test="updaterName != null and updaterName != ''"> and updater_name like concat('%', #{updaterName}, '%')</if>
</where> </where>
order by create_time desc
</select> </select>
<select id="selectRmResourceRegistrationById" parameterType="Long" resultMap="RmResourceRegistrationResult"> <select id="selectRmResourceRegistrationById" parameterType="Long" resultMap="RmResourceRegistrationResult">

View File

@@ -8,7 +8,7 @@ import com.ruoyi.rocketmq.domain.InitialBandwidthTraffic;
import com.ruoyi.rocketmq.enums.MessageCodeEnum; import com.ruoyi.rocketmq.enums.MessageCodeEnum;
import com.ruoyi.rocketmq.producer.ConsumeException; import com.ruoyi.rocketmq.producer.ConsumeException;
import com.ruoyi.rocketmq.service.IInitialBandwidthTrafficService; import com.ruoyi.rocketmq.service.IInitialBandwidthTrafficService;
import com.ruoyi.system.api.RemoteUserService; import com.ruoyi.system.api.RemoteRevenueConfigService;
import com.ruoyi.system.api.domain.EpsInitialTrafficDataRemote; import com.ruoyi.system.api.domain.EpsInitialTrafficDataRemote;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext; import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext;
@@ -31,13 +31,13 @@ public class RocketMsgListener implements MessageListenerConcurrently {
private final IInitialBandwidthTrafficService initialBandwidthTrafficService; private final IInitialBandwidthTrafficService initialBandwidthTrafficService;
private final RemoteUserService remoteUserService; private final RemoteRevenueConfigService remoteRevenueConfigService;
@Autowired @Autowired
public RocketMsgListener(IInitialBandwidthTrafficService initialBandwidthTrafficService, public RocketMsgListener(IInitialBandwidthTrafficService initialBandwidthTrafficService,
RemoteUserService remoteUserService) { RemoteRevenueConfigService remoteRevenueConfigService) {
this.initialBandwidthTrafficService = initialBandwidthTrafficService; this.initialBandwidthTrafficService = initialBandwidthTrafficService;
this.remoteUserService = remoteUserService; this.remoteRevenueConfigService = remoteRevenueConfigService;
} }
/** /**
@@ -77,6 +77,16 @@ public class RocketMsgListener implements MessageListenerConcurrently {
case "NET": case "NET":
handleNetMessage(message); handleNetMessage(message);
break; break;
case "CPU":
break;
case "SYSTEM":
break;
case "DISK":
break;
case "POINT":
break;
case "MEMORY":
break;
default: default:
log.warn("未知数据类型:{}",message.getDataType()); log.warn("未知数据类型:{}",message.getDataType());
@@ -111,6 +121,10 @@ public class RocketMsgListener implements MessageListenerConcurrently {
return ConsumeConcurrentlyStatus.RECONSUME_LATER; return ConsumeConcurrentlyStatus.RECONSUME_LATER;
} }
/**
* 网络流量数据入库
* @param message
*/
private void handleNetMessage(DeviceMessage message) { private void handleNetMessage(DeviceMessage message) {
List<InitialBandwidthTraffic> interfaces = JSON.parseArray(message.getData(), InitialBandwidthTraffic.class); List<InitialBandwidthTraffic> interfaces = JSON.parseArray(message.getData(), InitialBandwidthTraffic.class);
InitialBandwidthTraffic data = new InitialBandwidthTraffic(); InitialBandwidthTraffic data = new InitialBandwidthTraffic();
@@ -119,12 +133,17 @@ public class RocketMsgListener implements MessageListenerConcurrently {
}); });
// 批量入库集合 // 批量入库集合
data.setList(interfaces); data.setList(interfaces);
// 开始时间
String startTime = DateUtils.getTime();
// 初始流量数据入库 // 初始流量数据入库
initialBandwidthTrafficService.batchInsert(data); initialBandwidthTrafficService.batchInsert(data);
// 结束时间
String endTime = DateUtils.getTime();
EpsInitialTrafficDataRemote epsInitialTrafficDataRemote = new EpsInitialTrafficDataRemote(); EpsInitialTrafficDataRemote epsInitialTrafficDataRemote = new EpsInitialTrafficDataRemote();
epsInitialTrafficDataRemote.setCreateTime(DateUtils.getNowDate()); epsInitialTrafficDataRemote.setStartTime(startTime);
epsInitialTrafficDataRemote.setEndTime(endTime);
// 复制到业务初始库 // 复制到业务初始库
remoteUserService.autoSaveServiceTrafficData(epsInitialTrafficDataRemote, SecurityConstants.FROM_SOURCE); remoteRevenueConfigService.autoSaveServiceTrafficData(epsInitialTrafficDataRemote, SecurityConstants.INNER);
} }
} }

View File

@@ -1,26 +1,19 @@
package com.ruoyi.rocketmq.controller; package com.ruoyi.rocketmq.controller;
import java.util.List; import com.ruoyi.common.core.utils.poi.ExcelUtil;
import java.io.IOException; import com.ruoyi.common.core.web.controller.BaseController;
import javax.servlet.http.HttpServletResponse; import com.ruoyi.common.core.web.domain.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired; import com.ruoyi.common.core.web.page.TableDataInfo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log; import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType; import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions; import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.rocketmq.domain.InitialBandwidthTraffic; import com.ruoyi.rocketmq.domain.InitialBandwidthTraffic;
import com.ruoyi.rocketmq.service.IInitialBandwidthTrafficService; import com.ruoyi.rocketmq.service.IInitialBandwidthTrafficService;
import com.ruoyi.common.core.web.controller.BaseController; import org.springframework.beans.factory.annotation.Autowired;
import com.ruoyi.common.core.web.domain.AjaxResult; import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo; import javax.servlet.http.HttpServletResponse;
import java.util.List;
/** /**
* 初始带宽流量Controller * 初始带宽流量Controller
@@ -34,7 +27,6 @@ public class InitialBandwidthTrafficController extends BaseController
{ {
@Autowired @Autowired
private IInitialBandwidthTrafficService initialBandwidthTrafficService; private IInitialBandwidthTrafficService initialBandwidthTrafficService;
/** /**
* 查询初始带宽流量列表 * 查询初始带宽流量列表
*/ */