refactor🎨 部分功能重写

This commit is contained in:
wenjianzhang committed 2021-05-21 18:25:51 +08:00
1 parent 765775c54d
commit 408dcc5057
28 files changed
+649 -982

No files matched your search

+7 -49
View File
@@ -1,10 +1,6 @@
package dto
import (
"encoding/json"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"
"github.com/go-admin-team/go-admin-core/sdk/api"
"go-admin/app/admin/models"
common "go-admin/common/models"
@@ -28,15 +24,6 @@ func (m *SysMenuSearch) GetNeedSearch() interface{} {
return *m
}
// Bind 映射上下文中的结构体数据
func (m *SysMenuSearch) Bind(ctx *gin.Context) error {
log := api.GetRequestLogger(ctx)
err := ctx.ShouldBind(m)
if err != nil {
log.Debugf("ShouldBind error: %s", err.Error())
}
return err
}
// SysMenuControl 增、改使用的结构体
type SysMenuControl struct {
@@ -69,27 +56,6 @@ func (s *SysMenuControl) SetUpdateBy(id int) {
s.UpdateBy = id
}
// Bind 映射上下文中的结构体数据
func (s *SysMenuControl) Bind(ctx *gin.Context) error {
log := api.GetRequestLogger(ctx)
err := ctx.ShouldBindUri(s)
if err != nil {
log.Debugf("ShouldBindUri error: %s", err.Error())
return err
}
err = ctx.ShouldBindBodyWith(s, binding.JSON)
if err != nil {
log.Debugf("ShouldBind error: %s", err.Error())
}
var jsonStr []byte
jsonStr, err = json.Marshal(s)
if err != nil {
log.Debugf("ShouldBind error: %s", err.Error())
}
ctx.Set("body", string(jsonStr))
return err
}
// Generate 结构体数据转化 从 Control 至 model 对应的模型
func (s *SysMenuControl) Generate(model *models.SysMenu) {
if s.MenuId != 0 {
@@ -124,35 +90,27 @@ func (s *SysMenuControl) GetId() interface{} {
return s.MenuId
}
// SysConfigById 获取单个或者删除的结构体
// SysMenuById 获取单个或者删除的结构体
type SysMenuById struct {
Id int `uri:"id"`
Ids []int `json:"ids"`
common.ControlBy
}
func (s *SysMenuById) Generate() *SysMenuById {
cp := *s
return &cp
}
func (s *SysMenuById) GetId() interface{} {
if len(s.Ids) > 0 {
s.Ids = append(s.Ids, s.Id)
return s.Ids
}
return s.Id
}
func (s *SysMenuById) Bind(ctx *gin.Context) error {
log := api.GetRequestLogger(ctx)
err := ctx.ShouldBindUri(s)
if err != nil {
log.Debugf("ShouldBindUri error: %s", err.Error())
return err
}
err = ctx.ShouldBind(s)
if err != nil {
log.Debugf("ShouldBind error: %s", err.Error())
}
return err
}
func (s *SysMenuById) GenerateM() (*models.SysMenu, error) {
return &models.SysMenu{}, nil
}