xuzhiheng hace 1 año
padre
commit
c9d0f20284
Se han modificado 1 ficheros con 60 adiciones y 52 borrados
  1. 60 52
      service/company.go

+ 60 - 52
service/company.go

@@ -60,7 +60,7 @@ func DistributeClueShow(this *biservice.DistributeClueShowReq) *biservice.Distri
 		pArr = append(pArr, strconv.FormatInt(c.PositionId, 10))
 	}
 	//
-	sql1 := `SELECT b.cluename,b.position_id FROM dwd_f_crm_clue_info a INNER JOIN (SELECT cluename,position_id FROM dwd_f_crm_clue_info WHERE position_id in (` + strings.Join(pArr, ",") + `) GROUP BY cluename) AS b ON a.cluename = b.cluename WHERE id in (` + this.ClueIdList + `) GROUP BY cluename`
+	sql1 := `SELECT a.cluename,a.position_id FROM dwd_f_crm_clue_info a INNER JOIN (SELECT cluename,position_id FROM dwd_f_crm_clue_info WHERE position_id in (` + strings.Join(pArr, ",") + `) GROUP BY cluename) AS b ON a.cluename = b.cluename WHERE id in (` + this.ClueIdList + `) GROUP BY cluename`
 	log.Println("sql1 ", sql1)
 	sdata := JyBiTidb.SelectBySql(sql1)
 	if sdata != nil && len(*sdata) > 0 {
@@ -82,7 +82,8 @@ func DistributeClueShow(this *biservice.DistributeClueShowReq) *biservice.Distri
 	}
 	//
 	clueArrs := []string{}
-	sql2 := `SELECT b.id,b.position_id FROM dwd_f_crm_clue_info a INNER JOIN (SELECT id,cluename,position_id FROM dwd_f_crm_clue_info WHERE position_id in (` + strings.Join(pArr, ",") + `) GROUP BY cluename) AS b ON a.cluename = b.cluename WHERE a.id in (` + this.ClueIdList + `)`
+	clueArrSync := &sync.Mutex{}
+	sql2 := `SELECT a.id,a.position_id FROM dwd_f_crm_clue_info a INNER JOIN (SELECT id,cluename,position_id FROM dwd_f_crm_clue_info WHERE position_id in (` + strings.Join(pArr, ",") + `) GROUP BY cluename) AS b ON a.cluename = b.cluename WHERE a.id in (` + this.ClueIdList + `)`
 	log.Println("sql2 ", sql2)
 	ldata := JyBiTidb.SelectBySql(sql2)
 	if ldata != nil && len(*ldata) > 0 {
@@ -104,73 +105,80 @@ func DistributeClueShow(this *biservice.DistributeClueShowReq) *biservice.Distri
 				for _, a := range clueArr {
 					if a == ids {
 						isOk = false
+						log.Println("isOk2 ", isOk)
 						if this.DataType == 3 {
 							//分线索
 							dclue(id, positionId, this.IsTask, this.PositionId)
 						}
 					}
 				}
+				log.Println("isOk2 ", isOk, ids)
+				if isOk {
+					clueArrSync.Lock()
+					clueArrs = append(clueArrs, ids)
+					clueArrSync.Unlock()
+				}
 			}(isOk)
-			if isOk {
-				clueArrs = append(clueArrs, ids)
-			}
 		}
 		wg.Wait()
 	}
 	//
-	sql3 := `SELECT cluename,COUNT(*) AS count FROM dwd_f_crm_clue_info WHERE id in (` + strings.Join(clueArrs, ",") + `) GROUP BY cluename ORDER BY count desc`
-	log.Println("sql3 ", sql3)
-	cdata := JyBiTidb.SelectBySql(sql3)
-	if cdata != nil && len(*cdata) > 0 {
-		for _, v := range *cdata {
-			count := common.IntAll(v["count"])
-			cluename := common.ObjToString(v["cluename"])
-			minCount, minIndex := int64(0), 0
-			for k, r := range rdata {
-				if k == 0 {
-					minCount = r.CompanyCounts
-				}
-				if r.CompanyCounts < minCount && r.CompanyCounts < r.CompanyCount {
-					minCount = r.CompanyCounts
-				}
-			}
-			for k, r := range rdata {
-				if this.DataType == 1 {
-					if r.CompanyCounts <= minCount {
+	log.Println("clueArrs ", clueArrs)
+	if len(clueArrs) > 0 {
+		sql3 := `SELECT cluename,COUNT(*) AS count FROM dwd_f_crm_clue_info WHERE id in (` + strings.Join(clueArrs, ",") + `) GROUP BY cluename ORDER BY count desc`
+		log.Println("sql3 ", sql3)
+		cdata := JyBiTidb.SelectBySql(sql3)
+		if cdata != nil && len(*cdata) > 0 {
+			for _, v := range *cdata {
+				count := common.IntAll(v["count"])
+				cluename := common.ObjToString(v["cluename"])
+				minCount, minIndex := int64(0), 0
+				for k, r := range rdata {
+					if k == 0 {
 						minCount = r.CompanyCounts
-						minIndex = k
 					}
-				} else {
-					if r.CompanyCounts <= minCount && r.CompanyCounts < r.CompanyCount {
+					if r.CompanyCounts < minCount && r.CompanyCounts < r.CompanyCount {
 						minCount = r.CompanyCounts
-						minIndex = k
 					}
 				}
-			}
-			if this.DataType == 1 {
-				rdata[minIndex].CompanyCount++
-			}
-			rdata[minIndex].CompanyCounts++
-			rdata[minIndex].ClueCount += int64(count)
-			if this.DataType == 3 {
-				//分线索
-				iddata := JyBiTidb.SelectBySql(`SELECT id FROM dwd_f_crm_clue_info WHERE cluename = "` + cluename + `" and id in (` + strings.Join(clueArrs, ",") + `)`)
-				if iddata != nil {
-					wg := new(sync.WaitGroup)
-					ch := make(chan bool, 10)
-					for _, i := range *iddata {
-						wg.Add(1)
-						ch <- true
-						go func(i map[string]interface{}) {
-							defer func() {
-								wg.Done()
-								<-ch
-							}()
-							id := common.Int64All(i["id"])
-							dclue(id, rdata[minIndex].PositionId, this.IsTask, this.PositionId)
-						}(i)
+				for k, r := range rdata {
+					if this.DataType == 1 {
+						if r.CompanyCounts <= minCount {
+							minCount = r.CompanyCounts
+							minIndex = k
+						}
+					} else {
+						if r.CompanyCounts <= minCount && r.CompanyCounts < r.CompanyCount {
+							minCount = r.CompanyCounts
+							minIndex = k
+						}
+					}
+				}
+				if this.DataType == 1 {
+					rdata[minIndex].CompanyCount++
+				}
+				rdata[minIndex].CompanyCounts++
+				rdata[minIndex].ClueCount += int64(count)
+				if this.DataType == 3 {
+					//分线索
+					iddata := JyBiTidb.SelectBySql(`SELECT id FROM dwd_f_crm_clue_info WHERE cluename = "` + cluename + `" and id in (` + strings.Join(clueArrs, ",") + `)`)
+					if iddata != nil {
+						wg := new(sync.WaitGroup)
+						ch := make(chan bool, 10)
+						for _, i := range *iddata {
+							wg.Add(1)
+							ch <- true
+							go func(i map[string]interface{}) {
+								defer func() {
+									wg.Done()
+									<-ch
+								}()
+								id := common.Int64All(i["id"])
+								dclue(id, rdata[minIndex].PositionId, this.IsTask, this.PositionId)
+							}(i)
+						}
+						wg.Wait()
 					}
-					wg.Wait()
 				}
 			}
 		}