2023-06-21 10:59:27 +00:00
|
|
|
package logic
|
|
|
|
|
|
|
|
import (
|
2023-06-25 03:26:47 +00:00
|
|
|
"encoding/json"
|
2023-06-21 10:59:27 +00:00
|
|
|
"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"
|
|
|
|
)
|
|
|
|
|
2023-07-21 07:20:18 +00:00
|
|
|
type WebSetSettingLogic struct {
|
2023-06-21 10:59:27 +00:00
|
|
|
logx.Logger
|
|
|
|
ctx context.Context
|
|
|
|
svcCtx *svc.ServiceContext
|
|
|
|
}
|
|
|
|
|
2023-07-21 07:20:18 +00:00
|
|
|
func NewWebSetSettingLogic(ctx context.Context, svcCtx *svc.ServiceContext) *WebSetSettingLogic {
|
|
|
|
return &WebSetSettingLogic{
|
2023-06-21 10:59:27 +00:00
|
|
|
Logger: logx.WithContext(ctx),
|
|
|
|
ctx: ctx,
|
|
|
|
svcCtx: svcCtx,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-21 07:20:18 +00:00
|
|
|
// 处理进入前逻辑w,r
|
|
|
|
// func (l *WebSetSettingLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
|
|
|
|
// }
|
|
|
|
|
|
|
|
// 处理逻辑后 w,r 如:重定向
|
2023-07-24 05:17:02 +00:00
|
|
|
// func (l *WebSetSettingLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
|
2023-07-21 07:20:18 +00:00
|
|
|
// }
|
|
|
|
|
|
|
|
func (l *WebSetSettingLogic) WebSetSetting(req *types.RequestWebSet, userinfo *auth.UserInfo) (resp *basic.Response) {
|
2023-06-21 10:59:27 +00:00
|
|
|
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
|
|
|
// userinfo 传入值时, 一定不为null
|
2023-06-25 03:26:47 +00:00
|
|
|
typeConf := constants.TypeWebSet(req.Type)
|
2023-06-21 10:59:27 +00:00
|
|
|
|
2023-06-25 03:26:47 +00:00
|
|
|
//如果是这三个配置项 则读取缓存
|
|
|
|
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)
|
|
|
|
}
|
2023-06-21 10:59:27 +00:00
|
|
|
|
2023-06-25 03:26:47 +00:00
|
|
|
//读取配置项
|
|
|
|
err = json.Unmarshal([]byte(*data.Value), &result)
|
|
|
|
if err != nil {
|
|
|
|
return resp.SetStatus(basic.CodeJsonErr)
|
|
|
|
}
|
2023-06-21 10:59:27 +00:00
|
|
|
|
2023-06-25 05:15:55 +00:00
|
|
|
return resp.SetStatus(basic.CodeOK, result)
|
2023-07-21 07:20:18 +00:00
|
|
|
|
|
|
|
return resp.SetStatus(basic.CodeOK)
|
2023-06-21 10:59:27 +00:00
|
|
|
}
|