edb_update_log.go 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. package data_manage
  2. import (
  3. "eta/eta_task/global"
  4. "eta/eta_task/utils"
  5. "time"
  6. )
  7. type EdbUpdateLog struct {
  8. Id int64 `json:"id" gorm:"primaryKey;autoIncrement"`
  9. OpDbName string `json:"op_db_name"` // 库名
  10. OpTableName string `json:"op_table_name"` // 表名
  11. OpType string `json:"op_type"` // 变更类型
  12. OldData string `json:"old_data"` // 历史数据
  13. NewData string `json:"new_data"` // 新数据
  14. IsHandle int `json:"is_handle"` // 是否处理,0:未处理,1:已处理;默认:0
  15. ModifyTime time.Time `json:"modify_time"`
  16. CreateTime time.Time `json:"create_time"`
  17. }
  18. // GetEdbUpdateLogMaxId
  19. // @Description: 获取最大的数据id
  20. // @author: Roc
  21. // @datetime 2024-03-07 18:38:23
  22. // @param condition string
  23. // @param pars []interface{}
  24. // @return maxId int
  25. // @return err error
  26. func GetEdbUpdateLogMaxId() (maxId int64, err error) {
  27. o := global.DbMap[utils.DbNameIndex]
  28. sql := ` SELECT id FROM edb_update_log WHERE 1=1 ORDER BY id desc limit 1 `
  29. err = o.Raw(sql).Scan(&maxId).Error
  30. return
  31. }
  32. // GetEdbUpdateLogMaxHandleId
  33. // @Description: 获取已经操作了的最大的数据id
  34. // @author: Roc
  35. // @datetime 2024-03-08 17:53:29
  36. // @return maxId int64
  37. // @return err error
  38. func GetEdbUpdateLogMaxHandleId() (maxId int64, err error) {
  39. o := global.DbMap[utils.DbNameIndex]
  40. sql := ` SELECT id FROM edb_update_log WHERE 1=1 AND is_handle = 1 ORDER BY id desc limit 1 `
  41. err = o.Raw(sql).Scan(&maxId).Error
  42. return
  43. }
  44. // GetEdbUpdateLogByCondition
  45. // @Description: 获取指标更新列表
  46. // @author: Roc
  47. // @datetime 2024-03-07 18:36:44
  48. // @param condition string
  49. // @param pars []interface{}
  50. // @return item []*EdbUpdateLog
  51. // @return err error
  52. func GetEdbUpdateLogByCondition(condition string, pars []interface{}) (item []*EdbUpdateLog, err error) {
  53. o := global.DbMap[utils.DbNameIndex]
  54. sql := ` SELECT * FROM edb_update_log WHERE 1=1 `
  55. if condition != "" {
  56. sql += condition
  57. }
  58. sql += ` ORDER BY id ASC limit 500 `
  59. err = o.Raw(sql, pars...).Find(&item).Error
  60. return
  61. }
  62. // HandleUpdateLogByIds
  63. // @Description: 批量处理指标更新记录
  64. // @author: Roc
  65. // @datetime 2024-03-08 17:30:52
  66. // @param idList []int
  67. // @return err error
  68. func HandleUpdateLogByIds(idList []int64, modifyTime string) (err error) {
  69. num := len(idList)
  70. if num <= 0 {
  71. return
  72. }
  73. o := global.DbMap[utils.DbNameIndex]
  74. sql := ` UPDATE edb_update_log set is_handle=1 ,modify_time = ? WHERE id in (` + utils.GetOrmInReplace(num) + `) `
  75. err = o.Exec(sql, modifyTime, idList).Error
  76. return
  77. }
  78. type EdbInfoItem struct {
  79. CalculateFormula string `json:"calculate_formula"`
  80. Calendar string `json:"calendar"`
  81. ChartImage string `json:"chart_image"`
  82. ClassifyId int `json:"classify_id"`
  83. CreateTime string `json:"create_time"`
  84. DataDateType string `json:"data_date_type"`
  85. DataUpdateTime string `json:"data_update_time"`
  86. EdbCode string `json:"edb_code"`
  87. EdbInfoId int `json:"edb_info_id"`
  88. EdbInfoType int `json:"edb_info_type"`
  89. EdbName string `json:"edb_name"`
  90. EdbNameEn string `json:"edb_name_en"`
  91. EdbNameSource string `json:"edb_name_source"`
  92. EdbType int `json:"edb_type"`
  93. EmptyType int `json:"empty_type"`
  94. EndDate string `json:"end_date"`
  95. EndValue float64 `json:"end_value"`
  96. ErDataUpdateDate string `json:"er_data_update_date"`
  97. Extra string `json:"extra"`
  98. Frequency string `json:"frequency"`
  99. IndicatorCode string `json:"indicator_code"`
  100. IsUpdate int `json:"is_update"`
  101. LatestDate string `json:"latest_date"`
  102. LatestValue float64 `json:"latest_value"`
  103. ManualSave int `json:"manual_save"`
  104. MaxEmptyType int `json:"max_empty_type"`
  105. MaxValue float64 `json:"max_value"`
  106. MinValue float64 `json:"min_value"`
  107. ModifyTime string `json:"modify_time"`
  108. MoveFrequency string `json:"move_frequency"`
  109. MoveType int `json:"move_type"`
  110. NoUpdate int `json:"no_update"`
  111. ServerUrl string `json:"server_url"`
  112. Sort int `json:"sort"`
  113. Source int `json:"source"`
  114. SourceIndexName string `json:"source_index_name"`
  115. SourceName string `json:"source_name"`
  116. StartDate string `json:"start_date"`
  117. StockCode string `json:"stock_code"`
  118. SubSource int `json:"sub_source"`
  119. SubSourceName string `json:"sub_source_name"`
  120. SysUserId int `json:"sys_user_id"`
  121. SysUserRealName string `json:"sys_user_real_name"`
  122. TerminalCode string `json:"terminal_code"`
  123. UniqueCode string `json:"unique_code"`
  124. Unit string `json:"unit"`
  125. UnitEn string `json:"unit_en"`
  126. }
  127. func (m *EdbInfoItem) ConvertTimeStr() {
  128. m.StartDate = utils.GormDateStrToDateStr(m.StartDate)
  129. m.EndDate = utils.GormDateStrToDateStr(m.EndDate)
  130. m.LatestDate = utils.GormDateStrToDateStr(m.LatestDate)
  131. m.DataUpdateTime = utils.GormDateStrToDateTimeStr(m.DataUpdateTime)
  132. m.CreateTime = utils.GormDateStrToDateTimeStr(m.CreateTime)
  133. m.ModifyTime = utils.GormDateStrToDateTimeStr(m.ModifyTime)
  134. return
  135. }
  136. type EdbData struct {
  137. EdbDataId int32 `orm:"column(edb_data_id);pk" gorm:"primaryKey" json:"edb_data_id"`
  138. EdbInfoId int32 `json:"edb_info_id"` // 指标id
  139. EdbCode string `json:"edb_code"` // 指标编码
  140. //DataTime time.Time `json:"data_time"` // 数据日期
  141. DataTime string `json:"data_time"` // 数据日期
  142. Value float64 `json:"value"` // 数据值
  143. //CreateTime time.Time `json:"create_time"` // 创建时间
  144. //ModifyTime time.Time `json:"modify_time"` // 修改时间
  145. CreateTime string `json:"create_time"` // 创建时间
  146. ModifyTime string `json:"modify_time"` // 修改时间
  147. DataTimestamp int64 `json:"data_timestamp"` // 数据日期时间戳
  148. }