edb_refresh_default_config.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. package edb_refresh
  2. import (
  3. "errors"
  4. "eta/eta_index_lib/utils"
  5. "github.com/beego/beego/v2/client/orm"
  6. "time"
  7. )
  8. // EdbRefreshDefaultConfig
  9. // @Description: 指标的默认刷新时间配置表
  10. type EdbRefreshDefaultConfig struct {
  11. Id int `orm:"column(id);pk"`
  12. Source int `description:"来源"`
  13. SubSource int `description:"来源名称"`
  14. Frequency string `description:"频度"`
  15. RefreshFrequency string `description:"刷新频率"`
  16. RefreshFrequencyDay int `description:"具体刷新的日期"`
  17. RefreshTime string `description:"刷新时间"`
  18. RefreshAllData int `description:"是否刷新所有数据,0:否,1:刷新所有数据"`
  19. RefreshDataNum int `description:"刷新单元格数"`
  20. ModifyTime time.Time `description:"最晚一次的更新时间"`
  21. CreateTime time.Time `description:"添加时间"`
  22. }
  23. // Add
  24. // @Description: 添加
  25. // @author: Roc
  26. // @receiver m
  27. // @datetime 2023-12-14 16:11:10
  28. // @param cols []string
  29. // @return err error
  30. func (m *EdbRefreshDefaultConfig) Add() (err error) {
  31. if m.Id > 0 {
  32. err = errors.New("该配置已存在")
  33. return
  34. }
  35. o := orm.NewOrm()
  36. lastId, err := o.Insert(m)
  37. if err != nil {
  38. return
  39. }
  40. m.Id = int(lastId)
  41. return
  42. }
  43. // Update
  44. // @Description: 更新
  45. // @author: Roc
  46. // @receiver m
  47. // @datetime 2023-12-14 16:11:10
  48. // @param cols []string
  49. // @return err error
  50. func (m *EdbRefreshDefaultConfig) Update(cols []string) (err error) {
  51. o := orm.NewOrm()
  52. _, err = o.Update(m, cols...)
  53. return
  54. }
  55. // Delete
  56. // @Description: 删除
  57. // @author: Roc
  58. // @receiver m
  59. // @datetime 2023-12-14 16:11:10
  60. // @return err error
  61. func (m *EdbRefreshDefaultConfig) Delete() (err error) {
  62. o := orm.NewOrm()
  63. _, err = o.Delete(m)
  64. return
  65. }
  66. // GetListBySourceAndFrequency
  67. // @Description: 根据来源和频度获取列表
  68. // @author: Roc
  69. // @datetime 2024-01-04 17:39:47
  70. // @param source int
  71. // @param subSource int
  72. // @param frequency string
  73. // @return list []*EdbRefreshDefaultConfig
  74. // @return err error
  75. func GetListBySourceAndFrequency(source, subSource int, frequency string) (list []*EdbRefreshDefaultConfig, err error) {
  76. o := orm.NewOrm()
  77. sql := `SELECT * FROM edb_refresh_default_config
  78. WHERE source = ? AND sub_source = ? AND frequency = ? ORDER BY id ASC `
  79. _, err = o.Raw(sql, source, subSource, frequency).QueryRows(&list)
  80. return
  81. }
  82. // GetListByCondition
  83. // @Description: 根据条条件获取默认配置列表
  84. // @author: Roc
  85. // @datetime 2024-01-09 13:28:49
  86. // @param condition string
  87. // @param pars []interface{}
  88. // @return list []*EdbRefreshDefaultConfig
  89. // @return err error
  90. func GetListByCondition(condition string, pars []interface{}) (list []*EdbRefreshDefaultConfig, err error) {
  91. o := orm.NewOrm()
  92. sql := `SELECT * FROM edb_refresh_default_config
  93. WHERE 1 = 1 `
  94. if condition != "" {
  95. sql += condition
  96. }
  97. sql += ` ORDER BY id ASC `
  98. _, err = o.Raw(sql, pars).QueryRows(&list)
  99. return
  100. }
  101. // GetDefaultRefreshEdbInfoListBySourceAndSubSource
  102. // @Description: 根据来源获取默认刷新的指标列表
  103. // @author: Roc
  104. // @datetime 2024-01-09 16:22:49
  105. // @param source int
  106. // @param subSource int
  107. // @return list []*data_manage.EdbInfo
  108. // @return err error
  109. func GetDefaultRefreshEdbInfoListBySourceAndSubSource(source, subSource int, frequencyList []string) (list []*EdbInfoListAndRefreshConfig, err error) {
  110. num := len(frequencyList)
  111. if num <= 0 {
  112. return
  113. }
  114. o := orm.NewOrm()
  115. sql := `SELECT a.* FROM edb_info a
  116. LEFT JOIN edb_refresh_mapping b ON a.edb_info_id = b.edb_info_id
  117. WHERE a.source = ? AND a.sub_source = ? AND a.frequency IN (` + utils.GetOrmInReplace(num) + `) AND b.edb_info_id is null`
  118. _, err = o.Raw(sql, source, subSource, frequencyList).QueryRows(&list)
  119. return
  120. }