xyxie 1 年之前
父節點
當前提交
7e0801e87b
共有 3 個文件被更改,包括 49 次插入6 次删除
  1. 1 1
      models/jiayue/dict.go
  2. 46 4
      services/index_data/jiayue_platform.go
  3. 2 1
      utils/constants.go

文件差異過大導致無法顯示
+ 1 - 1
models/jiayue/dict.go


+ 46 - 4
services/index_data/jiayue_platform.go

@@ -7,6 +7,7 @@ import (
 	"eta/eta_bridge/models/response"
 	"eta/eta_bridge/utils"
 	"fmt"
+	"time"
 )
 
 func GetIndexFromJiaYue(indexCode, source, startDate, endDate string) (data *response.IndexResp, err error, errMsg string) {
@@ -56,18 +57,59 @@ func GetIndexFromJiaYue(indexCode, source, startDate, endDate string) (data *res
 	}
 	var list []response.IndexData
 	for _, v := range indexData {
+		var dataTimeStr string
+		if v.IndexDate != "" {
+			dataTime, e := time.ParseInLocation(utils.FormatDateDefault, v.IndexDate, time.Local)
+			if e != nil {
+				err = e
+				fmt.Println("解析时间失败:", err)
+				return
+			}
+			dataTimeStr = dataTime.Format(utils.FormatDate)
+		}
+		var updateTimeStr string
+		if v.UpdateTime != "" {
+			updateTime, e := time.ParseInLocation(utils.FormatDateDefault, v.UpdateTime, time.Local)
+			if e != nil {
+				err = e
+				fmt.Println("解析时间失败:", err)
+				return
+			}
+			updateTimeStr = updateTime.Format(utils.FormatDateTime)
+		}
+
 		tmp := response.IndexData{
 			Val:        v.IndexValue,
-			DataTime:   v.IndexDate.Format(utils.FormatDate),
-			UpdateTime: v.UpdateTime.Format(utils.FormatDateTime),
+			DataTime:   dataTimeStr,
+			UpdateTime: updateTimeStr,
 		}
 		list = append(list, tmp)
 	}
+	var dateLastStr, timeLastUpdateStr string
+	if index.DateLast != "" {
+		dateLast, e := time.ParseInLocation(utils.FormatDateDefault, index.DateLast, time.Local)
+		if e != nil {
+			err = e
+			fmt.Println("解析时间失败:", err)
+			return
+		}
+		dateLastStr = dateLast.Format(utils.FormatDate)
+	}
+	if index.TimeLastUpdate != "" {
+		timeLastUpdate, e := time.ParseInLocation(utils.FormatDateDefault, index.TimeLastUpdate, time.Local)
+		if e != nil {
+			err = e
+			fmt.Println("解析时间失败:", err)
+			return
+		}
+		timeLastUpdateStr = timeLastUpdate.Format(utils.FormatDateTime)
+	}
+
 	data = new(response.IndexResp)
 	data.IndexData = list
 	data.IndexCode = indexCode
-	data.LastDate = index.DateLast.Format(utils.FormatDate)
-	data.LastUpdateTime = index.TimeLastUpdate.Format(utils.FormatDateTime)
+	data.LastDate = dateLastStr
+	data.LastUpdateTime = timeLastUpdateStr
 	data.Status = index.Status
 	return
 }

+ 2 - 1
utils/constants.go

@@ -9,7 +9,8 @@ const (
 	FormatDateTime        = "2006-01-02 15:04:05"     //完整时间格式
 	HlbFormatDateTime     = "2006-01-02_15:04:05.999" //完整时间格式
 	FormatDateTimeUnSpace = "20060102150405"          //完整时间格式
-	PageSize15            = 15                        //列表页每页数据量
+	FormatDateDefault     = "2006-01-02T15:04:05+08:00"
+	PageSize15            = 15 //列表页每页数据量
 	PageSize5             = 5
 	PageSize10            = 10
 	PageSize20            = 20

部分文件因文件數量過多而無法顯示