boweniac 3 månader sedan
förälder
incheckning
58c0d8377a
2 ändrade filer med 21 tillägg och 10 borttagningar
  1. 11 4
      internal/logic/dashboard/get_charts_logic.go
  2. 10 6
      internal/logic/dashboard/get_wxs_logic.go

+ 11 - 4
internal/logic/dashboard/get_charts_logic.go

@@ -106,20 +106,27 @@ func (l *GetChartsLogic) GetCharts(req *types.ChartsReq) (resp *types.ChartsResp
 	activeUser := types.ChartsUint{}
 	newUser := types.ChartsInt{}
 	var labelDists []custom_types.LabelDist
-	if isCurrentDay && layoutsType == 1 && *req.StartDate == *req.EndDate {
-		// 返回当日每小时的数据
-		startOfDay := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.UTC)
-		startAddTimeString := startOfDay.Format("2006010200")
+	if layoutsType == 1 && *req.StartDate == *req.EndDate {
+		startAddTimeString := startTime.Format("2006010200")
 		startAddTime, err := strconv.ParseUint(startAddTimeString, 10, 64)
 		if err != nil {
 			fmt.Println("转换开始时间失败:", err)
 			return nil, err
 		}
+		
+		nextDayMidnight := time.Date(startTime.Year(), startTime.Month(), startTime.Day()+1, 0, 0, 0, 0, startTime.Location())
+		nextDayMidnightString := nextDayMidnight.Format("2006010200")
+		nextDayAddTime, err := strconv.ParseUint(nextDayMidnightString, 10, 64)
+		if err != nil {
+			fmt.Println("转换次日0点时间失败:", err)
+			return nil, err
+		}
 
 		var predicates []predicate.UsageStatisticHour
 		predicates = append(predicates, usagestatistichour.OrganizationID(organizationId))
 		predicates = append(predicates, usagestatistichour.BotID(""))
 		predicates = append(predicates, usagestatistichour.AddtimeGTE(startAddTime))
+		predicates = append(predicates, usagestatistichour.AddtimeLTE(nextDayAddTime))
 		usageStatisticHour, err := l.svcCtx.DB.UsageStatisticHour.Query().Where(predicates...).All(l.ctx)
 		if err != nil {
 			return nil, err

+ 10 - 6
internal/logic/dashboard/get_wxs_logic.go

@@ -95,7 +95,6 @@ func (l *GetWxsLogic) GetWxs(req *types.WxReq) (resp *types.WxResp, err error) {
 	}
 
 	var wxList []types.WxData
-
 	if isCurrentDay {
 		// 返回当日每小时的数据
 		var predicatesH []predicate.UsageStatisticHour
@@ -128,9 +127,13 @@ func (l *GetWxsLogic) GetWxs(req *types.WxReq) (resp *types.WxResp, err error) {
 			resp.Data.Total = usageStatisticHour.PageDetails.Total
 			for _, hourData := range usageStatisticHour.List {
 				if wxSet[hourData.BotID] != nil {
+					rate := float32(0)
+					if hourData.TotalFriend != 0 {
+						rate = float32(hourData.ActiveUser) / float32(hourData.TotalFriend)
+					}
 					wxList = append(wxList, types.WxData{
 						Nickname:        wxSet[hourData.BotID].Nickname,
-						InteractionRate: float32(hourData.ActiveUser) / float32(hourData.TotalFriend),
+						InteractionRate: rate,
 						TotalFriend:     hourData.TotalFriend,
 						TotalGroup:      hourData.TotalGroup,
 					})
@@ -158,11 +161,11 @@ func (l *GetWxsLogic) GetWxs(req *types.WxReq) (resp *types.WxResp, err error) {
 		if usageStatisticDay != nil && usageStatisticDay.List != nil {
 			resp.Data.Total = usageStatisticDay.PageDetails.Total
 			for _, dayData := range usageStatisticDay.List {
-				rate := float32(0)
-				if dayData.TotalFriend != 0 {
-					rate = float32(dayData.ActiveUser) / float32(dayData.TotalFriend)
-				}
 				if wxSet[dayData.BotID] != nil {
+					rate := float32(0)
+					if dayData.TotalFriend != 0 {
+						rate = float32(dayData.ActiveUser) / float32(dayData.TotalFriend)
+					}
 					wxList = append(wxList, types.WxData{
 						Nickname:        wxSet[dayData.BotID].Nickname,
 						InteractionRate: rate,
@@ -173,6 +176,7 @@ func (l *GetWxsLogic) GetWxs(req *types.WxReq) (resp *types.WxResp, err error) {
 			}
 		}
 	}
+
 	resp.Data.Data = wxList
 
 	return resp, nil