package service import ( "github.com/jinzhu/copier" "gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/entity" "gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/vo/request" "gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/vo/response" "gitlab.wodcloud.com/smart-operation/so-operation-api/src/pkg/beagle/jsontime" "xorm.io/xorm" ) type AlertListSvc struct { User entity.SystemUserInfo } func (a *AlertListSvc) Update(session *xorm.Session, req request.UpdateAlertList) error { now := jsontime.Now() data := entity.AlertList{ UpdatedBy: a.User.SystemAccount, UpdatedAt: now, } _ = copier.Copy(&data, &req) _, err := session.Cols("class_name", "updated_by", "updated_at").ID(data.ClassId).Update(&data) if err != nil { return err } return nil } func (a *AlertListSvc) GetDataById(req request.DetailAlertList) (resp response.AlertListItem, err error) { now := jsontime.Now() data := response.AlertListItem{ AlertList: entity.AlertList{ Id: 123, AlertPoint: "容器云/kube-apiserver", AlertRulesId: "762ed641-6c0e-4c39-bf7c-7463abb0f8a2", RiskLevel: 4, AlertTime: now, ClassId: 14, MetricConfigId: "d773b37b-dbb4-4a7b-be11-ab40f8acc00e", CurrentValue: 85, NotificationCount: 3, PushCount: 3, LastPushTime: now, Status: 0, CreatedBy: "admin", CreatedAt: now, UpdatedBy: "admin", UpdatedAt: now, }, AlertCondition: entity.AlertCondition{ ThresholdsMax: 100, ThresholdsMin: 80, RiskLevel: 4, }, } resp = data return } func (a *AlertListSvc) List(req request.ListAlertList) (resp response.AlertListList, err error) { now := jsontime.Now() data1 := response.AlertListItem{ AlertList: entity.AlertList{ Id: 123, AlertPoint: "容器云/kube-apiserver", AlertRulesId: "762ed641-6c0e-4c39-bf7c-7463abb0f8a2", RiskLevel: 4, AlertTime: now, ClassId: 14, MetricConfigId: "d773b37b-dbb4-4a7b-be11-ab40f8acc00e", CurrentValue: 85, NotificationCount: 3, PushCount: 3, LastPushTime: now, Status: 2, CreatedBy: "admin", CreatedAt: now, UpdatedBy: "admin", UpdatedAt: now, }, AlertCondition: entity.AlertCondition{ ThresholdsMax: 100, ThresholdsMin: 80, RiskLevel: 4, }, } data2 := response.AlertListItem{ AlertList: entity.AlertList{ Id: 125, AlertPoint: "容器云/apaas", AlertRulesId: "762ed641-6c0e-4c39-bf7c-7463abb0f8a2", RiskLevel: 3, AlertTime: now, ClassId: 14, MetricConfigId: "d773b37b-dbb4-4a7b-be11-ab40f8acc00e", CurrentValue: 85, NotificationCount: 1, PushCount: 1, LastPushTime: now, Status: 1, CreatedBy: "admin", CreatedAt: now, UpdatedBy: "admin", UpdatedAt: now, }, AlertCondition: entity.AlertCondition{ ThresholdsMax: 80, ThresholdsMin: 50, RiskLevel: 3, }, } resp.List = append(resp.List, data1, data2) resp.TotalCount = int64(len(resp.List)) return }