Browse Source

优化看板显示

boweniac 3 months ago
parent
commit
af626a7e7e
1 changed files with 36 additions and 22 deletions
  1. 36 22
      internal/logic/dashboard/get_charts_logic.go

+ 36 - 22
internal/logic/dashboard/get_charts_logic.go

@@ -4,6 +4,7 @@ import (
 	"context"
 	"fmt"
 	"github.com/suyuan32/simple-admin-common/msg/errormsg"
+	"math"
 	"strconv"
 	"time"
 	"wechat-api/ent/custom_types"
@@ -208,19 +209,24 @@ func (l *GetChartsLogic) GetCharts(req *types.ChartsReq) (resp *types.ChartsResp
 		if hourLen > 0 {
 			if usageStatisticHour[0].TotalFriend > 0 {
 				totalFriendRate := float32((float64(usageStatisticHour[hourLen-1].TotalFriend) - float64(usageStatisticHour[0].TotalFriend)) / float64(usageStatisticHour[0].TotalFriend))
-				totalFriend.Rate = &totalFriendRate
+				totalFriendRateRound := float32(math.Round(float64(totalFriendRate)*100) / 100)
+				totalFriend.Rate = &totalFriendRateRound
+				//totalFriend.Rate = &totalFriendRate
 			}
 			if usageStatisticHour[0].TotalGroup > 0 {
 				totalGroupRate := float32((float64(usageStatisticHour[hourLen-1].TotalGroup) - float64(usageStatisticHour[0].TotalGroup)) / float64(usageStatisticHour[0].TotalGroup))
-				totalGroup.Rate = &totalGroupRate
-			}
-			if usageStatisticHour[0].ActiveUser > 0 {
-				activeUserRate := float32((float64(usageStatisticHour[hourLen-1].ActiveUser) - float64(usageStatisticHour[0].ActiveUser)) / float64(usageStatisticHour[0].ActiveUser))
-				activeUser.Rate = &activeUserRate
+				totalGroupRateRound := float32(math.Round(float64(totalGroupRate)*100) / 100)
+				totalGroup.Rate = &totalGroupRateRound
 			}
+			//if usageStatisticHour[0].ActiveUser > 0 {
+			//	activeUserRate := float32((float64(usageStatisticHour[hourLen-1].ActiveUser) - float64(usageStatisticHour[0].ActiveUser)) / float64(usageStatisticHour[0].ActiveUser))
+			//	activeUserRateRound := float32(math.Round(float64(activeUserRate)*100) / 100)
+			//	activeUser.Rate = &activeUserRateRound
+			//}
 			if usageStatisticHour[0].NewUser > 0 {
 				newUserRate := float32((float64(usageStatisticHour[hourLen-1].NewUser) - float64(usageStatisticHour[0].NewUser)) / float64(usageStatisticHour[0].NewUser))
-				newUser.Rate = &newUserRate
+				newUserRateRound := float32(math.Round(float64(newUserRate)*100) / 100)
+				newUser.Rate = &newUserRateRound
 			}
 			labelDists = usageStatisticHour[hourLen-1].LabelDist
 		}
@@ -297,19 +303,23 @@ func (l *GetChartsLogic) GetCharts(req *types.ChartsReq) (resp *types.ChartsResp
 		if dayLen > 0 {
 			if usageStatisticDay[0].TotalFriend > 0 {
 				totalFriendRate := float32((float64(usageStatisticDay[dayLen-1].TotalFriend) - float64(usageStatisticDay[0].TotalFriend)) / float64(usageStatisticDay[0].TotalFriend))
-				totalFriend.Rate = &totalFriendRate
+				totalFriendRateRound := float32(math.Round(float64(totalFriendRate)*100) / 100)
+				totalFriend.Rate = &totalFriendRateRound
 			}
 			if usageStatisticDay[0].TotalGroup > 0 {
 				totalGroupRate := float32((float64(usageStatisticDay[dayLen-1].TotalGroup) - float64(usageStatisticDay[0].TotalGroup)) / float64(usageStatisticDay[0].TotalGroup))
-				totalGroup.Rate = &totalGroupRate
-			}
-			if usageStatisticDay[0].ActiveUser > 0 {
-				activeUserRate := float32((float64(usageStatisticDay[dayLen-1].ActiveUser) - float64(usageStatisticDay[0].ActiveUser)) / float64(usageStatisticDay[0].ActiveUser))
-				activeUser.Rate = &activeUserRate
+				totalGroupRateRound := float32(math.Round(float64(totalGroupRate)*100) / 100)
+				totalGroup.Rate = &totalGroupRateRound
 			}
+			//if usageStatisticDay[0].ActiveUser > 0 {
+			//	activeUserRate := float32((float64(usageStatisticDay[dayLen-1].ActiveUser) - float64(usageStatisticDay[0].ActiveUser)) / float64(usageStatisticDay[0].ActiveUser))
+			//	activeUserRateRound := float32(math.Round(float64(activeUserRate)*100) / 100)
+			//	activeUser.Rate = &activeUserRateRound
+			//}
 			if usageStatisticDay[0].NewUser > 0 {
 				newUserRate := float32((float64(usageStatisticDay[dayLen-1].NewUser) - float64(usageStatisticDay[0].NewUser)) / float64(usageStatisticDay[0].NewUser))
-				newUser.Rate = &newUserRate
+				newUserRateRound := float32(math.Round(float64(newUserRate)*100) / 100)
+				newUser.Rate = &newUserRateRound
 			}
 			labelDists = usageStatisticDay[dayLen-1].LabelDist
 		}
@@ -375,7 +385,8 @@ func (l *GetChartsLogic) GetCharts(req *types.ChartsReq) (resp *types.ChartsResp
 				tfLen := len(totalFriend.Val)
 				if tfLen > 0 && totalFriend.Val[0] > 0 {
 					totalFriendRate := float32((float64(totalFriend.Val[tfLen-1]) - float64(totalFriend.Val[0])) / float64(totalFriend.Val[0]))
-					totalFriend.Rate = &totalFriendRate
+					totalFriendRateRound := float32(math.Round(float64(totalFriendRate)*100) / 100)
+					totalFriend.Rate = &totalFriendRateRound
 				}
 				totalFriend.LabelText = "个"
 
@@ -385,7 +396,8 @@ func (l *GetChartsLogic) GetCharts(req *types.ChartsReq) (resp *types.ChartsResp
 				tgLen := len(totalGroup.Val)
 				if tgLen > 0 && totalGroup.Val[0] > 0 {
 					totalGroupRate := float32((float64(totalGroup.Val[tgLen-1]) - float64(totalGroup.Val[0])) / float64(totalGroup.Val[0]))
-					totalGroup.Rate = &totalGroupRate
+					totalGroupRateRound := float32(math.Round(float64(totalGroupRate)*100) / 100)
+					totalGroup.Rate = &totalGroupRateRound
 				}
 				totalGroup.LabelText = "个"
 
@@ -397,11 +409,12 @@ func (l *GetChartsLogic) GetCharts(req *types.ChartsReq) (resp *types.ChartsResp
 				//activeUser.Count = activeUserOfDay
 				activeUser.Val = append(activeUser.Val, activeUserOfDay)
 				activeUser.Label = append(activeUser.Label, "今日")
-				auLen := len(activeUser.Val)
-				if auLen > 0 && activeUser.Val[0] > 0 {
-					activeUserRate := float32((float64(activeUser.Val[auLen-1]) - float64(activeUser.Val[0])) / float64(activeUser.Val[0]))
-					activeUser.Rate = &activeUserRate
-				}
+				//auLen := len(activeUser.Val)
+				//if auLen > 0 && activeUser.Val[0] > 0 {
+				//	activeUserRate := float32((float64(activeUser.Val[auLen-1]) - float64(activeUser.Val[0])) / float64(activeUser.Val[0]))
+				//	activeUserRateRound := float32(math.Round(float64(activeUserRate)*100) / 100)
+				//	activeUser.Rate = &activeUserRateRound
+				//}
 				activeUser.LabelText = "个"
 
 				newUser.Count = newUserOfDay
@@ -410,7 +423,8 @@ func (l *GetChartsLogic) GetCharts(req *types.ChartsReq) (resp *types.ChartsResp
 				nuLen := len(newUser.Val)
 				if nuLen > 0 && newUser.Val[0] > 0 {
 					newUserRate := float32((float64(newUser.Val[nuLen-1]) - float64(newUser.Val[0])) / float64(newUser.Val[0]))
-					newUser.Rate = &newUserRate
+					newUserRateRound := float32(math.Round(float64(newUserRate)*100) / 100)
+					newUser.Rate = &newUserRateRound
 				}
 				newUser.LabelText = "个"