|
@@ -1,15 +1,11 @@
|
|
package contact
|
|
package contact
|
|
|
|
|
|
import (
|
|
import (
|
|
- "bytes"
|
|
|
|
"context"
|
|
"context"
|
|
"encoding/csv"
|
|
"encoding/csv"
|
|
"fmt"
|
|
"fmt"
|
|
"github.com/suyuan32/simple-admin-common/msg/errormsg"
|
|
"github.com/suyuan32/simple-admin-common/msg/errormsg"
|
|
"github.com/suyuan32/simple-admin-common/utils/uuidx"
|
|
"github.com/suyuan32/simple-admin-common/utils/uuidx"
|
|
- "golang.org/x/text/encoding/simplifiedchinese"
|
|
|
|
- "golang.org/x/text/transform"
|
|
|
|
- "io"
|
|
|
|
"mime/multipart"
|
|
"mime/multipart"
|
|
"strconv"
|
|
"strconv"
|
|
"strings"
|
|
"strings"
|
|
@@ -19,6 +15,7 @@ import (
|
|
"wechat-api/ent/label"
|
|
"wechat-api/ent/label"
|
|
"wechat-api/internal/svc"
|
|
"wechat-api/internal/svc"
|
|
"wechat-api/internal/types"
|
|
"wechat-api/internal/types"
|
|
|
|
+ "wechat-api/internal/utils"
|
|
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
)
|
|
@@ -59,8 +56,8 @@ func (l *ImportWhatsappContactLogic) ImportWhatsappContact(req *types.ImportWhat
|
|
_, err := l.svcCtx.DB.Contact.Query().Where(
|
|
_, err := l.svcCtx.DB.Contact.Query().Where(
|
|
contact.OrganizationID(organizationId),
|
|
contact.OrganizationID(organizationId),
|
|
contact.Ctype(2),
|
|
contact.Ctype(2),
|
|
- contact.Cc(trim(record[0])),
|
|
|
|
- contact.Phone(trim(record[1])),
|
|
|
|
|
|
+ contact.Cc(utils.Trim(record[0])),
|
|
|
|
+ contact.Phone(utils.Trim(record[1])),
|
|
).First(l.ctx)
|
|
).First(l.ctx)
|
|
if err == nil || !ent.IsNotFound(err) {
|
|
if err == nil || !ent.IsNotFound(err) {
|
|
fail++
|
|
fail++
|
|
@@ -68,16 +65,16 @@ func (l *ImportWhatsappContactLogic) ImportWhatsappContact(req *types.ImportWhat
|
|
}
|
|
}
|
|
|
|
|
|
uuidstr := uuidx.NewUUID().String()
|
|
uuidstr := uuidx.NewUUID().String()
|
|
- sex, _ := strconv.Atoi(trim(record[5]))
|
|
|
|
- cage, _ := strconv.Atoi(trim(record[7]))
|
|
|
|
|
|
+ sex, _ := strconv.Atoi(utils.Trim(record[5]))
|
|
|
|
+ cage, _ := strconv.Atoi(utils.Trim(record[7]))
|
|
var cbirthday string
|
|
var cbirthday string
|
|
- t, err := time.Parse("2006/01/02", trim(record[8]))
|
|
|
|
|
|
+ t, err := time.Parse("2006/01/02", utils.Trim(record[8]))
|
|
if err == nil {
|
|
if err == nil {
|
|
cbirthday = t.Format("2006-01-02")
|
|
cbirthday = t.Format("2006-01-02")
|
|
}
|
|
}
|
|
newContact, err := l.svcCtx.DB.Contact.Create().SetCtype(2).
|
|
newContact, err := l.svcCtx.DB.Contact.Create().SetCtype(2).
|
|
- SetCc(trim(record[0])).
|
|
|
|
- SetPhone(trim(record[1])).
|
|
|
|
|
|
+ SetCc(utils.Trim(record[0])).
|
|
|
|
+ SetPhone(utils.Trim(record[1])).
|
|
SetType(5).
|
|
SetType(5).
|
|
SetWxWxid(uuidstr).
|
|
SetWxWxid(uuidstr).
|
|
SetWxid(uuidstr).
|
|
SetWxid(uuidstr).
|
|
@@ -89,7 +86,7 @@ func (l *ImportWhatsappContactLogic) ImportWhatsappContact(req *types.ImportWhat
|
|
SetCarea(transCharset(record[9])).
|
|
SetCarea(transCharset(record[9])).
|
|
SetCbirthday(cbirthday).
|
|
SetCbirthday(cbirthday).
|
|
SetCbirtharea(transCharset(record[10])).
|
|
SetCbirtharea(transCharset(record[10])).
|
|
- SetCidcardNo(trim(record[11])).
|
|
|
|
|
|
+ SetCidcardNo(utils.Trim(record[11])).
|
|
SetOrganizationID(organizationId).
|
|
SetOrganizationID(organizationId).
|
|
Save(l.ctx)
|
|
Save(l.ctx)
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -100,7 +97,7 @@ func (l *ImportWhatsappContactLogic) ImportWhatsappContact(req *types.ImportWhat
|
|
success++
|
|
success++
|
|
}
|
|
}
|
|
|
|
|
|
- labels := trim(record[4])
|
|
|
|
|
|
+ labels := utils.Trim(record[4])
|
|
if labels != "" {
|
|
if labels != "" {
|
|
for _, value := range strings.Split(labels, "+") {
|
|
for _, value := range strings.Split(labels, "+") {
|
|
_, err = l.svcCtx.DB.Label.Query().Where(
|
|
_, err = l.svcCtx.DB.Label.Query().Where(
|
|
@@ -140,15 +137,6 @@ func (l *ImportWhatsappContactLogic) ImportWhatsappContact(req *types.ImportWhat
|
|
return &resp, nil
|
|
return &resp, nil
|
|
}
|
|
}
|
|
|
|
|
|
-func trim(s string) string {
|
|
|
|
- return strings.Trim(s, " \r\n\t")
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
func transCharset(s string) string {
|
|
func transCharset(s string) string {
|
|
- s = trim(s)
|
|
|
|
- return s
|
|
|
|
- rd := transform.NewReader(bytes.NewReader([]byte(s)), simplifiedchinese.GBK.NewDecoder())
|
|
|
|
- bytes, err := io.ReadAll(rd)
|
|
|
|
- fmt.Printf("bytes=%s err=%v\n", bytes, err)
|
|
|
|
- return string(bytes)
|
|
|
|
|
|
+ return utils.TransCharset(s)
|
|
}
|
|
}
|