Browse Source

update

adv_callback
shenjiachi 1 month ago
parent
commit
96021ad09b
7 changed files with 100 additions and 36 deletions
  1. +38
    -4
      app/hdl/institutional_management/public_platoon/hdl_basic.go
  2. +3
    -1
      app/md/institutional_management/public_platoon/md_public_platoon.go
  3. +1
    -1
      app/router/router.go
  4. +30
    -24
      app/svc/public_platoon/svc_relation_ship_map.go
  5. +10
    -2
      docs/docs.go
  6. +10
    -2
      docs/swagger.json
  7. +8
    -2
      docs/swagger.yaml

+ 38
- 4
app/hdl/institutional_management/public_platoon/hdl_basic.go View File

@@ -8,7 +8,9 @@ import (
"code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
"code.fnuoos.com/EggPlanet/egg_models.git/src/model"
"errors"
"fmt"
"github.com/gin-gonic/gin"
"strconv"
"time"
)

@@ -549,10 +551,10 @@ func AddCommunityDividendsWithUser(c *gin.Context) {
// @Accept json
// @Produce json
// @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 "具体数据"
// @Failure 400 {object} md.Response "具体错误"
// @Router /api/institutionalManagement/publicPlatoon/userDailyActivityAnalysis [post]
// @Router /api/institutionalManagement/publicPlatoon/userDailyActivityAnalysis/index [post]
func UserDailyActivityAnalysis(c *gin.Context) {
var req *md.UserDailyActivityAnalysisReq
if err := c.ShouldBindJSON(&req); err != nil {
@@ -570,14 +572,46 @@ func UserDailyActivityAnalysis(c *gin.Context) {
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 {
e.OutErr(c, e.ERR_DB_ORM, err.Error())
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{
TeamUserCount: parentRelation.HasSonNum,
TeamUserCount: total,
TeamActivityUserCount: activityUserCount,
ActivityCount: activityCount,
}


+ 3
- 1
app/md/institutional_management/public_platoon/md_public_platoon.go View File

@@ -105,6 +105,8 @@ type UserDailyActivityAnalysisReq struct {
Uid int64 `json:"uid,required"` // 查询用户 ID
StartDate string `json:"start_date,required" example:"开始日期"`
EndDate string `json:"end_date,required" example:"结束日期"`
Page int `json:"page,required"` // 页数
PageSize int `json:"page_size,required"` // 每页大小
}

type SonUserDailyActivityAnalysisNode struct {
@@ -115,7 +117,7 @@ type SonUserDailyActivityAnalysisNode struct {
}

type DailyActivityAnalysisTopData struct {
TeamUserCount int `json:"team_user_count"` // 团队人数
TeamUserCount int64 `json:"team_user_count"` // 团队人数
TeamActivityUserCount int64 `json:"team_activity_user_count"` // 子节点活跃人数
ActivityCount int64 `json:"activity_count"` // 子节点活跃天数
}


+ 1
- 1
app/router/router.go View File

@@ -78,7 +78,7 @@ func rInstitutionalManagement(r *gin.RouterGroup) { //制度管理
}
rUserDailyActivityAnalysis := rPublicPlatoon.Group("/userDailyActivityAnalysis")
{
rUserDailyActivityAnalysis.POST("", public_platoon.UserDailyActivityAnalysis)
rUserDailyActivityAnalysis.POST("/index", public_platoon.UserDailyActivityAnalysis)
}

}


+ 30
- 24
app/svc/public_platoon/svc_relation_ship_map.go View File

@@ -2,10 +2,12 @@ package svc

import (
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/model"
zhios_order_relate_logx "code.fnuoos.com/EggPlanet/egg_models.git/utils/logx"
"fmt"
"strconv"
"xorm.io/xorm"
)

@@ -146,44 +148,48 @@ func ExchangeUserPosition(engine *xorm.Engine, relation1, relation2 *model.Publi
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)
sonRelations, err := relationDb.FindUserRelateByParentUid(fatherUID, 1)
sonRelations, total, err := relationDb.PageFindUserRelateByParentUid(fatherUID, page, pageSize)
if err != nil {
return 0, 0, nil, err
return 0, nil, zhios_order_relate_logx.Error(err)
}
if sonRelations == nil {
return 0, 0, nil, nil
return 0, nil, nil
}
userIDs := make([]int64, 0)
for _, relation := range *sonRelations {
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 {
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)
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 {
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
}

+ 10
- 2
docs/docs.go View File

@@ -711,7 +711,7 @@ const docTemplate = `{
}
}
},
"/api/institutionalManagement/publicPlatoon/userDailyActivityAnalysis": {
"/api/institutionalManagement/publicPlatoon/userDailyActivityAnalysis/index": {
"post": {
"description": "日活分析",
"consumes": [
@@ -733,7 +733,7 @@ const docTemplate = `{
"required": true
},
{
"description": "用户 ID、查询开始时间、结束时间",
"description": "用户 ID、查询开始时间、结束时间(查询时间不超过30天)、页数、每页大小",
"name": "req",
"in": "body",
"required": true,
@@ -1514,6 +1514,14 @@ const docTemplate = `{
"type": "string",
"example": "结束日期"
},
"page": {
"description": "页数",
"type": "integer"
},
"page_size": {
"description": "每页大小",
"type": "integer"
},
"start_date": {
"type": "string",
"example": "开始日期"


+ 10
- 2
docs/swagger.json View File

@@ -704,7 +704,7 @@
}
}
},
"/api/institutionalManagement/publicPlatoon/userDailyActivityAnalysis": {
"/api/institutionalManagement/publicPlatoon/userDailyActivityAnalysis/index": {
"post": {
"description": "日活分析",
"consumes": [
@@ -726,7 +726,7 @@
"required": true
},
{
"description": "用户 ID、查询开始时间、结束时间",
"description": "用户 ID、查询开始时间、结束时间(查询时间不超过30天)、页数、每页大小",
"name": "req",
"in": "body",
"required": true,
@@ -1507,6 +1507,14 @@
"type": "string",
"example": "结束日期"
},
"page": {
"description": "页数",
"type": "integer"
},
"page_size": {
"description": "每页大小",
"type": "integer"
},
"start_date": {
"type": "string",
"example": "开始日期"


+ 8
- 2
docs/swagger.yaml View File

@@ -491,6 +491,12 @@ definitions:
end_date:
example: 结束日期
type: string
page:
description: 页数
type: integer
page_size:
description: 每页大小
type: integer
start_date:
example: 开始日期
type: string
@@ -1028,7 +1034,7 @@ paths:
summary: 制度中心-公排管理-公排基础设置(修改)
tags:
- 公排管理
/api/institutionalManagement/publicPlatoon/userDailyActivityAnalysis:
/api/institutionalManagement/publicPlatoon/userDailyActivityAnalysis/index:
post:
consumes:
- application/json
@@ -1039,7 +1045,7 @@ paths:
name: Authorization
required: true
type: string
- description: 用户 ID、查询开始时间、结束时间
- description: 用户 ID、查询开始时间、结束时间(查询时间不超过30天)、页数、每页大小
in: body
name: req
required: true


Loading…
Cancel
Save