|
@@ -48,7 +48,7 @@ func CompanyType(companyName string) (bool, bool) {
|
|
|
func DistributeClueShow(this *biservice.DistributeClueShowReq) *biservice.DistributeClueShowResp {
|
|
|
rdata := []*biservice.DistributeClueShowss{}
|
|
|
pArr := []string{}
|
|
|
- for _, c := range this.Datas {
|
|
|
+ for _, c := range this.Datas { //初始化返回数据
|
|
|
m := &biservice.DistributeClueShowss{}
|
|
|
m.PositionId = c.PositionId
|
|
|
m.ClueCount = 0
|
|
@@ -58,15 +58,74 @@ func DistributeClueShow(this *biservice.DistributeClueShowReq) *biservice.Distri
|
|
|
m.MinCount = 0
|
|
|
} else {
|
|
|
m.CompanyCount = c.DistributedCount
|
|
|
- // m.CompanyCounts = c.DistributedCount
|
|
|
}
|
|
|
rdata = append(rdata, m)
|
|
|
pArr = append(pArr, strconv.FormatInt(c.PositionId, 10))
|
|
|
}
|
|
|
- //
|
|
|
- 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`
|
|
|
+ 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 + `)`
|
|
|
+ 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
|
|
|
+ }
|
|
|
+ for _, v := range strings.Split(this.ClueIdList, ",") {
|
|
|
+ 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
|
|
|
+ }
|
|
|
+ for _, vv := range v {
|
|
|
+ for pa, _ := range ppMap {
|
|
|
+ if pa > 0 {
|
|
|
+ for n, r := range rdata {
|
|
|
+ if r.PositionId == pa {
|
|
|
+ if this.DataType == 1 {
|
|
|
+ rdata[n].CompanyCount++
|
|
|
+ rdata[n].MinCount++
|
|
|
+ rdata[n].CompanyCounts++
|
|
|
+ rdata[n].ClueCount += int64(len(v))
|
|
|
+ break
|
|
|
+ } else {
|
|
|
+ if rdata[n].CompanyCounts < rdata[n].CompanyCount {
|
|
|
+ rdata[n].CompanyCounts++
|
|
|
+ rdata[n].ClueCount += int64(len(v))
|
|
|
+ if this.DataType == 3 {
|
|
|
+ dclue(vv, pa, this.IsTask, this.PositionId) //分线索
|
|
|
+ }
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ clueArrs1 = strings.Split(this.ClueIdList, ",")
|
|
|
+ }
|
|
|
+ log.Println("clueArrs1 ", clueArrs1)
|
|
|
+ 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)
|
|
|
+ sdata := JyBiTidb.SelectBySql(sql1) //查这一批线索中属于当前分配人员的线索提前分配数量
|
|
|
if sdata != nil && len(*sdata) > 0 {
|
|
|
for _, v := range *sdata {
|
|
|
sPositionId := common.Int64All(v["position_id"])
|
|
@@ -88,17 +147,15 @@ func DistributeClueShow(this *biservice.DistributeClueShowReq) *biservice.Distri
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- //
|
|
|
clueArrs := []string{}
|
|
|
clueArrSync := &sync.Mutex{}
|
|
|
- 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)
|
|
|
+ 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 {
|
|
|
- clueArr := strings.Split(this.ClueIdList, ",")
|
|
|
wg := new(sync.WaitGroup)
|
|
|
ch := make(chan bool, 20)
|
|
|
- for _, a := range clueArr {
|
|
|
+ for _, a := range clueArrs1 {
|
|
|
isOk := true
|
|
|
wg.Add(1)
|
|
|
ch <- true
|
|
@@ -114,8 +171,7 @@ func DistributeClueShow(this *biservice.DistributeClueShowReq) *biservice.Distri
|
|
|
if a == ids {
|
|
|
isOk = false
|
|
|
if this.DataType == 3 {
|
|
|
- //分线索
|
|
|
- dclue(id, positionId, this.IsTask, this.PositionId)
|
|
|
+ dclue(id, positionId, this.IsTask, this.PositionId) //分线索
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -128,13 +184,12 @@ func DistributeClueShow(this *biservice.DistributeClueShowReq) *biservice.Distri
|
|
|
}
|
|
|
wg.Wait()
|
|
|
} else {
|
|
|
- clueArrs = strings.Split(this.ClueIdList, ",")
|
|
|
+ clueArrs = clueArrs1
|
|
|
}
|
|
|
- //
|
|
|
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)
|
|
|
+ log.Println("sql3 ", sql3) //从大到小排列这一列线索名称分组及数量情况
|
|
|
cdata := JyBiTidb.SelectBySql(sql3)
|
|
|
if cdata != nil && len(*cdata) > 0 {
|
|
|
for _, v := range *cdata {
|
|
@@ -187,9 +242,8 @@ func DistributeClueShow(this *biservice.DistributeClueShowReq) *biservice.Distri
|
|
|
}
|
|
|
}
|
|
|
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 {
|
|
|
+ if iddata != nil { //分线索
|
|
|
wg := new(sync.WaitGroup)
|
|
|
ch := make(chan bool, 10)
|
|
|
for _, i := range *iddata {
|