|
@@ -58,25 +58,46 @@ func GetLyDataListByIndexCodes(IndexCodes string) (items []string, err error) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// GetLyDataLastByIndexCode 根据指标编码查询 返回ModifyTime最后一条数据
|
|
|
-func GetLyDataLastByIndexCode(indexCodes []string) (items []*BaseFromLyData, err error) {
|
|
|
+// GetLyLastUpdateTimeLastByIndexCode 根据指标编码查询 返回ModifyTime最后一条数据
|
|
|
+func GetLyLastUpdateTimeLastByIndexCode(indexCodes []string) (items []*BaseFromLyData, err error) {
|
|
|
o := orm.NewOrmUsingDB("data")
|
|
|
|
|
|
// 将 indexCodes 切片转换为逗号分隔的字符串
|
|
|
placeholders := strings.Repeat("?,", len(indexCodes)-1) + "?"
|
|
|
|
|
|
// 构造 SQL 查询
|
|
|
- sql := `
|
|
|
- SELECT t1.*
|
|
|
- FROM base_from_ly_data t1
|
|
|
- INNER JOIN (
|
|
|
- SELECT index_code, MAX(modify_time) AS max_modify_time
|
|
|
+ sql := `SELECT index_code, MAX(modify_time) AS modify_time
|
|
|
FROM base_from_ly_data
|
|
|
WHERE index_code IN (` + placeholders + `)
|
|
|
- GROUP BY index_code
|
|
|
- ) t2
|
|
|
- ON t1.index_code = t2.index_code AND t1.modify_time = t2.max_modify_time
|
|
|
- `
|
|
|
+ GROUP BY index_code`
|
|
|
+
|
|
|
+ // 执行 SQL 查询
|
|
|
+ _, err = o.Raw(sql, indexCodes).QueryRows(&items)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ return items, nil
|
|
|
+}
|
|
|
+
|
|
|
+// GetLyLastDataTimeByIndexCode 根据指标编码查询 返回data_time最后一条数据的value
|
|
|
+func GetLyLastDataTimeByIndexCode(indexCodes []string) (items []*BaseFromLyData, err error) {
|
|
|
+ o := orm.NewOrmUsingDB("data")
|
|
|
+
|
|
|
+ // 将 indexCodes 切片转换为逗号分隔的字符串
|
|
|
+ placeholders := strings.Repeat("?,", len(indexCodes)-1) + "?"
|
|
|
+
|
|
|
+ // 构造 SQL 查询
|
|
|
+ sql := `
|
|
|
+ SELECT t1.*
|
|
|
+ FROM base_from_ly_data t1
|
|
|
+ INNER JOIN (
|
|
|
+ SELECT index_code, MAX(data_time) AS data_time
|
|
|
+ FROM base_from_ly_data
|
|
|
+ WHERE index_code IN (` + placeholders + `)
|
|
|
+ GROUP BY index_code
|
|
|
+ ) t2
|
|
|
+ ON t1.index_code = t2.index_code AND t1.data_time = t2.data_time
|
|
|
+ `
|
|
|
|
|
|
// 执行 SQL 查询
|
|
|
_, err = o.Raw(sql, indexCodes).QueryRows(&items)
|