Browse Source

运营商专版 xg

Jianghan 7 months ago
parent
commit
a45408f595
2 changed files with 129 additions and 59 deletions
  1. 29 42
      CMPlatform/history/task.go
  2. 100 17
      CMPlatform/service/data_ent.go

+ 29 - 42
CMPlatform/history/task.go

@@ -1002,70 +1002,55 @@ func GetMactchKeys(match []map[string]string, data map[string]interface{}) (stri
 	keyWord := []string{}
 	keyType := []string{}
 	for _, keys := range match {
-		types := keys["s_keymatch"] // 1,2,3
-		key := keys["s_matchkey"]   //软件,工程
+		types := keys["s_keymatch"]
+		key := keys["s_matchkey"]
 		if strings.Contains(types, "1") {
 			title := common.ObjToString(data["title"])
-			keyWord = KeyWordToDatas(types, title, key, keyWord)
-			if len(keyType) == 0 && len(keyWord) > 0 {
-				keyType = append(keyType, "title")
-			}
+			keyWord, keyType = KeyWordToDatas(types, title, key, keyWord, keyType, "title")
 		}
 		if strings.Contains(types, "2") {
 			detail := common.ObjToString(data["detail"])
-			keyWord = KeyWordToDatas(types, detail, key, keyWord)
-			if len(keyType) == 0 && len(keyWord) > 0 {
-				keyType = append(keyType, "detail")
-			}
+			keyWord, keyType = KeyWordToDatas(types, detail, key, keyWord, keyType, "detail")
 		}
 		if strings.Contains(types, "3") {
 			purchasing := common.ObjToString(data["purchasing"])
-			keyWord = KeyWordToDatas(types, purchasing, key, keyWord)
-			if len(keyType) == 0 && len(keyWord) > 0 {
-				keyType = append(keyType, "purchasing")
-			}
+			keyWord, keyType = KeyWordToDatas(types, purchasing, key, keyWord, keyType, "purchasing")
 		}
 		if strings.Contains(types, "4") {
 			filetext := common.ObjToString(data["filetext"])
-			keyWord = KeyWordToDatas(types, filetext, key, keyWord)
-			if len(keyType) == 0 && len(keyWord) > 0 {
-				keyType = append(keyType, "filetext")
-			}
+			keyWord, keyType = KeyWordToDatas(types, filetext, key, keyWord, keyType, "filetext")
 		}
 		if strings.Contains(types, "5") {
 			projectname := common.ObjToString(data["projectname"])
-			keyWord = KeyWordToDatas(types, projectname, key, keyWord)
-			if len(keyType) == 0 && len(keyWord) > 0 {
-				keyType = append(keyType, "projectname")
-			}
+			keyWord, keyType = KeyWordToDatas(types, projectname, key, keyWord, keyType, "projectname")
 		}
 		if strings.Contains(types, "6") || strings.Contains(types, "8") {
 			buyer := common.ObjToString(data["buyer"])
-			keyWord = KeyWordToDatas(types, buyer, key, keyWord)
-			if len(keyType) == 0 && len(keyWord) > 0 {
-				keyType = append(keyType, "buyer")
-			}
+			keyWord, keyType = KeyWordToDatas(types, buyer, key, keyWord, keyType, "buyer")
 		}
 		if strings.Contains(types, "7") || strings.Contains(types, "9") {
 			winner := common.ObjToString(data["s_winner"])
-			keyWord = KeyWordToDatas(types, winner, key, keyWord)
-			if len(keyType) == 0 && len(keyWord) > 0 {
-				keyType = append(keyType, "winner")
-			}
+			keyWord, keyType = KeyWordToDatas(types, winner, key, keyWord, keyType, "s_winner")
 		}
 	}
-	keyMap := map[string]bool{}
-	keyArr := []string{}
+	keyMap, keyTypeMap := map[string]bool{}, map[string]bool{}
+	keyArr, keyTypeArr := []string{}, []string{}
 	for _, key := range keyWord {
 		keyMap[key] = true
 	}
 	for k, _ := range keyMap {
 		keyArr = append(keyArr, k)
 	}
-	return strings.Join(keyArr, ","), strings.Join(keyType, ",")
+	for _, key := range keyType {
+		keyTypeMap[key] = true
+	}
+	for k, _ := range keyTypeMap {
+		keyTypeArr = append(keyTypeArr, k)
+	}
+	return strings.Join(keyArr, ","), strings.Join(keyTypeArr, ",")
 }
 
-func KeyWordToDatas(types, item, key string, keyWord []string) []string {
+func KeyWordToDatas(types, item, key string, keyWord []string, keyType []string, tag string) ([]string, []string) {
 	for _, mk := range strings.Split(key, ",") {
 		if strings.Contains(mk, "&&") {
 			arr := strings.Split(mk, "&&")
@@ -1079,45 +1064,47 @@ func KeyWordToDatas(types, item, key string, keyWord []string) []string {
 			}
 			if isok {
 				keyWord = append(keyWord, mk)
+				keyType = append(keyType, tag)
 			}
 		} else {
 			if strings.Contains(strings.ToUpper(item), strings.ToUpper(mk)) {
 				keyWord = append(keyWord, mk)
+				keyType = append(keyType, tag)
 			}
 		}
 	}
-	return keyWord
+	return keyWord, keyType
 }
 
 func TestMactchKeys(types, key string, data map[string]interface{}) string {
 	keyWord := []string{}
 	if strings.Contains(types, "1") {
 		title := common.ObjToString(data["title"])
-		keyWord = KeyWordToDatas(types, title, key, keyWord)
+		keyWord, _ = KeyWordToDatas(types, title, key, keyWord, []string{}, "")
 	}
 	if strings.Contains(types, "2") {
 		detail := common.ObjToString(data["detail"])
-		keyWord = KeyWordToDatas(types, detail, key, keyWord)
+		keyWord, _ = KeyWordToDatas(types, detail, key, keyWord, []string{}, "")
 	}
 	if strings.Contains(types, "3") {
 		purchasing := common.ObjToString(data["purchasing"])
-		keyWord = KeyWordToDatas(types, purchasing, key, keyWord)
+		keyWord, _ = KeyWordToDatas(types, purchasing, key, keyWord, []string{}, "")
 	}
 	if strings.Contains(types, "4") {
 		filetext := common.ObjToString(data["filetext"])
-		keyWord = KeyWordToDatas(types, filetext, key, keyWord)
+		keyWord, _ = KeyWordToDatas(types, filetext, key, keyWord, []string{}, "")
 	}
 	if strings.Contains(types, "5") {
 		projectname := common.ObjToString(data["projectname"])
-		keyWord = KeyWordToDatas(types, projectname, key, keyWord)
+		keyWord, _ = KeyWordToDatas(types, projectname, key, keyWord, []string{}, "")
 	}
 	if strings.Contains(types, "6") || strings.Contains(types, "8") {
 		buyer := common.ObjToString(data["buyer"])
-		keyWord = KeyWordToDatas(types, buyer, key, keyWord)
+		keyWord, _ = KeyWordToDatas(types, buyer, key, keyWord, []string{}, "")
 	}
 	if strings.Contains(types, "7") || strings.Contains(types, "9") {
 		winner := common.ObjToString(data["s_winner"])
-		keyWord = KeyWordToDatas(types, winner, key, keyWord)
+		keyWord, _ = KeyWordToDatas(types, winner, key, keyWord, []string{}, "")
 	}
 	keyMap := map[string]bool{}
 	keyArr := []string{}

+ 100 - 17
CMPlatform/service/data_ent.go

@@ -4,6 +4,7 @@ import (
 	"app.yhyue.com/moapp/jybase/common"
 	"app.yhyue.com/moapp/jybase/date"
 	elastic "app.yhyue.com/moapp/jybase/es"
+	"app.yhyue.com/moapp/jybase/go-xweb/uuid"
 	"app.yhyue.com/moapp/jybase/go-xweb/xweb"
 	"app.yhyue.com/moapp/jybase/log"
 	"app.yhyue.com/moapp/jybase/mongodb"
@@ -103,6 +104,7 @@ func ImportDataByExcel(mf multipart.File, eid int64, entid string) (int, int64,
 	rows := sheet.Rows
 	ch := make(chan bool, 20) // 协程处理
 	var idLock sync.Mutex
+	var areaIdLock sync.Mutex
 	wg := &sync.WaitGroup{}
 	for rn, row := range rows {
 		if rn == 0 {
@@ -150,7 +152,7 @@ func ImportDataByExcel(mf multipart.File, eid int64, entid string) (int, int64,
 							tmp[fMap[index]] = id
 						}
 						info1 := util.EntMysql.FindOne("customer_data_yys_permission_elements", bson.M{"ent_id": eid, "element_field": "region", "pcode": "$isNull"}, "", "")
-						if info1 != nil && len(*info) > 0 {
+						if info1 != nil && len(*info1) > 0 {
 							util.EntMysql.Insert("customer_data_yys_permission_elements", bson.M{"name": val, "ent_id": eid,
 								"element_field": "region", "pcode": common.IntAll((*info1)["code"]), "element_value": id})
 						}
@@ -170,12 +172,33 @@ func ImportDataByExcel(mf multipart.File, eid int64, entid string) (int, int64,
 							tmp[fMap[index]] = id
 						}
 						info1 := util.EntMysql.FindOne("customer_data_yys_permission_elements", bson.M{"ent_id": eid, "element_field": "industry", "pcode": "$isNull"}, "", "")
-						if info1 != nil && len(*info) > 0 {
+						if info1 != nil && len(*info1) > 0 {
+							util.EntMysql.Insert("customer_data_yys_permission_elements", bson.M{"name": val, "ent_id": eid,
+								"element_field": "industry", "pcode": common.IntAll((*info1)["code"]), "element_value": id})
+						}
+						idLock.Unlock()
+					} else if fMap[index] == "businesstype" {
+						// 行业
+						idLock.Lock()
+						var id int64
+						info := util.EntMysql.FindOne("d_yys_analyze_dimensions", bson.M{"ent_id": eid, "name": val,
+							"type": 6}, "", "")
+						if info != nil && len(*info) > 0 {
+							id = common.Int64All((*info)["code"])
+							tmp[fMap[index]] = id
+						} else {
+							id = util.EntMysql.Insert("d_yys_analyze_dimensions", bson.M{"ent_id": eid, "name": val,
+								"type": 6})
+							tmp[fMap[index]] = id
+						}
+						info1 := util.EntMysql.FindOne("customer_data_yys_permission_elements", bson.M{"ent_id": eid, "element_field": "industry", "pcode": "$isNull"}, "", "")
+						if info1 != nil && len(*info1) > 0 {
 							util.EntMysql.Insert("customer_data_yys_permission_elements", bson.M{"name": val, "ent_id": eid,
 								"element_field": "industry", "pcode": common.IntAll((*info1)["code"]), "element_value": id})
 						}
 						idLock.Unlock()
-					} else if fMap[index] == "bidopentime" || fMap[index] == "publishtime" || fMap[index] == "docstarttime" || fMap[index] == "bidstarttime" || fMap[index] == "bidendtime" {
+					} else if fMap[index] == "bidopentime" || fMap[index] == "publishtime" || fMap[index] == "docstarttime" || fMap[index] == "bidstarttime" || fMap[index] == "bidendtime" ||
+						fMap[index] == "expurasingtime" {
 						if cell.Type() == xlsx.CellTypeNumeric {
 							dates, err := cell.GetTime(false)
 							if err != nil {
@@ -186,7 +209,6 @@ func ImportDataByExcel(mf multipart.File, eid int64, entid string) (int, int64,
 						} else {
 							tmp[fMap[index]] = val
 						}
-
 					} else if fMap[index] == "winner_tag" {
 						// 中标单位标签
 						idLock.Lock()
@@ -207,6 +229,8 @@ func ImportDataByExcel(mf multipart.File, eid int64, entid string) (int, int64,
 								"element_field": "winner_tag", "pcode": common.IntAll((*info1)["code"]), "element_value": id})
 						}
 						idLock.Unlock()
+					} else if fMap[index] == "multpackage" {
+						tmp[fMap[index]] = common.IntAll(val)
 					} else {
 						if fMap[index] != "" {
 							tmp[fMap[index]] = val
@@ -214,8 +238,21 @@ func ImportDataByExcel(mf multipart.File, eid int64, entid string) (int, int64,
 					}
 				}
 			}
-			if tmp["infoid"] == nil {
-				return
+			if tmp["infoid"] != nil {
+				tmp["bid"] = tmp["infoid"]
+				if common.IntAll(tmp["multpackage"]) == 1 {
+					tmp["infoid"] = common.GetMd5String(fmt.Sprintf("%s-%s", tmp["bid"], common.ObjToString(tmp["packagenumb"])))
+				}
+			} else {
+				if common.IntAll(tmp["multpackage"]) == 0 {
+					str := strings.ReplaceAll(uuid.New(), "-", "")
+					tmp["bid"] = str
+					tmp["infoid"] = common.GetMd5String(str)
+				} else {
+					str := strings.ReplaceAll(uuid.New(), "-", "")
+					tmp["bid"] = str
+					tmp["infoid"] = common.GetMd5String(fmt.Sprintf("%s-%s", str, common.ObjToString(tmp["packagenumb"])))
+				}
 			}
 			*importDataNum++
 			if common.ObjToString(tmp["href"]) == "#" || strings.Contains(common.ObjToString(tmp["href"]), "jianyu360.cn") {
@@ -225,12 +262,16 @@ func ImportDataByExcel(mf multipart.File, eid int64, entid string) (int, int64,
 			}
 			tmp["eid"] = eid
 			tmp["entid"] = entid
-			tmp["jybxhref"] = "https://www.jianyu360.cn/succbi/yyssjdz/app/sjdz.app/detail.spg?E_id=" + common.ObjToString(tmp["infoid"])
+			tmp["jybxhref"] = "https://www.jianyu360.cn/succbi/yyssjdz/app/sjdz.app/detail.spg?E_id=" + common.ObjToString(tmp["bid"])
 			tmp["pici"] = now.Format(date.Date_Full_Layout)
 			if tmp["tagname3"] == nil {
 				tmp["tagname3"] = "DICT"
 			}
-			if info := util.EntMysql.FindOne("customer_data", bson.M{"entid": entid, "infoid": tmp["infoid"]}, "", ""); info != nil && len(*info) > 0 {
+			areaIdLock.Lock()
+			areaFuc(tmp) // 处理地区
+			areaIdLock.Unlock()
+			q := common.GetMd5String(fmt.Sprintf("%s-%s", common.ObjToString(tmp["bid"]), common.ObjToString(tmp["packagenumb"])))
+			if info := util.EntMysql.FindOne("customer_data", bson.M{"entid": entid, "infoid": q}, "", ""); info != nil && len(*info) > 0 {
 				tmp["status"] = 1
 				util.EntMysql.Update("customer_data", bson.M{"entid": entid, "infoid": tmp["infoid"]}, tmp)
 				id := (*info)["id"]
@@ -246,7 +287,7 @@ func ImportDataByExcel(mf multipart.File, eid int64, entid string) (int, int64,
 			} else {
 				id := util.EntMysql.Insert("customer_data", tmp)
 				tmp["id"] = id
-				detail := detailFuc(common.ObjToString(tmp["infoid"]))
+				detail := detailFuc(common.ObjToString(tmp["bid"]))
 				esSaveFuc(tmp, detail)
 			}
 		}(row.Cells, &importDataNum)
@@ -269,6 +310,45 @@ func FiledFuc(eid int64) (map[string]interface{}, map[string]interface{}) {
 	return mField, fField
 }
 
+func areaFuc(tmp map[string]interface{}) {
+	area_id := int64(0)
+	if a := common.ObjToString(tmp["area"]); a != "" {
+		info := util.EntMysql.SelectBySql("SELECT id FROM bi_service.d_yys_area_data WHERE ent_id = ? AND name = ?", tmp["eid"], a)
+		if len(*info) > 0 {
+			area_id = common.Int64All((*info)[0]["id"])
+		} else {
+			area_id = util.EntMysql.Insert("d_yys_area_data", bson.M{"ent_id": tmp["eid"], "name": a, "level": 1})
+			util.EntMysql.ExecBySql("UPDATE bi_service.d_yys_area_data SET SZ_PID0 = ? WHERE id = ?", a, area_id)
+		}
+	} else {
+		return
+	}
+	city_id := int64(0)
+	if c := common.ObjToString(tmp["city"]); c != "" {
+		info := util.EntMysql.SelectBySql("SELECT id FROM bi_service.d_yys_area_data WHERE ent_id = ? AND name = ?", tmp["eid"], c)
+		if len(*info) > 0 {
+			city_id = common.Int64All((*info)[0]["id"])
+		} else {
+			city_id = util.EntMysql.Insert("d_yys_area_data", bson.M{"ent_id": tmp["eid"], "name": c, "level": 2, "pcode": area_id})
+			util.EntMysql.ExecBySql("UPDATE bi_service.d_yys_area_data SET SZ_PID0 = ?, SZ_PID1 = ? WHERE id = ?", common.ObjToString(tmp["area"]), c, city_id)
+		}
+	} else {
+		return
+	}
+	district_id := int64(0)
+	if d := common.ObjToString(tmp["district"]); d != "" {
+		info := util.EntMysql.SelectBySql("SELECT id FROM bi_service.d_yys_area_data WHERE ent_id = ? AND name = ?", tmp["eid"], d)
+		if len(*info) > 0 {
+			district_id = common.Int64All((*info)[0]["id"])
+		} else {
+			district_id = util.EntMysql.Insert("d_yys_area_data", bson.M{"ent_id": tmp["eid"], "name": d, "level": 3, "pcode": city_id})
+			a := common.ObjToString(tmp["area"])
+			c := common.ObjToString(tmp["city"])
+			util.EntMysql.ExecBySql("UPDATE bi_service.d_yys_area_data SET SZ_PID0 = ?, SZ_PID1 = ?, SZ_PID2 = ? WHERE id = ?", a, c, d, district_id)
+		}
+	}
+}
+
 func CodeFieldFuc(entid int64) (map[string]interface{}, map[string]interface{}, map[string]interface{}) {
 	AreaMap := make(map[string]interface{})
 	IndustryMap := make(map[string]interface{})
@@ -352,6 +432,9 @@ func detailFuc(infoid string) string {
 	//if binfo != nil && len(*binfo) > 0 {
 	//	return common.ObjToString((*binfo)["ES_detail"])
 	//}
+	if !mongodb.IsObjectIdHex(infoid) {
+		return ""
+	}
 	info, _ := util.MgoBidding.FindById("bidding", infoid, bson.M{"detail": 1, "contenthtml": 1})
 	if info != nil && len(*info) == 0 {
 		info, _ = util.MgoBidding.FindById("bidding_back", infoid, bson.M{"detail": 1, "contenthtml": 1})
@@ -362,19 +445,19 @@ func detailFuc(infoid string) string {
 		save["ES_detail"] = (*info)["detail"]
 		detail = common.ObjToString((*info)["contenthtml"])
 		save["details"] = detail
+		go func() {
+			if util.EntMysql.Count("customer_data_yys_gl", bson.M{"info_id": infoid}) == 0 {
+				util.EntMysql.Insert("customer_data_yys_gl", save)
+			}
+		}()
 	}
-	go func() {
-		if util.EntMysql.Count("customer_data_yys_gl", bson.M{"info_id": infoid}) == 0 {
-			util.EntMysql.Insert("customer_data_yys_gl", save)
-		}
-	}()
 	return detail
 }
 
 func esSaveFuc(tmp map[string]interface{}, detail string) {
 	saveEs := make(map[string]interface{})
-	for _, f := range []string{"id", "tagname", "publishtime", "toptype", "subtype", "area", "city", "district", "title", "buyerclass",
-		"detail", "ent_id", "matchkey", "region", "industry", "winner_tag", "buyer", "budget", "s_winner", "bidamount", "pici"} {
+	for _, f := range []string{"id", "tagname", "publishtime", "toptype", "subtype", "area", "city", "district", "title", "buyerclass", "businesstype",
+		"detail", "ent_id", "matchkey", "region", "industry", "winner_tag", "buyer", "budget", "s_winner", "bidamount", "pici", "expurasingtime", "bidopentime"} {
 		if f == "tagname" {
 			var a1 []string
 			for _, i := range []string{"tagname", "tagname2", "tagname3"} {
@@ -387,7 +470,7 @@ func esSaveFuc(tmp map[string]interface{}, detail string) {
 			}
 		} else if f == "ent_id" {
 			saveEs[f] = tmp["eid"]
-		} else if f == "publishtime" || f == "pici" {
+		} else if f == "publishtime" || f == "pici" || f == "expurasingtime" || f == "bidopentime" {
 			thisTime, err := time.ParseInLocation(date.Date_Full_Layout, common.ObjToString(tmp[f]), time.Local)
 			if err == nil {
 				saveEs[f] = thisTime.Unix()