query.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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.MYSQL["rddp"].Where(" product_id = ?", productId).Find(&list).Error
  10. return
  11. }
  12. // GetFiccListExceptTacticByProductId 获取ficc 除了市场策略的所有权限
  13. func GetFiccListExceptTacticByProductId() (list []*ChartPermission, err error) {
  14. err = global.MYSQL["rddp"].Where(" enabled = 1 AND permission_type = 0 AND product_id = 1 and parent_id >0 and classify_name != '市场策略'").Order("sort asc").Find(&list).Error
  15. return
  16. }
  17. // GetClassNameListByProductId 根据权限id获取权限分类
  18. func GetClassNameListByProductId(productId int64) (list []*ChartPermission, err error) {
  19. err = global.MYSQL["rddp"].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.MYSQL["rddp"].Where(cond, whereVal...).Find(&list).Error
  30. return
  31. }
  32. // GetListByIds 通过IDs获取图表权限集合
  33. func GetListByIds(permissionIds []int) (list []*ChartPermission, err error) {
  34. err = global.MYSQL["rddp"].Model(ChartPermission{}).Where("chart_permission_id IN (?)", permissionIds).Scan(&list).Error
  35. return
  36. }
  37. // GetListByProductIdAndPermissionType 根据product及classify_name获取集合
  38. func GetListByProductIdAndPermissionType(productId int) (items []*ChartPermission, err error) {
  39. err = global.MYSQL["rddp"].Model(ChartPermission{}).Where("enabled = 1 AND permission_type = 0 AND product_id = ? ", productId).Order("sort ASC").Scan(&items).Error
  40. return
  41. }
  42. // GetByChartPermissionId 根据chartPermissionId 查找权限基本信息
  43. func GetByChartPermissionId(chartPermissionId int) (item *ChartPermission, err error) {
  44. err = global.MYSQL["rddp"].Model(ChartPermission{}).Where("chart_permission_id = ?", chartPermissionId).First(&item).Error
  45. if err == utils.ErrNoRow {
  46. err = nil
  47. }
  48. return
  49. }
  50. // GetFiccFirstListExceptTacticByProductId 获取ficc 除了市场策略的所有父级
  51. func GetFiccFirstListExceptTacticByProductId() (list []*ChartPermission, err error) {
  52. err = global.MYSQL["rddp"].Where(" enabled = 1 AND permission_type = 0 AND product_id = 1 and classify_name != '市场策略' AND parent_id = 0").Order("sort asc").Find(&list).Error
  53. return
  54. }
  55. // GetChartPermissionsByProductId 获取权限列表
  56. func GetChartPermissionsByProductId() (list []*ChartPermission, err error) {
  57. err = global.MYSQL["rddp"].Where(" enabled = 1 AND product_id = 1").Order("parent_id ASC, sort ASC, created_time ASC").Find(&list).Error
  58. return
  59. }
  60. type SimpleChartPermission struct {
  61. ChartPermissionId int `description:"品种ID" json:"chart_permission_id"`
  62. ChartPermissionName string `description:"品种名称" json:"chart_permission_name"`
  63. Sort int `description:"排序" json:"sort"`
  64. Children []*SimpleChartPermission `description:"子分类" json:"children"`
  65. }
  66. func FormatChartPermission2Simple(origin *ChartPermission) (item *SimpleChartPermission) {
  67. if origin == nil {
  68. return
  69. }
  70. item = new(SimpleChartPermission)
  71. item.ChartPermissionId = int(origin.ChartPermissionID)
  72. item.ChartPermissionName = origin.PermissionName
  73. item.Sort = origin.Sort
  74. return
  75. }