Compare commits

...

2 Commits

Author SHA1 Message Date
李寻欢
997ad806f0 新增发送词云图片(需配合外部工具预先生成词云图片) 2023-11-22 10:55:40 +08:00
李寻欢
86435e9707 🐛 修复月度数据统计错误的BUG 2023-11-22 10:10:36 +08:00
3 changed files with 23 additions and 2 deletions

View File

@@ -8,13 +8,20 @@ import (
"go-wechat/utils"
"log"
"strings"
"time"
)
// month
// @description: 月排行榜
func month() {
for _, id := range config.Conf.Task.WaterGroup.Groups {
// 消息统计
dealMonth(id)
// 获取上个月月份
yd := time.Now().Local().AddDate(0, 0, -1).Format("200601")
// 发送词云
fileName := fmt.Sprintf("%s_%s.png", yd, id)
utils.SendImage(id, "D:\\Share\\wordcloud\\"+fileName, 0)
}
}
@@ -29,7 +36,7 @@ func dealMonth(gid string) {
err := client.MySQL.Model(&entity.Message{}).
Where("from_user = ?", gid).
Where("`type` < 10000").
Where("YEARWEEK(date_format(create_at, '%Y-%m-%d')) = YEARWEEK(now()) - 1").
Where("PERIOD_DIFF(date_format(now(), '%Y%m'), date_format(create_at, '%Y%m')) = 1").
Count(&yesterdayMsgCount).Error
if err != nil {
log.Printf("获取上月消息总数失败, 错误信息: %v", err)
@@ -56,7 +63,7 @@ func dealMonth(gid string) {
Select("tm.group_user", "tgu.nickname", "count( 1 ) AS `count`").
Where("tm.from_user = ?", gid).
Where("tm.type < 10000").
Where("YEARWEEK(date_format(tm.create_at, '%Y-%m-%d')) = YEARWEEK(now()) - 1").
Where("PERIOD_DIFF(date_format(now(), '%Y%m'), date_format(create_at, '%Y%m')) = 1").
Group("tm.group_user, tgu.nickname").Order("`count` DESC").
Limit(10)

View File

@@ -8,6 +8,7 @@ import (
"go-wechat/utils"
"log"
"strings"
"time"
)
// 水群排行榜
@@ -16,7 +17,13 @@ import (
// @description: 昨日排行榜
func yesterday() {
for _, id := range config.Conf.Task.WaterGroup.Groups {
// 消息统计
dealYesterday(id)
// 获取昨日日期
yd := time.Now().Local().AddDate(0, 0, -1).Format("20060102")
// 发送词云
fileName := fmt.Sprintf("%s_%s.png", yd, id)
utils.SendImage(id, "D:\\Share\\wordcloud\\"+fileName, 0)
}
}

View File

@@ -8,13 +8,20 @@ import (
"go-wechat/utils"
"log"
"strings"
"time"
)
// week
// @description: 周排行榜
func week() {
for _, id := range config.Conf.Task.WaterGroup.Groups {
// 消息统计
dealWeek(id)
// 获取上周周数
year, weekNo := time.Now().Local().AddDate(0, 0, -1).ISOWeek()
// 发送词云
fileName := fmt.Sprintf("%d%d_%s.png", year, weekNo, id)
utils.SendImage(id, "D:\\Share\\wordcloud\\"+fileName, 0)
}
}