From 011cb40fdfc74d4f020512ff94386a156f13b5ac Mon Sep 17 00:00:00 2001 From: SliverHorn Date: Sat, 4 Sep 2021 22:59:13 +0800 Subject: [PATCH 1/2] =?UTF-8?q?update:=20service/system/sys=5Fdictionary.g?= =?UTF-8?q?o=20UpdateSysDictionary=20=E6=96=B9=E6=B3=95=20=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/service/system/sys_dictionary.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/server/service/system/sys_dictionary.go b/server/service/system/sys_dictionary.go index 1335218d..37f05b69 100644 --- a/server/service/system/sys_dictionary.go +++ b/server/service/system/sys_dictionary.go @@ -52,15 +52,12 @@ func (dictionaryService *DictionaryService) UpdateSysDictionary(sysDictionary *s "Desc": sysDictionary.Desc, } db := global.GVA_DB.Where("id = ?", sysDictionary.ID).First(&dict) - if dict.Type == sysDictionary.Type { - err = db.Updates(sysDictionaryMap).Error - } else { - if (!errors.Is(global.GVA_DB.First(&system.SysDictionary{}, "type = ?", sysDictionary.Type).Error, gorm.ErrRecordNotFound)) { + if dict.Type != sysDictionary.Type { + if !errors.Is(global.GVA_DB.First(&system.SysDictionary{}, "type = ?", sysDictionary.Type).Error, gorm.ErrRecordNotFound) { return errors.New("存在相同的type,不允许创建") } - err = db.Updates(sysDictionaryMap).Error - } + err = db.Updates(sysDictionaryMap).Error return err } From 4ae6ed866705390e75f007f85865a79103ce3d56 Mon Sep 17 00:00:00 2001 From: SliverHorn Date: Sun, 5 Sep 2021 12:56:59 +0800 Subject: [PATCH 2/2] =?UTF-8?q?update:=20LoadAll=E5=87=BD=E6=95=B0?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/service/system/jwt_black_list.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/server/service/system/jwt_black_list.go b/server/service/system/jwt_black_list.go index a73c32be..6a97619f 100644 --- a/server/service/system/jwt_black_list.go +++ b/server/service/system/jwt_black_list.go @@ -2,6 +2,7 @@ package system import ( "context" + "go.uber.org/zap" "time" "github.com/flipped-aurora/gin-vue-admin/server/global" @@ -22,8 +23,7 @@ func (jwtService *JwtService) JsonInBlacklist(jwtList system.JwtBlacklist) (err if err != nil { return } - global.BlackCache.SetDefault(jwtList.Jwt, struct { - }{}) + global.BlackCache.SetDefault(jwtList.Jwt, struct{}{}) return } @@ -67,12 +67,12 @@ func (jwtService *JwtService) SetRedisJWT(jwt string, userName string) (err erro func LoadAll() { var data []string - err := global.GVA_DB.Find(&system.JwtBlacklist{}).Select("jwt").Find(&data).Error + err := global.GVA_DB.Model(&system.JwtBlacklist{}).Select("jwt").Find(&data).Error if err != nil { - // 从db加载jwt数据 - for i := range data { - global.BlackCache.SetDefault(data[i], struct { - }{}) - } + global.GVA_LOG.Error("加载数据库jwt黑名单失败!", zap.Error(err)) + return } + for i := 0; i < len(data); i++ { + global.BlackCache.SetDefault(data[i], struct{}{}) + } // jwt黑名单 加入 BlackCache 中 }