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:"日期类型,枚举值:交易日、自然日"` } // 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:"截止日期"` 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:"截止日期"` 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:"截止日期"` 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 }