添加用户的信息统计数据获取接口
This commit is contained in:
parent
9c8324547e
commit
1d30dd214d
15
dao/user.go
15
dao/user.go
|
|
@ -173,3 +173,18 @@ func FindUsersDefault() []User {
|
|||
DB.Limit(20).Find(&users)
|
||||
return users
|
||||
}
|
||||
|
||||
// 用户的信息统计数据
|
||||
type UserStatistics struct {
|
||||
SessionCount int64 `json:"session_count" form:"session_count"` //会话数量
|
||||
FileCount int64 `json:"file_count" form:"file_count"` //文件数量
|
||||
MessageCount int64 `json:"message_count" form:"message_count"` //消息数量,提问数量
|
||||
}
|
||||
|
||||
func UserStatisticsData(userID int) UserStatistics {
|
||||
userStatistics := UserStatistics{}
|
||||
DB.Model(&Session{}).Group("user_id").Count(&userStatistics.SessionCount)
|
||||
DB.Model(&File{}).Group("user_id").Count(&userStatistics.FileCount)
|
||||
DB.Model(&Message{}).Where("from_id = ?", userID).Group("from_id").Count(&userStatistics.MessageCount)
|
||||
return userStatistics
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ func SetUpUserGroup(router *gin.Engine) {
|
|||
userGroup.POST("/sync", GetSyncUserInfo)
|
||||
userGroup.POST("/delete", DeleteUser)
|
||||
userGroup.POST("/reset", ResetPassword)
|
||||
userGroup.POST("/statistic", GetUserStatistic)
|
||||
}
|
||||
|
||||
type RLReq struct {
|
||||
|
|
@ -61,6 +62,14 @@ type ResetPasswordReq struct {
|
|||
Code string `json:"code" form:"code"` //验证码
|
||||
}
|
||||
|
||||
func GetUserStatistic(c *gin.Context) {
|
||||
id, _ := c.Get("id")
|
||||
userId := int(id.(float64))
|
||||
//获取数据
|
||||
us := service.GetUserStatistics(userId)
|
||||
c.JSON(200, gin.H{"code": proto.SuccessCode, "message": "success", "data": us})
|
||||
}
|
||||
|
||||
func ResetPassword(c *gin.Context) {
|
||||
var req_data ResetPasswordReq
|
||||
if err := c.ShouldBind(&req_data); err == nil {
|
||||
|
|
|
|||
|
|
@ -417,3 +417,7 @@ func CreateTokenAndSave(user dao.User) (string, error) {
|
|||
// 返回令牌
|
||||
return tokenString, err
|
||||
}
|
||||
|
||||
func GetUserStatistics(userID int) dao.UserStatistics {
|
||||
return dao.UserStatisticsData(userID)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue