feat: 添加图表统计功能
- TG: /chart 本月分类饼图, /week 近7天消费柱状图 - QQ: 统计/报表 本月文本统计 - 新增 go-chart 依赖生成 PNG 图表 - 新增 GetCategoryStats/GetDailyStats 查询方法
This commit is contained in:
@@ -102,6 +102,7 @@ func (b *QQBot) processAndReply(userID string, content string) string {
|
||||
"📋 命令列表:\n" +
|
||||
"• 记录/查看 — 最近10条\n" +
|
||||
"• 今日/今天 — 今日汇总\n" +
|
||||
"• 统计/报表 — 本月分类统计\n" +
|
||||
"• 帮助 — 本帮助信息"
|
||||
|
||||
case isCommand(text, "查看", "记录", "列表", "list", "/list", "最近"):
|
||||
@@ -136,6 +137,27 @@ func (b *QQBot) processAndReply(userID string, content string) string {
|
||||
}
|
||||
sb.WriteString(fmt.Sprintf("\n💰 共 %d 笔,合计 %.2f 元", len(items), float64(total)/100.0))
|
||||
return sb.String()
|
||||
|
||||
case isCommand(text, "统计", "报表", "图表", "chart", "/chart"):
|
||||
now := time.Now()
|
||||
dateFrom := now.Format("2006-01") + "-01"
|
||||
dateTo := now.Format("2006-01-02")
|
||||
stats, err := b.finance.GetCategoryStats(DefaultUserID, dateFrom, dateTo)
|
||||
if err != nil || len(stats) == 0 {
|
||||
return fmt.Sprintf("📭 %d年%d月暂无消费数据", now.Year(), now.Month())
|
||||
}
|
||||
var sb strings.Builder
|
||||
var grandTotal int64
|
||||
var grandCount int
|
||||
sb.WriteString(fmt.Sprintf("📊 %d年%d月消费统计:\n\n", now.Year(), now.Month()))
|
||||
for _, s := range stats {
|
||||
yuan := float64(s.Total) / 100.0
|
||||
sb.WriteString(fmt.Sprintf("• %s:%.2f元(%d笔)\n", s.Category, yuan, s.Count))
|
||||
grandTotal += s.Total
|
||||
grandCount += s.Count
|
||||
}
|
||||
sb.WriteString(fmt.Sprintf("\n💰 共 %d 笔,合计 %.2f 元", grandCount, float64(grandTotal)/100.0))
|
||||
return sb.String()
|
||||
}
|
||||
|
||||
amount, category, err := b.finance.AddTransaction(DefaultUserID, text)
|
||||
|
||||
Reference in New Issue
Block a user