|
@@ -4,7 +4,6 @@ package data_manage
|
|
|
import (
|
|
|
"eta/eta_api/utils"
|
|
|
"github.com/beego/beego/v2/client/orm"
|
|
|
- "strings"
|
|
|
)
|
|
|
|
|
|
type BaseFromRzdData struct {
|
|
@@ -97,14 +96,15 @@ func GetRzdDataListByIndexCodes(IndexCodes string) (items []string, err error) {
|
|
|
func GetRzdLastUpdateTimeLastByIndexCode(indexCodes []string) (items []*BaseFromRzdData, err error) {
|
|
|
o := orm.NewOrmUsingDB("data")
|
|
|
|
|
|
- // 将 indexCodes 切片转换为逗号分隔的字符串
|
|
|
- placeholders := strings.Repeat("?,", len(indexCodes)-1) + "?"
|
|
|
-
|
|
|
// 构造 SQL 查询
|
|
|
- sql := `SELECT index_code, MAX(modify_time) AS modify_time
|
|
|
- FROM base_from_rzd_data
|
|
|
- WHERE index_code IN (` + placeholders + `)
|
|
|
- GROUP BY index_code`
|
|
|
+ sql := `SELECT t1.index_code, t1.data_time, t2.value
|
|
|
+ FROM (
|
|
|
+ SELECT index_code, MAX(data_time) AS data_time
|
|
|
+ FROM base_from_rzd_data
|
|
|
+ WHERE index_code IN (` + utils.GetOrmInReplace(len(indexCodes)) + `)
|
|
|
+ GROUP BY index_code
|
|
|
+ ) AS t1
|
|
|
+ JOIN base_from_rzd_data AS t2 ON t1.index_code = t2.index_code AND t1.data_time = t2.data_time`
|
|
|
|
|
|
// 执行 SQL 查询
|
|
|
_, err = o.Raw(sql, indexCodes).QueryRows(&items)
|