|
@@ -421,16 +421,20 @@ type EdbInfoMaxAndMinInfo struct {
|
|
|
|
|
|
// AfterFind 在该模型上设置钩子函数,把日期转成正确的string,所以查询函数只能用Find函数,First或者Scan是不会触发该函数的来获取数据
|
|
|
func (m *EdbInfoMaxAndMinInfo) AfterFind(db *gorm.DB) (err error) {
|
|
|
- minDateTmp, err := time.ParseInLocation(utils.FormatDateWallWithLoc, m.MinDate, time.Local)
|
|
|
- if err != nil {
|
|
|
- return
|
|
|
+ if m.MinDate != "" {
|
|
|
+ minDateTmp, err := time.ParseInLocation(utils.FormatDateWallWithLoc, m.MinDate, time.Local)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ m.MinDate = minDateTmp.Format(utils.FormatDate)
|
|
|
}
|
|
|
- m.MinDate = minDateTmp.Format(utils.FormatDate)
|
|
|
- maxDateTmp, err := time.ParseInLocation(utils.FormatDateWallWithLoc, m.MaxDate, time.Local)
|
|
|
- if err != nil {
|
|
|
- return
|
|
|
+ if m.MaxDate != "" {
|
|
|
+ maxDateTmp, err := time.ParseInLocation(utils.FormatDateWallWithLoc, m.MaxDate, time.Local)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ m.MaxDate = maxDateTmp.Format(utils.FormatDate)
|
|
|
}
|
|
|
- m.MaxDate = maxDateTmp.Format(utils.FormatDate)
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -452,8 +456,7 @@ func GetEdbInfoMaxAndMinInfo(source, subSource int, edbCode string) (item *EdbIn
|
|
|
tableName := GetEdbDataTableName(source, subSource)
|
|
|
sql = ` SELECT MIN(data_time) AS min_date,MAX(data_time) AS max_date,MIN(value) AS min_value,MAX(value) AS max_value FROM %s WHERE edb_code=? `
|
|
|
sql = fmt.Sprintf(sql, tableName)
|
|
|
- err = global.DEFAULT_DmSQL.Raw(sql, edbCode).Find(&item).Error
|
|
|
- //fmt.Println("item.MinDate", item.MinDate)
|
|
|
+ err = global.DEFAULT_DmSQL.Raw(sql, edbCode).First(&item).Error
|
|
|
|
|
|
/*itemTmp.MinDate = itemTmp.MinDate.In(time.Local)
|
|
|
itemTmp.MaxDate = itemTmp.MaxDate.In(time.Local)
|
|
@@ -483,6 +486,9 @@ type EdbIndoDataUpdateTime struct {
|
|
|
|
|
|
// AfterFind 在该模型上设置钩子函数,把日期转成正确的string,所以查询函数只能用Find函数,First或者Scan是不会触发该函数的来获取数据
|
|
|
func (m *EdbIndoDataUpdateTime) AfterFind(db *gorm.DB) (err error) {
|
|
|
+ if m.MinDate == "" {
|
|
|
+ return
|
|
|
+ }
|
|
|
minDateTmp, err := time.ParseInLocation(utils.FormatDateWallWithLoc, m.MinDate, time.Local)
|
|
|
if err != nil {
|
|
|
return
|
|
@@ -498,7 +504,7 @@ func GetEdbDataUpdateTimeByModify(source, subSource int, edbCode string, dataUpd
|
|
|
tableName := GetEdbDataTableName(source, subSource)
|
|
|
sql = ` SELECT MIN(data_time) AS min_date FROM %s WHERE edb_code=? and modify_time>=?`
|
|
|
sql = fmt.Sprintf(sql, tableName)
|
|
|
- err = global.DEFAULT_DmSQL.Raw(sql, edbCode, dataUpdateTime).Find(&item).Error
|
|
|
+ err = global.DEFAULT_DmSQL.Raw(sql, edbCode, dataUpdateTime).First(&item).Error
|
|
|
return
|
|
|
}
|
|
|
|