Browse Source

Merge branch 'feature/dashboard' into debug

* feature/dashboard:
  看板增加账号纬度展示 单位改为由接口返回 优化账号统计与展示
boweniac 3 months ago
parent
commit
2000b8417b

+ 4 - 1
crontask/compute_statistic.go

@@ -2,6 +2,7 @@ package crontask
 
 import (
 	"strconv"
+	"strings"
 	"time"
 	"wechat-api/ent"
 	"wechat-api/ent/contact"
@@ -26,7 +27,9 @@ func (l *CronTask) computeStatistic() {
 
 	wxbotsSet := make(map[uint64][]*ent.Wx)
 	for _, bot := range wxbots {
-		wxbotsSet[bot.OrganizationID] = append(wxbotsSet[bot.OrganizationID], bot)
+		if !strings.HasPrefix(bot.Wxid, "temp-") {
+			wxbotsSet[bot.OrganizationID] = append(wxbotsSet[bot.OrganizationID], bot)
+		}
 	}
 	LabelsCountSet := make(map[uint64][]custom_types.LabelDist)
 

+ 4 - 0
desc/wechat/dashboard.api

@@ -12,6 +12,8 @@ type (
 
         // 租户id
         OrganizationId  *uint64 `json:"organizationId,optional"`
+
+        Wxid  *string `json:"wxid,optional"`
     }
     ChartsResp {
         BaseDataInfo
@@ -36,6 +38,7 @@ type (
         Rate float32 `json:"rate"`
         Label []string `json:"label"`
         Val []uint64 `json:"val"`
+        LabelText string `json:"labelText"`
     }
 
     ChartsInt {
@@ -43,6 +46,7 @@ type (
         Rate float32 `json:"rate"`
         Label []string `json:"label"`
         Val []int64 `json:"val"`
+        LabelText string `json:"labelText"`
     }
 
     LabelsData {

+ 1 - 1
internal/logic/Wx/get_select_wx_list_logic.go

@@ -35,7 +35,7 @@ func (l *GetSelectWxListLogic) GetSelectWxList(req *types.WxSelectListReq) (resp
 	if !isAdmin {
 		predicates = append(predicates, wx.OrganizationIDEQ(organizationId))
 	} else {
-		if req.OrganizationId != nil {
+		if req.OrganizationId != nil && *req.OrganizationId != 0 {
 			predicates = append(predicates, wx.OrganizationIDEQ(*req.OrganizationId))
 		}
 	}

+ 37 - 3
internal/logic/dashboard/get_charts_logic.go

@@ -101,6 +101,7 @@ func (l *GetChartsLogic) GetCharts(req *types.ChartsReq) (resp *types.ChartsResp
 	totalFriend := types.ChartsUint{}
 	totalGroup := types.ChartsUint{}
 	accountBalance := types.ChartsUint{}
+	accountBalance.LabelText = "积分"
 	consumeToken := types.ChartsUint{}
 	activeUser := types.ChartsUint{}
 	newUser := types.ChartsInt{}
@@ -123,7 +124,11 @@ func (l *GetChartsLogic) GetCharts(req *types.ChartsReq) (resp *types.ChartsResp
 
 		var predicates []predicate.UsageStatisticHour
 		predicates = append(predicates, usagestatistichour.OrganizationID(organizationId))
-		predicates = append(predicates, usagestatistichour.BotID(""))
+		if req.Wxid != nil {
+			predicates = append(predicates, usagestatistichour.BotID(*req.Wxid))
+		} else {
+			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)
@@ -135,30 +140,37 @@ func (l *GetChartsLogic) GetCharts(req *types.ChartsReq) (resp *types.ChartsResp
 			aiResponse.Count += hourData.AiResponse
 			aiResponse.Val = append(aiResponse.Val, hourData.AiResponse)
 			aiResponse.Label = append(aiResponse.Label, fmt.Sprintf("%02d点", addtimeLastTwoDigits))
+			aiResponse.LabelText = "次"
 
 			sopRun.Count += hourData.SopRun
 			sopRun.Val = append(sopRun.Val, hourData.SopRun)
 			sopRun.Label = append(sopRun.Label, fmt.Sprintf("%02d点", addtimeLastTwoDigits))
+			sopRun.LabelText = "次"
 
 			totalFriend.Count = hourData.TotalFriend
 			totalFriend.Val = append(totalFriend.Val, hourData.TotalFriend)
 			totalFriend.Label = append(totalFriend.Label, fmt.Sprintf("%02d点", addtimeLastTwoDigits))
+			totalFriend.LabelText = "个"
 
 			totalGroup.Count = hourData.TotalGroup
 			totalGroup.Val = append(totalGroup.Val, hourData.TotalGroup)
 			totalGroup.Label = append(totalGroup.Label, fmt.Sprintf("%02d点", addtimeLastTwoDigits))
+			totalGroup.LabelText = "个"
 
 			consumeToken.Count += hourData.ConsumeToken
 			consumeToken.Val = append(consumeToken.Val, hourData.ConsumeToken)
 			consumeToken.Label = append(consumeToken.Label, fmt.Sprintf("%02d点", addtimeLastTwoDigits))
+			consumeToken.LabelText = "token"
 
 			activeUser.Count = hourData.ActiveUser
 			activeUser.Val = append(activeUser.Val, hourData.ActiveUser)
 			activeUser.Label = append(activeUser.Label, fmt.Sprintf("%02d点", addtimeLastTwoDigits))
+			activeUser.LabelText = "个"
 
 			newUser.Count += hourData.NewUser
 			newUser.Val = append(newUser.Val, hourData.NewUser)
 			newUser.Label = append(newUser.Label, fmt.Sprintf("%02d点", addtimeLastTwoDigits))
+			newUser.LabelText = "个"
 		}
 		hourLen := len(usageStatisticHour)
 		if hourLen > 0 {
@@ -193,7 +205,11 @@ func (l *GetChartsLogic) GetCharts(req *types.ChartsReq) (resp *types.ChartsResp
 
 		var predicatesDay []predicate.UsageStatisticDay
 		predicatesDay = append(predicatesDay, usagestatisticday.OrganizationID(organizationId))
-		predicatesDay = append(predicatesDay, usagestatisticday.BotID(""))
+		if req.Wxid != nil {
+			predicatesDay = append(predicatesDay, usagestatisticday.BotID(*req.Wxid))
+		} else {
+			predicatesDay = append(predicatesDay, usagestatisticday.BotID(""))
+		}
 		predicatesDay = append(predicatesDay, usagestatisticday.AddtimeGTE(startAddTime))
 		predicatesDay = append(predicatesDay, usagestatisticday.AddtimeLTE(endAddTime))
 		usageStatisticDay, err := l.svcCtx.DB.UsageStatisticDay.Query().Where(predicatesDay...).All(l.ctx)
@@ -204,30 +220,37 @@ func (l *GetChartsLogic) GetCharts(req *types.ChartsReq) (resp *types.ChartsResp
 			aiResponse.Count = aiResponse.Count + dayData.AiResponse
 			aiResponse.Val = append(aiResponse.Val, dayData.AiResponse)
 			aiResponse.Label = append(aiResponse.Label, fmt.Sprintf("%d", dayData.Addtime))
+			aiResponse.LabelText = "次"
 
 			sopRun.Count += dayData.SopRun
 			sopRun.Val = append(sopRun.Val, dayData.SopRun)
 			sopRun.Label = append(sopRun.Label, fmt.Sprintf("%d", dayData.Addtime))
+			sopRun.LabelText = "次"
 
 			totalFriend.Count = dayData.TotalFriend
 			totalFriend.Val = append(totalFriend.Val, dayData.TotalFriend)
 			totalFriend.Label = append(totalFriend.Label, fmt.Sprintf("%d", dayData.Addtime))
+			totalFriend.LabelText = "个"
 
 			totalGroup.Count = dayData.TotalGroup
 			totalGroup.Val = append(totalGroup.Val, dayData.TotalGroup)
 			totalGroup.Label = append(totalGroup.Label, fmt.Sprintf("%d", dayData.Addtime))
+			totalGroup.LabelText = "个"
 
 			consumeToken.Count += dayData.ConsumeToken
 			consumeToken.Val = append(consumeToken.Val, dayData.ConsumeToken)
 			consumeToken.Label = append(consumeToken.Label, fmt.Sprintf("%d", dayData.Addtime))
+			consumeToken.LabelText = "token"
 
 			activeUser.Count = dayData.ActiveUser
 			activeUser.Val = append(activeUser.Val, dayData.ActiveUser)
 			activeUser.Label = append(activeUser.Label, fmt.Sprintf("%d", dayData.Addtime))
+			activeUser.LabelText = "个"
 
 			newUser.Count += dayData.NewUser
 			newUser.Val = append(newUser.Val, dayData.NewUser)
 			newUser.Label = append(newUser.Label, fmt.Sprintf("%d", dayData.Addtime))
+			newUser.LabelText = "个"
 		}
 		dayLen := len(usageStatisticDay)
 		if dayLen > 0 {
@@ -258,7 +281,11 @@ func (l *GetChartsLogic) GetCharts(req *types.ChartsReq) (resp *types.ChartsResp
 
 			var predicates []predicate.UsageStatisticHour
 			predicates = append(predicates, usagestatistichour.OrganizationID(organizationId))
-			predicates = append(predicates, usagestatistichour.BotID(""))
+			if req.Wxid != nil {
+				predicates = append(predicates, usagestatistichour.BotID(*req.Wxid))
+			} else {
+				predicates = append(predicates, usagestatistichour.BotID(""))
+			}
 			predicates = append(predicates, usagestatistichour.AddtimeGTE(startOfDayAddTime))
 			usageStatisticHour, err := l.svcCtx.DB.UsageStatisticHour.Query().Where(predicates...).All(l.ctx)
 			if err != nil {
@@ -287,10 +314,12 @@ func (l *GetChartsLogic) GetCharts(req *types.ChartsReq) (resp *types.ChartsResp
 				aiResponse.Count = aiResponse.Count + aiResponseOfDay
 				aiResponse.Val = append(aiResponse.Val, aiResponseOfDay)
 				aiResponse.Label = append(aiResponse.Label, "今日")
+				aiResponse.LabelText = "次"
 
 				sopRun.Count = sopRun.Count + sopRunOfDay
 				sopRun.Val = append(sopRun.Val, sopRunOfDay)
 				sopRun.Label = append(sopRun.Label, "今日")
+				sopRun.LabelText = "次"
 
 				totalFriend.Count = totalFriendOfDay
 				totalFriend.Val = append(totalFriend.Val, totalFriendOfDay)
@@ -299,6 +328,7 @@ func (l *GetChartsLogic) GetCharts(req *types.ChartsReq) (resp *types.ChartsResp
 				if tfLen > 0 && totalFriend.Val[0] > 0 {
 					totalFriend.Rate = float32((totalFriend.Val[tfLen-1] - totalFriend.Val[0]) / totalFriend.Val[0])
 				}
+				totalFriend.LabelText = "个"
 
 				totalGroup.Count = totalGroupOfDay
 				totalGroup.Val = append(totalGroup.Val, totalGroupOfDay)
@@ -307,10 +337,12 @@ func (l *GetChartsLogic) GetCharts(req *types.ChartsReq) (resp *types.ChartsResp
 				if tgLen > 0 && totalGroup.Val[0] > 0 {
 					totalGroup.Rate = float32((totalGroup.Val[tgLen-1] - totalGroup.Val[0]) / totalGroup.Val[0])
 				}
+				totalGroup.LabelText = "个"
 
 				consumeToken.Count = consumeToken.Count + consumeTokenOfDay
 				consumeToken.Val = append(consumeToken.Val, consumeTokenOfDay)
 				consumeToken.Label = append(consumeToken.Label, "今日")
+				consumeToken.LabelText = "token"
 
 				activeUser.Count = activeUserOfDay
 				activeUser.Val = append(activeUser.Val, activeUserOfDay)
@@ -319,6 +351,7 @@ func (l *GetChartsLogic) GetCharts(req *types.ChartsReq) (resp *types.ChartsResp
 				if auLen > 0 && activeUser.Val[0] > 0 {
 					activeUser.Rate = float32((activeUser.Val[auLen-1] - activeUser.Val[0]) / activeUser.Val[0])
 				}
+				activeUser.LabelText = "个"
 
 				newUser.Count = newUserOfDay
 				newUser.Val = append(newUser.Val, newUserOfDay)
@@ -327,6 +360,7 @@ func (l *GetChartsLogic) GetCharts(req *types.ChartsReq) (resp *types.ChartsResp
 				if nuLen > 0 && newUser.Val[0] > 0 {
 					newUser.Rate = float32((newUser.Val[nuLen-1] - newUser.Val[0]) / newUser.Val[0])
 				}
+				newUser.LabelText = "个"
 
 				labelDists = usageStatisticHour[hourLen-1].LabelDist
 			}

+ 5 - 2
internal/logic/dashboard/get_wxs_logic.go

@@ -5,6 +5,7 @@ import (
 	"fmt"
 	"github.com/suyuan32/simple-admin-common/msg/errormsg"
 	"strconv"
+	"strings"
 	"time"
 	"wechat-api/ent"
 	"wechat-api/ent/predicate"
@@ -90,8 +91,10 @@ func (l *GetWxsLogic) GetWxs(req *types.WxReq) (resp *types.WxResp, err error) {
 	var wxIds []string
 	wxSet := make(map[string]*ent.Wx)
 	for _, w := range wxs {
-		wxIds = append(wxIds, w.Wxid)
-		wxSet[w.Wxid] = w
+		if !strings.HasPrefix(w.Wxid, "temp-") {
+			wxIds = append(wxIds, w.Wxid)
+			wxSet[w.Wxid] = w
+		}
 	}
 
 	var wxList []types.WxData

+ 11 - 8
internal/types/types.go

@@ -3126,6 +3126,7 @@ type ChartsReq struct {
 	EndDate   *string `json:"end_date"`
 	// 租户id
 	OrganizationId *uint64 `json:"organizationId,optional"`
+	Wxid           *string `json:"wxid,optional"`
 }
 
 // swagger:model ChartsResp
@@ -3147,17 +3148,19 @@ type ChartsData struct {
 }
 
 type ChartsUint struct {
-	Count uint64   `json:"count"`
-	Rate  float32  `json:"rate"`
-	Label []string `json:"label"`
-	Val   []uint64 `json:"val"`
+	Count     uint64   `json:"count"`
+	Rate      float32  `json:"rate"`
+	Label     []string `json:"label"`
+	Val       []uint64 `json:"val"`
+	LabelText string   `json:"labelText"`
 }
 
 type ChartsInt struct {
-	Count int64    `json:"count"`
-	Rate  float32  `json:"rate"`
-	Label []string `json:"label"`
-	Val   []int64  `json:"val"`
+	Count     int64    `json:"count"`
+	Rate      float32  `json:"rate"`
+	Label     []string `json:"label"`
+	Val       []int64  `json:"val"`
+	LabelText string   `json:"labelText"`
 }
 
 type LabelsData struct {