query.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package chart_permission
  2. import (
  3. "errors"
  4. "hongze/hongze_yb/global"
  5. "hongze/hongze_yb/utils"
  6. )
  7. // GetListByProductId 根据产品id获取所有权限列表
  8. func GetListByProductId(productId int64) (list []*ChartPermission, err error) {
  9. err = global.DEFAULT_MYSQL.Where(" product_id = ?", productId).Find(&list).Error
  10. return
  11. }
  12. // GetFiccListExceptTacticByProductId 获取ficc 除了市场策略的所有权限
  13. func GetFiccListExceptTacticByProductId() (list []*ChartPermission, err error) {
  14. err = global.DEFAULT_MYSQL.Where(" enabled = 1 AND permission_type = 0 AND product_id = 1 and classify_name != '市场策略'").Find(&list).Error
  15. return
  16. }
  17. // GetFiccListExceptTacticByProductIdOrderSort 获取ficc 除了市场策略的所有权限
  18. func GetFiccListExceptTacticByProductIdOrderSort() (list []*ChartPermission, err error) {
  19. err = global.DEFAULT_MYSQL.Where(" enabled = 1 AND permission_type = 0 AND product_id = 1 and classify_name != '市场策略'").
  20. Order("sort asc").Find(&list).Error
  21. return
  22. }
  23. // GetClassNameListByProductId 根据权限id获取权限分类
  24. func GetClassNameListByProductId(productId int64) (list []*ChartPermission, err error) {
  25. err = global.DEFAULT_MYSQL.Where(" product_id = ?", productId).Group("classify_name").Find(&list).Error
  26. return
  27. }
  28. // GetByWhereMap 根据查询条件map获取信息
  29. func GetByWhereMap(where map[string]interface{}) (list []*ChartPermission, err error) {
  30. cond, whereVal, buildErr := utils.WhereBuild(where)
  31. if buildErr != nil {
  32. err = errors.New("系统异常,生成查询语句失败")
  33. return
  34. }
  35. err = global.DEFAULT_MYSQL.Where(cond, whereVal...).Find(&list).Error
  36. return
  37. }
  38. // GetListByIds 通过IDs获取图表权限集合
  39. func GetListByIds(permissionIds []int) (list []*ChartPermission, err error) {
  40. err = global.DEFAULT_MYSQL.Model(ChartPermission{}).Where("chart_permission_id IN (?)", permissionIds).Scan(&list).Error
  41. return
  42. }
  43. // GetListByProductIdAndClassifyName 根据product及classify_name获取集合
  44. func GetListByProductIdAndClassifyName(productId int, classifyName string) (items []*ChartPermission, err error) {
  45. err = global.DEFAULT_MYSQL.Model(ChartPermission{}).Where("enabled = 1 AND permission_type = 0 AND product_id = ? AND classify_name = ?", productId, classifyName).Order("sort ASC").Scan(&items).Error
  46. return
  47. }
  48. // GetByChartPermissionId 根据chartPermissionId 查找权限基本信息
  49. func GetByChartPermissionId(chartPermissionId int) (item *ChartPermission, err error) {
  50. err = global.DEFAULT_MYSQL.Model(ChartPermission{}).Where("chart_permission_id = ?", chartPermissionId).First(&item).Error
  51. if err == utils.ErrNoRow {
  52. err = nil
  53. }
  54. return
  55. }