|
@@ -1,6 +1,7 @@
|
|
|
package future_good
|
|
|
|
|
|
import (
|
|
|
+ "eta/eta_api/utils"
|
|
|
"github.com/beego/beego/v2/client/orm"
|
|
|
"time"
|
|
|
)
|
|
@@ -19,8 +20,8 @@ type FutureGoodEdbInfo struct {
|
|
|
DateSourceId int `description:"画图时,日期来源的指标id"`
|
|
|
Year int `description:"所属年份"`
|
|
|
Month int `description:"所属月份"`
|
|
|
- StartDate string `description:"起始日期"`
|
|
|
- EndDate string `description:"终止日期"`
|
|
|
+ StartDate time.Time `description:"起始日期"`
|
|
|
+ EndDate time.Time `description:"终止日期"`
|
|
|
MinValue float64 `description:"最小值"`
|
|
|
MaxValue float64 `description:"最大值"`
|
|
|
LatestValue float64 `description:"数据最新的值"`
|
|
@@ -30,57 +31,156 @@ type FutureGoodEdbInfo struct {
|
|
|
ModifyTime time.Time
|
|
|
}
|
|
|
|
|
|
+// FutureGoodEdbInfoView 显示返回
|
|
|
+type FutureGoodEdbInfoView struct {
|
|
|
+ FutureGoodEdbInfoId int `orm:"column(future_good_edb_info_id);pk;auto"`
|
|
|
+ FutureGoodEdbCode string `description:"期货指标code"`
|
|
|
+ FutureGoodEdbName string `description:"期货指标名称"`
|
|
|
+ FutureGoodEdbNameEn string `description:"期货指标英文名称"`
|
|
|
+ ParentId int `description:"上级期货id"`
|
|
|
+ RegionType string `description:"交易所来源,海外还是国内"`
|
|
|
+ Exchange string `description:"所属交易所"`
|
|
|
+ ExchangeEn string `description:"所属交易所(英文名称)"`
|
|
|
+ FutureGoodEdbType int `description:"指标类型,1:年月是固定的合约;2:只有M+N期的合约,未固定年月"`
|
|
|
+ DateSourceId int `description:"画图时,日期来源的指标id"`
|
|
|
+ Year int `description:"所属年份"`
|
|
|
+ Month int `description:"所属月份"`
|
|
|
+ StartDate string `description:"起始日期"`
|
|
|
+ EndDate string `description:"终止日期"`
|
|
|
+ MinValue float64 `description:"最小值"`
|
|
|
+ MaxValue float64 `description:"最大值"`
|
|
|
+ LatestValue float64 `description:"数据最新的值"`
|
|
|
+ LatestDate string `description:"数据最新的日期"`
|
|
|
+ ServerUrl string `description:"服务器地址"`
|
|
|
+ CreateTime string
|
|
|
+ ModifyTime string
|
|
|
+}
|
|
|
+
|
|
|
+func (m *FutureGoodEdbInfo) ToView() *FutureGoodEdbInfoView {
|
|
|
+ return &FutureGoodEdbInfoView{
|
|
|
+ FutureGoodEdbInfoId: m.FutureGoodEdbInfoId,
|
|
|
+ FutureGoodEdbCode: m.FutureGoodEdbCode,
|
|
|
+ FutureGoodEdbName: m.FutureGoodEdbName,
|
|
|
+ FutureGoodEdbNameEn: m.FutureGoodEdbNameEn,
|
|
|
+ ParentId: m.ParentId,
|
|
|
+ RegionType: m.RegionType,
|
|
|
+ Exchange: m.Exchange,
|
|
|
+ ExchangeEn: m.ExchangeEn,
|
|
|
+ FutureGoodEdbType: m.FutureGoodEdbType,
|
|
|
+ DateSourceId: m.DateSourceId,
|
|
|
+ Year: m.Year,
|
|
|
+ Month: m.Month,
|
|
|
+ StartDate: m.StartDate.Format(utils.FormatDate),
|
|
|
+ EndDate: m.EndDate.Format(utils.FormatDate),
|
|
|
+ MinValue: m.MinValue,
|
|
|
+ MaxValue: m.MaxValue,
|
|
|
+ LatestValue: m.LatestValue,
|
|
|
+ LatestDate: m.LatestDate.Format(utils.FormatDate),
|
|
|
+ ServerUrl: m.ServerUrl,
|
|
|
+ CreateTime: m.CreateTime.Format(utils.FormatDateTime),
|
|
|
+ ModifyTime: m.ModifyTime.Format(utils.FormatDateTime),
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
// GetFutureGoodEdbInfo 期货指标
|
|
|
-func GetFutureGoodEdbInfo(edbInfoId int) (item *FutureGoodEdbInfo, err error) {
|
|
|
+func GetFutureGoodEdbInfo(edbInfoId int) (item *FutureGoodEdbInfoView, err error) {
|
|
|
+ var itemOrm *FutureGoodEdbInfo
|
|
|
o := orm.NewOrmUsingDB("data")
|
|
|
sql := `SELECT * FROM future_good_edb_info WHERE future_good_edb_info_id = ? `
|
|
|
sql += ` ORDER BY future_good_edb_info_id DESC `
|
|
|
- err = o.Raw(sql, edbInfoId).QueryRow(&item)
|
|
|
+ err = o.Raw(sql, edbInfoId).QueryRow(&itemOrm)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ item = itemOrm.ToView()
|
|
|
+
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// GetFutureGoodEdbInfoByCode 根据期货code获取 期货指标信息
|
|
|
-func GetFutureGoodEdbInfoByCode(futureGoodEdbCode string) (item *FutureGoodEdbInfo, err error) {
|
|
|
+func GetFutureGoodEdbInfoByCode(futureGoodEdbCode string) (item *FutureGoodEdbInfoView, err error) {
|
|
|
+ var itemOrm *FutureGoodEdbInfo
|
|
|
o := orm.NewOrmUsingDB("data")
|
|
|
sql := `SELECT * FROM future_good_edb_info WHERE future_good_edb_code = ? `
|
|
|
sql += ` ORDER BY future_good_edb_info_id DESC `
|
|
|
- err = o.Raw(sql, futureGoodEdbCode).QueryRow(&item)
|
|
|
+ err = o.Raw(sql, futureGoodEdbCode).QueryRow(&itemOrm)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ item = itemOrm.ToView()
|
|
|
+
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// GetFutureGoodEdbInfoList 获取指标数据列表
|
|
|
-func GetFutureGoodEdbInfoList(condition string, pars []interface{}) (list []*FutureGoodEdbInfo, err error) {
|
|
|
+func GetFutureGoodEdbInfoList(condition string, pars []interface{}) (items []*FutureGoodEdbInfoView, err error) {
|
|
|
+ var ormList []*FutureGoodEdbInfo
|
|
|
+ items = make([]*FutureGoodEdbInfoView, 0)
|
|
|
o := orm.NewOrmUsingDB("data")
|
|
|
sql := `SELECT * FROM future_good_edb_info WHERE 1=1 `
|
|
|
if condition != "" {
|
|
|
sql += condition
|
|
|
}
|
|
|
sql += ` ORDER BY future_good_edb_info_id DESC `
|
|
|
- _, err = o.Raw(sql, pars).QueryRows(&list)
|
|
|
+ _, err = o.Raw(sql, pars).QueryRows(&ormList)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, ormItem := range ormList {
|
|
|
+ items = append(items, ormItem.ToView())
|
|
|
+ }
|
|
|
+
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// GetAllFutureGoodEdbInfoList 获取指标数据列表
|
|
|
-func GetAllFutureGoodEdbInfoList() (list []*FutureGoodEdbInfo, err error) {
|
|
|
+func GetAllFutureGoodEdbInfoList() (items []*FutureGoodEdbInfoView, err error) {
|
|
|
+ var ormList []*FutureGoodEdbInfo
|
|
|
+ items = make([]*FutureGoodEdbInfoView, 0)
|
|
|
o := orm.NewOrmUsingDB("data")
|
|
|
sql := `SELECT * FROM future_good_edb_info ORDER BY future_good_edb_info_id DESC `
|
|
|
- _, err = o.Raw(sql).QueryRows(&list)
|
|
|
+ _, err = o.Raw(sql).QueryRows(&ormList)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, ormItem := range ormList {
|
|
|
+ items = append(items, ormItem.ToView())
|
|
|
+ }
|
|
|
+
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// GetFutureGoodEdbInfoListByParentId 根据父级ID获取指标数据列表
|
|
|
-func GetFutureGoodEdbInfoListByParentId(parentId int) (list []*FutureGoodEdbInfo, err error) {
|
|
|
+func GetFutureGoodEdbInfoListByParentId(parentId int) (items []*FutureGoodEdbInfoView, err error) {
|
|
|
+ var ormList []*FutureGoodEdbInfo
|
|
|
+ items = make([]*FutureGoodEdbInfoView, 0)
|
|
|
o := orm.NewOrmUsingDB("data")
|
|
|
sql := `SELECT * FROM future_good_edb_info WHERE parent_id = ? or future_good_edb_info_id = ? ORDER BY future_good_edb_info_id ASC `
|
|
|
- _, err = o.Raw(sql, parentId, parentId).QueryRows(&list)
|
|
|
+ _, err = o.Raw(sql, parentId, parentId).QueryRows(&ormList)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, ormItem := range ormList {
|
|
|
+ items = append(items, ormItem.ToView())
|
|
|
+ }
|
|
|
+
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// GetChildFutureGoodEdbInfoListByParentId 根据父级ID获取下面所有的指标数据列表
|
|
|
-func GetChildFutureGoodEdbInfoListByParentId(parentId int) (list []*FutureGoodEdbInfo, err error) {
|
|
|
+func GetChildFutureGoodEdbInfoListByParentId(parentId int) (items []*FutureGoodEdbInfoView, err error) {
|
|
|
+ var ormList []*FutureGoodEdbInfo
|
|
|
+ items = make([]*FutureGoodEdbInfoView, 0)
|
|
|
o := orm.NewOrmUsingDB("data")
|
|
|
sql := `SELECT * FROM future_good_edb_info WHERE parent_id = ? ORDER BY future_good_edb_info_id ASC `
|
|
|
- _, err = o.Raw(sql, parentId).QueryRows(&list)
|
|
|
+ _, err = o.Raw(sql, parentId).QueryRows(&ormList)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, ormItem := range ormList {
|
|
|
+ items = append(items, ormItem.ToView())
|
|
|
+ }
|
|
|
+
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -96,9 +196,9 @@ func AddFutureGoodEdbInfo(item *FutureGoodEdbInfo) (err error) {
|
|
|
}
|
|
|
|
|
|
// Update 更新指标基础信息
|
|
|
-func (FutureGoodEdbInfo *FutureGoodEdbInfo) Update(cols []string) (err error) {
|
|
|
+func (m *FutureGoodEdbInfo) Update(cols []string) (err error) {
|
|
|
o := orm.NewOrmUsingDB("data")
|
|
|
- _, err = o.Update(FutureGoodEdbInfo, cols...)
|
|
|
+ _, err = o.Update(m, cols...)
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -111,14 +211,24 @@ type FutureGoodEdbInfoGroupListResp struct {
|
|
|
}
|
|
|
|
|
|
// GetFutureGoodEdbInfoGroupList 获取分組指标数据列表
|
|
|
-func GetFutureGoodEdbInfoGroupList(condition string, pars []interface{}) (list []*FutureGoodEdbInfo, err error) {
|
|
|
+func GetFutureGoodEdbInfoGroupList(condition string, pars []interface{}) (items []*FutureGoodEdbInfoView, err error) {
|
|
|
+ var ormList []*FutureGoodEdbInfo
|
|
|
+ items = make([]*FutureGoodEdbInfoView, 0)
|
|
|
+
|
|
|
o := orm.NewOrmUsingDB("data")
|
|
|
sql := `SELECT * FROM future_good_edb_info WHERE 1=1 `
|
|
|
if condition != "" {
|
|
|
sql += condition
|
|
|
}
|
|
|
sql += ` ORDER BY future_good_edb_info_id DESC `
|
|
|
- _, err = o.Raw(sql, pars).QueryRows(&list)
|
|
|
+ _, err = o.Raw(sql, pars).QueryRows(&ormList)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, ormItem := range ormList {
|
|
|
+ items = append(items, ormItem.ToView())
|
|
|
+ }
|
|
|
+
|
|
|
return
|
|
|
}
|
|
|
|