🆕 水群排行榜新增群活跃度 #25

Merged
李寻欢 merged 1 commits from hotfix into main 2024-03-07 09:43:28 +08:00
5 changed files with 77 additions and 1 deletions

View File

@ -2,7 +2,9 @@ package watergroup
import (
"fmt"
"go-wechat/client"
"go-wechat/config"
"go-wechat/entity"
"go-wechat/service"
"go-wechat/utils"
"log"
@ -55,6 +57,20 @@ func dealMonth(gid string) {
log.Printf("上月群[%s]无对话记录", gid)
return
}
// 查询群成员总数
var groupUsers int64
err = client.MySQL.Model(&entity.GroupUser{}).Where("group_id = ?", gid).Count(&groupUsers).Error
if err != nil {
log.Printf("查询群成员总数失败, 错误信息: %v", err)
}
// 计算活跃度
showActivity := err != nil && groupUsers > 0
activity := "0.00"
if groupUsers > 0 {
activity = fmt.Sprintf("%.2f", (float64(len(records))/float64(groupUsers))*100)
}
// 计算消息总数
var msgCount int64
for _, v := range records {
@ -63,6 +79,9 @@ func dealMonth(gid string) {
// 组装消息总数推送信息
notifyMsgs = append(notifyMsgs, " ")
notifyMsgs = append(notifyMsgs, fmt.Sprintf("🗣️ %s本群 %d 位朋友共产生 %d 条发言", monthStr, len(records), msgCount))
if showActivity {
notifyMsgs = append(notifyMsgs, fmt.Sprintf("🎭 活跃度: %s%", activity))
}
notifyMsgs = append(notifyMsgs, "\n🏵 活跃用户排行榜 🏵")
notifyMsgs = append(notifyMsgs, " ")

View File

@ -18,7 +18,7 @@ type rankUser struct {
// @return err
func getRankData(groupId, date string) (rank []rankUser, err error) {
tx := client.MySQL.Table("t_message AS tm").
Joins("LEFT JOIN t_group_user AS tgu ON tgu.wxid = tm.group_user AND tm.from_user = tgu.group_id AND tgu.skip_chat_rank = 0").
Joins("LEFT JOIN t_group_user AS tgu ON tgu.wxid = tm.group_user AND tm.from_user = tgu.group_id AND tgu.skip_chat_rank = 0 AND is_member = 1").
Select("tm.group_user", "tgu.nickname", "count( 1 ) AS `count`").
Where("tm.from_user = ?", groupId).
Where("tm.type < 10000").

View File

@ -2,7 +2,9 @@ package watergroup
import (
"fmt"
"go-wechat/client"
"go-wechat/config"
"go-wechat/entity"
"go-wechat/service"
"go-wechat/utils"
"log"
@ -54,6 +56,20 @@ func dealWeek(gid string) {
log.Printf("上周群[%s]无对话记录", gid)
return
}
// 查询群成员总数
var groupUsers int64
err = client.MySQL.Model(&entity.GroupUser{}).Where("group_id = ?", gid).Count(&groupUsers).Error
if err != nil {
log.Printf("查询群成员总数失败, 错误信息: %v", err)
}
// 计算活跃度
showActivity := err != nil && groupUsers > 0
activity := "0.00"
if groupUsers > 0 {
activity = fmt.Sprintf("%.2f", (float64(len(records))/float64(groupUsers))*100)
}
// 计算消息总数
var msgCount int64
for _, v := range records {
@ -62,6 +78,9 @@ func dealWeek(gid string) {
// 组装消息总数推送信息
notifyMsgs = append(notifyMsgs, " ")
notifyMsgs = append(notifyMsgs, fmt.Sprintf("🗣️ 上周本群 %d 位朋友共产生 %d 条发言", len(records), msgCount))
if showActivity {
notifyMsgs = append(notifyMsgs, fmt.Sprintf("🎭 活跃度: %s%", activity))
}
notifyMsgs = append(notifyMsgs, "\n🏵 活跃用户排行榜 🏵")
notifyMsgs = append(notifyMsgs, " ")

View File

@ -2,7 +2,9 @@ package watergroup
import (
"fmt"
"go-wechat/client"
"go-wechat/config"
"go-wechat/entity"
"go-wechat/service"
"go-wechat/utils"
"log"
@ -54,6 +56,20 @@ func dealYear(gid string) {
log.Printf("去年本群[%s]无对话记录", gid)
return
}
// 查询群成员总数
var groupUsers int64
err = client.MySQL.Model(&entity.GroupUser{}).Where("group_id = ?", gid).Count(&groupUsers).Error
if err != nil {
log.Printf("查询群成员总数失败, 错误信息: %v", err)
}
// 计算活跃度
showActivity := err != nil && groupUsers > 0
activity := "0.00"
if groupUsers > 0 {
activity = fmt.Sprintf("%.2f", (float64(len(records))/float64(groupUsers))*100)
}
// 计算消息总数
var msgCount int64
for _, v := range records {
@ -70,6 +86,9 @@ func dealYear(gid string) {
notifyMsgs = append(notifyMsgs, fmt.Sprintf("祝福你们新年快乐!让我们一起迎接%d年的到来", time.Now().Local().Year()))
notifyMsgs = append(notifyMsgs, " ")
notifyMsgs = append(notifyMsgs, fmt.Sprintf("🗣️ 去年本群 %d 位朋友共产生 %d 条发言", len(records), msgCount))
if showActivity {
notifyMsgs = append(notifyMsgs, fmt.Sprintf("🎭 活跃度: %s%", activity))
}
notifyMsgs = append(notifyMsgs, "\n🏵 活跃用户排行榜 🏵")
notifyMsgs = append(notifyMsgs, " ")

View File

@ -2,7 +2,9 @@ package watergroup
import (
"fmt"
"go-wechat/client"
"go-wechat/config"
"go-wechat/entity"
"go-wechat/service"
"go-wechat/utils"
"log"
@ -56,6 +58,20 @@ func dealYesterday(gid string) {
log.Printf("昨日群[%s]无对话记录", gid)
return
}
// 查询群成员总数
var groupUsers int64
err = client.MySQL.Model(&entity.GroupUser{}).Where("group_id = ?", gid).Count(&groupUsers).Error
if err != nil {
log.Printf("查询群成员总数失败, 错误信息: %v", err)
}
// 计算活跃度
showActivity := err != nil && groupUsers > 0
activity := "0.00"
if groupUsers > 0 {
activity = fmt.Sprintf("%.2f", (float64(len(records))/float64(groupUsers))*100)
}
// 计算消息总数
var msgCount int64
for _, v := range records {
@ -64,6 +80,9 @@ func dealYesterday(gid string) {
// 组装消息总数推送信息
notifyMsgs = append(notifyMsgs, " ")
notifyMsgs = append(notifyMsgs, fmt.Sprintf("🗣️ 昨日本群 %d 位朋友共产生 %d 条发言", len(records), msgCount))
if showActivity {
notifyMsgs = append(notifyMsgs, fmt.Sprintf("🎭 活跃度: %s%", activity))
}
notifyMsgs = append(notifyMsgs, "\n🏵 活跃用户排行榜 🏵")
notifyMsgs = append(notifyMsgs, " ")