refactor🎨 核心业务结构调整
This commit is contained in:
1 parent
408dcc5057
commit
e473f158e8
13 files changed
+406
-761
No files matched your search
@@ -1,11 +1,10 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"go-admin/app/admin/models"
|
||||
common "go-admin/common/models"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gin-gonic/gin/binding"
|
||||
"github.com/go-admin-team/go-admin-core/sdk/api"
|
||||
|
||||
"go-admin/common/dto"
|
||||
@@ -36,7 +35,7 @@ func (m *SysPostSearch) Bind(ctx *gin.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// SysConfigControl 增、改使用的结构体
|
||||
// SysPostControl 增、改使用的结构体
|
||||
type SysPostControl struct {
|
||||
PostId int `uri:"id" comment:"id"` // id
|
||||
PostName string `form:"postName" comment:"名称"` // 名称
|
||||
@@ -44,39 +43,25 @@ type SysPostControl struct {
|
||||
Sort int `form:"sort" comment:"排序"` // 排序
|
||||
Status int `form:"status" comment:"状态"` // 状态
|
||||
Remark string `form:"remark" comment:"备注"` // 备注
|
||||
}
|
||||
|
||||
// Bind 映射上下文中的结构体数据
|
||||
func (s *SysPostControl) 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
|
||||
common.ControlBy
|
||||
}
|
||||
|
||||
// Generate 结构体数据转化 从 SysConfigControl 至 system.SysConfig 对应的模型
|
||||
func (s *SysPostControl) Generate() (*models.SysPost, error) {
|
||||
return &models.SysPost{
|
||||
PostId: s.PostId,
|
||||
PostName: s.PostName,
|
||||
PostCode: s.PostCode,
|
||||
Sort: s.Sort,
|
||||
Status: s.Status,
|
||||
Remark: s.Remark,
|
||||
}, nil
|
||||
func (s *SysPostControl) Generate(model *models.SysPost) {
|
||||
if s.PostId != 0 {
|
||||
model.PostId = s.PostId
|
||||
}
|
||||
model.PostName = s.PostName
|
||||
model.PostCode = s.PostCode
|
||||
model.Sort = s.Sort
|
||||
model.Status = s.Status
|
||||
model.Remark = s.Remark
|
||||
if s.ControlBy.UpdateBy != 0 {
|
||||
model.UpdateBy = s.UpdateBy
|
||||
}
|
||||
if s.ControlBy.CreateBy != 0 {
|
||||
model.CreateBy = s.CreateBy
|
||||
}
|
||||
}
|
||||
|
||||
// GetId 获取数据对应的ID
|
||||
@@ -84,15 +69,20 @@ func (s *SysPostControl) GetId() interface{} {
|
||||
return s.PostId
|
||||
}
|
||||
|
||||
// SysConfigById 获取单个或者删除的结构体
|
||||
// SysPostById 获取单个或者删除的结构体
|
||||
type SysPostById struct {
|
||||
Id int `uri:"id"`
|
||||
Ids []int `json:"ids"`
|
||||
common.ControlBy
|
||||
}
|
||||
|
||||
func (s *SysPostById) Generate() *SysPostById {
|
||||
cp := *s
|
||||
return &cp
|
||||
func (s *SysPostById) Generate(model *models.SysPost) {
|
||||
if s.ControlBy.UpdateBy != 0 {
|
||||
model.UpdateBy = s.UpdateBy
|
||||
}
|
||||
if s.ControlBy.CreateBy != 0 {
|
||||
model.CreateBy = s.CreateBy
|
||||
}
|
||||
}
|
||||
|
||||
func (s *SysPostById) GetId() interface{} {
|
||||
@@ -119,4 +109,4 @@ func (s *SysPostById) Bind(ctx *gin.Context) error {
|
||||
|
||||
func (s *SysPostById) GenerateM() (*models.SysPost, error) {
|
||||
return &models.SysPost{}, nil
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user