package svc import ( "applet/app/db" "applet/app/utils" "applet/app/utils/cache" "applet/app/utils/logx" "code.fnuoos.com/EggPlanet/egg_models.git/src/dao" "code.fnuoos.com/EggPlanet/egg_models.git/src/implement" "code.fnuoos.com/EggPlanet/egg_models.git/src/model" openapi "github.com/alibabacloud-go/darabonba-openapi/v2/client" ram20150501 "github.com/alibabacloud-go/ram-20150501/v2/client" sts20150401 "github.com/alibabacloud-go/sts-20150401/v2/client" util2 "github.com/alibabacloud-go/tea-utils/v2/service" "github.com/alibabacloud-go/tea/tea" "github.com/gin-gonic/gin" "strings" "time" ) func GetOssUrl(img string) string { redisConn := cache.GetPool().Get() sysCfgDb := implement.NewSysCfgDb(db.Db, redisConn) defer func(sysCfgDb dao.SysCfgDao) { err := sysCfgDb.Close() if err != nil { logx.Error("redis close err:" + err.Error()) // 记录错误信息 } }(sysCfgDb) sysCfg := sysCfgDb.SysCfgFindWithDb("oss_domain", "oss_bucket_scheme") if strings.Contains(img, "http") == false && img != "" { http := sysCfg["oss_bucket_scheme"] img = http + "://" + sysCfg["oss_domain"] + "/" + img } return img } func GetOssDomain() string { redisConn := cache.GetPool().Get() sysCfgDb := implement.NewSysCfgDb(db.Db, redisConn) defer func(sysCfgDb dao.SysCfgDao) { err := sysCfgDb.Close() if err != nil { logx.Error("redis close err:" + err.Error()) // 记录错误信息 } }(sysCfgDb) sysCfg := sysCfgDb.SysCfgFindWithDb("oss_domain", "oss_bucket_scheme") http := sysCfg["oss_bucket_scheme"] return http + "://" + sysCfg["oss_domain"] + "/" } func GetSysCfgStr(key string) string { redisConn := cache.GetPool().Get() sysCfgDb := implement.NewSysCfgDb(db.Db, redisConn) defer func(sysCfgDb dao.SysCfgDao) { err := sysCfgDb.Close() if err != nil { logx.Error("redis close err:" + err.Error()) // 记录错误信息 } }(sysCfgDb) return sysCfgDb.SysCfgGetWithDb(key) } func SetSysCfgStr(key, val string) bool { redisConn := cache.GetPool().Get() cfgDb := implement.NewSysCfgDb(db.Db, redisConn) defer func(cfgDb dao.SysCfgDao) { err := cfgDb.Close() if err != nil { logx.Error("redis close err:" + err.Error()) // 记录错误信息 } }(cfgDb) var bools bool if val != "" { data, _ := cfgDb.SysCfgGetOne(key) if data == nil { bools = cfgDb.SysCfgInsert(key, val, "") } else { bools = cfgDb.SysCfgUpdate(key, val) } } return bools } func CreateSTSClient(accessKeyId *string, accessKeySecret *string, stsEndpoint *string) (*sts20150401.Client, error) { config := &openapi.Config{ AccessKeyId: accessKeyId, AccessKeySecret: accessKeySecret, // Endpoint 请参考 https://api.aliyun.com/product/Sts Endpoint: stsEndpoint, } return sts20150401.NewClient(config) } func AssumeRole(client *sts20150401.Client, roleArn *string, roleSessionName *string, durationSeconds int64) (*sts20150401.AssumeRoleResponse, error) { assumeRoleRequest := &sts20150401.AssumeRoleRequest{ DurationSeconds: &durationSeconds, RoleArn: roleArn, RoleSessionName: roleSessionName, } return client.AssumeRoleWithOptions(assumeRoleRequest, &util2.RuntimeOptions{}) } func CreateGetRoleClient(accessKeyId, accessKeySecret *string) (_result *ram20150501.Client, _err error) { config := &openapi.Config{ AccessKeyId: accessKeyId, AccessKeySecret: accessKeySecret, } // Endpoint 请参考 https://api.aliyun.com/product/Ram config.Endpoint = tea.String("ram.aliyuncs.com") _result = &ram20150501.Client{} _result, _err = ram20150501.NewClient(config) return _result, _err } // 操作日志 func AddAdminLog(c *gin.Context, adminId int, types, memo, ext string) { var tmp = model.AdminLog{ Type: types, AdminId: adminId, Memo: memo, Time: time.Now(), Ip: utils.GetIP(c.Request), Data: ext, } db.Db.Insert(&tmp) }