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

+26 -48
View File
@@ -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"
@@ -39,7 +38,7 @@ func (m *SysDeptSearch) Bind(ctx *gin.Context) error {
return err
}
// SysConfigControl 增、改使用的结构体
// SysDeptControl 增、改使用的结构体
type SysDeptControl struct {
DeptId int `uri:"id" comment:"编码"` // 编码
ParentId int `form:"parentId" comment:"上级部门"` //上级部门
@@ -50,42 +49,30 @@ type SysDeptControl struct {
Phone string `form:"phone" comment:"手机"` //手机
Email string `form:"email" comment:"邮箱"` //邮箱
Status string `form:"status" comment:"状态"` //状态
common.ControlBy
}
// Bind 映射上下文中的结构体数据
func (s *SysDeptControl) 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
func (s *SysDeptControl) SetCreateBy(id int) {
s.CreateBy = id
}
// Generate 结构体数据转化 从 SysConfigControl 至 system.SysConfig 对应的模型
func (s *SysDeptControl) Generate() (*models.SysDept, error) {
return &models.SysDept{
DeptId: s.DeptId,
DeptName: s.DeptName,
ParentId: s.ParentId,
DeptPath: s.DeptPath,
Sort: s.Sort,
Leader: s.Leader,
Phone: s.Phone,
Email: s.Email,
Status: s.Status,
}, nil
func (s *SysDeptControl) SetUpdateBy(id int) {
s.UpdateBy = id
}
// Generate 结构体数据转化 从 SysDeptControl 至 SysDept 对应的模型
func (s *SysDeptControl) Generate(model *models.SysDept) {
if s.DeptId != 0 {
model.DeptId = s.DeptId
}
model.DeptName = s.DeptName
model.ParentId = s.ParentId
model.DeptPath = s.DeptPath
model.Sort = s.Sort
model.Leader = s.Leader
model.Phone = s.Phone
model.Email = s.Email
model.Status = s.Status
}
// GetId 获取数据对应的ID
@@ -105,22 +92,13 @@ func (s *SysDeptById) Generate() *SysDeptById {
}
func (s *SysDeptById) GetId() interface{} {
if len(s.Ids) > 0 {
s.Ids = append(s.Ids, s.Id)
return s.Ids
}
return s.Id
}
func (s *SysDeptById) 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 *SysDeptById) GenerateM() (*models.SysDept, error) {
return &models.SysDept{}, nil