批量更新功能
This commit is contained in:
@@ -161,6 +161,30 @@ func mobileInMobiles(mobile, mobiles string) bool {
|
||||
return strings.Contains(mobiles, mobile)
|
||||
}
|
||||
|
||||
// entityContactMobiles 过程库联系人的手机号集合(JSON 数组字符串):
|
||||
// 优先取新的 mobiles 字段,缺省时回退旧的单个 mobile。
|
||||
func entityContactMobiles(src models.TenantCrmEntityContact) string {
|
||||
if s := strings.TrimSpace(src.Mobiles); s != "" {
|
||||
return s
|
||||
}
|
||||
return buildMobiles(src.Mobile)
|
||||
}
|
||||
|
||||
// mobilesMatched 判断两组手机号是否有交集(JSON 数组或分隔符字符串)
|
||||
func mobilesMatched(a, b string) bool {
|
||||
for _, x := range splitMobiles(a) {
|
||||
if x == "" {
|
||||
continue
|
||||
}
|
||||
for _, y := range splitMobiles(b) {
|
||||
if x == y {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// mergeCompanyContact 合并过程库联系人到正式库联系人:仅补齐正式库空缺字段,不覆盖已有数据。
|
||||
func mergeCompanyContact(dst *models.ErpCompanyContact, src models.TenantCrmEntityContact) {
|
||||
changed := false
|
||||
@@ -180,9 +204,11 @@ func mergeCompanyContact(dst *models.ErpCompanyContact, src models.TenantCrmEnti
|
||||
dst.Position = strings.TrimSpace(src.Position)
|
||||
changed = true
|
||||
}
|
||||
if strings.TrimSpace(dst.Mobiles) == "" && strings.TrimSpace(src.Mobile) != "" {
|
||||
dst.Mobiles = buildMobiles(src.Mobile)
|
||||
changed = true
|
||||
if strings.TrimSpace(dst.Mobiles) == "" {
|
||||
if m := entityContactMobiles(src); m != "" {
|
||||
dst.Mobiles = m
|
||||
changed = true
|
||||
}
|
||||
}
|
||||
if dst.Remark == "" && strings.TrimSpace(src.Remark) != "" {
|
||||
dst.Remark = strings.TrimSpace(src.Remark)
|
||||
@@ -213,7 +239,8 @@ func syncContactsToCompany(tenantID string, customerID uint64, contacts []models
|
||||
if name == "" {
|
||||
continue
|
||||
}
|
||||
mobile := strings.TrimSpace(src.Mobile)
|
||||
mobiles := entityContactMobiles(src)
|
||||
mobile := firstMobile(mobiles)
|
||||
// 本次待同步集合内去重(同名同手机只处理一次)
|
||||
key := name + "|" + mobile
|
||||
if seen[key] {
|
||||
@@ -232,8 +259,8 @@ func syncContactsToCompany(tenantID string, customerID uint64, contacts []models
|
||||
|
||||
matched := false
|
||||
for i := range existingList {
|
||||
// 有手机号时必须手机号匹配;无手机号时按同名视为同一人
|
||||
if mobile == "" || mobileInMobiles(mobile, existingList[i].Mobiles) {
|
||||
// 有手机号时手机号需有交集才视为同一人;无手机号时按同名视为同一人
|
||||
if mobile == "" || mobilesMatched(mobiles, existingList[i].Mobiles) {
|
||||
mergeCompanyContact(&existingList[i], src)
|
||||
merged++
|
||||
matched = true
|
||||
@@ -250,7 +277,7 @@ func syncContactsToCompany(tenantID string, customerID uint64, contacts []models
|
||||
CompanyID: customerID,
|
||||
Name: name,
|
||||
Phone: "",
|
||||
Mobiles: buildMobiles(mobile),
|
||||
Mobiles: mobiles,
|
||||
Wechat: strings.TrimSpace(src.Wechat),
|
||||
QQ: strings.TrimSpace(src.QQ),
|
||||
Email: strings.TrimSpace(src.Email),
|
||||
|
||||
Reference in New Issue
Block a user