ref: v3变更,,同步v2.2508.4

This commit is contained in:
TsMask
2025-09-01 11:15:32 +08:00
parent 86dd22c274
commit 382bc311e6
198 changed files with 3768 additions and 3257 deletions

View File

@@ -1,7 +1,6 @@
package repository
import (
"fmt"
"strings"
"time"
@@ -23,17 +22,14 @@ func (r Alarm) SelectByPage(query model.AlarmQuery) ([]model.Alarm, int64) {
if query.NeType != "" {
tx = tx.Where("ne_type = ?", query.NeType)
}
if query.NeID != "" {
tx = tx.Where("ne_id = ?", query.NeID)
if query.NeUID != "" {
tx = tx.Where("ne_uid = ?", query.NeUID)
}
if query.NeName != "" {
tx = tx.Where("ne_name = ?", query.NeName)
}
if query.PvFlag != "" {
tx = tx.Where("pv_flag = ?", query.PvFlag)
if query.CoreUID != "" {
tx = tx.Where("core_uid = ?", query.CoreUID)
}
if query.AlarmCode != "" {
tx = tx.Where("alarm_code like ?", fmt.Sprintf("%%%s%%", query.AlarmCode))
tx = tx.Where("alarm_code = ?", query.AlarmCode)
}
if query.AlarmType != "" {
tx = tx.Where("alarm_type in (?)", strings.Split(query.AlarmType, ","))
@@ -88,11 +84,11 @@ func (r Alarm) Select(param model.Alarm) []model.Alarm {
if param.NeType != "" {
tx = tx.Where("ne_type = ?", param.NeType)
}
if param.NeId != "" {
tx = tx.Where("ne_id = ?", param.NeId)
if param.NeUID != "" {
tx = tx.Where("ne_uid = ?", param.NeUID)
}
if param.NeName != "" {
tx = tx.Where("ne_name = ?", param.NeName)
if param.CoreUID != "" {
tx = tx.Where("core_uid = ?", param.CoreUID)
}
if param.AlarmCode > 0 {
tx = tx.Where("alarm_code = ?", param.AlarmCode)
@@ -107,9 +103,6 @@ func (r Alarm) Select(param model.Alarm) []model.Alarm {
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{}
@@ -139,8 +132,8 @@ func (r Alarm) SelectByIds(ids []int64) []model.Alarm {
// Insert 新增信息 返回新增数据ID
func (r Alarm) Insert(param model.Alarm) int64 {
if param.Timestamp == 0 {
param.Timestamp = time.Now().UnixMilli()
if param.CreatedAt == 0 {
param.CreatedAt = time.Now().UnixMilli()
}
// 执行插入
if err := db.DB("").Create(&param).Error; err != nil {
@@ -158,7 +151,7 @@ func (r Alarm) Update(param model.Alarm) int64 {
tx := db.DB("").Model(&model.Alarm{})
// 构建查询条件
tx = tx.Where("id = ?", param.ID)
tx = tx.Omit("id", "timestamp")
tx = tx.Omit("id", "created_at")
// 执行更新
if err := tx.Updates(param).Error; err != nil {
logger.Errorf("update err => %v", err.Error())
@@ -181,9 +174,9 @@ func (r Alarm) DeleteByIds(ids []int64) int64 {
}
// SelectAlarmSeqLast 查询网元告警最后一条序号
func (r Alarm) SelectAlarmSeqLast(neType, neId string) int64 {
func (r Alarm) SelectAlarmSeqLast(coreUid, neUid string) int64 {
tx := db.DB("").Model(&model.Alarm{})
tx = tx.Where("ne_type=? and ne_id=?", neType, neId)
tx = tx.Where("core_uid=? and ne_uid=?", coreUid, neUid)
tx = tx.Select("alarm_seq").Order("alarm_seq DESC")
// 查询数据
var alarmSeq int64 = 0
@@ -195,10 +188,10 @@ func (r Alarm) SelectAlarmSeqLast(neType, neId string) int64 {
}
// GroupTotal 分组统计
func (r Alarm) GroupTotal(alarmStatus string, group string, limit int) []map[string]any {
func (r Alarm) GroupTotal(coreUid, alarmStatus string, group string, limit int) []map[string]any {
tx := db.DB("").Model(&model.Alarm{})
tx = tx.Select("count(*) as total", group)
tx = tx.Where("alarm_status=?", alarmStatus)
tx = tx.Where("core_uid=? and alarm_status=? ", coreUid, alarmStatus)
tx = tx.Group(group).Order("total DESC")
// 查询数据
var rows []map[string]any = make([]map[string]any, 0)