Browse Source

合并 fixbug/632-bowen-wx-org-change

boweniac 2 days ago
parent
commit
2c6cd20680

+ 4 - 2
internal/logic/Wx/change_organization_logic.go

@@ -34,13 +34,14 @@ func (l *ChangeOrganizationLogic) ChangeOrganization(req *types.WxInfo) (resp *t
 
 	tx, err := l.svcCtx.DB.Tx(l.ctx)
 	if err != nil {
+		logx.Info("err: ", err)
 		return nil, err
 	}
-	defer tx.Rollback()
 
 	change := wechat.WxSafeChange{Ctx: l.ctx, Tx: tx, WxId: *req.Wxid, OrganizationId: *req.OrganizationId}
 	err = change.KeepAllSafe()
 	if err != nil {
+		logx.Info("Rollback: ", err)
 		_ = tx.Rollback()
 		return nil, err
 	}
@@ -49,10 +50,11 @@ func (l *ChangeOrganizationLogic) ChangeOrganization(req *types.WxInfo) (resp *t
 		SetNotNilOrganizationID(req.OrganizationId).
 		Save(l.ctx)
 	if err != nil {
+		logx.Info("Rollback: ", err)
 		_ = tx.Rollback()
 		return nil, err
 	}
-
+	logx.Info("Commit: ")
 	err = tx.Commit()
 	if err != nil {
 		return nil, err

+ 1 - 1
internal/logic/contact/get_contact_list_logic.go

@@ -57,7 +57,7 @@ func (l *GetContactListLogic) GetContactList(req *types.ContactListReq) (*types.
 	wxslist := make([]string, 0)
 
 	var predicates []predicate.Contact
-	if req.WxWxid == nil {
+	if req.WxWxid == nil || *req.WxWxid == "" {
 		wxsInfo, err := l.svcCtx.DB.Wx.Query().
 			Where(
 				wx.OrganizationIDEQ(organizationId),

+ 1 - 1
internal/logic/label/get_label_contacts_logic.go

@@ -74,7 +74,7 @@ func (l *GetLabelContactsLogic) GetLabelContacts(req *types.LabelListReq) (*type
 						CreatedAt: pointy.GetPointer(lr.CreatedAt.UnixMilli()),
 						UpdatedAt: pointy.GetPointer(lr.UpdatedAt.UnixMilli()),
 					},
-					Status:    &lr.Status,
+					//Status:    &lr.Status,
 					LabelId:   &lr.LabelID,
 					ContactId: &lr.ContactID,
 					Contact:   convertContactToContactInfo(lr.Edges.Contacts),

+ 1 - 1
internal/logic/label_relationship/create_label_relationship_logic.go

@@ -29,7 +29,7 @@ func NewCreateLabelRelationshipLogic(ctx context.Context, svcCtx *svc.ServiceCon
 func (l *CreateLabelRelationshipLogic) CreateLabelRelationship(req *types.LabelRelationshipInfo) (*types.BaseMsgResp, error) {
 	organizationId := l.ctx.Value("organizationId").(uint64)
 	_, err := l.svcCtx.DB.LabelRelationship.Create().
-		SetNotNilStatus(req.Status).
+		//SetNotNilStatus(req.Status).
 		SetNotNilLabelID(req.LabelId).
 		SetNotNilContactID(req.ContactId).
 		SetOrganizationID(organizationId).

+ 1 - 1
internal/logic/label_relationship/get_label_relationship_by_id_logic.go

@@ -51,7 +51,7 @@ func (l *GetLabelRelationshipByIdLogic) GetLabelRelationshipById(req *types.IDRe
 				CreatedAt: pointy.GetPointer(data.CreatedAt.UnixMilli()),
 				UpdatedAt: pointy.GetPointer(data.UpdatedAt.UnixMilli()),
 			},
-			Status:    &data.Status,
+			//Status:    &data.Status,
 			LabelId:   &data.LabelID,
 			ContactId: &data.ContactID,
 		},

+ 1 - 1
internal/logic/label_relationship/get_label_relationship_list_logic.go

@@ -149,7 +149,7 @@ func (l *GetLabelRelationshipListLogic) GetLabelRelationshipList(req *types.Labe
 					CreatedAt: pointy.GetPointer(v.CreatedAt.UnixMilli()),
 					UpdatedAt: pointy.GetPointer(v.UpdatedAt.UnixMilli()),
 				},
-				Status:             &v.Status,
+				//Status:             &v.Status,
 				WxWxid:             &c.WxWxid,
 				WxWxidNickname:     &wwx.Nickname,
 				Type:               &c.Type,

+ 1 - 1
internal/logic/label_relationship/update_label_relationship_logic.go

@@ -30,7 +30,7 @@ func (l *UpdateLabelRelationshipLogic) UpdateLabelRelationship(req *types.LabelR
 	organizationId := l.ctx.Value("organizationId").(uint64)
 	err := l.svcCtx.DB.LabelRelationship.UpdateOneID(*req.Id).
 		Where(labelrelationship.OrganizationID(organizationId)).
-		SetNotNilStatus(req.Status).
+		//SetNotNilStatus(req.Status).
 		SetNotNilLabelID(req.LabelId).
 		SetNotNilContactID(req.ContactId).
 		Exec(l.ctx)

+ 20 - 3
internal/service/wechat/wx_safe_change.go

@@ -228,31 +228,48 @@ func (w *WxSafeChange) LabelSafe() error {
 	if err != nil {
 		return err
 	}
-
+	logx.Info("w.OrganizationId: ", w.OrganizationId)
 	for _, relationship := range labelRelationships {
+		logx.Info("relationship.Edges.Labels.Name: ", relationship.Edges.Labels.Name)
+		logx.Info("labelSet[relationship.Edges.Labels.Name]: ", labelSet[relationship.Edges.Labels.Name])
+		logx.Info("relationship.Edges.Contacts.ID: ", relationship.Edges.Contacts.ID)
 		if relationship.Edges.Labels == nil {
 			continue
 		}
+		//err = w.Tx.LabelRelationship.Create().
+		//	SetLabelID(labelSet[relationship.Edges.Labels.Name]).
+		//	SetContactID(relationship.Edges.Contacts.ID).
+		//	SetOrganizationID(w.OrganizationId).
+		//	OnConflict(
+		//		// 这里需要数据库中存在唯一约束,如 label_id + contact_id
+		//		sql.ConflictColumns("label_id", "contact_id"),
+		//	).
+		//	DoNothing().
+		//	Exec(w.Ctx)
 		_, err = w.Tx.LabelRelationship.Create().
 			SetLabelID(labelSet[relationship.Edges.Labels.Name]).
 			SetContactID(relationship.Edges.Contacts.ID).
+			SetOrganizationID(w.OrganizationId).
 			Save(w.Ctx)
 		if err != nil {
-			return err
+			logx.Info("err: ", err)
+			continue
 		}
 	}
 
 	// 删除旧的标签关系
+	logx.Info("wxinfo.OrganizationID: ", wxinfo.OrganizationID)
 	_, err = w.Tx.LabelRelationship.Delete().
 		Where(
 			//labelrelationship.DeletedAtIsNil(),
 			labelrelationship.HasLabelsWith(
-				label.OrganizationIDNEQ(wxinfo.OrganizationID)),
+				label.OrganizationIDEQ(wxinfo.OrganizationID)),
 			labelrelationship.HasContactsWith(
 				contact.WxWxidEQ(w.WxId),
 			),
 		).Exec(w.Ctx)
 	if err != nil {
+		logx.Info("err: ", err)
 		return err
 	}
 	return nil