蛋蛋星球-客户端
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.
 
 
 
 
 
 

163 lines
4.4 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. "applet/app/utils/cache"
  10. "code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
  11. "github.com/aliyun/aliyun-oss-go-sdk/oss"
  12. "github.com/gin-gonic/gin"
  13. )
  14. func MenuList(c *gin.Context) {
  15. engine := db.Db
  16. admin := svc.GetUser(c)
  17. qrcodeWithBatchRecordsDb := implement.NewPermissionGroupDb(engine)
  18. groupList, err := qrcodeWithBatchRecordsDb.FindPermissionGroupV2()
  19. if err != nil {
  20. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  21. return
  22. }
  23. // 1、查询出当前用户所有角色
  24. adminRoleDb := implement.NewAdminRoleDb(engine)
  25. roles, err := adminRoleDb.FindAdminRole(admin.AdmId)
  26. if err != nil {
  27. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  28. return
  29. }
  30. roleDb := implement.NewRoleDb(engine, 0)
  31. var adminHasPermissionGroupIds []string
  32. for _, v := range *roles {
  33. list, _, err1 := roleDb.FindPermissionGroupByRole(v.RoleId)
  34. if err1 != nil {
  35. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  36. return
  37. }
  38. for _, v1 := range list {
  39. adminHasPermissionGroupIds = append(adminHasPermissionGroupIds, utils.IntToStr(v1.PermissionGroup.Id))
  40. }
  41. }
  42. var tempRespMap = map[string]*md.PermissionGroupListResp{}
  43. var tempRespMapKeys []string
  44. for _, v := range *groupList {
  45. var isCheck bool
  46. if admin.IsSuperAdministrator == enum.IsSuperAdministratorTure {
  47. isCheck = true
  48. } else {
  49. isCheck = false
  50. }
  51. if utils.InArr(utils.IntToStr(v.Id), adminHasPermissionGroupIds) {
  52. isCheck = true
  53. }
  54. if v.State == enum.PermissionGroupStateForDiscard {
  55. isCheck = false
  56. }
  57. tempRespMap[utils.IntToStr(v.Id)] = &md.PermissionGroupListResp{
  58. Id: v.Id,
  59. Name: v.Name,
  60. Key: v.Key,
  61. State: v.State,
  62. ParentId: v.ParentId,
  63. CreateAt: v.CreateAt,
  64. UpdateAt: v.UpdateAt,
  65. IsCheck: isCheck,
  66. }
  67. tempRespMapKeys = append(tempRespMapKeys, utils.IntToStr(v.Id))
  68. }
  69. for _, v := range tempRespMap {
  70. if v.ParentId != 0 && tempRespMap[utils.IntToStr(v.ParentId)].ParentId != 0 {
  71. tempRespMap[utils.IntToStr(v.ParentId)].SubPermissionGroupList = append(tempRespMap[utils.IntToStr(v.ParentId)].SubPermissionGroupList, *v)
  72. }
  73. }
  74. for _, v := range tempRespMap {
  75. if v.ParentId != 0 && tempRespMap[utils.IntToStr(v.ParentId)].ParentId == 0 {
  76. tempRespMap[utils.IntToStr(v.ParentId)].SubPermissionGroupList = append(tempRespMap[utils.IntToStr(v.ParentId)].SubPermissionGroupList, *v)
  77. }
  78. }
  79. var resp []*md.PermissionGroupListResp
  80. for _, v := range tempRespMapKeys {
  81. if tempRespMap[v].ParentId == 0 {
  82. resp = append(resp, tempRespMap[v])
  83. }
  84. }
  85. e.OutSuc(c, map[string]interface{}{
  86. "list": resp,
  87. "state": []map[string]interface{}{
  88. {
  89. "name": enum.PermissionGroupState(enum.PermissionGroupStateForNormal).String(),
  90. "value": enum.PermissionGroupStateForNormal,
  91. },
  92. {
  93. "name": enum.PermissionGroupState(enum.PermissionGroupStateForDiscard).String(),
  94. "value": enum.PermissionGroupStateForDiscard,
  95. },
  96. },
  97. }, nil)
  98. return
  99. }
  100. // GetOssUrl
  101. // @Summary 通用请求-对象存储-上传许可链接(获取)
  102. // @Tags 对象存储
  103. // @Description 上传许可链接(获取)
  104. // @Accept json
  105. // @Produce json
  106. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  107. // @Success 200 {string} "许可链接"
  108. // @Failure 400 {object} md.Response "具体错误"
  109. // @Router /api/comm/getOssUrl [get]
  110. func GetOssUrl(c *gin.Context) {
  111. redisConn := cache.GetPool().Get()
  112. sysCfgDb := implement.NewSysCfgDb(db.Db, redisConn)
  113. sysCfgs, err := sysCfgDb.SysCfgGetAll()
  114. if err != nil {
  115. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  116. return
  117. }
  118. if sysCfgs == nil {
  119. e.OutErr(c, e.ERR_CFG_CACHE, nil)
  120. return
  121. }
  122. cfgMap := make(map[string]string, len(*sysCfgs))
  123. for _, cfg := range *sysCfgs {
  124. cfgMap[cfg.Key] = cfg.Val
  125. }
  126. endpoint := cfgMap["oss_endpoint"]
  127. bucketName := cfgMap["oss_bucket_name"]
  128. objectName := cfgMap["oss_object_scheme"]
  129. accessKeyID := cfgMap["oss_access_key_id"]
  130. accessKeySecret := cfgMap["oss_access_key_secret"]
  131. client, err := oss.New(endpoint, accessKeyID, accessKeySecret)
  132. if err != nil {
  133. e.OutErr(c, e.ERR_AES_ENCODE, err.Error())
  134. return
  135. }
  136. bucket, err := client.Bucket(bucketName)
  137. if err != nil {
  138. e.OutErr(c, e.ERR_AES_ENCODE, err.Error())
  139. return
  140. }
  141. signedURL, err := bucket.SignURL(objectName, oss.HTTPPut, 60)
  142. if err != nil {
  143. e.OutErr(c, e.ERR_AES_ENCODE, err.Error())
  144. return
  145. }
  146. e.OutSuc(c, signedURL, nil)
  147. }