|
@@ -14,6 +14,7 @@ import (
|
|
|
"net/url"
|
|
|
"sort"
|
|
|
"strconv"
|
|
|
+ "strings"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
@@ -477,8 +478,8 @@ func SyncWhiteList(cont context.Context) (err error) {
|
|
|
fmt.Println("GetUserMobileFormal Err:", err.Error())
|
|
|
return
|
|
|
}
|
|
|
- addMobiles := make([]string, 0)
|
|
|
- addemails := make([]string, 0)
|
|
|
+ addMobiles := ""
|
|
|
+ addemails := ""
|
|
|
addList := make([]*models.ComeinWhiteUser, 0)
|
|
|
for _, v := range needAddList {
|
|
|
if _, ok := syncedMap[v.Mobile+v.Email]; !ok {
|
|
@@ -492,35 +493,43 @@ func SyncWhiteList(cont context.Context) (err error) {
|
|
|
|
|
|
|
|
|
if v.Mobile != "" {
|
|
|
- addMobiles = append(addMobiles,"'"+ v.Mobile+"'")
|
|
|
+ //addMobiles = append(addMobiles,"'"+ v.Mobile+"'")
|
|
|
+ addMobiles += "'"+ v.Mobile+"'"+","
|
|
|
} else if v.Email != "" {
|
|
|
- addemails = append(addemails,"'"+ v.Email+"'")
|
|
|
+ //addemails = append(addemails,"'"+ v.Email+"'")
|
|
|
+ addemails += "'"+ v.Email+"'"+","
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- err = models.AddComeinWhiteUserMulti(addList)
|
|
|
- if err != nil {
|
|
|
- fmt.Println("新增白名单失败,AddComeinWhiteUserMulti", err.Error())
|
|
|
- return
|
|
|
- }
|
|
|
- err = syncWhiteList(addMobiles,addemails, 1)
|
|
|
- if err != nil {
|
|
|
- fmt.Println("新增白名单失败", err.Error())
|
|
|
- return
|
|
|
+ addMobiles = strings.TrimSuffix(addMobiles, ",")
|
|
|
+ addemails = strings.TrimSuffix(addemails, ",")
|
|
|
+ if len(addList) > 0 {
|
|
|
+ err = models.AddComeinWhiteUserMulti(addList)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("新增白名单失败,AddComeinWhiteUserMulti", err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ err = syncWhiteList(addMobiles,addemails, 1)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("新增白名单失败", err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+
|
|
|
//拿联系人表,需要删除的
|
|
|
needDelList, err := models.GetUserMobileNotFormal()
|
|
|
if err != nil {
|
|
|
fmt.Println("GetUserMobileFormal Err:", err.Error())
|
|
|
return
|
|
|
}
|
|
|
- delMobiles := make([]string, 0)
|
|
|
- delEmials := make([]string, 0)
|
|
|
+ delMobiles := ""
|
|
|
+ delEmials := ""
|
|
|
delList := make([]*models.ComeinWhiteUser, 0)
|
|
|
for _, v := range needDelList {
|
|
|
if _, ok := syncedMap[v.Mobile+v.Email]; ok {
|
|
|
user := models.ComeinWhiteUser{
|
|
|
+ UserId: v.UserId,
|
|
|
Mobile: v.Mobile,
|
|
|
CountryCode: "+"+v.CountryCode,
|
|
|
Email: v.Email,
|
|
@@ -529,31 +538,35 @@ func SyncWhiteList(cont context.Context) (err error) {
|
|
|
delList = append(delList, &user)
|
|
|
|
|
|
if v.Mobile != "" {
|
|
|
- delMobiles = append(delMobiles, "'"+v.Mobile+"'")
|
|
|
+ //delMobiles = append(delMobiles, "'"+v.Mobile+"'")
|
|
|
+ delMobiles += "'"+v.Mobile+"'"+","
|
|
|
} else if v.Email != "" {
|
|
|
- delEmials = append(delEmials, "'"+v.Email+"'")
|
|
|
+ //delEmials = append(delEmials, "'"+v.Email+"'")
|
|
|
+ delEmials += "'"+v.Email+"'"+","
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- err = syncWhiteList(delMobiles, delEmials, 2)
|
|
|
- if err != nil {
|
|
|
- fmt.Println("删除白名单失败", err.Error())
|
|
|
- return
|
|
|
- }
|
|
|
- delIds := make([]int, 0)
|
|
|
- for _, v := range delList {
|
|
|
- delIds = append(delIds, v.UserId)
|
|
|
- }
|
|
|
- err = models.DelComeinWhiteUserMulti(delIds)
|
|
|
- if err != nil {
|
|
|
- fmt.Println("删除白名单失败,DelComeinWhiteUserMulti", err.Error())
|
|
|
- return
|
|
|
+ if len(delList) > 0 {
|
|
|
+ err = syncWhiteList(delMobiles, delEmials, 2)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("删除白名单失败", err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ delIds := make([]int, 0)
|
|
|
+ for _, v := range delList {
|
|
|
+ delIds = append(delIds, v.UserId)
|
|
|
+ }
|
|
|
+ err = models.DelComeinWhiteUserMulti(delIds)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("删除白名单失败,DelComeinWhiteUserMulti", err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-func syncWhiteList(mobiles, emails []string, opt int) (err error) {
|
|
|
+func syncWhiteList(mobiles, emails string, opt int) (err error) {
|
|
|
postUrl := utils.COMEIN_URL
|
|
|
|
|
|
timestamp := fmt.Sprintf("%d", time.Now().UnixNano()/1e6)
|