feat: 补充告警新增新增/确认/清除功能
This commit is contained in:
@@ -2,6 +2,7 @@ package repository
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"be.ems/src/framework/datasource"
|
||||
"be.ems/src/framework/logger"
|
||||
@@ -72,6 +73,45 @@ func (r Alarm) SelectByPage(querys model.AlarmQuery) ([]model.Alarm, int64) {
|
||||
return rows, total
|
||||
}
|
||||
|
||||
// Select 查询集合
|
||||
func (r Alarm) Select(param model.Alarm) []model.Alarm {
|
||||
tx := datasource.DB("").Model(&model.Alarm{})
|
||||
// 查询条件拼接
|
||||
if param.NeType != "" {
|
||||
tx = tx.Where("ne_type = ?", param.NeType)
|
||||
}
|
||||
if param.NeId != "" {
|
||||
tx = tx.Where("ne_id = ?", param.NeId)
|
||||
}
|
||||
if param.NeName != "" {
|
||||
tx = tx.Where("ne_name = ?", param.NeName)
|
||||
}
|
||||
if param.AlarmCode != "" {
|
||||
tx = tx.Where("alarm_code = ?", param.AlarmCode)
|
||||
}
|
||||
if param.AlarmType != "" {
|
||||
tx = tx.Where("alarm_type = ?", param.AlarmType)
|
||||
}
|
||||
if param.AlarmId != "" {
|
||||
tx = tx.Where("alarm_id = ?", param.AlarmId)
|
||||
}
|
||||
if param.OrigSeverity != "" {
|
||||
eventTypes := strings.Split(param.OrigSeverity, ",")
|
||||
tx = tx.Where("orig_severity in (%s)", eventTypes)
|
||||
}
|
||||
if param.PvFlag != "" {
|
||||
tx = tx.Where("pv_flag = ?", param.PvFlag)
|
||||
}
|
||||
|
||||
// 查询数据
|
||||
rows := []model.Alarm{}
|
||||
if err := tx.Find(&rows).Error; err != nil {
|
||||
logger.Errorf("query find err => %v", err.Error())
|
||||
return rows
|
||||
}
|
||||
return rows
|
||||
}
|
||||
|
||||
// SelectByIds 通过ID查询
|
||||
func (r *Alarm) SelectByIds(ids []string) []model.Alarm {
|
||||
rows := []model.Alarm{}
|
||||
@@ -89,8 +129,38 @@ func (r *Alarm) SelectByIds(ids []string) []model.Alarm {
|
||||
return rows
|
||||
}
|
||||
|
||||
// Insert 新增信息 返回新增数据ID
|
||||
func (r Alarm) Insert(param model.Alarm) string {
|
||||
if param.Timestamp.IsZero() {
|
||||
param.Timestamp = time.Now()
|
||||
}
|
||||
// 执行插入
|
||||
if err := datasource.DB("").Create(¶m).Error; err != nil {
|
||||
logger.Errorf("insert err => %v", err.Error())
|
||||
return ""
|
||||
}
|
||||
return param.ID
|
||||
}
|
||||
|
||||
// Update 修改信息 返回受影响的行数
|
||||
func (r Alarm) Update(param model.Alarm) int64 {
|
||||
if param.ID == "" {
|
||||
return 0
|
||||
}
|
||||
tx := datasource.DB("").Model(&model.Alarm{})
|
||||
// 构建查询条件
|
||||
tx = tx.Where("id = ?", param.ID)
|
||||
tx = tx.Omit("id", "timestamp")
|
||||
// 执行更新
|
||||
if err := tx.Updates(param).Error; err != nil {
|
||||
logger.Errorf("update err => %v", err.Error())
|
||||
return 0
|
||||
}
|
||||
return tx.RowsAffected
|
||||
}
|
||||
|
||||
// DeleteByIds 批量删除信息
|
||||
func (r *Alarm) DeleteByIds(ids []string) int64 {
|
||||
func (r Alarm) DeleteByIds(ids []string) int64 {
|
||||
if len(ids) <= 0 {
|
||||
return 0
|
||||
}
|
||||
@@ -101,3 +171,17 @@ func (r *Alarm) DeleteByIds(ids []string) int64 {
|
||||
}
|
||||
return tx.RowsAffected
|
||||
}
|
||||
|
||||
// SelectAlarmSeqLast 查询网元告警最后一条序号
|
||||
func (r Alarm) SelectAlarmSeqLast(neType, neId string) int64 {
|
||||
tx := datasource.DB("").Model(&model.Alarm{})
|
||||
tx = tx.Where("ne_type=? and ne_id=?", neType, neId)
|
||||
tx = tx.Select("alarm_seq").Order("alarm_seq DESC")
|
||||
// 查询数据
|
||||
var alarmSeq int64 = 0
|
||||
if err := tx.Limit(1).Find(&alarmSeq).Error; err != nil {
|
||||
logger.Errorf("query find err => %v", err.Error())
|
||||
return alarmSeq
|
||||
}
|
||||
return alarmSeq
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user