Просмотр исходного кода

Revert "优化"

This reverts commit e7bd3cf0344d8a0ec7c1c4cf8cb61a4c9aaa0512.
boweniac 3 месяцев назад
Родитель
Сommit
7b6ea385ce
1 измененных файлов с 18 добавлено и 29 удалено
  1. 18 29
      internal/logic/dashboard/get_charts_logic.go

+ 18 - 29
internal/logic/dashboard/get_charts_logic.go

@@ -8,7 +8,6 @@ import (
 	"time"
 	"wechat-api/ent/custom_types"
 	"wechat-api/ent/label"
-	"wechat-api/ent/predicate"
 	"wechat-api/ent/usagestatisticday"
 	"wechat-api/ent/usagestatistichour"
 	"wechat-api/internal/svc"
@@ -45,9 +44,7 @@ func (l *GetChartsLogic) GetCharts(req *types.ChartsReq) (resp *types.ChartsResp
 	var organizationId uint64 = 0
 	isAdmin := l.ctx.Value("isAdmin").(bool)
 	if isAdmin && req.OrganizationId != nil && *req.OrganizationId != 0 {
-		if req.OrganizationId != nil && *req.OrganizationId != 0 {
-			organizationId = *req.OrganizationId
-		}
+		organizationId = *req.OrganizationId
 	} else {
 		organizationId = l.ctx.Value("organizationId").(uint64)
 	}
@@ -116,14 +113,11 @@ func (l *GetChartsLogic) GetCharts(req *types.ChartsReq) (resp *types.ChartsResp
 			fmt.Println("转换开始时间失败:", err)
 			return nil, err
 		}
-
-		var predicates []predicate.UsageStatisticHour
-		if organizationId != 0 {
-			predicates = append(predicates, usagestatistichour.OrganizationID(organizationId))
-		}
-		predicates = append(predicates, usagestatistichour.BotIDIsNil())
-		predicates = append(predicates, usagestatistichour.AddtimeGTE(startAddTime))
-		usageStatisticHour, err := l.svcCtx.DB.UsageStatisticHour.Query().Where(predicates...).All(l.ctx)
+		usageStatisticHour, err := l.svcCtx.DB.UsageStatisticHour.Query().Where(
+			usagestatistichour.OrganizationID(organizationId),
+			usagestatistichour.BotIDIsNil(),
+			usagestatistichour.AddtimeGTE(startAddTime),
+		).All(l.ctx)
 		if err != nil {
 			return nil, err
 		}
@@ -183,15 +177,13 @@ func (l *GetChartsLogic) GetCharts(req *types.ChartsReq) (resp *types.ChartsResp
 			fmt.Println("转换截止时间失败:", err)
 			return nil, err
 		}
-
-		var predicatesDay []predicate.UsageStatisticDay
-		if organizationId != 0 {
-			predicatesDay = append(predicatesDay, usagestatisticday.OrganizationID(organizationId))
-		}
-		predicatesDay = append(predicatesDay, usagestatisticday.BotIDIsNil())
-		predicatesDay = append(predicatesDay, usagestatisticday.AddtimeGTE(startAddTime))
-		predicatesDay = append(predicatesDay, usagestatisticday.AddtimeLTE(endAddTime))
-		usageStatisticDay, err := l.svcCtx.DB.UsageStatisticDay.Query().Where(predicatesDay...).All(l.ctx)
+		usageStatisticDay, err := l.svcCtx.DB.UsageStatisticDay.Query().
+			Where(
+				usagestatisticday.OrganizationID(organizationId),
+				usagestatisticday.BotIDIsNil(),
+				usagestatisticday.AddtimeGTE(startAddTime),
+				usagestatisticday.AddtimeLTE(endAddTime),
+			).All(l.ctx)
 		if err != nil {
 			return nil, err
 		}
@@ -245,14 +237,11 @@ func (l *GetChartsLogic) GetCharts(req *types.ChartsReq) (resp *types.ChartsResp
 				fmt.Println("转换开始时间失败:", err)
 				return nil, err
 			}
-
-			var predicates []predicate.UsageStatisticHour
-			if organizationId != 0 {
-				predicates = append(predicates, usagestatistichour.OrganizationID(organizationId))
-			}
-			predicates = append(predicates, usagestatistichour.BotIDIsNil())
-			predicates = append(predicates, usagestatistichour.AddtimeGTE(startOfDayAddTime))
-			usageStatisticHour, err := l.svcCtx.DB.UsageStatisticHour.Query().Where(predicates...).All(l.ctx)
+			usageStatisticHour, err := l.svcCtx.DB.UsageStatisticHour.Query().Where(
+				usagestatistichour.OrganizationID(organizationId),
+				usagestatistichour.BotIDIsNil(),
+				usagestatistichour.AddtimeGTE(startOfDayAddTime),
+			).All(l.ctx)
 			if err != nil {
 				return nil, err
 			}