123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- package models
- import (
- "eta/eta_index_lib/utils"
- "github.com/beego/beego/v2/client/orm"
- "time"
- )
- // AddPredictEdbInfoReq 添加预测指标请求
- type AddPredictEdbInfoReq struct {
- EdbInfoId int `description:"指标ID"`
- ClassifyId int `description:"分类id"`
- AdminId int `description:"添加人id"`
- AdminName string `description:"添加人名称"`
- SourceEdbInfoId int `description:"来源指标id"`
- EdbName string `description:"指标名称"`
- RuleList []RuleConfig `description:"配置规则列表"`
- MaxValue float64 `description:"最大值"`
- MinValue float64 `description:"最小值"`
- DataDateType string `description:"日期类型,枚举值:交易日、自然日"`
- EndDateType int `description:"截止日期类型:0:未来日期,1未来期数"`
- }
- // RuleConfig 预测规则配置
- type RuleConfig struct {
- RuleType int `description:"预测规则,1:最新,2:固定值,3:同比,4:同差,5:环比,6:环差,7:N期移动均值,8:N期段线性外推值,9:动态环差"`
- Value string `description:"值/计算公式"`
- EmptyType int `description:"空值处理类型(0查找前后35天,1不计算,2前值填充,3后值填充,4等于0)"`
- MaxEmptyType int `description:"MAX、MIN公式空值处理类型(1、等于0;2、跳过空值)"`
- EndDate string `description:"截止日期"`
- EndNum int `description:"截止期数"`
- EdbInfoIdArr []EdbInfoFromTag `description:"指标信息"`
- }
- // EditPredictEdbInfoReq 编辑预测指标请求
- type EditPredictEdbInfoReq struct {
- EdbInfoId int `description:"指标ID"`
- ClassifyId int `description:"分类id"`
- EdbName string `description:"指标名称"`
- RuleList []RuleConfig `description:"配置规则列表"`
- }
- type PredictEdbConf struct {
- ConfigId int `orm:"column(config_id);pk" description:"规则id"`
- PredictEdbInfoId int `orm:"column(predict_edb_info_id)" description:"预测指标id"`
- SourceEdbInfoId int `description:"来源指标id"`
- RuleType int `description:"预测规则,1:最新,2:固定值,3:同比,4:同差,5:环比,6:环差,7:N期移动均值,8:N期段线性外推值"`
- FixedValue float64 `description:"固定值"`
- Value string `description:"配置的值"`
- EmptyType int `description:"空值处理类型(0查找前后35天,1不计算,2前值填充,3后值填充,4等于0)"`
- MaxEmptyType int `description:"MAX、MIN公式空值处理类型(1、等于0;2、跳过空值)"`
- EndDate time.Time `description:"截止日期"`
- EndNum int `description:"截止期数"`
- ModifyTime time.Time `description:"修改时间"`
- CreateTime time.Time `description:"添加时间"`
- }
- // PredictEdbConfAndData 预测规则和其对应的动态数据
- type PredictEdbConfAndData struct {
- ConfigId int `orm:"column(config_id);pk" description:"规则id"`
- PredictEdbInfoId int `orm:"column(predict_edb_info_id)" description:"预测指标id"`
- SourceEdbInfoId int `description:"来源指标id"`
- RuleType int `description:"预测规则,1:最新,2:固定值,3:同比,4:同差,5:环比,6:环差,7:N期移动均值,8:N期段线性外推值,9:动态环差"`
- FixedValue float64 `description:"固定值"`
- Value string `description:"配置的值"`
- EmptyType int `description:"空值处理类型(0查找前后35天,1不计算,2前值填充,3后值填充,4等于0)"`
- MaxEmptyType int `description:"MAX、MIN公式空值处理类型(1、等于0;2、跳过空值)"`
- EndDate time.Time `description:"截止日期"`
- EndNum int `description:"截止期数"`
- ModifyTime time.Time `description:"修改时间"`
- CreateTime time.Time `description:"添加时间"`
- DataList []*EdbInfoSearchData `description:"动态数据"`
- }
- // GetPredictEdbConfById 根据预测指标id获取预测指标配置信息
- func GetPredictEdbConfById(edbInfoId int) (item *PredictEdbConf, err error) {
- o := orm.NewOrm()
- sql := ` SELECT * FROM predict_edb_conf WHERE predict_edb_info_id=? `
- err = o.Raw(sql, edbInfoId).QueryRow(&item)
- return
- }
- // GetPredictEdbConfCount 根据来源指标id获取被引用的次数
- func GetPredictEdbConfCount(sourceEdbInfoId int) (count int, err error) {
- o := orm.NewOrm()
- sql := ` SELECT COUNT(1) AS count FROM predict_edb_conf WHERE source_edb_info_id=? `
- err = o.Raw(sql, sourceEdbInfoId).QueryRow(&count)
- return
- }
- // GetPredictEdbConfListById 根据预测指标id获取预测指标配置信息列表
- func GetPredictEdbConfListById(edbInfoId int) (items []*PredictEdbConf, err error) {
- o := orm.NewOrm()
- sql := ` SELECT * FROM predict_edb_conf WHERE predict_edb_info_id=? ORDER BY config_id ASC`
- _, err = o.Raw(sql, edbInfoId).QueryRows(&items)
- return
- }
- // GetPredictEdbConfAndDataListById 根据预测指标id获取预测指标配置信息列表
- func GetPredictEdbConfAndDataListById(edbInfoId int) (items []*PredictEdbConfAndData, err error) {
- o := orm.NewOrm()
- sql := ` SELECT * FROM predict_edb_conf WHERE predict_edb_info_id=? ORDER BY config_id ASC`
- _, err = o.Raw(sql, edbInfoId).QueryRows(&items)
- return
- }
- // GetPredictEdbConfListByConfigIdList 根据预测指标id列表获取预测指标配置信息列表
- func GetPredictEdbConfListByConfigIdList(configIdList []int) (items []*PredictEdbConf, err error) {
- num := len(configIdList)
- if num <= 0 {
- return
- }
- o := orm.NewOrm()
- sql := ` SELECT * FROM predict_edb_conf WHERE config_id in (` + utils.GetOrmInReplace(num) + `) ORDER BY config_id ASC`
- _, err = o.Raw(sql, configIdList).QueryRows(&items)
- return
- }
- // ModifyPredictEdbInfoMaxAndMinInfoBySourceEdbInfoId 根据来源指标修改预测指标的最新数据信息
- func ModifyPredictEdbInfoMaxAndMinInfoBySourceEdbInfoId(sourceEdbInfoId int, item *EdbInfoMaxAndMinInfo) (err error) {
- //return
- o := orm.NewOrm()
- var list []*PredictEdbConf
- sql := ` SELECT * FROM predict_edb_conf WHERE source_edb_info_id=? `
- total, err := o.Raw(sql, sourceEdbInfoId).QueryRows(&list)
- if err != nil {
- return
- }
- if total > 0 {
- idList := make([]int, 0)
- for _, v := range list {
- idList = append(idList, v.PredictEdbInfoId)
- }
- //sql := ` UPDATE edb_info SET start_date=?,min_value=?,max_value=?,is_update=2,latest_date=?,latest_value=?,modify_time=NOW() WHERE edb_info_id in (` + utils.GetOrmInReplace(int(total)) + `) `
- //_, err = o.Raw(sql, item.MinDate, item.MinValue, item.MaxValue, item.MaxDate, item.LatestValue, idList).Exec()
- sql := ` UPDATE edb_info SET start_date=?,is_update=2,latest_date=?,latest_value=?,end_value=?,modify_time=NOW() WHERE edb_info_id in (` + utils.GetOrmInReplace(int(total)) + `) `
- _, err = o.Raw(sql, item.MinDate, item.MaxDate, item.LatestValue, item.LatestValue, idList).Exec()
- }
- return
- }
- // GetPredictEdbConfBySourceEdbInfoId 根据来源指标id获取配置
- func GetPredictEdbConfBySourceEdbInfoId(sourceEdbInfoId int) (item *PredictEdbConf, err error) {
- o := orm.NewOrm()
- sql := ` SELECT * FROM predict_edb_conf WHERE source_edb_info_id=? `
- err = o.Raw(sql, sourceEdbInfoId).QueryRow(&item)
- return
- }
- // AddPredictEdbConf 添加预测指标规则
- func AddPredictEdbConf(item *PredictEdbConf) (lastId int64, err error) {
- o := orm.NewOrm()
- lastId, err = o.Insert(item)
- return
- }
- // GetPredictEdbInfoAllCalculate 根据基础预测指标id集合 获取 所有的普通指标列表数据
- func GetPredictEdbInfoAllCalculate(edbInfoIdList []int) (list []*EdbInfo, err error) {
- num := len(edbInfoIdList)
- if num <= 0 {
- return
- }
- o := orm.NewOrm()
- sql := ` SELECT b.* FROM predict_edb_conf AS a
- INNER JOIN edb_info AS b ON a.source_edb_info_id=b.edb_info_id
- WHERE a.predict_edb_info_id in (` + utils.GetOrmInReplace(num) + `)
- GROUP BY a.source_edb_info_id
- ORDER BY a.source_edb_info_id ASC `
- _, err = o.Raw(sql, edbInfoIdList).QueryRows(&list)
- return
- }
|