edb_refresh_mapping.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. package edb_refresh
  2. import (
  3. "errors"
  4. "eta_gn/eta_index_lib/global"
  5. "eta_gn/eta_index_lib/utils"
  6. "time"
  7. )
  8. // EdbRefreshMapping
  9. // @Description: 指标刷新时间配置关系表
  10. type EdbRefreshMapping struct {
  11. EdbRefreshMappingId int `gorm:"primaryKey;autoIncrement;column:edb_refresh_mapping_id" description:"映射ID"`
  12. Source int `gorm:"column:source" description:"来源"`
  13. SubSource int `gorm:"column:sub_source" description:"来源名称"`
  14. EdbInfoId int `gorm:"column:edb_info_id" description:"指标id,如果是数据源(钢联、有色)的,那么就是数据源里面的id"`
  15. EdbRefreshConfigId int `gorm:"column:edb_refresh_config_id" description:"刷新配置id"`
  16. SysUserId int `gorm:"column:sys_user_id" description:"操作人id"`
  17. SysUserRealName string `gorm:"column:sys_user_real_name" description:"操作人真实姓名"`
  18. ModifyTime time.Time `gorm:"column:modify_time" description:"最晚一次的更新时间"`
  19. CreateTime time.Time `gorm:"column:create_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. err = global.DEFAULT_DmSQL.Create(m).Error
  34. return
  35. }
  36. // Update
  37. // @Description: 更新
  38. // @author: Roc
  39. // @receiver m
  40. // @datetime 2023-12-14 16:11:10
  41. // @param cols []string
  42. // @return err error
  43. func (m *EdbRefreshMapping) Update(cols []string) (err error) {
  44. err = global.DEFAULT_DmSQL.Model(m).Select(cols).Updates(m).Error
  45. return
  46. }
  47. // Delete
  48. // @Description: 删除
  49. // @author: Roc
  50. // @receiver m
  51. // @datetime 2023-12-14 16:11:10
  52. // @return err error
  53. func (m *EdbRefreshMapping) Delete() (err error) {
  54. err = global.DEFAULT_DmSQL.Delete(m).Error
  55. return
  56. }
  57. type EdbInfoListAndRefreshConfig struct {
  58. EdbInfoId int `gorm:"primaryKey;autoIncrement;column:edb_info_id"`
  59. SourceName string `gorm:"column:source_name" description:"来源名称"`
  60. Source int `gorm:"column:source" description:"来源id"`
  61. SubSource int `gorm:"column:sub_source" description:"子数据来源:0:经济数据库,1:日期序列"`
  62. SubSourceName string `gorm:"column:sub_source_name" description:"子数据来源名称"`
  63. EdbCode string `gorm:"column:edb_code" description:"指标编码"`
  64. EdbName string `gorm:"column:edb_name" description:"指标名称"`
  65. Frequency string `gorm:"column:frequency" description:"频率"`
  66. Unit string `gorm:"column:unit" description:"单位"`
  67. StartDate time.Time `gorm:"column:start_date" description:"起始日期"`
  68. EndDate time.Time `gorm:"column:end_date" description:"终止日期"`
  69. ClassifyId int `gorm:"column:classify_id" description:"分类id"`
  70. UniqueCode string `gorm:"column:unique_code" description:"指标唯一编码"`
  71. CalculateFormula string `gorm:"column:calculate_formula" description:"计算公式"`
  72. ModifyTime string `gorm:"column:modify_time" description:"更新时间"`
  73. NoUpdate int8 `gorm:"column:no_update" description:"是否停止更新,0:继续更新;1:停止更新"`
  74. EdbRefreshConfigId int `gorm:"column:edb_refresh_config_id" description:"刷新配置id"`
  75. DataRefreshNum int `gorm:"column:data_refresh_num" description:"刷新的期数"`
  76. }
  77. // GetConfigRefreshEdbInfoListBySourceAndSubSource
  78. // @Description: 根据来源和配置id列表获取指标列表
  79. // @author: Roc
  80. // @datetime 2024-01-09 17:28:06
  81. // @param sourceList []int
  82. // @param configIdList []int
  83. // @return list []*data_manage.EdbInfoList
  84. // @return err error
  85. func GetConfigRefreshEdbInfoListBySourceAndSubSource(sourceList, configIdList []int) (list []*EdbInfoListAndRefreshConfig, err error) {
  86. num := len(configIdList)
  87. if num <= 0 {
  88. return
  89. }
  90. var pars []interface{}
  91. sql := `SELECT a.*,b.edb_refresh_config_id FROM edb_info a
  92. JOIN edb_refresh_mapping b ON a.edb_info_id = b.edb_info_id
  93. WHERE b.edb_refresh_config_id IN (` + utils.GetOrmInReplace(num) + `) `
  94. pars = append(pars, configIdList)
  95. sourceNum := len(sourceList)
  96. if sourceNum > 0 {
  97. sql += ` AND b.source not in (` + utils.GetOrmInReplace(sourceNum) + `) `
  98. pars = append(pars, sourceList)
  99. }
  100. err = global.DEFAULT_DmSQL.Raw(sql, pars...).Scan(&list).Error
  101. return
  102. }