Files

58 lines
1.2 KiB
Go
Raw Normal View History

2021-10-27 13:27:01 +08:00
package controller
2021-12-16 13:22:14 +08:00
import (
2022-01-10 10:00:04 +08:00
"SciencesServer/app/api/admin/model"
model2 "SciencesServer/app/common/model"
2022-01-05 18:40:08 +08:00
"SciencesServer/app/session"
2021-12-16 13:22:14 +08:00
)
2021-10-27 13:27:01 +08:00
2022-01-13 18:07:40 +08:00
type Config struct{ *session.Enterprise }
2021-10-27 13:27:01 +08:00
2022-01-13 18:07:40 +08:00
type ConfigHandle func(session *session.Enterprise) *Config
2021-10-27 13:27:01 +08:00
2022-01-10 10:00:04 +08:00
type (
2022-01-15 11:54:05 +08:00
// ConfigInfo 配置信息
2022-01-10 10:00:04 +08:00
ConfigInfo struct {
Name string `json:"name"`
Value string `json:"value"`
}
)
2022-02-23 15:18:55 +08:00
func (c *Config) Instance(kind int, key []string) (map[string]*ConfigInfo, error) {
2022-01-10 10:00:04 +08:00
mSysConfig := model.NewSysConfig()
2021-12-16 13:22:14 +08:00
2022-02-23 15:18:55 +08:00
where := []*model2.ModelWhereOrder{&model2.ModelWhereOrder{
Where: model2.NewWhereIn("`key`", key),
Order: nil,
}}
2022-01-10 10:00:04 +08:00
2022-01-15 11:54:05 +08:00
if kind > 0 {
2022-02-23 15:18:55 +08:00
where = append(where, &model2.ModelWhereOrder{
Where: model2.NewWhere("kind", kind),
Order: nil,
})
2022-01-15 11:54:05 +08:00
}
2022-02-23 15:18:55 +08:00
out := make([]*model2.SysConfig, 0)
err := model2.ScanFields(mSysConfig.SysConfig, &out, []string{"id", "`key`", "name", "`value`"}, where...)
2022-01-15 11:54:05 +08:00
if err != nil {
2022-01-10 10:00:04 +08:00
return nil, err
}
2022-02-23 15:18:55 +08:00
list := make(map[string]*ConfigInfo, 0)
for _, v := range out {
list[v.Key] = &ConfigInfo{
Name: v.Name,
Value: v.Value,
}
}
return list, nil
2021-12-16 13:22:14 +08:00
}
2021-10-27 13:27:01 +08:00
func NewConfig() ConfigHandle {
2022-01-13 18:07:40 +08:00
return func(session *session.Enterprise) *Config {
return &Config{Enterprise: session}
2021-10-27 13:27:01 +08:00
}
}