瀏覽代碼

Merge branch 'dev_v1.0.1.1_wh' of CRM/application into hotfix/v1.0.1.1

王浩 1 年之前
父節點
當前提交
79144bfde6
共有 1 個文件被更改,包括 92 次插入62 次删除
  1. 92 62
      api/internal/service/employService.go

+ 92 - 62
api/internal/service/employService.go

@@ -77,45 +77,42 @@ func (e *EmPloyService) InfoEmployinfo(in *types.InfoEmployinfoReq) ([]map[strin
 	wuye1Arr := []string{}
 	wuye2Arr := []string{}
 	infoMap := map[string]interface{}{}
-	var table, findKey, employKey, projectId, subtype string
-	for _, v := range strings.Split(in.IdArr, ",") {
-		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
+	table, findKey, employKey, employData := employKeyFormat(in.EmployType, in.IdArr)
+	for _, employ := range employData {
+		source := employ.Source
+		isNiJian := employ.IsNiJian
+		if (employ.Subtype == "成交" || employ.Subtype == "中标" || employ.Subtype == "合同" || employ.Subtype == "验收" || employ.Subtype == "违规") && in.EmployType == 1 && version == 1 {
+			infoMap[employ.Id] = employ.ProjectId
 			if isNiJian {
-				infoMap[v] = projectId
+				infoMap[employ.Id] = employ.ProjectId
 				if source == 1 {
-					wuye1Arr = append(wuye1Arr, projectId)
+					wuye1Arr = append(wuye1Arr, employ.ProjectId)
 				} else {
-					wuye2Arr = append(wuye2Arr, projectId)
+					wuye2Arr = append(wuye2Arr, employ.ProjectId)
 				}
 			} else {
-				infoMap[v] = id
+				infoMap[employ.Id] = employ.SourceId
 				if source == 1 {
-					wuye1Arr = append(wuye1Arr, id)
+					wuye1Arr = append(wuye1Arr, employ.SourceId)
 				} else {
-					wuye2Arr = append(wuye2Arr, id)
+					wuye2Arr = append(wuye2Arr, employ.SourceId)
 				}
 			}
 		} else if isNiJian {
-			infoMap[v] = projectId
-			niJianIdArr = append(niJianIdArr, projectId)
+			infoMap[employ.Id] = employ.ProjectId
+			niJianIdArr = append(niJianIdArr, employ.ProjectId)
 		} else if source == 2 {
-			infoMap[v] = id
-			infoId2Arr = append(infoId2Arr, id)
+			infoMap[employ.Id] = employ.SourceId
+			infoId2Arr = append(infoId2Arr, employ.SourceId)
 		} else if source == 1 {
-			infoMap[v] = id
-			infoId1Arr = append(infoId1Arr, id)
+			infoMap[employ.Id] = employ.SourceId
+			infoId1Arr = append(infoId1Arr, employ.SourceId)
 		}
-
 	}
 	//收录情况查询
 	dataList := map[string]map[string]interface{}{}
 	if in.EntNicheDis > 0 {
-		dataList = employInfoEnt(table, employKey, findKey, depIDArr, in, version, subtype, infoId1Arr, infoId2Arr, niJianIdArr, wuye1Arr, wuye2Arr)
+		dataList = employInfoEnt(table, employKey, findKey, depIDArr, in, version, infoId1Arr, infoId2Arr, niJianIdArr, wuye1Arr, wuye2Arr)
 	} else {
 		dataList = employInfoPerson(table, employKey, findKey, in, version, infoId1Arr, infoId2Arr, niJianIdArr, wuye1Arr, wuye2Arr)
 	}
@@ -152,20 +149,18 @@ func (e *EmPloyService) EmployOperate(in *types.EmployOperateReq) (bool, string)
 	msg := ""
 	return MC.CrmMysql.ExecTx("收录操作", func(tx *sql.Tx) bool {
 		fool := false
-		for _, v1 := range strings.Split(in.IdArr, ",") {
-			//id转中文
-			id := ""
+		//id转中文
+		table, _, employKey, data := employKeyFormat(in.EmployType, in.IdArr)
+		for id, employ := range data {
 			findMap := map[string]interface{}{}
 			findMap["position_id"] = in.PositionId
-			id = idFormat(v1, in.EmployType)
-			table, _, employKey, source, projectId, isNijian, _ := employKeyFormat(in.EmployType, id)
-			if isNijian {
-				findMap[employKey] = projectId
+			if employ.IsNiJian {
+				findMap[employKey] = employ.ProjectId
 			} else {
 				findMap[employKey] = id
 			}
-			if id == "" {
-				log.Println(v1, in.EmployType, "该信息查询不到数据")
+			if employ.SourceId == "" {
+				log.Println(employ.Id, in.EmployType, "该信息查询不到数据")
 				continue
 			}
 			if in.IsEmploy {
@@ -177,15 +172,15 @@ func (e *EmPloyService) EmployOperate(in *types.EmployOperateReq) (bool, string)
 					//收录新增
 					data := map[string]interface{}{}
 					if in.EmployType == 1 || in.EmployType == 4 {
-						data = infoFind(id, v1)
+						data = infoFind(id, employ.SourceId)
 					} else if in.EmployType == 2 {
 						data = customFind(id, in.EmployType)
-						data["jybx_url"] = "/swordfish/page_big_pc/ent_portrait/" + v1
-						data["source"] = source
+						data["jybx_url"] = "/swordfish/page_big_pc/ent_portrait/" + employ.Id
+						data["source"] = employ.Source
 					} else if in.EmployType == 3 {
 						data = customFind(id, in.EmployType)
-						data["jybx_url"] = "/publicapply/biTransfer?buyerName=" + v1
-						data["source"] = source
+						data["jybx_url"] = "/publicapply/biTransfer?buyerName=" + employ.Id
+						data["source"] = employ.Source
 					}
 					data["position_id"] = in.PositionId
 					data["ent_id"] = in.EntId
@@ -193,7 +188,7 @@ func (e *EmPloyService) EmployOperate(in *types.EmployOperateReq) (bool, string)
 					data["ent_user_id"] = in.EntUserId
 					ok := MC.CrmMysql.InsertByTx(tx, table, data)
 					if ok <= 0 {
-						log.Println(v1, id, in.EmployType, "收录失败")
+						log.Println(employ.Id, id, in.EmployType, "收录失败")
 						continue
 					}
 				}
@@ -208,7 +203,7 @@ func (e *EmPloyService) EmployOperate(in *types.EmployOperateReq) (bool, string)
 						"status": -1,
 					})
 					if !ok {
-						log.Println(v1, id, in.EmployType, "取消收录失败")
+						log.Println(employ.Id, id, in.EmployType, "取消收录失败")
 						continue
 					}
 					fool = true
@@ -361,39 +356,29 @@ func idFormat(encryptionId string, employType int64) string {
 	return decryptId
 }
 
+type Employ struct {
+	Source    int64
+	IsNiJian  bool
+	ProjectId string
+	Id        string
+	SourceId  string
+	Subtype   string
+}
+
 // employKeyFormat 根据收录类型 字段处理 table,findKey,employKey,source
-func employKeyFormat(employType int64, id string) (string, string, string, int64, string, bool, string) {
+func employKeyFormat(employType int64, idArrStr string) (string, string, string, map[string]Employ) {
 	table := ""
 	employKey := "company_id"
 	findKey := "employ_custom_id"
-	projectId := ""
+	infoIdMap := map[string]Employ{}
+	idArr := []string{}
 	source := int64(0)
-	IsNiJian := false
-	subtype := ""
 	switch employType {
 	case 1:
 		table = entity.EMPLOY_INFO
 		employKey = "source_id"
 		findKey = "employ_info_id"
 		source = 1
-		obj := map[string]interface{}{}
-		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 obj != nil && len(obj) > 0 {
-			subtype = common.InterfaceToStr(obj["subtype"])
-			if subtype == "拟建" {
-				project, _ := MC.MgoProject.FindOne("projectset_proposed", map[string]interface{}{
-					"ids": id,
-				})
-				source = 2
-				if project != nil && len(*project) > 0 {
-					projectId = common.InterfaceToStr((*project)["_id"])
-					IsNiJian = true
-				}
-			}
-		}
 	case 2:
 		table = entity.EMPLOY_CUSTOM
 		source = 1
@@ -406,7 +391,52 @@ func employKeyFormat(employType int64, id string) (string, string, string, int64
 		employKey = "source_id"
 		findKey = "employ_info_id"
 	}
-	return table, findKey, employKey, source, projectId, IsNiJian, subtype
+	for _, v := range strings.Split(idArrStr, ",") {
+		id := idFormat(v, employType)
+		idArr = append(idArr, id)
+		infoIdMap[id] = Employ{
+			Source:    source,
+			IsNiJian:  false,
+			ProjectId: "",
+			Id:        v,
+			SourceId:  id,
+		}
+	}
+
+	if employType == 1 {
+		table = entity.EMPLOY_INFO
+		employKey = "source_id"
+		findKey = "employ_info_id"
+		source = 1
+		aobj := elastic.Get(INDEX, TYPE, fmt.Sprintf(`{"query":{"bool":{"must_not":[],"should":[ {
+          "terms": {
+            "id": [
+              "%s"
+            ]
+          }
+        }]}},"from":0,"size":100,"_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":{}}`, strings.Join(idArr, `","`)))
+		if aobj != nil && len(*aobj) > 0 || *aobj != nil {
+			for _, v := range *aobj {
+				id := common.InterfaceToStr(v["_id"])
+				subtype := common.InterfaceToStr(v["subtype"])
+				data, ok := infoIdMap[id]
+				data.Subtype = subtype
+				if subtype == "拟建" && ok {
+					project, _ := MC.MgoProject.FindOne("projectset_proposed", map[string]interface{}{
+						"ids": id,
+					})
+					data.Source = 2
+					if project != nil && len(*project) > 0 {
+						projectId := common.InterfaceToStr((*project)["_id"])
+						data.IsNiJian = true
+						data.ProjectId = projectId
+					}
+				}
+				infoIdMap[id] = data
+			}
+		}
+	}
+	return table, findKey, employKey, infoIdMap
 
 }
 
@@ -722,7 +752,7 @@ func employInfoPerson(table, employKey, findKey string, in *types.InfoEmployinfo
 }
 
 // 企业收录情况查询
-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{} {
+func employInfoEnt(table, employKey, findKey, depIDArr 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{}{}