edb_info_update_stat.go 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. package data_stat
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "time"
  6. )
  7. // EdbInfoUpdateStat 指标更新/刷新 汇总表(数据源明细表)
  8. type EdbInfoUpdateStat struct {
  9. Id uint64 `orm:"column(id);pk"`
  10. EdbInfoId int `description:"指标ID"`
  11. SourceName string `description:"来源名称"`
  12. Source int `description:"来源id"`
  13. EdbCode string `description:"指标编码"`
  14. EdbName string `description:"指标名称"`
  15. EdbNameSource string `description:"指标名称来源"`
  16. Frequency string `description:"频率"`
  17. Unit string `description:"单位"`
  18. StartDate string `description:"起始日期"`
  19. EndDate string `description:"终止日期"`
  20. SysUserId int `description:"创建人ID"`
  21. SysUserRealName string `description:"创建人姓名"`
  22. UniqueCode string `description:"指标唯一编码"`
  23. EdbCreateTime time.Time `description:"指标创建时间"`
  24. EdbModifyTime time.Time `description:"指标修改时间"`
  25. CreateTime time.Time
  26. UpdateTime string `description:"刷新时间"`
  27. LatestDate string `description:"数据最新日期"`
  28. LatestValue float64 `description:"数据最新值"`
  29. TerminalCode string `description:"终端编码,用于配置在机器上"`
  30. ErDataUpdateDate string `description:"本次更新,数据发生变化的最早日期"`
  31. DataUpdateResult int `description:"数据更新结果:1成功,2失败"`
  32. DataUpdateFailedReason string `description:"数据未正常更新原因"`
  33. DataUpdateTime string `description:"数据更新时间"`
  34. UpdateResult int `description:"本次刷新操作结果:1成功,2失败"`
  35. UpdateFailedReason string `description:"刷新失败原因"`
  36. ModifyTime string `description:"修改时间"`
  37. IsAdd int8 `description:"是否是当日新增的指标:1是,2否"`
  38. NeedRefresh int8 `description:"今日是否需要定时刷新,1需要,0不需要"` //todo 确认该字段
  39. HasRefresh int8 `description:"今日是否已刷新,1是,0否"`
  40. }
  41. type EdbInfoUpdateStatItem struct {
  42. Id uint64 `orm:"column(id);pk"`
  43. EdbInfoId int `description:"指标ID"`
  44. SourceName string `description:"来源名称"`
  45. Source int `description:"来源id"`
  46. EdbCode string `description:"指标编码"`
  47. EdbName string `description:"指标名称"`
  48. EdbNameSource string `description:"指标名称来源"`
  49. Frequency string `description:"频率"`
  50. Unit string `description:"单位"`
  51. StartDate string `description:"起始日期"`
  52. SysUserId int `description:"创建人ID"`
  53. SysUserRealName string `description:"创建人姓名"`
  54. LatestDate string `description:"数据最新日期"`
  55. CreateTime string `description:"创建时间"`
  56. LatestValue float64 `description:"数据最新值"`
  57. TerminalCode string `description:"终端编码,用于配置在机器上"`
  58. ErDataUpdateDate string `description:"本次更新,数据发生变化的最早日期"`
  59. DataUpdateResult int `description:"数据更新结果:1成功,2失败"`
  60. DataUpdateFailedReason string `description:"数据未正常更新原因"`
  61. DataUpdateTime string `description:"数据更新时间"`
  62. UpdateResult int `description:"本次刷新操作结果:1成功,2失败"`
  63. UpdateFailedReason string `description:"刷新失败原因"`
  64. UpdateTime string `description:"刷新时间"`
  65. IsAdd int8 `description:"是否是当日新增的指标:1是,2否"`
  66. NeedRefresh int8 `description:"今日是否需要定时刷新,1需要,0不需要"`
  67. HasRefresh int8 `description:"今日是否已刷新,1是,0否"`
  68. }
  69. type EdbInfoUpdateStatItemMore struct {
  70. EdbInfoUpdateStatItem
  71. InitSourceName string `description:"初始数据源"`
  72. }
  73. type GetEdbUpdateStatResp struct {
  74. List []*EdbInfoUpdateStatItemMore
  75. Paging *paging.PagingItem
  76. }
  77. func GetEdbUpdateStatByCondition(condition string, pars []interface{}, orderStr string, pageSize, startSize int) (item []*EdbInfoUpdateStat, err error) {
  78. o := orm.NewOrmUsingDB("data")
  79. sql := ` SELECT * FROM edb_info_update_stat WHERE 1=1 `
  80. if condition != "" {
  81. sql += condition
  82. }
  83. if orderStr != "" {
  84. sql += orderStr
  85. } else {
  86. sql += ` ORDER BY create_time DESC, id DESC `
  87. }
  88. sql += ` LIMIT ?,? `
  89. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&item)
  90. return
  91. }
  92. // GetEdbUpdateStatCount
  93. func GetEdbUpdateStatCount(condition string, pars []interface{}) (count int, err error) {
  94. o := orm.NewOrmUsingDB("data")
  95. sql := ` SELECT count(*) FROM edb_info_update_stat WHERE 1=1 `
  96. if condition != "" {
  97. sql += condition
  98. }
  99. err = o.Raw(sql, pars).QueryRow(&count)
  100. return
  101. }
  102. type EdbUpdateFailedList struct {
  103. TerminalCode string `description:"终端编码,用于配置在机器上"`
  104. SourceUpdateFailedReason string `description:"从终端刷新到数据源的数据未正常刷新原因"`
  105. Frequency string `description:"频率"`
  106. SourceUpdateResult int `description:"从终端刷新到数据源的刷新结果:1成功,2失败"`
  107. Num int
  108. }
  109. type GetEdbUpdateFailedResp struct {
  110. List []*EdbUpdateFailedList
  111. Name string `description:"终端名称"`
  112. TerminalCode string `description:"终端编码,用于配置在机器上"`
  113. DirPath string `description:"终端存放的文件夹路径"`
  114. UpdateSuccessNum int `description:"今日已更新成功指标数"`
  115. UpdateFailedNum int `description:"今日已更新失败指标数"`
  116. }
  117. func GetEdbUpdateStatFailedGroupByCondition(condition string, pars []interface{}) (item []*EdbUpdateFailedList, err error) {
  118. o := orm.NewOrmUsingDB("data")
  119. sql := `SELECT
  120. terminal_code,
  121. data_update_result as source_update_result,
  122. frequency,
  123. data_update_failed_reason as source_update_failed_reason,
  124. count(*) as num
  125. FROM
  126. edb_info_update_stat
  127. WHERE
  128. data_update_result != 0`
  129. if condition != "" {
  130. sql += condition
  131. }
  132. sql += ` GROUP BY
  133. data_update_result,
  134. frequency,
  135. data_update_failed_reason
  136. ORDER BY count(*) desc`
  137. _, err = o.Raw(sql, pars).QueryRows(&item)
  138. return
  139. }