query.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package my_chart_classify
  2. import (
  3. "errors"
  4. "hongze/hongze_yb/global"
  5. "hongze/hongze_yb/utils"
  6. )
  7. // GetClassifyListByCondition 根据条件获取图表分类列表
  8. func GetClassifyListByCondition(condition map[string]interface{}, sort string) (list []*MyChartClassify, err error) {
  9. maps, values, buildErr := utils.WhereBuild(condition)
  10. if buildErr != nil {
  11. err = errors.New("系统异常,生成查询语句失败")
  12. return
  13. }
  14. err = global.MYSQL["data"].Model(MyChartClassify{}).Where(maps, values...).Order(sort).Scan(&list).Error
  15. return
  16. }
  17. // GetClassifyById 根据主键获取分类信息
  18. func GetClassifyById(chartClassifyId int) (item *MyChartClassify, err error) {
  19. err = global.MYSQL["data"].Model(MyChartClassify{}).Where("my_chart_classify_id = ?", chartClassifyId).First(&item).Error
  20. return
  21. }
  22. // GetClassifyByIdAndAdminId 根据ID及adminId获取分类信息
  23. func GetClassifyByIdAndAdminId(adminId, myChartClassifyId int) (item *MyChartClassify, err error) {
  24. err = global.MYSQL["data"].Model(MyChartClassify{}).Where("my_chart_classify_id = ? AND admin_id = ?", myChartClassifyId, adminId).First(&item).Error
  25. return
  26. }
  27. // GetFirstClassifyByAdminId 获取账号排序第一条的分类数据
  28. func GetFirstClassifyByAdminId(adminId int) (item *MyChartClassify, err error) {
  29. sql := ` SELECT * FROM my_chart_classify WHERE admin_id=? order by sort asc,my_chart_classify_id asc limit 1`
  30. err = global.MYSQL["data"].Raw(sql, adminId).Scan(&item).Error
  31. return
  32. }