base_from_business_index.go 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. package data_manage
  2. import (
  3. "eta/eta_api/utils"
  4. "github.com/beego/beego/v2/client/orm"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "time"
  7. )
  8. // BaseFromBusinessIndex
  9. // @Description: 外部指标(商家系统)表
  10. type BaseFromBusinessIndex struct {
  11. BaseFromBusinessIndexId int64 `orm:"column(base_from_business_index_id);pk"`
  12. IndexCode string `description:"指标编码"`
  13. IndexName string `description:"指标名称"`
  14. Unit string `description:"单位"`
  15. Frequency string `description:"频度"`
  16. Source int `description:"数据来源"`
  17. SourceName string `description:"数据来源名称"`
  18. StartDate time.Time `description:"开始日期"`
  19. EndDate time.Time `description:"结束日期"`
  20. Remark string `description:"备注字段"`
  21. BaseModifyTime time.Time `description:"基础信息(名称,单位,频度)变更时间"`
  22. DataUpdateTime time.Time `description:"最近一次数据发生变化的时间"`
  23. CreateTime time.Time `description:"创建时间"`
  24. ModifyTime time.Time `description:"修改时间"`
  25. }
  26. var BaseFromBusinessIndexCols = struct {
  27. BaseFromBusinessIndexId string
  28. IndexCode string
  29. IndexName string
  30. Unit string
  31. Frequency string
  32. Source string
  33. SourceName string
  34. StartDate string
  35. EndDate string
  36. Remark string
  37. BaseModifyTime string
  38. DataUpdateTime string
  39. CreateTime string
  40. ModifyTime string
  41. }{
  42. BaseFromBusinessIndexId: "base_from_business_index_id",
  43. IndexCode: "index_code",
  44. IndexName: "index_name",
  45. Unit: "unit",
  46. Frequency: "frequency",
  47. Source: "source",
  48. SourceName: "source_name",
  49. StartDate: "start_date",
  50. EndDate: "end_date",
  51. Remark: "remark",
  52. BaseModifyTime: "base_modify_time",
  53. DataUpdateTime: "data_update_time",
  54. CreateTime: "create_time",
  55. ModifyTime: "modify_time",
  56. }
  57. // EdbBusinessSource
  58. // @Description: 自有数据(商家)指标来源
  59. type EdbBusinessSource struct {
  60. EdbBusinessSourceId int64 `orm:"column(edb_business_source_id);pk"`
  61. SourceName string `description:"来源名称"` // 来源名称
  62. CreateTime time.Time `description:"创建时间"` // 创建时间
  63. }
  64. // GetEdbBusinessSourceItem
  65. // @Description: 根据来源名称获取来源信息
  66. // @author: Roc
  67. // @receiver m
  68. // @datetime 2024-04-25 18:09:03
  69. // @param sourceName string
  70. // @return item *EdbBusinessSource
  71. // @return err error
  72. func (m *EdbBusinessSource) GetEdbBusinessSourceItem(sourceName string) (item *EdbBusinessSource, err error) {
  73. o := orm.NewOrmUsingDB("data")
  74. sql := `SELECT * FROM edb_business_source WHERE source_name = ? `
  75. err = o.Raw(sql, sourceName).QueryRow(&item)
  76. return
  77. }
  78. // GetAllList
  79. // @Description: 获取所有来源列表
  80. // @author: Roc
  81. // @receiver m
  82. // @datetime 2024-05-06 09:21:42
  83. // @return items []*EdbBusinessSource
  84. // @return err error
  85. func (m *EdbBusinessSource) GetAllList() (items []*EdbBusinessSource, err error) {
  86. o := orm.NewOrmUsingDB("data")
  87. sql := `SELECT * FROM edb_business_source order by edb_business_source_id desc `
  88. _, err = o.Raw(sql).QueryRows(&items)
  89. return
  90. }
  91. // GetListCount
  92. // @Description: 根据条件获取列表页的总数量
  93. // @author: Roc
  94. // @receiver m
  95. // @datetime 2024-05-06 17:15:28
  96. // @param condition string
  97. // @param pars []interface{}
  98. // @return count int
  99. // @return err error
  100. func (m *BaseFromBusinessIndex) GetListCount(condition string, pars []interface{}) (count int, err error) {
  101. sql := ` select count(1) as count FROM base_from_business_index as a WHERE 1=1 `
  102. if condition != "" {
  103. sql += condition
  104. }
  105. o := orm.NewOrmUsingDB("data")
  106. err = o.Raw(sql, pars).QueryRow(&count)
  107. return
  108. }
  109. // GetList
  110. // @Description: 根据条件获取列表页的数据
  111. // @author: Roc
  112. // @receiver m
  113. // @datetime 2024-05-06 17:15:42
  114. // @param condition string
  115. // @param pars []interface{}
  116. // @param startSize int
  117. // @param pageSize int
  118. // @return items []*BaseFromBusinessIndex
  119. // @return err error
  120. func (m *BaseFromBusinessIndex) GetList(condition string, pars []interface{}, startSize, pageSize int) (items []*BaseFromBusinessIndex, err error) {
  121. sql := `select * FROM base_from_business_index AS a WHERE 1=1 `
  122. if condition != "" {
  123. sql += condition
  124. }
  125. sql += ` order by a.base_from_business_index_id desc limit ?,? `
  126. o := orm.NewOrmUsingDB("data")
  127. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  128. return
  129. }
  130. // BusinessIndexListResp
  131. // @Description: 外部(商家)指标列表返回
  132. type BusinessIndexListResp struct {
  133. List []*BaseFromBusinessIndexItem
  134. Paging *paging.PagingItem `description:"分页数据"`
  135. }
  136. // BaseFromBusinessIndexItem
  137. // @Description: 外部指标(商家系统)结构
  138. type BaseFromBusinessIndexItem struct {
  139. BaseFromBusinessIndexId int64 `orm:"column(base_from_business_index_id);pk"`
  140. IndexCode string `description:"指标编码"`
  141. IndexName string `description:"指标名称"`
  142. Unit string `description:"单位"`
  143. Frequency string `description:"频度"`
  144. Source int `description:"数据来源"`
  145. SourceName string `description:"数据来源名称"`
  146. StartDate string `description:"开始日期"`
  147. EndDate string `description:"结束日期"`
  148. Remark string `description:"备注字段"`
  149. BaseModifyTime string `description:"基础信息(名称,单位,频度)变更时间"`
  150. DataUpdateTime string `description:"最近一次数据发生变化的时间"`
  151. CreateTime string `description:"创建时间"`
  152. ModifyTime string `description:"修改时间"`
  153. EdbInfoId int `description:"eta指标库的id"`
  154. EdbUniqueCode string `description:"指标库唯一编码"`
  155. EdbClassifyId int `description:"指标库分类ID"`
  156. EdbExist int `description:"指标库是否已添加:0-否;1-是"`
  157. }
  158. func (m *BaseFromBusinessIndex) GetPageItemsByCondition(condition string, pars []interface{}, orderRule string, startSize, pageSize int) (items []*BaseFromBusinessIndexItem, err error) {
  159. sql := `select a.*,b.edb_info_id,b.unique_code as edb_unique_code,b.classify_id as edb_classify_id FROM base_from_business_index AS a LEFT JOIN edb_info b on a.index_code=b.edb_code AND b.source=? WHERE 1=1 `
  160. if condition != "" {
  161. sql += condition
  162. }
  163. if orderRule == `` {
  164. sql += ` order by a.base_from_business_index_id desc`
  165. } else {
  166. sql += ` order by ` + orderRule
  167. }
  168. sql += ` limit ?,? `
  169. o := orm.NewOrmUsingDB("data")
  170. _, err = o.Raw(sql, utils.DATA_SOURCE_BUSINESS, pars, startSize, pageSize).QueryRows(&items)
  171. return
  172. }
  173. // GeItemsByCondition
  174. // @Description: 根据条件获取指定数量的指标
  175. // @author: Roc
  176. // @receiver m
  177. // @datetime 2024-05-06 17:16:02
  178. // @param condition string
  179. // @param pars []interface{}
  180. // @param limitSize int
  181. // @return items []*BaseFromBusinessIndexItem
  182. // @return err error
  183. func (m *BaseFromBusinessIndex) GeItemsByCondition(condition string, pars []interface{}, limitSize int) (items []*BaseFromBusinessIndexItem, err error) {
  184. if pars == nil {
  185. pars = make([]interface{}, 0)
  186. }
  187. sql := `select a.*,b.edb_info_id,b.unique_code as edb_unique_code,b.classify_id as edb_classify_id FROM base_from_business_index AS a LEFT JOIN edb_info b on a.index_code=b.edb_code AND b.source=? WHERE 1=1 `
  188. if condition != "" {
  189. sql += condition
  190. }
  191. sql += ` order by a.base_from_business_index_id desc `
  192. if limitSize > 0 {
  193. sql += " limit ? "
  194. pars = append(pars, limitSize)
  195. }
  196. o := orm.NewOrmUsingDB("data")
  197. _, err = o.Raw(sql, utils.DATA_SOURCE_BUSINESS, pars).QueryRows(&items)
  198. return
  199. }
  200. // GetDetailByEdbCode
  201. // @Description: 根据edbCode获取指标详情
  202. // @author: Roc
  203. // @receiver m
  204. // @datetime 2024-05-07 11:00:07
  205. // @param edbCode string
  206. // @return item *BaseFromBusinessIndex
  207. // @return err error
  208. func (m *BaseFromBusinessIndex) GetDetailByEdbCode(edbCode string) (item *BaseFromBusinessIndex, err error) {
  209. sql := `select * FROM base_from_business_index WHERE index_code = ? `
  210. o := orm.NewOrmUsingDB("data")
  211. err = o.Raw(sql, edbCode).QueryRow(&item)
  212. return
  213. }
  214. // BusinessIndexDataListResp
  215. // @Description: 外部(商家)指标数据列表返回
  216. type BusinessIndexDataListResp struct {
  217. List []*BaseFromBusinessIndexDataItem
  218. Paging *paging.PagingItem `description:"分页数据"`
  219. }
  220. // BaseFromBusinessIndexDataItem
  221. // @Description: 外部指标(商家系统)数据结构
  222. type BaseFromBusinessIndexDataItem struct {
  223. ID string
  224. EdbDataId int `orm:"column(edb_data_id);pk"`
  225. IndexCode string
  226. DataTime string
  227. Value float64
  228. }