|
@@ -28,7 +28,10 @@ func (l *CronTask) sendWxOnTimeout() {
|
|
|
sopTasks = append(sopTasks, st.ID)
|
|
|
}
|
|
|
sopStages, _ := l.svcCtx.DB.SopStage.Query().Where(sopstage.TaskIDIn(sopTasks...), sopstage.DeletedAtIsNil()).All(l.ctx)
|
|
|
-
|
|
|
+ stageMap := make(map[uint64]*ent.SopStage)
|
|
|
+ for _, stage := range sopStages {
|
|
|
+ stageMap[stage.ID] = stage
|
|
|
+ }
|
|
|
// 查询所有 no_reply_condition 值非 0 的 sop_node 记录
|
|
|
nodes, err := l.svcCtx.DB.SopNode.Query().
|
|
|
Where(sopnode.NoReplyConditionNEQ(0)).
|
|
@@ -174,7 +177,7 @@ func (l *CronTask) sendWxOnTimeout() {
|
|
|
Wxid: s.ContactWxid,
|
|
|
}
|
|
|
if node.ActionLabelAdd != nil || node.ActionLabelDel != nil {
|
|
|
- _ = l.AddLabelRelationships(sopStages, *contact, currentLabelIds, node.ActionLabelAdd, node.ActionLabelDel, s.OrganizationID)
|
|
|
+ _ = l.AddLabelRelationships(stageMap, *contact, currentLabelIds, node.ActionLabelAdd, node.ActionLabelDel, s.OrganizationID)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -193,7 +196,7 @@ func splitString(input string) []string {
|
|
|
return re.Split(input, -1)
|
|
|
}
|
|
|
|
|
|
-func (l *CronTask) AddLabelRelationships(sopStages []*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) (err error) {
|
|
|
//// 开始事务
|
|
|
//tx, err := l.svcCtx.DB.Tx(context.Background())
|
|
|
//if err != nil {
|
|
@@ -268,8 +271,8 @@ func (l *CronTask) AddLabelRelationships(sopStages []*ent.SopStage, contact ent.
|
|
|
finalLabelIds = append(finalLabelIds, id)
|
|
|
}
|
|
|
// 遍历 sop_stages,找出满足条件的 stage
|
|
|
- for _, stage := range sopStages {
|
|
|
- if stage.ConditionType == 1 && isLabelIdListMatchFilter(finalLabelIds, stage.ConditionOperator, stage.ConditionList) {
|
|
|
+ for key, stage := range sopStages {
|
|
|
+ if stage != nil && stage.ConditionType == 1 && isLabelIdListMatchFilter(finalLabelIds, stage.ConditionOperator, stage.ConditionList) {
|
|
|
// 判断是否有 contact_wxid、source_type、source_id、sub_source_id 相同的记录
|
|
|
_, err := l.svcCtx.DB.MessageRecords.Query().
|
|
|
Where(
|
|
@@ -340,6 +343,7 @@ func (l *CronTask) AddLabelRelationships(sopStages []*ent.SopStage, contact ent.
|
|
|
|
|
|
if stage.ActionLabelAdd != nil || stage.ActionLabelDel != nil {
|
|
|
// 递归调用 AddLabelRelationships
|
|
|
+ sopStages[key] = nil
|
|
|
err = l.AddLabelRelationships(sopStages, contact, finalLabelIds, stage.ActionLabelAdd, stage.ActionLabelDel, organizationId)
|
|
|
if err != nil {
|
|
|
//_ = tx.Rollback()
|