添加基础统计信息数据
This commit is contained in:
parent
77777ceff2
commit
56229303a4
30
dao/im.go
30
dao/im.go
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
"log"
|
"log"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Session struct {
|
type Session struct {
|
||||||
|
|
@ -133,3 +134,32 @@ func FindSessionMessageCountByUserID(userID int) []SessionMessageCount {
|
||||||
}
|
}
|
||||||
return sessionMessageCounts
|
return sessionMessageCounts
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取会话数,问答数,今日问答数
|
||||||
|
func FindBaseSessionMessageStatisticsInfo() (int64, int64, int64, error) {
|
||||||
|
//所有会话数
|
||||||
|
var sessionCount int64
|
||||||
|
var messageCount int64
|
||||||
|
var todayMessageCount int64
|
||||||
|
today := time.Now().Truncate(24 * time.Hour)
|
||||||
|
var db2 *gorm.DB
|
||||||
|
if proto.Config.SERVER_SQL_LOG {
|
||||||
|
db2 = DB.Debug()
|
||||||
|
} else {
|
||||||
|
db2 = DB
|
||||||
|
}
|
||||||
|
|
||||||
|
// 查询会话数量
|
||||||
|
if err := db2.Model(&Session{}).Count(&sessionCount).Error; err != nil {
|
||||||
|
return 0, 0, 0, err
|
||||||
|
}
|
||||||
|
// 查询消息数量
|
||||||
|
if err := db2.Model(&Message{}).Count(&messageCount).Error; err != nil {
|
||||||
|
return 0, 0, 0, err
|
||||||
|
}
|
||||||
|
// 查询今天的消息数量
|
||||||
|
if err := db2.Model(&Message{}).Where("created_at > ?", today).Count(&todayMessageCount).Error; err != nil {
|
||||||
|
return 0, 0, 0, err
|
||||||
|
}
|
||||||
|
return sessionCount, messageCount, todayMessageCount, nil
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -188,3 +188,9 @@ func UserStatisticsData(userID int) UserStatistics {
|
||||||
DB.Model(&Message{}).Where("from_id = ?", userID).Count(&userStatistics.MessageCount)
|
DB.Model(&Message{}).Where("from_id = ?", userID).Count(&userStatistics.MessageCount)
|
||||||
return userStatistics
|
return userStatistics
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func FindUserNum() int64 {
|
||||||
|
var count int64
|
||||||
|
DB.Model(&User{}).Count(&count)
|
||||||
|
return count
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,7 @@ func SetUpToolGroup(router *gin.Engine) {
|
||||||
toolGroup.POST("/monitor", SetDeviceStatusV2)
|
toolGroup.POST("/monitor", SetDeviceStatusV2)
|
||||||
//发送邮件
|
//发送邮件
|
||||||
toolGroup.POST("/send_mail", SendMailTool)
|
toolGroup.POST("/send_mail", SendMailTool)
|
||||||
|
toolGroup.POST("/dashboard", DashBoardStatistics)
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetDeviceStatusV2(c *gin.Context) {
|
func SetDeviceStatusV2(c *gin.Context) {
|
||||||
|
|
@ -403,3 +404,12 @@ func SendMailTool(c *gin.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func DashBoardStatistics(c *gin.Context) {
|
||||||
|
//用户统计信息
|
||||||
|
rbase := service.GetBaseDashboardInfo()
|
||||||
|
var resp proto.DashBoardStatisticsResp
|
||||||
|
resp.DashBoardStatisticsSt = rbase
|
||||||
|
c.JSON(http.StatusOK, gin.H{"code": proto.SuccessCode, "message": "success", "data": resp})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
package proto
|
||||||
|
|
||||||
|
// 基础统计信息,会话数,问答数,用户数,今日处理问答数
|
||||||
|
type DashBoardStatisticsSt struct {
|
||||||
|
SessionNum int64 `json:"session_num"`
|
||||||
|
MessageCount int64 `json:"message_count"`
|
||||||
|
UserCount int64 `json:"user_count"`
|
||||||
|
TodayMessageCount int64 `json:"today_message_count"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type DashBoardStatisticsResp struct {
|
||||||
|
DashBoardStatisticsSt DashBoardStatisticsSt `json:"dashboard_statistics_st"`
|
||||||
|
}
|
||||||
|
|
@ -1,9 +1,11 @@
|
||||||
package service
|
package service
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"StuAcaWorksAI/dao"
|
||||||
"StuAcaWorksAI/proto"
|
"StuAcaWorksAI/proto"
|
||||||
"StuAcaWorksAI/worker"
|
"StuAcaWorksAI/worker"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"regexp"
|
"regexp"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
@ -113,3 +115,16 @@ func CheckEmail(email string) bool {
|
||||||
reg := regexp.MustCompile(pattern)
|
reg := regexp.MustCompile(pattern)
|
||||||
return reg.MatchString(email)
|
return reg.MatchString(email)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取基础信息统计信息
|
||||||
|
func GetBaseDashboardInfo() proto.DashBoardStatisticsSt {
|
||||||
|
var res proto.DashBoardStatisticsSt
|
||||||
|
var err error
|
||||||
|
res.SessionNum, res.MessageCount, res.TodayMessageCount, err = dao.FindBaseSessionMessageStatisticsInfo()
|
||||||
|
if err != nil {
|
||||||
|
log.Println("get base dashboard info error:", err)
|
||||||
|
}
|
||||||
|
// 获取用户数
|
||||||
|
res.UserCount = dao.FindUserNum()
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue