|
@@ -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
|