|
@@ -4,8 +4,31 @@ package data_manage
|
|
|
import (
|
|
|
"eta/eta_api/utils"
|
|
|
"github.com/beego/beego/v2/client/orm"
|
|
|
+ "time"
|
|
|
)
|
|
|
|
|
|
+type BaseFromRzdDataOrm struct {
|
|
|
+ BaseFromRzdDataId int `orm:"column(base_from_rzd_data_id);pk"`
|
|
|
+ BaseFromRzdIndexId int `orm:"column(base_from_rzd_index_id)"`
|
|
|
+ CreateTime time.Time `orm:"column(create_time)"`
|
|
|
+ DataTime time.Time `orm:"column(data_time)"`
|
|
|
+ IndexCode string `orm:"column(index_code)"`
|
|
|
+ ModifyTime time.Time `orm:"column(modify_time)"`
|
|
|
+ Value float64 `orm:"column(value)"`
|
|
|
+}
|
|
|
+
|
|
|
+func (m *BaseFromRzdDataOrm) ToItem() (item *BaseFromRzdData) {
|
|
|
+ return &BaseFromRzdData{
|
|
|
+ BaseFromRzdDataId: m.BaseFromRzdDataId,
|
|
|
+ BaseFromRzdIndexId: m.BaseFromRzdIndexId,
|
|
|
+ CreateTime: m.CreateTime.Format(utils.FormatDateTime),
|
|
|
+ DataTime: m.DataTime.Format(utils.FormatDate),
|
|
|
+ IndexCode: m.IndexCode,
|
|
|
+ ModifyTime: m.ModifyTime.Format(utils.FormatDateTime),
|
|
|
+ Value: m.Value,
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
type BaseFromRzdData struct {
|
|
|
BaseFromRzdDataId int `orm:"column(base_from_rzd_data_id);pk"`
|
|
|
BaseFromRzdIndexId int `orm:"column(base_from_rzd_index_id)"`
|
|
@@ -47,17 +70,36 @@ func GetRzdIndexDataCountGroup(indexCodes []string) (items []*RzdIndexDataCountG
|
|
|
}
|
|
|
|
|
|
func GetRzdIndexData(indexCode string, startSize, pageSize int) (items []*BaseFromRzdData, err error) {
|
|
|
+ var ormList []*BaseFromRzdDataOrm
|
|
|
+ items = make([]*BaseFromRzdData, 0)
|
|
|
+
|
|
|
o := orm.NewOrmUsingDB("data")
|
|
|
sql := ` SELECT * FROM base_from_rzd_data WHERE index_code=? ORDER BY data_time DESC LIMIT ?,? `
|
|
|
- _, err = o.Raw(sql, indexCode, startSize, pageSize).QueryRows(&items)
|
|
|
+ _, err = o.Raw(sql, indexCode, startSize, pageSize).QueryRows(&ormList)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, ormItem := range ormList {
|
|
|
+ items = append(items, ormItem.ToItem())
|
|
|
+ }
|
|
|
+
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// GetBaseFormRzdDataByIndexCode 根据指标编码查询
|
|
|
func GetBaseFormRzdDataByIndexCode(indexCode string) (items []*BaseFromRzdData, err error) {
|
|
|
+ var ormList []*BaseFromRzdDataOrm
|
|
|
+ items = make([]*BaseFromRzdData, 0)
|
|
|
sql := `SELECT * FROM base_from_rzd_data WHERE index_code=? ORDER BY data_time desc`
|
|
|
o := orm.NewOrmUsingDB("data")
|
|
|
- _, err = o.Raw(sql, indexCode).QueryRows(&items)
|
|
|
+ _, err = o.Raw(sql, indexCode).QueryRows(&ormList)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, ormItem := range ormList {
|
|
|
+ items = append(items, ormItem.ToItem())
|
|
|
+ }
|
|
|
+
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -75,12 +117,22 @@ func GetBaseFormRzdDataByConditionCount(condition string, pars interface{}) (cou
|
|
|
}
|
|
|
|
|
|
func GetBaseFormRzdDataByCondition(condition string, pars interface{}) (items []*BaseFromRzdData, err error) {
|
|
|
+ var ormList []*BaseFromRzdDataOrm
|
|
|
+ items = make([]*BaseFromRzdData, 0)
|
|
|
+
|
|
|
o := orm.NewOrmUsingDB("data")
|
|
|
sql := ` SELECT * FROM base_from_rzd_data WHERE 1=1 `
|
|
|
if condition != "" {
|
|
|
sql += condition
|
|
|
}
|
|
|
- _, err = o.Raw(sql, pars).QueryRows(&items)
|
|
|
+ _, err = o.Raw(sql, pars).QueryRows(&ormList)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, ormItem := range ormList {
|
|
|
+ items = append(items, ormItem.ToItem())
|
|
|
+ }
|
|
|
+
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -94,6 +146,9 @@ func GetRzdDataListByIndexCodes(IndexCodes string) (items []string, err error) {
|
|
|
|
|
|
// GetRzdLastUpdateTimeLastByIndexCode 根据指标编码查询 返回ModifyTime最后一条数据
|
|
|
func GetRzdLastUpdateTimeLastByIndexCode(indexCodes []string) (items []*BaseFromRzdData, err error) {
|
|
|
+ var ormList []*BaseFromRzdDataOrm
|
|
|
+ items = make([]*BaseFromRzdData, 0)
|
|
|
+
|
|
|
o := orm.NewOrmUsingDB("data")
|
|
|
|
|
|
// 构造 SQL 查询
|
|
@@ -107,9 +162,12 @@ func GetRzdLastUpdateTimeLastByIndexCode(indexCodes []string) (items []*BaseFrom
|
|
|
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)
|
|
|
+ _, err = o.Raw(sql, indexCodes).QueryRows(&ormList)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
+ for _, ormItem := range ormList {
|
|
|
+ items = append(items, ormItem.ToItem())
|
|
|
+ }
|
|
|
return items, nil
|
|
|
}
|