|
@@ -2,6 +2,7 @@ package crontask
|
|
|
|
|
|
import (
|
|
import (
|
|
"context"
|
|
"context"
|
|
|
|
+ "github.com/zeromicro/go-zero/core/logx"
|
|
"regexp"
|
|
"regexp"
|
|
"time"
|
|
"time"
|
|
"wechat-api/ent"
|
|
"wechat-api/ent"
|
|
@@ -73,7 +74,7 @@ func (l *CronTask) sendWxOnTimeout() {
|
|
Where(messagerecords.SourceTypeEQ(3)).
|
|
Where(messagerecords.SourceTypeEQ(3)).
|
|
Where(messagerecords.SourceIDEQ(node.StageID)).
|
|
Where(messagerecords.SourceIDEQ(node.StageID)).
|
|
Where(messagerecords.SubSourceIDEQ(0)).
|
|
Where(messagerecords.SubSourceIDEQ(0)).
|
|
- Where(messagerecords.SendTimeGTE(lowerBound)).
|
|
|
|
|
|
+ //Where(messagerecords.SendTimeGTE(lowerBound)).
|
|
Where(messagerecords.SendTimeLTE(upperBound)).
|
|
Where(messagerecords.SendTimeLTE(upperBound)).
|
|
All(ctx)
|
|
All(ctx)
|
|
} else {
|
|
} else {
|
|
@@ -183,7 +184,8 @@ func (l *CronTask) sendWxOnTimeout() {
|
|
Wxid: s.ContactWxid,
|
|
Wxid: s.ContactWxid,
|
|
}
|
|
}
|
|
if node.ActionLabelAdd != nil || node.ActionLabelDel != nil {
|
|
if node.ActionLabelAdd != nil || node.ActionLabelDel != nil {
|
|
- _ = l.AddLabelRelationships(stageMap, *contact, currentLabelIds, node.ActionLabelAdd, node.ActionLabelDel, s.OrganizationID)
|
|
|
|
|
|
+ visitedStages := make(map[uint64]bool)
|
|
|
|
+ _ = l.AddLabelRelationships(stageMap, *contact, currentLabelIds, node.ActionLabelAdd, node.ActionLabelDel, s.OrganizationID, visitedStages)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -201,8 +203,7 @@ func splitString(input string) []string {
|
|
// Split the input string based on the pattern
|
|
// Split the input string based on the pattern
|
|
return re.Split(input, -1)
|
|
return re.Split(input, -1)
|
|
}
|
|
}
|
|
-
|
|
|
|
-func (l *CronTask) AddLabelRelationships(sopStages map[uint64]*ent.SopStage, contact ent.Contact, currentLabelIds []uint64, addLabelIds []uint64, delLabelIds []uint64, organizationId uint64) (err error) {
|
|
|
|
|
|
+func (l *CronTask) AddLabelRelationships(sopStages map[uint64]*ent.SopStage, contact ent.Contact, currentLabelIds []uint64, addLabelIds []uint64, delLabelIds []uint64, organizationId uint64, visitedStages map[uint64]bool) (err error) {
|
|
//// 开始事务
|
|
//// 开始事务
|
|
//tx, err := l.svcCtx.DB.Tx(context.Background())
|
|
//tx, err := l.svcCtx.DB.Tx(context.Background())
|
|
//if err != nil {
|
|
//if err != nil {
|
|
@@ -278,9 +279,12 @@ func (l *CronTask) AddLabelRelationships(sopStages map[uint64]*ent.SopStage, con
|
|
}
|
|
}
|
|
// 遍历 sop_stages,找出满足条件的 stage
|
|
// 遍历 sop_stages,找出满足条件的 stage
|
|
for key, stage := range sopStages {
|
|
for key, stage := range sopStages {
|
|
- if stage != nil && stage.ConditionType == 1 && isLabelIdListMatchFilter(finalLabelIds, stage.ConditionOperator, stage.ConditionList) {
|
|
|
|
|
|
+ if stage == nil || visitedStages[key] {
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+ if stage.ConditionType == 1 && isLabelIdListMatchFilter(finalLabelIds, stage.ConditionOperator, stage.ConditionList) {
|
|
// 判断是否有 contact_wxid、source_type、source_id、sub_source_id 相同的记录
|
|
// 判断是否有 contact_wxid、source_type、source_id、sub_source_id 相同的记录
|
|
- _, err := l.svcCtx.DB.MessageRecords.Query().
|
|
|
|
|
|
+ x, err := l.svcCtx.DB.MessageRecords.Query().
|
|
Where(
|
|
Where(
|
|
messagerecords.ContactWxid(contact.Wxid),
|
|
messagerecords.ContactWxid(contact.Wxid),
|
|
messagerecords.SourceType(3),
|
|
messagerecords.SourceType(3),
|
|
@@ -288,7 +292,10 @@ func (l *CronTask) AddLabelRelationships(sopStages map[uint64]*ent.SopStage, con
|
|
messagerecords.SubSourceID(0),
|
|
messagerecords.SubSourceID(0),
|
|
).
|
|
).
|
|
Only(l.ctx)
|
|
Only(l.ctx)
|
|
|
|
+ logx.Info("x: ", x)
|
|
|
|
+ logx.Info("err: ", err)
|
|
if !ent.IsNotFound(err) {
|
|
if !ent.IsNotFound(err) {
|
|
|
|
+ logx.Info("continue")
|
|
continue
|
|
continue
|
|
}
|
|
}
|
|
// 判断ActionMessage是否为空
|
|
// 判断ActionMessage是否为空
|
|
@@ -349,8 +356,8 @@ func (l *CronTask) AddLabelRelationships(sopStages map[uint64]*ent.SopStage, con
|
|
|
|
|
|
if stage.ActionLabelAdd != nil || stage.ActionLabelDel != nil {
|
|
if stage.ActionLabelAdd != nil || stage.ActionLabelDel != nil {
|
|
// 递归调用 AddLabelRelationships
|
|
// 递归调用 AddLabelRelationships
|
|
- sopStages[key] = nil
|
|
|
|
- err = l.AddLabelRelationships(sopStages, contact, finalLabelIds, stage.ActionLabelAdd, stage.ActionLabelDel, organizationId)
|
|
|
|
|
|
+ visitedStages[key] = true
|
|
|
|
+ err = l.AddLabelRelationships(sopStages, contact, finalLabelIds, stage.ActionLabelAdd, stage.ActionLabelDel, organizationId, visitedStages)
|
|
if err != nil {
|
|
if err != nil {
|
|
//_ = tx.Rollback()
|
|
//_ = tx.Rollback()
|
|
return err
|
|
return err
|