Browse Source

fix:图表时间格式

zqbao 5 months ago
parent
commit
96e49efae0
2 changed files with 19 additions and 8 deletions
  1. 11 1
      models/chart.go
  2. 8 7
      utils/constants.go

+ 11 - 1
models/chart.go

@@ -10,6 +10,7 @@ import (
 	"time"
 
 	"go.mongodb.org/mongo-driver/bson"
+	"gorm.io/gorm"
 
 	"github.com/nosixtools/solarlunar"
 )
@@ -276,6 +277,15 @@ type EdbDataList struct {
 	Value         float64 `gorm:"column:value" description:"数据值"`
 }
 
+func (e *EdbDataList) AfterFind(db *gorm.DB) (err error) {
+	tmp, err := time.Parse(utils.FormatDateWallWithLoc, e.DataTime)
+	if err != nil {
+		return
+	}
+	e.DataTime = tmp.Format(utils.FormatDate)
+	return
+}
+
 // GetEdbDataList 获取指标的数据(日期正序返回)
 func GetEdbDataList(source, subSource, edbInfoId int, startDate, endDate string) (list []*EdbDataList, err error) {
 	// 自有数据需要额外处理(从mongo获取)
@@ -325,7 +335,7 @@ func getEdbDataListByMysql(source, subSource, edbInfoId int, startDate, endDate
 	sql = fmt.Sprintf(sql, tableName)
 	o := global.DmSQL["data"]
 	pars = append([]interface{}{edbInfoId}, pars...)
-	err = o.Raw(sql, pars...).Scan(&list).Error
+	err = o.Raw(sql, pars...).Find(&list).Error
 	return
 }
 

+ 8 - 7
utils/constants.go

@@ -2,13 +2,14 @@ package utils
 
 // 常量定义
 const (
-	FormatTime            = "15:04:05"                //时间格式
-	FormatDate            = "2006-01-02"              //日期格式
-	FormatDateUnSpace     = "20060102"                //日期格式
-	FormatDateTime        = "2006-01-02 15:04:05"     //完整时间格式
-	HlbFormatDateTime     = "2006-01-02_15:04:05.999" //完整时间格式
-	FormatDateTimeUnSpace = "20060102150405"          //完整时间格式
-	PageSize15            = 15                        //列表页每页数据量
+	FormatTime            = "15:04:05"                  //时间格式
+	FormatDate            = "2006-01-02"                //日期格式
+	FormatDateWallWithLoc = "2006-01-02T15:04:05-07:00" //日期格式
+	FormatDateUnSpace     = "20060102"                  //日期格式
+	FormatDateTime        = "2006-01-02 15:04:05"       //完整时间格式
+	HlbFormatDateTime     = "2006-01-02_15:04:05.999"   //完整时间格式
+	FormatDateTimeUnSpace = "20060102150405"            //完整时间格式
+	PageSize15            = 15                          //列表页每页数据量
 	PageSize5             = 5
 	PageSize10            = 10
 	PageSize20            = 20