|
@@ -1,11 +1,15 @@
|
|
|
package contact
|
|
|
|
|
|
import (
|
|
|
+ "bytes"
|
|
|
"context"
|
|
|
"encoding/csv"
|
|
|
"fmt"
|
|
|
"github.com/suyuan32/simple-admin-common/msg/errormsg"
|
|
|
"github.com/suyuan32/simple-admin-common/utils/uuidx"
|
|
|
+ "golang.org/x/text/encoding/simplifiedchinese"
|
|
|
+ "golang.org/x/text/transform"
|
|
|
+ "io"
|
|
|
"mime/multipart"
|
|
|
"strconv"
|
|
|
"strings"
|
|
@@ -50,21 +54,22 @@ func (l *ImportWhatsappContactLogic) ImportWhatsappContact(req *types.ImportWhat
|
|
|
uuidstr := uuidx.NewUUID().String()
|
|
|
sex, _ := strconv.Atoi(trim(record[5]))
|
|
|
cage, _ := strconv.Atoi(trim(record[7]))
|
|
|
+
|
|
|
newContact, err := l.svcCtx.DB.Contact.Create().SetCtype(2).
|
|
|
SetCc(record[0]).
|
|
|
SetPhone(record[1]).
|
|
|
SetType(5).
|
|
|
SetWxWxid(uuidstr).
|
|
|
SetWxid(uuidstr).
|
|
|
- SetCname(trim(record[2])).
|
|
|
- SetMarkname(trim(record[3])).
|
|
|
+ SetCname(transCharset(record[2])).
|
|
|
+ SetMarkname(transCharset(record[3])).
|
|
|
SetSex(sex).
|
|
|
SetCage(cage).
|
|
|
- SetCtitle(trim(record[6])).
|
|
|
- SetCarea(trim(record[9])).
|
|
|
- SetCbirthday(trim(record[8])).
|
|
|
- SetCbirtharea(trim(record[10])).
|
|
|
- SetCidcardNo(trim(record[11])).
|
|
|
+ SetCtitle(transCharset(record[6])).
|
|
|
+ SetCarea(transCharset(record[9])).
|
|
|
+ SetCbirthday(transCharset(record[8])).
|
|
|
+ SetCbirtharea(transCharset(record[10])).
|
|
|
+ SetCidcardNo(transCharset(record[11])).
|
|
|
SetOrganizationID(organizationId).
|
|
|
Save(l.ctx)
|
|
|
if err != nil {
|
|
@@ -109,3 +114,10 @@ func (l *ImportWhatsappContactLogic) ImportWhatsappContact(req *types.ImportWhat
|
|
|
func trim(s string) string {
|
|
|
return strings.Trim(s, " \r\n\t")
|
|
|
}
|
|
|
+
|
|
|
+func transCharset(s string) string {
|
|
|
+ s = trim(s)
|
|
|
+ rd := transform.NewReader(bytes.NewReader([]byte(s)), simplifiedchinese.GBK.NewDecoder())
|
|
|
+ bytes, _ := io.ReadAll(rd)
|
|
|
+ return string(bytes)
|
|
|
+}
|