Browse Source

调整/events/nums, app_ids参数改为 app_aliases

路佳明 3 months ago
parent
commit
36544a92aa
2 changed files with 14 additions and 4 deletions
  1. 6 1
      app/observe/service/dto/event.go
  2. 8 3
      app/observe/service/event.go

+ 6 - 1
app/observe/service/dto/event.go

@@ -25,7 +25,8 @@ type EventListResp struct {
 // }
 
 type EventExceptionNumsReq struct {
-	AppIds string `form:"app_ids"`
+	AppIds     string `form:"app_ids"`
+	AppAliases string `form:"app_aliases"`
 	models.TimeRange
 	dto.Pagination
 }
@@ -34,6 +35,10 @@ func (r *EventExceptionNumsReq) GetAppIds() []string {
 	return strings.Split(r.AppIds, ",")
 }
 
+func (r *EventExceptionNumsReq) GetAppAliases() []string {
+	return strings.Split(r.AppAliases, ",")
+}
+
 type EventExceptionNumsResp struct {
 	AppId        int64  `json:"app_id"`
 	AppName      string `json:"app_name"`

+ 8 - 3
app/observe/service/event.go

@@ -63,9 +63,14 @@ func (e *Event) ExceptionNums(c *dto.EventExceptionNumsReq, result *[]dto.EventE
 	if c.EndTime > 0 {
 		db.Where("created_at<?", time.Unix(c.EndTime, 0).Format(time.DateTime))
 	}
-	appIds := c.GetAppIds()
-	if len(appIds) > 0 {
-		db.Where("app_id IN ?", appIds)
+	appAliases := c.GetAppAliases()
+	if len(appAliases) > 0 {
+		db.Where("app_alias in ?", appAliases)
+	} else { // 兼容旧逻辑, 后期去掉
+		appIds := c.GetAppIds()
+		if len(appIds) > 0 {
+			db.Where("app_id IN ?", appIds)
+		}
 	}
 	if err := db.Group("app_id").Find(result).Count(count).Error; err != nil {
 		return errors.Wrap(err, "执行查询应用异常数量失败")