浏览代码

改为白名单模式

lichangdong 1 天之前
父节点
当前提交
340e6c59de
共有 1 个文件被更改,包括 20 次插入10 次删除
  1. 20 10
      internal/service/MessageHandlers/friend_push_notice.go

+ 20 - 10
internal/service/MessageHandlers/friend_push_notice.go

@@ -178,16 +178,26 @@ func (f *FriendPushNoticeTypeHandler) Handle(ctx context.Context, msg *wechat_ws
 				logx.Error("label not found.fail: ", wxInfo.OrganizationID)
 				continue
 			}
-			labelRelationshipCreates = append(labelRelationshipCreates,
-				svcCtx.DB.LabelRelationship.Create().
-					//SetID(int(label.LabelId)).
-					SetOrganizationID(wxInfo.OrganizationID).
-					SetContactID(friendId).
-					SetStatus(1).
-					SetLabelID(labelInfo.ID).
-					SetCreatedAt(time.Now()).
-					SetUpdatedAt(time.Now()),
-			)
+
+			_, err = svcCtx.DB.LabelRelationship.Query().Where(
+				labelrelationship.LabelIDEQ(labelInfo.ID),
+				//label.StatusEQ(remoteLabel.LabelName),
+				labelrelationship.ContactIDEQ(friendId),
+			).Only(ctx)
+
+			if err != nil || ent.IsNotFound(err) {
+				labelRelationshipCreates = append(labelRelationshipCreates,
+					svcCtx.DB.LabelRelationship.Create().
+						//SetID(int(label.LabelId)).
+						SetOrganizationID(wxInfo.OrganizationID).
+						SetContactID(friendId).
+						SetStatus(1).
+						SetLabelID(labelInfo.ID).
+						SetCreatedAt(time.Now()).
+						SetUpdatedAt(time.Now()),
+				)
+			}
+
 			//
 		}
 	}