|
@@ -18,7 +18,7 @@ import (
|
|
|
)
|
|
|
|
|
|
// GetChartEdbData 获取图表的指标数据
|
|
|
-func GetChartEdbData(chartInfoId int, startDate, endDate string, edbInfoMapping, futureGoodEdbInfoMapping *chartEdbMappingModel.ChartEdbInfoMappingList, barChartInfoDateList []request.BarChartInfoDateReq, barChartInfoSort request.BarChartInfoSortReq) (barConfigEdbInfoIdList []request.BarChartInfoEdbItemReq, edbList []*chartEdbMappingModel.ChartEdbInfoMappingList, xEdbIdValue []int, xDataList []chart_info.XData, yDataList []chart_info.YData, sourceArr []string, err error) {
|
|
|
+func GetChartEdbData(chartInfoId int, startDate, endDate string, edbInfoMapping, futureGoodEdbInfoMapping *chartEdbMappingModel.ChartEdbInfoMappingList, barChartInfoDateList []request.BarChartInfoDateReq) (barConfigEdbInfoIdList []request.BarChartInfoEdbItemReq, edbList []*chartEdbMappingModel.ChartEdbInfoMappingList, xEdbIdValue []int, xDataList []chart_info.XData, yDataList []chart_info.YData, sourceArr []string, err error) {
|
|
|
edbList = make([]*chartEdbMappingModel.ChartEdbInfoMappingList, 0)
|
|
|
|
|
|
sourceArr = make([]string, 0)
|
|
@@ -95,12 +95,78 @@ func GetChartEdbData(chartInfoId int, startDate, endDate string, edbInfoMapping,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // 获取主力合约和最新日期
|
|
|
+ var zlFutureGoodEdbInfo *future_good_edb_info.FutureGoodEdbInfo
|
|
|
+ var latestDate string // 最新日期是这个
|
|
|
+ var regionType string // 交易所来源:“国内”,“海外”
|
|
|
+ {
|
|
|
+ // 寻找主力合约
|
|
|
+ zlFutureGoodEdbInfo, err = future_good_edb_info.GetFutureGoodEdbInfo(futureGoodEdbInfoMapping.EdbInfoId)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ regionType = zlFutureGoodEdbInfo.RegionType
|
|
|
+
|
|
|
+ // 如果当前合约配置的 "画图时,日期来源的指标id" 并不是自己的话,那么就去查找对应配置的合约
|
|
|
+ if uint64(zlFutureGoodEdbInfo.DateSourceID) != zlFutureGoodEdbInfo.FutureGoodEdbInfoID {
|
|
|
+ sourceDateFutureGoodEdbInfo, tmpErr := future_good_edb_info.GetFutureGoodEdbInfo(int(zlFutureGoodEdbInfo.DateSourceID))
|
|
|
+ if tmpErr != nil {
|
|
|
+ err = tmpErr
|
|
|
+ return
|
|
|
+ }
|
|
|
+ latestDate = sourceDateFutureGoodEdbInfo.EndDate.Format(utils.FormatDate) // 最新日期是这个
|
|
|
+ } else {
|
|
|
+ latestDate = zlFutureGoodEdbInfo.EndDate.Format(utils.FormatDate) // 最新日期是这个
|
|
|
+ }
|
|
|
+ if latestDate == `0000-00-00` {
|
|
|
+ err = errors.New("日期异常")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// 获取期货指标以及期货数据
|
|
|
- futureGoodEdbInfoList, err := future_good_edb_info.GetFutureGoodEdbInfoListByParentId(futureGoodEdbInfoMapping.EdbInfoId)
|
|
|
+ tmpFutureGoodEdbInfoList, err := future_good_edb_info.GetFutureGoodEdbInfoListByParentId(futureGoodEdbInfoMapping.EdbInfoId)
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+ maxM := 36
|
|
|
+ futureGoodEdbInfoList := make([]*future_good_edb_info.FutureGoodEdbInfo, 0)
|
|
|
+ latestDateTime, _ := time.ParseInLocation(utils.FormatDate, latestDate, time.Local)
|
|
|
+
|
|
|
+ for _, v := range tmpFutureGoodEdbInfoList {
|
|
|
+ if v.RegionType == `国内` {
|
|
|
+ futureGoodEdbInfoList = append(futureGoodEdbInfoList, v)
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ //海外的连续日期,目前
|
|
|
+ if v.FutureGoodEdbType == 2 {
|
|
|
+ if int(v.Month) <= maxM {
|
|
|
+ addMonth := int(latestDateTime.Month()) + int(v.Month)
|
|
|
+ v.Year = latestDateTime.Year() + addMonth/12
|
|
|
+ realMonth := addMonth % 12
|
|
|
+ if realMonth == 0 {
|
|
|
+ realMonth = 12
|
|
|
+ }
|
|
|
+ v.Month = uint32(realMonth)
|
|
|
+ futureGoodEdbInfoList = append(futureGoodEdbInfoList, v)
|
|
|
+ }
|
|
|
+ continue
|
|
|
+ }
|
|
|
+
|
|
|
+ // 小于等于当前年,那么就肯定是ok的
|
|
|
+ if v.Year <= latestDateTime.Year() {
|
|
|
+ futureGoodEdbInfoList = append(futureGoodEdbInfoList, v)
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ // 如果(当前年-最新日期的年份) * 12个月 + (当前月-最新日期的月份) 小于总月份
|
|
|
+ if (v.Year-latestDateTime.Year())*12+(int(v.Month)-int(latestDateTime.Month())) <= maxM {
|
|
|
+ futureGoodEdbInfoList = append(futureGoodEdbInfoList, v)
|
|
|
+ continue
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
futureGoodMappingList := make([]*chartEdbMappingModel.ChartEdbInfoMappingList, 0)
|
|
|
for k, v := range futureGoodEdbInfoList {
|
|
|
newMappingInfo := &chartEdbMappingModel.ChartEdbInfoMappingList{
|
|
@@ -177,7 +243,8 @@ func GetChartEdbData(chartInfoId int, startDate, endDate string, edbInfoMapping,
|
|
|
}
|
|
|
|
|
|
edbList = append(edbList, futureGoodMappingList...)
|
|
|
- xEdbIdValue, yDataList, err = BarChartData(edbList[0], futureGoodMappingList, edbDataListMap, barChartInfoDateList, barChartInfoSort)
|
|
|
+
|
|
|
+ xEdbIdValue, yDataList, err = BarChartData(edbList[0], futureGoodEdbInfoList, edbDataListMap, barChartInfoDateList, regionType, latestDate)
|
|
|
|
|
|
xDataList = []chart_info.XData{
|
|
|
{
|
|
@@ -185,19 +252,28 @@ func GetChartEdbData(chartInfoId int, startDate, endDate string, edbInfoMapping,
|
|
|
NameEn: "Spot Price",
|
|
|
},
|
|
|
}
|
|
|
-
|
|
|
- for i := 1; i <= 11; i++ {
|
|
|
- xDataList = append(xDataList, chart_info.XData{
|
|
|
- Name: fmt.Sprint("M+", i),
|
|
|
- NameEn: fmt.Sprint("M+", i),
|
|
|
- })
|
|
|
+ if regionType == `国内` {
|
|
|
+ for i := range futureGoodEdbInfoList {
|
|
|
+ xDataList = append(xDataList, chart_info.XData{
|
|
|
+ Name: fmt.Sprint("M+", i),
|
|
|
+ NameEn: fmt.Sprint("M+ ", i),
|
|
|
+ })
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ for _, v := range futureGoodEdbInfoList {
|
|
|
+ divMonth := (v.Year-latestDateTime.Year())*12 + (int(v.Month) - int(latestDateTime.Month()))
|
|
|
+ xDataList = append(xDataList, chart_info.XData{
|
|
|
+ Name: fmt.Sprint("M+", divMonth),
|
|
|
+ NameEn: fmt.Sprint("M+ ", divMonth),
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// BarChartData 柱方图的数据处理
|
|
|
-func BarChartData(edbInfoMapping *chartEdbMappingModel.ChartEdbInfoMappingList, futureGoodMappingList []*chartEdbMappingModel.ChartEdbInfoMappingList, edbDataListMap map[int][]*edbDataModel.EdbDataList, barChartInfoDateList []request.BarChartInfoDateReq, barChartInfoSort request.BarChartInfoSortReq) (edbIdList []int, yDataList []chart_info.YData, err error) {
|
|
|
+// BarChartData 商品价格曲线的数据处理
|
|
|
+func BarChartData(edbInfoMapping *chartEdbMappingModel.ChartEdbInfoMappingList, futureGoodMappingList []*future_good_edb_info.FutureGoodEdbInfo, edbDataListMap map[int][]*edbDataModel.EdbDataList, barChartInfoDateList []request.BarChartInfoDateReq, regionType, latestDate string) (edbIdList []int, yDataList []chart_info.YData, err error) {
|
|
|
// 指标数据数组(10086:{"2022-12-02":100.01,"2022-12-01":102.3})
|
|
|
edbDataMap := make(map[int]map[string]float64)
|
|
|
for edbInfoId, edbDataList := range edbDataListMap {
|
|
@@ -211,23 +287,11 @@ func BarChartData(edbInfoMapping *chartEdbMappingModel.ChartEdbInfoMappingList,
|
|
|
// edbIdList 指标展示顺序;x轴的指标顺序
|
|
|
edbIdList = make([]int, 0)
|
|
|
edbIdList = append(edbIdList, edbInfoMapping.EdbInfoId)
|
|
|
- if barChartInfoSort.Sort == 0 {
|
|
|
- for _, v := range futureGoodMappingList {
|
|
|
- edbIdList = append(edbIdList, v.EdbInfoId)
|
|
|
- }
|
|
|
+ for _, v := range futureGoodMappingList {
|
|
|
+ edbIdList = append(edbIdList, int(v.FutureGoodEdbInfoID))
|
|
|
}
|
|
|
|
|
|
- //固定取螺纹期货主力合约的时间序列,最新值为该合约最新日期、N天前为该合约最新日期N天前
|
|
|
- rbzlInfo, err := future_good_edb_info.GetFutureGoodEdbInfoByCode("RBZL.SHF")
|
|
|
- if err != nil {
|
|
|
- return
|
|
|
- }
|
|
|
- // 最新日期是这个
|
|
|
- if rbzlInfo.EndDate.IsZero() {
|
|
|
- err = errors.New("日期异常")
|
|
|
- return
|
|
|
- }
|
|
|
- latestDateTime := rbzlInfo.EndDate
|
|
|
+ latestDateTime, _ := time.ParseInLocation(utils.FormatDate, latestDate, time.Local)
|
|
|
|
|
|
yDataList = make([]chart_info.YData, 0) //y轴的数据列表
|
|
|
|
|
@@ -276,33 +340,28 @@ func BarChartData(edbInfoMapping *chartEdbMappingModel.ChartEdbInfoMappingList,
|
|
|
noDataIdMap[edbInfoMapping.EdbInfoId] = edbInfoMapping.EdbInfoId
|
|
|
}
|
|
|
currMonth := findDateTime.Month() // 当前月份
|
|
|
+ currYear := findDateTime.Year() // 当前年份
|
|
|
xEdbInfoIdList = append(xEdbInfoIdList, edbInfoMapping.EdbInfoId)
|
|
|
|
|
|
- // 当前月的后面月份合约的数据
|
|
|
- for i := currMonth; i < 12; i++ {
|
|
|
- futureGoodMapping := futureGoodMappingList[i] // 当前的期货指标
|
|
|
- tmpRealDateTime, tmpFindDataValue, tmpIsFind, tmpErr := GetNeedDateData(findDateTime, edbDataListMap[futureGoodMapping.EdbInfoId], edbDataMap[futureGoodMapping.EdbInfoId])
|
|
|
- if tmpErr != nil {
|
|
|
- err = tmpErr
|
|
|
- return
|
|
|
+ indexList := make([]int, 0)
|
|
|
+ if regionType == `国内` {
|
|
|
+ for i := currMonth; i < 12; i++ {
|
|
|
+ indexList = append(indexList, int(i))
|
|
|
}
|
|
|
- findDataList = append(findDataList, tmpFindDataValue)
|
|
|
- if tmpIsFind {
|
|
|
- if maxDate.IsZero() || maxDate.Before(tmpRealDateTime) {
|
|
|
- maxDate = tmpRealDateTime
|
|
|
+ for i := 1; i < int(currMonth); i++ {
|
|
|
+ indexList = append(indexList, i)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ for i, v := range futureGoodMappingList {
|
|
|
+ if v.Year > currYear || (v.Year == currYear && int(v.Month) >= int(currMonth)) {
|
|
|
+ indexList = append(indexList, i)
|
|
|
}
|
|
|
- } else {
|
|
|
- noDataIdList = append(noDataIdList, futureGoodMapping.EdbInfoId)
|
|
|
- noDataIdMap[futureGoodMapping.EdbInfoId] = futureGoodMapping.EdbInfoId
|
|
|
}
|
|
|
- // 当前期货合约的指标
|
|
|
- xEdbInfoIdList = append(xEdbInfoIdList, futureGoodMapping.EdbInfoId)
|
|
|
}
|
|
|
|
|
|
- // 当前月的前面月份合约的数据
|
|
|
- for i := 1; i < int(currMonth); i++ {
|
|
|
- futureGoodMapping := futureGoodMappingList[i-1] // 当前的期货指标
|
|
|
- tmpRealDateTime, tmpFindDataValue, tmpIsFind, tmpErr := GetNeedDateData(findDateTime, edbDataListMap[futureGoodMapping.EdbInfoId], edbDataMap[futureGoodMapping.EdbInfoId])
|
|
|
+ for _, i := range indexList {
|
|
|
+ futureGoodMapping := futureGoodMappingList[i] // 当前的期货指标
|
|
|
+ tmpRealDateTime, tmpFindDataValue, tmpIsFind, tmpErr := GetNeedDateData(findDateTime, edbDataListMap[int(futureGoodMapping.FutureGoodEdbInfoID)], edbDataMap[int(futureGoodMapping.FutureGoodEdbInfoID)])
|
|
|
if tmpErr != nil {
|
|
|
err = tmpErr
|
|
|
return
|
|
@@ -313,11 +372,11 @@ func BarChartData(edbInfoMapping *chartEdbMappingModel.ChartEdbInfoMappingList,
|
|
|
maxDate = tmpRealDateTime
|
|
|
}
|
|
|
} else {
|
|
|
- noDataIdList = append(noDataIdList, futureGoodMapping.EdbInfoId)
|
|
|
- noDataIdMap[futureGoodMapping.EdbInfoId] = futureGoodMapping.EdbInfoId
|
|
|
+ noDataIdList = append(noDataIdList, int(futureGoodMapping.FutureGoodEdbInfoID))
|
|
|
+ noDataIdMap[int(futureGoodMapping.FutureGoodEdbInfoID)] = int(futureGoodMapping.FutureGoodEdbInfoID)
|
|
|
}
|
|
|
// 当前期货合约的指标
|
|
|
- xEdbInfoIdList = append(xEdbInfoIdList, futureGoodMapping.EdbInfoId)
|
|
|
+ xEdbInfoIdList = append(xEdbInfoIdList, int(futureGoodMapping.FutureGoodEdbInfoID))
|
|
|
}
|
|
|
|
|
|
yName := barChartInfoDate.Name
|