65 lines
1.7 KiB
Go
65 lines
1.7 KiB
Go
package dto
|
||
|
||
import (
|
||
"fmt"
|
||
"hospital-admin-api/api/model"
|
||
"strconv"
|
||
)
|
||
|
||
// AdminRoleDto 角色详情
|
||
type AdminRoleDto struct {
|
||
RoleId string `json:"role_id"` // 角色id
|
||
RoleName string `json:"role_name"` // 角色名称
|
||
RoleStatus int `json:"role_status"` // 角色状态(1:正常 2:禁用)
|
||
IsAdmin int `json:"is_admin"` // 是否管理员(0:否 1:是)
|
||
MenuIds []string `json:"menu_ids"` // 菜单id
|
||
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
|
||
UpdatedAt model.LocalTime `json:"updated_at"` // 修改时间
|
||
}
|
||
|
||
func GetAdminRoleDto(m *model.AdminRole) *AdminRoleDto {
|
||
return &AdminRoleDto{
|
||
RoleId: fmt.Sprintf("%d", m.RoleId),
|
||
RoleName: m.RoleName,
|
||
RoleStatus: m.RoleStatus,
|
||
IsAdmin: m.IsAdmin,
|
||
CreatedAt: m.CreatedAt,
|
||
UpdatedAt: m.UpdatedAt,
|
||
}
|
||
}
|
||
|
||
func GetAdminRoleListDto(m []*model.AdminRole) []AdminRoleDto {
|
||
// 处理返回值
|
||
responses := make([]AdminRoleDto, len(m))
|
||
|
||
if len(m) > 0 {
|
||
for i, v := range m {
|
||
response := AdminRoleDto{
|
||
RoleId: fmt.Sprintf("%d", v.RoleId),
|
||
RoleName: v.RoleName,
|
||
RoleStatus: v.RoleStatus,
|
||
IsAdmin: v.IsAdmin,
|
||
CreatedAt: v.CreatedAt,
|
||
UpdatedAt: v.UpdatedAt,
|
||
}
|
||
|
||
// 将转换后的结构体添加到新切片中
|
||
responses[i] = response
|
||
}
|
||
}
|
||
|
||
return responses
|
||
}
|
||
|
||
// LoadRoleMenuIdsDto 加载角色菜单id
|
||
func (m *AdminRoleDto) LoadRoleMenuIdsDto(menuIds []int64) *AdminRoleDto {
|
||
var menuIdsString []string
|
||
for _, menuId := range menuIds {
|
||
menuId := strconv.FormatInt(menuId, 10)
|
||
menuIdsString = append(menuIdsString, menuId)
|
||
}
|
||
|
||
m.MenuIds = menuIdsString
|
||
return m
|
||
}
|