Browse Source
Merge pull request #674 from SliverHorn/sliver_horn_develop
update: service/system/sys_dictionary.go UpdateSysDictionary 方法 代码优化
main
奇淼(piexlmax
3 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
11 additions and
14 deletions
-
server/service/system/jwt_black_list.go
-
server/service/system/sys_dictionary.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 中
|
|
|
|
} |
|
|
@ -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 |
|
|
|
} |
|
|
|
|
|
|
|