瀏覽代碼

Merge branch 'feature/eta1.9.5_feature_good' into debug

# Conflicts:
#	services/data/future_good/profit_chart_info.go
xyxie 9 月之前
父節點
當前提交
9ecaeacc97

+ 1 - 0
controllers/data_manage/future_good/future_good_chart_info.go

@@ -1682,6 +1682,7 @@ func GetChartInfoDetailFromUniqueCode(chartInfo *data_manage.ChartInfoView, isCa
 		// 默认取第一个现货指标
 		baseEdbInfoId = edbInfoMappingList[0].EdbInfoId
 		baseEdbInfoMapping = edbInfoMappingList[0]
+		barConfig.BaseEdbInfoId = baseEdbInfoId
 	} else {
 		baseEdbInfoMapping, err = data_manage.GetChartEdbMappingByEdbInfoId(baseEdbInfoId)
 		if err != nil {

+ 55 - 34
services/data/future_good/profit_chart_info.go

@@ -177,22 +177,23 @@ func GetProfitChartEdbData(baseEdbInfo *data_manage.EdbInfo, edbInfoList []*data
 	sort.Slice(dateList, func(i, j int) bool {
 		return dateList[i] < dateList[j]
 	})
-
-	_, yDataList, err = ProfitChartChartData(baseEdbInfo, baseDataListMap, futureGoodEdbInfoDateMap, futureGoodDataListMap, chartInfoDateList, baseEdbInfo.EndDate, specialFutureGoodEdbInfoMap, formulaStr, tagEdbIdMap, dateList, maxN)
+	for _, v := range edbInfoList {
+		tmp := data_manage.XData{
+			Name:   v.EdbName,
+			NameEn: v.EdbNameEn,
+		}
+		xDataList = append(xDataList, tmp)
+	}
+	var edbIdList []int
+	edbIdList, yDataList, err = ProfitChartChartData(baseEdbInfo, baseDataListMap, futureGoodEdbInfoDateMap, futureGoodDataListMap, chartInfoDateList, baseEdbInfo.EndDate, specialFutureGoodEdbInfoMap, formulaStr, tagEdbIdMap, dateList, maxN)
 
 	// todo 最后处理数据
-	tmpXDataList, newYDataList, err := handleProfitResultData(baseEdbInfo, yDataList, earliestDateTime)
+	tmpXDataList, newYDataList, err := handleProfitResultData(xDataList, baseEdbInfo, yDataList, earliestDateTime, edbIdList)
 	if err != nil {
 		return
 	}
 	if len(reqXDataList) == 0 {
-		xDataList = []data_manage.XData{
-			{
-				Name:   "现货利润",
-				NameEn: "Spot Price",
-			},
-		}
-		xDataList = append(xDataList, tmpXDataList...)
+		xDataList = tmpXDataList
 	} else {
 		xDataList = reqXDataList
 	}
@@ -267,28 +268,44 @@ func ProfitChartChartData(baseEdbInfo *data_manage.EdbInfo, baseDataListMap map[
 		// 现货指标
 		index := 0
 		var realDateTime time.Time
+		// 现货指标
+		baseEdbDateData, ok := allBaseEdbDateDataMap[baseEdbInfo.EdbInfoId]
+		if !ok {
+			err = fmt.Errorf("指标id: %d 没有数据", baseEdbInfo.EdbInfoId)
+			return
+		}
+		realDateTime, findDataValue, isFind, tmpErr := GetNeedDateData(findDateTime, baseDataListMap[baseEdbInfo.EdbInfoId], baseEdbDateData)
+		if tmpErr != nil {
+			err = tmpErr
+			return
+		}
+		if isFind {
+			maxDate = realDateTime
+		}
+		edbIdList = make([]int, 0) //普通指标ID
 		for edbInfoId, baseDataList := range baseDataListMap {
-			baseEdbDateData, ok := allBaseEdbDateDataMap[edbInfoId]
+			if edbInfoId == baseEdbInfo.EdbInfoId {
+				findDataList = append(findDataList, findDataValue)
+				yDataMap[0] = findDataValue
+				xEdbInfoIdList = append(xEdbInfoIdList, edbInfoId)
+				edbIdList = append(edbIdList, edbInfoId)
+				index += 1
+				continue
+			}
+			baseEdbDateDataTmp, ok := allBaseEdbDateDataMap[edbInfoId]
 			if !ok {
 				err = fmt.Errorf("指标id: %d 没有数据", edbInfoId)
 				return
 			}
-			realDateTimeTmp, findDataValue, isFind, tmpErr := GetNeedDateData(findDateTime, baseDataList, baseEdbDateData)
-			if tmpErr != nil {
-				err = tmpErr
+			_, findDataValueTmp, _, e := GetNeedDateData(realDateTime, baseDataList, baseEdbDateDataTmp)
+			if e != nil {
+				err = e
 				return
 			}
-			findDataList = append(findDataList, findDataValue)
-			yDataMap[index] = findDataValue
-			if edbInfoId == baseEdbInfo.EdbInfoId {
-				realDateTime = realDateTimeTmp
-			}
-			if isFind {
-				if edbInfoId == baseEdbInfo.EdbInfoId {
-					maxDate = realDateTimeTmp
-				}
-			}
+			findDataList = append(findDataList, findDataValueTmp)
+			yDataMap[index] = findDataValueTmp
 			xEdbInfoIdList = append(xEdbInfoIdList, edbInfoId)
+			edbIdList = append(edbIdList, edbInfoId)
 			index += 1
 		}
 
@@ -506,29 +523,33 @@ func getProfitFutureGoodEdbInfoList(earliestDateTime time.Time, zlFutureGoodEdbI
 }
 
 // handleProfitResultData 处理成最终的结果数据
-func handleProfitResultData(baseEdbInfo *data_manage.EdbInfo, yDataList []data_manage.YData, earliestDateTime time.Time) (xDataList []data_manage.XData, newYDataList []data_manage.YData, err error) {
-	xDataList = make([]data_manage.XData, 0)
+func handleProfitResultData(xDataListInit []data_manage.XData, baseEdbInfo *data_manage.EdbInfo, yDataList []data_manage.YData, earliestDateTime time.Time, allEdbInfoIds []int) (xDataList []data_manage.XData, newYDataList []data_manage.YData, err error) {
 	newYDataList = yDataList
+	xDataList = xDataListInit
 
 	nMap := make(map[int]int)
-
+	nList := make([]int, 0)
 	for _, v := range yDataList {
 		for _, n := range v.XEdbInfoIdList {
-			nMap[n] = n
+			if utils.InArrayByInt(allEdbInfoIds, n) {
+				nList = append(nList, n)
+			} else {
+				nMap[n] = n
+			}
 		}
 	}
 
 	// 找出所有的N值,并进行正序排列
-	nList := make([]int, 0)
+	nListTmp := make([]int, 0)
 	for _, n := range nMap {
-		nList = append(nList, n)
+		nListTmp = append(nListTmp, n)
 	}
-	sort.Slice(nList, func(i, j int) bool {
-		return nList[i] < nList[j]
+	sort.Slice(nListTmp, func(i, j int) bool {
+		return nListTmp[i] < nListTmp[j]
 	})
-
+	nList = append(nList, nListTmp...)
 	for _, n := range nList {
-		if n == 0 {
+		if utils.InArrayByInt(allEdbInfoIds, n) {
 			continue
 		}
 		xDataList = append(xDataList, data_manage.XData{