蛋蛋星球 后台端
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.
 
 
 
 
 

109 rivejä
2.9 KiB

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