浏览代码

Merge remote-tracking branch 'origin/fix/sci_end_date' into debug

Roc 2 月之前
父节点
当前提交
a90f5d2fdf
共有 2 个文件被更改,包括 32 次插入1 次删除
  1. 1 0
      models/base_from_sci.go
  2. 31 1
      services/base_from_sci.go

+ 1 - 0
models/base_from_sci.go

@@ -235,6 +235,7 @@ type BaseFromSciIndex struct {
 	ModifyTime         time.Time `gorm:"autoUpdateTime:milli;column:modify_time" json:"modify_time"` //最后更新时间
 	FilePath           string    `gorm:"column:file_path" json:"file_path"`                          // 文件路径
 	TerminalCode       string    `gorm:"column:terminal_code" json:"terminal_code"`                  // 指标编码
+	LatestValue        float64   `gorm:"column:latest_value" json:"latest_value"`                    // 数据最新值
 }
 
 // TableName get sql table name.获取数据库表名

+ 31 - 1
services/base_from_sci.go

@@ -6,6 +6,7 @@ import (
 	"eta/eta_index_lib/services/alarm_msg"
 	"eta/eta_index_lib/utils"
 	"fmt"
+	"github.com/shopspring/decimal"
 	"strings"
 	"time"
 )
@@ -125,12 +126,25 @@ func HandleSciData(dataMap map[string]map[string]string) {
 		}
 		addSciDataList := make([]*models.BaseFromSciData, 0)
 
+		var tmpStartDate, tmpEndDate time.Time
+		var latestValue string
+
 		for currDate, currVal := range data {
 			currDataTime, tmpErr := time.ParseInLocation(utils.FormatDate, currDate, time.Local)
 			if tmpErr != nil {
 				errMsgList = append(errMsgList, fmt.Sprint("时间格式化失败,指标编码:", currDate, ";错误原因:", tmpErr.Error()))
 				continue
 			}
+			// 如果开始日期为空、或者当前日期早于开始日期,那么给开始日期赋值为当前日期
+			if tmpStartDate.IsZero() || currDataTime.Before(tmpStartDate) {
+				tmpStartDate = currDataTime
+			}
+			// 如果结束日期为空、或者当前日期晚于结束日期,那么给结束日期赋值为当前日期,且赋值最新值
+			if tmpEndDate.IsZero() || currDataTime.After(tmpEndDate) {
+				tmpEndDate = currDataTime
+				latestValue = currVal
+			}
+
 			timestamp := currDataTime.UnixNano() / 1e6
 
 			sciData, ok := indexDataExistMap[currDate]
@@ -174,8 +188,24 @@ func HandleSciData(dataMap map[string]map[string]string) {
 				continue
 			}
 		}
+
+		updateCols := []string{"ModifyTime"}
 		indexInfo.ModifyTime = time.Now()
-		indexInfo.Update([]string{"ModifyTime"})
+		if !tmpStartDate.IsZero() {
+			indexInfo.StartDate = tmpStartDate
+			updateCols = append(updateCols, "StartDate")
+		}
+		if !tmpEndDate.IsZero() {
+			indexInfo.EndDate = tmpEndDate
+			updateCols = append(updateCols, "EndDate")
+		}
+
+		latestValueDeci, tmpErr := decimal.NewFromString(latestValue)
+		if tmpErr == nil {
+			indexInfo.LatestValue, _ = latestValueDeci.Float64()
+			updateCols = append(updateCols, "LatestValue")
+		}
+		indexInfo.Update(updateCols)
 
 		// 同步刷新ETA图库红桃3的指标
 		{