package comm import ( "applet/app/db" "applet/app/e" "applet/app/enum" "applet/app/md" "applet/app/svc" "applet/app/utils" "applet/app/utils/cache" "code.fnuoos.com/EggPlanet/egg_models.git/src/implement" enum2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/enum" "github.com/aliyun/aliyun-oss-go-sdk/oss" "github.com/gin-gonic/gin" ) func MenuList(c *gin.Context) { engine := db.Db admin := svc.GetUser(c) qrcodeWithBatchRecordsDb := implement.NewPermissionGroupDb(engine) groupList, err := qrcodeWithBatchRecordsDb.FindPermissionGroupV2() if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } // 1、查询出当前用户所有角色 adminRoleDb := implement.NewAdminRoleDb(engine) roles, err := adminRoleDb.FindAdminRole(admin.AdmId) if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } roleDb := implement.NewRoleDb(engine, 0) var adminHasPermissionGroupIds []string for _, v := range *roles { list, _, err1 := roleDb.FindPermissionGroupByRole(v.RoleId) if err1 != nil { e.OutErr(c, e.ERR_DB_ORM, err1.Error()) return } for _, v1 := range list { adminHasPermissionGroupIds = append(adminHasPermissionGroupIds, utils.IntToStr(v1.PermissionGroup.Id)) } } var tempRespMap = map[string]*md.PermissionGroupListResp{} var tempRespMapKeys []string for _, v := range *groupList { var isCheck bool if admin.IsSuperAdministrator == enum.IsSuperAdministratorTure { isCheck = true } else { isCheck = false } if utils.InArr(utils.IntToStr(v.Id), adminHasPermissionGroupIds) { isCheck = true } if v.State == enum.PermissionGroupStateForDiscard { isCheck = false } tempRespMap[utils.IntToStr(v.Id)] = &md.PermissionGroupListResp{ Id: v.Id, Name: v.Name, Key: v.Key, State: v.State, ParentId: v.ParentId, CreateAt: v.CreateAt, UpdateAt: v.UpdateAt, IsCheck: isCheck, } tempRespMapKeys = append(tempRespMapKeys, utils.IntToStr(v.Id)) } for _, v := range tempRespMap { if v.ParentId != 0 && tempRespMap[utils.IntToStr(v.ParentId)].ParentId != 0 { tempRespMap[utils.IntToStr(v.ParentId)].SubPermissionGroupList = append(tempRespMap[utils.IntToStr(v.ParentId)].SubPermissionGroupList, *v) } } for _, v := range tempRespMap { if v.ParentId != 0 && tempRespMap[utils.IntToStr(v.ParentId)].ParentId == 0 { tempRespMap[utils.IntToStr(v.ParentId)].SubPermissionGroupList = append(tempRespMap[utils.IntToStr(v.ParentId)].SubPermissionGroupList, *v) } } var resp []*md.PermissionGroupListResp for _, v := range tempRespMapKeys { if tempRespMap[v].ParentId == 0 { resp = append(resp, tempRespMap[v]) } } e.OutSuc(c, map[string]interface{}{ "list": resp, "state": []map[string]interface{}{ { "name": enum.PermissionGroupState(enum.PermissionGroupStateForNormal).String(), "value": enum.PermissionGroupStateForNormal, }, { "name": enum.PermissionGroupState(enum.PermissionGroupStateForDiscard).String(), "value": enum.PermissionGroupStateForDiscard, }, }, }, nil) return } // GetOssUrl // @Summary 通用请求-对象存储-上传许可链接(获取) // @Tags 对象存储 // @Description 上传许可链接(获取) // @Accept json // @Produce json // @param Authorization header string true "验证参数Bearer和token空格拼接" // @Success 200 {string} "许可链接" // @Failure 400 {object} md.Response "具体错误" // @Router /api/comm/getOssUrl [get] func GetOssUrl(c *gin.Context) { redisConn := cache.GetPool().Get() sysCfgDb := implement.NewSysCfgDb(db.Db, redisConn) sysCfgs, err := sysCfgDb.SysCfgGetAll() if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } if sysCfgs == nil { e.OutErr(c, e.ERR_CFG_CACHE, nil) return } cfgMap := make(map[string]string, len(*sysCfgs)) for _, cfg := range *sysCfgs { cfgMap[cfg.Key] = cfg.Val } endpoint := cfgMap[enum2.AliyunOss(enum2.AliyunOssEndpoint).String()] bucketName := cfgMap[enum2.AliyunOss(enum2.AliyunOssBucketName).String()] objectName := cfgMap[enum2.AliyunOss(enum2.AliyunOssBucketScheme).String()] accessKeyID := cfgMap[enum2.AliyunOss(enum2.AliyunOssAccessKeyID).String()] accessKeySecret := cfgMap[enum2.AliyunOss(enum2.AliyunOssAccessKeySecret).String()] client, err := oss.New(endpoint, accessKeyID, accessKeySecret) if err != nil { e.OutErr(c, e.ERR_AES_ENCODE, err.Error()) return } bucket, err := client.Bucket(bucketName) if err != nil { e.OutErr(c, e.ERR_AES_ENCODE, err.Error()) return } signedURL, err := bucket.SignURL(objectName, oss.HTTPPut, 60*5) if err != nil { e.OutErr(c, e.ERR_AES_ENCODE, err.Error()) return } e.OutSuc(c, signedURL, nil) }