104 lines
2.9 KiB
Go
104 lines
2.9 KiB
Go
package service
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"hospital-admin-api/api/dao"
|
|
"hospital-admin-api/api/requests"
|
|
"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/global"
|
|
"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
|
|
}
|
|
|
|
// PutUserDoctorStatus 修改患者状态
|
|
func (r *UserPatientService) PutUserDoctorStatus(patientId int64, req requests.PutUserDoctorStatus) (res bool, err error) {
|
|
// 获取患者数据
|
|
userPatientDao := dao.UserPatientDao{}
|
|
userPatient, err := userPatientDao.GetUserPatientPreloadById(patientId)
|
|
if err != nil || userPatient == nil {
|
|
return false, errors.New("患者错误")
|
|
}
|
|
|
|
if req.Status == userPatient.Status {
|
|
return true, nil
|
|
}
|
|
|
|
if req.Status == 0 {
|
|
if req.DisableReason == "" {
|
|
return false, errors.New("请填写禁用理由")
|
|
}
|
|
}
|
|
|
|
// 开始事务
|
|
tx := global.Db.Begin()
|
|
defer func() {
|
|
if r := recover(); r != nil {
|
|
tx.Rollback()
|
|
}
|
|
}()
|
|
|
|
// 修改部门
|
|
data := make(map[string]interface{})
|
|
data["status"] = req.Status
|
|
data["disable_reason"] = req.DisableReason
|
|
|
|
err = userPatientDao.EditUserPatientById(tx, patientId, data)
|
|
if err != nil {
|
|
tx.Rollback()
|
|
return false, errors.New("修改失败")
|
|
}
|
|
|
|
tx.Commit()
|
|
|
|
return true, nil
|
|
}
|