query.go 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. package my_chart
  2. import (
  3. "hongze/hongze_yb/global"
  4. "time"
  5. )
  6. type MyChartList struct {
  7. MyChartId int `description:"我的图表主键"`
  8. ChartInfoId int
  9. ChartName string `description:"来源名称"`
  10. ChartClassifyId int `description:"图表分类id"`
  11. SysUserId int
  12. SysUserRealName string
  13. UniqueCode string `description:"图表唯一编码"`
  14. CreateTime time.Time
  15. ModifyTime time.Time
  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 float64 `description:"排序字段,数字越小越排前面"`
  27. IsAdd bool `description:"true:已加入我的图库,false:未加入我的图库"`
  28. MyChartClassifyName string `description:"分类名称,多个用英文逗号分割"`
  29. MyChartClassifyId string `description:"分类id,多个用英文逗号分割"`
  30. EdbEndDate string `description:"指标最新更新日期"`
  31. Source int `description:"1:ETA图库;2:商品价格"`
  32. }
  33. type MyChartView struct {
  34. MyChartId int `description:"我的图表id"`
  35. ChartInfoId int `description:"图表id"`
  36. AdminId int `description:"用户id"`
  37. CreateTime time.Time `description:"创建时间"`
  38. ModifyTime time.Time `description:"修改时间"`
  39. MyChartClassifyId string `description:"我的图表分类ID"`
  40. //Sort int `description:"我的图表排序"`
  41. }
  42. type MoveMyChartReq struct {
  43. MyChartId int `description:"移动的,我的图表图表ID"`
  44. PrevMyChartId int `description:"移动到的位置,上一级的,我的图表ID,如果没有上一级,则传0"`
  45. NextMyChartId int `description:"移动到的位置,下一级的,我的图表ID,如果没有下一级,则传0"`
  46. MyChartClassifyId int `description:"当前分类id"`
  47. }
  48. type MoveMyChartClassifyReq struct {
  49. MyChartClassifyId int `description:"分类id"`
  50. PrevClassifyId int `description:"上一个兄弟节点分类id"`
  51. NextClassifyId int `description:"下一个兄弟节点分类id"`
  52. }
  53. // GetMyChartListByCondition 条件获取我的图表列表
  54. func GetMyChartListByCondition(condition string, pars []interface{}, page, limit int) (list []*MyChartList, err error) {
  55. sql := ` SELECT a.my_chart_id,c.sort,b.* FROM my_chart AS a
  56. INNER JOIN chart_info AS b ON a.chart_info_id=b.chart_info_id
  57. INNER JOIN my_chart_classify_mapping AS c ON a.my_chart_id=c.my_chart_id
  58. INNER JOIN my_chart_classify AS d ON c.my_chart_classify_id=d.my_chart_classify_id
  59. WHERE 1=1 `
  60. if condition != "" {
  61. sql += condition
  62. }
  63. sql += " GROUP BY a.chart_info_id ORDER BY c.sort ASC LIMIT ?,? "
  64. offset := (page - 1) * limit
  65. pars = append(pars, offset, limit)
  66. err = global.MYSQL["data"].Raw(sql, pars...).Scan(&list).Error
  67. return
  68. }
  69. // GetMyChartByCondition 条件获取我的图表
  70. func GetMyChartByCondition(condition string, pars []interface{}) (list []*MyChartView, err error) {
  71. sql := ` SELECT a.*,GROUP_CONCAT(c.my_chart_classify_id SEPARATOR ',') AS my_chart_classify_id FROM my_chart AS a
  72. LEFT JOIN my_chart_classify_mapping AS b ON a.my_chart_id=b.my_chart_id AND a.admin_id=b.admin_id
  73. LEFT JOIN my_chart_classify AS c ON b.my_chart_classify_id=c.my_chart_classify_id AND b.admin_id=c.admin_id
  74. WHERE 1=1 `
  75. if condition != "" {
  76. sql += condition
  77. }
  78. sql += ` GROUP BY a.chart_info_id `
  79. err = global.MYSQL["data"].Raw(sql, pars).Scan(&list).Error
  80. return
  81. }
  82. // GetMyChartById 主键获取我的图表
  83. func GetMyChartById(myChartId int, myChartClassifyId string) (item *MyChartView, err error) {
  84. sql := ` SELECT a.*,b.sort,c.my_chart_classify_id FROM my_chart AS a
  85. INNER JOIN my_chart_classify_mapping AS b ON a.my_chart_id=b.my_chart_id AND a.admin_id=b.admin_id
  86. INNER JOIN my_chart_classify AS c ON b.my_chart_classify_id=c.my_chart_classify_id AND b.admin_id=c.admin_id
  87. WHERE 1=1 AND a.my_chart_id = ? AND b.my_chart_classify_id = ?`
  88. err = global.MYSQL["data"].Raw(sql, myChartId, myChartClassifyId).First(&item).Error
  89. return
  90. }