|
@@ -63,147 +63,147 @@ func DistributeClueShow(this *biservice.DistributeClueShowReq) *biservice.Distri
|
|
|
pArr = append(pArr, strconv.FormatInt(c.PositionId, 10))
|
|
|
}
|
|
|
clueArrs1 := []string{}
|
|
|
- sql0 := `SELECT a.cluename,a.id,b.position_id FROM dwd_f_crm_clue_info a INNER JOIN (SELECT a.cluename,a.position_id FROM dwd_f_crm_clue_info a INNER JOIN dwd_f_crm_personnel_management b on a.position_id = b.position_id WHERE a.cluename in (SELECT cluename FROM dwd_f_crm_clue_info WHERE id in (` + this.ClueIdList + `) GROUP BY cluename) AND a.id not in (` + this.ClueIdList + `) AND b.resign = 1 GROUP BY a.cluename) as b on b.cluename = a.cluename where a.id in (` + this.ClueIdList + `)`
|
|
|
- log.Println("sql0", sql0)
|
|
|
- mdata := JyBiTidb.SelectBySql(sql0)
|
|
|
- if mdata != nil && len(*mdata) > 0 {
|
|
|
- nameMap := map[string][]int64{}
|
|
|
- namePMap := map[string]int64{}
|
|
|
- idMap := map[string]bool{}
|
|
|
- for _, v := range *mdata {
|
|
|
- cluename := common.ObjToString(v["cluename"])
|
|
|
- id := common.Int64All(v["id"])
|
|
|
- positionId := common.Int64All(v["position_id"])
|
|
|
- nameMap[cluename] = append(nameMap[cluename], id)
|
|
|
- namePMap[cluename] = positionId
|
|
|
- ids := strconv.FormatInt(id, 10)
|
|
|
- idMap[ids] = true
|
|
|
- }
|
|
|
- log.Println("nameMap ", nameMap)
|
|
|
- log.Println("namePMap ", namePMap)
|
|
|
- for _, v := range strings.Split(this.ClueIdList, ",") {
|
|
|
- if !idMap[v] {
|
|
|
- clueArrs1 = append(clueArrs1, v)
|
|
|
+ clueArrs := []string{}
|
|
|
+ clueArrSync := &sync.Mutex{}
|
|
|
+ sql1 := `SELECT b.cluename,b.position_id,count(*) as count 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, ",") + `) AND id not in (` + this.ClueIdList + `) AND company_nature = 0 AND company_verification = 1 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 {
|
|
|
+ for _, v := range *sdata {
|
|
|
+ sPositionId := common.Int64All(v["position_id"])
|
|
|
+ count := common.IntAll(v["count"])
|
|
|
+ for k, r := range rdata {
|
|
|
+ if r.PositionId == sPositionId {
|
|
|
+ if this.DataType == 1 {
|
|
|
+ rdata[k].CompanyCount++
|
|
|
+ rdata[k].MinCount++
|
|
|
+ rdata[k].CompanyCounts++
|
|
|
+ rdata[k].ClueCount += int64(count)
|
|
|
+ } else {
|
|
|
+ if rdata[k].CompanyCounts < rdata[k].CompanyCount {
|
|
|
+ rdata[k].CompanyCounts++
|
|
|
+ rdata[k].ClueCount += int64(count)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- for k, v := range nameMap {
|
|
|
- ppdata := JyBiTidb.SelectBySql(`SELECT b.name,b.position_id,b.seat_number from dwd_d_crm_department_level_succbi a INNER JOIN dwd_f_crm_personnel_management b on a.position_id = b.position_id where a.bi_pcode = (SELECT bi_pcode from dwd_d_crm_department_level_succbi where position_id = ?) AND b.position_id != ?`, namePMap[k], namePMap[k])
|
|
|
- if ppdata != nil && len(*ppdata) > 0 {
|
|
|
- ppMap := map[int64]int{}
|
|
|
- for _, vv := range *ppdata {
|
|
|
- positionId := common.Int64All(vv["position_id"])
|
|
|
- ppMap[positionId] = 0
|
|
|
+ }
|
|
|
+ sql2 := `SELECT a.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, ",") + `) AND id not in (` + this.ClueIdList + `) AND company_nature = 0 AND company_verification = 1 GROUP BY cluename) AS b ON a.cluename = b.cluename WHERE a.id in (` + this.ClueIdList + `)`
|
|
|
+ log.Println("sql2 ", sql2) //查这一批线索中属于当前分配人员的线索id,分出去,并且排除掉
|
|
|
+ ldata := JyBiTidb.SelectBySql(sql2)
|
|
|
+ if ldata != nil && len(*ldata) > 0 {
|
|
|
+ wg := new(sync.WaitGroup)
|
|
|
+ ch := make(chan bool, 20)
|
|
|
+ for _, a := range strings.Split(this.ClueIdList, ",") {
|
|
|
+ isOk := true
|
|
|
+ wg.Add(1)
|
|
|
+ ch <- true
|
|
|
+ go func(a string, isOk bool) {
|
|
|
+ defer func() {
|
|
|
+ wg.Done()
|
|
|
+ <-ch
|
|
|
+ }()
|
|
|
+ for _, v := range *ldata {
|
|
|
+ id := common.Int64All(v["id"])
|
|
|
+ positionId := common.Int64All(v["position_id"])
|
|
|
+ ids := strconv.FormatInt(id, 10)
|
|
|
+ if a == ids {
|
|
|
+ isOk = false
|
|
|
+ if this.DataType == 3 {
|
|
|
+ dclue(id, positionId, this.IsTask, this.PositionId) //分线索
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if isOk {
|
|
|
+ clueArrSync.Lock()
|
|
|
+ clueArrs = append(clueArrs, a)
|
|
|
+ clueArrSync.Unlock()
|
|
|
+ }
|
|
|
+ }(a, isOk)
|
|
|
+ }
|
|
|
+ wg.Wait()
|
|
|
+ } else {
|
|
|
+ clueArrs = strings.Split(this.ClueIdList, ",")
|
|
|
+ }
|
|
|
+ log.Println("clueArrs ", clueArrs)
|
|
|
+ if len(clueArrs) > 0 {
|
|
|
+ sql0 := `SELECT a.cluename,a.id,b.position_id FROM dwd_f_crm_clue_info a INNER JOIN (SELECT a.cluename,a.position_id FROM dwd_f_crm_clue_info a INNER JOIN dwd_f_crm_personnel_management b on a.position_id = b.position_id WHERE a.cluename in (SELECT cluename FROM dwd_f_crm_clue_info WHERE id in (` + strings.Join(clueArrs, ",") + `) GROUP BY cluename) AND a.id not in (` + strings.Join(clueArrs, ",") + `) AND b.resign = 1 GROUP BY a.cluename) as b on b.cluename = a.cluename where a.id in (` + strings.Join(clueArrs, ",") + `)`
|
|
|
+ log.Println("sql0", sql0)
|
|
|
+ mdata := JyBiTidb.SelectBySql(sql0)
|
|
|
+ if mdata != nil && len(*mdata) > 0 {
|
|
|
+ nameMap := map[string][]int64{}
|
|
|
+ namePMap := map[string]int64{}
|
|
|
+ idMap := map[string]bool{}
|
|
|
+ for _, v := range *mdata {
|
|
|
+ cluename := common.ObjToString(v["cluename"])
|
|
|
+ id := common.Int64All(v["id"])
|
|
|
+ positionId := common.Int64All(v["position_id"])
|
|
|
+ nameMap[cluename] = append(nameMap[cluename], id)
|
|
|
+ namePMap[cluename] = positionId
|
|
|
+ ids := strconv.FormatInt(id, 10)
|
|
|
+ idMap[ids] = true
|
|
|
+ }
|
|
|
+ log.Println("nameMap ", nameMap)
|
|
|
+ log.Println("namePMap ", namePMap)
|
|
|
+ for _, v := range strings.Split(this.ClueIdList, ",") {
|
|
|
+ if !idMap[v] {
|
|
|
+ clueArrs1 = append(clueArrs1, v)
|
|
|
}
|
|
|
- isOk, sindex, paid := false, 0, int64(0)
|
|
|
- L:
|
|
|
- for pa, _ := range ppMap {
|
|
|
- if pa > 0 {
|
|
|
- for n, r := range rdata {
|
|
|
- if r.PositionId == pa {
|
|
|
- if this.DataType == 1 {
|
|
|
- isOk = true
|
|
|
- sindex = n
|
|
|
- paid = pa
|
|
|
- break L
|
|
|
- } else {
|
|
|
- if rdata[n].CompanyCounts < rdata[n].CompanyCount {
|
|
|
+ }
|
|
|
+ for k, v := range nameMap {
|
|
|
+ ppdata := JyBiTidb.SelectBySql(`SELECT b.name,b.position_id,b.seat_number from dwd_d_crm_department_level_succbi a INNER JOIN dwd_f_crm_personnel_management b on a.position_id = b.position_id where a.bi_pcode = (SELECT bi_pcode from dwd_d_crm_department_level_succbi where position_id = ?) AND b.position_id != ?`, namePMap[k], namePMap[k])
|
|
|
+ if ppdata != nil && len(*ppdata) > 0 {
|
|
|
+ ppMap := map[int64]int{}
|
|
|
+ for _, vv := range *ppdata {
|
|
|
+ positionId := common.Int64All(vv["position_id"])
|
|
|
+ ppMap[positionId] = 0
|
|
|
+ }
|
|
|
+ isOk, sindex, paid := false, 0, int64(0)
|
|
|
+ L:
|
|
|
+ for pa, _ := range ppMap {
|
|
|
+ if pa > 0 {
|
|
|
+ for n, r := range rdata {
|
|
|
+ if r.PositionId == pa {
|
|
|
+ if this.DataType == 1 {
|
|
|
isOk = true
|
|
|
sindex = n
|
|
|
paid = pa
|
|
|
break L
|
|
|
+ } else {
|
|
|
+ if rdata[n].CompanyCounts < rdata[n].CompanyCount {
|
|
|
+ isOk = true
|
|
|
+ sindex = n
|
|
|
+ paid = pa
|
|
|
+ break L
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- if isOk {
|
|
|
- if this.DataType == 1 {
|
|
|
- rdata[sindex].CompanyCount++
|
|
|
- rdata[sindex].MinCount++
|
|
|
- rdata[sindex].CompanyCounts++
|
|
|
- rdata[sindex].ClueCount += int64(len(v))
|
|
|
- } else {
|
|
|
- rdata[sindex].CompanyCounts++
|
|
|
- rdata[sindex].ClueCount += int64(len(v))
|
|
|
- for _, vv := range v {
|
|
|
- dclue(vv, paid, this.IsTask, this.PositionId) //分线索
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- clueArrs1 = strings.Split(this.ClueIdList, ",")
|
|
|
- }
|
|
|
- log.Println("clueArrs1 ", clueArrs1)
|
|
|
- clueArrs := []string{}
|
|
|
- clueArrSync := &sync.Mutex{}
|
|
|
- if len(clueArrs1) > 0 {
|
|
|
- sql1 := `SELECT b.cluename,b.position_id,count(*) as count 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, ",") + `) AND id not in (` + strings.Join(clueArrs1, ",") + `) AND company_nature = 0 AND company_verification = 1 GROUP BY cluename) AS b ON a.cluename = b.cluename WHERE id in (` + strings.Join(clueArrs1, ",") + `) GROUP BY cluename`
|
|
|
- log.Println("sql1 ", sql1)
|
|
|
- sdata := JyBiTidb.SelectBySql(sql1) //查这一批线索中属于当前分配人员的线索提前分配数量
|
|
|
- if sdata != nil && len(*sdata) > 0 {
|
|
|
- for _, v := range *sdata {
|
|
|
- sPositionId := common.Int64All(v["position_id"])
|
|
|
- count := common.IntAll(v["count"])
|
|
|
- for k, r := range rdata {
|
|
|
- if r.PositionId == sPositionId {
|
|
|
+ if isOk {
|
|
|
if this.DataType == 1 {
|
|
|
- rdata[k].CompanyCount++
|
|
|
- rdata[k].MinCount++
|
|
|
- rdata[k].CompanyCounts++
|
|
|
- rdata[k].ClueCount += int64(count)
|
|
|
+ rdata[sindex].CompanyCount++
|
|
|
+ rdata[sindex].MinCount++
|
|
|
+ rdata[sindex].CompanyCounts++
|
|
|
+ rdata[sindex].ClueCount += int64(len(v))
|
|
|
} else {
|
|
|
- if rdata[k].CompanyCounts < rdata[k].CompanyCount {
|
|
|
- rdata[k].CompanyCounts++
|
|
|
- rdata[k].ClueCount += int64(count)
|
|
|
+ rdata[sindex].CompanyCounts++
|
|
|
+ rdata[sindex].ClueCount += int64(len(v))
|
|
|
+ for _, vv := range v {
|
|
|
+ dclue(vv, paid, this.IsTask, this.PositionId) //分线索
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- sql2 := `SELECT a.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, ",") + `) AND id not in (` + strings.Join(clueArrs1, ",") + `) AND company_nature = 0 AND company_verification = 1 GROUP BY cluename) AS b ON a.cluename = b.cluename WHERE a.id in (` + strings.Join(clueArrs1, ",") + `)`
|
|
|
- log.Println("sql2 ", sql2) //查这一批线索中属于当前分配人员的线索id,分出去,并且排除掉
|
|
|
- ldata := JyBiTidb.SelectBySql(sql2)
|
|
|
- if ldata != nil && len(*ldata) > 0 {
|
|
|
- wg := new(sync.WaitGroup)
|
|
|
- ch := make(chan bool, 20)
|
|
|
- for _, a := range clueArrs1 {
|
|
|
- isOk := true
|
|
|
- wg.Add(1)
|
|
|
- ch <- true
|
|
|
- go func(a string, isOk bool) {
|
|
|
- defer func() {
|
|
|
- wg.Done()
|
|
|
- <-ch
|
|
|
- }()
|
|
|
- for _, v := range *ldata {
|
|
|
- id := common.Int64All(v["id"])
|
|
|
- positionId := common.Int64All(v["position_id"])
|
|
|
- ids := strconv.FormatInt(id, 10)
|
|
|
- if a == ids {
|
|
|
- isOk = false
|
|
|
- if this.DataType == 3 {
|
|
|
- dclue(id, positionId, this.IsTask, this.PositionId) //分线索
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- if isOk {
|
|
|
- clueArrSync.Lock()
|
|
|
- clueArrs = append(clueArrs, a)
|
|
|
- clueArrSync.Unlock()
|
|
|
- }
|
|
|
- }(a, isOk)
|
|
|
- }
|
|
|
- wg.Wait()
|
|
|
} else {
|
|
|
- clueArrs = clueArrs1
|
|
|
+ clueArrs1 = strings.Split(this.ClueIdList, ",")
|
|
|
}
|
|
|
}
|
|
|
- log.Println("clueArrs ", clueArrs)
|
|
|
- if len(clueArrs) > 0 {
|
|
|
+ log.Println("clueArrs1 ", clueArrs1)
|
|
|
+ if len(clueArrs1) > 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)
|