feat:优化项目信息
This commit is contained in:
@ -10,8 +10,8 @@ type Config struct{}
|
||||
|
||||
func (*Config) Index(c *gin.Context) {
|
||||
form := &struct {
|
||||
Kind int `json:"kind" form:"kind"`
|
||||
Key string `json:"key" form:"key" binding:"required"`
|
||||
Kind int `json:"kind" form:"kind"`
|
||||
Key []string `json:"key" form:"key" binding:"required"`
|
||||
}{}
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
|
@ -4,7 +4,6 @@ import (
|
||||
"SciencesServer/app/api/admin/model"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/session"
|
||||
"errors"
|
||||
)
|
||||
|
||||
type Config struct{ *session.Enterprise }
|
||||
@ -19,22 +18,36 @@ type (
|
||||
}
|
||||
)
|
||||
|
||||
func (c *Config) Instance(kind int, key string) (*ConfigInfo, error) {
|
||||
func (c *Config) Instance(kind int, key []string) (map[string]*ConfigInfo, error) {
|
||||
mSysConfig := model.NewSysConfig()
|
||||
|
||||
where := []*model2.ModelWhere{model2.NewWhere("`key`", key)}
|
||||
where := []*model2.ModelWhereOrder{&model2.ModelWhereOrder{
|
||||
Where: model2.NewWhereIn("`key`", key),
|
||||
Order: nil,
|
||||
}}
|
||||
|
||||
if kind > 0 {
|
||||
where = append(where, model2.NewWhere("kind", kind))
|
||||
where = append(where, &model2.ModelWhereOrder{
|
||||
Where: model2.NewWhere("kind", kind),
|
||||
Order: nil,
|
||||
})
|
||||
}
|
||||
isExist, err := model2.FirstField(mSysConfig.SysConfig, []string{"id", "name", "`value`"}, where...)
|
||||
out := make([]*model2.SysConfig, 0)
|
||||
|
||||
err := model2.ScanFields(mSysConfig.SysConfig, &out, []string{"id", "`key`", "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
|
||||
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 {
|
||||
|
Reference in New Issue
Block a user