58 lines
1.2 KiB
Go
58 lines
1.2 KiB
Go
package controller
|
|
|
|
import (
|
|
"SciencesServer/app/api/admin/model"
|
|
model2 "SciencesServer/app/common/model"
|
|
"SciencesServer/app/session"
|
|
)
|
|
|
|
type Config struct{ *session.Enterprise }
|
|
|
|
type ConfigHandle func(session *session.Enterprise) *Config
|
|
|
|
type (
|
|
// ConfigInfo 配置信息
|
|
ConfigInfo struct {
|
|
Name string `json:"name"`
|
|
Value string `json:"value"`
|
|
}
|
|
)
|
|
|
|
func (c *Config) Instance(kind int, key []string) (map[string]*ConfigInfo, error) {
|
|
mSysConfig := model.NewSysConfig()
|
|
|
|
where := []*model2.ModelWhereOrder{&model2.ModelWhereOrder{
|
|
Where: model2.NewWhereIn("`key`", key),
|
|
Order: nil,
|
|
}}
|
|
|
|
if kind > 0 {
|
|
where = append(where, &model2.ModelWhereOrder{
|
|
Where: model2.NewWhere("kind", kind),
|
|
Order: nil,
|
|
})
|
|
}
|
|
out := make([]*model2.SysConfig, 0)
|
|
|
|
err := model2.ScanFields(mSysConfig.SysConfig, &out, []string{"id", "`key`", "name", "`value`"}, where...)
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
list := make(map[string]*ConfigInfo, 0)
|
|
|
|
for _, v := range out {
|
|
list[v.Key] = &ConfigInfo{
|
|
Name: v.Name,
|
|
Value: v.Value,
|
|
}
|
|
}
|
|
return list, nil
|
|
}
|
|
|
|
func NewConfig() ConfigHandle {
|
|
return func(session *session.Enterprise) *Config {
|
|
return &Config{Enterprise: session}
|
|
}
|
|
}
|