@@ -8,7 +8,9 @@ import ( | |||||
"code.fnuoos.com/EggPlanet/egg_models.git/src/implement" | "code.fnuoos.com/EggPlanet/egg_models.git/src/implement" | ||||
"code.fnuoos.com/EggPlanet/egg_models.git/src/model" | "code.fnuoos.com/EggPlanet/egg_models.git/src/model" | ||||
"errors" | "errors" | ||||
"fmt" | |||||
"github.com/gin-gonic/gin" | "github.com/gin-gonic/gin" | ||||
"strconv" | |||||
"time" | "time" | ||||
) | ) | ||||
@@ -549,10 +551,10 @@ func AddCommunityDividendsWithUser(c *gin.Context) { | |||||
// @Accept json | // @Accept json | ||||
// @Produce json | // @Produce json | ||||
// @param Authorization header string true "验证参数Bearer和token空格拼接" | // @param Authorization header string true "验证参数Bearer和token空格拼接" | ||||
// @Param req body md.UserDailyActivityAnalysisReq true "用户 ID、查询开始时间、结束时间" | |||||
// @Param req body md.UserDailyActivityAnalysisReq true "用户 ID、查询开始时间、结束时间(查询时间不超过30天)、页数、每页大小" | |||||
// @Success 200 {object} md.UserDailyActivityAnalysisResp "具体数据" | // @Success 200 {object} md.UserDailyActivityAnalysisResp "具体数据" | ||||
// @Failure 400 {object} md.Response "具体错误" | // @Failure 400 {object} md.Response "具体错误" | ||||
// @Router /api/institutionalManagement/publicPlatoon/userDailyActivityAnalysis [post] | |||||
// @Router /api/institutionalManagement/publicPlatoon/userDailyActivityAnalysis/index [post] | |||||
func UserDailyActivityAnalysis(c *gin.Context) { | func UserDailyActivityAnalysis(c *gin.Context) { | ||||
var req *md.UserDailyActivityAnalysisReq | var req *md.UserDailyActivityAnalysisReq | ||||
if err := c.ShouldBindJSON(&req); err != nil { | if err := c.ShouldBindJSON(&req); err != nil { | ||||
@@ -570,14 +572,46 @@ func UserDailyActivityAnalysis(c *gin.Context) { | |||||
return | return | ||||
} | } | ||||
activityUserCount, activityCount, sons, err := svc.GetSonUserDailyActivity(db.Db, req.Uid, req.StartDate, req.EndDate) | |||||
total, sons, err := svc.GetSonUserDailyActivity(db.Db, req.Uid, req.StartDate, req.EndDate, req.Page, req.PageSize) | |||||
if err != nil { | if err != nil { | ||||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | e.OutErr(c, e.ERR_DB_ORM, err.Error()) | ||||
return | return | ||||
} | } | ||||
sql1 := "SELECT COUNT(*) AS total, uid FROM `egg_enery_user_activity` WHERE uid IN (SELECT uid FROM `user_relate` WHERE parent_uid = ?) GROUP BY uid" | |||||
res1, err := db.Db.QueryInterface(sql1, parentRelation.Uid) | |||||
if err != nil { | |||||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||||
return | |||||
} | |||||
var activityUserCount int64 | |||||
for _, value := range res1 { | |||||
tempCount, err := strconv.ParseInt(fmt.Sprintf("%v", value), 10, 64) | |||||
if err != nil { | |||||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||||
} | |||||
activityUserCount += tempCount | |||||
} | |||||
sql2 := "SELECT COUNT(1) AS total FROM `egg_enery_user_activity` WHERE uid IN (SELECT uid FROM `user_relate` WHERE parent_uid = ?)" | |||||
res2, err := db.Db.QueryInterface(sql2, parentRelation.Uid) | |||||
if err != nil { | |||||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||||
return | |||||
} | |||||
var activityCount int64 | |||||
for _, value := range res2 { | |||||
tempCount, err := strconv.ParseInt(fmt.Sprintf("%v", value), 10, 64) | |||||
if err != nil { | |||||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||||
} | |||||
activityCount += tempCount | |||||
} | |||||
topData := md.DailyActivityAnalysisTopData{ | topData := md.DailyActivityAnalysisTopData{ | ||||
TeamUserCount: parentRelation.HasSonNum, | |||||
TeamUserCount: total, | |||||
TeamActivityUserCount: activityUserCount, | TeamActivityUserCount: activityUserCount, | ||||
ActivityCount: activityCount, | ActivityCount: activityCount, | ||||
} | } | ||||
@@ -105,6 +105,8 @@ type UserDailyActivityAnalysisReq struct { | |||||
Uid int64 `json:"uid,required"` // 查询用户 ID | Uid int64 `json:"uid,required"` // 查询用户 ID | ||||
StartDate string `json:"start_date,required" example:"开始日期"` | StartDate string `json:"start_date,required" example:"开始日期"` | ||||
EndDate string `json:"end_date,required" example:"结束日期"` | EndDate string `json:"end_date,required" example:"结束日期"` | ||||
Page int `json:"page,required"` // 页数 | |||||
PageSize int `json:"page_size,required"` // 每页大小 | |||||
} | } | ||||
type SonUserDailyActivityAnalysisNode struct { | type SonUserDailyActivityAnalysisNode struct { | ||||
@@ -115,7 +117,7 @@ type SonUserDailyActivityAnalysisNode struct { | |||||
} | } | ||||
type DailyActivityAnalysisTopData struct { | type DailyActivityAnalysisTopData struct { | ||||
TeamUserCount int `json:"team_user_count"` // 团队人数 | |||||
TeamUserCount int64 `json:"team_user_count"` // 团队人数 | |||||
TeamActivityUserCount int64 `json:"team_activity_user_count"` // 子节点活跃人数 | TeamActivityUserCount int64 `json:"team_activity_user_count"` // 子节点活跃人数 | ||||
ActivityCount int64 `json:"activity_count"` // 子节点活跃天数 | ActivityCount int64 `json:"activity_count"` // 子节点活跃天数 | ||||
} | } | ||||
@@ -78,7 +78,7 @@ func rInstitutionalManagement(r *gin.RouterGroup) { //制度管理 | |||||
} | } | ||||
rUserDailyActivityAnalysis := rPublicPlatoon.Group("/userDailyActivityAnalysis") | rUserDailyActivityAnalysis := rPublicPlatoon.Group("/userDailyActivityAnalysis") | ||||
{ | { | ||||
rUserDailyActivityAnalysis.POST("", public_platoon.UserDailyActivityAnalysis) | |||||
rUserDailyActivityAnalysis.POST("/index", public_platoon.UserDailyActivityAnalysis) | |||||
} | } | ||||
} | } | ||||
@@ -2,10 +2,12 @@ package svc | |||||
import ( | import ( | ||||
md "applet/app/md/institutional_management/public_platoon" | md "applet/app/md/institutional_management/public_platoon" | ||||
"applet/app/utils" | |||||
"code.fnuoos.com/EggPlanet/egg_models.git/src/implement" | "code.fnuoos.com/EggPlanet/egg_models.git/src/implement" | ||||
"code.fnuoos.com/EggPlanet/egg_models.git/src/model" | "code.fnuoos.com/EggPlanet/egg_models.git/src/model" | ||||
zhios_order_relate_logx "code.fnuoos.com/EggPlanet/egg_models.git/utils/logx" | zhios_order_relate_logx "code.fnuoos.com/EggPlanet/egg_models.git/utils/logx" | ||||
"fmt" | "fmt" | ||||
"strconv" | |||||
"xorm.io/xorm" | "xorm.io/xorm" | ||||
) | ) | ||||
@@ -146,44 +148,48 @@ func ExchangeUserPosition(engine *xorm.Engine, relation1, relation2 *model.Publi | |||||
return nil | return nil | ||||
} | } | ||||
func GetSonUserDailyActivity(engine *xorm.Engine, fatherUID int64, startDate, endDate string) (activityUserCount int64, activityCount int64, sons []md.SonUserDailyActivityAnalysisNode, err error) { | |||||
func GetSonUserDailyActivity(engine *xorm.Engine, fatherUID int64, startDate, endDate string, page, pageSize int) (total int64, sons []md.SonUserDailyActivityAnalysisNode, err error) { | |||||
relationDb := implement.NewUserRelateDb(engine) | relationDb := implement.NewUserRelateDb(engine) | ||||
sonRelations, err := relationDb.FindUserRelateByParentUid(fatherUID, 1) | |||||
sonRelations, total, err := relationDb.PageFindUserRelateByParentUid(fatherUID, page, pageSize) | |||||
if err != nil { | if err != nil { | ||||
return 0, 0, nil, err | |||||
return 0, nil, zhios_order_relate_logx.Error(err) | |||||
} | } | ||||
if sonRelations == nil { | if sonRelations == nil { | ||||
return 0, 0, nil, nil | |||||
return 0, nil, nil | |||||
} | } | ||||
userIDs := make([]int64, 0) | userIDs := make([]int64, 0) | ||||
for _, relation := range *sonRelations { | for _, relation := range *sonRelations { | ||||
userIDs = append(userIDs, relation.Uid) | userIDs = append(userIDs, relation.Uid) | ||||
} | } | ||||
activityDb := implement.NewEggEnergyUserActivityDb(engine) | |||||
// 先判断这些用户中是否有活跃用户,如果有再逐个统计 | |||||
activityCount, err = activityDb.UserDailyActivityAnalysisCountByUidAndTime(startDate, endDate, userIDs...) | |||||
userDb := implement.NewUserDb(engine) | |||||
users, err := userDb.UserFindByParams(map[string]interface{}{ | |||||
"key": "id", | |||||
"value": userIDs, | |||||
}) | |||||
if err != nil { | if err != nil { | ||||
return 0, 0, nil, zhios_order_relate_logx.Error(err) | |||||
return 0, nil, zhios_order_relate_logx.Error(err) | |||||
} | } | ||||
if activityCount == 0 { | |||||
return 0, 0, nil, nil | |||||
sql1 := "SELECT COUNT(*) AS total, uid FROM `egg_enery_user_activity` WHERE uid IN ? AND date > ? AND date < ? GROUP BY uid" | |||||
res, err := engine.QueryInterface(sql1, utils.AnyToString(userIDs), startDate, endDate) | |||||
if err != nil { | |||||
return 0, nil, zhios_order_relate_logx.Error(err) | |||||
} | } | ||||
sons = make([]md.SonUserDailyActivityAnalysisNode, 0) | sons = make([]md.SonUserDailyActivityAnalysisNode, 0) | ||||
for _, userID := range userIDs { | |||||
count, err := activityDb.UserDailyActivityAnalysisCountByUidAndTime(startDate, endDate, userID) | |||||
for _, user := range users { | |||||
value := res[user.Id] | |||||
activityDayNums, err := strconv.ParseInt(fmt.Sprintf("%v", value), 10, 64) | |||||
if err != nil { | if err != nil { | ||||
return 0, 0, nil, err | |||||
return 0, nil, zhios_order_relate_logx.Error(err) | |||||
} | } | ||||
if count > 0 { | |||||
sons = append(sons, md.SonUserDailyActivityAnalysisNode{ | |||||
Uid: userID, | |||||
Nickname: "", | |||||
Phone: "", | |||||
ActivityDayNums: count, | |||||
}) | |||||
activityUserCount++ | |||||
} | |||||
} | |||||
return activityUserCount, activityCount, sons, nil | |||||
sons = append(sons, md.SonUserDailyActivityAnalysisNode{ | |||||
Uid: user.Id, | |||||
Nickname: user.Nickname, | |||||
Phone: user.Phone, | |||||
ActivityDayNums: activityDayNums, | |||||
}) | |||||
} | |||||
return total, sons, nil | |||||
} | } |
@@ -711,7 +711,7 @@ const docTemplate = `{ | |||||
} | } | ||||
} | } | ||||
}, | }, | ||||
"/api/institutionalManagement/publicPlatoon/userDailyActivityAnalysis": { | |||||
"/api/institutionalManagement/publicPlatoon/userDailyActivityAnalysis/index": { | |||||
"post": { | "post": { | ||||
"description": "日活分析", | "description": "日活分析", | ||||
"consumes": [ | "consumes": [ | ||||
@@ -733,7 +733,7 @@ const docTemplate = `{ | |||||
"required": true | "required": true | ||||
}, | }, | ||||
{ | { | ||||
"description": "用户 ID、查询开始时间、结束时间", | |||||
"description": "用户 ID、查询开始时间、结束时间(查询时间不超过30天)、页数、每页大小", | |||||
"name": "req", | "name": "req", | ||||
"in": "body", | "in": "body", | ||||
"required": true, | "required": true, | ||||
@@ -1514,6 +1514,14 @@ const docTemplate = `{ | |||||
"type": "string", | "type": "string", | ||||
"example": "结束日期" | "example": "结束日期" | ||||
}, | }, | ||||
"page": { | |||||
"description": "页数", | |||||
"type": "integer" | |||||
}, | |||||
"page_size": { | |||||
"description": "每页大小", | |||||
"type": "integer" | |||||
}, | |||||
"start_date": { | "start_date": { | ||||
"type": "string", | "type": "string", | ||||
"example": "开始日期" | "example": "开始日期" | ||||
@@ -704,7 +704,7 @@ | |||||
} | } | ||||
} | } | ||||
}, | }, | ||||
"/api/institutionalManagement/publicPlatoon/userDailyActivityAnalysis": { | |||||
"/api/institutionalManagement/publicPlatoon/userDailyActivityAnalysis/index": { | |||||
"post": { | "post": { | ||||
"description": "日活分析", | "description": "日活分析", | ||||
"consumes": [ | "consumes": [ | ||||
@@ -726,7 +726,7 @@ | |||||
"required": true | "required": true | ||||
}, | }, | ||||
{ | { | ||||
"description": "用户 ID、查询开始时间、结束时间", | |||||
"description": "用户 ID、查询开始时间、结束时间(查询时间不超过30天)、页数、每页大小", | |||||
"name": "req", | "name": "req", | ||||
"in": "body", | "in": "body", | ||||
"required": true, | "required": true, | ||||
@@ -1507,6 +1507,14 @@ | |||||
"type": "string", | "type": "string", | ||||
"example": "结束日期" | "example": "结束日期" | ||||
}, | }, | ||||
"page": { | |||||
"description": "页数", | |||||
"type": "integer" | |||||
}, | |||||
"page_size": { | |||||
"description": "每页大小", | |||||
"type": "integer" | |||||
}, | |||||
"start_date": { | "start_date": { | ||||
"type": "string", | "type": "string", | ||||
"example": "开始日期" | "example": "开始日期" | ||||
@@ -491,6 +491,12 @@ definitions: | |||||
end_date: | end_date: | ||||
example: 结束日期 | example: 结束日期 | ||||
type: string | type: string | ||||
page: | |||||
description: 页数 | |||||
type: integer | |||||
page_size: | |||||
description: 每页大小 | |||||
type: integer | |||||
start_date: | start_date: | ||||
example: 开始日期 | example: 开始日期 | ||||
type: string | type: string | ||||
@@ -1028,7 +1034,7 @@ paths: | |||||
summary: 制度中心-公排管理-公排基础设置(修改) | summary: 制度中心-公排管理-公排基础设置(修改) | ||||
tags: | tags: | ||||
- 公排管理 | - 公排管理 | ||||
/api/institutionalManagement/publicPlatoon/userDailyActivityAnalysis: | |||||
/api/institutionalManagement/publicPlatoon/userDailyActivityAnalysis/index: | |||||
post: | post: | ||||
consumes: | consumes: | ||||
- application/json | - application/json | ||||
@@ -1039,7 +1045,7 @@ paths: | |||||
name: Authorization | name: Authorization | ||||
required: true | required: true | ||||
type: string | type: string | ||||
- description: 用户 ID、查询开始时间、结束时间 | |||||
- description: 用户 ID、查询开始时间、结束时间(查询时间不超过30天)、页数、每页大小 | |||||
in: body | in: body | ||||
name: req | name: req | ||||
required: true | required: true | ||||