edb_info.go 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. package data_manage
  2. import (
  3. "eta_gn/eta_chart_lib/global"
  4. "eta_gn/eta_chart_lib/utils"
  5. "gorm.io/gorm"
  6. "time"
  7. )
  8. // type EdbInfo struct {
  9. // EdbInfoId int `orm:"column(edb_info_id);pk"`
  10. // EdbInfoType int `description:"指标类型,0:普通指标,1:预测指标"`
  11. // SourceName string `description:"来源名称"`
  12. // Source int `description:"来源id"`
  13. // EdbCode string `description:"指标编码"`
  14. // EdbName string `description:"指标名称"`
  15. // EdbNameEn string `description:"英文指标名称"`
  16. // EdbNameSource string `description:"指标名称来源"`
  17. // Frequency string `description:"频率"`
  18. // Unit string `description:"单位"`
  19. // UnitEn string `description:"英文单位"`
  20. // StartDate string `description:"起始日期"`
  21. // EndDate string `description:"终止日期"`
  22. // ClassifyId int `description:"分类id"`
  23. // SysUserId int
  24. // SysUserRealName string
  25. // UniqueCode string `description:"指标唯一编码"`
  26. // CreateTime time.Time
  27. // ModifyTime time.Time
  28. // MinValue float64 `description:"指标最小值"`
  29. // MaxValue float64 `description:"指标最大值"`
  30. // CalculateFormula string `description:"计算公式"`
  31. // EdbType int `description:"指标类型:1:基础指标,2:计算指标"`
  32. // Sort int `description:"排序字段"`
  33. // LatestDate string `description:"数据最新日期"`
  34. // LatestValue float64 `description:"数据最新值"`
  35. // MoveType int `description:"移动方式:1:领先(默认),2:滞后"`
  36. // MoveFrequency string `description:"移动频度"`
  37. // NoUpdate int8 `description:"是否停止更新,0:继续更新;1:停止更新"`
  38. // DataDateType string `orm:"column(data_date_type);size(255);null;default(交易日)"`
  39. // SubSource int `description:"子数据来源:0:经济数据库,1:日期序列"`
  40. // SubSourceName string `description:"子数据来源名称"`
  41. // IndicatorCode string `description:"指标代码"`
  42. // StockCode string `description:"证券代码"`
  43. // }
  44. type EdbInfo struct {
  45. EdbInfoId int `gorm:"column:edb_info_id;primaryKey" description:"指标ID" orm:"column(edb_info_id);pk"`
  46. EdbInfoType int `gorm:"column:edb_info_type" description:"指标类型,0:普通指标,1:预测指标"`
  47. SourceName string `gorm:"column:source_name" description:"来源名称"`
  48. Source int `gorm:"column:source" description:"来源id"`
  49. EdbCode string `gorm:"column:edb_code" description:"指标编码"`
  50. EdbName string `gorm:"column:edb_name" description:"指标名称"`
  51. EdbNameEn string `gorm:"column:edb_name_en" description:"英文指标名称"`
  52. EdbNameSource string `gorm:"column:edb_name_source" description:"指标名称来源"`
  53. Frequency string `gorm:"column:frequency" description:"频率"`
  54. Unit string `gorm:"column:unit" description:"单位"`
  55. UnitEn string `gorm:"column:unit_en" description:"英文单位"`
  56. StartDate string `gorm:"column:start_date" description:"起始日期"`
  57. EndDate string `gorm:"column:end_date" description:"终止日期"`
  58. ClassifyId int `gorm:"column:classify_id" description:"分类id"`
  59. SysUserId int `gorm:"column:sys_user_id"`
  60. SysUserRealName string `gorm:"column:sys_user_real_name"`
  61. UniqueCode string `gorm:"column:unique_code" description:"指标唯一编码"`
  62. CreateTime time.Time `gorm:"column:create_time"`
  63. ModifyTime time.Time `gorm:"column:modify_time"`
  64. MinValue float64 `gorm:"column:min_value" description:"指标最小值"`
  65. MaxValue float64 `gorm:"column:max_value" description:"指标最大值"`
  66. CalculateFormula string `gorm:"column:calculate_formula" description:"计算公式"`
  67. EdbType int `gorm:"column:edb_type" description:"指标类型:1:基础指标,2:计算指标"`
  68. Sort int `gorm:"column:sort" description:"排序字段"`
  69. LatestDate string `gorm:"column:latest_date" description:"数据最新日期"`
  70. LatestValue float64 `gorm:"column:latest_value" description:"数据最新值"`
  71. MoveType int `gorm:"column:move_type" description:"移动方式:1:领先(默认),2:滞后"`
  72. MoveFrequency string `gorm:"column:move_frequency" description:"移动频度"`
  73. NoUpdate int8 `gorm:"column:no_update" description:"是否停止更新,0:继续更新;1:停止更新"`
  74. DataDateType string `gorm:"column:data_date_type;size(255);null;default:交易日" description:"数据日期类型"`
  75. SubSource int `gorm:"column:sub_source" description:"子数据来源:0:经济数据库,1:日期序列"`
  76. SubSourceName string `gorm:"column:sub_source_name" description:"子数据来源名称"`
  77. IndicatorCode string `gorm:"column:indicator_code" description:"指标代码"`
  78. StockCode string `gorm:"column:stock_code" description:"证券代码"`
  79. }
  80. type EdbInfoMaxAndMinInfo struct {
  81. MinDate string `description:"最小日期"`
  82. MaxDate string `description:"最大日期"`
  83. MinValue float64 `description:"最小值"`
  84. MaxValue float64 `description:"最大值"`
  85. LatestValue float64 `description:"最新值"`
  86. }
  87. func GetEdbInfoById(edbInfoId int) (item *EdbInfo, err error) {
  88. o := global.DmSQL["data"]
  89. sql := ` SELECT * FROM edb_info WHERE edb_info_id=? `
  90. err = o.Raw(sql, edbInfoId).First(&item).Error
  91. return
  92. }
  93. // GetEdbInfoByIdList 根据指标id集合 获取 指标列表
  94. func GetEdbInfoByIdList(edbInfoIdList []int) (items []*EdbInfo, err error) {
  95. num := len(edbInfoIdList)
  96. if num <= 0 {
  97. return
  98. }
  99. o := global.DmSQL["data"]
  100. sql := ` SELECT * FROM edb_info WHERE edb_info_id in (` + utils.GetGormInReplace(num) + `) `
  101. err = o.Raw(sql, edbInfoIdList).Find(&items).Error
  102. return
  103. }
  104. func GetRefreshEdbInfoFromBase(edbInfoId, source int) (baseEdbInfoArr, calculateInfoArr []*EdbInfo, err error) {
  105. calculateList, err := GetEdbInfoCalculateMap(edbInfoId, source)
  106. if err != nil && !utils.IsErrNoRow(err) {
  107. return
  108. }
  109. for _, item := range calculateList {
  110. if item.EdbInfoId == edbInfoId { // 如果查出来关联的指标就是自己的话,那么就过滤
  111. continue
  112. }
  113. if item.EdbType == 1 {
  114. baseEdbInfoArr = append(baseEdbInfoArr, item)
  115. } else {
  116. calculateInfoArr = append(calculateInfoArr, item)
  117. newBaseEdbInfoArr, newCalculateInfoArr, _ := GetRefreshEdbInfoFromBase(item.EdbInfoId, item.Source)
  118. baseEdbInfoArr = append(baseEdbInfoArr, newBaseEdbInfoArr...)
  119. calculateInfoArr = append(calculateInfoArr, newCalculateInfoArr...)
  120. }
  121. }
  122. return
  123. }
  124. // func GetEdbInfoById(edbInfoId int) (item *EdbInfo, err error) {
  125. // o := orm.NewOrmUsingDB("data")
  126. // sql := ` SELECT * FROM edb_info WHERE edb_info_id=? `
  127. // err = o.Raw(sql, edbInfoId).QueryRow(&item)
  128. // return
  129. // }
  130. // // GetEdbInfoByIdList 根据指标id集合 获取 指标列表
  131. // func GetEdbInfoByIdList(edbInfoIdList []int) (items []*EdbInfo, err error) {
  132. // num := len(edbInfoIdList)
  133. // if num <= 0 {
  134. // return
  135. // }
  136. // o := orm.NewOrmUsingDB("data")
  137. // sql := ` SELECT * FROM edb_info WHERE edb_info_id in (` + utils.GetOrmInReplace(num) + `) `
  138. // _, err = o.Raw(sql, edbInfoIdList).QueryRows(&items)
  139. // return
  140. // }
  141. // func GetRefreshEdbInfoFromBase(edbInfoId, source int) (baseEdbInfoArr, calculateInfoArr []*EdbInfo, err error) {
  142. // calculateList, err := GetEdbInfoCalculateMap(edbInfoId, source)
  143. // if err != nil && !utils.IsErrNoRow() {
  144. // return
  145. // }
  146. // for _, item := range calculateList {
  147. // if item.EdbInfoId == edbInfoId { // 如果查出来关联的指标就是自己的话,那么就过滤
  148. // continue
  149. // }
  150. // if item.EdbType == 1 {
  151. // baseEdbInfoArr = append(baseEdbInfoArr, item)
  152. // } else {
  153. // calculateInfoArr = append(calculateInfoArr, item)
  154. // newBaseEdbInfoArr, newCalculateInfoArr, _ := GetRefreshEdbInfoFromBase(item.EdbInfoId, item.Source)
  155. // baseEdbInfoArr = append(baseEdbInfoArr, newBaseEdbInfoArr...)
  156. // calculateInfoArr = append(calculateInfoArr, newCalculateInfoArr...)
  157. // }
  158. // }
  159. // return
  160. // }
  161. type EdbInfoSearchData struct {
  162. DataTime string `description:"数据日期"`
  163. Value float64 `description:"数据"`
  164. }
  165. // TraceEdbInfoResp 指标追溯数据返回
  166. type TraceEdbInfoResp struct {
  167. EdbInfoId int `description:"指标id"`
  168. EdbInfoType int `description:"指标类型: 0-普通指标; 1-预测指标"`
  169. EdbName string `description:"指标名称"`
  170. EdbType int `description:"指标类型: 1-基础指标; 2-计算指标"`
  171. RuleTitle string `description:"指标规则"`
  172. UniqueCode string `description:"唯一编码"`
  173. ClassifyId int `description:"分类ID"`
  174. Child []TraceEdbInfoResp `description:"下级来源"`
  175. EdbInfo *EdbInfo `description:"指标信息" json:"-"`
  176. }
  177. func (e *EdbInfo) AfterFind(db *gorm.DB) (err error) {
  178. tmpLatestDate, err := time.Parse(utils.FormatDateWallWithLoc, e.LatestDate)
  179. if err != nil {
  180. return nil
  181. }
  182. tmpStartDate, err := time.Parse(utils.FormatDateWallWithLoc, e.StartDate)
  183. if err != nil {
  184. return nil
  185. }
  186. tmpEndDate, err := time.Parse(utils.FormatDateWallWithLoc, e.EndDate)
  187. if err != nil {
  188. return nil
  189. }
  190. e.LatestDate = utils.TimeTransferString(utils.FormatDate, tmpLatestDate)
  191. e.StartDate = utils.TimeTransferString(utils.FormatDate, tmpStartDate)
  192. e.EndDate = utils.TimeTransferString(utils.FormatDate, tmpEndDate)
  193. return nil
  194. }