Răsfoiți Sursa

标签逻辑入库

lichangdong 1 săptămână în urmă
părinte
comite
7fe86d86ec
1 a modificat fișierele cu 22 adăugiri și 3 ștergeri
  1. 22 3
      internal/service/MessageHandlers/friend_push_notice.go

+ 22 - 3
internal/service/MessageHandlers/friend_push_notice.go

@@ -11,6 +11,7 @@ import (
 	"wechat-api/ent"
 	"wechat-api/ent/label"
 	"wechat-api/ent/labellog"
+	"wechat-api/ent/labelrelationship"
 	"wechat-api/ent/wx"
 	"wechat-api/internal/pkg/wechat_ws"
 	"wechat-api/internal/svc"
@@ -126,6 +127,7 @@ func (f *FriendPushNoticeTypeHandler) Handle(ctx context.Context, msg *wechat_ws
 		}
 		//判断friend里的labelId="1,2,3,4,5"为空就不处理了,不为空的时候就查下label表里有没有这个labelId,没有就插入,有就跳过
 		if friend.LabelIds == "" {
+			logx.Infof("没有labelIds 失败, wx_wxId=%v", message.WeChatId)
 			continue
 		}
 		//获取labelId,并且按照逗号去分割成数组
@@ -133,6 +135,7 @@ func (f *FriendPushNoticeTypeHandler) Handle(ctx context.Context, msg *wechat_ws
 		var ids []int
 		ids, err = ParseCSVToIntSlice(labelIdsStr)
 		if err != nil {
+			logx.Infof("labelstring切割失败, labelIds=%v", labelIdsStr)
 			continue
 		}
 
@@ -145,6 +148,7 @@ func (f *FriendPushNoticeTypeHandler) Handle(ctx context.Context, msg *wechat_ws
 			All(ctx)
 
 		if err != nil || len(LabelLogs) == 0 {
+			logx.Error("labelLog.Query.fail: 跳过", wxInfo.OrganizationID)
 			continue
 		}
 
@@ -153,20 +157,35 @@ func (f *FriendPushNoticeTypeHandler) Handle(ctx context.Context, msg *wechat_ws
 		for _, remoteLabel := range LabelLogs {
 			labelInfo, err := svcCtx.DB.Label.Query().Where(
 				label.NameEQ(remoteLabel.LabelName),
-				//label.FromEQ(2),
-				//label.ModeEQ(2),
 				label.OrganizationID(currentOrgID),
 			).Only(ctx)
 			if err != nil || ent.IsNotFound(err) {
 				logx.Error("label not found.fail: ", wxInfo.OrganizationID)
 				continue
 			}
+
+			//svcCtx.DB.LabelRelationship.Create().
+			//	SetOrganizationID(wxInfo.OrganizationID).
+			//	SetContactID(friendId).
+			//	SetLabelID(labelInfo.ID).
+			//	SetAccount(friend.FriendNo).
+			//	SetNickname(friend.FriendNick).
+			//	SetMarkname(friend.Memo).
+			//	SetHeadimg(friend.Avatar).
+			//	SetOrganizationID(wxInfo.OrganizationID).
+			//	OnConflict().
+			//	UpdateNewValues().
+			//	SetType(friendType).
+			//	SetOrganizationID(wxInfo.OrganizationID).
+			//	ID(ctx)
+
 			//生成批量的关系数据 待插入
 			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()),
@@ -177,7 +196,7 @@ func (f *FriendPushNoticeTypeHandler) Handle(ctx context.Context, msg *wechat_ws
 	if len(labelRelationshipCreates) > 0 {
 		errShip := svcCtx.DB.LabelRelationship.CreateBulk(labelRelationshipCreates...).
 			OnConflict(
-				sql.ConflictColumns("label_id", "contact_id"),
+				sql.ConflictColumns(labelrelationship.FieldLabelID, labelrelationship.FieldContactID),
 			).DoNothing().Exec(ctx)
 		if errShip != nil {
 			logx.Error("label_relationship.create.fail: ", wxInfo.OrganizationID, labelRelationshipCreates)