fusenapi/server/webset/internal/logic/websetsettinglogic.go
2023-07-11 13:07:44 +08:00

56 lines
1.4 KiB
Go

package logic
import (
"encoding/json"
"fusenapi/constants"
"fusenapi/utils/auth"
"fusenapi/utils/basic"
"context"
"fusenapi/server/webset/internal/svc"
"fusenapi/server/webset/internal/types"
"github.com/zeromicro/go-zero/core/logx"
"gorm.io/gorm"
)
type WetSetSettingLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewWetSetSettingLogic(ctx context.Context, svcCtx *svc.ServiceContext) *WetSetSettingLogic {
return &WetSetSettingLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *WetSetSettingLogic) WebSetSetting(req *types.RequestWebSet, userinfo *auth.UserInfo) (resp *basic.Response) {
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
// userinfo 传入值时, 一定不为null
typeConf := constants.TypeWebSet(req.Type)
//如果是这三个配置项 则读取缓存
var result map[string]interface{}
data, err := l.svcCtx.AllModels.FsWebSet.FindValueByKey(l.ctx, string(typeConf))
if err != nil {
if err == gorm.ErrRecordNotFound {
return resp.SetStatus(basic.CodeDbRecordNotFoundErr)
}
return resp.SetStatus(basic.CodeDbSqlErr)
}
//读取配置项
err = json.Unmarshal([]byte(*data.Value), &result)
if err != nil {
return resp.SetStatus(basic.CodeJsonErr)
}
return resp.SetStatus(basic.CodeOK, result)
}