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 (
|
|
|
|
ConfigInfo struct {
|
|
|
|
Kind int `json:"kind"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
Key string `json:"key"`
|
|
|
|
Value string `json:"value"`
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
func (c *Config) Instance(kind int) ([]*ConfigInfo, error) {
|
|
|
|
mSysConfig := model.NewSysConfig()
|
2021-12-16 13:22:14 +08:00
|
|
|
|
2022-01-10 10:00:04 +08:00
|
|
|
out := make([]*ConfigInfo, 0)
|
|
|
|
|
|
|
|
if err := model2.ScanFields(mSysConfig.SysConfig, &out, []string{"kind", "name", "`key`", "`value`"},
|
|
|
|
&model2.ModelWhereOrder{Where: model2.NewWhere("kind", kind)}); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return out, 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
|
|
|
}
|
|
|
|
}
|