refactor: code optimization

This commit is contained in:
meilin.huang
2025-04-23 20:36:32 +08:00
parent 798ab7d18b
commit 2170509d92
33 changed files with 445 additions and 380 deletions

View File

@@ -110,7 +110,7 @@ func (a *Account) ChangePassword(rc *req.Ctx) {
form := req.BindJsonAndValid(rc, new(form.AccountChangePasswordForm))
originOldPwd, err := cryptox.DefaultRsaDecrypt(form.OldPassword, true)
originOldPwd, err := utils.DefaultRsaDecrypt(form.OldPassword, true)
biz.ErrIsNilAppendErr(err, "Wrong to decrypt old password: %s")
account := &entity.Account{Username: form.Username}
@@ -119,7 +119,7 @@ func (a *Account) ChangePassword(rc *req.Ctx) {
biz.IsTrueI(ctx, cryptox.CheckPwdHash(originOldPwd, account.Password), imsg.ErrOldPasswordWrong)
biz.IsTrue(account.IsEnable(), "This account is not available")
originNewPwd, err := cryptox.DefaultRsaDecrypt(form.NewPassword, true)
originNewPwd, err := utils.DefaultRsaDecrypt(form.NewPassword, true)
biz.ErrIsNilAppendErr(err, "Wrong to decrypt new password: %s")
biz.IsTrueI(ctx, utils.CheckAccountPasswordLever(originNewPwd), imsg.ErrAccountPasswordNotFollowRule)

View File

@@ -2,7 +2,6 @@ package application
import (
"context"
"encoding/json"
"mayfly-go/internal/sys/domain/entity"
"mayfly-go/internal/sys/domain/repository"
"mayfly-go/pkg/base"
@@ -10,7 +9,6 @@ import (
"mayfly-go/pkg/errorx"
"mayfly-go/pkg/logx"
"mayfly-go/pkg/model"
"mayfly-go/pkg/utils/jsonx"
"strings"
)
@@ -56,16 +54,14 @@ func (a *configAppImpl) Save(ctx context.Context, config *entity.Config) error {
func (a *configAppImpl) GetConfig(key string) *entity.Config {
config := &entity.Config{Key: key}
// 优先从缓存中获取
cacheStr := cache.GetStr(SysConfigKeyPrefix + key)
if cacheStr != "" {
json.Unmarshal([]byte(cacheStr), &config)
if exist := cache.Get(SysConfigKeyPrefix+key, &config); exist {
return config
}
if err := a.GetByCond(model.NewModelCond(config).Columns("Id", "Key", "Value", "Permission")); err != nil {
logx.Warnf("There is no system configuration with key = [%s]", key)
} else {
cache.SetStr(SysConfigKeyPrefix+key, jsonx.ToStr(config), -1)
cache.Set(SysConfigKeyPrefix+key, config, -1)
}
return config
}