|
@@ -0,0 +1,539 @@
|
|
|
+package future_good
|
|
|
+
|
|
|
+import (
|
|
|
+ "errors"
|
|
|
+ "fmt"
|
|
|
+ "github.com/shopspring/decimal"
|
|
|
+ "hongze/hongze_chart_lib/models"
|
|
|
+ "hongze/hongze_chart_lib/models/data_manage"
|
|
|
+ efuture_good "hongze/hongze_chart_lib/models/data_manage/future_good"
|
|
|
+ "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) {
|
|
|
+ edbList = make([]*models.ChartEdbInfoMapping, 0)
|
|
|
+
|
|
|
+ if futureGoodEdbInfoMapping == nil {
|
|
|
+ err = errors.New("商品指标未选取")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if edbInfoMapping == nil {
|
|
|
+ err = errors.New("ETA指标未选取")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 指标对应的所有数据
|
|
|
+ edbDataListMap := make(map[int][]*models.EdbDataList)
|
|
|
+
|
|
|
+ item := new(data_manage.ChartEdbInfoMapping)
|
|
|
+ edbInfoMapping.FrequencyEn = data.GetFrequencyEn(edbInfoMapping.Frequency)
|
|
|
+
|
|
|
+ if edbInfoMapping.Unit == `无` {
|
|
|
+ edbInfoMapping.Unit = ``
|
|
|
+ }
|
|
|
+ if futureGoodEdbInfoMapping.Unit == `无` {
|
|
|
+ futureGoodEdbInfoMapping.Unit = ``
|
|
|
+ }
|
|
|
+
|
|
|
+ if chartInfoId <= 0 {
|
|
|
+ edbInfoMapping.IsAxis = 1
|
|
|
+ edbInfoMapping.LeadValue = 0
|
|
|
+ edbInfoMapping.LeadUnit = ""
|
|
|
+ edbInfoMapping.ChartEdbMappingId = 0
|
|
|
+ edbInfoMapping.ChartInfoId = 0
|
|
|
+ edbInfoMapping.IsOrder = false
|
|
|
+ edbInfoMapping.EdbInfoType = 1
|
|
|
+ edbInfoMapping.ChartStyle = ""
|
|
|
+ edbInfoMapping.ChartColor = ""
|
|
|
+ edbInfoMapping.ChartWidth = 0
|
|
|
+
|
|
|
+ futureGoodEdbInfoMapping.IsAxis = 1
|
|
|
+ futureGoodEdbInfoMapping.LeadValue = 0
|
|
|
+ futureGoodEdbInfoMapping.LeadUnit = ""
|
|
|
+ futureGoodEdbInfoMapping.ChartEdbMappingId = 0
|
|
|
+ futureGoodEdbInfoMapping.ChartInfoId = 0
|
|
|
+ futureGoodEdbInfoMapping.IsOrder = false
|
|
|
+ futureGoodEdbInfoMapping.EdbInfoType = 1
|
|
|
+ futureGoodEdbInfoMapping.ChartStyle = ""
|
|
|
+ futureGoodEdbInfoMapping.ChartColor = ""
|
|
|
+ futureGoodEdbInfoMapping.ChartWidth = 0
|
|
|
+ } else {
|
|
|
+ edbInfoMapping.LeadUnitEn = data.GetLeadUnitEn(edbInfoMapping.LeadUnit)
|
|
|
+ futureGoodEdbInfoMapping.LeadUnitEn = data.GetLeadUnitEn(futureGoodEdbInfoMapping.LeadUnit)
|
|
|
+ }
|
|
|
+
|
|
|
+ // 普通的指标数据
|
|
|
+ {
|
|
|
+ dataList := make([]*models.EdbDataList, 0)
|
|
|
+
|
|
|
+ dataList, err = models.GetEdbDataList(edbInfoMapping.Source, edbInfoMapping.EdbInfoId, startDate, endDate)
|
|
|
+ edbDataListMap[edbInfoMapping.EdbInfoId] = dataList
|
|
|
+ item.DataList = dataList
|
|
|
+
|
|
|
+ edbList = append(edbList, edbInfoMapping)
|
|
|
+
|
|
|
+ barConfigEdbInfoIdList = append(barConfigEdbInfoIdList, data_manage.BarChartInfoEdbItemReq{
|
|
|
+ EdbInfoId: edbInfoMapping.EdbInfoId,
|
|
|
+ //Name: edbInfoMapping.EdbName,
|
|
|
+ Name: "现货价",
|
|
|
+ NameEn: "Spot Price",
|
|
|
+ Source: edbInfoMapping.Source,
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ nowMonth := time.Now().Month()
|
|
|
+ // 获取期货指标以及期货数据
|
|
|
+ futureGoodEdbInfoList, err := efuture_good.GetFutureGoodEdbInfoListByParentId(futureGoodEdbInfoMapping.EdbInfoId)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ 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,
|
|
|
+ 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 + 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 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)
|
|
|
+
|
|
|
+ tmpDataList, tmpErr := efuture_good.GetFutureGoodEdbDataListByDate(v.EdbInfoId, startDate, endDate)
|
|
|
+ if tmpErr != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, tmpData := range tmpDataList {
|
|
|
+ dataList = append(dataList, &models.EdbDataList{
|
|
|
+ EdbDataId: tmpData.FutureGoodEdbDataId,
|
|
|
+ EdbInfoId: tmpData.FutureGoodEdbInfoId,
|
|
|
+ DataTime: tmpData.DataTime.Format(utils.FormatDate),
|
|
|
+ DataTimestamp: tmpData.DataTimestamp,
|
|
|
+ Value: tmpData.Close,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ edbDataListMap[v.EdbInfoId] = dataList
|
|
|
+ v.DataList = dataList
|
|
|
+ }
|
|
|
+
|
|
|
+ edbList = append(edbList, futureGoodMappingList...)
|
|
|
+ xEdbIdValue, yDataList, err = BarChartData(edbList, edbDataListMap, barChartInfoDateList, barChartInfoSort)
|
|
|
+ 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) {
|
|
|
+ // 指标数据数组(10086:{"2022-12-02":100.01,"2022-12-01":102.3})
|
|
|
+ edbDataMap := make(map[int]map[string]float64)
|
|
|
+ for edbInfoId, edbDataList := range edbDataListMap {
|
|
|
+ edbDateData := make(map[string]float64)
|
|
|
+ for _, edbData := range edbDataList {
|
|
|
+ edbDateData[edbData.DataTime] = edbData.Value
|
|
|
+ }
|
|
|
+ edbDataMap[edbInfoId] = edbDateData
|
|
|
+ }
|
|
|
+
|
|
|
+ // edbIdList 指标展示顺序;x轴的指标顺序
|
|
|
+ edbIdList = make([]int, 0)
|
|
|
+ //Sort int `description:"排序类型,0:默认,1:升序,2:降序"`
|
|
|
+ dateData := make(map[int]float64)
|
|
|
+ if barChartInfoSort.Sort == 0 {
|
|
|
+ for _, v := range mappingList {
|
|
|
+ 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...)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ yDataList = make([]models.YData, 0) //y轴的数据列表
|
|
|
+
|
|
|
+ for _, barChartInfoDate := range barChartInfoDateList {
|
|
|
+ var maxDate time.Time
|
|
|
+
|
|
|
+ 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
|
|
|
+ }
|
|
|
+ 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
|
|
|
+ }
|
|
|
+ //寻找固定日期的数据
|
|
|
+ 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
|
|
|
+ }
|
|
|
+ findDateTime, _ := time.ParseInLocation(utils.FormatDate, findDate, time.Local)
|
|
|
+ if maxDate.IsZero() {
|
|
|
+ maxDate = findDateTime
|
|
|
+ } else {
|
|
|
+ if findDateTime.After(maxDate) {
|
|
|
+ maxDate = findDateTime
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if tmpValue, ok := edbDataMap[edbInfoId][findDate]; ok {
|
|
|
+ findDataList = append(findDataList, tmpValue)
|
|
|
+ } else {
|
|
|
+ findDataList = append(findDataList, 0)
|
|
|
+ noDataIdList = append(noDataIdList, edbInfoId)
|
|
|
+ noDataIdMap[edbInfoId] = edbInfoId
|
|
|
+ }
|
|
|
+ }
|
|
|
+ yName := barChartInfoDate.Name
|
|
|
+ yNameEn := barChartInfoDate.Name
|
|
|
+ if yName == `` {
|
|
|
+ if barChartInfoDate.Type == 2 {
|
|
|
+ yName = strconv.Itoa(barChartInfoDate.Value) + "天前"
|
|
|
+ if barChartInfoDate.Value == 1 {
|
|
|
+ yNameEn = strconv.Itoa(barChartInfoDate.Value) + "day ago"
|
|
|
+ } else {
|
|
|
+ yNameEn = strconv.Itoa(barChartInfoDate.Value) + " days ago"
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ yName = maxDate.Format(utils.FormatDate)
|
|
|
+ yNameEn = maxDate.Format(utils.FormatDate)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ yDate := "0000-00-00"
|
|
|
+ if !maxDate.IsZero() {
|
|
|
+ yDate = maxDate.Format(utils.FormatDate)
|
|
|
+ }
|
|
|
+
|
|
|
+ // 数据处理,将没有数据的下标,赋值平均值
|
|
|
+ {
|
|
|
+ hasDataIndexList := make([]int, 0)
|
|
|
+ for dataK, edbInfoId := range edbIdList {
|
|
|
+ if _, ok := noDataIdMap[edbInfoId]; !ok { // 如果是没有数据的指标id
|
|
|
+ hasDataIndexList = append(hasDataIndexList, dataK)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ lenHasDataIndex := len(hasDataIndexList)
|
|
|
+ if lenHasDataIndex > 0 {
|
|
|
+ for lenHasDataI := 1; lenHasDataI < lenHasDataIndex; lenHasDataI++ {
|
|
|
+ perK := hasDataIndexList[lenHasDataI-1] //上一个有数据的指标下标
|
|
|
+ currK := hasDataIndexList[lenHasDataI] //当前有数据的指标下标
|
|
|
+ preVal := findDataList[perK] //上一个有数据的坐标的值
|
|
|
+ currVal := findDataList[currK] //当前有数据的指标的值
|
|
|
+
|
|
|
+ // 环差值
|
|
|
+ hcValDeci := decimal.NewFromFloat(currVal).Sub(decimal.NewFromFloat(preVal)).Div(decimal.NewFromInt(int64(currK - perK)))
|
|
|
+ var tmpI int64
|
|
|
+ // 将两个中间的数据做平均值补全
|
|
|
+ for hcI := perK + 1; hcI < currK; hcI++ {
|
|
|
+ tmpI++
|
|
|
+ findDataList[hcI], _ = decimal.NewFromFloat(preVal).Add(hcValDeci.Mul(decimal.NewFromInt(tmpI))).RoundCeil(4).Float64()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ yDataList = append(yDataList, models.YData{
|
|
|
+ Date: yDate,
|
|
|
+ Value: findDataList,
|
|
|
+ NoDataEdbList: noDataIdList,
|
|
|
+ Color: barChartInfoDate.Color,
|
|
|
+ Name: yName,
|
|
|
+ NameEn: yNameEn,
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// FutureGoodChartInfoRefresh
|
|
|
+// @author Roc
|
|
|
+// @datetime 2023-2-2 18:44:46
|
|
|
+// @description 商品价格曲线图表刷新
|
|
|
+func FutureGoodChartInfoRefresh(chartInfoId int) (err error) {
|
|
|
+ var errMsg string
|
|
|
+ defer func() {
|
|
|
+ if err != nil {
|
|
|
+ go alarm_msg.SendAlarmMsg("ChartInfoRefresh:"+errMsg, 3)
|
|
|
+ fmt.Println("ChartInfoRefresh Err:" + errMsg)
|
|
|
+ }
|
|
|
+ }()
|
|
|
+
|
|
|
+ edbInfoMapping, err := models.GetEtaEdbChartEdbMapping(chartInfoId)
|
|
|
+ if err != nil {
|
|
|
+ errMsg = "获取需要刷新的ETA指标失败:Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 获取期货指标
|
|
|
+ futureGoodEdbInfoMapping, err := models.GetFutureGoodEdbChartEdbMapping(chartInfoId)
|
|
|
+ if err != nil {
|
|
|
+ errMsg = "获取需要刷新的商品期货指标失败:Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取期货指标以及期货数据
|
|
|
+ futureGoodEdbInfoList, err := efuture_good.GetFutureGoodEdbInfoListByParentId(futureGoodEdbInfoMapping.EdbInfoId)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 批量刷新ETA指标
|
|
|
+ err, _ = data.EdbInfoRefreshAllFromBase([]int{edbInfoMapping.EdbInfoId}, false)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 批量刷新期货指标
|
|
|
+ err = FutureGoodEdbInfoRefreshAllFromBase(futureGoodEdbInfoList, false)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ return
|
|
|
+}
|