edb_refresh_mapping.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. // EdbRefreshMapping
  9. // @Description: 指标刷新时间配置关系表
  10. type EdbRefreshMapping struct {
  11. EdbRefreshMappingId int `orm:"column(edb_refresh_mapping_id);pk"`
  12. Source int `description:"来源"`
  13. SubSource int `description:"来源名称"`
  14. EdbInfoId int `description:"指标id,如果是数据源(钢联、有色)的,那么就是数据源里面的id"`
  15. EdbRefreshConfigId int `description:"刷新配置id"`
  16. SysUserId int `description:"操作人id"`
  17. SysUserRealName string `description:"操作人真实姓名"`
  18. ModifyTime time.Time `description:"最晚一次的更新时间"`
  19. CreateTime time.Time `description:"添加时间"`
  20. }
  21. // Add
  22. // @Description: 添加
  23. // @author: Roc
  24. // @receiver m
  25. // @datetime 2023-12-14 16:11:10
  26. // @param cols []string
  27. // @return err error
  28. func (m *EdbRefreshMapping) Add() (err error) {
  29. if m.EdbRefreshMappingId > 0 {
  30. err = errors.New("该配置已存在")
  31. return
  32. }
  33. o := orm.NewOrm()
  34. lastId, err := o.Insert(m)
  35. if err != nil {
  36. return
  37. }
  38. m.EdbRefreshMappingId = int(lastId)
  39. return
  40. }
  41. // Update
  42. // @Description: 更新
  43. // @author: Roc
  44. // @receiver m
  45. // @datetime 2023-12-14 16:11:10
  46. // @param cols []string
  47. // @return err error
  48. func (m *EdbRefreshMapping) Update(cols []string) (err error) {
  49. o := orm.NewOrm()
  50. _, err = o.Update(m, cols...)
  51. return
  52. }
  53. // Delete
  54. // @Description: 删除
  55. // @author: Roc
  56. // @receiver m
  57. // @datetime 2023-12-14 16:11:10
  58. // @return err error
  59. func (m *EdbRefreshMapping) Delete() (err error) {
  60. o := orm.NewOrm()
  61. _, err = o.Delete(m)
  62. return
  63. }
  64. type EdbInfoListAndRefreshConfig struct {
  65. EdbInfoId int `orm:"column(edb_info_id);pk"`
  66. SourceName string `description:"来源名称"`
  67. Source int `description:"来源id"`
  68. SubSource int `description:"子数据来源:0:经济数据库,1:日期序列"`
  69. SubSourceName string `description:"子数据来源名称"`
  70. EdbCode string `description:"指标编码"`
  71. EdbName string `description:"指标名称"`
  72. Frequency string `description:"频率"`
  73. Unit string `description:"单位"`
  74. StartDate time.Time `description:"起始日期"`
  75. EndDate time.Time `description:"终止日期"`
  76. ClassifyId int `description:"分类id"`
  77. UniqueCode string `description:"指标唯一编码"`
  78. CalculateFormula string `description:"计算公式"`
  79. ModifyTime string `description:"更新时间"`
  80. NoUpdate int8 `description:"是否停止更新,0:继续更新;1:停止更新"`
  81. EdbRefreshConfigId int `description:"刷新配置id"`
  82. DataRefreshNum int `description:"刷新的期数"`
  83. }
  84. // GetConfigRefreshEdbInfoListBySourceAndSubSource
  85. // @Description: 根据来源和配置id列表获取指标列表
  86. // @author: Roc
  87. // @datetime 2024-01-09 17:28:06
  88. // @param sourceList []int
  89. // @param configIdList []int
  90. // @return list []*data_manage.EdbInfoList
  91. // @return err error
  92. func GetConfigRefreshEdbInfoListBySourceAndSubSource(sourceList, configIdList []int) (list []*EdbInfoListAndRefreshConfig, err error) {
  93. num := len(configIdList)
  94. if num <= 0 {
  95. return
  96. }
  97. var pars []interface{}
  98. o := orm.NewOrm()
  99. sql := `SELECT a.*,b.edb_refresh_config_id FROM edb_info a
  100. JOIN edb_refresh_mapping b ON a.edb_info_id = b.edb_info_id
  101. WHERE b.edb_refresh_config_id IN (` + utils.GetOrmInReplace(num) + `) `
  102. pars = append(pars, configIdList)
  103. sourceNum := len(sourceList)
  104. if sourceNum > 0 {
  105. sql += ` AND b.source not in (` + utils.GetOrmInReplace(sourceNum) + `) `
  106. pars = append(pars, sourceList)
  107. }
  108. _, err = o.Raw(sql, pars).QueryRows(&list)
  109. return
  110. }