|
@@ -1,7 +1,6 @@
|
|
|
package crontask
|
|
|
|
|
|
import (
|
|
|
- "github.com/zeromicro/go-zero/core/logx"
|
|
|
"time"
|
|
|
"wechat-api/ent"
|
|
|
"wechat-api/ent/creditbalance"
|
|
@@ -11,6 +10,7 @@ import (
|
|
|
)
|
|
|
|
|
|
func (l *CronTask) computeHistoricalCredit() {
|
|
|
+ // 获取所有当时的组织和机器人对应关系
|
|
|
orgBots := []OrgBot{}
|
|
|
err := l.svcCtx.DB.UsageDetail.Query().
|
|
|
GroupBy(usagedetail.FieldOrganizationID, usagedetail.FieldBotID).
|
|
@@ -22,11 +22,11 @@ func (l *CronTask) computeHistoricalCredit() {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+ // 遍历获得每个组织有过哪些机器人
|
|
|
wxbotsSet := make(map[uint64][]string)
|
|
|
for _, ob := range orgBots {
|
|
|
wxbotsSet[ob.OrganizationID] = append(wxbotsSet[ob.OrganizationID], ob.BotID)
|
|
|
}
|
|
|
- logx.Info("wxbotsSet: ", wxbotsSet)
|
|
|
|
|
|
/*
|
|
|
计算本小时的数据
|
|
@@ -39,7 +39,7 @@ func (l *CronTask) computeHistoricalCredit() {
|
|
|
// 获取当前时间
|
|
|
//now := time.Now()
|
|
|
//start := time.Date(2024, 12, 25, 0, 0, 0, 0, time.Local)
|
|
|
- start := time.Date(2025, 4, 1, 0, 0, 0, 0, time.Local)
|
|
|
+ start := time.Date(2024, 12, 25, 0, 0, 0, 0, time.Local)
|
|
|
end := time.Date(2025, 4, 27, 23, 0, 0, 0, time.Local)
|
|
|
//start := time.Date(2025, 3, 18, 0, 0, 0, 0, time.Local)
|
|
|
//end := time.Date(2025, 3, 19, 23, 0, 0, 0, time.Local)
|
|
@@ -48,10 +48,14 @@ func (l *CronTask) computeHistoricalCredit() {
|
|
|
balanceBotSet := make(map[string]float64)
|
|
|
|
|
|
for orgID, wxinfos := range wxbotsSet {
|
|
|
+ // 遍历每个组织
|
|
|
if _, ok := balanceOrgSet[orgID]; !ok {
|
|
|
balanceOrgSet[orgID] = 0
|
|
|
}
|
|
|
for _, wxinfo := range wxinfos {
|
|
|
+ // 遍历每个组织中曾经有过的机器人
|
|
|
+
|
|
|
+ // 建立机器人积分消耗字典,用于累计积分
|
|
|
if _, ok := balanceBotSet[wxinfo]; !ok {
|
|
|
balanceBotSet[wxinfo] = 0
|
|
|
}
|
|
@@ -97,7 +101,7 @@ func (l *CronTask) computeHistoricalCredit() {
|
|
|
Save(l.ctx)
|
|
|
l.Errorf("save hour data error:%v \n", err)
|
|
|
} else {
|
|
|
- b := creditBalance.Balance - balance
|
|
|
+ b := creditBalance.Balance + balance
|
|
|
_, err = l.svcCtx.DB.CreditBalance.Update().
|
|
|
Where(creditbalance.OrganizationIDEQ(orgID)).
|
|
|
SetBalance(b).
|