|
@@ -10,13 +10,12 @@ import (
|
|
|
"hongze/hongze_chart_lib/services/alarm_msg"
|
|
|
"hongze/hongze_chart_lib/services/data"
|
|
|
"hongze/hongze_chart_lib/utils"
|
|
|
- "sort"
|
|
|
"strconv"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
// GetChartEdbData 获取图表的指标数据
|
|
|
-func GetChartEdbData(chartInfoId int, startDate, endDate string, edbInfoMapping, futureGoodEdbInfoMapping *models.ChartEdbInfoMapping, barChartInfoDateList []data_manage.BarChartInfoDateReq, barChartInfoSort data_manage.BarChartInfoSortReq) (barConfigEdbInfoIdList []data_manage.BarChartInfoEdbItemReq, edbList []*models.ChartEdbInfoMapping, xEdbIdValue []int, yDataList []models.YData, err error) {
|
|
|
+func GetChartEdbData(chartInfoId int, startDate, endDate string, edbInfoMapping, futureGoodEdbInfoMapping *models.ChartEdbInfoMapping, barChartInfoDateList []data_manage.BarChartInfoDateReq, barChartInfoSort data_manage.BarChartInfoSortReq) (barConfigEdbInfoIdList []data_manage.BarChartInfoEdbItemReq, edbList []*models.ChartEdbInfoMapping, xEdbIdValue []int, xDataList []models.XData, yDataList []models.YData, err error) {
|
|
|
edbList = make([]*models.ChartEdbInfoMapping, 0)
|
|
|
|
|
|
if futureGoodEdbInfoMapping == nil {
|
|
@@ -86,7 +85,6 @@ func GetChartEdbData(chartInfoId int, startDate, endDate string, edbInfoMapping,
|
|
|
})
|
|
|
}
|
|
|
|
|
|
- nowMonth := time.Now().Month()
|
|
|
// 获取期货指标以及期货数据
|
|
|
futureGoodEdbInfoList, err := efuture_good.GetFutureGoodEdbInfoListByParentId(futureGoodEdbInfoMapping.EdbInfoId)
|
|
|
if err != nil {
|
|
@@ -94,18 +92,7 @@ func GetChartEdbData(chartInfoId int, startDate, endDate string, edbInfoMapping,
|
|
|
}
|
|
|
|
|
|
futureGoodMappingList := make([]*models.ChartEdbInfoMapping, 0)
|
|
|
- //当前月份之后的月
|
|
|
- nextFutureGoodEdbInfoList := make([]*efuture_good.FutureGoodEdbInfo, 0)
|
|
|
for k, v := range futureGoodEdbInfoList {
|
|
|
- // 过滤当前月
|
|
|
- if v.Month == int(nowMonth) {
|
|
|
- continue
|
|
|
- }
|
|
|
-
|
|
|
- if v.Month < int(nowMonth) {
|
|
|
- nextFutureGoodEdbInfoList = append(nextFutureGoodEdbInfoList, v)
|
|
|
- continue
|
|
|
- }
|
|
|
newMappingInfo := &models.ChartEdbInfoMapping{
|
|
|
EdbInfoId: v.FutureGoodEdbInfoId,
|
|
|
SourceName: v.Exchange,
|
|
@@ -156,57 +143,6 @@ func GetChartEdbData(chartInfoId int, startDate, endDate string, edbInfoMapping,
|
|
|
})
|
|
|
}
|
|
|
|
|
|
- //当前月份之前的月
|
|
|
- for k, v := range nextFutureGoodEdbInfoList {
|
|
|
- newMappingInfo := &models.ChartEdbInfoMapping{
|
|
|
- EdbInfoId: v.FutureGoodEdbInfoId,
|
|
|
- SourceName: v.Exchange,
|
|
|
- Source: utils.CHART_SOURCE_FUTURE_GOOD,
|
|
|
- EdbCode: v.FutureGoodEdbCode,
|
|
|
- EdbName: v.FutureGoodEdbName,
|
|
|
- EdbAliasName: v.FutureGoodEdbName,
|
|
|
- EdbNameEn: v.FutureGoodEdbNameEn,
|
|
|
- EdbType: edbInfoMapping.EdbType,
|
|
|
- Frequency: edbInfoMapping.Frequency,
|
|
|
- FrequencyEn: edbInfoMapping.FrequencyEn,
|
|
|
- Unit: edbInfoMapping.Unit,
|
|
|
- UnitEn: edbInfoMapping.UnitEn,
|
|
|
- StartDate: v.StartDate,
|
|
|
- EndDate: v.EndDate,
|
|
|
- ModifyTime: v.ModifyTime.Format(utils.FormatDateTime),
|
|
|
- ChartEdbMappingId: v.FutureGoodEdbInfoId,
|
|
|
- ChartInfoId: edbInfoMapping.ChartInfoId,
|
|
|
- MaxData: v.MaxValue,
|
|
|
- MinData: v.MinValue,
|
|
|
- IsOrder: edbInfoMapping.IsOrder,
|
|
|
- IsAxis: edbInfoMapping.IsAxis,
|
|
|
- EdbInfoType: edbInfoMapping.EdbInfoType,
|
|
|
- EdbInfoCategoryType: edbInfoMapping.EdbInfoCategoryType,
|
|
|
- LeadValue: edbInfoMapping.LeadValue,
|
|
|
- LeadUnit: edbInfoMapping.LeadUnit,
|
|
|
- LeadUnitEn: edbInfoMapping.LeadUnitEn,
|
|
|
- ChartStyle: edbInfoMapping.ChartStyle,
|
|
|
- ChartColor: edbInfoMapping.ChartColor,
|
|
|
- PredictChartColor: edbInfoMapping.PredictChartColor,
|
|
|
- ChartWidth: edbInfoMapping.ChartWidth,
|
|
|
- ChartType: edbInfoMapping.ChartType,
|
|
|
- LatestDate: v.LatestDate.Format(utils.FormatDateTime),
|
|
|
- LatestValue: v.LatestValue,
|
|
|
- UniqueCode: futureGoodEdbInfoMapping.UniqueCode + "1" + strconv.Itoa(k),
|
|
|
- MinValue: v.MinValue,
|
|
|
- MaxValue: v.MaxValue,
|
|
|
- DataList: nil,
|
|
|
- IsNullData: false,
|
|
|
- }
|
|
|
- futureGoodMappingList = append(futureGoodMappingList, newMappingInfo)
|
|
|
-
|
|
|
- barConfigEdbInfoIdList = append(barConfigEdbInfoIdList, data_manage.BarChartInfoEdbItemReq{
|
|
|
- EdbInfoId: newMappingInfo.EdbInfoId,
|
|
|
- Name: fmt.Sprint("M+", v.Month),
|
|
|
- NameEn: fmt.Sprint("M+", v.Month),
|
|
|
- Source: newMappingInfo.Source,
|
|
|
- })
|
|
|
- }
|
|
|
// 获取数据
|
|
|
for _, v := range futureGoodMappingList {
|
|
|
dataList := make([]*models.EdbDataList, 0)
|
|
@@ -229,12 +165,26 @@ func GetChartEdbData(chartInfoId int, startDate, endDate string, edbInfoMapping,
|
|
|
}
|
|
|
|
|
|
edbList = append(edbList, futureGoodMappingList...)
|
|
|
- xEdbIdValue, yDataList, err = BarChartData(edbList, edbDataListMap, barChartInfoDateList, barChartInfoSort)
|
|
|
+ xEdbIdValue, yDataList, err = BarChartData(edbList[0], futureGoodMappingList, edbDataListMap, barChartInfoDateList, barChartInfoSort)
|
|
|
+
|
|
|
+ xDataList = []models.XData{
|
|
|
+ {
|
|
|
+ Name: "现货价",
|
|
|
+ NameEn: "Spot Price",
|
|
|
+ },
|
|
|
+ }
|
|
|
+
|
|
|
+ for i := 1; i <= 11; i++ {
|
|
|
+ xDataList = append(xDataList, models.XData{
|
|
|
+ Name: fmt.Sprint("M+", i),
|
|
|
+ NameEn: fmt.Sprint("M+", i),
|
|
|
+ })
|
|
|
+ }
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// BarChartData 柱方图的数据处理
|
|
|
-func BarChartData(mappingList []*models.ChartEdbInfoMapping, edbDataListMap map[int][]*models.EdbDataList, barChartInfoDateList []data_manage.BarChartInfoDateReq, barChartInfoSort data_manage.BarChartInfoSortReq) (edbIdList []int, yDataList []models.YData, err error) {
|
|
|
+func BarChartData(edbInfoMapping *models.ChartEdbInfoMapping, futureGoodMappingList []*models.ChartEdbInfoMapping, edbDataListMap map[int][]*models.EdbDataList, barChartInfoDateList []data_manage.BarChartInfoDateReq, barChartInfoSort data_manage.BarChartInfoSortReq) (edbIdList []int, yDataList []models.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 {
|
|
@@ -247,190 +197,113 @@ func BarChartData(mappingList []*models.ChartEdbInfoMapping, edbDataListMap map[
|
|
|
|
|
|
// edbIdList 指标展示顺序;x轴的指标顺序
|
|
|
edbIdList = make([]int, 0)
|
|
|
- //Sort int `description:"排序类型,0:默认,1:升序,2:降序"`
|
|
|
- dateData := make(map[int]float64)
|
|
|
+ edbIdList = append(edbIdList, edbInfoMapping.EdbInfoId)
|
|
|
if barChartInfoSort.Sort == 0 {
|
|
|
- for _, v := range mappingList {
|
|
|
+ for _, v := range futureGoodMappingList {
|
|
|
edbIdList = append(edbIdList, v.EdbInfoId)
|
|
|
}
|
|
|
- } else {
|
|
|
- lenBarChartInfoDateList := len(barChartInfoDateList)
|
|
|
- if barChartInfoSort.DateIndex >= lenBarChartInfoDateList {
|
|
|
- err = errors.New("排序日期异常")
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- notDataEdbIdList := make([]int, 0) //没有数据的指标id
|
|
|
- // 日期配置
|
|
|
- barChartInfoDate := barChartInfoDateList[barChartInfoSort.DateIndex]
|
|
|
- for edbInfoId, dataList := range edbDataListMap {
|
|
|
- if len(dataList) <= 0 {
|
|
|
- // 没有数据的指标id
|
|
|
- notDataEdbIdList = append(notDataEdbIdList, edbInfoId)
|
|
|
- continue
|
|
|
- }
|
|
|
- findDate := barChartInfoDate.Date
|
|
|
- switch barChartInfoDate.Type {
|
|
|
- case 1: //最新值
|
|
|
- findDate = dataList[len(dataList)-1].DataTime
|
|
|
- case 2: //近期几天
|
|
|
- findDateTime, tmpErr := time.ParseInLocation(utils.FormatDate, dataList[len(dataList)-1].DataTime, time.Local)
|
|
|
- if tmpErr != nil {
|
|
|
- err = tmpErr
|
|
|
- return
|
|
|
- }
|
|
|
- findDateTime = findDateTime.AddDate(0, 0, -barChartInfoDate.Value)
|
|
|
-
|
|
|
- lenData := len(dataList) - 1
|
|
|
-
|
|
|
- for i := lenData; i >= 0; i-- {
|
|
|
- currDateTime, tmpErr := time.ParseInLocation(utils.FormatDate, dataList[i].DataTime, time.Local)
|
|
|
- if tmpErr != nil {
|
|
|
- err = tmpErr
|
|
|
- return
|
|
|
- }
|
|
|
- if currDateTime.Equal(findDateTime) || currDateTime.Before(findDateTime) {
|
|
|
- findDate = dataList[i].DataTime
|
|
|
- break
|
|
|
- }
|
|
|
- }
|
|
|
- case 3: // 固定日期
|
|
|
- //最早的日期
|
|
|
- minDateTime, tmpErr := time.ParseInLocation(utils.FormatDate, dataList[0].DataTime, time.Local)
|
|
|
- if tmpErr != nil {
|
|
|
- err = tmpErr
|
|
|
- return
|
|
|
- }
|
|
|
- //寻找固定日期的数据
|
|
|
- findDateTime, tmpErr := time.ParseInLocation(utils.FormatDate, barChartInfoDate.Date, time.Local)
|
|
|
- if tmpErr != nil {
|
|
|
- err = tmpErr
|
|
|
- return
|
|
|
- }
|
|
|
- for tmpDateTime := findDateTime; tmpDateTime.After(minDateTime) || tmpDateTime.Equal(minDateTime); tmpDateTime = tmpDateTime.AddDate(0, 0, -1) {
|
|
|
- tmpDate := tmpDateTime.Format(utils.FormatDate)
|
|
|
- if _, ok := edbDataMap[edbInfoId][tmpDate]; ok { //如果能找到数据,那么就返回
|
|
|
- findDate = tmpDate
|
|
|
- break
|
|
|
- }
|
|
|
- }
|
|
|
- default:
|
|
|
- err = errors.New(fmt.Sprint("日期类型异常,Type:", barChartInfoDate.Type))
|
|
|
- return
|
|
|
- }
|
|
|
- if tmpValue, ok := edbDataMap[edbInfoId][findDate]; ok {
|
|
|
- dateData[edbInfoId] = tmpValue
|
|
|
- } else {
|
|
|
- // 没有数据的指标id
|
|
|
- notDataEdbIdList = append(notDataEdbIdList, edbInfoId)
|
|
|
- }
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
- //Sort int `description:"排序类型,0:默认,1:升序,2:降序"`
|
|
|
- // 排序
|
|
|
- dateDataSort := utils.NewMapSorter(dateData)
|
|
|
- sort.Sort(dateDataSort)
|
|
|
- if barChartInfoSort.Sort == 1 {
|
|
|
- // 先将没有数据的指标id放在最前面
|
|
|
- if len(notDataEdbIdList) > 0 {
|
|
|
- edbIdList = append(edbIdList, notDataEdbIdList...)
|
|
|
- }
|
|
|
- for _, v := range dateDataSort {
|
|
|
- edbIdList = append(edbIdList, v.Key)
|
|
|
- }
|
|
|
- } else {
|
|
|
- for i := len(dateDataSort) - 1; i >= 0; i-- {
|
|
|
- edbIdList = append(edbIdList, dateDataSort[i].Key)
|
|
|
- }
|
|
|
- // 再将没有数据的指标id放在最后面
|
|
|
- if len(notDataEdbIdList) > 0 {
|
|
|
- edbIdList = append(edbIdList, notDataEdbIdList...)
|
|
|
- }
|
|
|
- }
|
|
|
+ //固定取螺纹期货主力合约的时间序列,最新值为该合约最新日期、N天前为该合约最新日期N天前
|
|
|
+ rbzlInfo, err := efuture_good.GetFutureGoodEdbInfoByCode("RBZL.SHF")
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ latestDate := rbzlInfo.EndDate // 最新日期是这个
|
|
|
+ if rbzlInfo.EndDate == `0000-00-00` {
|
|
|
+ err = errors.New("日期异常")
|
|
|
+ return
|
|
|
}
|
|
|
+ latestDateTime, _ := time.ParseInLocation(utils.FormatDate, latestDate, time.Local)
|
|
|
|
|
|
yDataList = make([]models.YData, 0) //y轴的数据列表
|
|
|
|
|
|
for _, barChartInfoDate := range barChartInfoDateList {
|
|
|
var maxDate time.Time
|
|
|
+ var findDateTime time.Time
|
|
|
+ switch barChartInfoDate.Type {
|
|
|
+ case 1: //最新值
|
|
|
+ findDateTime = latestDateTime
|
|
|
+ case 2: //近期几天
|
|
|
+ findDateTime = latestDateTime.AddDate(0, 0, -barChartInfoDate.Value)
|
|
|
+ case 3: // 固定日期
|
|
|
+ //寻找固定日期的数据
|
|
|
+ tmpFindDateTime, tmpErr := time.ParseInLocation(utils.FormatDate, barChartInfoDate.Date, time.Local)
|
|
|
+ if tmpErr != nil {
|
|
|
+ err = tmpErr
|
|
|
+ return
|
|
|
+ }
|
|
|
+ findDateTime = tmpFindDateTime
|
|
|
+ default:
|
|
|
+ err = errors.New(fmt.Sprint("日期类型异常,Type:", barChartInfoDate.Type))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if findDateTime.IsZero() {
|
|
|
+ err = errors.New("错误的日期")
|
|
|
+ return
|
|
|
+ }
|
|
|
|
|
|
findDataList := make([]float64, 0) // 当前日期的数据值
|
|
|
noDataIdList := make([]int, 0) // 没有数据的指标id
|
|
|
noDataIdMap := make(map[int]int, 0) // 没有数据的指标map
|
|
|
- for _, edbInfoId := range edbIdList {
|
|
|
- findDate := barChartInfoDate.Date //需要的日期值
|
|
|
- dataList := edbDataListMap[edbInfoId] //指标的所有数据值
|
|
|
- if len(dataList) <= 0 {
|
|
|
- // 没有数据的指标id
|
|
|
- findDataList = append(findDataList, 0)
|
|
|
- noDataIdList = append(noDataIdList, edbInfoId)
|
|
|
- noDataIdMap[edbInfoId] = edbInfoId
|
|
|
- continue
|
|
|
+ xEdbInfoIdList := make([]int, 0) // 当前数据的指标id列表
|
|
|
+
|
|
|
+ // 现货指标
|
|
|
+ realDateTime, findDataValue, isFind, tmpErr := GetNeedDateData(findDateTime, edbDataListMap[edbInfoMapping.EdbInfoId], edbDataMap[edbInfoMapping.EdbInfoId])
|
|
|
+ if tmpErr != nil {
|
|
|
+ err = tmpErr
|
|
|
+ return
|
|
|
+ }
|
|
|
+ findDataList = append(findDataList, findDataValue)
|
|
|
+ if isFind {
|
|
|
+ maxDate = realDateTime
|
|
|
+ } else {
|
|
|
+ noDataIdList = append(noDataIdList, edbInfoMapping.EdbInfoId)
|
|
|
+ noDataIdMap[edbInfoMapping.EdbInfoId] = edbInfoMapping.EdbInfoId
|
|
|
+ }
|
|
|
+ currMonth := findDateTime.Month() // 当前月份
|
|
|
+ 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
|
|
|
}
|
|
|
- switch barChartInfoDate.Type {
|
|
|
- case 1: //最新值
|
|
|
- dataList := edbDataListMap[edbInfoId]
|
|
|
- findDate = dataList[len(dataList)-1].DataTime
|
|
|
- case 2: //近期几天
|
|
|
- findDateTime, tmpErr := time.ParseInLocation(utils.FormatDate, dataList[len(dataList)-1].DataTime, time.Local)
|
|
|
- if tmpErr != nil {
|
|
|
- err = tmpErr
|
|
|
- return
|
|
|
- }
|
|
|
- findDateTime = findDateTime.AddDate(0, 0, -barChartInfoDate.Value)
|
|
|
-
|
|
|
- lenData := len(dataList) - 1
|
|
|
- for i := lenData; i >= 0; i-- {
|
|
|
- currDateTime, tmpErr := time.ParseInLocation(utils.FormatDate, dataList[i].DataTime, time.Local)
|
|
|
- if tmpErr != nil {
|
|
|
- err = tmpErr
|
|
|
- return
|
|
|
- }
|
|
|
- if currDateTime.Equal(findDateTime) || currDateTime.Before(findDateTime) {
|
|
|
- findDate = dataList[i].DataTime
|
|
|
- break
|
|
|
- }
|
|
|
- }
|
|
|
- case 3: // 固定日期
|
|
|
- //最早的日期
|
|
|
- minDateTime, tmpErr := time.ParseInLocation(utils.FormatDate, dataList[0].DataTime, time.Local)
|
|
|
- if tmpErr != nil {
|
|
|
- err = tmpErr
|
|
|
- return
|
|
|
+ findDataList = append(findDataList, tmpFindDataValue)
|
|
|
+ if tmpIsFind {
|
|
|
+ if maxDate.IsZero() || maxDate.Before(tmpRealDateTime) {
|
|
|
+ maxDate = realDateTime
|
|
|
}
|
|
|
- //寻找固定日期的数据
|
|
|
- findDateTime, tmpErr := time.ParseInLocation(utils.FormatDate, barChartInfoDate.Date, time.Local)
|
|
|
- if tmpErr != nil {
|
|
|
- err = tmpErr
|
|
|
- return
|
|
|
- }
|
|
|
- for tmpDateTime := findDateTime; tmpDateTime.After(minDateTime) || tmpDateTime.Equal(minDateTime); tmpDateTime = tmpDateTime.AddDate(0, 0, -1) {
|
|
|
- tmpDate := tmpDateTime.Format(utils.FormatDate)
|
|
|
- if _, ok := edbDataMap[edbInfoId][tmpDate]; ok { //如果能找到数据,那么就返回
|
|
|
- findDate = tmpDate
|
|
|
- break
|
|
|
- }
|
|
|
- }
|
|
|
- default:
|
|
|
- err = errors.New(fmt.Sprint("日期类型异常,Type:", barChartInfoDate.Type))
|
|
|
+ } 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])
|
|
|
+ if tmpErr != nil {
|
|
|
+ err = tmpErr
|
|
|
return
|
|
|
}
|
|
|
- findDateTime, _ := time.ParseInLocation(utils.FormatDate, findDate, time.Local)
|
|
|
- if maxDate.IsZero() {
|
|
|
- maxDate = findDateTime
|
|
|
- } else {
|
|
|
- if findDateTime.After(maxDate) {
|
|
|
- maxDate = findDateTime
|
|
|
+ findDataList = append(findDataList, tmpFindDataValue)
|
|
|
+ if tmpIsFind {
|
|
|
+ if maxDate.IsZero() || maxDate.Before(tmpRealDateTime) {
|
|
|
+ maxDate = realDateTime
|
|
|
}
|
|
|
- }
|
|
|
- if tmpValue, ok := edbDataMap[edbInfoId][findDate]; ok {
|
|
|
- findDataList = append(findDataList, tmpValue)
|
|
|
} else {
|
|
|
- findDataList = append(findDataList, 0)
|
|
|
- noDataIdList = append(noDataIdList, edbInfoId)
|
|
|
- noDataIdMap[edbInfoId] = edbInfoId
|
|
|
+ noDataIdList = append(noDataIdList, futureGoodMapping.EdbInfoId)
|
|
|
+ noDataIdMap[futureGoodMapping.EdbInfoId] = futureGoodMapping.EdbInfoId
|
|
|
}
|
|
|
+ // 当前期货合约的指标
|
|
|
+ xEdbInfoIdList = append(xEdbInfoIdList, futureGoodMapping.EdbInfoId)
|
|
|
}
|
|
|
+
|
|
|
yName := barChartInfoDate.Name
|
|
|
yNameEn := barChartInfoDate.Name
|
|
|
if yName == `` {
|
|
@@ -492,6 +365,33 @@ func BarChartData(mappingList []*models.ChartEdbInfoMapping, edbDataListMap map[
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+// GetNeedDateData 获取合约内需要的日期数据
|
|
|
+func GetNeedDateData(needDateTime time.Time, dataList []*models.EdbDataList, edbDataMap map[string]float64) (findDateTime time.Time, findDataValue float64, isFind bool, err error) {
|
|
|
+ //dataList := edbDataListMap[edbInfoId] //指标的所有数据值
|
|
|
+ if len(dataList) <= 0 {
|
|
|
+ // 没有数据的指标id
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ //最早的日期
|
|
|
+ minDateTime, err := time.ParseInLocation(utils.FormatDate, dataList[0].DataTime, time.Local)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ 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 { //如果能找到数据,那么就返回
|
|
|
+ findDateTime, _ = time.ParseInLocation(utils.FormatDate, tmpDate, time.Local)
|
|
|
+ findDataValue = tmpValue
|
|
|
+ isFind = true
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
// FutureGoodChartInfoRefresh
|
|
|
// @author Roc
|
|
|
// @datetime 2023-2-2 18:44:46
|