修正返回目录

This commit is contained in:
2023-09-28 08:40:43 +08:00
parent aedf61c31b
commit 70c35e0ce6
84 changed files with 3579 additions and 2007 deletions
+101
View File
@@ -0,0 +1,101 @@
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:女)
Avatar string `json:"avatar"` // 头像
LoginIP string `json:"login_ip"` // 登陆ip
LastLoginAt model.LocalTime `json:"last_login_at"` // 最后登陆时间
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,
Avatar: utils.AddOssDomain(m.Avatar),
LoginIP: m.LoginIp,
LastLoginAt: m.LastLoginAt,
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,
Avatar: utils.AddOssDomain(m.Avatar),
LoginIP: m.LoginIp,
LastLoginAt: m.LastLoginAt,
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,
Avatar: utils.AddOssDomain(v.Avatar),
LoginIP: v.LoginIp,
LastLoginAt: v.LastLoginAt,
CreatedBy: v.CreatedBy,
CreatedAt: v.CreatedAt,
UpdatedAt: v.UpdatedAt,
}
// 将转换后的结构体添加到新切片中
responses[i] = response
}
}
return responses
}