predict_edb_conf.go 8.0 KB

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