智慧食堂
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

hdl_comm.go 2.8 KiB

1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. package hdl
  2. import (
  3. "applet/app/admin/enum"
  4. "applet/app/admin/md"
  5. "applet/app/admin/svc"
  6. "applet/app/db"
  7. "applet/app/e"
  8. "applet/app/utils"
  9. "github.com/gin-gonic/gin"
  10. )
  11. func MenuList(c *gin.Context) {
  12. admin := svc.GetUser(c)
  13. qrcodeWithBatchRecordsDb := db.PermissionGroupDb{}
  14. qrcodeWithBatchRecordsDb.Set()
  15. groupList, err := qrcodeWithBatchRecordsDb.FindPermissionGroup()
  16. if err != nil {
  17. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  18. return
  19. }
  20. //1、查询出当前用户所有角色
  21. adminRoleDb := db.AdminRoleDb{}
  22. adminRoleDb.Set()
  23. roles, err := adminRoleDb.FindAdminRole(admin.AdmId)
  24. if err != nil {
  25. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  26. return
  27. }
  28. roleDb := db.RoleDb{}
  29. roleDb.Set(0)
  30. var adminHasPermissionGroupIds []string
  31. for _, v := range *roles {
  32. list, _, err1 := roleDb.FindPermissionGroupByRole(v.RoleId)
  33. if err1 != nil {
  34. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  35. return
  36. }
  37. for _, v1 := range list {
  38. adminHasPermissionGroupIds = append(adminHasPermissionGroupIds, utils.IntToStr(v1.PermissionGroup.Id))
  39. }
  40. }
  41. var tempRespMap = map[string]*md.PermissionGroupListResp{}
  42. var tempRespMapKeys []string
  43. for _, v := range *groupList {
  44. var isCheck bool
  45. if admin.IsSuperAdministrator == enum.IsSuperAdministratorTure {
  46. isCheck = true
  47. } else {
  48. isCheck = false
  49. }
  50. if utils.InArr(utils.IntToStr(v.Id), adminHasPermissionGroupIds) {
  51. isCheck = true
  52. }
  53. tempRespMap[utils.IntToStr(v.Id)] = &md.PermissionGroupListResp{
  54. Id: v.Id,
  55. Name: v.Name,
  56. Key: v.Key,
  57. State: v.State,
  58. ParentId: v.ParentId,
  59. CreateAt: v.CreateAt,
  60. UpdateAt: v.UpdateAt,
  61. IsCheck: isCheck,
  62. }
  63. tempRespMapKeys = append(tempRespMapKeys, utils.IntToStr(v.Id))
  64. }
  65. for _, v := range tempRespMap {
  66. if v.ParentId != 0 && tempRespMap[utils.IntToStr(v.ParentId)].ParentId != 0 {
  67. tempRespMap[utils.IntToStr(v.ParentId)].SubPermissionGroupList = append(tempRespMap[utils.IntToStr(v.ParentId)].SubPermissionGroupList, *v)
  68. }
  69. }
  70. for _, v := range tempRespMap {
  71. if v.ParentId != 0 && tempRespMap[utils.IntToStr(v.ParentId)].ParentId == 0 {
  72. tempRespMap[utils.IntToStr(v.ParentId)].SubPermissionGroupList = append(tempRespMap[utils.IntToStr(v.ParentId)].SubPermissionGroupList, *v)
  73. }
  74. }
  75. var resp []*md.PermissionGroupListResp
  76. for _, v := range tempRespMapKeys {
  77. if tempRespMap[v].ParentId == 0 {
  78. resp = append(resp, tempRespMap[v])
  79. }
  80. }
  81. e.OutSuc(c, map[string]interface{}{
  82. "list": resp,
  83. "state": []map[string]interface{}{
  84. {
  85. "name": enum.PermissionGroupState(enum.PermissionGroupStateForNormal).String(),
  86. "value": enum.PermissionGroupStateForNormal,
  87. },
  88. {
  89. "name": enum.PermissionGroupState(enum.PermissionGroupStateForDiscard).String(),
  90. "value": enum.PermissionGroupStateForDiscard,
  91. },
  92. },
  93. }, nil)
  94. return
  95. }