From 891ec1ef5357c9778c9cefdc7403965e2dfca13d Mon Sep 17 00:00:00 2001 From: shenjiachi Date: Wed, 13 Nov 2024 18:41:04 +0800 Subject: [PATCH] add oss setting --- app/hdl/comm/hdl_comm.go | 50 +++++ app/hdl/setCenter/oss/aliyun/hdl_basic.go | 104 +++++++++++ .../egg_energy/md_basic.go | 12 +- app/md/setCenter/oss/aliyun/md.basic.go | 19 ++ docs/docs.go | 171 +++++++++++++++++- docs/swagger.json | 171 +++++++++++++++++- docs/swagger.yaml | 117 +++++++++++- go.mod | 2 + 8 files changed, 634 insertions(+), 12 deletions(-) create mode 100644 app/md/setCenter/oss/aliyun/md.basic.go diff --git a/app/hdl/comm/hdl_comm.go b/app/hdl/comm/hdl_comm.go index c675995..11ed133 100644 --- a/app/hdl/comm/hdl_comm.go +++ b/app/hdl/comm/hdl_comm.go @@ -7,7 +7,9 @@ import ( "applet/app/md" "applet/app/svc" "applet/app/utils" + "applet/app/utils/cache" "code.fnuoos.com/EggPlanet/egg_models.git/src/implement" + "github.com/aliyun/aliyun-oss-go-sdk/oss" "github.com/gin-gonic/gin" ) @@ -107,6 +109,54 @@ func MenuList(c *gin.Context) { 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["oss_endpoint"] + bucketName := cfgMap["oss_bucket_name"] + objectName := cfgMap["oss_object_scheme"] + accessKeyID := cfgMap["oss_access_key_id"] + accessKeySecret := cfgMap["oss_access_key_secret"] + + 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) + if err != nil { + e.OutErr(c, e.ERR_AES_ENCODE, err.Error()) + return + } + e.OutSuc(c, signedURL, nil) } diff --git a/app/hdl/setCenter/oss/aliyun/hdl_basic.go b/app/hdl/setCenter/oss/aliyun/hdl_basic.go index 7559130..2706c02 100644 --- a/app/hdl/setCenter/oss/aliyun/hdl_basic.go +++ b/app/hdl/setCenter/oss/aliyun/hdl_basic.go @@ -1,13 +1,117 @@ package aliyun import ( + "applet/app/db" + "applet/app/e" + md "applet/app/md/setCenter/oss/aliyun" + "applet/app/utils/cache" + "code.fnuoos.com/EggPlanet/egg_models.git/src/implement" "github.com/gin-gonic/gin" ) +// GetBasic +// @Summary 设置中心-对象存储-对象存储设置(获取) +// @Tags 对象存储 +// @Description 对象存储设置(获取) +// @Accept json +// @Produce json +// @param Authorization header string true "验证参数Bearer和token空格拼接" +// @Success 200 {object} md.GetBasicResp "设置列表" +// @Failure 400 {object} md.Response "具体错误" +// @Router /api/comm/oss/getOssUrl [get] func GetBasic(c *gin.Context) { + redisConn := cache.GetPool().Get() + sysCfgDb := implement.NewSysCfgDb(db.Db, redisConn) + sysCfg, err := sysCfgDb.SysCfgGetAll() + if err != nil { + e.OutErr(c, e.ERR_DB_ORM, err.Error()) + return + } + cfgMap := make(map[string]string, len(*sysCfg)) + for _, cfg := range *sysCfg { + cfgMap[cfg.Key] = cfg.Val + } + endpoint, ok := cfgMap["oss_endpoint"] + if !ok { + sysCfgDb.SysCfgInsert("oss_endpoint", "", "oss地域节点") + endpoint = "" + } + bucketName, ok := cfgMap["oss_bucket_name"] + if !ok { + sysCfgDb.SysCfgInsert("oss_bucket_name", "", "oss存储桶名称") + bucketName = "" + } + objectScheme, ok := cfgMap["oss_object_scheme"] + if !ok { + sysCfgDb.SysCfgInsert("oss_object_scheme", "", "oss上传方式") + objectScheme = "" + } + accessKeyID, ok := cfgMap["oss_access_key_id"] + if !ok { + sysCfgDb.SysCfgInsert("oss_access_key_id", "", "oss访问秘钥id") + accessKeyID = "" + } + accessKeySecret, ok := cfgMap["oss_access_key_secret"] + if !ok { + sysCfgDb.SysCfgInsert("oss_access_key_secret", "", "oss访问秘钥") + accessKeySecret = "" + } + domain, ok := cfgMap["oss_object_domain"] + if !ok { + sysCfgDb.SysCfgInsert("oss_object_domain", "", "oss域名") + domain = "" + } + resp := md.GetBasicResp{ + OssEndpoint: endpoint, + OssBucketName: bucketName, + OssObjectScheme: objectScheme, + OssAccessKeyId: accessKeyID, + OssAccessKeySecret: accessKeySecret, + OssObjectDomain: domain, + } + + e.OutSuc(c, resp, nil) } +// SetBasic +// @Summary 设置中心-对象存储-对象存储设置(更新) +// @Tags 对象存储 +// @Description 对象存储设置(更新) +// @Accept json +// @Produce json +// @param Authorization header string true "验证参数Bearer和token空格拼接" +// @param req body md.SetBasicReq true "上传需要修改的信息" +// @Success 200 {string} "success" +// @Failure 400 {object} md.Response "具体错误" +// @Router /api/comm/oss/getOssUrl [get] func SetBasic(c *gin.Context) { + var req *md.SetBasicReq + if err1 := c.ShouldBindJSON(&req); err1 != nil { + e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error()) + return + } + + redisConn := cache.GetPool().Get() + cfgDb := implement.NewSysCfgDb(db.Db, redisConn) + if req.OssAccessKeyId != "" { + cfgDb.SysCfgUpdate("oss_access_key_id", req.OssAccessKeyId) + } + if req.OssAccessKeySecret != "" { + cfgDb.SysCfgUpdate("oss_access_key_secret", req.OssAccessKeySecret) + } + if req.OssObjectScheme != "" { + cfgDb.SysCfgUpdate("oss_object_scheme", req.OssObjectScheme) + } + if req.OssObjectDomain != "" { + cfgDb.SysCfgUpdate("oss_object_domain", req.OssObjectDomain) + } + if req.OssBucketName != "" { + cfgDb.SysCfgUpdate("oss_bucket_name", req.OssBucketName) + } + if req.OssEndpoint != "" { + cfgDb.SysCfgUpdate("oss_endpoint", req.OssEndpoint) + } + e.OutSuc(c, "success", nil) } diff --git a/app/md/institutional_management/egg_energy/md_basic.go b/app/md/institutional_management/egg_energy/md_basic.go index c1f5f04..699b42a 100644 --- a/app/md/institutional_management/egg_energy/md_basic.go +++ b/app/md/institutional_management/egg_energy/md_basic.go @@ -15,12 +15,12 @@ type VirtualCoin struct { // BasicSetting 基础设置 type BasicSetting struct { - IsOpen int `json:"is_open" ` // 是否开启(1:开启 0:关闭) - PersonEggEnergyCoinId int `json:"person_egg_energy_coin_id" ` // 个人蛋蛋能量对应虚拟币 id - TeamEggEnergyCoinId int `json:"team_egg_energy_coin_id" ` // 团队蛋蛋能量对应虚拟币 id - PersonEggPointsCoinId int `json:"person_egg_points_coin_id" ` // 个人蛋蛋积分对应虚拟币 id - TeamEggPointsCoinId int `json:"team_egg_points_coin_id" ` // 团队蛋蛋积分对应虚拟币 id - DirectPushReward md.TeamRewardSettingStruct `json:"direct_push_reward" example:"直推奖励"` // 直推奖励 + IsOpen int `json:"is_open" ` // 是否开启(1:开启 0:关闭) + PersonEggEnergyCoinId int `json:"person_egg_energy_coin_id" ` // 个人蛋蛋能量对应虚拟币 id + TeamEggEnergyCoinId int `json:"team_egg_energy_coin_id" ` // 团队蛋蛋能量对应虚拟币 id + PersonEggPointsCoinId int `json:"person_egg_points_coin_id" ` // 个人蛋蛋积分对应虚拟币 id + TeamEggPointsCoinId int `json:"team_egg_points_coin_id" ` // 团队蛋蛋积分对应虚拟币 id + DirectPushReward md.TeamRewardSettingStruct `json:"direct_push_reward"` // 直推奖励 } // VideoRewardSetting 视频奖励 diff --git a/app/md/setCenter/oss/aliyun/md.basic.go b/app/md/setCenter/oss/aliyun/md.basic.go new file mode 100644 index 0000000..0f44e19 --- /dev/null +++ b/app/md/setCenter/oss/aliyun/md.basic.go @@ -0,0 +1,19 @@ +package md + +type GetBasicResp struct { + OssEndpoint string `json:"oss_endpoint" example:"oss地域节点"` + OssBucketName string `json:"oss_bucket_name" example:"oss存储桶名称"` + OssObjectScheme string `json:"oss_object_scheme" example:"oss上传方式"` + OssAccessKeyId string `json:"oss_access_key_id" example:"oss访问秘钥id"` + OssAccessKeySecret string `json:"oss_access_key_secret" example:"oss访问秘钥"` + OssObjectDomain string `json:"oss_object_domain" example:"oss域名"` +} + +type SetBasicReq struct { + OssEndpoint string `json:"oss_endpoint" example:"oss地域节点"` + OssBucketName string `json:"oss_bucket_name" example:"oss存储桶名称"` + OssObjectScheme string `json:"oss_object_scheme" example:"oss上传方式"` + OssAccessKeyId string `json:"oss_access_key_id" example:"oss访问秘钥id"` + OssAccessKeySecret string `json:"oss_access_key_secret" example:"oss访问秘钥"` + OssObjectDomain string `json:"oss_object_domain" example:"oss域名"` +} diff --git a/docs/docs.go b/docs/docs.go index 3468ed6..19c8726 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -24,6 +24,91 @@ const docTemplate = `{ "host": "{{.Host}}", "basePath": "{{.BasePath}}", "paths": { + "/api/comm/getOssUrl": { + "get": { + "description": "上传许可链接(获取)", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "对象存储" + ], + "summary": "通用请求-对象存储-上传许可链接(获取)", + "parameters": [ + { + "type": "string", + "description": "验证参数Bearer和token空格拼接", + "name": "Authorization", + "in": "header", + "required": true + } + ], + "responses": { + "200": { + "description": "许可链接", + "schema": { + "type": "string" + } + }, + "400": { + "description": "具体错误", + "schema": { + "$ref": "#/definitions/md.Response" + } + } + } + } + }, + "/api/comm/oss/getOssUrl": { + "get": { + "description": "对象存储设置(更新)", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "对象存储" + ], + "summary": "设置中心-对象存储-对象存储设置(更新)", + "parameters": [ + { + "type": "string", + "description": "验证参数Bearer和token空格拼接", + "name": "Authorization", + "in": "header", + "required": true + }, + { + "description": "上传需要修改的信息", + "name": "req", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/md.SetBasicReq" + } + } + ], + "responses": { + "200": { + "description": "success", + "schema": { + "type": "string" + } + }, + "400": { + "description": "具体错误", + "schema": { + "$ref": "#/definitions/md.Response" + } + } + } + } + }, "/api/demo": { "post": { "description": "Demo样例测试", @@ -1248,8 +1333,11 @@ const docTemplate = `{ "properties": { "direct_push_reward": { "description": "直推奖励", - "type": "string", - "example": "直推奖励" + "allOf": [ + { + "$ref": "#/definitions/md.TeamRewardSettingStruct" + } + ] }, "is_open": { "description": "是否开启(1:开启 0:关闭)", @@ -1965,6 +2053,35 @@ const docTemplate = `{ } } }, + "md.GetBasicResp": { + "type": "object", + "properties": { + "oss_access_key_id": { + "type": "string", + "example": "oss访问秘钥id" + }, + "oss_access_key_secret": { + "type": "string", + "example": "oss访问秘钥" + }, + "oss_bucket_name": { + "type": "string", + "example": "oss存储桶名称" + }, + "oss_endpoint": { + "type": "string", + "example": "oss地域节点" + }, + "oss_object_domain": { + "type": "string", + "example": "oss域名" + }, + "oss_object_scheme": { + "type": "string", + "example": "oss上传方式" + } + } + }, "md.GetEggCoreDataListResp": { "type": "object", "properties": { @@ -2545,6 +2662,35 @@ const docTemplate = `{ } } }, + "md.SetBasicReq": { + "type": "object", + "properties": { + "oss_access_key_id": { + "type": "string", + "example": "oss访问秘钥id" + }, + "oss_access_key_secret": { + "type": "string", + "example": "oss访问秘钥" + }, + "oss_bucket_name": { + "type": "string", + "example": "oss存储桶名称" + }, + "oss_endpoint": { + "type": "string", + "example": "oss地域节点" + }, + "oss_object_domain": { + "type": "string", + "example": "oss域名" + }, + "oss_object_scheme": { + "type": "string", + "example": "oss上传方式" + } + } + }, "md.SonUserDailyActivityAnalysisNode": { "type": "object", "properties": { @@ -2597,6 +2743,27 @@ const docTemplate = `{ } } }, + "md.TeamRewardSettingStruct": { + "type": "object", + "properties": { + "member_self_is_open_get_team_reward": { + "description": "会员是否活跃得到团队奖励", + "type": "string" + }, + "one_round_duration": { + "description": "一轮持续时间", + "type": "string" + }, + "reward_decrement_value": { + "description": "递减百分比", + "type": "string" + }, + "reward_end_value": { + "description": "奖励结束值", + "type": "string" + } + } + }, "md.TreeNode": { "type": "object", "properties": { diff --git a/docs/swagger.json b/docs/swagger.json index 40233ee..ff07ab3 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -17,6 +17,91 @@ }, "host": "localhost:4001", "paths": { + "/api/comm/getOssUrl": { + "get": { + "description": "上传许可链接(获取)", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "对象存储" + ], + "summary": "通用请求-对象存储-上传许可链接(获取)", + "parameters": [ + { + "type": "string", + "description": "验证参数Bearer和token空格拼接", + "name": "Authorization", + "in": "header", + "required": true + } + ], + "responses": { + "200": { + "description": "许可链接", + "schema": { + "type": "string" + } + }, + "400": { + "description": "具体错误", + "schema": { + "$ref": "#/definitions/md.Response" + } + } + } + } + }, + "/api/comm/oss/getOssUrl": { + "get": { + "description": "对象存储设置(更新)", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "对象存储" + ], + "summary": "设置中心-对象存储-对象存储设置(更新)", + "parameters": [ + { + "type": "string", + "description": "验证参数Bearer和token空格拼接", + "name": "Authorization", + "in": "header", + "required": true + }, + { + "description": "上传需要修改的信息", + "name": "req", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/md.SetBasicReq" + } + } + ], + "responses": { + "200": { + "description": "success", + "schema": { + "type": "string" + } + }, + "400": { + "description": "具体错误", + "schema": { + "$ref": "#/definitions/md.Response" + } + } + } + } + }, "/api/demo": { "post": { "description": "Demo样例测试", @@ -1241,8 +1326,11 @@ "properties": { "direct_push_reward": { "description": "直推奖励", - "type": "string", - "example": "直推奖励" + "allOf": [ + { + "$ref": "#/definitions/md.TeamRewardSettingStruct" + } + ] }, "is_open": { "description": "是否开启(1:开启 0:关闭)", @@ -1958,6 +2046,35 @@ } } }, + "md.GetBasicResp": { + "type": "object", + "properties": { + "oss_access_key_id": { + "type": "string", + "example": "oss访问秘钥id" + }, + "oss_access_key_secret": { + "type": "string", + "example": "oss访问秘钥" + }, + "oss_bucket_name": { + "type": "string", + "example": "oss存储桶名称" + }, + "oss_endpoint": { + "type": "string", + "example": "oss地域节点" + }, + "oss_object_domain": { + "type": "string", + "example": "oss域名" + }, + "oss_object_scheme": { + "type": "string", + "example": "oss上传方式" + } + } + }, "md.GetEggCoreDataListResp": { "type": "object", "properties": { @@ -2538,6 +2655,35 @@ } } }, + "md.SetBasicReq": { + "type": "object", + "properties": { + "oss_access_key_id": { + "type": "string", + "example": "oss访问秘钥id" + }, + "oss_access_key_secret": { + "type": "string", + "example": "oss访问秘钥" + }, + "oss_bucket_name": { + "type": "string", + "example": "oss存储桶名称" + }, + "oss_endpoint": { + "type": "string", + "example": "oss地域节点" + }, + "oss_object_domain": { + "type": "string", + "example": "oss域名" + }, + "oss_object_scheme": { + "type": "string", + "example": "oss上传方式" + } + } + }, "md.SonUserDailyActivityAnalysisNode": { "type": "object", "properties": { @@ -2590,6 +2736,27 @@ } } }, + "md.TeamRewardSettingStruct": { + "type": "object", + "properties": { + "member_self_is_open_get_team_reward": { + "description": "会员是否活跃得到团队奖励", + "type": "string" + }, + "one_round_duration": { + "description": "一轮持续时间", + "type": "string" + }, + "reward_decrement_value": { + "description": "递减百分比", + "type": "string" + }, + "reward_end_value": { + "description": "奖励结束值", + "type": "string" + } + } + }, "md.TreeNode": { "type": "object", "properties": { diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 5834a80..a504e16 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -2,9 +2,9 @@ definitions: applet_app_md_institutional_management_egg_energy.BasicSetting: properties: direct_push_reward: + allOf: + - $ref: '#/definitions/md.TeamRewardSettingStruct' description: 直推奖励 - example: 直推奖励 - type: string is_open: description: 是否开启(1:开启 0:关闭) type: integer @@ -505,6 +505,27 @@ definitions: description: 持有该类型用户数 type: integer type: object + md.GetBasicResp: + properties: + oss_access_key_id: + example: oss访问秘钥id + type: string + oss_access_key_secret: + example: oss访问秘钥 + type: string + oss_bucket_name: + example: oss存储桶名称 + type: string + oss_endpoint: + example: oss地域节点 + type: string + oss_object_domain: + example: oss域名 + type: string + oss_object_scheme: + example: oss上传方式 + type: string + type: object md.GetEggCoreDataListResp: properties: now_energy_total_nums: @@ -892,6 +913,27 @@ definitions: type: object type: array type: object + md.SetBasicReq: + properties: + oss_access_key_id: + example: oss访问秘钥id + type: string + oss_access_key_secret: + example: oss访问秘钥 + type: string + oss_bucket_name: + example: oss存储桶名称 + type: string + oss_endpoint: + example: oss地域节点 + type: string + oss_object_domain: + example: oss域名 + type: string + oss_object_scheme: + example: oss上传方式 + type: string + type: object md.SonUserDailyActivityAnalysisNode: properties: activity_day_nums: @@ -929,6 +971,21 @@ definitions: uid: type: integer type: object + md.TeamRewardSettingStruct: + properties: + member_self_is_open_get_team_reward: + description: 会员是否活跃得到团队奖励 + type: string + one_round_duration: + description: 一轮持续时间 + type: string + reward_decrement_value: + description: 递减百分比 + type: string + reward_end_value: + description: 奖励结束值 + type: string + type: object md.TreeNode: properties: avatar_url: @@ -1156,6 +1213,62 @@ info: title: 蛋蛋星球-管理后台 version: "1.0" paths: + /api/comm/getOssUrl: + get: + consumes: + - application/json + description: 上传许可链接(获取) + parameters: + - description: 验证参数Bearer和token空格拼接 + in: header + name: Authorization + required: true + type: string + produces: + - application/json + responses: + "200": + description: 许可链接 + schema: + type: string + "400": + description: 具体错误 + schema: + $ref: '#/definitions/md.Response' + summary: 通用请求-对象存储-上传许可链接(获取) + tags: + - 对象存储 + /api/comm/oss/getOssUrl: + get: + consumes: + - application/json + description: 对象存储设置(更新) + parameters: + - description: 验证参数Bearer和token空格拼接 + in: header + name: Authorization + required: true + type: string + - description: 上传需要修改的信息 + in: body + name: req + required: true + schema: + $ref: '#/definitions/md.SetBasicReq' + produces: + - application/json + responses: + "200": + description: success + schema: + type: string + "400": + description: 具体错误 + schema: + $ref: '#/definitions/md.Response' + summary: 设置中心-对象存储-对象存储设置(更新) + tags: + - 对象存储 /api/demo: post: consumes: diff --git a/go.mod b/go.mod index 96580c9..b1ee5e3 100644 --- a/go.mod +++ b/go.mod @@ -47,6 +47,7 @@ require ( github.com/BurntSushi/toml v1.4.0 // indirect github.com/KyleBanks/depth v1.2.1 // indirect github.com/PuerkitoBio/goquery v1.9.2 // indirect + github.com/aliyun/aliyun-oss-go-sdk v3.0.2+incompatible // indirect github.com/andybalholm/cascadia v1.3.2 // indirect github.com/antchfx/htmlquery v1.3.3 // indirect github.com/antchfx/xmlquery v1.4.2 // indirect @@ -101,6 +102,7 @@ require ( golang.org/x/sync v0.8.0 // indirect golang.org/x/sys v0.26.0 // indirect golang.org/x/text v0.15.0 // indirect + golang.org/x/time v0.0.0-20191024005414-555d28b269f0 // indirect golang.org/x/tools v0.20.0 // indirect golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect google.golang.org/appengine v1.4.0 // indirect