edb_info_calculate_mapping.go 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. package data_manage
  2. import (
  3. sql2 "database/sql"
  4. "eta_gn/eta_api/global"
  5. "eta_gn/eta_api/utils"
  6. "time"
  7. )
  8. // EdbInfoCalculateMapping 计算指标于基础指标,关系表
  9. type EdbInfoCalculateMapping struct {
  10. EdbInfoCalculateMappingId int `orm:"column(edb_info_calculate_mapping_id);pk" gorm:"primaryKey" `
  11. EdbInfoId int `description:"计算指标id"`
  12. Source int `description:"计算指标来源"`
  13. SourceName string `description:"计算指标来源名称"`
  14. EdbCode string `description:"计算指标编码"`
  15. FromEdbInfoId int `description:"基础指标id"`
  16. FromEdbCode string `description:"基础指标编码"`
  17. FromEdbName string `description:"基础指标名称"`
  18. FromSource int `description:"基础指标来源"`
  19. FromSourceName string `description:"基础指标来源名称"`
  20. FromTag string `description:"来源指标标签"`
  21. Sort int `description:"计算指标名称排序"`
  22. CreateTime time.Time `description:"创建时间"`
  23. ModifyTime time.Time `description:"修改时间"`
  24. }
  25. func GetEdbInfoCalculateMappingCount(edbInfoId int) (count int, err error) {
  26. o := global.DmSQL["data"]
  27. sql := ` SELECT COUNT(1) AS count FROM edb_info_calculate_mapping WHERE from_edb_info_id=? `
  28. err = o.Raw(sql, edbInfoId).Scan(&count).Error
  29. return
  30. }
  31. type EdbInfoCalculateMappingView struct {
  32. EdbInfoCalculateMappingId int `orm:"column(edb_info_calculate_mapping_id);pk" gorm:"primaryKey" `
  33. EdbInfoId int `description:"计算指标id"`
  34. Source int `description:"计算指标来源"`
  35. SourceName string `description:"计算指标来源名称"`
  36. EdbCode string `description:"计算指标编码"`
  37. FromEdbInfoId int `description:"基础指标id"`
  38. FromEdbCode string `description:"基础指标编码"`
  39. FromEdbName string `description:"基础指标名称"`
  40. FromSource int `description:"基础指标来源"`
  41. FromSourceName string `description:"基础指标来源名称"`
  42. FromTag string `description:"来源指标标签"`
  43. Sort int `description:"计算指标名称排序"`
  44. CreateTime time.Time `description:"创建时间"`
  45. ModifyTime time.Time `description:"修改时间"`
  46. StartDate string `description:"开始日期"`
  47. EndDate string `description:"结束日期"`
  48. CalculateFormula string `description:"N值"`
  49. MoveType int `description:"移动方式:1:领先(默认),2:滞后"`
  50. MoveFrequency string `description:"移动频度"`
  51. }
  52. func GetEdbInfoCalculateMappingDetail(edbInfoId int) (item *EdbInfoCalculateMappingView, err error) {
  53. o := global.DmSQL["data"]
  54. sql := ` SELECT a.*,b.start_date,b.end_date,b.calculate_formula,b.move_type,b.move_frequency FROM edb_info_calculate_mapping AS a
  55. INNER JOIN edb_info AS b ON a.edb_info_id=b.edb_info_id
  56. WHERE a.edb_info_id=? `
  57. err = o.Raw(sql, edbInfoId).Scan(&item).Error
  58. return
  59. }
  60. // EdbInfoCalculateMappingInfo
  61. // @Description: 计算指标与基础指标关系表
  62. type EdbInfoCalculateMappingInfo struct {
  63. EdbInfoCalculateMappingId int `orm:"column(edb_info_calculate_mapping_id);pk" gorm:"primaryKey" `
  64. EdbInfoId int `description:"计算指标id"`
  65. Source int `description:"计算指标来源"`
  66. SourceName string `description:"计算指标来源名称"`
  67. EdbCode string `description:"计算指标编码"`
  68. FromEdbInfoId int `description:"基础指标id"`
  69. FromEdbCode string `description:"基础指标编码"`
  70. FromEdbName string `description:"基础指标名称"`
  71. FromSource int `description:"基础指标来源"`
  72. FromSourceName string `description:"基础指标来源名称"`
  73. MoveValue int `description:"领先值"`
  74. FromTag string `description:"来源指标标签"`
  75. Sort int `description:"计算指标名称排序"`
  76. CreateTime time.Time `description:"创建时间"`
  77. ModifyTime time.Time `description:"修改时间"`
  78. FromEdbType int `description:"来源指标类型:1:基础指标,2:计算指标"`
  79. FromEdbInfoType int `description:"来源指标类型: 0-基础指标; 1-预测指标"`
  80. FromClassifyId int `description:"来源指标分类ID"`
  81. FromUniqueCode string `description:"来源指标唯一编码"`
  82. NoUpdate int8 `description:"是否停止更新,0:继续更新;1:停止更新"`
  83. }
  84. // GetEdbInfoCalculateMappingListByEdbInfoId 根据生成的指标id获取来源的指标id列表
  85. func GetEdbInfoCalculateMappingListByEdbInfoId(edbInfoId int) (items []*EdbInfoCalculateMappingInfo, err error) {
  86. o := global.DmSQL["data"]
  87. sql := ` SELECT a.*,b.edb_type as from_edb_type,b.edb_info_type as from_edb_info_type, b.unique_code AS from_unique_code, b.classify_id AS from_classify_id,b.no_update FROM edb_info_calculate_mapping AS a
  88. INNER JOIN edb_info AS b ON a.from_edb_info_id=b.edb_info_id
  89. WHERE a.edb_info_id=? `
  90. err = o.Raw(sql, edbInfoId).Scan(&items).Error
  91. return
  92. }
  93. // GetEdbInfoCalculateMappingListByEdbInfoIds 根据生成的指标id获取来源的指标id列表
  94. func GetEdbInfoCalculateMappingListByEdbInfoIds(edbInfoIds []int) (items []*EdbInfoCalculateMappingInfo, err error) {
  95. o := global.DmSQL["data"]
  96. sql := ` SELECT a.*,b.edb_type as from_edb_type,b.edb_info_type as from_edb_info_type, b.unique_code AS from_unique_code, b.classify_id AS from_classify_id,b.no_update FROM edb_info_calculate_mapping AS a
  97. INNER JOIN edb_info AS b ON a.from_edb_info_id=b.edb_info_id
  98. WHERE a.edb_info_id in (` + utils.GetOrmInReplace(len(edbInfoIds)) + `) `
  99. err = o.Raw(sql, edbInfoIds).Scan(&items).Error
  100. return
  101. }
  102. // GetCountRelationEdbInfoListMappingByCondition
  103. // @Description: 根据条件获取关联指标数量
  104. // @author: Roc
  105. // @datetime 2024-12-26 10:37:48
  106. // @param condition string
  107. // @param pars []interface{}
  108. // @return total int
  109. // @return err error
  110. func GetCountRelationEdbInfoListMappingByCondition(condition string, pars []interface{}) (total int, err error) {
  111. o := global.DmSQL["data"]
  112. sql := ` SELECT COUNT(1) total FROM edb_info_calculate_mapping AS a
  113. JOIN edb_info AS b on a.edb_info_id = b.edb_info_id WHERE 1=1 `
  114. if condition != "" {
  115. sql += condition
  116. }
  117. var totalNull sql2.NullInt64
  118. err = o.Raw(sql, pars...).Scan(&totalNull).Error
  119. if err != nil {
  120. return
  121. }
  122. total = int(totalNull.Int64)
  123. return
  124. }
  125. // GetCountRelationEdbInfoListMappingByCondition
  126. // @Description: 根据条件获取关联指标的用户id列表
  127. // @author: Roc
  128. // @datetime 2024-12-26 10:37:48
  129. // @param condition string
  130. // @param pars []interface{}
  131. // @return total int
  132. // @return err error
  133. func GetUserIdListRelationEdbInfoListMappingByCondition(condition string, pars []interface{}) (userIdList []int, err error) {
  134. o := global.DmSQL["data"]
  135. sql := ` SELECT b.sys_user_id FROM edb_info_calculate_mapping AS a
  136. JOIN edb_info AS b on a.edb_info_id = b.edb_info_id WHERE 1=1 `
  137. if condition != "" {
  138. sql += condition
  139. }
  140. sql += ` GROUP BY b.sys_user_id `
  141. err = o.Raw(sql, pars...).Scan(&userIdList).Error
  142. return
  143. }