|
@@ -97,169 +97,7 @@ func DistributeClueShow(this *biservice.DistributeClueShowReq, allocationCap int
|
|
|
}
|
|
|
}
|
|
|
clueArrs1 := []string{}
|
|
|
- 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`
|
|
|
- logx.Info("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)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- 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 + `)`
|
|
|
- logx.Info("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) //分线索
|
|
|
- log.Println("11111111", id, positionId)
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- if isOk {
|
|
|
- clueArrSync.Lock()
|
|
|
- clueArrs = append(clueArrs, a)
|
|
|
- clueArrSync.Unlock()
|
|
|
- }
|
|
|
- }(a, isOk)
|
|
|
- }
|
|
|
- wg.Wait()
|
|
|
- } else {
|
|
|
- clueArrs = strings.Split(this.ClueIdList, ",")
|
|
|
- }
|
|
|
- logx.Info("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 AND a.company_nature = 0 AND a.company_verification = 1 GROUP BY a.cluename) as b on b.cluename = a.cluename
|
|
|
- where a.id in (` + strings.Join(clueArrs, ",") + `)`
|
|
|
- logx.Info("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
|
|
|
- }
|
|
|
- logx.Info("nameMap ", nameMap)
|
|
|
- logx.Info("namePMap ", namePMap)
|
|
|
- for _, v := range clueArrs {
|
|
|
- if !idMap[v] {
|
|
|
- clueArrs1 = append(clueArrs1, v)
|
|
|
- }
|
|
|
- }
|
|
|
- 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 && !r.FullStatus {
|
|
|
- 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
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- logx.Info("RDATA ", rdata[sindex].CompanyCount, rdata[sindex].MinCount, rdata[sindex].CompanyCounts, rdata[sindex].ClueCount, len(v))
|
|
|
- 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))
|
|
|
- if this.DataType == 3 {
|
|
|
- for _, vv := range v {
|
|
|
- dclue(vv, paid, this.IsTask, this.PositionId) //分线索*/
|
|
|
- log.Println("2222", vv, paid)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- logx.Info("RDATA2 ", rdata[sindex].CompanyCount, rdata[sindex].MinCount, rdata[sindex].CompanyCounts, rdata[sindex].ClueCount, len(v))
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- clueArrs1 = clueArrs
|
|
|
- }
|
|
|
- }
|
|
|
+ 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`
|
|
@@ -393,7 +231,6 @@ func DistributeClueShow(this *biservice.DistributeClueShowReq, allocationCap int
|
|
|
}
|
|
|
|
|
|
func dclue(v, positionId, isTask, thispositionId int64) {
|
|
|
-
|
|
|
clueData := JyBiTidb.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"id": v}, "", "")
|
|
|
nowTime := time.Now().Format(date.Date_Full_Layout)
|
|
|
if clueData != nil && len(*clueData) > 0 {
|