package dto import ( "fmt" "hospital-admin-api/api/model" ) // AdminDeptDto 部门详情 type AdminDeptDto struct { DeptId string `json:"dept_id"` ParentId string `json:"parent_id"` // 父菜单ID(0表示一级) DeptName string `json:"dept_name"` // 部门名称 DeptStatus int `json:"dept_status"` // 部门状态(1:正常 2:删除) CreatedAt model.LocalTime `json:"created_at"` // 创建时间 UpdatedAt model.LocalTime `json:"updated_at"` // 修改时间 Children []*AdminDeptDto `json:"children"` // 下级页面 } func GetAdminDeptDto(m *model.AdminDept) *AdminDeptDto { return &AdminDeptDto{ DeptId: fmt.Sprintf("%d", m.DeptId), ParentId: fmt.Sprintf("%d", m.ParentId), DeptName: m.DeptName, DeptStatus: m.DeptStatus, CreatedAt: m.CreatedAt, UpdatedAt: m.UpdatedAt, } } func GetAdminDeptListDto(m []*model.AdminDept) []AdminDeptDto { // 处理返回值 responses := make([]AdminDeptDto, len(m)) if len(m) > 0 { for i, v := range m { response := AdminDeptDto{ DeptId: fmt.Sprintf("%d", v.DeptId), ParentId: fmt.Sprintf("%d", v.ParentId), DeptName: v.DeptName, DeptStatus: v.DeptStatus, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, } // 将转换后的结构体添加到新切片中 responses[i] = response } } return responses }