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

This commit is contained in:
gaoyutao
2025-08-21 18:29:22 +08:00
parent 80dbba70fe
commit 34049d1c78
30 changed files with 912 additions and 446 deletions

View File

@@ -22,4 +22,5 @@ public class TableScheduleConfig {
public void createNextMonthTables() {
epsInitialTrafficDataService.createNextMonthTables();
}
}

View File

@@ -7,6 +7,7 @@ import com.ruoyi.common.core.web.page.PageDomain;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.InnerAuth;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.EpsServerRevenueConfig;
import com.ruoyi.system.service.IEpsServerRevenueConfigService;
@@ -70,4 +71,15 @@ public class EpsServerRevenueConfigController extends BaseController
return toAjax(epsServerRevenueConfigService.updateEpsServerRevenueConfig(epsServerRevenueConfig));
}
/**
* 流量相关数据入库
*/
@Log(title = "流量相关数据入库", businessType = BusinessType.EXPORT)
@InnerAuth
@PostMapping("/autoSaveServiceTrafficData")
public void autoSaveServiceTrafficData(@RequestBody EpsServerRevenueConfig epsServerRevenueConfig)
{
epsServerRevenueConfigService.autoSaveServiceTrafficData(epsServerRevenueConfig);
}
}

View File

@@ -1,8 +1,10 @@
package com.ruoyi.system.domain;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.common.core.annotation.Excel;
import lombok.Data;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
@@ -13,15 +15,82 @@ import java.util.List;
*/
@Data
public class EpsInitialTrafficData {
/** 主键ID */
private static final long serialVersionUID = 1L;
/** 唯一标识ID */
private Long id;
/** 接口名称 */
@Excel(name = "接口名称")
private String interfaceName;
/** MAC地址 */
@Excel(name = "MAC地址")
private String macAddress;
/** 运行状态 */
@Excel(name = "运行状态")
private String operationStatus;
/** 接口类型 */
@Excel(name = "接口类型")
private String interfaceType;
/** IPv4地址 */
@Excel(name = "IPv4地址")
private String ipv4Address;
/** 入站丢包率(%) */
@Excel(name = "入站丢包率(%)")
private BigDecimal inboundPacketLoss;
/** 出站丢包率(%) */
@Excel(name = "出站丢包率(%)")
private BigDecimal outboundPacketLoss;
/** 接收带宽(Mbps) */
@Excel(name = "接收带宽(Mbps)")
private BigDecimal receiveBandwidth;
/** 发送带宽(Mbps) */
@Excel(name = "发送带宽(Mbps)")
private BigDecimal sendBandwidth;
/** 业务代码 */
@Excel(name = "业务代码")
private String businessId;
/** 业务名称 */
@Excel(name = "业务名称")
private String businessName;
/** 服务器SN */
@Excel(name = "服务器SN")
private String serviceSn;
/** 服务器名称 */
@Excel(name = "服务器名称")
private String nodeName;
/** 收益方式(1.流量,2包端) */
@Excel(name = "收益方式(1.流量,2包端)")
private String revenueMethod;
/** 包端带宽值 */
@Excel(name = "包端带宽值")
private BigDecimal packageBandwidth;
/** 批量插入集合 **/
private List<EpsInitialTrafficData> dataList;
/**
* 动态表名
* 格式eps_traffic_[年]_[月]_[日期范围]
* 示例eps_traffic_2023_08_1_10
*/
private String tableName;
/** 设备唯一标识 */
private String clientId;
/** 流量统计开始时间 */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@@ -31,36 +100,11 @@ public class EpsInitialTrafficData {
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime endTime;
/** 接收流量单位MB */
private Double receiveTraffic;
/** 发送流量单位MB */
private Double sendTraffic;
/** 设备序列号 */
private String deviceSn;
/** 流量端口 */
private String trafficPort;
/** 业务代码 */
private String businesId;
/** 数据创建时间 */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime createTime;
/** 备用字段1 */
private String remark1;
/** 备用字段2 */
private String remark2;
/** 备用字段3 */
private String remark3;
/** 备用字段4 */
private String remark4;
/** 批量插入集合 **/
private List<EpsInitialTrafficData> dataList;
}

View File

@@ -34,4 +34,11 @@ public interface EpsInitialTrafficDataMapper {
* @return 流量数据列表
*/
List<EpsInitialTrafficData> selectByCondition(EpsInitialTrafficData condition);
/**
* 查询初始流量信息
* @param condition 查询条件实体
* @return 初始流量数据列表
*/
List<EpsInitialTrafficData> getAllTraficMsg(EpsInitialTrafficData condition);
}

View File

@@ -4,6 +4,7 @@ import com.ruoyi.system.domain.EpsServerRevenueConfig;
import org.springframework.data.repository.query.Param;
import java.util.List;
import java.util.Map;
/**
* 服务器收益方式配置Mapper接口
@@ -68,4 +69,12 @@ public interface EpsServerRevenueConfigMapper
* @return 数据条数
*/
public int countBySn(@Param("hardwareSn") String hardwareSn);
/**
* 查询服务器信息
*
* @param ipAddress ipv4地址
* @return 服务器收益方式配置
*/
public Map getNodeMsgByIp(@Param("ipAddress") String ipAddress);
}

View File

@@ -33,5 +33,11 @@ public interface EpsInitialTrafficDataService {
* @return 流量数据列表
*/
List<EpsInitialTrafficData> query(EpsInitialTrafficData queryParam);
/**
* 查询初始流量信息
* @param queryParam 查询参数实体
* @return 初始流量数据列表
*/
List<EpsInitialTrafficData> getAllTraficMsg(EpsInitialTrafficData queryParam);
}

View File

@@ -1,8 +1,9 @@
package com.ruoyi.system.service;
import java.util.List;
import com.ruoyi.system.domain.EpsServerRevenueConfig;
import java.util.List;
/**
* 服务器收益方式配置Service接口
*
@@ -58,4 +59,11 @@ public interface IEpsServerRevenueConfigService
* @return 结果
*/
public int deleteEpsServerRevenueConfigById(Long id);
/**
* 保存业务相关流量表
* 每5分钟自动执行
* @param epsServerRevenueConfig
*/
void autoSaveServiceTrafficData(EpsServerRevenueConfig epsServerRevenueConfig);
}

View File

@@ -151,14 +151,35 @@ public class EpsInitialTrafficDataServiceImpl implements EpsInitialTrafficDataSe
.flatMap(tableName -> {
EpsInitialTrafficData condition = new EpsInitialTrafficData();
condition.setTableName(tableName);
condition.setDeviceSn(queryParam.getDeviceSn());
condition.setServiceSn(queryParam.getServiceSn());
condition.setStartTime(queryParam.getStartTime());
condition.setEndTime(queryParam.getEndTime());
condition.setReceiveTraffic(queryParam.getReceiveTraffic());
condition.setSendTraffic(queryParam.getSendTraffic());
condition.setBusinessId(queryParam.getBusinessId());
condition.setBusinessName(queryParam.getBusinessName());
return epsInitialTrafficDataMapper.selectByCondition(condition).stream();
})
.collect(Collectors.toList());
}
/**
* 查询初始流量信息
*/
@Override
public List<EpsInitialTrafficData> getAllTraficMsg(EpsInitialTrafficData queryParam) {
// 获取涉及的表名
Set<String> tableNames = TableRouterUtil.getTableNamesBetweenInitial(queryParam.getStartTime(), queryParam.getEndTime());
// 并行查询各表
return tableNames.parallelStream()
.flatMap(tableName -> {
EpsInitialTrafficData condition = new EpsInitialTrafficData();
condition.setTableName(tableName);
condition.setStartTime(queryParam.getStartTime());
condition.setEndTime(queryParam.getEndTime());
condition.setInterfaceName(queryParam.getInterfaceName());
return epsInitialTrafficDataMapper.getAllTraficMsg(condition).stream();
})
.collect(Collectors.toList());
}
}

View File

@@ -6,6 +6,7 @@ import com.ruoyi.system.domain.EpsNodeBandwidth;
import com.ruoyi.system.mapper.EpsNodeBandwidthMapper;
import com.ruoyi.system.service.EpsInitialTrafficDataService;
import com.ruoyi.system.service.IEpsNodeBandwidthService;
import com.ruoyi.system.util.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -13,8 +14,10 @@ import org.webjars.NotFoundException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.*;
import java.util.Date;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.YearMonth;
import java.util.List;
/**
@@ -60,10 +63,10 @@ public class EpsNodeBandwidthServiceImpl implements IEpsNodeBandwidthService
// 2. 设置查询条件
EpsInitialTrafficData queryParams = new EpsInitialTrafficData();
queryParams.setDeviceSn(epsNodeBandwidth.getHardwareSn());
queryParams.setServiceSn(epsNodeBandwidth.getHardwareSn());
// 3. 根据带宽类型设置时间范围
LocalDateTime createTime = dateToLocalDateTime(epsNodeBandwidth.getCreateTime());
LocalDateTime createTime = DateUtil.dateToLocalDateTime(epsNodeBandwidth.getCreateTime());
setTimeRangeByBandwidthType(queryParams, epsNodeBandwidth.getBandwidthType(), createTime);
// 4. 查询并返回数据
@@ -176,16 +179,6 @@ public class EpsNodeBandwidthServiceImpl implements IEpsNodeBandwidthService
return epsNodeBandwidthMapper.getAvgDetailMsg(epsNodeBandwidth);
}
/**
* Date 类型 转为 LocalDateTime 类型
* @param date
* @return
*/
public static LocalDateTime dateToLocalDateTime(Date date) {
return date.toInstant()
.atZone(ZoneId.systemDefault())
.toLocalDateTime();
}
/**
* 根据带宽类型设置时间范围
*/

View File

@@ -2,14 +2,18 @@ package com.ruoyi.system.service.impl;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.system.domain.EpsInitialTrafficData;
import com.ruoyi.system.domain.EpsMethodChangeRecord;
import com.ruoyi.system.domain.EpsServerRevenueConfig;
import com.ruoyi.system.mapper.EpsServerRevenueConfigMapper;
import com.ruoyi.system.service.EpsInitialTrafficDataService;
import com.ruoyi.system.service.IEpsServerRevenueConfigService;
import com.ruoyi.system.util.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
/**
* 服务器收益方式配置Service业务层处理
@@ -22,6 +26,8 @@ public class EpsServerRevenueConfigServiceImpl implements IEpsServerRevenueConfi
{
@Autowired
private EpsServerRevenueConfigMapper epsServerRevenueConfigMapper;
@Autowired
private EpsInitialTrafficDataService epsInitialTrafficDataService;
/**
* 查询服务器收益方式配置
@@ -78,34 +84,88 @@ public class EpsServerRevenueConfigServiceImpl implements IEpsServerRevenueConfi
// 修改条数
int rows = epsServerRevenueConfigMapper.updateEpsServerRevenueConfig(epsServerRevenueConfig);
if(rows>=0){
EpsMethodChangeRecord epsMethodChangeRecord = new EpsMethodChangeRecord();
// 节点名称
epsMethodChangeRecord.setNodeName(epsServerRevenueConfig.getNodeName());
// 硬件sn
epsMethodChangeRecord.setHardwareSn(epsServerRevenueConfig.getHardwareSn());
// 修改时间
epsMethodChangeRecord.setCreateTime(DateUtils.getNowDate());
// 修改人
epsMethodChangeRecord.setCreatBy(SecurityUtils.getUsername());
// 修改内容
String content = "";
if("流量".equals(nowRevenueMethod)){
// 修改内容
content = "收益方式变为【"+nowRevenueMethod+"】,流量网口设置为"+epsServerRevenueConfig.getTrafficPort()+
",业务为"+epsServerRevenueConfig.getBusinessName();
}
if("包端".equals(nowRevenueMethod)){
// 修改内容
content = "收益方式变为【"+nowRevenueMethod+"】,流量网口设置为"+epsServerRevenueConfig.getTrafficPort()+
",带宽值设置为"+epsServerRevenueConfig.getPackageBandwidth()+"Mbps,"+"业务为"+epsServerRevenueConfig.getBusinessName();
}
epsMethodChangeRecord.setChangeContent(content);
// 添加操作记录
epsServerRevenueConfigMapper.insertEpsServerRevenueConfig(epsServerRevenueConfig);
addRecord(epsServerRevenueConfig);
// 添加包端数据到相关数据表
saveServiceTrafficData(epsServerRevenueConfig);
}
return rows;
}
/**
* 添加服务器配置操作记录
*/
private void addRecord(EpsServerRevenueConfig epsServerRevenueConfig) {
String nowRevenueMethod = getMethodName(epsServerRevenueConfig.getRevenueMethod());
EpsMethodChangeRecord changeRecord = new EpsMethodChangeRecord();
// 设置基本信息
changeRecord.setNodeName(epsServerRevenueConfig.getNodeName());
changeRecord.setHardwareSn(epsServerRevenueConfig.getHardwareSn());
changeRecord.setCreateTime(DateUtils.getNowDate());
changeRecord.setCreatBy(SecurityUtils.getUsername());
// 修改内容
String content = "";
if("流量".equals(nowRevenueMethod)){
// 修改内容
content = "收益方式变为【"+nowRevenueMethod+"】,流量网口设置为"+epsServerRevenueConfig.getTrafficPort()+
",业务为"+epsServerRevenueConfig.getBusinessName();
}
if("包端".equals(nowRevenueMethod)){
// 修改内容
content = "收益方式变为【"+nowRevenueMethod+"】,流量网口设置为"+epsServerRevenueConfig.getTrafficPort()+
",带宽值设置为"+epsServerRevenueConfig.getPackageBandwidth()+"Mbps,"+"业务为"+epsServerRevenueConfig.getBusinessName();
}
changeRecord.setChangeContent(content);
// 添加操作记录
epsServerRevenueConfigMapper.insertEpsServerRevenueConfig(epsServerRevenueConfig);
}
/**
* 保存流量信息
* @param epsServerRevenueConfig
*/
private void saveServiceTrafficData(EpsServerRevenueConfig epsServerRevenueConfig) {
// 查询初始流量数据
EpsInitialTrafficData epsInitialTrafficData = new EpsInitialTrafficData();
epsInitialTrafficData.setServiceSn(epsServerRevenueConfig.getHardwareSn());
epsInitialTrafficData.setBusinessId(epsServerRevenueConfig.getBusinessCode());
epsInitialTrafficData.setBusinessName(epsServerRevenueConfig.getBusinessName());
epsInitialTrafficData.setInterfaceName(epsServerRevenueConfig.getTrafficPort());
epsInitialTrafficData.setPackageBandwidth(epsServerRevenueConfig.getPackageBandwidth());
epsInitialTrafficData.setRevenueMethod(epsServerRevenueConfig.getRevenueMethod());
epsInitialTrafficData.setNodeName(epsServerRevenueConfig.getNodeName());
epsInitialTrafficData.setStartTime(DateUtil.dateToLocalDateTime(epsServerRevenueConfig.getCreateTime()));
epsInitialTrafficData.setEndTime(DateUtil.dateToLocalDateTime(epsServerRevenueConfig.getCreateTime()));
epsInitialTrafficDataService.save(epsInitialTrafficData);
}
/**
* 保存流量信息
* @param epsServerRevenueConfig
*/
@Override
public void autoSaveServiceTrafficData(EpsServerRevenueConfig epsServerRevenueConfig) {
// 查询初始流量数据
EpsInitialTrafficData epsInitialTrafficData = new EpsInitialTrafficData();
epsInitialTrafficData.setStartTime(DateUtil.dateToLocalDateTime(epsServerRevenueConfig.getCreateTime()));
epsInitialTrafficData.setEndTime(DateUtil.dateToLocalDateTime(epsServerRevenueConfig.getCreateTime()));
List<EpsInitialTrafficData> dataList = epsInitialTrafficDataService.getAllTraficMsg(epsInitialTrafficData);
for (EpsInitialTrafficData initialTrafficData : dataList) {
// 根据ip查询节点名称
String ip = initialTrafficData.getIpv4Address();
Map nodeMsg = epsServerRevenueConfigMapper.getNodeMsgByIp(ip);
// 赋值
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") + "");
initialTrafficData.setStartTime(initialTrafficData.getCreateTime());
initialTrafficData.setEndTime(initialTrafficData.getCreateTime());
// 流量相关数据入库
epsInitialTrafficDataService.save(initialTrafficData);
}
}
/**
* 批量删除服务器收益方式配置
*

View File

@@ -0,0 +1,19 @@
package com.ruoyi.system.util;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;
public class DateUtil {
/**
* Date 类型 转为 LocalDateTime 类型
* @param date
* @return
*/
public static LocalDateTime dateToLocalDateTime(Date date) {
return date.toInstant()
.atZone(ZoneId.systemDefault())
.toLocalDateTime();
}
}

View File

@@ -12,7 +12,9 @@ import java.util.Set;
public class TableRouterUtil {
// 表名前缀
private static final String TABLE_PREFIX = "eps_initial_traffic";
private static final String TABLE_PREFIX = "eps_traffic_details";
private static final String TABLE_PREFIX_INITIAL = "initial_bandwidth_traffic";
// 日期格式
private static final DateTimeFormatter YEAR_MONTH_FORMAT =
@@ -42,6 +44,19 @@ public class TableRouterUtil {
yearMonth,
getDayRange(day));
}
public static String getInitialTableName(LocalDateTime createTime) {
if (createTime == null) {
throw new IllegalArgumentException("创建时间不能为null");
}
String yearMonth = createTime.format(YEAR_MONTH_FORMAT);
int day = createTime.getDayOfMonth();
return String.format("%s_%s_%s",
TABLE_PREFIX_INITIAL,
yearMonth,
getDayRange(day));
}
/**
* 获取时间范围内涉及的所有表名
@@ -62,6 +77,25 @@ public class TableRouterUtil {
return tableNames;
}
/**
* 获取时间范围内涉及的所有表名
* @param startTime 开始时间(包含)
* @param endTime 结束时间(包含)
* @return 按时间顺序排列的表名集合
*/
public static Set<String> getTableNamesBetweenInitial(LocalDateTime startTime, LocalDateTime endTime) {
validateTimeRange(startTime, endTime);
Set<String> tableNames = new LinkedHashSet<>();
LocalDateTime current = startTime.withHour(0).withMinute(0).withSecond(0);
while (!current.isAfter(endTime)) {
tableNames.add(getInitialTableName(current));
current = current.plusDays(1);
}
return tableNames;
}
// 获取日期区间

View File

@@ -6,16 +6,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<update id="createEpsTrafficTable">
CREATE TABLE IF NOT EXISTS ${tableName} (
id BIGINT(20) COMMENT '唯一标识ID',
interface_name VARCHAR(50) COMMENT '接口名称',
mac_address VARCHAR(17) COMMENT 'MAC地址',
operation_status VARCHAR(20) COMMENT '运行状态',
interface_type VARCHAR(30) COMMENT '接口类型',
ipv4_address VARCHAR(15) COMMENT 'IPv4地址',
inbound_packet_loss DECIMAL(5,2) COMMENT '入站丢包率(%)',
outbound_packet_loss DECIMAL(5,2) COMMENT '出站丢包率(%)',
receive_bandwidth DECIMAL(10,2) COMMENT '接收带宽(Mbps)',
send_bandwidth DECIMAL(10,2) COMMENT '发送带宽(Mbps)',
id BIGINT(20) AUTO_INCREMENT COMMENT '唯一标识ID',
`name` VARCHAR(100) COMMENT '接口名称',
`mac` VARCHAR(50) COMMENT 'MAC地址',
`status` VARCHAR(20) COMMENT '运行状态',
`type` VARCHAR(30) COMMENT '接口类型',
ipV4 VARCHAR(20) COMMENT 'IPv4地址',
`in_dropped` DECIMAL(5,2) COMMENT '入站丢包率(%)',
`out_dropped` DECIMAL(5,2) COMMENT '出站丢包率(%)',
`in_speed` varchar(20) COMMENT '接收带宽(Mbps)',
`out_speed` varchar(20) COMMENT '发送带宽(Mbps)',
business_id varchar(12) COMMENT '业务代码',
business_name varchar(50) COMMENT '业务名称',
service_sn varchar(50) COMMENT '服务器SN',
@@ -26,75 +26,125 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
create_by VARCHAR(50) COMMENT '创建人',
update_by VARCHAR(50) COMMENT '修改人',
client_id VARCHAR(64) COMMENT '设备唯一标识',
PRIMARY KEY (id),
INDEX idx_name_time (interface_name,create_time),
INDEX idx_name_time (`name`,create_time),
INDEX idx_revenue_method (revenue_method),
INDEX idx_service_sn (service_sn)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='EPS设备流量初始数据表';
</update>
<update id="createEpsInitialTrafficTable">
CREATE TABLE IF NOT EXISTS ${tableName} (
id BIGINT(20) COMMENT '唯一标识ID',
interface_name VARCHAR(50) COMMENT '接口名称',
mac_address VARCHAR(17) COMMENT 'MAC地址',
operation_status VARCHAR(20) COMMENT '运行状态',
interface_type VARCHAR(30) COMMENT '接口类型',
ipv4_address VARCHAR(15) COMMENT 'IPv4地址',
inbound_packet_loss DECIMAL(5,2) COMMENT '入站丢包率(%)',
outbound_packet_loss DECIMAL(5,2) COMMENT '出站丢包率(%)',
receive_bandwidth DECIMAL(10,2) COMMENT '接收带宽(Mbps)',
send_bandwidth DECIMAL(10,2) COMMENT '发送带宽(Mbps)',
id BIGINT(20) AUTO_INCREMENT COMMENT '唯一标识ID',
`name` VARCHAR(100) COMMENT '接口名称',
`mac` VARCHAR(20) COMMENT 'MAC地址',
`status` VARCHAR(20) COMMENT '运行状态',
`type` VARCHAR(30) COMMENT '接口类型',
ipV4 VARCHAR(20) COMMENT 'IPv4地址',
`in_dropped` DECIMAL(5,2) COMMENT '入站丢包率(%)',
`out_dropped` DECIMAL(5,2) COMMENT '出站丢包率(%)',
`in_speed` VARCHAR(20) COMMENT '接收带宽(Mbps)',
`out_speed` VARCHAR(20) COMMENT '发送带宽(Mbps)',
create_time DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
create_by VARCHAR(50) COMMENT '创建人',
update_by VARCHAR(50) COMMENT '修改人',
client_id VARCHAR(64) COMMENT '设备唯一标识',
PRIMARY KEY (id),
INDEX idx_name_time (interface_name,create_time)
INDEX idx_name_time (`name`,create_time)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='初始带宽流量表';
</update>
<!-- 单条插入 -->
<insert id="insert">
INSERT INTO ${tableName} (
receive_traffic,
send_traffic,
device_sn,
interface_name,
mac_address,
operation_status,
interface_type,
ipv4_address,
inbound_packet_loss,
outbound_packet_loss,
receive_bandwidth,
send_bandwidth,
business_id,
traffic_port,
create_time,
remark1, remark2, remark3, remark4
business_name,
service_sn,
node_name,
revenue_method,
package_bandwidth,
create_by,
update_by,
client_id
) VALUES (
#{receiveTraffic},
#{sendTraffic},
#{deviceSn},
#{interfaceName},
#{macAddress},
#{operationStatus},
#{interfaceType},
#{ipv4Address},
#{inboundPacketLoss},
#{outboundPacketLoss},
#{receiveBandwidth},
#{sendBandwidth},
#{businessId},
#{trafficPort},
#{createTime},
#{remark1}, #{remark2},
#{remark3}, #{remark4}
#{businessName},
#{serviceSn},
#{nodeName},
#{revenueMethod},
#{packageBandwidth},
#{createBy},
#{updateBy},
#{clientId}
)
</insert>
<!-- 批量插入 -->
<insert id="batchInsert">
INSERT INTO ${tableName} (
receive_traffic,
send_traffic,
device_sn,
id,
interface_name,
mac_address,
operation_status,
interface_type,
ipv4_address,
inbound_packet_loss,
outbound_packet_loss,
receive_bandwidth,
send_bandwidth,
business_id,
traffic_port,
business_name,
service_sn,
node_name,
revenue_method,
package_bandwidth,
create_time,
remark1, remark2, remark3, remark4
update_time,
create_by,
update_by,
client_id
) VALUES
<foreach collection="dataList" item="data" separator=",">
<foreach collection="list" item="data" separator=",">
(
#{data.receiveTraffic},
#{data.sendTraffic},
#{data.deviceSn},
#{data.businessId},
#{data.trafficPort},
#{data.createTime},
#{data.remark1}, #{data.remark2},
#{data.remark3}, #{data.remark4}
#{data.id,jdbcType=BIGINT},
#{data.interfaceName,jdbcType=VARCHAR},
#{data.macAddress,jdbcType=CHAR},
#{data.operationStatus,jdbcType=VARCHAR},
#{data.interfaceType,jdbcType=VARCHAR},
#{data.ipv4Address,jdbcType=VARCHAR},
#{data.inboundPacketLoss,jdbcType=DECIMAL},
#{data.outboundPacketLoss,jdbcType=DECIMAL},
#{data.receiveBandwidth,jdbcType=DECIMAL},
#{data.sendBandwidth,jdbcType=DECIMAL},
#{data.businessId,jdbcType=CHAR},
#{data.businessName,jdbcType=VARCHAR},
#{data.serviceSn,jdbcType=VARCHAR},
#{data.nodeName,jdbcType=VARCHAR},
#{data.revenueMethod,jdbcType=VARCHAR},
#{data.packageBandwidth,jdbcType=DECIMAL},
#{data.createTime,jdbcType=TIMESTAMP},
#{data.updateTime,jdbcType=TIMESTAMP},
#{data.createBy,jdbcType=VARCHAR},
#{data.updateBy,jdbcType=VARCHAR},
#{data.clientId,jdbcType=VARCHAR}
)
</foreach>
</insert>
@@ -102,18 +152,31 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<!-- 条件查询 -->
<select id="selectByCondition" resultType="EpsInitialTrafficData">
SELECT
id,
receive_traffic as receiveTraffic,
send_traffic as sendTraffic,
device_sn as deviceSn,
business_id as businessId,
traffic_port as trafficPort,
create_time as createTime,
remark1, remark2, remark3, remark4
id,
`name` AS interfaceName,
`mac` AS macAddress,
`status` AS operationStatus,
`type` AS interfaceType,
`ipV4` AS ipv4Address,
`in_dropped` AS inboundPacketLoss,
`out_dropped` AS outboundPacketLoss,
`in_speed` AS receiveBandwidth,
`out_speed` AS sendBandwidth,
business_id AS businessId,
business_name AS businessName,
service_sn AS serviceSn,
node_name AS nodeName,
revenue_method AS revenueMethod,
package_bandwidth AS packageBandwidth,
create_time AS createTime,
update_time AS updateTime,
create_by AS createBy,
update_by AS updateBy,
client_id AS clientId
FROM ${tableName}
<where>
<if test="deviceSn != '' and deviceSn != null">
and device_sn = #{deviceSn}
<if test="serviceSn != '' and serviceSn != null">
and service_sn = #{serviceSn}
</if>
<if test="startTime != null">
and create_time &gt;= #{startTime}
@@ -125,4 +188,35 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</where>
ORDER BY create_time desc
</select>
<!-- 条件查询 -->
<select id="getAllTraficMsg" resultType="EpsInitialTrafficData">
SELECT
id,
`name` AS interfaceName,
`mac` AS macAddress,
`status` AS operationStatus,
`type` AS interfaceType,
`ipV4` AS ipv4Address,
`in_dropped` AS inboundPacketLoss,
`out_dropped` AS outboundPacketLoss,
`in_speed` AS receiveBandwidth,
`out_speed` AS sendBandwidth,
create_time AS createTime,
update_time AS updateTime,
create_by AS createBy,
update_by AS updateBy,
client_id AS clientId
FROM ${tableName}
<where>
<if test="startTime != null">
and create_time &gt;= #{startTime}
</if>
<if test="endTime != null">
and create_time &lt;= #{endTime}
</if>
</where>
ORDER BY create_time desc
</select>
</mapper>

View File

@@ -116,4 +116,23 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#{id}
</foreach>
</delete>
<select id="getNodeMsgByIp" parameterType="String" resultType="java.util.Map">
SELECT
rrr.hardware_sn AS hardwareSn,
rrr.resource_name AS resourceName,
esrc.revenue_method AS revenueMethod,
esrc.business_code AS businessCode,
esrc.business_name AS businessName
FROM
rm_resource_registration rrr
LEFT JOIN
eps_server_revenue_config esrc
ON
rrr.hardware_sn = esrc.hardware_sn
<where>
and rrr.registration_status = '1'
<if test="ipAddress != null and ipAddress != ''"> and rrr.ip_address = #{ipAddress}</if>
</where>
</select>
</mapper>