|
@@ -8,14 +8,14 @@ import (
|
|
|
)
|
|
|
|
|
|
type BaseFromSciHqIndex struct {
|
|
|
- BaseFromSciHqIndexId int `orm:"column(base_from_sci_index_id);pk;auto"`
|
|
|
+ BaseFromSciHqIndexId int `orm:"column(base_from_sci_hq_index_id);pk;auto"`
|
|
|
ClassifyId int `description:"指标分类id"`
|
|
|
IndexCode string `description:"指标编码"`
|
|
|
IndexName string `description:"指标名称"`
|
|
|
Unit string `description:"单位"`
|
|
|
Frequency string `description:"频度"`
|
|
|
- StartDate string `description:"开始日期"`
|
|
|
- EndDate string `description:"结束日期"`
|
|
|
+ StartDate time.Time `description:"开始日期"`
|
|
|
+ EndDate time.Time `description:"结束日期"`
|
|
|
Sort int `description:"排序"`
|
|
|
LatestValue float64 `description:"最新值"`
|
|
|
LatestDate time.Time `description:"最后更新时间"`
|
|
@@ -25,6 +25,44 @@ type BaseFromSciHqIndex struct {
|
|
|
ModifyTime time.Time
|
|
|
}
|
|
|
|
|
|
+func (m *BaseFromSciHqIndex) ToView() (item *BaseFromSciHqIndexView) {
|
|
|
+ return &BaseFromSciHqIndexView{
|
|
|
+ BaseFromSciHqIndexId: m.BaseFromSciHqIndexId,
|
|
|
+ //EdbInfoId: 0,
|
|
|
+ //ClassifyId: 0,
|
|
|
+ IndexCode: m.IndexCode,
|
|
|
+ IndexName: m.IndexName,
|
|
|
+ //UniqueCode: "",
|
|
|
+ Frequency: m.Frequency,
|
|
|
+ Unit: m.Unit,
|
|
|
+ StartDate: m.StartDate.Format(utils.FormatDate),
|
|
|
+ EndDate: m.EndDate.Format(utils.FormatDate),
|
|
|
+ Sort: m.Sort,
|
|
|
+ LatestValue: m.LatestValue,
|
|
|
+ LatestDate: m.LatestDate.Format(utils.FormatDate),
|
|
|
+ EdbExist: 0,
|
|
|
+ ModifyTime: m.ModifyTime.Format(utils.FormatDateTime),
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+type BaseFromSciHqIndexViewOrm struct {
|
|
|
+ BaseFromSciHqIndexId int `orm:"pk"`
|
|
|
+ EdbInfoId int `description:"指标库id"`
|
|
|
+ ClassifyId int `description:"指标分类id"`
|
|
|
+ IndexCode string `description:"指标编码"`
|
|
|
+ IndexName string `description:"指标名称"`
|
|
|
+ UniqueCode string `description:"唯一code"`
|
|
|
+ Frequency string `description:"频度"`
|
|
|
+ Unit string `description:"单位"`
|
|
|
+ StartDate time.Time `description:"开始日期"`
|
|
|
+ EndDate time.Time `description:"结束日期"`
|
|
|
+ Sort int `description:"排序"`
|
|
|
+ LatestValue float64 `description:"最新值"`
|
|
|
+ LatestDate time.Time `description:"最后更新时间"`
|
|
|
+ EdbExist int `description:"edb是否存在"`
|
|
|
+ ModifyTime time.Time
|
|
|
+}
|
|
|
+
|
|
|
type BaseFromSciHqIndexView struct {
|
|
|
BaseFromSciHqIndexId int `orm:"pk"`
|
|
|
EdbInfoId int `description:"指标库id"`
|
|
@@ -43,6 +81,26 @@ type BaseFromSciHqIndexView struct {
|
|
|
ModifyTime string
|
|
|
}
|
|
|
|
|
|
+func (m *BaseFromSciHqIndexViewOrm) ToView() (item *BaseFromSciHqIndexView) {
|
|
|
+ return &BaseFromSciHqIndexView{
|
|
|
+ BaseFromSciHqIndexId: m.BaseFromSciHqIndexId,
|
|
|
+ EdbInfoId: m.EdbInfoId,
|
|
|
+ ClassifyId: m.ClassifyId,
|
|
|
+ IndexCode: m.IndexCode,
|
|
|
+ IndexName: m.IndexName,
|
|
|
+ UniqueCode: m.UniqueCode,
|
|
|
+ Frequency: m.Frequency,
|
|
|
+ Unit: m.Unit,
|
|
|
+ StartDate: m.StartDate.Format(utils.FormatDate),
|
|
|
+ EndDate: m.EndDate.Format(utils.FormatDate),
|
|
|
+ Sort: m.Sort,
|
|
|
+ LatestValue: m.LatestValue,
|
|
|
+ LatestDate: m.LatestDate.Format(utils.FormatDate),
|
|
|
+ EdbExist: m.EdbExist,
|
|
|
+ ModifyTime: m.ModifyTime.Format(utils.FormatDateTime),
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
func (b *BaseFromSciHqIndex) Update(cols []string) (err error) {
|
|
|
o := orm.NewOrmUsingDB("data")
|
|
|
_, err = o.Update(b, cols...)
|
|
@@ -90,6 +148,9 @@ func GetSciHqIndexCountByCondition(condition string, pars []interface{}) (count
|
|
|
|
|
|
// GetSciHqIndexAndEdbInfoByCondition 根据条件获取卓创红期index和指标库的信息
|
|
|
func GetSciHqIndexAndEdbInfoByCondition(condition string, pars []interface{}) (items []*BaseFromSciHqIndexView, err error) {
|
|
|
+ var ormList []*BaseFromSciHqIndexViewOrm
|
|
|
+ items = make([]*BaseFromSciHqIndexView, 0)
|
|
|
+
|
|
|
o := orm.NewOrmUsingDB("data")
|
|
|
sql := ` SELECT b.*, e.edb_info_id FROM base_from_sci_hq_index AS b LEFT JOIN edb_info AS e ON b.index_code=e.edb_code AND e.source=? WHERE 1=1 `
|
|
|
|
|
@@ -97,7 +158,14 @@ func GetSciHqIndexAndEdbInfoByCondition(condition string, pars []interface{}) (i
|
|
|
sql += condition
|
|
|
}
|
|
|
sql += ` ORDER BY sort ASC `
|
|
|
- _, err = o.Raw(sql, utils.DATA_SOURCE_SCI_HQ, pars).QueryRows(&items)
|
|
|
+ _, err = o.Raw(sql, utils.DATA_SOURCE_SCI_HQ, pars).QueryRows(&ormList)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, ormItem := range ormList {
|
|
|
+ items = append(items, ormItem.ToView())
|
|
|
+ }
|
|
|
+
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -142,13 +210,23 @@ func GetSciHqIndexCountByClassifyIds(classifyIds []int) (count int, err error) {
|
|
|
|
|
|
// GetSciHqIndexByClassifyId 根据分类id获取卓创红期指标列表
|
|
|
func GetSciHqIndexByClassifyId(classifyIds []int, startSize, pageSize int) (items []*BaseFromSciHqIndexView, err error) {
|
|
|
+ var ormList []*BaseFromSciHqIndexViewOrm
|
|
|
+ items = make([]*BaseFromSciHqIndexView, 0)
|
|
|
+
|
|
|
o := orm.NewOrmUsingDB("data")
|
|
|
sql := ` SELECT b.*, e.edb_info_id,
|
|
|
CASE WHEN e.edb_info_id IS NULL THEN 0 ELSE 1 END AS edb_exist
|
|
|
FROM base_from_sci_hq_index AS b
|
|
|
LEFT JOIN edb_info AS e ON b.index_code=e.edb_code AND e.source=88
|
|
|
WHERE b.classify_id IN (` + utils.GetOrmInReplace(len(classifyIds)) + `) ORDER BY b.sort ASC LIMIT ?,? `
|
|
|
- _, err = o.Raw(sql, classifyIds, startSize, pageSize).QueryRows(&items)
|
|
|
+ _, err = o.Raw(sql, classifyIds, startSize, pageSize).QueryRows(&ormList)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, ormItem := range ormList {
|
|
|
+ items = append(items, ormItem.ToView())
|
|
|
+ }
|
|
|
+
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -172,21 +250,41 @@ func GetSciHqIndexCount() (count int, err error) {
|
|
|
}
|
|
|
|
|
|
func GetSciHqIndexByPage(startSize, pageSize int) (items []*BaseFromSciHqIndexView, err error) {
|
|
|
+ var ormList []*BaseFromSciHqIndexViewOrm
|
|
|
+ items = make([]*BaseFromSciHqIndexView, 0)
|
|
|
+
|
|
|
o := orm.NewOrmUsingDB("data")
|
|
|
sql := ` SELECT b.*, e.edb_info_id,
|
|
|
CASE WHEN e.edb_info_id IS NULL THEN 0 ELSE 1 END AS edb_exist
|
|
|
FROM base_from_sci_hq_index AS b
|
|
|
LEFT JOIN edb_info AS e ON b.index_code=e.edb_code AND e.source=88
|
|
|
ORDER BY b.modify_time DESC LIMIT ?,?`
|
|
|
- _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
|
|
|
+ _, err = o.Raw(sql, startSize, pageSize).QueryRows(&ormList)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, ormItem := range ormList {
|
|
|
+ items = append(items, ormItem.ToView())
|
|
|
+ }
|
|
|
+
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// GetSciHqIndexBaseInfoByClassifyId 根据分类id获取卓创红期指标列表
|
|
|
func GetSciHqIndexBaseInfoByClassifyId(classifyId int) (items []*BaseFromSciHqIndexView, err error) {
|
|
|
+ var ormList []*BaseFromSciHqIndexViewOrm
|
|
|
+ items = make([]*BaseFromSciHqIndexView, 0)
|
|
|
+
|
|
|
o := orm.NewOrmUsingDB("data")
|
|
|
sql := ` SELECT base_from_sci_hq_index_id, classify_id, index_code, index_name, CONCAT(classify_id, '_', base_from_sci_hq_index_id) AS unique_code FROM base_from_sci_hq_index WHERE classify_id = ? ORDER BY sort ASC `
|
|
|
_, err = o.Raw(sql, classifyId).QueryRows(&items)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, ormItem := range ormList {
|
|
|
+ items = append(items, ormItem.ToView())
|
|
|
+ }
|
|
|
+
|
|
|
return
|
|
|
}
|
|
|
|