predict_edb_conf.go 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. package models
  2. import (
  3. "eta/eta_index_lib/utils"
  4. "github.com/beego/beego/v2/client/orm"
  5. "time"
  6. )
  7. // AddPredictEdbInfoReq 添加预测指标请求
  8. type AddPredictEdbInfoReq struct {
  9. EdbInfoId int `description:"指标ID"`
  10. ClassifyId int `description:"分类id"`
  11. AdminId int `description:"添加人id"`
  12. AdminName string `description:"添加人名称"`
  13. SourceEdbInfoId int `description:"来源指标id"`
  14. EdbName string `description:"指标名称"`
  15. RuleList []RuleConfig `description:"配置规则列表"`
  16. MaxValue float64 `description:"最大值"`
  17. MinValue float64 `description:"最小值"`
  18. DataDateType string `description:"日期类型,枚举值:交易日、自然日"`
  19. EndDateType int `description:"截止日期类型:0:未来日期,1未来期数"`
  20. }
  21. // RuleConfig 预测规则配置
  22. type RuleConfig struct {
  23. RuleType int `description:"预测规则,1:最新,2:固定值,3:同比,4:同差,5:环比,6:环差,7:N期移动均值,8:N期段线性外推值,9:动态环差"`
  24. Value string `description:"值/计算公式"`
  25. EmptyType int `description:"空值处理类型(0查找前后35天,1不计算,2前值填充,3后值填充,4等于0)"`
  26. MaxEmptyType int `description:"MAX、MIN公式空值处理类型(1、等于0;2、跳过空值)"`
  27. EndDate string `description:"截止日期"`
  28. EndNum int `description:"截止期数"`
  29. EdbInfoIdArr []EdbInfoFromTag `description:"指标信息"`
  30. }
  31. // EditPredictEdbInfoReq 编辑预测指标请求
  32. type EditPredictEdbInfoReq struct {
  33. EdbInfoId int `description:"指标ID"`
  34. ClassifyId int `description:"分类id"`
  35. EdbName string `description:"指标名称"`
  36. RuleList []RuleConfig `description:"配置规则列表"`
  37. }
  38. type PredictEdbConf struct {
  39. ConfigId int `orm:"column(config_id);pk" description:"规则id"`
  40. PredictEdbInfoId int `orm:"column(predict_edb_info_id)" description:"预测指标id"`
  41. SourceEdbInfoId int `description:"来源指标id"`
  42. RuleType int `description:"预测规则,1:最新,2:固定值,3:同比,4:同差,5:环比,6:环差,7:N期移动均值,8:N期段线性外推值"`
  43. FixedValue float64 `description:"固定值"`
  44. Value string `description:"配置的值"`
  45. EmptyType int `description:"空值处理类型(0查找前后35天,1不计算,2前值填充,3后值填充,4等于0)"`
  46. MaxEmptyType int `description:"MAX、MIN公式空值处理类型(1、等于0;2、跳过空值)"`
  47. EndDate time.Time `description:"截止日期"`
  48. EndNum int `description:"截止期数"`
  49. ModifyTime time.Time `description:"修改时间"`
  50. CreateTime time.Time `description:"添加时间"`
  51. }
  52. // PredictEdbConfAndData 预测规则和其对应的动态数据
  53. type PredictEdbConfAndData struct {
  54. ConfigId int `orm:"column(config_id);pk" description:"规则id"`
  55. PredictEdbInfoId int `orm:"column(predict_edb_info_id)" description:"预测指标id"`
  56. SourceEdbInfoId int `description:"来源指标id"`
  57. RuleType int `description:"预测规则,1:最新,2:固定值,3:同比,4:同差,5:环比,6:环差,7:N期移动均值,8:N期段线性外推值,9:动态环差"`
  58. FixedValue float64 `description:"固定值"`
  59. Value string `description:"配置的值"`
  60. EmptyType int `description:"空值处理类型(0查找前后35天,1不计算,2前值填充,3后值填充,4等于0)"`
  61. MaxEmptyType int `description:"MAX、MIN公式空值处理类型(1、等于0;2、跳过空值)"`
  62. EndDate time.Time `description:"截止日期"`
  63. EndNum int `description:"截止期数"`
  64. ModifyTime time.Time `description:"修改时间"`
  65. CreateTime time.Time `description:"添加时间"`
  66. DataList []*EdbInfoSearchData `description:"动态数据"`
  67. }
  68. // GetPredictEdbConfById 根据预测指标id获取预测指标配置信息
  69. func GetPredictEdbConfById(edbInfoId int) (item *PredictEdbConf, err error) {
  70. o := orm.NewOrm()
  71. sql := ` SELECT * FROM predict_edb_conf WHERE predict_edb_info_id=? `
  72. err = o.Raw(sql, edbInfoId).QueryRow(&item)
  73. return
  74. }
  75. // GetPredictEdbConfCount 根据来源指标id获取被引用的次数
  76. func GetPredictEdbConfCount(sourceEdbInfoId int) (count int, err error) {
  77. o := orm.NewOrm()
  78. sql := ` SELECT COUNT(1) AS count FROM predict_edb_conf WHERE source_edb_info_id=? `
  79. err = o.Raw(sql, sourceEdbInfoId).QueryRow(&count)
  80. return
  81. }
  82. // GetPredictEdbConfListById 根据预测指标id获取预测指标配置信息列表
  83. func GetPredictEdbConfListById(edbInfoId int) (items []*PredictEdbConf, err error) {
  84. o := orm.NewOrm()
  85. sql := ` SELECT * FROM predict_edb_conf WHERE predict_edb_info_id=? ORDER BY config_id ASC`
  86. _, err = o.Raw(sql, edbInfoId).QueryRows(&items)
  87. return
  88. }
  89. // GetPredictEdbConfAndDataListById 根据预测指标id获取预测指标配置信息列表
  90. func GetPredictEdbConfAndDataListById(edbInfoId int) (items []*PredictEdbConfAndData, err error) {
  91. o := orm.NewOrm()
  92. sql := ` SELECT * FROM predict_edb_conf WHERE predict_edb_info_id=? ORDER BY config_id ASC`
  93. _, err = o.Raw(sql, edbInfoId).QueryRows(&items)
  94. return
  95. }
  96. // GetPredictEdbConfListByConfigIdList 根据预测指标id列表获取预测指标配置信息列表
  97. func GetPredictEdbConfListByConfigIdList(configIdList []int) (items []*PredictEdbConf, err error) {
  98. num := len(configIdList)
  99. if num <= 0 {
  100. return
  101. }
  102. o := orm.NewOrm()
  103. sql := ` SELECT * FROM predict_edb_conf WHERE config_id in (` + utils.GetOrmInReplace(num) + `) ORDER BY config_id ASC`
  104. _, err = o.Raw(sql, configIdList).QueryRows(&items)
  105. return
  106. }
  107. // ModifyPredictEdbInfoMaxAndMinInfoBySourceEdbInfoId 根据来源指标修改预测指标的最新数据信息
  108. func ModifyPredictEdbInfoMaxAndMinInfoBySourceEdbInfoId(sourceEdbInfoId int, item *EdbInfoMaxAndMinInfo) (err error) {
  109. //return
  110. o := orm.NewOrm()
  111. var list []*PredictEdbConf
  112. sql := ` SELECT * FROM predict_edb_conf WHERE source_edb_info_id=? `
  113. total, err := o.Raw(sql, sourceEdbInfoId).QueryRows(&list)
  114. if err != nil {
  115. return
  116. }
  117. if total > 0 {
  118. idList := make([]int, 0)
  119. for _, v := range list {
  120. idList = append(idList, v.PredictEdbInfoId)
  121. }
  122. //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)) + `) `
  123. //_, err = o.Raw(sql, item.MinDate, item.MinValue, item.MaxValue, item.MaxDate, item.LatestValue, idList).Exec()
  124. 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)) + `) `
  125. _, err = o.Raw(sql, item.MinDate, item.MaxDate, item.LatestValue, item.LatestValue, idList).Exec()
  126. }
  127. return
  128. }
  129. // GetPredictEdbConfBySourceEdbInfoId 根据来源指标id获取配置
  130. func GetPredictEdbConfBySourceEdbInfoId(sourceEdbInfoId int) (item *PredictEdbConf, err error) {
  131. o := orm.NewOrm()
  132. sql := ` SELECT * FROM predict_edb_conf WHERE source_edb_info_id=? `
  133. err = o.Raw(sql, sourceEdbInfoId).QueryRow(&item)
  134. return
  135. }
  136. // AddPredictEdbConf 添加预测指标规则
  137. func AddPredictEdbConf(item *PredictEdbConf) (lastId int64, err error) {
  138. o := orm.NewOrm()
  139. lastId, err = o.Insert(item)
  140. return
  141. }
  142. // GetPredictEdbInfoAllCalculate 根据基础预测指标id集合 获取 所有的普通指标列表数据
  143. func GetPredictEdbInfoAllCalculate(edbInfoIdList []int) (list []*EdbInfo, err error) {
  144. num := len(edbInfoIdList)
  145. if num <= 0 {
  146. return
  147. }
  148. o := orm.NewOrm()
  149. sql := ` SELECT b.* FROM predict_edb_conf AS a
  150. INNER JOIN edb_info AS b ON a.source_edb_info_id=b.edb_info_id
  151. WHERE a.predict_edb_info_id in (` + utils.GetOrmInReplace(num) + `)
  152. GROUP BY a.source_edb_info_id
  153. ORDER BY a.source_edb_info_id ASC `
  154. _, err = o.Raw(sql, edbInfoIdList).QueryRows(&list)
  155. return
  156. }