59 lines
1.9 KiB
Go
59 lines
1.9 KiB
Go
package service
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"hospital-admin-api/api/dao"
|
|
"hospital-admin-api/api/responses/patientFamilyResponse"
|
|
"hospital-admin-api/api/responses/userPatientResponse"
|
|
"hospital-admin-api/api/responses/userResponse"
|
|
"hospital-admin-api/api/responses/userShipAddressResponse"
|
|
"hospital-admin-api/utils"
|
|
)
|
|
|
|
type UserPatientService struct {
|
|
}
|
|
|
|
// GetUserPatient 患者详情
|
|
func (r *UserPatientService) GetUserPatient(patientId int64) (getUserPatientResponse *userPatientResponse.GetUserPatient, err error) {
|
|
// 获取患者数据
|
|
userPatientDao := dao.UserPatientDao{}
|
|
userPatient, err := userPatientDao.GetUserPatientPreloadById(patientId)
|
|
if err != nil || userPatient == nil {
|
|
return nil, errors.New("患者错误")
|
|
}
|
|
|
|
// 患者收货地址
|
|
var userShipAddress []*userShipAddressResponse.UserShipAddress
|
|
if userPatient.UserShipAddress != nil {
|
|
userShipAddress = userShipAddressResponse.GetUserShipAddressListResponse(userPatient.UserShipAddress)
|
|
}
|
|
|
|
// 获取家庭成员数据
|
|
var patientFamilysResponse []*patientFamilyResponse.GetUserPatient
|
|
if userPatient.PatientFamily != nil {
|
|
patientFamilysResponse = patientFamilyResponse.GetUserPatientResponse(userPatient.PatientFamily)
|
|
}
|
|
|
|
// 获取用户数据
|
|
var user *userResponse.User
|
|
if userPatient.User != nil {
|
|
user = userResponse.UserResponse(userPatient.User)
|
|
}
|
|
|
|
getUserPatientResponse = &userPatientResponse.GetUserPatient{
|
|
PatientId: fmt.Sprintf("%d", userPatient.PatientId),
|
|
UserId: fmt.Sprintf("%d", userPatient.UserId),
|
|
UserName: userPatient.UserName,
|
|
Status: &userPatient.Status,
|
|
Avatar: utils.AddOssDomain(userPatient.Avatar),
|
|
Mobile: user.Mobile,
|
|
PatientFamily: patientFamilysResponse,
|
|
UserShipAddress: userShipAddress,
|
|
CreatedAt: userPatient.CreatedAt,
|
|
UpdatedAt: userPatient.UpdatedAt,
|
|
}
|
|
|
|
return getUserPatientResponse, nil
|
|
}
|