eta_business_chart_permission.go 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. package data_manage
  2. import (
  3. "eta/eta_hub/utils"
  4. "fmt"
  5. "time"
  6. "github.com/beego/beego/v2/client/orm"
  7. "github.com/rdlucklib/rdluck_tools/paging"
  8. )
  9. // EtaBusinessChartPermission 商家图表权限表
  10. type EtaBusinessChartPermission struct {
  11. EtaBusinessChartPermissionId int64 `orm:"column(eta_business_chart_permission_id);pk;auto"`
  12. ChartInfoId int `orm:"column(chart_info_id)" description:"图表id"`
  13. Source int `orm:"column(source)" description:"分类来源: 1-图库; 2-商品价格曲线; 3-相关性图表; 6-拟合方程图表; 7-统计特征"`
  14. BusinessCode string `orm:"column(business_code)" description:"客户编码"`
  15. EtaBusinessId int `orm:"column(eta_business_id)" description:"商家ID"`
  16. ModifyTime time.Time `orm:"column(modify_time);type(datetime);null" description:"变更时间"`
  17. CreateTime time.Time `orm:"column(create_time);type(datetime);null" description:"关系建立时间"`
  18. }
  19. // TableName 设置表名
  20. func (m *EtaBusinessChartPermission) TableName() string {
  21. return "eta_business_chart_permission"
  22. }
  23. type BusinessChartInfoView struct {
  24. ChartInfoId int
  25. ChartName string
  26. UniqueCode string
  27. Description []string
  28. EdbInfoList []*BusinessChartEdbListItem
  29. }
  30. // GetChartListByBusinessCode 根据商家编码获取图表列表
  31. func (m *EtaBusinessChartPermission) GetChartListByBusinessCode(businessCode string, startSize int, pageSize int) ([]*BusinessChartInfoView, error) {
  32. if businessCode == "" {
  33. return nil, fmt.Errorf("business code cannot be empty")
  34. }
  35. var chartList []*BusinessChartInfoView
  36. o := orm.NewOrmUsingDB("data")
  37. // 构建SQL查询
  38. sql := `
  39. SELECT
  40. c.chart_info_id, c.chart_name, c.unique_code
  41. FROM
  42. eta_business_chart_permission p
  43. JOIN
  44. chart_info c ON p.chart_info_id = c.chart_info_id
  45. WHERE
  46. p.business_code = ?
  47. ORDER BY
  48. c.sort ASC, c.chart_info_id DESC
  49. LIMIT ?, ?
  50. `
  51. _, err := o.Raw(sql, businessCode, startSize, pageSize).QueryRows(&chartList)
  52. if err != nil {
  53. return nil, fmt.Errorf("failed to get chart list: %v", err)
  54. }
  55. return chartList, nil
  56. }
  57. func (m *EtaBusinessChartPermission) GetChartListByBusinessCodeTotal(businessCode string) (int64, error) {
  58. o := orm.NewOrmUsingDB("data")
  59. sql := `
  60. SELECT COUNT(*) FROM eta_business_chart_permission p
  61. JOIN
  62. chart_info c ON p.chart_info_id = c.chart_info_id
  63. WHERE
  64. p.business_code = ?
  65. `
  66. var total int64
  67. err := o.Raw(sql, businessCode).QueryRow(&total)
  68. if err != nil {
  69. return 0, fmt.Errorf("failed to get chart list total: %v", err)
  70. }
  71. return total, nil
  72. }
  73. // GetChartInfoByUniqueCode 根据唯一编码获取图表信息
  74. func (m *EtaBusinessChartPermission) GetChartInfoByUniqueCode(businessCode string, uniqueCode string) (chartInfo *BusinessChartInfoView, err error) {
  75. o := orm.NewOrmUsingDB("data")
  76. sql := `
  77. SELECT
  78. c.chart_info_id, c.chart_name, c.unique_code
  79. FROM
  80. eta_business_chart_permission p
  81. JOIN
  82. chart_info c ON p.chart_info_id = c.chart_info_id
  83. WHERE
  84. p.business_code = ? AND c.unique_code = ?
  85. `
  86. err = o.Raw(sql, businessCode, uniqueCode).QueryRow(&chartInfo)
  87. return
  88. }
  89. // Init 初始化表结构
  90. func init() {
  91. orm.RegisterModel(new(EtaBusinessChartPermission))
  92. }
  93. type BusinessChartInfoResp struct {
  94. List []*BusinessChartInfoView
  95. Paging *paging.PagingItem
  96. }
  97. type BusinessChartEdbListResp struct {
  98. List []*BusinessChartEdbListItem
  99. }
  100. type BusinessChartEdbListItem struct {
  101. EdbInfoId int
  102. EdbCode string
  103. EdbName string
  104. EdbInfoType int
  105. Frequency string
  106. Unit string
  107. EndDate string
  108. EndValue float64
  109. LatestDate string
  110. LatestValue float64
  111. UniqueCode string
  112. }
  113. type ChartDescription struct {
  114. ChartInfoId int
  115. Description string
  116. }
  117. // 查询图表描述列表
  118. func (m *EtaBusinessChartPermission) GetChartDescriptionListByChartInfoIds(chartInfoIds []int) (list []*ChartDescription, err error) {
  119. o := orm.NewOrmUsingDB("data")
  120. sql := `
  121. SELECT * FROM chart_description WHERE chart_info_id IN (`+utils.GetOrmInReplace(len(chartInfoIds))+`) ORDER BY id DESC
  122. `
  123. _, err = o.Raw(sql, chartInfoIds).QueryRows(&list)
  124. return list, err
  125. }
  126. func (m *EtaBusinessChartPermission) GetChartDescriptionListByChartInfoId(chartInfoId int) (list []*ChartDescription, err error) {
  127. o := orm.NewOrmUsingDB("data")
  128. sql := `
  129. SELECT * FROM chart_description WHERE chart_info_id = ? ORDER BY id DESC
  130. `
  131. _, err = o.Raw(sql, chartInfoId).QueryRows(&list)
  132. return
  133. }
  134. type BusinessChartDetailResp struct {
  135. ChartInfoId int
  136. ChartName string
  137. UniqueCode string
  138. Description []string
  139. EdbInfoList []TraceEdbInfoMoreResp
  140. }
  141. // GetChartListByBusinessCode 根据商家编码获取图表列表
  142. func (m *EtaBusinessChartPermission) GetChartCountByBusinessCodeAndEdbInfoId(businessCode string, edbInfoId int) (count int64, err error) {
  143. if businessCode == "" {
  144. return 0, fmt.Errorf("business code cannot be empty")
  145. }
  146. o := orm.NewOrmUsingDB("data")
  147. // 构建SQL查询
  148. sql := `
  149. SELECT
  150. COUNT(DISTINCT p.chart_info_id)
  151. FROM
  152. eta_business_chart_permission p
  153. JOIN
  154. chart_edb_mapping c ON p.chart_info_id = c.chart_info_id
  155. WHERE
  156. p.business_code = ? AND c.edb_info_id = ?
  157. `
  158. err = o.Raw(sql, businessCode, edbInfoId).QueryRow(&count)
  159. return
  160. }