package userPatientResponse import ( "fmt" "hospital-admin-api/api/model" "hospital-admin-api/api/responses/patientFamilyResponse" "hospital-admin-api/api/responses/userShipAddressResponse" "hospital-admin-api/utils" ) // getUserPatientPage 获取患者列表-分页 type getUserPatientPage 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"` // 更新时间 } // GetUserPatient 患者详情 type GetUserPatient 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"` // 手机号 PatientFamily []*patientFamilyResponse.GetUserPatient `json:"patient_family"` // 家庭成员 UserShipAddress []*userShipAddressResponse.UserShipAddress `json:"user_ship_address"` // 收货地址 CreatedAt model.LocalTime `json:"created_at"` // 创建时间 UpdatedAt model.LocalTime `json:"updated_at"` // 更新时间 } // GetUserPatientPageResponse 获取用户列表-分页 func GetUserPatientPageResponse(userPatient []*model.UserPatient) []getUserPatientPage { // 处理返回值 responses := make([]getUserPatientPage, len(userPatient)) if len(userPatient) > 0 { for i, v := range userPatient { // 将原始结构体转换为新结构体 response := getUserPatientPage{ 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, } if v.PatientFamily != nil { response.PatientFamilyCount = len(v.PatientFamily) } if v.User != nil { response.Mobile = utils.MaskPhoneStr(v.User.Mobile) } // 将转换后的结构体添加到新切片中 responses[i] = response } } return responses }