فهرست منبع

收录详情处理

WH01243 1 سال پیش
والد
کامیت
8a299f2c76
1فایلهای تغییر یافته به همراه302 افزوده شده و 212 حذف شده
  1. 302 212
      api/internal/service/employService.go

+ 302 - 212
api/internal/service/employService.go

@@ -5,7 +5,6 @@ import (
 	"app.yhyue.com/moapp/jybase/date"
 	elastic "app.yhyue.com/moapp/jybase/es"
 	"app.yhyue.com/moapp/jypkg/ent/util"
-	"app.yhyue.com/moapp/jypkg/public"
 	MC "bp.jydev.jianyu360.cn/CRM/application/api/common"
 	"bp.jydev.jianyu360.cn/CRM/application/api/internal/types"
 	"bp.jydev.jianyu360.cn/CRM/application/entity"
@@ -13,7 +12,6 @@ import (
 	"fmt"
 	"github.com/RoaringBitmap/roaring"
 	"github.com/gogf/gf/v2/util/gconv"
-	"go.mongodb.org/mongo-driver/bson"
 	"log"
 	"strings"
 	"time"
@@ -52,7 +50,6 @@ func (e *EmPloyService) InfoEmployinfo(in *types.InfoEmployinfoReq) ([]map[strin
 		}
 	}
 	//是否可以批量收录配置回显
-
 	accountId := int64(0)
 	if in.PositionType == 0 {
 		accountId = in.AccountId
@@ -67,25 +64,81 @@ func (e *EmPloyService) InfoEmployinfo(in *types.InfoEmployinfoReq) ([]map[strin
 	}
 	//版本查询
 	res := MC.Middleground.ResourceCenter.Haspowers(in.AccountId, in.EntAccountId, in.EntId, in.EntUserId)
-	version := 0
+	version := 1
 	for _, pCode := range res.Powers {
 		//0:通用版 1:物业专版
 		if pCode == "bi_yx_wyzb" {
 			version = 1
 		}
 	}
+	infoId1Arr := []string{}
+	niJianIdArr := []string{}
+	infoId2Arr := []string{}
+	wuye1Arr := []string{}
+	wuye2Arr := []string{}
+	infoMap := map[string]interface{}{}
+	var table, findKey, employKey, projectId, subtype string
 	for _, v := range strings.Split(in.IdArr, ",") {
-		id := ""
-		id = idFormat(v, in.EmployType)
-		table, findKey, employKey, source, projectId, isNiJian, subtype := employKeyFormat(in.EmployType, id)
-		if id == "" {
-			log.Println(v, in.EmployType, "该信息查询不到数据")
-			continue
+		var isNiJian bool
+		var source int64
+		id := idFormat(v, in.EmployType)
+		table, findKey, employKey, source, projectId, isNiJian, subtype = employKeyFormat(in.EmployType, id)
+		if (subtype == "成交" || subtype == "中标" || subtype == "合同" || subtype == "验收" || subtype == "违规") && in.EmployType == 1 && version == 1 {
+			infoMap[v] = projectId
+			if isNiJian {
+				infoMap[v] = projectId
+				if source == 1 {
+					wuye1Arr = append(wuye1Arr, projectId)
+				} else {
+					wuye2Arr = append(wuye2Arr, projectId)
+				}
+			} else {
+				infoMap[v] = id
+				if source == 1 {
+					wuye1Arr = append(wuye1Arr, id)
+				} else {
+					wuye2Arr = append(wuye2Arr, id)
+				}
+			}
+		} else if isNiJian {
+			infoMap[v] = projectId
+			niJianIdArr = append(niJianIdArr, id)
+		} else if source == 2 {
+			infoMap[v] = id
+			infoId2Arr = append(infoId2Arr, projectId)
+		} else if source == 1 {
+			infoMap[v] = id
+			infoId1Arr = append(infoId2Arr, projectId)
 		}
-		if in.EntNicheDis > 0 {
-			data = append(data, employInfoEnt(v, table, id, employKey, findKey, depIDArr, source, in, projectId, isNiJian, version, subtype))
-		} else {
-			data = append(data, employInfoPerson(v, table, id, employKey, findKey, source, in, projectId, isNiJian, version, subtype))
+
+	}
+	//收录情况查询
+	dataList := map[string]map[string]interface{}{}
+	if in.EntNicheDis > 0 {
+		dataList = employInfoEnt(table, employKey, findKey, depIDArr, in, version, subtype, infoId1Arr, infoId2Arr, niJianIdArr, wuye1Arr, wuye2Arr)
+	} else {
+		dataList = employInfoPerson(table, employKey, findKey, in, version, infoId1Arr, infoId2Arr, niJianIdArr, wuye1Arr, wuye2Arr)
+	}
+	for k, v := range infoMap {
+		fool := true
+		for sourceId, v1 := range dataList {
+			if v == sourceId {
+				v1["id"] = k
+				data = append(data, v1)
+				fool = false
+				break
+			}
+		}
+		if fool {
+			data = append(data, map[string]interface{}{
+				"id":          k,
+				"isIgnore":    false,
+				"isEmploy":    false,
+				"customCount": 0,
+				"clueCount":   0,
+				"chanceCount": 0,
+				"type":        1,
+			})
 		}
 	}
 	return data, batchEmploy
@@ -214,16 +267,6 @@ func infoFind(id string, v1 string) map[string]interface{} {
 	//ownerclass  业主类型(拟在建搜索) expurasing_time 预计采购时间   jybx_url 标讯详情页
 	//标讯信息
 	obj := map[string]interface{}{}
-	/*brobj, ok := MC.Mgo.Find("bidding_rec", bson.M{"s_id": id}, `{"l_recoverydate":-1}`, public.MgoBiddingFields, false, 0, 1)
-	if ok && (*brobj) != nil && len(*brobj) == 1 && (*brobj)[0] != nil {
-		obj = (*brobj)[0]
-	} else {
-		aobj, ok := MC.MgoBidding.FindById("bidding", id, public.MgoBiddingFields)
-		if ok && (aobj == nil || *aobj == nil || len(*aobj) == 0) {
-			aobj, ok = MC.MgoBidding.FindById("bidding_back", id, public.MgoBiddingFields)
-		}
-		obj = *aobj
-	}*/
 	aobj := elastic.Get(INDEX, TYPE, fmt.Sprintf(`{"query":{"bool":{"must":[{"match":{"id":"%s"}}],"must_not":[],"should":[]}},"from":0,"size":10,"_source":["_id","purchasinglist","projectname","projectcode","title","s_winner","buyertel","bidstatus","site","bidamount","toptype","winneraddr","winner","agency","buyer","detail","city","subtype","buyerclass","href","comeintime","winnertel","area","publishtime","buyeraddr","agencytel","budget","entidlist","buyerperson","winnerperson","agencyaddr","recommended_service","competehref","owner","total_investment","projectaddr","projectperiod","approvedept","approvecontent","approvecode","approvenumber","approvetime","approvestatus","project_scale"],"sort":[],"aggs":{}}`, id))
 	if aobj != nil || *aobj != nil || len(*aobj) > 0 {
 		obj = (*aobj)[0]
@@ -334,17 +377,11 @@ func employKeyFormat(employType int64, id string) (string, string, string, int64
 		findKey = "employ_info_id"
 		source = 1
 		obj := map[string]interface{}{}
-		brobj, ok := MC.Mgo.Find("bidding_rec", bson.M{"s_id": id}, `{"l_recoverydate":-1}`, public.MgoBiddingFields, false, 0, 1)
-		if ok && (*brobj) != nil && len(*brobj) == 1 && (*brobj)[0] != nil {
-			obj = (*brobj)[0]
-		} else {
-			aobj, ok := MC.MgoBidding.FindById("bidding", id, public.MgoBiddingFields)
-			if ok && (aobj == nil || *aobj == nil || len(*aobj) == 0) {
-				aobj, ok = MC.MgoBidding.FindById("bidding_back", id, public.MgoBiddingFields)
-			}
-			obj = *aobj
+		aobj := elastic.Get(INDEX, TYPE, fmt.Sprintf(`{"query":{"bool":{"must":[{"match":{"id":"%s"}}],"must_not":[],"should":[]}},"from":0,"size":10,"_source":["_id","purchasinglist","projectname","projectcode","title","s_winner","buyertel","bidstatus","site","bidamount","toptype","winneraddr","winner","agency","buyer","detail","city","subtype","buyerclass","href","comeintime","winnertel","area","publishtime","buyeraddr","agencytel","budget","entidlist","buyerperson","winnerperson","agencyaddr","recommended_service","competehref","owner","total_investment","projectaddr","projectperiod","approvedept","approvecontent","approvecode","approvenumber","approvetime","approvestatus","project_scale"],"sort":[],"aggs":{}}`, id))
+		if aobj != nil || *aobj != nil || len(*aobj) > 0 {
+			obj = (*aobj)[0]
 		}
-		if ok && obj != nil && len(obj) > 0 {
+		if obj != nil && len(obj) > 0 {
 			subtype = common.InterfaceToStr(obj["subtype"])
 			if subtype == "拟建" {
 				project, _ := MC.MgoProject.FindOne("projectset_proposed", map[string]interface{}{
@@ -593,210 +630,263 @@ func niJianHandle(infoId string, data map[string]interface{}, v1, pushTime strin
 }
 
 // 个人收录情况查询
-func employInfoPerson(v, table, id, employKey, findKey string, source int64, in *types.InfoEmployinfoReq, projectId string, isNiJian bool, version int, subtype string) map[string]interface{} {
-	valueMap := map[string]interface{}{
-		"id": v,
+func employInfoPerson(table, employKey, findKey string, in *types.InfoEmployinfoReq, version int, infoId1Arr, infoId2Arr, niJianIdArr, wuye1Arr, wuye2Arr []string) map[string]map[string]interface{} {
+	//
+	data := map[string]map[string]interface{}{}
+	infoData1 := &[]map[string]interface{}{}
+	infoData2 := &[]map[string]interface{}{}
+	niJianData := &[]map[string]interface{}{}
+	wuyeData1 := &[]map[string]interface{}{}
+	wuyeData2 := &[]map[string]interface{}{}
+	if len(infoId1Arr) > 0 {
+		infoData1 = MC.CrmMysql.SelectBySql(fmt.Sprintf("select  is_ignore,status,id,type from  %s   where position_id =? and  %s in ('%s')    GROUP BY %s ", table, employKey, strings.Join(infoId1Arr, "','"), employKey), in.PositionId, 1)
 	}
-	sourceId := ""
-	if isNiJian {
-		sourceId = projectId
-	} else {
-		sourceId = id
+	if len(infoId2Arr) > 0 {
+		infoData2 = MC.CrmMysql.SelectBySql(fmt.Sprintf("select  is_ignore,status,id,type from  %s   where position_id =? and  %s in '%s')    GROUP BY %s ", table, employKey, strings.Join(infoId2Arr, "','"), employKey), in.PositionId, 1)
 	}
-
-	employData := &[]map[string]interface{}{}
-	if in.EmployType == 1 {
-		employData = MC.CrmMysql.Find(table, map[string]interface{}{
-			employKey:     sourceId,
-			"position_id": in.PositionId,
-		}, "is_ignore,status,id,type", "id", -1, -1)
-	} else {
-		employData = MC.CrmMysql.Find(table, map[string]interface{}{
-			employKey:     sourceId,
-			"position_id": in.PositionId,
-		}, "is_ignore,status,id", "id", -1, -1)
+	if len(niJianIdArr) > 0 {
+		niJianData = MC.CrmMysql.SelectBySql(fmt.Sprintf("select  is_ignore,status,id,type from  %s   where position_id =? and  %s in ('%s')    GROUP BY %s ", table, employKey, strings.Join(niJianIdArr, "','"), employKey), in.PositionId, 1)
 	}
-	employId := int64(0)
-	if employData != nil && len(*employData) > 0 {
-		if (subtype == "成交" || subtype == "中标" || subtype == "合同" || subtype == "验收" || subtype == "违规") && in.EmployType == 1 && version == 1 {
-			employ2 := false
-			employ3 := false
-			employIgnore := false
-			employType := int64(0)
-			is_ignore := int64(0)
-			for _, v1 := range *employData {
-				employType := common.Int64All(v1["type"])
-				employStatus := common.Int64All(v1["status"])
-				if in.From == "jhfp" && employType == 3 {
-					is_ignore = common.Int64All(v1["is_ignore"])
-				} else {
-					is_ignore = common.Int64All(v1["is_ignore"])
-				}
-				switch employType {
-				case 2:
-					if employStatus == 1 {
-						employ2 = true
-					}
-				case 3:
-					if employStatus == 1 {
-						employ3 = true
-					}
-				}
-				if is_ignore > 0 {
-					employIgnore = true
-				}
-				employType = common.Int64All(v1["type"])
-				employId = common.Int64All(v1["id"])
-			}
-			valueMap["isIgnore"] = employIgnore
-			if in.From == "jhfp" {
-				valueMap["isEmploy"] = employ3
-			} else {
-				valueMap["isEmploy"] = common.If(employ2 && employ3, true, false)
-			}
-			valueMap["type"] = employType
-			valueMap["employId"] = employId
-		} else {
-			valueMap["isIgnore"] = common.If(common.Int64All((*employData)[0]["is_ignore"]) == 1, true, false)
-			valueMap["isEmploy"] = common.If(common.Int64All((*employData)[0]["status"]) == 1, true, false)
-			valueMap["type"] = common.Int64All((*employData)[0]["type"])
-			employId = common.Int64All((*employData)[0]["id"])
-			valueMap["employId"] = employId
-		}
-
-	} else {
-		valueMap["isIgnore"] = false
-		valueMap["isEmploy"] = false
-		valueMap["type"] = 1
+	if len(wuye1Arr) > 0 {
+		wuyeData1 = MC.CrmMysql.SelectBySql(fmt.Sprintf("select  is_ignore,status,id,type from  %s   where position_id =? and  %s in ('%s')  GROUP BY %s ", table, employKey, strings.Join(wuye1Arr, "','"), employKey), in.PositionId, 1)
 	}
-	if len(strings.Split(in.IdArr, ",")) == 1 && employId > 0 {
-		//列表查询
-		//是否忽略处理
-		//客户数量
-		customCount := MC.CrmMysql.Count(entity.CUSTOM, map[string]interface{}{
-			findKey:       employId,
-			"position_id": in.PositionId,
-		})
-		valueMap["customCount"] = customCount
-		if in.EmployType == 1 || in.EmployType == 4 {
-			//销售线索数量
-			clueCount := MC.CrmMysql.Count(entity.SALE_CLUE, map[string]interface{}{
-				"employ_info_id": employId,
-				"position_id":    in.PositionId,
-			})
-			valueMap["clueCount"] = clueCount
-			//销售机会数量
-			chanceCount := MC.CrmMysql.Count(entity.SALE_CHANCE, map[string]interface{}{
-				"employ_info_id": employId,
-				"position_id":    in.PositionId,
-			})
-			valueMap["chanceCount"] = chanceCount
-		}
-	} else {
-		valueMap["chanceCount"] = 0
-		valueMap["clueCount"] = 0
-		valueMap["isIgnore"] = false
-		valueMap["customCount"] = 0
+	if len(wuye2Arr) > 0 {
+		wuyeData2 = MC.CrmMysql.SelectBySql(fmt.Sprintf("select  is_ignore,status,id,type from  %s   where position_id =? and  %s in ('%s')    GROUP BY %s ", table, employKey, strings.Join(wuye2Arr, "','"), employKey), in.PositionId, 1)
 	}
-	return valueMap
+	for _, v := range *infoData1 {
+		valueMap := map[string]interface{}{
+			"id":          v,
+			"isIgnore":    false,
+			"isEmploy":    false,
+			"customCount": 0,
+			"clueCount":   0,
+			"chanceCount": 0,
+			"type":        1,
+		}
+		sourceId := gconv.String(v[employKey])
+		data[sourceId] = EmployHandle(valueMap, v, 0, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
+	}
+	for _, v := range *infoData2 {
+		valueMap := map[string]interface{}{
+			"id":          v,
+			"isIgnore":    false,
+			"isEmploy":    false,
+			"customCount": 0,
+			"clueCount":   0,
+			"chanceCount": 0,
+			"type":        1,
+		}
+		sourceId := gconv.String(v[employKey])
+		data[sourceId] = EmployHandle(valueMap, v, 0, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
+	}
+	for _, v := range *niJianData {
+		valueMap := map[string]interface{}{
+			"id":          v,
+			"isIgnore":    false,
+			"isEmploy":    false,
+			"customCount": 0,
+			"clueCount":   0,
+			"chanceCount": 0,
+			"type":        1,
+		}
+		sourceId := gconv.String(v[employKey])
+		data[sourceId] = EmployHandle(valueMap, v, 0, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
+	}
+	for _, v := range *wuyeData1 {
+		valueMap := map[string]interface{}{
+			"id":          v,
+			"isIgnore":    false,
+			"isEmploy":    false,
+			"customCount": 0,
+			"clueCount":   0,
+			"chanceCount": 0,
+			"type":        1,
+		}
+		sourceId := gconv.String(v[employKey])
+		data[sourceId] = EmployHandle(valueMap, v, 1, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
+	}
+	for _, v := range *wuyeData2 {
+		valueMap := map[string]interface{}{
+			"id":          v,
+			"isIgnore":    false,
+			"isEmploy":    false,
+			"customCount": 0,
+			"clueCount":   0,
+			"chanceCount": 0,
+			"type":        1,
+		}
+		sourceId := gconv.String(v[employKey])
+		data[sourceId] = EmployHandle(valueMap, v, 1, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
+	}
+	return data
 }
 
 // 企业收录情况查询
-func employInfoEnt(v, table, id, employKey, findKey, depIDArr string, source int64, in *types.InfoEmployinfoReq, projectId string, isNiJian bool, version int, subtype string) map[string]interface{} {
-	valueMap := map[string]interface{}{
-		"id":          v,
-		"isIgnore":    false,
-		"isEmploy":    false,
-		"customCount": 0,
-		"clueCount":   0,
-		"chanceCount": 0,
-		"type":        1,
-	}
-	sourceId := ""
-	if isNiJian {
-		sourceId = projectId
-	} else {
-		sourceId = id
+func employInfoEnt(table, employKey, findKey, depIDArr string, in *types.InfoEmployinfoReq, version int, subtype string, infoId1Arr, infoId2Arr, niJianIdArr, wuye1Arr, wuye2Arr []string) map[string]map[string]interface{} {
+	data := map[string]map[string]interface{}{}
+	infoData1 := &[]map[string]interface{}{}
+	infoData2 := &[]map[string]interface{}{}
+	niJianData := &[]map[string]interface{}{}
+	wuyeData1 := &[]map[string]interface{}{}
+	wuyeData2 := &[]map[string]interface{}{}
+	if len(infoId1Arr) > 0 {
+		infoData1 = MC.CrmMysql.SelectBySql(fmt.Sprintf("select  %s,GROUP_CONCAT(id) as  employIdArr,MAX(is_ignore) as is_ignore,MAX(status) as status from  %s   where %s in ('%s') and  source=? and    ent_dept_id in  (%s) GROUP BY %s ", employKey, table, employKey, strings.Join(infoId1Arr, "','"), depIDArr, employKey), 1)
 	}
-	employData := &[]map[string]interface{}{}
-	if in.EmployType == 1 {
-		if (subtype == "成交" || subtype == "中标" || subtype == "合同" || subtype == "验收" || subtype == "违规") && in.EmployType == 1 && version == 1 {
-			//物业版本查询
-			employData = MC.CrmMysql.SelectBySql(fmt.Sprintf("select  id,is_ignore,status ,type  from  %s   where %s=?  and status =1 and  source=? and    ent_dept_id in  (%s) ", table, employKey, depIDArr), sourceId, source)
-		} else {
-			employData = MC.CrmMysql.SelectBySql(fmt.Sprintf("select  GROUP_CONCAT(id) as  employIdArr,MAX(is_ignore) as is_ignore,MAX(status) as status,MAX(type) as  type from  %s   where %s=? and  source=? and    ent_dept_id in  (%s) ", table, employKey, depIDArr), sourceId, source)
-		}
-	} else {
-		employData = MC.CrmMysql.SelectBySql(fmt.Sprintf("select  GROUP_CONCAT(id) as  employIdArr,MAX(is_ignore) as is_ignore,MAX(status) as status from  %s   where %s=? and  source=? and    ent_dept_id in  (%s) ", table, employKey, depIDArr), sourceId, source)
+	if len(infoId2Arr) > 0 {
+		infoData2 = MC.CrmMysql.SelectBySql(fmt.Sprintf("select %s, GROUP_CONCAT(id) as  employIdArr,MAX(is_ignore) as is_ignore,MAX(status) as status from  %s   where %s in ('%s') and  source=? and    ent_dept_id in  (%s)  GROUP BY %s ", employKey, table, employKey, strings.Join(infoId2Arr, "','"), depIDArr, employKey), 2)
+	}
+	if len(niJianIdArr) > 0 {
+		niJianData = MC.CrmMysql.SelectBySql(fmt.Sprintf("select %s, GROUP_CONCAT(id) as  employIdArr,MAX(is_ignore) as is_ignore,MAX(status) as status from  %s   where %s  in ('%s') and  source=? and    ent_dept_id in  (%s) GROUP BY %s ", employKey, table, employKey, strings.Join(niJianIdArr, "','"), depIDArr, employKey), 2)
+	}
+	if len(wuye1Arr) > 0 {
+		wuyeData1 = MC.CrmMysql.SelectBySql(fmt.Sprintf("select %s,  id,is_ignore,status ,type  from  %s   where %s in ('%s')  and status =1 and  source=? and    ent_dept_id in  (%s)  GROUP BY %s  ", employKey, table, employKey, strings.Join(wuye1Arr, "','"), depIDArr, employKey), 1)
 	}
+	if len(wuye2Arr) > 0 {
+		wuyeData2 = MC.CrmMysql.SelectBySql(fmt.Sprintf("select %s id,is_ignore,status ,type  from  %s   where %s  in ('%s')  and status =1 and  source=? and    ent_dept_id in  (%s) GROUP BY %s ", employKey, table, employKey, strings.Join(wuye2Arr, "','"), depIDArr, employKey), 2)
+	}
+	for _, v := range *infoData1 {
+		valueMap := map[string]interface{}{
+			"id":          v,
+			"isIgnore":    false,
+			"isEmploy":    false,
+			"customCount": 0,
+			"clueCount":   0,
+			"chanceCount": 0,
+			"type":        1,
+		}
+		sourceId := gconv.String(v[employKey])
+		data[sourceId] = EmployHandle(valueMap, v, 0, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
+	}
+	for _, v := range *infoData2 {
+		valueMap := map[string]interface{}{
+			"id":          v,
+			"isIgnore":    false,
+			"isEmploy":    false,
+			"customCount": 0,
+			"clueCount":   0,
+			"chanceCount": 0,
+			"type":        1,
+		}
+		sourceId := gconv.String(v[employKey])
+		data[sourceId] = EmployHandle(valueMap, v, 0, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
+	}
+	for _, v := range *niJianData {
+		valueMap := map[string]interface{}{
+			"id":          v,
+			"isIgnore":    false,
+			"isEmploy":    false,
+			"customCount": 0,
+			"clueCount":   0,
+			"chanceCount": 0,
+			"type":        1,
+		}
+		sourceId := gconv.String(v[employKey])
+		data[sourceId] = EmployHandle(valueMap, v, version, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
+	}
+	for _, v := range *wuyeData1 {
+		valueMap := map[string]interface{}{
+			"id":          v,
+			"isIgnore":    false,
+			"isEmploy":    false,
+			"customCount": 0,
+			"clueCount":   0,
+			"chanceCount": 0,
+			"type":        1,
+		}
+		sourceId := gconv.String(v[employKey])
+		data[sourceId] = EmployHandle(valueMap, v, 1, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
+	}
+	for _, v := range *wuyeData2 {
+		valueMap := map[string]interface{}{
+			"id":          v,
+			"isIgnore":    false,
+			"isEmploy":    false,
+			"customCount": 0,
+			"clueCount":   0,
+			"chanceCount": 0,
+			"type":        1,
+		}
+		sourceId := gconv.String(v[employKey])
+		data[sourceId] = EmployHandle(valueMap, v, 1, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
+	}
+	return data
+}
+func EmployHandle(valueMap map[string]interface{}, employData map[string]interface{}, version int, originate string, single bool, findKey string, positionId, positionType, inEmployType int64) map[string]interface{} {
+	employType := common.Int64All(employData["type"])
+	employStatus := common.Int64All(employData["status"])
+	employ2 := false
+	employ3 := false
+	employIgnore := false
+	employId := int64(0)
+	is_ignore := int64(0)
 	employArrStr := ""
-	if employData != nil && len(*employData) > 0 {
-		if (subtype == "成交" || subtype == "中标" || subtype == "合同" || subtype == "验收" || subtype == "违规") && in.EmployType == 1 {
-			employ2 := false
-			employ3 := false
-			employIgnore := false
-			employType := int64(0)
-			employId := int64(0)
-			is_ignore := int64(0)
-			for _, v1 := range *employData {
-				employType := common.Int64All(v1["type"])
-				employStatus := common.Int64All(v1["status"])
-				if in.From == "jhfp" && employType == 3 {
-					is_ignore = common.Int64All(v1["is_ignore"])
-				} else {
-					is_ignore = common.Int64All(v1["is_ignore"])
-				}
-				switch employType {
-				case 2:
-					if employStatus == 1 {
-						employ2 = true
-					}
-				case 3:
-					if employStatus == 1 {
-						employ3 = true
-					}
-				}
-				if is_ignore > 0 {
-					employIgnore = true
-				}
-				employType = common.Int64All(v1["type"])
-				employId = common.Int64All(v1["id"])
+	if version == 1 {
+		if originate == "jhfp" && employType == 3 {
+			is_ignore = common.Int64All(employData["is_ignore"])
+		} else {
+			is_ignore = common.Int64All(employData["is_ignore"])
+		}
+		switch employType {
+		case 2:
+			if valueMap["employ3"] != nil {
+				employ3 = gconv.Bool(valueMap["employ3"])
 			}
-			valueMap["isIgnore"] = employIgnore
-			if in.From == "jhfp" {
-				valueMap["isEmploy"] = employ3
-			} else {
-				valueMap["isEmploy"] = common.If(employ2 && employ3, true, false)
+			if employStatus == 1 {
+				employ2 = true
 			}
-
-			valueMap["type"] = employType
-			valueMap["employId"] = employId
+		case 3:
+			if valueMap["employ2"] != nil {
+				employ3 = gconv.Bool(valueMap["employ2"])
+			}
+			if employStatus == 1 {
+				employ3 = true
+			}
+		}
+		if is_ignore > 0 {
+			employIgnore = true
+		}
+		employType = common.Int64All(employData["type"])
+		employId = common.Int64All(employData["id"])
+		valueMap["isIgnore"] = employIgnore
+		if originate == "jhfp" {
+			valueMap["isEmploy"] = employ3
 		} else {
-			valueMap["isIgnore"] = common.If(common.Int64All((*employData)[0]["is_ignore"]) == 1, true, false)
-			valueMap["isEmploy"] = common.If(common.Int64All((*employData)[0]["status"]) == 1, true, false)
-			valueMap["type"] = common.Int64All((*employData)[0]["type"])
-			employArrStr = common.InterfaceToStr((*employData)[0]["employIdArr"])
-			valueMap["employId"] = strings.Split(employArrStr, ",")[0]
+			valueMap["isEmploy"] = common.If(employ2 && employ3, true, false)
 		}
+		valueMap["type"] = employType
+		valueMap["employ2"] = employ2
+		valueMap["employ3"] = employ3
+		valueMap["employId"] = employId
 	} else {
-		valueMap["isIgnore"] = false
-		valueMap["isIgnore"] = false
-		valueMap["type"] = 1
+		valueMap["isIgnore"] = common.If(common.Int64All(employData["is_ignore"]) == 1, true, false)
+		valueMap["isEmploy"] = common.If(common.Int64All(employData["status"]) == 1, true, false)
+		valueMap["type"] = common.Int64All(employData["type"])
+		employArrStr := common.InterfaceToStr(employData["employIdArr"])
+		valueMap["employId"] = strings.Split(employArrStr, ",")[0]
 	}
-	if len(strings.Split(in.IdArr, ",")) == 1 && employArrStr != "" {
+	if single && employArrStr != "" {
 		//列表查询
 		//是否忽略处理
 		//客户数量
-		customSql := fmt.Sprintf("select  COUNT(1) from  %s where  %s  in (%s)", entity.CUSTOM, findKey, employArrStr)
+		customSql := ""
+		clueSql := ""
+		chanceSql := ""
+		if positionType == 0 {
+			customSql = fmt.Sprintf("select  COUNT(1) from  %s where  %s  in (%s) and  position_id=?", entity.CUSTOM, findKey, employArrStr, positionId)
+			clueSql = fmt.Sprintf("select  COUNT(1) from  %s where employ_info_id  in (%s) and  position_id=?", entity.SALE_CLUE, employArrStr, positionId)
+			chanceSql = fmt.Sprintf("select  COUNT(1) from  %s where employ_info_id  in (%s) and  position_id=?", entity.SALE_CHANCE, employArrStr, positionId)
+		} else {
+			customSql = fmt.Sprintf("select  COUNT(1) from  %s where  %s  in (%s)", entity.CUSTOM, findKey, employArrStr)
+			clueSql = fmt.Sprintf("select  COUNT(1) from  %s where employ_info_id  in (%s)", entity.SALE_CLUE, employArrStr)
+			chanceSql = fmt.Sprintf("select  COUNT(1) from  %s where employ_info_id  in (%s)", entity.SALE_CHANCE, employArrStr)
+		}
 		customCount := MC.CrmMysql.CountBySql(customSql)
 		valueMap["customCount"] = customCount
-		if in.EmployType == 1 || in.EmployType == 4 {
+		if inEmployType == 1 || inEmployType == 4 {
 			//销售线索数量
-			clueSql := fmt.Sprintf("select  COUNT(1) from  %s where employ_info_id  in (%s)", entity.SALE_CLUE, employArrStr)
 			clueCount := MC.CrmMysql.CountBySql(clueSql)
 			valueMap["clueCount"] = clueCount
 			//销售机会数量
-			chanceSql := fmt.Sprintf("select  COUNT(1) from  %s where employ_info_id  in (%s)", entity.SALE_CHANCE, employArrStr)
 			chanceCount := MC.CrmMysql.CountBySql(chanceSql)
 			valueMap["chanceCount"] = chanceCount
 		}