edb_info_calculate_mapping.go 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. package models
  2. import (
  3. "eta_gn/eta_index_lib/utils"
  4. "github.com/beego/beego/v2/client/orm"
  5. "time"
  6. )
  7. // EdbInfoCalculateMapping 计算指标于基础指标,关系表
  8. type EdbInfoCalculateMapping struct {
  9. EdbInfoCalculateMappingId int `orm:"column(edb_info_calculate_mapping_id);pk"`
  10. EdbInfoId int `description:"计算指标id"`
  11. Source int `description:"计算指标来源"`
  12. SourceName string `description:"计算指标来源名称"`
  13. EdbCode string `description:"计算指标编码"`
  14. FromEdbInfoId int `description:"基础指标id"`
  15. FromEdbCode string `description:"基础指标编码"`
  16. FromEdbName string `description:"基础指标名称"`
  17. FromSource int `description:"基础指标来源"`
  18. FromSourceName string `description:"基础指标来源名称"`
  19. MoveValue int `description:"移动的值,小于0是提前,0是不变,大于0是滞后"`
  20. Sort int `description:"计算指标名称排序"`
  21. CreateTime time.Time `description:"创建时间"`
  22. ModifyTime time.Time `description:"修改时间"`
  23. FromTag string `description:"来源指标标签"`
  24. FromSubSource int `description:"渠道子数据库来源"`
  25. }
  26. // EdbInfoCalculateMappingInfo
  27. // @Description: 计算指标与基础指标关系表
  28. type EdbInfoCalculateMappingInfo struct {
  29. EdbInfoCalculateMappingId int `orm:"column(edb_info_calculate_mapping_id);pk"`
  30. EdbInfoId int `description:"计算指标id"`
  31. Source int `description:"计算指标来源"`
  32. SourceName string `description:"计算指标来源名称"`
  33. EdbCode string `description:"计算指标编码"`
  34. FromEdbInfoId int `description:"基础指标id"`
  35. FromEdbCode string `description:"基础指标编码"`
  36. FromEdbName string `description:"基础指标名称"`
  37. FromSource int `description:"基础指标来源"`
  38. FromSourceName string `description:"基础指标来源名称"`
  39. MoveValue int `description:"领先值"`
  40. FromTag string `description:"来源指标标签"`
  41. Sort int `description:"计算指标名称排序"`
  42. CreateTime time.Time `description:"创建时间"`
  43. ModifyTime time.Time `description:"修改时间"`
  44. FromEdbType int `description:"来源指标类型:1:基础指标,2:计算指标"`
  45. FromEdbInfoType int `description:"来源指标类型: 0-基础指标; 1-预测指标"`
  46. FromClassifyId int `description:"来源指标分类ID"`
  47. FromUniqueCode string `description:"来源指标唯一编码"`
  48. NoUpdate int8 `description:"是否停止更新,0:继续更新;1:停止更新"`
  49. }
  50. // AddEdbInfoCalculateMappingMulti 批量添加指标关系表
  51. func AddEdbInfoCalculateMappingMulti(items []*EdbInfoCalculateMapping) (err error) {
  52. o := orm.NewOrm()
  53. _, err = o.InsertMulti(len(items), items)
  54. return
  55. }
  56. // AddEdbInfoCalculateMappingMulti 批量添加指标关系表
  57. func (e *EdbInfoCalculateMapping) Add() (err error) {
  58. o := orm.NewOrm()
  59. _, err = o.Insert(e)
  60. return
  61. }
  62. // EdbInfoCalculateMappingView
  63. type EdbInfoCalculateMappingView struct {
  64. EdbInfoCalculateMappingId int `orm:"column(edb_info_calculate_mapping_id);pk"`
  65. EdbInfoId int `description:"计算指标id"`
  66. Source int `description:"计算指标来源"`
  67. SourceName string `description:"计算指标来源名称"`
  68. EdbCode string `description:"计算指标编码"`
  69. FromEdbInfoId int `description:"基础指标id"`
  70. FromEdbCode string `description:"基础指标编码"`
  71. FromEdbName string `description:"基础指标名称"`
  72. FromSource int `description:"基础指标来源"`
  73. FromSourceName string `description:"基础指标来源名称"`
  74. FromTag string `description:"来源指标标签"`
  75. Sort int `description:"计算指标名称排序"`
  76. CreateTime time.Time `description:"创建时间"`
  77. ModifyTime time.Time `description:"修改时间"`
  78. StartDate string `description:"开始日期"`
  79. EndDate string `description:"结束日期"`
  80. CalculateFormula string `description:"N值"`
  81. MoveType int `description:"移动方式:1:领先(默认),2:滞后"`
  82. MoveFrequency string `description:"移动频度"`
  83. }
  84. // GetEdbInfoCalculateMappingDetail 获取单条关联指标
  85. func GetEdbInfoCalculateMappingDetail(edbInfoId int) (item *EdbInfoCalculateMappingView, err error) {
  86. o := orm.NewOrm()
  87. sql := ` SELECT a.*,b.start_date,b.end_date,b.calculate_formula,b.move_type,b.move_frequency FROM edb_info_calculate_mapping AS a
  88. INNER JOIN edb_info AS b ON a.edb_info_id=b.edb_info_id
  89. WHERE a.edb_info_id=? `
  90. err = o.Raw(sql, edbInfoId).QueryRow(&item)
  91. return
  92. }
  93. // GetEdbInfoCalculateMappingDetailByFromTag 获取单条关联指标
  94. func GetEdbInfoCalculateMappingDetailByFromTag(edbInfoId int, fromTag string) (item *EdbInfoCalculateMappingView, err error) {
  95. o := orm.NewOrm()
  96. sql := ` SELECT a.*,b.start_date,b.end_date,b.calculate_formula,b.move_type,b.move_frequency FROM edb_info_calculate_mapping AS a
  97. INNER JOIN edb_info AS b ON a.edb_info_id=b.edb_info_id
  98. WHERE a.edb_info_id=? and a.from_tag=? `
  99. err = o.Raw(sql, edbInfoId, fromTag).QueryRow(&item)
  100. return
  101. }
  102. // EdbInfoCalculateDetail
  103. type EdbInfoCalculateDetail struct {
  104. EdbInfoCalculateId int `orm:"column(edb_info_calculate_id);pk"`
  105. EdbInfoId int `description:"指标id"`
  106. EdbCode string `description:"指标编码"`
  107. FromEdbInfoId int `description:"计算指标id"`
  108. FromEdbCode string `description:"计算指标编码"`
  109. FromEdbName string `description:"计算指标名称"`
  110. FromSource int `description:"计算指标来源"`
  111. FromSourceName string `description:"计算指标来源名称"`
  112. FromTag string `description:"来源指标标签"`
  113. Sort int `description:"计算指标名称排序"`
  114. CreateTime time.Time `description:"创建时间"`
  115. ModifyTime time.Time `description:"修改时间"`
  116. StartDate string `description:"开始日期"`
  117. EndDate string `description:"结束日期"`
  118. EdbType int `description:"指标类型:1:基础指标,2:计算指标"`
  119. }
  120. // GetEdbInfoCalculateDetailList 获取关联指标列表
  121. func GetEdbInfoCalculateDetailList(edbInfoId int) (list []*EdbInfoCalculateDetail, err error) {
  122. o := orm.NewOrm()
  123. sql := ` SELECT a.*,b.start_date,b.end_date,b.edb_type FROM edb_info_calculate_mapping AS a
  124. INNER JOIN edb_info AS b ON a.from_edb_info_id=b.edb_info_id
  125. WHERE a.edb_info_id=? ORDER BY sort ASC `
  126. _, err = o.Raw(sql, edbInfoId).QueryRows(&list)
  127. return
  128. }
  129. // GetEdbInfoByEdbCode 根据指标code获取指标信息
  130. func GetEdbInfoCalculateByEdbCode(edbCode, fromEdbCode string) (item *EdbInfoCalculateMapping, err error) {
  131. o := orm.NewOrm()
  132. sql := ` SELECT * FROM edb_info_calculate_mapping WHERE edb_code=? AND from_edb_code=? `
  133. err = o.Raw(sql, edbCode, fromEdbCode).QueryRow(&item)
  134. return
  135. }
  136. // GetEdbInfoCalculateMappingListByEdbInfoIds 根据生成的指标id获取来源的指标id列表
  137. func GetEdbInfoCalculateMappingListByEdbInfoIds(edbInfoIds []int) (items []*EdbInfoCalculateMappingInfo, err error) {
  138. o := orm.NewOrm()
  139. sql := ` SELECT a.*,b.edb_type as from_edb_type,b.edb_info_type as from_edb_info_type, b.unique_code AS from_unique_code, b.classify_id AS from_classify_id,b.no_update FROM edb_info_calculate_mapping AS a
  140. INNER JOIN edb_info AS b ON a.from_edb_info_id=b.edb_info_id
  141. WHERE a.edb_info_id in (` + utils.GetOrmInReplace(len(edbInfoIds)) + `) `
  142. _, err = o.Raw(sql, edbInfoIds).QueryRows(&items)
  143. return
  144. }
  145. // GetEdbInfoCalculateMappingListByEdbInfoId 根据生成的指标id获取来源的指标id列表
  146. func GetEdbInfoCalculateMappingListByEdbInfoId(edbInfoId int) (items []*EdbInfoCalculateMappingInfo, err error) {
  147. o := orm.NewOrm()
  148. sql := ` SELECT a.*,b.edb_type as from_edb_type,b.edb_info_type as from_edb_info_type, b.unique_code AS from_unique_code, b.classify_id AS from_classify_id,b.no_update FROM edb_info_calculate_mapping AS a
  149. INNER JOIN edb_info AS b ON a.from_edb_info_id=b.edb_info_id
  150. WHERE a.edb_info_id=? `
  151. _, err = o.Raw(sql, edbInfoId).QueryRows(&items)
  152. return
  153. }