chart.go 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. package data_manage_permission
  2. import (
  3. "eta_gn/eta_api/models/data_manage"
  4. "eta_gn/eta_api/models/data_manage/data_manage_permission"
  5. "eta_gn/eta_api/utils"
  6. "fmt"
  7. )
  8. func CheckChartPermissionByPermissionIdList(chartIsJoinPermission, chartClassifyIsJoinPermission, chartInfoId, chartClassifyId int, permissionChartInfoIdList, permissionChartClassifyIdList []int) (hasAuth bool) {
  9. if chartClassifyIsJoinPermission == 1 {
  10. if !utils.InArrayByInt(permissionChartClassifyIdList, chartClassifyId) {
  11. return false
  12. }
  13. }
  14. if chartIsJoinPermission == 1 {
  15. if !utils.InArrayByInt(permissionChartInfoIdList, chartInfoId) {
  16. return false
  17. }
  18. }
  19. hasAuth = true
  20. return
  21. }
  22. func CheckChartClassifyPermissionByPermissionIdList(chartClassifyIsJoinPermission, chartClassifyId int, permissionChartClassifyIdList []int) (hasAuth bool) {
  23. if chartClassifyIsJoinPermission == 1 {
  24. if !utils.InArrayByInt(permissionChartClassifyIdList, chartClassifyId) {
  25. return
  26. }
  27. }
  28. hasAuth = true
  29. return
  30. }
  31. func GetUserChartAndClassifyPermissionList(userId, chartInfoId, classifyId int) (chartIdList, classifyIdList []int, err error) {
  32. chartIdList, err = data_manage_permission.GetPermissionChartIdList(userId, chartInfoId)
  33. if err != nil {
  34. fmt.Println("获取授权指标列表失败, err:", err)
  35. return
  36. }
  37. classifyIdList, err = data_manage_permission.GetPermissionChartClassifyIdList(userId, classifyId)
  38. if err != nil {
  39. fmt.Println("获取授权指标分类列表失败, err:", err)
  40. return
  41. }
  42. return
  43. }
  44. func GetUserChartClassifyPermissionList(userId, classifyId int) (classifyIdList []int, err error) {
  45. classifyIdList, err = data_manage_permission.GetPermissionChartClassifyIdList(userId, classifyId)
  46. if err != nil {
  47. fmt.Println("获取授权指标分类列表失败, err:", err)
  48. return
  49. }
  50. return
  51. }
  52. func CheckChartPermissionByChartInfoId(chartInfoId, chartClassifyId, chartIsJoinPermission, userId int) (hasAuth bool, err error) {
  53. currClassify, err := data_manage.GetChartClassifyById(chartClassifyId)
  54. if err != nil {
  55. return
  56. }
  57. if currClassify != nil {
  58. return CheckChartPermission(chartIsJoinPermission, currClassify.IsJoinPermission, userId, chartInfoId, chartClassifyId)
  59. }
  60. return
  61. }
  62. func CheckChartPermission(chartIsJoinPermission, chartClassifyIsJoinPermission, userId, chartInfoId, chartClassifyId int) (hasAuth bool, err error) {
  63. chartIdList, classifyIdList, err := GetUserChartAndClassifyPermissionList(userId, chartInfoId, chartClassifyId)
  64. if err != nil {
  65. fmt.Println("GetUserChartAndClassifyPermissionList err:", err)
  66. return
  67. }
  68. hasAuth = CheckChartPermissionByPermissionIdList(chartIsJoinPermission, chartClassifyIsJoinPermission, chartInfoId, chartClassifyId, chartIdList, classifyIdList)
  69. return
  70. }