114 lines
3.9 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package dto
import (
"fmt"
"hospital-admin-api/api/model"
"hospital-admin-api/utils"
)
type UserDto struct {
UserID string `json:"user_id"` // 主键
UserName string `json:"user_name"` // 用户名称
UserAccount string `json:"user_account"` // 账号
Mobile string `json:"mobile"` // 手机号
WxMobile string `json:"wx_mobile"` // 微信手机号
UserType int `json:"user_type"` // 用户类型1:患者 2:医师 3:药师)
UserStatus int `json:"user_status"` // 状态0:禁用 1:正常 2:删除)
RegisterMethod int `json:"register_method"` // 注册方式1:微信小程序)
Age uint `json:"age"` // 年龄
Sex int `json:"sex"` // 性别0:未知 1:男 2:女)
Email string `json:"email"` // 邮箱
Avatar string `json:"avatar"` // 头像
IsOnline int `json:"is_online"` // 是否在线0:不在线 1:在线)
LoginAt model.LocalTime `json:"login_at"` // 小程序登陆时间
ImLoginAt model.LocalTime `json:"im_login_at"` // im登陆时间
LoginIp string `json:"login_ip"` // 登陆ip
CreatedBy string `json:"created_by"` // 创建者id后台用户表id null:自己注册)
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
UpdatedAt model.LocalTime `json:"updated_at"` // 修改时间
}
func GetUserDto(m *model.User) *UserDto {
return &UserDto{
UserID: fmt.Sprintf("%d", m.UserId),
UserName: m.UserName,
UserAccount: m.UserAccount,
Mobile: m.Mobile,
WxMobile: m.WxMobile,
UserType: m.UserType,
UserStatus: m.UserStatus,
RegisterMethod: m.RegisterMethod,
Age: m.Age,
Sex: m.Sex,
Email: m.Email,
Avatar: utils.AddOssDomain(m.Avatar),
IsOnline: m.IsOnline,
LoginAt: m.LoginAt,
ImLoginAt: m.ImLoginAt,
LoginIp: m.LoginIp,
CreatedBy: m.CreatedBy,
CreatedAt: m.CreatedAt,
UpdatedAt: m.UpdatedAt,
}
}
func GetMaskUserDto(m *model.User) *UserDto {
return &UserDto{
UserID: fmt.Sprintf("%d", m.UserId),
UserName: m.UserName,
UserAccount: m.UserAccount,
Mobile: utils.MaskPhoneStr(m.Mobile),
WxMobile: utils.MaskPhoneStr(m.WxMobile),
UserType: m.UserType,
UserStatus: m.UserStatus,
RegisterMethod: m.RegisterMethod,
Age: m.Age,
Sex: m.Sex,
Email: m.Email,
Avatar: utils.AddOssDomain(m.Avatar),
IsOnline: m.IsOnline,
LoginAt: m.LoginAt,
ImLoginAt: m.ImLoginAt,
LoginIp: m.LoginIp,
CreatedBy: m.CreatedBy,
CreatedAt: m.CreatedAt,
UpdatedAt: m.UpdatedAt,
}
}
func GetUserListDto(m []*model.User) []UserDto {
// 处理返回值
responses := make([]UserDto, len(m))
if len(m) > 0 {
for i, v := range m {
response := UserDto{
UserID: fmt.Sprintf("%d", v.UserId),
UserName: v.UserName,
UserAccount: v.UserAccount,
Mobile: v.Mobile,
WxMobile: v.WxMobile,
UserType: v.UserType,
UserStatus: v.UserStatus,
RegisterMethod: v.RegisterMethod,
Age: v.Age,
Sex: v.Sex,
Email: v.Email,
Avatar: utils.AddOssDomain(v.Avatar),
IsOnline: v.IsOnline,
LoginAt: v.LoginAt,
ImLoginAt: v.ImLoginAt,
LoginIp: v.LoginIp,
CreatedBy: v.CreatedBy,
CreatedAt: v.CreatedAt,
UpdatedAt: v.UpdatedAt,
}
// 将转换后的结构体添加到新切片中
responses[i] = response
}
}
return responses
}