Browse Source

Merge branch 'dev_v1.0.27_wh' of BaseService/biService into feature/v1.0.27

王浩 1 year ago
parent
commit
25d62932e2
2 changed files with 71 additions and 104 deletions
  1. 3 1
      service/acceptance.go
  2. 68 103
      service/company.go

+ 3 - 1
service/acceptance.go

@@ -196,8 +196,10 @@ func Findcandidate(DkPersonMap []map[string]interface{}, entId int64, orderType
 	personMap := map[string]map[string]interface{}{}
 	positionId := int64(0)
 	phoneArr := []string{}
+	personNameArr := []string{}
 	for _, v := range DkPersonMap {
 		phoneArr = append(phoneArr, fmt.Sprintf(`"%s"`, gconv.String(v["phone"])))
+		personNameArr = append(personNameArr, fmt.Sprintf(`"%s"`, gconv.String(v["personName"])))
 		personMap[gconv.String(v["phone"])] = map[string]interface{}{
 			"name": gconv.String(v["personName"]),
 		}
@@ -248,7 +250,7 @@ FROM
 			FIND_IN_SET(current_position_id , ?)  and  two_type=?
 		GROUP BY   current_position_id 
 		ORDER BY
-			count`, strings.Join(positionArr, ","), orderType)
+			count ,FIELD(current_name,?) asc `, strings.Join(positionArr, ","), orderType, strings.Join(personNameArr, ","))
 	if positionNumberMap != nil && len(*positionNumberMap) == len(DkPersonMap) {
 		positionId = gconv.Int64((*positionNumberMap)[0]["current_position_id"])
 	} else if positionNumberMap != nil && len(*positionNumberMap) != len(DkPersonMap) {

+ 68 - 103
service/company.go

@@ -5,7 +5,6 @@ import (
 	"log"
 	"strconv"
 	"strings"
-	"sync"
 	"time"
 
 	"app.yhyue.com/moapp/jybase/common"
@@ -99,120 +98,86 @@ func DistributeClueShow(this *biservice.DistributeClueShowReq, allocationCap int
 	clueArrs1 := []string{}
 	clueArrs1 = strings.Split(this.ClueIdList, ",")
 	logx.Info("clueArrs1 ", clueArrs1)
-	if len(clueArrs1) > 0 {
-		sql3 := `SELECT cluename,COUNT(*) AS count FROM dwd_f_crm_clue_info WHERE id in (` + strings.Join(clueArrs1, ",") + `) GROUP BY cluename ORDER BY count desc`
-		logx.Info("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), -1
-				isindexok := false
-				k1 := 0
-				for _, r := range rdata {
-					if !r.FullStatus {
-						if this.DataType == 1 {
-							if k1 == 0 {
-								minCount = r.CompanyCounts
-								break
-							}
-						} else {
-							if r.CompanyCounts < r.CompanyCount {
-								minCount = r.CompanyCounts
-							}
-						}
-					}
-				}
-				for _, r := range rdata {
-					if !r.FullStatus {
-						if this.DataType == 1 {
-							if r.CompanyCounts < minCount {
-								minCount = r.CompanyCounts
-							}
-						} else {
-							if r.CompanyCounts < minCount && r.CompanyCounts < r.CompanyCount {
-								minCount = r.CompanyCounts
-							}
-						}
+	for _, v := range strings.Split(this.ClueIdList, ",") {
+		count := 1
+		id := v
+		minCount, minIndex := int64(0), -1
+		isindexok := false
+		k1 := 0
+		for _, r := range rdata {
+			if !r.FullStatus {
+				if this.DataType == 1 {
+					if k1 == 0 {
+						minCount = r.CompanyCounts
+						break
 					}
-				}
-				for k, r := range rdata {
-					countNumber := r.ExistingCount + r.ClueCount + int64(count)
-					if this.DataType == 1 {
-						if countNumber <= allocationCap {
-							if r.CompanyCounts <= minCount {
-								minCount = r.CompanyCounts
-								minIndex = k
-							}
-						}
-					} else {
-						if countNumber <= allocationCap {
-							if r.CompanyCounts <= minCount && r.CompanyCounts < r.CompanyCount {
-								minCount = r.CompanyCounts
-								minIndex = k
-							}
-						} /* else {
-							if this.DataType == 2 {
-								if r.CompanyCounts <= minCount && r.CompanyCounts < r.CompanyCount && this.UpdatePositionID == r.PositionId {
-									return &biservice.DistributeClueShowResp{
-										ErrorCode: 1,
-										ErrorMsg:  "超出私海线索上限",
-									}
-								}
-							}
-
-						}*/
+				} else {
+					if r.CompanyCounts < r.CompanyCount {
+						minCount = r.CompanyCounts
 					}
 				}
-				if minIndex == -1 {
-					continue
-				}
+			}
+		}
+		for _, r := range rdata {
+			if !r.FullStatus {
 				if this.DataType == 1 {
-					countNumber := rdata[minIndex].ExistingCount + rdata[minIndex].ClueCount + int64(count)
-					if countNumber == allocationCap {
-						rdata[minIndex].FullStatus = true
+					if r.CompanyCounts < minCount {
+						minCount = r.CompanyCounts
 					}
-					rdata[minIndex].CompanyCount++
-					rdata[minIndex].CompanyCounts++
-					rdata[minIndex].ClueCount += int64(count)
 				} else {
-					countNumber := rdata[minIndex].ExistingCount + rdata[minIndex].ClueCount + int64(count)
-					if rdata[minIndex].CompanyCounts < rdata[minIndex].CompanyCount {
-						isindexok = true
-						rdata[minIndex].CompanyCounts++
-						rdata[minIndex].ClueCount += int64(count)
-						if countNumber == allocationCap {
-							rdata[minIndex].FullStatus = true
-						}
+					if r.CompanyCounts < minCount && r.CompanyCounts < r.CompanyCount {
+						minCount = r.CompanyCounts
 					}
 				}
-
-				if this.DataType == 3 && isindexok {
-					iddata := JyBiTidb.SelectBySql(`SELECT id FROM dwd_f_crm_clue_info WHERE cluename = "` + cluename + `" and id in (` + strings.Join(clueArrs1, ",") + `) ORDER BY createtime DESC LIMIT ` + gconv.String(count))
-					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)
-								log.Println("3333", id, rdata[minIndex].PositionId)
-							}(i)
-						}
-						wg.Wait()
+			}
+		}
+		for k, r := range rdata {
+			countNumber := r.ExistingCount + r.ClueCount + int64(count)
+			if this.DataType == 1 {
+				if countNumber <= allocationCap {
+					if r.CompanyCounts <= minCount {
+						minCount = r.CompanyCounts
+						minIndex = k
 					}
 				}
+			} else {
+				if countNumber <= allocationCap {
+					if r.CompanyCounts <= minCount && r.CompanyCounts < r.CompanyCount {
+						minCount = r.CompanyCounts
+						minIndex = k
+					}
+				}
+			}
+		}
+		if minIndex == -1 {
+			continue
+		}
+		if this.DataType == 1 {
+			countNumber := rdata[minIndex].ExistingCount + rdata[minIndex].ClueCount + int64(count)
+			if countNumber == allocationCap {
+				rdata[minIndex].FullStatus = true
+			}
+			rdata[minIndex].CompanyCount++
+			rdata[minIndex].CompanyCounts++
+			rdata[minIndex].ClueCount += int64(count)
+		} else {
+			countNumber := rdata[minIndex].ExistingCount + rdata[minIndex].ClueCount + int64(count)
+			if rdata[minIndex].CompanyCounts < rdata[minIndex].CompanyCount {
+				isindexok = true
+				rdata[minIndex].CompanyCounts++
+				rdata[minIndex].ClueCount += int64(count)
+				if countNumber == allocationCap {
+					rdata[minIndex].FullStatus = true
+				}
 			}
 		}
+
+		if this.DataType == 3 && isindexok {
+			dclue(gconv.Int64(id), rdata[minIndex].PositionId, this.IsTask, this.PositionId)
+			log.Println("3333", id, rdata[minIndex].PositionId)
+		}
 	}
-	if this.DataType == 2 {
+	/*if this.DataType == 2 {
 		for _, v := range rdata {
 			if this.UpdatePositionID == v.PositionId {
 				if v.CompanyCounts < v.CompanyCount {
@@ -223,7 +188,7 @@ func DistributeClueShow(this *biservice.DistributeClueShowReq, allocationCap int
 				}
 			}
 		}
-	}
+	}*/
 	return &biservice.DistributeClueShowResp{
 		ErrorCode: 0,
 		Data:      rdata,