蛋蛋星球 后台端
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 

192 рядки
5.3 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. enum2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/enum"
  12. "github.com/aliyun/aliyun-oss-go-sdk/oss"
  13. "github.com/gin-gonic/gin"
  14. )
  15. func MenuList(c *gin.Context) {
  16. engine := db.Db
  17. admin := svc.GetUser(c)
  18. qrcodeWithBatchRecordsDb := implement.NewPermissionGroupDb(engine)
  19. groupList, err := qrcodeWithBatchRecordsDb.FindPermissionGroupV2()
  20. if err != nil {
  21. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  22. return
  23. }
  24. // 1、查询出当前用户所有角色
  25. adminRoleDb := implement.NewAdminRoleDb(engine)
  26. roles, err := adminRoleDb.FindAdminRole(admin.AdmId)
  27. if err != nil {
  28. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  29. return
  30. }
  31. roleDb := implement.NewRoleDb(engine, 0)
  32. var adminHasPermissionGroupIds []string
  33. for _, v := range *roles {
  34. list, _, err1 := roleDb.FindPermissionGroupByRole(v.RoleId)
  35. if err1 != nil {
  36. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  37. return
  38. }
  39. for _, v1 := range list {
  40. adminHasPermissionGroupIds = append(adminHasPermissionGroupIds, utils.IntToStr(v1.PermissionGroup.Id))
  41. }
  42. }
  43. var tempRespMap = map[string]*md.PermissionGroupListResp{}
  44. var tempRespMapKeys []string
  45. for _, v := range *groupList {
  46. var isCheck bool
  47. if admin.IsSuperAdministrator == enum.IsSuperAdministratorTure {
  48. isCheck = true
  49. } else {
  50. isCheck = false
  51. }
  52. if utils.InArr(utils.IntToStr(v.Id), adminHasPermissionGroupIds) {
  53. isCheck = true
  54. }
  55. if v.State == enum.PermissionGroupStateForDiscard {
  56. isCheck = false
  57. }
  58. tempRespMap[utils.IntToStr(v.Id)] = &md.PermissionGroupListResp{
  59. Id: v.Id,
  60. Name: v.Name,
  61. Key: v.Key,
  62. State: v.State,
  63. ParentId: v.ParentId,
  64. CreateAt: v.CreateAt,
  65. UpdateAt: v.UpdateAt,
  66. IsCheck: isCheck,
  67. }
  68. tempRespMapKeys = append(tempRespMapKeys, utils.IntToStr(v.Id))
  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. for _, v := range tempRespMap {
  76. if v.ParentId != 0 && tempRespMap[utils.IntToStr(v.ParentId)].ParentId == 0 {
  77. tempRespMap[utils.IntToStr(v.ParentId)].SubPermissionGroupList = append(tempRespMap[utils.IntToStr(v.ParentId)].SubPermissionGroupList, *v)
  78. }
  79. }
  80. var resp []*md.PermissionGroupListResp
  81. for _, v := range tempRespMapKeys {
  82. if tempRespMap[v].ParentId == 0 {
  83. resp = append(resp, tempRespMap[v])
  84. }
  85. }
  86. e.OutSuc(c, map[string]interface{}{
  87. "list": resp,
  88. "state": []map[string]interface{}{
  89. {
  90. "name": enum.PermissionGroupState(enum.PermissionGroupStateForNormal).String(),
  91. "value": enum.PermissionGroupStateForNormal,
  92. },
  93. {
  94. "name": enum.PermissionGroupState(enum.PermissionGroupStateForDiscard).String(),
  95. "value": enum.PermissionGroupStateForDiscard,
  96. },
  97. },
  98. }, nil)
  99. return
  100. }
  101. type ImgReqUploadReq struct {
  102. FileName string `json:"file_name" binding:"required" example:"文件名"`
  103. ContentType string `json:"content_type,required" binding:"required" example:"image/jpeg"`
  104. }
  105. type ImgReqUploadResp struct {
  106. SignUrl string `json:"sign_url" example:"签名上传url"`
  107. }
  108. // GetOssUrl
  109. // @Summary 通用请求-对象存储-上传许可链接(获取)
  110. // @Tags 对象存储
  111. // @Description 上传许可链接(获取)
  112. // @Accept json
  113. // @Produce json
  114. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  115. // @Param req body comm.ImgReqUploadReq true "签名上传url"
  116. // @Success 200 {string} "许可链接"
  117. // @Failure 400 {object} md.Response "具体错误"
  118. // @Router /api/comm/getOssUrl [POST]
  119. func GetOssUrl(c *gin.Context) {
  120. var args ImgReqUploadReq
  121. err := c.ShouldBindJSON(&args)
  122. if err != nil {
  123. err = svc.HandleValidateErr(err)
  124. err1 := err.(e.E)
  125. e.OutErr(c, err1.Code, err1.Error())
  126. return
  127. }
  128. CommOss(c, args)
  129. }
  130. func CommOss(c *gin.Context, args ImgReqUploadReq) {
  131. redisConn := cache.GetPool().Get()
  132. sysCfgDb := implement.NewSysCfgDb(db.Db, redisConn)
  133. sysCfgs, err := sysCfgDb.SysCfgGetAll()
  134. if err != nil {
  135. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  136. return
  137. }
  138. if sysCfgs == nil {
  139. e.OutErr(c, e.ERR_CFG_CACHE, nil)
  140. return
  141. }
  142. cfgMap := make(map[string]string, len(*sysCfgs))
  143. for _, cfg := range *sysCfgs {
  144. cfgMap[cfg.Key] = cfg.Val
  145. }
  146. endpoint := cfgMap[enum2.AliyunOssEndpoint]
  147. bucketName := cfgMap[enum2.AliyunOssBucketName]
  148. ossBucketScheme := cfgMap[enum2.AliyunOssBucketScheme]
  149. accessKeyID := cfgMap[enum2.AliyunOssAccessKeyID]
  150. accessKeySecret := cfgMap[enum2.AliyunOssAccessKeySecret]
  151. // 创建OSSClient实例。
  152. client, err := oss.New(ossBucketScheme+"://"+endpoint, accessKeyID, accessKeySecret)
  153. if err != nil {
  154. e.OutErr(c, e.ERR, err.Error())
  155. return
  156. }
  157. // 获取存储空间。
  158. bucket, err := client.Bucket(bucketName)
  159. if err != nil {
  160. e.OutErr(c, e.ERR, err.Error())
  161. return
  162. }
  163. options := []oss.Option{
  164. oss.ContentType(args.ContentType),
  165. }
  166. signedURL, err := bucket.SignURL(args.FileName, oss.HTTPPut, 60*5, options...)
  167. if err != nil {
  168. e.OutErr(c, e.ERR_AES_ENCODE, err.Error())
  169. return
  170. }
  171. e.OutSuc(c, signedURL, nil)
  172. }