91 lines
2.1 KiB
Go
91 lines
2.1 KiB
Go
package service
|
|
|
|
import (
|
|
"errors"
|
|
"hospital-admin-api/api/dao"
|
|
"hospital-admin-api/api/dto"
|
|
"hospital-admin-api/api/requests"
|
|
"hospital-admin-api/global"
|
|
)
|
|
|
|
type UserPatientService struct {
|
|
}
|
|
|
|
// GetUserPatient 患者详情
|
|
func (r *UserPatientService) GetUserPatient(patientId int64) (g *dto.UserPatientDto, err error) {
|
|
// 获取患者数据
|
|
userPatientDao := dao.UserPatientDao{}
|
|
userPatient, err := userPatientDao.GetUserPatientPreloadById(patientId)
|
|
if err != nil || userPatient == nil {
|
|
return nil, errors.New("患者错误")
|
|
}
|
|
|
|
// 处理返回数据
|
|
g = dto.GetUserPatientDto(userPatient)
|
|
|
|
// 加载用户手机号
|
|
g.LoadPatientMobile(userPatient.User)
|
|
|
|
// 加载用户收货地址
|
|
g.LoadUserShipAddress(userPatient.UserShipAddress)
|
|
|
|
// 加载家庭成员数据
|
|
g.LoadMaskPatientFamily(userPatient.PatientFamily)
|
|
|
|
return g, 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()
|
|
}
|
|
}()
|
|
|
|
// 修改患者
|
|
userPatientData := make(map[string]interface{})
|
|
userPatientData["status"] = req.Status
|
|
userPatientData["disable_reason"] = req.DisableReason
|
|
|
|
err = userPatientDao.EditUserPatientById(tx, patientId, userPatientData)
|
|
if err != nil {
|
|
tx.Rollback()
|
|
return false, errors.New("修改失败")
|
|
}
|
|
|
|
// 修改用户
|
|
userData := make(map[string]interface{})
|
|
userData["user_status"] = req.Status
|
|
|
|
userDao := dao.UserDao{}
|
|
err = userDao.EditUserById(tx, patientId, userData)
|
|
if err != nil {
|
|
tx.Rollback()
|
|
return false, errors.New("修改失败")
|
|
}
|
|
|
|
tx.Commit()
|
|
|
|
return true, nil
|
|
}
|