面包店
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

hdl_comm.go 2.8 KiB

9 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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.FindPermissionGroupV2()
  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. if v.State == enum.PermissionGroupStateForDiscard {
  54. isCheck = false
  55. }
  56. tempRespMap[utils.IntToStr(v.Id)] = &md.PermissionGroupListResp{
  57. Id: v.Id,
  58. Name: v.Name,
  59. Key: v.Key,
  60. State: v.State,
  61. ParentId: v.ParentId,
  62. CreateAt: v.CreateAt,
  63. UpdateAt: v.UpdateAt,
  64. IsCheck: isCheck,
  65. }
  66. tempRespMapKeys = append(tempRespMapKeys, utils.IntToStr(v.Id))
  67. }
  68. for _, v := range tempRespMap {
  69. if v.ParentId != 0 && tempRespMap[utils.IntToStr(v.ParentId)].ParentId != 0 {
  70. tempRespMap[utils.IntToStr(v.ParentId)].SubPermissionGroupList = append(tempRespMap[utils.IntToStr(v.ParentId)].SubPermissionGroupList, *v)
  71. }
  72. }
  73. for _, v := range tempRespMap {
  74. if v.ParentId != 0 && tempRespMap[utils.IntToStr(v.ParentId)].ParentId == 0 {
  75. tempRespMap[utils.IntToStr(v.ParentId)].SubPermissionGroupList = append(tempRespMap[utils.IntToStr(v.ParentId)].SubPermissionGroupList, *v)
  76. }
  77. }
  78. var resp []*md.PermissionGroupListResp
  79. for _, v := range tempRespMapKeys {
  80. if tempRespMap[v].ParentId == 0 {
  81. resp = append(resp, tempRespMap[v])
  82. }
  83. }
  84. e.OutSuc(c, map[string]interface{}{
  85. "list": resp,
  86. "state": []map[string]interface{}{
  87. {
  88. "name": enum.PermissionGroupState(enum.PermissionGroupStateForNormal).String(),
  89. "value": enum.PermissionGroupStateForNormal,
  90. },
  91. {
  92. "name": enum.PermissionGroupState(enum.PermissionGroupStateForDiscard).String(),
  93. "value": enum.PermissionGroupStateForDiscard,
  94. },
  95. },
  96. }, nil)
  97. return
  98. }