|
@@ -202,6 +202,10 @@ func (l *AnalyzeContactField) Analyze(bot_wxid *string, contact_wxid *string) {
|
|
|
}
|
|
|
logx.Info("usageDetails: ", usageDetails)
|
|
|
for botID, template := range contactFieldTemplates {
|
|
|
+ templatesSet := map[string]custom_types.ContactFieldTemplate{}
|
|
|
+ for _, t := range template {
|
|
|
+ templatesSet[*t.Id] = t
|
|
|
+ }
|
|
|
if template == nil {
|
|
|
template = contactBasicFieldTemplates
|
|
|
} else {
|
|
@@ -215,7 +219,7 @@ func (l *AnalyzeContactField) Analyze(bot_wxid *string, contact_wxid *string) {
|
|
|
if result == nil {
|
|
|
continue
|
|
|
}
|
|
|
- _ = l.UpdateContactFields(botID, receiverID, result)
|
|
|
+ _ = l.UpdateContactFields(botID, receiverID, result, templatesSet)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -318,7 +322,7 @@ func (l *AnalyzeContactField) openaiRequest(messages string, template []custom_t
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
-func (l *AnalyzeContactField) UpdateContactFields(botID string, receiverID string, fields []ResponseItem) error {
|
|
|
+func (l *AnalyzeContactField) UpdateContactFields(botID string, receiverID string, fields []ResponseItem, templatesSet map[string]custom_types.ContactFieldTemplate) error {
|
|
|
basic_ids := []string{"sex", "phone", "name", "age", "area", "birthday", "birtharea", "idcard_no", "title"}
|
|
|
c, _ := l.svcCtx.DB.Contact.Query().Where(contact.WxWxidEQ(botID), contact.WxidEQ(receiverID)).First(l.ctx)
|
|
|
if c == nil {
|
|
@@ -413,25 +417,43 @@ func (l *AnalyzeContactField) UpdateContactFields(botID string, receiverID strin
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
- f, _ := l.svcCtx.DB.ContactField.Query().Where(contactfield.ContactID(c.ID), contactfield.FormID(field.DataIndex)).First(l.ctx)
|
|
|
- if f == nil {
|
|
|
- if field.Value != nil && len(field.Value) > 0 && field.Value[0] != "" {
|
|
|
- _, err := l.svcCtx.DB.ContactField.Create().
|
|
|
- SetContactID(c.ID).
|
|
|
- SetFormID(field.DataIndex).
|
|
|
- SetValue(field.Value).
|
|
|
- Save(l.ctx)
|
|
|
- if err != nil {
|
|
|
- continue
|
|
|
+ values := []string{}
|
|
|
+ template, exists := templatesSet[field.DataIndex]
|
|
|
+ if exists {
|
|
|
+ if template.Options != nil {
|
|
|
+ for _, option := range template.Options {
|
|
|
+ for _, v := range field.Value {
|
|
|
+ if v == *option.Value {
|
|
|
+ values = append(values, v)
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
+ } else {
|
|
|
+ values = field.Value
|
|
|
+ }
|
|
|
+ if len(values) == 0 {
|
|
|
+ continue
|
|
|
}
|
|
|
- } else if len(f.Value) == 0 || f.Value[0] == "" {
|
|
|
- if field.Value != nil && len(field.Value) > 0 && field.Value[0] != "" {
|
|
|
- _, err := l.svcCtx.DB.ContactField.UpdateOneID(f.ID).
|
|
|
- SetValue(field.Value).
|
|
|
- Save(l.ctx)
|
|
|
- if err != nil {
|
|
|
- continue
|
|
|
+ f, _ := l.svcCtx.DB.ContactField.Query().Where(contactfield.ContactID(c.ID), contactfield.FormID(field.DataIndex)).First(l.ctx)
|
|
|
+ if f == nil {
|
|
|
+ if values != nil && len(values) > 0 && values[0] != "" {
|
|
|
+ _, err := l.svcCtx.DB.ContactField.Create().
|
|
|
+ SetContactID(c.ID).
|
|
|
+ SetFormID(field.DataIndex).
|
|
|
+ SetValue(values).
|
|
|
+ Save(l.ctx)
|
|
|
+ if err != nil {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if len(f.Value) == 0 || f.Value[0] == "" {
|
|
|
+ if values != nil && len(values) > 0 && values[0] != "" {
|
|
|
+ _, err := l.svcCtx.DB.ContactField.UpdateOneID(f.ID).
|
|
|
+ SetValue(values).
|
|
|
+ Save(l.ctx)
|
|
|
+ if err != nil {
|
|
|
+ continue
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|