|
@@ -5,6 +5,7 @@ import (
|
|
|
"database/sql"
|
|
|
"fmt"
|
|
|
"strings"
|
|
|
+ "sync"
|
|
|
|
|
|
util "app.yhyue.com/moapp/jybase/common"
|
|
|
. "app.yhyue.com/moapp/jybase/date"
|
|
@@ -187,29 +188,41 @@ func (i *InitNetwork) Init() {
|
|
|
}
|
|
|
//
|
|
|
nowFormat := NowFormat(Date_Full_Layout)
|
|
|
- values := []interface{}{}
|
|
|
+ newArray := []*Connection{}
|
|
|
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"}
|
|
|
- index := 0
|
|
|
- typeLimit := map[int]int{}
|
|
|
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 {
|
|
|
return false
|
|
|
}
|
|
|
- for _, v := range array {
|
|
|
- if v.Company_name == i.EntName || v.ContactInfo == nil || v.ContactInfo.Phone == "" || v.ContactInfo.Name == "" {
|
|
|
- continue
|
|
|
- } else if typeLimit[v.Itype] >= 100 {
|
|
|
+ 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 == "" {
|
|
|
continue
|
|
|
}
|
|
|
- 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 {
|
|
|
- typeLimit[v.Itype] = typeLimit[v.Itype] + 1
|
|
|
+ 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))
|
|
|
- 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)
|
|
|
- } else {
|
|
|
- logx.Info("过滤掉已存在的人脉", fmt.Sprintf("%+v", v))
|
|
|
- }
|
|
|
- index++
|
|
|
- if index == 200 {
|
|
|
+ newArray = append(newArray, v)
|
|
|
+ }(vt)
|
|
|
+ }
|
|
|
+ wait.Wait()
|
|
|
+ values := []interface{}{}
|
|
|
+ for _, v := range newArray {
|
|
|
+ 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 {
|
|
|
if r1, r2 := CrmMysql.InsertBatchByTx(tx, "crm.connection", fields, values); r1 <= 0 || r2 <= 0 {
|
|
|
return false
|
|
|
}
|