From 1124d413fa928381ec36749be717051c3104a901 Mon Sep 17 00:00:00 2001 From: Leufolium Date: Wed, 26 Jun 2024 17:37:00 +0800 Subject: [PATCH] by Robin at 20240626 --- app/mix/dao/mysql_zone.go | 16 ++++++++++++++++ app/mix/service/logic/vas_zone.go | 23 +++++++++++++++++++++++ app/mix/service/utilservice.go | 11 ++++++++++- dbstruct/vas_mysql.go | 28 ++++++++++++++++++++++++++++ 4 files changed, 77 insertions(+), 1 deletion(-) diff --git a/app/mix/dao/mysql_zone.go b/app/mix/dao/mysql_zone.go index 5b6bda1b..a05b10ef 100644 --- a/app/mix/dao/mysql_zone.go +++ b/app/mix/dao/mysql_zone.go @@ -574,3 +574,19 @@ func (m *Mysql) GetLastHourZoneAdmissionInfo(ctx *gin.Context, tx *sqlx.Tx, st, } return } + +// 统计空间总人数 +func (m *Mysql) GetZoneMemberCountGroupByZoneMemberType(ctx *gin.Context, tx *sqlx.Tx, zids []int64) (list []*dbstruct.ZoneMemberCount, err error) { + sql := fmt.Sprintf("select count(1), zid , member_type from %s where zid in (%s) group by member_type, zid", TableVasZoneMember, util.Convert2SqlArr(zids)) + list = make([]*dbstruct.ZoneMemberCount, 0) + if tx != nil { + err = tx.SelectContext(ctx, &list, sql) + } else { + db := m.getDBVas() + err = db.SelectContext(ctx, &list, sql) + } + if err != nil { + return + } + return +} diff --git a/app/mix/service/logic/vas_zone.go b/app/mix/service/logic/vas_zone.go index 63ac599c..3c1c05bf 100644 --- a/app/mix/service/logic/vas_zone.go +++ b/app/mix/service/logic/vas_zone.go @@ -1238,3 +1238,26 @@ func (v *Vas) GetLastHourZoneProfit(ctx *gin.Context, st, et int64) ([]*dbstruct func (v *Vas) GetLastHourZoneAdmissionInfo(ctx *gin.Context, tx *sqlx.Tx, st, et int64) ([]*dbstruct.ZoneAdmissionInfo, error) { return v.store.GetLastHourZoneAdmissionInfo(ctx, tx, st, et) } + +// 统计空间总人数 +func (v *Vas) GetZoneMemberCountGroupByZoneMemberType(ctx *gin.Context, zids []int64) (map[int64]map[int64]int64, error) { + countMp := make(map[int64]map[int64]int64, 0) + list, err := v.store.GetZoneMemberCountGroupByZoneMemberType(ctx, nil, zids) + if err != nil { + logger.Error("GetZoneMemberCountGroupByZoneMemberType fail err: %v", err) + return make(map[int64]map[int64]int64), nil + } + + for _, zonemembercount := range list { + mp, ok := countMp[zonemembercount.GetZid()] + if ok { + mp[zonemembercount.GetMemberType()] = zonemembercount.GetNum() + } else { + mp = make(map[int64]int64) + mp[zonemembercount.GetMemberType()] = zonemembercount.GetNum() + countMp[zonemembercount.GetZid()] = mp + } + } + + return countMp, nil +} diff --git a/app/mix/service/utilservice.go b/app/mix/service/utilservice.go index 00f43e78..02c8cbe2 100644 --- a/app/mix/service/utilservice.go +++ b/app/mix/service/utilservice.go @@ -1970,7 +1970,10 @@ func (s *Service) utilFillZonesWithOpVOInfo(ctx *gin.Context, list []*dbstruct.Z // 8.获取空间付费信息 zvMap, _ := _DefaultVas.GetZoneVasByIds(ctx, zids) - // 9.填充信息 + // 9.获取空间人数信息 + zmcountMap, _ := _DefaultVas.GetZoneMemberCountGroupByZoneMemberType(ctx, zids) + + // 10.填充信息 for _, vo := range volist { zid := vo.Zone.GetId() @@ -2003,6 +2006,12 @@ func (s *Service) utilFillZonesWithOpVOInfo(ctx *gin.Context, list []*dbstruct.Z if zv, ok := zvMap[zid]; ok { vo.CopyZoneVas(zv) } + + // 填充空间总人数 + zmcount := zmcountMap[zid] + vo.IronfanNum = zmcount[int64(dbstruct.ZoneMemberTypeIronfan)] + vo.SuperfanNum = zmcount[int64(dbstruct.ZoneMemberTypeSuperfan)] + vo.EntrantNum = zmcount[int64(dbstruct.ZoneMemberTypeNormal)] + vo.IronfanNum + vo.SuperfanNum } return diff --git a/dbstruct/vas_mysql.go b/dbstruct/vas_mysql.go index b4925965..61d05552 100644 --- a/dbstruct/vas_mysql.go +++ b/dbstruct/vas_mysql.go @@ -1483,3 +1483,31 @@ func (p *RefundRate) GetRefundRate() float64 { } return 0 } + +// 空间总人数统计 +type ZoneMemberCount struct { + Zid *int64 `json:"zid" db:"zid"` + MemberType *int64 `json:"member_type" db:"member_type"` + Num *int64 `json:"num" db:"num"` +} + +func (p *ZoneMemberCount) GetZid() int64 { + if p != nil && p.Zid != nil { + return *p.Zid + } + return 0 +} + +func (p *ZoneMemberCount) GetMemberType() int64 { + if p != nil && p.MemberType != nil { + return *p.MemberType + } + return 0 +} + +func (p *ZoneMemberCount) GetNum() int64 { + if p != nil && p.Num != nil { + return *p.Num + } + return 0 +}