Files

45 lines
1.0 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"
2022-01-15 11:54:05 +08:00
"errors"
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-01-15 11:54:05 +08:00
func (c *Config) Instance(kind int, key string) (*ConfigInfo, error) {
2022-01-10 10:00:04 +08:00
mSysConfig := model.NewSysConfig()
2021-12-16 13:22:14 +08:00
2022-01-15 11:54:05 +08:00
where := []*model2.ModelWhere{model2.NewWhere("`key`", key)}
2022-01-10 10:00:04 +08:00
2022-01-15 11:54:05 +08:00
if kind > 0 {
where = append(where, model2.NewWhere("kind", kind))
}
isExist, err := model2.FirstField(mSysConfig.SysConfig, []string{"id", "name", "`value`"}, where...)
if err != nil {
2022-01-10 10:00:04 +08:00
return nil, err
2022-01-15 11:54:05 +08:00
} else if !isExist {
return nil, errors.New("操作错误,数据不存在或已被删除")
2022-01-10 10:00:04 +08:00
}
2022-01-15 11:54:05 +08:00
return &ConfigInfo{Name: mSysConfig.Name, Value: mSysConfig.Value}, 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
}
}