瀏覽代碼

feat:xiugai

wangchuanjin 9 月之前
父節點
當前提交
1db21bd74b
共有 4 個文件被更改,包括 37 次插入24 次删除
  1. 1 1
      api/etc/networkmanage.yaml
  2. 6 6
      api/internal/config/config.go
  3. 28 15
      api/internal/service/initNetwork.go
  4. 2 2
      api/internal/service/network.go

+ 1 - 1
api/etc/networkmanage.yaml

@@ -8,7 +8,7 @@ Gateway:
     - 127.0.0.1:2379
 CacheTimeOut: "01:00"
 SelectBatchSize: 200
-ExportIdCachaPoolSize: 3
+PoolSize: 3
 ProjectYearLimit: 13
 InitNetworkMaxSize: 50
 EntNameList: ["思特威(上海)电子科技股份有限公司","浙江宇视科技有限公司","广州敏视数码科技有限公司","安徽创世科技股份有限公司","深圳市同为数码科技股份有限公司",

+ 6 - 6
api/internal/config/config.go

@@ -11,12 +11,12 @@ type Config struct {
 		ServerCode string
 		Etcd       []string
 	}
-	CacheTimeOut          string
-	SelectBatchSize       int
-	ExportIdCachaPoolSize int
-	ProjectYearLimit      int
-	EntNameList           []string
-	InitNetworkMaxSize    int
+	CacheTimeOut       string
+	SelectBatchSize    int
+	PoolSize           int
+	ProjectYearLimit   int
+	EntNameList        []string
+	InitNetworkMaxSize int
 }
 
 type Db struct {

+ 28 - 15
api/internal/service/initNetwork.go

@@ -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
 				}

+ 2 - 2
api/internal/service/network.go

@@ -662,7 +662,7 @@ func (n *network) AllProject(in *types.AllprojectReq) (reply *types.Reply) {
 			}
 		} else {
 			for _, v := range *parentConvList {
-				if (*parentConvList)[0].NAME != v.SZ_PID0 {
+				if (*parentConvList)[0].NAME != v.SZ_PID0 || v.SZ_LEVEL == 0 {
 					continue
 				}
 				newCheckCode = append(newCheckCode, v.CODE)
@@ -944,7 +944,7 @@ func (n *network) List(in *types.NetWorkListReq) *types.Reply {
 	} else {
 		finalList = csList.List
 	}
-	pool := make(chan bool, C.ExportIdCachaPoolSize)
+	pool := make(chan bool, C.PoolSize)
 	wait := &sync.WaitGroup{}
 	for _, v := range finalList {
 		exportId := ObjToString((*v)["export_id"])