edb_info_update_stat.go 6.6 KB

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