marge: 合并代码
This commit is contained in:
33
src/modules/monitor/repository/monitor.go
Normal file
33
src/modules/monitor/repository/monitor.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package repository
|
||||
|
||||
import "ems.agt/src/modules/monitor/model"
|
||||
|
||||
// IMonitor 监控服务资源相关信息 数据接口
|
||||
type IMonitor interface {
|
||||
// CreateMonitorBase 创建监控_基本信息
|
||||
CreateMonitorBase(m model.MonitorBase) error
|
||||
|
||||
// DelMonitorBase 删除监控_基本信息
|
||||
DelMonitorBase(ltTime int64) error
|
||||
|
||||
// SelectMonitorBase 查询监控_基本信息
|
||||
SelectMonitorBase(query map[string]any) []model.MonitorBase
|
||||
|
||||
// BatchCreateMonitorIO 批量创建监控_IO
|
||||
BatchCreateMonitorIO(ioList []model.MonitorIO) error
|
||||
|
||||
// DelMonitorIO 删除监控_IO
|
||||
DelMonitorIO(ltTime int64) error
|
||||
|
||||
// SelectMonitorIO 查询监控_IO
|
||||
SelectMonitorIO(query map[string]any) []model.MonitorIO
|
||||
|
||||
// BatchCreateMonitorNet 批量创建监控_网络
|
||||
BatchCreateMonitorNet(netList []model.MonitorNetwork) error
|
||||
|
||||
// DelMonitorNet 删除监控_网络
|
||||
DelMonitorNet(ltTime int64) error
|
||||
|
||||
// SelectMonitorNetwork 查询监控_网络
|
||||
SelectMonitorNetwork(query map[string]any) []model.MonitorNetwork
|
||||
}
|
||||
103
src/modules/monitor/repository/monitor.impl.go
Normal file
103
src/modules/monitor/repository/monitor.impl.go
Normal file
@@ -0,0 +1,103 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"ems.agt/src/framework/datasource"
|
||||
"ems.agt/src/framework/logger"
|
||||
"ems.agt/src/modules/monitor/model"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// 实例化数据层 MonitorImpl 结构体
|
||||
var NewMonitorImpl = &MonitorImpl{
|
||||
db: datasource.DefaultDB,
|
||||
}
|
||||
|
||||
// MonitorImpl 监控服务资源相关信息 数据层处理
|
||||
type MonitorImpl struct {
|
||||
// 数据库实例
|
||||
db func() *gorm.DB
|
||||
}
|
||||
|
||||
// CreateMonitorBase 创建监控_基本信息
|
||||
func (r *MonitorImpl) CreateMonitorBase(m model.MonitorBase) error {
|
||||
return r.db().Create(&m).Error
|
||||
}
|
||||
|
||||
// DelMonitorBase 删除监控_基本信息
|
||||
func (r *MonitorImpl) DelMonitorBase(ltTime int64) error {
|
||||
return r.db().Where("create_time < ?", ltTime).Delete(&model.MonitorBase{}).Error
|
||||
}
|
||||
|
||||
// SelectMonitorBase 查询监控_基本信息
|
||||
func (r *MonitorImpl) SelectMonitorBase(query map[string]any) []model.MonitorBase {
|
||||
var bases []model.MonitorBase
|
||||
dbConn := r.db()
|
||||
if query["neType"] != "" && query["neId"] != "" {
|
||||
dbConn = dbConn.Where("ne_type = ? and ne_id = ?", query["neType"], query["neId"])
|
||||
}
|
||||
dbConn = dbConn.Where("create_time >= ? and create_time <= ?", query["startTime"], query["endTime"])
|
||||
err := dbConn.Order("create_time desc").Find(&bases).Error
|
||||
if err != nil {
|
||||
logger.Errorf("SelectMonitorBase %v", err)
|
||||
return bases
|
||||
}
|
||||
return bases
|
||||
}
|
||||
|
||||
// BatchCreateMonitorIO 批量创建监控_IO
|
||||
func (r *MonitorImpl) BatchCreateMonitorIO(ioList []model.MonitorIO) error {
|
||||
return r.db().CreateInBatches(ioList, len(ioList)).Error
|
||||
}
|
||||
|
||||
// DelMonitorIO 删除监控_IO
|
||||
func (r *MonitorImpl) DelMonitorIO(ltTime int64) error {
|
||||
return r.db().Where("create_time < ?", ltTime).Delete(&model.MonitorIO{}).Error
|
||||
}
|
||||
|
||||
// SelectMonitorIO 查询监控_IO
|
||||
func (r *MonitorImpl) SelectMonitorIO(query map[string]any) []model.MonitorIO {
|
||||
var ios []model.MonitorIO
|
||||
dbConn := r.db()
|
||||
if query["name"] != "" {
|
||||
dbConn = dbConn.Where("name = ?", query["name"])
|
||||
}
|
||||
if query["neType"] != "" && query["neId"] != "" {
|
||||
dbConn = dbConn.Where("ne_type = ? and ne_id = ?", query["neType"], query["neId"])
|
||||
}
|
||||
dbConn = dbConn.Where("create_time >= ? and create_time <= ?", query["startTime"], query["endTime"])
|
||||
err := dbConn.Order("create_time desc").Find(&ios).Error
|
||||
if err != nil {
|
||||
logger.Errorf("SelectMonitorIO %v", err)
|
||||
return ios
|
||||
}
|
||||
return ios
|
||||
}
|
||||
|
||||
// BatchCreateMonitorNet 批量创建监控_网络
|
||||
func (r *MonitorImpl) BatchCreateMonitorNet(netList []model.MonitorNetwork) error {
|
||||
return r.db().CreateInBatches(netList, len(netList)).Error
|
||||
}
|
||||
|
||||
// DelMonitorNet 删除监控_网络
|
||||
func (r *MonitorImpl) DelMonitorNet(ltTime int64) error {
|
||||
return r.db().Where("create_time < ?", ltTime).Delete(&model.MonitorNetwork{}).Error
|
||||
}
|
||||
|
||||
// SelectMonitorNetwork 查询监控_网络
|
||||
func (r *MonitorImpl) SelectMonitorNetwork(query map[string]any) []model.MonitorNetwork {
|
||||
var networks []model.MonitorNetwork
|
||||
dbConn := r.db()
|
||||
if query["name"] != "" {
|
||||
dbConn = dbConn.Where("name = ?", query["name"])
|
||||
}
|
||||
if query["neType"] != "" && query["neId"] != "" {
|
||||
dbConn = dbConn.Where("ne_type = ? and ne_id = ?", query["neType"], query["neId"])
|
||||
}
|
||||
dbConn = dbConn.Where("create_time >= ? and create_time <= ?", query["startTime"], query["endTime"])
|
||||
err := dbConn.Order("create_time desc").Find(&networks).Error
|
||||
if err != nil {
|
||||
logger.Errorf("SelectMonitorNetwork %v", err)
|
||||
return networks
|
||||
}
|
||||
return networks
|
||||
}
|
||||
Reference in New Issue
Block a user