|
@@ -15,6 +15,7 @@ import (
|
|
"wechat-api/ent/custom_types"
|
|
"wechat-api/ent/custom_types"
|
|
"wechat-api/ent/predicate"
|
|
"wechat-api/ent/predicate"
|
|
"wechat-api/ent/usagedetail"
|
|
"wechat-api/ent/usagedetail"
|
|
|
|
+ "wechat-api/ent/wx"
|
|
"wechat-api/internal/svc"
|
|
"wechat-api/internal/svc"
|
|
"wechat-api/internal/types"
|
|
"wechat-api/internal/types"
|
|
"wechat-api/internal/utils/compapi"
|
|
"wechat-api/internal/utils/compapi"
|
|
@@ -147,10 +148,13 @@ func (l *AnalyzeContactField) Analyze(bot_wxid *string, contact_wxid *string) {
|
|
//yesterdayEnd := yesterdayStart.Add(24 * time.Hour)
|
|
//yesterdayEnd := yesterdayStart.Add(24 * time.Hour)
|
|
loc, _ := time.LoadLocation("Asia/Shanghai")
|
|
loc, _ := time.LoadLocation("Asia/Shanghai")
|
|
now := time.Now().In(loc)
|
|
now := time.Now().In(loc)
|
|
- yesterdayEnd := now.Truncate(24 * time.Hour)
|
|
|
|
- yesterdayStart := yesterdayEnd.AddDate(0, 0, -2)
|
|
|
|
|
|
+ yesterdayEnd := now.Truncate(24 * time.Hour).Add(-16 * time.Hour)
|
|
|
|
+ yesterdayStart := yesterdayEnd.AddDate(0, 0, -1)
|
|
predicates = append(predicates, usagedetail.CreatedAtGTE(yesterdayStart))
|
|
predicates = append(predicates, usagedetail.CreatedAtGTE(yesterdayStart))
|
|
predicates = append(predicates, usagedetail.CreatedAtLT(yesterdayEnd))
|
|
predicates = append(predicates, usagedetail.CreatedAtLT(yesterdayEnd))
|
|
|
|
+ if bot_wxid != nil && *bot_wxid != "" {
|
|
|
|
+ predicates = append(predicates, usagedetail.BotIDEQ(*bot_wxid))
|
|
|
|
+ }
|
|
if bot_wxid != nil && *bot_wxid != "" && contact_wxid != nil && *contact_wxid != "" {
|
|
if bot_wxid != nil && *bot_wxid != "" && contact_wxid != nil && *contact_wxid != "" {
|
|
predicates = append(predicates, usagedetail.BotIDEQ(*bot_wxid))
|
|
predicates = append(predicates, usagedetail.BotIDEQ(*bot_wxid))
|
|
predicates = append(predicates, usagedetail.ReceiverIDEQ(*contact_wxid))
|
|
predicates = append(predicates, usagedetail.ReceiverIDEQ(*contact_wxid))
|
|
@@ -162,16 +166,20 @@ func (l *AnalyzeContactField) Analyze(bot_wxid *string, contact_wxid *string) {
|
|
//predicates = append(predicates, usagedetail.CreatedAtLT(todayEnd))
|
|
//predicates = append(predicates, usagedetail.CreatedAtLT(todayEnd))
|
|
|
|
|
|
data, err := l.svcCtx.DB.UsageDetail.Query().Where(predicates...).All(l.ctx)
|
|
data, err := l.svcCtx.DB.UsageDetail.Query().Where(predicates...).All(l.ctx)
|
|
- logx.Info("usageDetails: ", data)
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
- wxs, err := l.svcCtx.DB.Wx.Query().All(l.ctx)
|
|
|
|
|
|
+ var wxPredicates []predicate.Wx
|
|
|
|
+ if bot_wxid != nil && *bot_wxid != "" {
|
|
|
|
+ wxPredicates = append(wxPredicates, wx.WxidEQ(*bot_wxid))
|
|
|
|
+ }
|
|
|
|
+ wxs, err := l.svcCtx.DB.Wx.Query().Where(wxPredicates...).All(l.ctx)
|
|
if err != nil {
|
|
if err != nil {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+ logx.Info("data: ", data)
|
|
|
|
+ logx.Info("wxs: ", wxs)
|
|
for _, wx := range wxs {
|
|
for _, wx := range wxs {
|
|
c, _ := l.svcCtx.DB.ContactFieldTemplate.Query().Where(contactfieldtemplate.OrganizationID(wx.OrganizationID)).First(l.ctx)
|
|
c, _ := l.svcCtx.DB.ContactFieldTemplate.Query().Where(contactfieldtemplate.OrganizationID(wx.OrganizationID)).First(l.ctx)
|
|
if c != nil {
|
|
if c != nil {
|
|
@@ -198,6 +206,8 @@ func (l *AnalyzeContactField) Analyze(bot_wxid *string, contact_wxid *string) {
|
|
template = append(template, contactBasicFieldTemplates...)
|
|
template = append(template, contactBasicFieldTemplates...)
|
|
}
|
|
}
|
|
for receiverID, messages := range usageDetails[botID] {
|
|
for receiverID, messages := range usageDetails[botID] {
|
|
|
|
+ logx.Info("messages: ", messages)
|
|
|
|
+ logx.Info("template: ", template)
|
|
result, _ := l.openaiRequest(messages, template)
|
|
result, _ := l.openaiRequest(messages, template)
|
|
logx.Info("result: ", result)
|
|
logx.Info("result: ", result)
|
|
if result == nil {
|
|
if result == nil {
|