mirror of
https://github.com/go-admin-team/go-admin.git
synced 2026-09-22 02:27:57 +00:00
perf👌 : 部门和菜单功能改造
This commit is contained in:
@@ -0,0 +1,131 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gin-gonic/gin/binding"
|
||||
"go-admin/app/admin/models"
|
||||
"go-admin/common/dto"
|
||||
"go-admin/common/log"
|
||||
"go-admin/tools"
|
||||
)
|
||||
|
||||
// SysConfigSearch 列表或者搜索使用结构体
|
||||
type SysDeptSearch struct {
|
||||
dto.Pagination `search:"-"`
|
||||
ParentId int `form:"parentId" search:"type:exact;column:parent_id;table:sys_dept" comment:"上级部门"` //上级部门
|
||||
DeptPath string `form:"deptPath" search:"type:exact;column:dept_path;table:sys_dept" comment:""` //路径
|
||||
DeptName string `form:"deptName" search:"type:exact;column:dept_name;table:sys_dept" comment:"部门名称"` //部门名称
|
||||
Sort int `form:"sort" search:"type:exact;column:sort;table:sys_dept" comment:"排序"` //排序
|
||||
Leader string `form:"leader" search:"type:exact;column:leader;table:sys_dept" comment:"负责人"` //负责人
|
||||
Phone string `form:"phone" search:"type:exact;column:phone;table:sys_dept" comment:"手机"` //手机
|
||||
Email string `form:"email" search:"type:exact;column:email;table:sys_dept" comment:"邮箱"` //邮箱
|
||||
Status string `form:"status" search:"type:exact;column:status;table:sys_dept" comment:"状态"` //状态
|
||||
}
|
||||
|
||||
func (m *SysDeptSearch) GetNeedSearch() interface{} {
|
||||
return *m
|
||||
}
|
||||
|
||||
// Bind 映射上下文中的结构体数据
|
||||
func (m *SysDeptSearch) Bind(ctx *gin.Context) error {
|
||||
msgID := tools.GenerateMsgIDFromContext(ctx)
|
||||
err := ctx.ShouldBind(m)
|
||||
if err != nil {
|
||||
log.Debugf("MsgID[%s] ShouldBind error: %s", msgID, err.Error())
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// SysConfigControl 增、改使用的结构体
|
||||
type SysDeptControl struct {
|
||||
DeptId int `uri:"id" comment:"编码"` // 编码
|
||||
ParentId int `form:"parentId" comment:"上级部门"` //上级部门
|
||||
DeptPath string `form:"deptPath" comment:""` //路径
|
||||
DeptName string `form:"deptName" comment:"部门名称"` //部门名称
|
||||
Sort int `form:"sort" comment:"排序"` //排序
|
||||
Leader string `form:"leader" comment:"负责人"` //负责人
|
||||
Phone string `form:"phone" comment:"手机"` //手机
|
||||
Email string `form:"email" comment:"邮箱"` //邮箱
|
||||
Status string `form:"status" comment:"状态"` //状态
|
||||
}
|
||||
|
||||
// Bind 映射上下文中的结构体数据
|
||||
func (s *SysDeptControl) Bind(ctx *gin.Context) error {
|
||||
msgID := tools.GenerateMsgIDFromContext(ctx)
|
||||
err := ctx.ShouldBindUri(s)
|
||||
if err != nil {
|
||||
log.Debugf("MsgID[%s] ShouldBindUri error: %s", msgID, err.Error())
|
||||
return err
|
||||
}
|
||||
err = ctx.ShouldBindBodyWith(s, binding.JSON)
|
||||
if err != nil {
|
||||
log.Debugf("MsgID[%s] ShouldBind error: %#v", msgID, err.Error())
|
||||
}
|
||||
var jsonStr []byte
|
||||
jsonStr, err = json.Marshal(s)
|
||||
if err != nil {
|
||||
log.Debugf("MsgID[%s] ShouldBind error: %#v", msgID, err.Error())
|
||||
}
|
||||
ctx.Set("body", string(jsonStr))
|
||||
return err
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
// GetId 获取数据对应的ID
|
||||
func (s *SysDeptControl) GetId() interface{} {
|
||||
return s.DeptId
|
||||
}
|
||||
|
||||
// SysConfigById 获取单个或者删除的结构体
|
||||
type SysDeptById struct {
|
||||
Id int `uri:"id"`
|
||||
Ids []int `json:"ids"`
|
||||
}
|
||||
|
||||
func (s *SysDeptById) Generate() *SysDeptById {
|
||||
cp := *s
|
||||
return &cp
|
||||
}
|
||||
|
||||
func (s *SysDeptById) GetId() interface{} {
|
||||
return s.Id
|
||||
}
|
||||
|
||||
func (s *SysDeptById) Bind(ctx *gin.Context) error {
|
||||
msgID := tools.GenerateMsgIDFromContext(ctx)
|
||||
err := ctx.ShouldBindUri(s)
|
||||
if err != nil {
|
||||
log.Debugf("MsgID[%s] ShouldBindUri error: %s", msgID, err.Error())
|
||||
return err
|
||||
}
|
||||
err = ctx.ShouldBind(s)
|
||||
if err != nil {
|
||||
log.Debugf("MsgID[%s] ShouldBind error: %#v", msgID, err.Error())
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *SysDeptById) GenerateM() (*models.SysDept, error) {
|
||||
return &models.SysDept{}, nil
|
||||
}
|
||||
|
||||
type DeptLabel struct {
|
||||
Id int `gorm:"-" json:"id"`
|
||||
Label string `gorm:"-" json:"label"`
|
||||
Children []DeptLabel `gorm:"-" json:"children"`
|
||||
}
|
||||
Reference in New Issue
Block a user