|
@@ -13,6 +13,10 @@ import (
|
|
|
"mime/multipart"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
+ "time"
|
|
|
+ "wechat-api/ent"
|
|
|
+ "wechat-api/ent/contact"
|
|
|
+ "wechat-api/ent/label"
|
|
|
"wechat-api/internal/svc"
|
|
|
"wechat-api/internal/types"
|
|
|
|
|
@@ -46,18 +50,34 @@ func (l *ImportWhatsappContactLogic) ImportWhatsappContact(req *types.ImportWhat
|
|
|
var total, success, fail, add_labels int
|
|
|
var conditions = "{}"
|
|
|
for idx, record := range records {
|
|
|
+ l.Logger.Infof("record=%v\n", record)
|
|
|
if idx == 0 {
|
|
|
continue
|
|
|
}
|
|
|
total++
|
|
|
|
|
|
+ _, err := l.svcCtx.DB.Contact.Query().Where(
|
|
|
+ contact.OrganizationID(organizationId),
|
|
|
+ contact.Ctype(2),
|
|
|
+ contact.Cc(trim(record[0])),
|
|
|
+ contact.Phone(trim(record[1])),
|
|
|
+ ).First(l.ctx)
|
|
|
+ if err == nil || !ent.IsNotFound(err) {
|
|
|
+ fail++
|
|
|
+ continue
|
|
|
+ }
|
|
|
+
|
|
|
uuidstr := uuidx.NewUUID().String()
|
|
|
sex, _ := strconv.Atoi(trim(record[5]))
|
|
|
cage, _ := strconv.Atoi(trim(record[7]))
|
|
|
-
|
|
|
+ var cbirthday string
|
|
|
+ t, err := time.Parse("2006/01/02", trim(record[8]))
|
|
|
+ if err == nil {
|
|
|
+ cbirthday = t.Format("2006-01-02")
|
|
|
+ }
|
|
|
newContact, err := l.svcCtx.DB.Contact.Create().SetCtype(2).
|
|
|
- SetCc(record[0]).
|
|
|
- SetPhone(record[1]).
|
|
|
+ SetCc(trim(record[0])).
|
|
|
+ SetPhone(trim(record[1])).
|
|
|
SetType(5).
|
|
|
SetWxWxid(uuidstr).
|
|
|
SetWxid(uuidstr).
|
|
@@ -67,14 +87,15 @@ func (l *ImportWhatsappContactLogic) ImportWhatsappContact(req *types.ImportWhat
|
|
|
SetCage(cage).
|
|
|
SetCtitle(transCharset(record[6])).
|
|
|
SetCarea(transCharset(record[9])).
|
|
|
- SetCbirthday(transCharset(record[8])).
|
|
|
+ SetCbirthday(cbirthday).
|
|
|
SetCbirtharea(transCharset(record[10])).
|
|
|
- SetCidcardNo(transCharset(record[11])).
|
|
|
+ SetCidcardNo(trim(record[11])).
|
|
|
SetOrganizationID(organizationId).
|
|
|
Save(l.ctx)
|
|
|
if err != nil {
|
|
|
- l.Logger.Error("insert to whatsapp contact failed. err=%v\n", err)
|
|
|
+ l.Logger.Errorf("insert to whatsapp contact failed. err=%v\n", err)
|
|
|
fail++
|
|
|
+ continue
|
|
|
} else {
|
|
|
success++
|
|
|
}
|
|
@@ -82,6 +103,15 @@ func (l *ImportWhatsappContactLogic) ImportWhatsappContact(req *types.ImportWhat
|
|
|
labels := trim(record[4])
|
|
|
if labels != "" {
|
|
|
for _, value := range strings.Split(labels, "+") {
|
|
|
+ _, err = l.svcCtx.DB.Label.Query().Where(
|
|
|
+ label.Ctype(2),
|
|
|
+ label.OrganizationID(organizationId),
|
|
|
+ label.Name(value),
|
|
|
+ ).First(l.ctx)
|
|
|
+ if err == nil || !ent.IsNotFound(err) {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+
|
|
|
newLabel, err := l.svcCtx.DB.Label.Create().SetCtype(2).
|
|
|
SetName(value).
|
|
|
SetType(5).
|