From 096b7d7c83deee8cc9f700f64e62f978faec520c Mon Sep 17 00:00:00 2001 From: huanghai <10402852@qq.com> Date: Mon, 24 Aug 2020 13:04:42 +0800 Subject: [PATCH] 'commit' --- .../AccessSystemDao/AccessSystemDao.go | 162 +++++++++++++----- 1 file changed, 116 insertions(+), 46 deletions(-) diff --git a/dsSupport/MyModel/AccessSystem/AccessSystemDao/AccessSystemDao.go b/dsSupport/MyModel/AccessSystem/AccessSystemDao/AccessSystemDao.go index 2c3b8110..c88829e2 100644 --- a/dsSupport/MyModel/AccessSystem/AccessSystemDao/AccessSystemDao.go +++ b/dsSupport/MyModel/AccessSystem/AccessSystemDao/AccessSystemDao.go @@ -23,7 +23,7 @@ var db = DbUtil.Engine /** 功能:增加一个接入系统 */ -func AddApp(appCode string, appName string, appUrl string, appIcon string, redirectUri string, sortId int32) error { +func AddApp(appCode string, appName string, sortId int32) error { //生成AK+SK ak := xid.New() appKey := ak.String() //新增就生成一个secret @@ -44,9 +44,13 @@ func AddApp(appCode string, appName string, appUrl string, appIcon string, redir model.AppName = appName model.AccessKey = appKey model.SecretKey = appSecret - model.AppUrl = appUrl - model.AppIcon = appIcon - model.RedirectUri = redirectUri + if sortId == 0 { + c, err := getMaxSortId() + if err != nil { + return err + } + sortId = int32(c) + } model.SortId = sortId model.BUse = 1 _, err := db.Insert(&model) @@ -58,44 +62,6 @@ func AddApp(appCode string, appName string, appUrl string, appIcon string, redir return err } -/** -功能:插入REDIS缓存 -*/ -func insertRedisCache(accessKey string, secreKey string, redirectUri string) error { - resp, err := http.PostForm("http://127.0.0.1/oauth2/AddClient", - url.Values{"access_key": {accessKey}, "secret_key": {secreKey}, "redirect_uri": {redirectUri}}) - if err != nil { - return err - } - - defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) - if err != nil { - return err - } - fmt.Println(string(body)) - return nil -} - -/** -功能:删除REDIS缓存 -*/ -func deleteRedisCache(accessKey string) error { - //插入REDIS缓存 - resp, err := http.PostForm("http://127.0.0.1/oauth2/DelClient", - url.Values{"access_key": {accessKey}}) - if err != nil { - return err - } - defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) - if err != nil { - return nil - } - fmt.Println(string(body)) - return nil -} - /** 功能:删除一个接入系统 */ @@ -112,7 +78,7 @@ func DelApp(appId string) error { /** 功能:修改一个接入系统 */ -func UpdateApp(appId string, appCode string, appName string, appUrl string, appIcon string, redirectUri string, sortId int32) error { +func UpdateApp(appId string, appCode string, appName string, sortId int32) error { model := new(models.TAppBase) //修改REDIS缓存 _, err := db.Where("app_id = ?", appId).Get(&model) @@ -121,17 +87,70 @@ func UpdateApp(appId string, appCode string, appName string, appUrl string, appI model.AppCode = appCode model.AppName = appName - model.AppUrl = appUrl - model.AppIcon = appIcon - model.RedirectUri = redirectUri model.SortId = sortId _, err = db.ID(appId).Update(model) + return err +} + +/** +功能:统一认证配置 +*/ +func UpdateSso(appId string, redirectUri string, logoutUri string) error { + model := new(models.TAppBase) + //修改REDIS缓存 + _, err := db.Where("app_id = ?", appId).Get(&model) + //删除REDIS缓存 + deleteRedisCache(model.AccessKey) + model.RedirectUri = redirectUri + model.LogoutUri = logoutUri + _, err = db.ID(appId).Update(model) + //插入REDIS缓存 + err = insertRedisCache(model.AccessKey, model.SecretKey, model.RedirectUri) + return err +} +/** +功能:清空统一认证信息 +*/ +func ClearSso(appId string) error { + model := new(models.TAppBase) + //修改REDIS缓存 + _, err := db.Where("app_id = ?", appId).Get(&model) + //删除REDIS缓存 + deleteRedisCache(model.AccessKey) + model.RedirectUri = "" + model.LogoutUri = "" + _, err = db.ID(appId).Cols("redirect_uri", "logout_uri").Update(model) //插入REDIS缓存 err = insertRedisCache(model.AccessKey, model.SecretKey, model.RedirectUri) return err } +/** +功能:集成系统配置 +*/ +func UpdateIntegration(appId string, appUrl string, appIcon string) error { + model := new(models.TAppBase) + //修改REDIS缓存 + _, err := db.Where("app_id = ?", appId).Get(&model) + model.AppUrl = appUrl + model.AppIcon = appIcon + _, err = db.ID(appId).Update(model) + return err +} + +/** +功能:清空集成系统信息 +*/ +func ClearIntegration(appId string) error { + model := new(models.TAppBase) + _, err := db.Where("app_id = ?", appId).Get(&model) + model.AppUrl = "" + model.AppIcon = "" + _, err = db.ID(appId).Cols("app_url", "app_icon").Update(model) + return err +} + /** 功能:获取单个App的信息 */ @@ -164,3 +183,54 @@ func ListApp(keyword string, page int, limit int) ([]map[string]interface{}, int list, count, err := SqlKit.Query(sql) return list, count, err } + +/******************************************以下为内部函数***************************/ +/** +功能:获取最大排序号 +*/ +func getMaxSortId() (int64, error) { + sql := `select ifnull(max(sort_id),1) as c from t_app_base` + list, err := db.SQL(sql).Query().List() + if err != nil { + return -1, err + } + return list[0]["c"].(int64), nil +} + +/** +功能:插入REDIS缓存 +*/ +func insertRedisCache(accessKey string, secreKey string, redirectUri string) error { + resp, err := http.PostForm("http://127.0.0.1/oauth2/AddClient", + url.Values{"access_key": {accessKey}, "secret_key": {secreKey}, "redirect_uri": {redirectUri}}) + if err != nil { + return err + } + + defer resp.Body.Close() + body, err := ioutil.ReadAll(resp.Body) + if err != nil { + return err + } + fmt.Println(string(body)) + return nil +} + +/** +功能:删除REDIS缓存 +*/ +func deleteRedisCache(accessKey string) error { + //插入REDIS缓存 + resp, err := http.PostForm("http://127.0.0.1/oauth2/DelClient", + url.Values{"access_key": {accessKey}}) + if err != nil { + return err + } + defer resp.Body.Close() + body, err := ioutil.ReadAll(resp.Body) + if err != nil { + return nil + } + fmt.Println(string(body)) + return nil +}