feat:完善项目

This commit is contained in:
henry
2022-01-15 11:54:05 +08:00
parent 048d116b05
commit c5fb6023f3
18 changed files with 191 additions and 129 deletions

View File

@ -4,6 +4,7 @@ import (
"SciencesServer/app/api/admin/model"
model2 "SciencesServer/app/common/model"
"SciencesServer/app/session"
"errors"
)
type Config struct{ *session.Enterprise }
@ -11,24 +12,29 @@ type Config struct{ *session.Enterprise }
type ConfigHandle func(session *session.Enterprise) *Config
type (
// ConfigInfo 配置信息
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) {
func (c *Config) Instance(kind int, key string) (*ConfigInfo, error) {
mSysConfig := model.NewSysConfig()
out := make([]*ConfigInfo, 0)
where := []*model2.ModelWhere{model2.NewWhere("`key`", key)}
if err := model2.ScanFields(mSysConfig.SysConfig, &out, []string{"kind", "name", "`key`", "`value`"},
&model2.ModelWhereOrder{Where: model2.NewWhere("kind", kind)}); err != nil {
return nil, err
if kind > 0 {
where = append(where, model2.NewWhere("kind", kind))
}
return out, nil
isExist, err := model2.FirstField(mSysConfig.SysConfig, []string{"id", "name", "`value`"}, where...)
if err != nil {
return nil, err
} else if !isExist {
return nil, errors.New("操作错误,数据不存在或已被删除")
}
return &ConfigInfo{Name: mSysConfig.Name, Value: mSysConfig.Value}, nil
}
func NewConfig() ConfigHandle {