edb_info_update_stat.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. package data_stat
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. // EdbInfoUpdateStat 指标更新/刷新 汇总表(数据源明细表)
  7. type EdbInfoUpdateStat struct {
  8. Id uint64 `orm:"column(id);pk"`
  9. EdbInfoId int `description:"指标ID"`
  10. SourceName string `description:"来源名称"`
  11. Source int `description:"来源id"`
  12. EdbCode string `description:"指标编码"`
  13. EdbName string `description:"指标名称"`
  14. EdbNameSource string `description:"指标名称来源"`
  15. Frequency string `description:"频率"`
  16. Unit string `description:"单位"`
  17. StartDate string `description:"起始日期"`
  18. EndDate string `description:"终止日期"`
  19. SysUserId int `description:"创建人ID"`
  20. SysUserRealName string `description:"创建人姓名"`
  21. UniqueCode string `description:"指标唯一编码"`
  22. EdbCreateTime time.Time `description:"指标创建时间"`
  23. EdbModifyTime time.Time `description:"指标修改时间"`
  24. CreateTime time.Time `description:"记录创建时间"`
  25. LatestDate string `description:"数据最新日期"`
  26. LatestValue float64 `description:"数据最新值"`
  27. TerminalCode string `description:"终端编码,用于配置在机器上"`
  28. ErDataUpdateDate string `description:"本次更新,数据发生变化的最早日期"`
  29. DataUpdateResult int `description:"数据更新结果:1成功,2失败"`
  30. DataUpdateFailedReason string `description:"数据未正常更新原因"`
  31. DataUpdateTime string `description:"数据更新时间"`
  32. UpdateResult int `description:"本次刷新操作结果:1成功,2失败"`
  33. UpdateFailedReason string `description:"刷新失败原因"`
  34. UpdateTime string `description:"刷新时间"`
  35. ModifyTime time.Time `description:"修改时间"`
  36. IsAdd int `description:"是否是当日新增的指标:1是,2否"`
  37. NeedRefresh int `description:"今日是否需要定时刷新,1需要,0不需要"`
  38. HasRefresh int `description:"今日是否发起刷新服务,1是,0否"`
  39. }
  40. // Add 新增
  41. func (r *EdbInfoUpdateStat) Add(list []*EdbInfoUpdateStat) (err error) {
  42. o := orm.NewOrm()
  43. _, err = o.InsertMulti(len(list), list)
  44. return
  45. }
  46. // UpdateEdbUpdateStatMulti 批量更新
  47. func UpdateEdbUpdateStatMulti(list []*EdbInfoUpdateStat) (err error) {
  48. o := orm.NewOrm()
  49. sql := `UPDATE edb_info_update_stat
  50. SET
  51. edb_name = ?,
  52. edb_name_source = ?,
  53. frequency = ?,
  54. unit = ?,
  55. start_date = ?,
  56. end_date = ?,
  57. edb_modify_time = ?,
  58. latest_date = ?,
  59. latest_value = ?,
  60. terminal_code = ?,
  61. modify_time = ?,
  62. er_data_update_date = ?,
  63. is_add = ?,
  64. need_refresh = ?,
  65. has_refresh = ?,
  66. data_update_result = ?,
  67. data_update_failed_reason = ?,
  68. data_update_time = ?,
  69. update_result = ?,
  70. update_failed_reason = ?,
  71. update_time = ?
  72. WHERE
  73. id = ?`
  74. p, err := o.Raw(sql).Prepare()
  75. if err != nil {
  76. return
  77. }
  78. defer func() {
  79. _ = p.Close() // 别忘记关闭 statement
  80. }()
  81. for _, v := range list {
  82. _, err = p.Exec(v.EdbName, v.EdbNameSource, v.Frequency, v.Unit, v.StartDate, v.EndDate, v.EdbModifyTime, v.LatestDate, v.LatestValue, v.TerminalCode, v.ModifyTime, v.ErDataUpdateDate, v.IsAdd, v.NeedRefresh, v.HasRefresh, v.DataUpdateResult, v.DataUpdateFailedReason, v.DataUpdateTime, v.UpdateResult, v.UpdateFailedReason, v.UpdateTime, v.Id)
  83. if err != nil {
  84. return
  85. }
  86. }
  87. return
  88. }
  89. // GetEdbUpdateStatByCondition 获取指标更新汇总记录
  90. func GetEdbUpdateStatByCondition(condition string, pars []interface{}) (item []*EdbInfoUpdateStat, err error) {
  91. o := orm.NewOrm()
  92. sql := ` SELECT * FROM edb_info_update_stat WHERE 1=1 `
  93. if condition != "" {
  94. sql += condition
  95. }
  96. _, err = o.Raw(sql, pars).QueryRows(&item)
  97. return
  98. }