Преглед на файлове

Merge branch 'lcd2025422' into debug

lichangdong преди 6 дни
родител
ревизия
708573a1c4

+ 1 - 6
ent/migrate/schema.go

@@ -583,14 +583,9 @@ var (
 		PrimaryKey: []*schema.Column{LabelLogColumns[0]},
 		Indexes: []*schema.Index{
 			{
-				Name:    "labellog_label_id",
-				Unique:  false,
-				Columns: []*schema.Column{LabelLogColumns[4]},
-			},
-			{
 				Name:    "idx_org_label",
 				Unique:  true,
-				Columns: []*schema.Column{LabelLogColumns[4], LabelLogColumns[6]},
+				Columns: []*schema.Column{LabelLogColumns[4], LabelLogColumns[5], LabelLogColumns[6]},
 			},
 		},
 	}

+ 1 - 2
ent/schema/label_log.go

@@ -30,8 +30,7 @@ func (LabelLog) Mixin() []ent.Mixin {
 
 func (LabelLog) Indexes() []ent.Index {
 	return []ent.Index{
-		index.Fields("label_id"),
-		index.Fields("label_id", "organization_id").Unique().StorageKey("idx_org_label"),
+		index.Fields("label_id", "wx_id", "organization_id").Unique().StorageKey("idx_org_label"),
 	}
 }
 

+ 0 - 1
internal/logic/message_records/get_message_records_list_logic.go

@@ -52,7 +52,6 @@ func (l *GetMessageRecordsListLogic) GetMessageRecordsList(req *types.MessageRec
 		predicates = append(predicates, messagerecords.StatusNEQ(0))
 	}
 	data, err := l.svcCtx.DB.MessageRecords.Query().Where(predicates...).Page(l.ctx, req.Page, req.PageSize)
-
 	if err != nil {
 		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
 	}

+ 2 - 2
internal/service/MessageHandlers/contact_Label_info_notice.go

@@ -125,7 +125,7 @@ func (f *ContactLabelInfoNotice) Handle(ctx context.Context, msg *wechat_ws.MsgJ
 	// 批量插入 LabelLog
 	if len(bulkLabelLogs) > 0 {
 		err := svcCtx.DB.LabelLog.CreateBulk(bulkLabelLogs...).
-			OnConflict(sql.ConflictColumns("label_id", "organization_id")).
+			OnConflict(sql.ConflictColumns(labellog.FieldLabelID, labellog.FieldWxID, labellog.FieldOrganizationID)).
 			DoNothing().
 			Exec(ctx)
 		if err != nil {
@@ -136,7 +136,7 @@ func (f *ContactLabelInfoNotice) Handle(ctx context.Context, msg *wechat_ws.MsgJ
 	// 批量插入 Label
 	if len(bulkLabels) > 0 {
 		err := svcCtx.DB.Label.CreateBulk(bulkLabels...).
-			OnConflict(sql.ConflictColumns("name", "organization_id")).
+			OnConflict(sql.ConflictColumns(label.FieldName, label.FieldOrganizationID)).
 			DoNothing().
 			Exec(ctx)
 		if err != nil {

+ 26 - 6
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"
@@ -88,7 +89,7 @@ func NewFriendPushNoticeTypeHandler(svcCtx *svc.ServiceContext) *FriendPushNotic
 func (f *FriendPushNoticeTypeHandler) Handle(ctx context.Context, msg *wechat_ws.MsgJsonObject, svcCtx *svc.ServiceContext) error {
 	message := workphone.FriendPushNoticeMessage{}
 	err := json.Unmarshal([]byte(msg.Message), &message)
-	//logx.Infof("msg.Message 的内容是:%s", msg.Message)
+	logx.Infof("msg.Message 的内容是:%s", msg.Message)
 	if err != nil {
 		logx.Errorf("Unmarshal.fail")
 		return err
@@ -97,8 +98,7 @@ func (f *FriendPushNoticeTypeHandler) Handle(ctx context.Context, msg *wechat_ws
 	wxInfo, err := svcCtx.DB.Wx.Query().
 		Where(
 			wx.WxidEQ(message.WeChatId), // Additional filter by organizationId
-		).
-		Only(ctx)
+		).Only(ctx)
 	if err != nil {
 		return err
 	}
@@ -126,6 +126,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 +134,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
 		}
 
@@ -142,9 +144,11 @@ func (f *FriendPushNoticeTypeHandler) Handle(ctx context.Context, msg *wechat_ws
 
 		LabelLogs, err := svcCtx.DB.LabelLog.Query().
 			Where(labellog.LabelIDIn(ids...)).
+			Where(labellog.WxID(message.WeChatId)).
 			All(ctx)
 
 		if err != nil || len(LabelLogs) == 0 {
+			logx.Error("labelLog.Query.fail: 跳过 || 或者查询失败", wxInfo.OrganizationID)
 			continue
 		}
 
@@ -153,20 +157,36 @@ 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.StatusEQ(remoteLabel.LabelName),
 				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 +197,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)