Browse Source

Merge branch 'feature/dashboard'

* feature/dashboard:
  修复统计结果问题
boweniac 3 months ago
parent
commit
0f2f7be2a3

+ 4 - 4
crontask/compute_statistic.go

@@ -274,11 +274,11 @@ func (l *CronTask) computeStatistic() {
 			for _, hourData := range hourDataBatch {
 				aiResponse += hourData.AiResponse
 				sopRun += hourData.SopRun
-				totalFriend += hourData.TotalFriend
-				totalGroup += hourData.TotalGroup
-				accountBalance += hourData.AccountBalance
+				totalFriend = hourData.TotalFriend
+				totalGroup = hourData.TotalGroup
+				accountBalance = hourData.AccountBalance
 				consumeToken += hourData.ConsumeToken
-				activeUser += hourData.ActiveUser
+				//activeUser += hourData.ActiveUser
 				newUser += hourData.NewUser
 			}
 

+ 1 - 1
internal/logic/dashboard/get_charts_logic.go

@@ -148,7 +148,7 @@ func (l *GetChartsLogic) GetCharts(req *types.ChartsReq) (resp *types.ChartsResp
 			predicates = append(predicates, usagestatistichour.BotID(""))
 		}
 		predicates = append(predicates, usagestatistichour.AddtimeGTE(startAddTime))
-		predicates = append(predicates, usagestatistichour.AddtimeLTE(nextDayAddTime))
+		predicates = append(predicates, usagestatistichour.AddtimeLT(nextDayAddTime))
 		usageStatisticHour, err := l.svcCtx.DB.UsageStatisticHour.Query().Where(predicates...).All(l.ctx)
 		if err != nil {
 			return nil, err

+ 7 - 4
internal/logic/dashboard/get_wxs_logic.go

@@ -4,6 +4,7 @@ import (
 	"context"
 	"fmt"
 	"github.com/suyuan32/simple-admin-common/msg/errormsg"
+	"math"
 	"strconv"
 	"strings"
 	"time"
@@ -112,7 +113,6 @@ func (l *GetWxsLogic) GetWxs(req *types.WxReq) (resp *types.WxResp, err error) {
 			Where(predicatesH...).
 			Order(ent.Desc(usagestatistichour.FieldAddtime)).
 			First(l.ctx)
-		l.Infof("----------------l.svcCtx.DB.UsageStatisticHour 1--------------: %+v", err)
 		if err != nil {
 			return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
 		}
@@ -127,17 +127,18 @@ func (l *GetWxsLogic) GetWxs(req *types.WxReq) (resp *types.WxResp, err error) {
 		predicatesHour = append(predicatesHour, usagestatistichour.BotIDIn(wxIds...))
 		predicatesHour = append(predicatesHour, usagestatistichour.Addtime(lastHourData.Addtime))
 		usageStatisticHour, err := l.svcCtx.DB.UsageStatisticHour.Query().Where(predicatesHour...).Page(l.ctx, req.Page, req.PageSize)
-		l.Infof("----------------l.svcCtx.DB.UsageStatisticHour 2--------------: %+v", err)
 		if err != nil {
 			return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
 		}
 		if usageStatisticHour != nil && usageStatisticHour.List != nil {
+			l.Infof("----------------usageStatisticHour 1--------------: %+v", usageStatisticHour)
 			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)
+						rate = float32(float64(hourData.ActiveUser)) / float32(float64(hourData.TotalFriend))
+						rate = float32(math.Round(float64(rate)*100) / 100)
 					}
 					wxList = append(wxList, types.WxData{
 						Nickname:        wxSet[hourData.BotID].Nickname,
@@ -167,12 +168,14 @@ func (l *GetWxsLogic) GetWxs(req *types.WxReq) (resp *types.WxResp, err error) {
 			return nil, err
 		}
 		if usageStatisticDay != nil && usageStatisticDay.List != nil {
+			l.Infof("----------------usageStatisticDay 2--------------: %+v", usageStatisticDay)
 			resp.Data.Total = usageStatisticDay.PageDetails.Total
 			for _, dayData := range usageStatisticDay.List {
 				if wxSet[dayData.BotID] != nil {
 					rate := float32(0)
 					if dayData.TotalFriend != 0 {
-						rate = float32(dayData.ActiveUser) / float32(dayData.TotalFriend)
+						rate = float32(float64(dayData.ActiveUser)) / float32(float64(dayData.TotalFriend))
+						rate = float32(math.Round(float64(rate)*100) / 100)
 					}
 					wxList = append(wxList, types.WxData{
 						Nickname:        wxSet[dayData.BotID].Nickname,