query.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. // GetClassNameListByProductId 根据权限id获取权限分类
  18. func GetClassNameListByProductId(productId int64) (list []*ChartPermission, err error) {
  19. err = global.DEFAULT_MYSQL.Where(" product_id = ?", productId).Group("classify_name").Find(&list).Error
  20. return
  21. }
  22. // GetByWhereMap 根据查询条件map获取信息
  23. func GetByWhereMap(where map[string]interface{}) (list []*ChartPermission, err error) {
  24. cond, whereVal, buildErr := utils.WhereBuild(where)
  25. if buildErr != nil {
  26. err = errors.New("系统异常,生成查询语句失败")
  27. return
  28. }
  29. err = global.DEFAULT_MYSQL.Where(cond, whereVal...).Find(&list).Error
  30. return
  31. }
  32. // GetListByIds 通过IDs获取图表权限集合
  33. func GetListByIds(permissionIds []int) (list []*ChartPermission, err error) {
  34. err = global.DEFAULT_MYSQL.Model(ChartPermission{}).Where("chart_permission_id IN (?)", permissionIds).Scan(&list).Error
  35. return
  36. }
  37. // GetListByProductIdAndClassifyName 根据product及classify_name获取集合
  38. func GetListByProductIdAndClassifyName(productId int, classifyName string) (items []*ChartPermission, err error) {
  39. 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
  40. return
  41. }
  42. // GetByChartPermissionId 根据chartPermissionId 查找权限基本信息
  43. func GetByChartPermissionId(chartPermissionId int) (item *ChartPermission, err error) {
  44. err = global.DEFAULT_MYSQL.Model(ChartPermission{}).Where("chart_permission_id = ?", chartPermissionId).First(&item).Error
  45. if err == utils.ErrNoRow {
  46. err = nil
  47. }
  48. return
  49. }