query.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. package my_chart_classify_mapping
  2. import (
  3. "hongze/hongze_yb/global"
  4. )
  5. // GetMyChartSort 获取我的图表排序
  6. func GetMyChartSort(adminId, myChartClassifyId, sort int) (item *MyChartClassifyMapping, err error) {
  7. sql := ` SELECT * FROM my_chart_classify_mapping WHERE 1=1 AND admin_id = ? AND my_chart_classify_id = ? `
  8. if sort == 1 {
  9. sql += ` ORDER BY sort DESC LIMIT 1 `
  10. } else {
  11. sql += ` ORDER BY sort ASC LIMIT 1 `
  12. }
  13. err = global.MYSQL["data"].Raw(sql, adminId, myChartClassifyId).First(&item).Error
  14. return
  15. }
  16. // GetMyChartClassifyMapping 获取图表分类关联信息
  17. func GetMyChartClassifyMapping(adminId, myChartId, myChartClassifyId int) (item *MyChartClassifyMapping, err error) {
  18. sql := `SELECT * FROM my_chart_classify_mapping WHERE admin_id=? AND my_chart_id=? AND my_chart_classify_id=? `
  19. err = global.MYSQL["data"].Raw(sql, adminId, myChartId, myChartClassifyId).First(&item).Error
  20. return
  21. }
  22. type MyChartSortInfo struct {
  23. ChartInfoId int `description:"图表ID"`
  24. ChartInfoSource int `description:"1:ETA图库;2:商品价格"`
  25. MyChartId int `description:"我的图表ID"`
  26. MyChartClassifyId int `description:"我的图表分类ID"`
  27. MyChartClassifyName string `description:"我的图表分类名称"`
  28. UniqueCode string `description:"图表唯一编码"`
  29. Sort float64 `description:"排序"`
  30. }
  31. // GetClassifyChartSort 获取指定分类图表排序
  32. func GetClassifyChartSort(myChartClassifyId, sort int) (item []*MyChartClassifyMapping, err error) {
  33. sql := ` SELECT * FROM my_chart_classify_mapping WHERE 1=1 AND my_chart_classify_id = ? `
  34. if sort == 1 {
  35. sql += ` ORDER BY sort DESC `
  36. } else {
  37. sql += ` ORDER BY sort ASC `
  38. }
  39. err = global.MYSQL["data"].Raw(sql, myChartClassifyId).Scan(&item).Error
  40. return
  41. }
  42. // GetMyChartSortInfoList 获取我的图表信息
  43. func GetMyChartSortInfoList(myChartClassifyId string, sort int) (item []*MyChartSortInfo, err error) {
  44. sql := `SELECT
  45. a.my_chart_id,
  46. a.my_chart_classify_id,
  47. a.sort,
  48. c.chart_info_id,
  49. c.source as chart_info_source,
  50. c.unique_code,
  51. d.my_chart_classify_name
  52. FROM
  53. my_chart_classify_mapping AS a
  54. INNER JOIN
  55. my_chart AS b ON a.my_chart_id = b.my_chart_id
  56. INNER JOIN
  57. chart_info AS c ON b.chart_info_id = c.chart_info_id
  58. INNER JOIN
  59. my_chart_classify AS d ON a.my_chart_classify_id = d.my_chart_classify_id
  60. WHERE
  61. 1 = 1
  62. AND a.my_chart_classify_id = ? `
  63. //GROUP BY c.chart_info_id `
  64. if sort == 1 {
  65. sql += ` ORDER BY sort DESC `
  66. } else {
  67. sql += ` ORDER BY sort ASC `
  68. }
  69. err = global.MYSQL["data"].Raw(sql, myChartClassifyId).Scan(&item).Error
  70. return
  71. }