111 lines
3.4 KiB
Go
111 lines
3.4 KiB
Go
package dto
|
||
|
||
import (
|
||
"fmt"
|
||
"hospital-admin-api/api/model"
|
||
"hospital-admin-api/utils"
|
||
)
|
||
|
||
type UserPatientDto struct {
|
||
PatientId string `json:"patient_id"` // 主键id
|
||
UserId string `json:"user_id"` // 用户id;NOT NULL
|
||
UserName string `json:"user_name"` // 用户名称
|
||
Status *int `json:"status"` // 状态(0:禁用 1:正常 2:删除)
|
||
Avatar string `json:"avatar"` // 头像
|
||
Mobile string `json:"mobile"` // 手机号
|
||
DisableReason string `json:"disable_reason"` // 禁用理由
|
||
PatientFamilyCount int `json:"patient_family_count"` // 家庭成员数量
|
||
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
|
||
UpdatedAt model.LocalTime `json:"updated_at"` // 更新时间
|
||
PatientFamily []*PatientFamilyMaskDto `json:"patient_family"` // 家庭成员
|
||
UserShipAddress []*UserShipAddressDto `json:"user_ship_address"` // 收货地址
|
||
}
|
||
|
||
func GetUserPatientDto(m *model.UserPatient) *UserPatientDto {
|
||
return &UserPatientDto{
|
||
PatientId: fmt.Sprintf("%d", m.PatientId),
|
||
UserId: fmt.Sprintf("%d", m.UserId),
|
||
UserName: m.UserName,
|
||
Status: &m.Status,
|
||
Avatar: utils.AddOssDomain(m.Avatar),
|
||
DisableReason: m.DisableReason,
|
||
CreatedAt: m.CreatedAt,
|
||
UpdatedAt: m.UpdatedAt,
|
||
}
|
||
}
|
||
|
||
func GetUserPatientListDto(m []*model.UserPatient) []*UserPatientDto {
|
||
// 处理返回值
|
||
responses := make([]*UserPatientDto, len(m))
|
||
|
||
if len(m) > 0 {
|
||
for i, v := range m {
|
||
response := &UserPatientDto{
|
||
PatientId: fmt.Sprintf("%d", v.PatientId),
|
||
UserId: fmt.Sprintf("%d", v.UserId),
|
||
UserName: v.UserName,
|
||
Status: &v.Status,
|
||
Avatar: utils.AddOssDomain(v.Avatar),
|
||
DisableReason: v.DisableReason,
|
||
CreatedAt: v.CreatedAt,
|
||
UpdatedAt: v.UpdatedAt,
|
||
}
|
||
|
||
// 加载家庭成员数量
|
||
response.LoadPatientFamilyCount(v.PatientFamily)
|
||
|
||
// 加载患者手机号
|
||
response.LoadPatientMaskMobile(v.User)
|
||
|
||
// 将转换后的结构体添加到新切片中
|
||
responses[i] = response
|
||
}
|
||
}
|
||
|
||
return responses
|
||
}
|
||
|
||
// LoadPatientFamilyCount 加载家庭成员数量
|
||
func (r *UserPatientDto) LoadPatientFamilyCount(m []*model.PatientFamily) *UserPatientDto {
|
||
if len(m) > 0 {
|
||
r.PatientFamilyCount = len(m)
|
||
}
|
||
return r
|
||
}
|
||
|
||
// LoadPatientMaskMobile 加载患者加密手机号
|
||
func (r *UserPatientDto) LoadPatientMaskMobile(m *model.User) *UserPatientDto {
|
||
if m != nil {
|
||
r.Mobile = utils.MaskPhoneStr(m.Mobile)
|
||
}
|
||
return r
|
||
}
|
||
|
||
// LoadPatientMobile 加载患者手机号
|
||
func (r *UserPatientDto) LoadPatientMobile(m *model.User) *UserPatientDto {
|
||
if m != nil {
|
||
r.Mobile = m.Mobile
|
||
}
|
||
return r
|
||
}
|
||
|
||
// LoadUserShipAddress 加载用户收货地址
|
||
func (r *UserPatientDto) LoadUserShipAddress(m []*model.UserShipAddress) *UserPatientDto {
|
||
if len(m) > 0 {
|
||
d := GetUserShipAddressListDto(m)
|
||
|
||
r.UserShipAddress = d
|
||
}
|
||
return r
|
||
}
|
||
|
||
// LoadMaskPatientFamily 加载家庭成员数据-加密
|
||
func (r *UserPatientDto) LoadMaskPatientFamily(m []*model.PatientFamily) *UserPatientDto {
|
||
if len(m) > 0 {
|
||
d := GetPatientFamilyMaskListDto(m)
|
||
|
||
r.PatientFamily = d
|
||
}
|
||
return r
|
||
}
|