Browse Source

Merge branch 'ETA_1.8.7' into custom

zwxi 9 months ago
parent
commit
4fdb572003

+ 58 - 14
services/data/future_good/chart_info.go

@@ -376,13 +376,27 @@ func GetChartEdbData(chartInfoId int, startDate, endDate string, edbInfoMapping,
 // BarChartData 获取数据
 func BarChartData(edbInfoMapping *data_manage.ChartEdbInfoMapping, futureGoodMappingList []*future_good2.FutureGoodEdbInfo, edbDataListMap map[int][]*data_manage.EdbDataList, barChartInfoDateList []data_manage.BarChartInfoDateReq, regionType, latestDate string) (edbIdList []int, yDataList []data_manage.YData, err error) {
 	// 指标数据数组(10086:{"2022-12-02":100.01,"2022-12-01":102.3})
-	edbDataMap := make(map[int]map[string]float64)
+	// 现货指标数据map
+	baseEdbDataMap := make(map[string]float64)
 	for edbInfoId, edbDataList := range edbDataListMap {
+		if edbInfoId == edbInfoMapping.EdbInfoId {
+			for _, edbData := range edbDataList {
+				baseEdbDataMap[edbData.DataTime] = edbData.Value
+			}
+		}
+	}
+
+	// 期货指标数据map
+	futureGoodEdbDataMap := make(map[int]map[string]float64)
+	for edbInfoId, edbDataList := range edbDataListMap {
+		if edbInfoId == edbInfoMapping.EdbInfoId {
+			continue
+		}
 		edbDateData := make(map[string]float64)
 		for _, edbData := range edbDataList {
 			edbDateData[edbData.DataTime] = edbData.Value
 		}
-		edbDataMap[edbInfoId] = edbDateData
+		futureGoodEdbDataMap[edbInfoId] = edbDateData
 	}
 
 	// edbIdList 指标展示顺序;x轴的指标顺序
@@ -429,7 +443,7 @@ func BarChartData(edbInfoMapping *data_manage.ChartEdbInfoMapping, futureGoodMap
 		xEdbInfoIdList := make([]int, 0)    // 当前数据的指标id列表
 
 		// 现货指标
-		realDateTime, findDataValue, isFind, tmpErr := GetNeedDateData(findDateTime, edbDataListMap[edbInfoMapping.EdbInfoId], edbDataMap[edbInfoMapping.EdbInfoId])
+		realDateTime, findDataValue, isFind, tmpErr := GetNeedDateData(findDateTime, edbDataListMap[edbInfoMapping.EdbInfoId], baseEdbDataMap, futureGoodEdbDataMap)
 		if tmpErr != nil {
 			err = tmpErr
 			return
@@ -442,8 +456,13 @@ func BarChartData(edbInfoMapping *data_manage.ChartEdbInfoMapping, futureGoodMap
 			noDataIdList = append(noDataIdList, edbInfoMapping.EdbInfoId)
 			noDataIdMap[edbInfoMapping.EdbInfoId] = edbInfoMapping.EdbInfoId
 		}
-		currMonth := findDateTime.Month() // 当前月份
-		currYear := findDateTime.Year()   // 当前年份
+		//currMonth := findDateTime.Month() // 当前月份
+		//currYear := findDateTime.Year()   // 当前年份
+
+		// 用实际日期的月份作为基准,往前推12个月(2024-5-13 16:26:43修改)
+		currMonth := realDateTime.Month() // 当前月份
+		currYear := realDateTime.Year()   // 当前年份
+
 		xEdbInfoIdList = append(xEdbInfoIdList, edbInfoMapping.EdbInfoId)
 		mList := make([]int, 0) // 间隔月份
 		indexList := make([]int, 0)
@@ -482,7 +501,7 @@ func BarChartData(edbInfoMapping *data_manage.ChartEdbInfoMapping, futureGoodMap
 			//}
 			//tmpRealDateTime := findDateTime	// 按照配置找到的日期
 			tmpRealDateTime := realDateTime // 实际现货的日期
-			tmpFindDataValue, tmpIsFind := edbDataMap[futureGoodMapping.FutureGoodEdbInfoId][tmpRealDateTime.Format(utils.FormatDate)]
+			tmpFindDataValue, tmpIsFind := futureGoodEdbDataMap[futureGoodMapping.FutureGoodEdbInfoId][tmpRealDateTime.Format(utils.FormatDate)]
 			yDataMap[futureGoodMapping.FutureGoodEdbInfoId] = tmpFindDataValue
 
 			findDataList = append(findDataList, tmpFindDataValue)
@@ -860,7 +879,7 @@ func getFutureGoodEdbInfoList(latestDateTime time.Time, tmpFutureGoodEdbInfoList
 }
 
 // GetNeedDateData 获取合约内需要的日期数据
-func GetNeedDateData(needDateTime time.Time, dataList []*data_manage.EdbDataList, edbDataMap map[string]float64) (findDateTime time.Time, findDataValue float64, isFind bool, err error) {
+func GetNeedDateData(needDateTime time.Time, dataList []*data_manage.EdbDataList, edbDataMap map[string]float64, allEdbDataMap map[int]map[string]float64) (findDateTime time.Time, findDataValue float64, isFind bool, err error) {
 	//dataList := edbDataListMap[edbInfoId] //指标的所有数据值
 	if len(dataList) <= 0 {
 		// 没有数据的指标id
@@ -873,18 +892,43 @@ func GetNeedDateData(needDateTime time.Time, dataList []*data_manage.EdbDataList
 		return
 	}
 
+	// 该日期存在数据的期货指标的最小数量,目前是现货和期货各1个,总共2个
+	maxCount := 1
+
 	for tmpDateTime := needDateTime; tmpDateTime.After(minDateTime) || tmpDateTime.Equal(minDateTime); tmpDateTime = tmpDateTime.AddDate(0, 0, -1) {
 		tmpDate := tmpDateTime.Format(utils.FormatDate)
-		if tmpValue, ok := edbDataMap[tmpDate]; ok { //如果能找到数据,那么就返回
-			// 数据为0,也直接返回,做无值处理
-			if tmpValue == 0 {
-				return
+		tmpValue, ok := edbDataMap[tmpDate]
+		if !ok {
+			continue
+		}
+
+		// 该日期存在数据的指标数量
+		count := 0
+
+		for _, currEdbDataMap := range allEdbDataMap {
+			_, tmpIsFind := currEdbDataMap[tmpDate]
+			if tmpIsFind {
+				count++
+				if count >= maxCount {
+					continue
+				}
 			}
-			findDateTime, _ = time.ParseInLocation(utils.FormatDate, tmpDate, time.Local)
-			findDataValue = tmpValue
-			isFind = true
+		}
+
+		// 该日期存在数据的期货指标数量小于2个,那么要继续往前找
+		if count < maxCount {
+			continue
+		}
+
+		//如果能找到数据,那么就返回
+		// 数据为0,也直接返回,做无值处理
+		if tmpValue == 0 {
 			return
 		}
+		findDateTime, _ = time.ParseInLocation(utils.FormatDate, tmpDate, time.Local)
+		findDataValue = tmpValue
+		isFind = true
+		return
 	}
 
 	return

+ 4 - 2
services/data/future_good/profit_chart_info.go

@@ -248,7 +248,7 @@ func ProfitChartChartData(baseDataList []*data_manage.EdbDataList, futureGoodEdb
 		xEdbInfoIdList := make([]int, 0)   // 当前数据的指标id列表
 
 		// 现货指标
-		realDateTime, findDataValue, isFind, tmpErr := GetNeedDateData(findDateTime, baseDataList, baseEdbDateData)
+		realDateTime, findDataValue, isFind, tmpErr := GetNeedDateData(findDateTime, baseDataList, baseEdbDateData, edbDataMap)
 		if tmpErr != nil {
 			err = tmpErr
 			return
@@ -274,7 +274,9 @@ func ProfitChartChartData(baseDataList []*data_manage.EdbDataList, futureGoodEdb
 			//findDateTime
 
 			// 获取当前日期相对开始日期的期数
-			tmpN := (currDate.Year()-findDateTime.Year())*12 + int(currDate.Month()-findDateTime.Month())
+			//tmpN := (currDate.Year()-findDateTime.Year())*12 + int(currDate.Month()-findDateTime.Month())
+			// 用实际日期的月份作为基准,往前推12个月(2024-5-13 16:26:43修改)
+			tmpN := (currDate.Year()-realDateTime.Year())*12 + int(currDate.Month()-realDateTime.Month())
 			if tmpN <= 0 {
 				continue
 			}

+ 190 - 32
services/elastic/elastic.go

@@ -333,6 +333,35 @@ func SearchEdbInfoData(indexName, keywordStr string, from, size, filterSource, s
 	//})
 
 	//关键字匹配
+	//shouldMap := map[string]interface{}{
+	//	"should": []interface{}{
+	//		map[string]interface{}{
+	//			"match": map[string]interface{}{
+	//				"EdbCode": keywordStr,
+	//				//"Frequency.keyword": "月度",
+	//			},
+	//		},
+	//		map[string]interface{}{
+	//			"match": map[string]interface{}{
+	//				"EdbName": keywordStr,
+	//				//"Frequency.keyword": "月度",
+	//			},
+	//		},
+	//		map[string]interface{}{
+	//			"match": map[string]interface{}{
+	//				"EdbNameEn": keywordStr,
+	//				//"Frequency.keyword": "月度",
+	//			},
+	//		},
+	//	},
+	//}
+
+	// 默认使用中文名字字段去匹配
+	keywordNameKey := `EdbName`
+	// 如果没有中文,则使用英文名称字段去匹配
+	if !utils.ContainsChinese(keywordStr) {
+		keywordNameKey = `EdbNameEn`
+	}
 	shouldMap := map[string]interface{}{
 		"should": []interface{}{
 			map[string]interface{}{
@@ -343,21 +372,16 @@ func SearchEdbInfoData(indexName, keywordStr string, from, size, filterSource, s
 			},
 			map[string]interface{}{
 				"match": map[string]interface{}{
-					"EdbName": keywordStr,
-					//"Frequency.keyword": "月度",
-				},
-			},
-			map[string]interface{}{
-				"match": map[string]interface{}{
-					"EdbNameEn": keywordStr,
+					keywordNameKey: keywordStr,
 					//"Frequency.keyword": "月度",
 				},
 			},
 		},
 	}
-	mustMap = append(mustMap, map[string]interface{}{
-		"bool": shouldMap,
-	})
+
+	//mustMap = append(mustMap, map[string]interface{}{
+	//	"bool": shouldMap,
+	//})
 
 	return searchEdbInfoData(indexName, mustMap, mustNotMap, shouldMap, from, size)
 }
@@ -697,6 +721,35 @@ func SearchAddPredictEdbInfoData(indexName, keywordStr string, noPermissionEdbIn
 	})
 
 	//关键字匹配
+	//shouldMap := map[string]interface{}{
+	//	"should": []interface{}{
+	//		map[string]interface{}{
+	//			"match": map[string]interface{}{
+	//				"EdbCode": keywordStr,
+	//				//"Frequency.keyword": "月度",
+	//			},
+	//		},
+	//		map[string]interface{}{
+	//			"match": map[string]interface{}{
+	//				"EdbName": keywordStr,
+	//				//"Frequency.keyword": "月度",
+	//			},
+	//		},
+	//		map[string]interface{}{
+	//			"match": map[string]interface{}{
+	//				"EdbNameEn": keywordStr,
+	//				//"Frequency.keyword": "月度",
+	//			},
+	//		},
+	//	},
+	//}
+
+	// 默认使用中文名字字段去匹配
+	keywordNameKey := `EdbName`
+	// 如果没有中文,则使用英文名称字段去匹配
+	if !utils.ContainsChinese(keywordStr) {
+		keywordNameKey = `EdbNameEn`
+	}
 	shouldMap := map[string]interface{}{
 		"should": []interface{}{
 			map[string]interface{}{
@@ -707,7 +760,7 @@ func SearchAddPredictEdbInfoData(indexName, keywordStr string, noPermissionEdbIn
 			},
 			map[string]interface{}{
 				"match": map[string]interface{}{
-					"EdbName": keywordStr,
+					keywordNameKey: keywordStr,
 					//"Frequency.keyword": "月度",
 				},
 			},
@@ -1211,34 +1264,61 @@ func SearchChartInfoData(indexName, keywordStr string, showSysId int, sourceList
 	})
 
 	//关键字匹配
+	//shouldMap := map[string]interface{}{
+	//	"should": []interface{}{
+	//		map[string]interface{}{
+	//			"match": map[string]interface{}{
+	//				"ChartName": keywordStr,
+	//				//"Frequency.keyword": "月度",
+	//			},
+	//		},
+	//		// 因为关键词被分了,所以需要用下面的语句来让他 整个词 查询,从而加重整词的权重
+	//		map[string]interface{}{
+	//			"match": map[string]interface{}{
+	//				"ChartName": map[string]interface{}{
+	//					"query":    keywordStr,
+	//					"operator": "and",
+	//				},
+	//				//"Frequency.keyword": "月度",
+	//			},
+	//		},
+	//		map[string]interface{}{
+	//			"match": map[string]interface{}{
+	//				"ChartNameEn": keywordStr,
+	//				//"Frequency.keyword": "月度",
+	//			},
+	//		},
+	//		// 因为关键词被分了,所以需要用下面的语句来让他 整个词 查询,从而加重整词的权重
+	//		map[string]interface{}{
+	//			"match": map[string]interface{}{
+	//				"ChartNameEn": map[string]interface{}{
+	//					"query":    keywordStr,
+	//					"operator": "and",
+	//				},
+	//				//"Frequency.keyword": "月度",
+	//			},
+	//		},
+	//	},
+	//}
+
+	// 默认使用中文名字字段去匹配
+	keywordNameKey := `ChartName`
+	// 如果没有中文,则使用英文名称字段去匹配
+	if !utils.ContainsChinese(keywordStr) {
+		keywordNameKey = `ChartNameEn`
+	}
 	shouldMap := map[string]interface{}{
 		"should": []interface{}{
 			map[string]interface{}{
 				"match": map[string]interface{}{
-					"ChartName": keywordStr,
-					//"Frequency.keyword": "月度",
-				},
-			},
-			// 因为关键词被分了,所以需要用下面的语句来让他 整个词 查询,从而加重整词的权重
-			map[string]interface{}{
-				"match": map[string]interface{}{
-					"ChartName": map[string]interface{}{
-						"query":    keywordStr,
-						"operator": "and",
-					},
-					//"Frequency.keyword": "月度",
-				},
-			},
-			map[string]interface{}{
-				"match": map[string]interface{}{
-					"ChartNameEn": keywordStr,
+					keywordNameKey: keywordStr,
 					//"Frequency.keyword": "月度",
 				},
 			},
 			// 因为关键词被分了,所以需要用下面的语句来让他 整个词 查询,从而加重整词的权重
 			map[string]interface{}{
 				"match": map[string]interface{}{
-					"ChartNameEn": map[string]interface{}{
+					keywordNameKey: map[string]interface{}{
 						"query":    keywordStr,
 						"operator": "and",
 					},
@@ -1247,6 +1327,7 @@ func SearchChartInfoData(indexName, keywordStr string, showSysId int, sourceList
 			},
 		},
 	}
+
 	mustMap = append(mustMap, map[string]interface{}{
 		"bool": shouldMap,
 	})
@@ -1394,18 +1475,62 @@ func SearchMyChartInfoData(indexName, keywordStr string, adminId int, noPermissi
 	}
 
 	//关键字匹配
+
+	//shouldMap := map[string]interface{}{
+	//	"should": []interface{}{
+	//		map[string]interface{}{
+	//			"match": map[string]interface{}{
+	//				"ChartName": keywordStr,
+	//				//"Frequency.keyword": "月度",
+	//			},
+	//		},
+	//		// 因为关键词被分了,所以需要用下面的语句来让他 整个词 查询,从而加重整词的权重
+	//		map[string]interface{}{
+	//			"match": map[string]interface{}{
+	//				"ChartName": map[string]interface{}{
+	//					"query":    keywordStr,
+	//					"operator": "and",
+	//				},
+	//				//"Frequency.keyword": "月度",
+	//			},
+	//		},
+	//		map[string]interface{}{
+	//			"match": map[string]interface{}{
+	//				"ChartNameEn": keywordStr,
+	//				//"Frequency.keyword": "月度",
+	//			},
+	//		},
+	//		// 因为关键词被分了,所以需要用下面的语句来让他 整个词 查询,从而加重整词的权重
+	//		map[string]interface{}{
+	//			"match": map[string]interface{}{
+	//				"ChartNameEn": map[string]interface{}{
+	//					"query":    keywordStr,
+	//					"operator": "and",
+	//				},
+	//				//"Frequency.keyword": "月度",
+	//			},
+	//		},
+	//	},
+	//}
+
+	// 默认使用中文名字字段去匹配
+	keywordNameKey := `ChartName`
+	// 如果没有中文,则使用英文名称字段去匹配
+	if !utils.ContainsChinese(keywordStr) {
+		keywordNameKey = `ChartNameEn`
+	}
 	shouldMap := map[string]interface{}{
 		"should": []interface{}{
 			map[string]interface{}{
 				"match": map[string]interface{}{
-					"ChartName": keywordStr,
+					keywordNameKey: keywordStr,
 					//"Frequency.keyword": "月度",
 				},
 			},
 			// 因为关键词被分了,所以需要用下面的语句来让他 整个词 查询,从而加重整词的权重
 			map[string]interface{}{
 				"match": map[string]interface{}{
-					"ChartName": map[string]interface{}{
+					keywordNameKey: map[string]interface{}{
 						"query":    keywordStr,
 						"operator": "and",
 					},
@@ -1414,6 +1539,7 @@ func SearchMyChartInfoData(indexName, keywordStr string, adminId int, noPermissi
 			},
 		},
 	}
+
 	mustMap = append(mustMap, map[string]interface{}{
 		"bool": shouldMap,
 	})
@@ -1624,6 +1750,14 @@ func SearchEdbInfoDataByAdminId(indexName, keywordStr string, from, size, filter
 				},
 			},
 		}
+	case 6:
+		mustNotMap = []interface{}{
+			map[string]interface{}{
+				"match": map[string]interface{}{
+					"Frequency.keyword": "年度",
+				},
+			},
+		}
 	}
 
 	//指标来源
@@ -1661,6 +1795,29 @@ func SearchEdbInfoDataByAdminId(indexName, keywordStr string, from, size, filter
 	//})
 
 	//关键字匹配
+	//shouldMap := map[string]interface{}{
+	//	"should": []interface{}{
+	//		map[string]interface{}{
+	//			"match": map[string]interface{}{
+	//				"EdbCode": keywordStr,
+	//				//"Frequency.keyword": "月度",
+	//			},
+	//		},
+	//		map[string]interface{}{
+	//			"match": map[string]interface{}{
+	//				"EdbName": keywordStr,
+	//				//"Frequency.keyword": "月度",
+	//			},
+	//		},
+	//	},
+	//}
+
+	// 默认使用中文名字字段去匹配
+	keywordNameKey := `EdbName`
+	// 如果没有中文,则使用英文名称字段去匹配
+	if !utils.ContainsChinese(keywordStr) {
+		keywordNameKey = `EdbNameEn`
+	}
 	shouldMap := map[string]interface{}{
 		"should": []interface{}{
 			map[string]interface{}{
@@ -1671,12 +1828,13 @@ func SearchEdbInfoDataByAdminId(indexName, keywordStr string, from, size, filter
 			},
 			map[string]interface{}{
 				"match": map[string]interface{}{
-					"EdbName": keywordStr,
+					keywordNameKey: keywordStr,
 					//"Frequency.keyword": "月度",
 				},
 			},
 		},
 	}
+
 	mustMap = append(mustMap, map[string]interface{}{
 		"bool": shouldMap,
 	})