|
@@ -5,7 +5,6 @@ import (
|
|
"database/sql"
|
|
"database/sql"
|
|
"fmt"
|
|
"fmt"
|
|
"strings"
|
|
"strings"
|
|
- "sync"
|
|
|
|
|
|
|
|
util "app.yhyue.com/moapp/jybase/common"
|
|
util "app.yhyue.com/moapp/jybase/common"
|
|
. "app.yhyue.com/moapp/jybase/date"
|
|
. "app.yhyue.com/moapp/jybase/date"
|
|
@@ -188,48 +187,38 @@ func (i *InitNetwork) Init() {
|
|
}
|
|
}
|
|
//
|
|
//
|
|
nowFormat := NowFormat(Date_Full_Layout)
|
|
nowFormat := NowFormat(Date_Full_Layout)
|
|
- newArray := []*Connection{}
|
|
|
|
|
|
+ values := []interface{}{}
|
|
|
|
+ index := 0
|
|
fields := []string{"position_id", "ent_id", "ent_dept_id", "ent_user_id", "itype", "company_name", "company_id", "qyxy_id", "contact_person", "contact_phone", "status", "source", "create_time", "update_time"}
|
|
fields := []string{"position_id", "ent_id", "ent_dept_id", "ent_user_id", "itype", "company_name", "company_id", "qyxy_id", "contact_person", "contact_phone", "status", "source", "create_time", "update_time"}
|
|
if CrmMysql.ExecTx("初始化人脉", func(tx *sql.Tx) bool {
|
|
if CrmMysql.ExecTx("初始化人脉", func(tx *sql.Tx) bool {
|
|
if CrmMysql.UpdateOrDeleteBySqlByTx(tx, `delete from crm.connection where position_id=? and source=1`, i.PositionId) < 0 {
|
|
if CrmMysql.UpdateOrDeleteBySqlByTx(tx, `delete from crm.connection where position_id=? and source=1`, i.PositionId) < 0 {
|
|
return false
|
|
return false
|
|
}
|
|
}
|
|
- pool := make(chan bool, C.PoolSize)
|
|
|
|
- lock := &sync.Mutex{}
|
|
|
|
- wait := &sync.WaitGroup{}
|
|
|
|
- for _, vt := range array {
|
|
|
|
- if vt.Company_name == i.EntName || vt.ContactInfo == nil || vt.ContactInfo.Phone == "" || vt.ContactInfo.Name == "" {
|
|
|
|
|
|
+ allcon := map[string]bool{}
|
|
|
|
+ CrmMysql.SelectByBathByTx(1, func(l *[]map[string]interface{}) bool {
|
|
|
|
+ allcon[fmt.Sprintf("%s_%d", util.ObjToString((*l)[0]["company_id"]), util.Int64All((*l)[0]["itype"]))] = true
|
|
|
|
+ return true
|
|
|
|
+ }, tx, `select company_id,itype from crm.connection where position_id=?`, i.PositionId)
|
|
|
|
+ for _, v := range array {
|
|
|
|
+ if v.Company_name == i.EntName || v.ContactInfo == nil || v.ContactInfo.Phone == "" || v.ContactInfo.Name == "" {
|
|
continue
|
|
continue
|
|
}
|
|
}
|
|
- pool <- true
|
|
|
|
- wait.Add(1)
|
|
|
|
- go func(v *Connection) {
|
|
|
|
- defer func() {
|
|
|
|
- <-pool
|
|
|
|
- wait.Done()
|
|
|
|
- }()
|
|
|
|
- if CrmMysql.CountBySqlByTx(tx, `select count(1) from crm.connection where position_id=? and company_id=? and itype=?`, i.PositionId, v.Company_id, v.Itype) != 0 {
|
|
|
|
- logx.Info("过滤掉已存在的人脉", fmt.Sprintf("%+v", v))
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
- lock.Lock()
|
|
|
|
- defer lock.Unlock()
|
|
|
|
- logx.Info("保存人脉", fmt.Sprintf("%+v", v))
|
|
|
|
- newArray = append(newArray, v)
|
|
|
|
- }(vt)
|
|
|
|
- }
|
|
|
|
- wait.Wait()
|
|
|
|
- values := []interface{}{}
|
|
|
|
- for _, v := range newArray {
|
|
|
|
|
|
+ if allcon[fmt.Sprintf("%s_%d", v.Company_id, v.Itype)] {
|
|
|
|
+ logx.Info("过滤掉已存在的人脉", fmt.Sprintf("%+v", v))
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+ logx.Info("保存人脉", fmt.Sprintf("%+v", v))
|
|
values = append(values, i.PositionId, i.EntId, i.DeptId, i.UserId, v.Itype, v.Company_name, v.Company_id, v.QyxyId, v.ContactInfo.Name, v.ContactInfo.Phone, 1, 1, nowFormat, nowFormat)
|
|
values = append(values, i.PositionId, i.EntId, i.DeptId, i.UserId, v.Itype, v.Company_name, v.Company_id, v.QyxyId, v.ContactInfo.Name, v.ContactInfo.Phone, 1, 1, nowFormat, nowFormat)
|
|
- if len(values) == 200 {
|
|
|
|
|
|
+ index++
|
|
|
|
+ if index == 200 {
|
|
if r1, r2 := CrmMysql.InsertBatchByTx(tx, "crm.connection", fields, values); r1 <= 0 || r2 <= 0 {
|
|
if r1, r2 := CrmMysql.InsertBatchByTx(tx, "crm.connection", fields, values); r1 <= 0 || r2 <= 0 {
|
|
return false
|
|
return false
|
|
}
|
|
}
|
|
|
|
+ index = 0
|
|
values = []interface{}{}
|
|
values = []interface{}{}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- if len(values) > 0 {
|
|
|
|
|
|
+ if index > 0 {
|
|
if r1, r2 := CrmMysql.InsertBatchByTx(tx, "crm.connection", fields, values); r1 <= 0 || r2 <= 0 {
|
|
if r1, r2 := CrmMysql.InsertBatchByTx(tx, "crm.connection", fields, values); r1 <= 0 || r2 <= 0 {
|
|
return false
|
|
return false
|
|
}
|
|
}
|