70 lines
2.7 KiB
Go
70 lines
2.7 KiB
Go
// Copyright © 2023 OpenIM open source community. All rights reserved.
|
||
//
|
||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||
// you may not use this file except in compliance with the License.
|
||
// You may obtain a copy of the License at
|
||
//
|
||
// http://www.apache.org/licenses/LICENSE-2.0
|
||
//
|
||
// Unless required by applicable law or agreed to in writing, software
|
||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||
// See the License for the specific language governing permissions and
|
||
// limitations under the License.
|
||
|
||
package chat
|
||
|
||
import (
|
||
"context"
|
||
"time"
|
||
|
||
"github.com/openimsdk/tools/db/pagination"
|
||
)
|
||
|
||
// ConfigValueType 配置值类型
|
||
const (
|
||
ConfigValueTypeString = 1 // 字符串类型
|
||
ConfigValueTypeNumber = 2 // 数字类型
|
||
ConfigValueTypeBool = 3 // 布尔类型
|
||
ConfigValueTypeJSON = 4 // JSON类型
|
||
)
|
||
|
||
// ConfigKey 常用配置键
|
||
const (
|
||
// 钱包相关配置
|
||
ConfigKeyWalletEnabled = "wallet.enabled" // 是否开启钱包功能
|
||
|
||
// 注册相关配置
|
||
ConfigKeyPhoneRegisterVerifyCodeEnabled = "register.phone.verify_code.enabled" // 手机号注册验证码功能是否开启
|
||
)
|
||
|
||
// SystemConfig 系统配置模型
|
||
type SystemConfig struct {
|
||
Key string `bson:"key"` // 配置键(唯一标识)
|
||
Title string `bson:"title"` // 配置标题
|
||
Value string `bson:"value"` // 配置值(字符串形式存储,根据ValueType解析)
|
||
ValueType int32 `bson:"value_type"` // 配置值类型:1-字符串,2-数字,3-布尔,4-JSON
|
||
Description string `bson:"description"` // 配置描述
|
||
Enabled bool `bson:"enabled"` // 是否启用(用于开关类配置)
|
||
ShowInApp bool `bson:"show_in_app"` // 是否在APP端展示
|
||
CreateTime time.Time `bson:"create_time"` // 创建时间
|
||
UpdateTime time.Time `bson:"update_time"` // 更新时间
|
||
}
|
||
|
||
func (SystemConfig) TableName() string {
|
||
return "system_configs"
|
||
}
|
||
|
||
type SystemConfigInterface interface {
|
||
Create(ctx context.Context, configs ...*SystemConfig) error
|
||
Take(ctx context.Context, key string) (*SystemConfig, error)
|
||
FindByKeys(ctx context.Context, keys []string) ([]*SystemConfig, error)
|
||
FindAll(ctx context.Context, pagination pagination.Pagination) (int64, []*SystemConfig, error)
|
||
Update(ctx context.Context, key string, data map[string]any) error
|
||
UpdateValue(ctx context.Context, key string, value string) error
|
||
UpdateEnabled(ctx context.Context, key string, enabled bool) error
|
||
Delete(ctx context.Context, keys []string) error
|
||
GetEnabledConfigs(ctx context.Context) ([]*SystemConfig, error)
|
||
GetAppConfigs(ctx context.Context) ([]*SystemConfig, error) // 获取所有 show_in_app=true 的配置
|
||
}
|