query.go 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. package chart_info
  2. import (
  3. "hongze/hongze_yb/global"
  4. "time"
  5. )
  6. type ChartInfoView struct {
  7. ChartInfoId int `description:"图表ID"`
  8. ChartName string `description:"来源名称"`
  9. ChartClassifyId int `description:"图表分类id"`
  10. ChartClassifyName string `description:"图表名称"`
  11. SysUserId int
  12. SysUserRealName string
  13. UniqueCode string `description:"图表唯一编码"`
  14. CreateTime time.Time `json:"-"`
  15. ModifyTime time.Time `json:"-"`
  16. DateType int `description:"日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间"`
  17. StartDate string `description:"自定义开始日期"`
  18. EndDate string `description:"自定义结束日期"`
  19. IsSetName int `description:"设置名称"`
  20. EdbInfoIds string `description:"指标id"`
  21. ChartType int `description:"生成样式:1:曲线图,2:季节性图"`
  22. Calendar string `description:"公历/农历"`
  23. SeasonStartDate string `description:"季节性图开始日期"`
  24. SeasonEndDate string `description:"季节性图开始日期"`
  25. ChartImage string `description:"图表图片"`
  26. Sort int `description:"排序字段,数字越小越排前面"`
  27. IsAdd bool `description:"true:已加入我的图库,false:未加入我的图库"`
  28. MyChartId int
  29. MyChartClassifyId string `description:"我的图表分类,多个用逗号隔开"`
  30. EdbEndDate string `description:"指标最新更新日期"`
  31. LeftMin string `description:"图表左侧最小值"`
  32. LeftMax string `description:"图表左侧最大值"`
  33. RightMin string `description:"图表右侧最小值"`
  34. RightMax string `description:"图表右侧最大值"`
  35. Right2Min string `description:"图表右侧2最小值"`
  36. Right2Max string `description:"图表右侧2最大值"`
  37. MinMaxSave int `description:"是否手动保存过上下限:0-否;1-是"`
  38. ChartSource string `description:"图表来源str"`
  39. ChartSourceEn string `description:"图表来源(英文)"`
  40. BarConfig string `description:"柱方图的配置,json数据" json:"-"`
  41. ChartNameEn string `description:"英文图表名称"`
  42. Unit string `description:"中文单位名称"`
  43. UnitEn string `description:"英文单位名称"`
  44. Source int `description:"1:ETA图库;2:商品价格"`
  45. ExtraConfig string `description:"图表额外配置,json数据"`
  46. //ChartClassify []*chart_classify.ChartClassifyView
  47. SeasonExtraConfig string `description:"季节性图表中的配置,json数据"`
  48. StartYear int `description:"当选择的日期类型为最近N年类型时,即date_type=20, 用start_year表示N"`
  49. ChartThemeId int `description:"图表应用主题ID"`
  50. ChartThemeStyle string `description:"图表应用主题样式"`
  51. SourcesFrom string `description:"图表来源"`
  52. Instructions string `description:"图表说明"`
  53. MarkersLines string `description:"标识线"`
  54. MarkersAreas string `description:"标识区"`
  55. }
  56. type SaveChartInfoReq struct {
  57. ChartEdbInfoList []*ChartSaveItem `description:"指标及配置信息"`
  58. ChartInfoId int `description:"图表id,新增时传0"`
  59. DateType int `description:"日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间,6:起始日期至今"`
  60. StartDate string `description:"自定义开始日期"`
  61. EndDate string `description:"自定义结束日期"`
  62. Calendar string `description:"公历/农历"`
  63. SeasonStartDate string `description:"季节性图开始日期"`
  64. SeasonEndDate string `description:"季节性图开始日期"`
  65. LeftMin string `description:"图表左侧最小值"`
  66. LeftMax string `description:"图表左侧最大值"`
  67. RightMin string `description:"图表右侧最小值"`
  68. RightMax string `description:"图表右侧最大值"`
  69. ExtraConfig string `description:"图表额外配置信息,json字符串"`
  70. }
  71. type ChartSaveItem struct {
  72. EdbInfoId int `description:"指标id"`
  73. MaxData float64 `description:"上限"`
  74. MinData float64 `description:"下限"`
  75. IsOrder bool `description:"true:正序,false:逆序"`
  76. IsAxis int `description:"1:左轴,0:右轴"`
  77. EdbInfoType int `description:"1:标准指标,0:领先指标"`
  78. LeadValue int `description:"领先值"`
  79. LeadUnit string `description:"领先单位"`
  80. ChartStyle string `description:"图表类型"`
  81. ChartColor string `description:"颜色"`
  82. ChartWidth float64 `description:"线条大小"`
  83. Source int `description:"1:ETA图库;2:商品价格"`
  84. }
  85. type ChartSortInfo struct {
  86. ChartInfoId int `description:"图表ID"`
  87. ChartInfoSource int `description:"1:ETA图库;2:商品价格"`
  88. MyChartId int `description:"我的图表ID"`
  89. MyChartClassifyId int `description:"我的图表分类ID"`
  90. MyChartClassifyName string `description:"我的图表分类名称"`
  91. UniqueCode string `description:"图表唯一编码"`
  92. Sort int `description:"排序"`
  93. Switch int `description:"是否切换 0-未切换 1-已切换"`
  94. //SwitchTips string `description:"切换分类提示信息"`
  95. }
  96. type ChartBeforeNext struct {
  97. PrevChart ChartSortInfo
  98. NextChart ChartSortInfo
  99. }
  100. type RefreshChartInfoReq struct {
  101. ChartInfoId int
  102. }
  103. // GetChartInfoViewById 通过Id获取图表展示信息
  104. func GetChartInfoViewById(chartInfoId int) (item *ChartInfoView, err error) {
  105. sql := `SELECT * FROM chart_info WHERE chart_info_id = ? `
  106. err = global.MYSQL["data"].Raw(sql, chartInfoId).First(&item).Error
  107. //err = global.MYSQL["data"].Model(ChartInfo{}).Where("chart_info_id = ?", chartInfoId).First(&item).Error
  108. return
  109. }
  110. // GetChartInfoViewById 通过ID获取图表数据库信息
  111. func GetChartInfoById(chartInfoId int) (item *ChartInfo, err error) {
  112. err = global.MYSQL["data"].Model(ChartInfo{}).Where("chart_info_id = ?", chartInfoId).First(&item).Error
  113. return
  114. }
  115. // GetChartInfoViewByUniqueCode 通过唯一编码获取图表展示信息
  116. func GetChartInfoViewByUniqueCode(uniqueCode string) (item *ChartInfoView, err error) {
  117. sql := `SELECT * FROM chart_info WHERE unique_code = ? LIMIT 1`
  118. err = global.MYSQL["data"].Raw(sql, uniqueCode).First(&item).Error
  119. return
  120. }
  121. type ChartSectionSeriesValSortAsc []ChartSectionSeriesValSort
  122. type ChartSectionSeriesValSortDesc []ChartSectionSeriesValSort
  123. type ChartSectionSeriesValSort struct {
  124. Index int
  125. Value float64
  126. }
  127. func (s ChartSectionSeriesValSortAsc) Len() int {
  128. return len(s)
  129. }
  130. func (s ChartSectionSeriesValSortAsc) Less(i, j int) bool {
  131. return s[i].Value < s[j].Value // 升序排序,如果想要降序则改为 s[i].Value > s[j].Value
  132. }
  133. func (s ChartSectionSeriesValSortAsc) Swap(i, j int) {
  134. s[i], s[j] = s[j], s[i]
  135. }
  136. func (s ChartSectionSeriesValSortDesc) Len() int {
  137. return len(s)
  138. }
  139. func (s ChartSectionSeriesValSortDesc) Less(i, j int) bool {
  140. return s[i].Value > s[j].Value // 升序排序,如果想要降序则改为 s[i].Value > s[j].Value
  141. }
  142. func (s ChartSectionSeriesValSortDesc) Swap(i, j int) {
  143. s[i], s[j] = s[j], s[i]
  144. }