75 lines
2.5 KiB
Go
75 lines
2.5 KiB
Go
|
|
package service
|
|
|
|
import (
|
|
"context"
|
|
"github.com/flipped-aurora/gin-vue-admin/server/global"
|
|
"github.com/flipped-aurora/gin-vue-admin/server/plugin/monitor/model"
|
|
"github.com/flipped-aurora/gin-vue-admin/server/plugin/monitor/model/request"
|
|
)
|
|
|
|
var MonitorConfig = new(MC)
|
|
|
|
type MC struct {}
|
|
// CreateMonitorConfig 创建监控配置记录
|
|
// Author [yourname](https://github.com/yourname)
|
|
func (s *MC) CreateMonitorConfig(ctx context.Context, MC *model.MonitorConfig) (err error) {
|
|
err = global.GVA_DB.Create(MC).Error
|
|
return err
|
|
}
|
|
|
|
// DeleteMonitorConfig 删除监控配置记录
|
|
// Author [yourname](https://github.com/yourname)
|
|
func (s *MC) DeleteMonitorConfig(ctx context.Context, ID string) (err error) {
|
|
err = global.GVA_DB.Delete(&model.MonitorConfig{},"id = ?",ID).Error
|
|
return err
|
|
}
|
|
|
|
// DeleteMonitorConfigByIds 批量删除监控配置记录
|
|
// Author [yourname](https://github.com/yourname)
|
|
func (s *MC) DeleteMonitorConfigByIds(ctx context.Context, IDs []string) (err error) {
|
|
err = global.GVA_DB.Delete(&[]model.MonitorConfig{},"id in ?",IDs).Error
|
|
return err
|
|
}
|
|
|
|
// UpdateMonitorConfig 更新监控配置记录
|
|
// Author [yourname](https://github.com/yourname)
|
|
func (s *MC) UpdateMonitorConfig(ctx context.Context, MC model.MonitorConfig) (err error) {
|
|
err = global.GVA_DB.Model(&model.MonitorConfig{}).Where("id = ?",MC.ID).Updates(&MC).Error
|
|
return err
|
|
}
|
|
|
|
// GetMonitorConfig 根据ID获取监控配置记录
|
|
// Author [yourname](https://github.com/yourname)
|
|
func (s *MC) GetMonitorConfig(ctx context.Context, ID string) (MC model.MonitorConfig, err error) {
|
|
err = global.GVA_DB.Where("id = ?", ID).First(&MC).Error
|
|
return
|
|
}
|
|
// GetMonitorConfigInfoList 分页获取监控配置记录
|
|
// Author [yourname](https://github.com/yourname)
|
|
func (s *MC) GetMonitorConfigInfoList(ctx context.Context, info request.MonitorConfigSearch) (list []model.MonitorConfig, total int64, err error) {
|
|
limit := info.PageSize
|
|
offset := info.PageSize * (info.Page - 1)
|
|
// 创建db
|
|
db := global.GVA_DB.Model(&model.MonitorConfig{})
|
|
var MCs []model.MonitorConfig
|
|
// 如果有条件搜索 下方会自动创建搜索语句
|
|
if info.StartCreatedAt !=nil && info.EndCreatedAt !=nil {
|
|
db = db.Where("created_at BETWEEN ? AND ?", info.StartCreatedAt, info.EndCreatedAt)
|
|
}
|
|
err = db.Count(&total).Error
|
|
if err!=nil {
|
|
return
|
|
}
|
|
|
|
if limit != 0 {
|
|
db = db.Limit(limit).Offset(offset)
|
|
}
|
|
err = db.Find(&MCs).Error
|
|
return MCs, total, err
|
|
}
|
|
|
|
func (s *MC)GetMonitorConfigPublic(ctx context.Context) {
|
|
|
|
}
|