新增专长
This commit is contained in:
+210
-1
@@ -5,6 +5,11 @@ import (
|
||||
"hospital-admin-api/api/dao"
|
||||
"hospital-admin-api/api/model"
|
||||
"hospital-admin-api/api/requests"
|
||||
"hospital-admin-api/api/responses/doctorExpertiseResponse"
|
||||
"hospital-admin-api/api/responses/hospitalResponse"
|
||||
"hospital-admin-api/api/responses/userDoctorInfoResponse"
|
||||
"hospital-admin-api/api/responses/userDoctorResponse"
|
||||
"hospital-admin-api/api/responses/userResponse"
|
||||
"hospital-admin-api/config"
|
||||
"hospital-admin-api/extend/ca"
|
||||
"hospital-admin-api/extend/tencentIm"
|
||||
@@ -17,9 +22,83 @@ import (
|
||||
type UserDoctorService struct {
|
||||
}
|
||||
|
||||
// GetUserDoctor 医生详情
|
||||
func (r *UserDoctorService) GetUserDoctor(doctorId int64) (getUserDoctorResponse *userDoctorResponse.GetUserDoctor, err error) {
|
||||
// 获取医生数据
|
||||
userDoctorDao := dao.UserDoctorDao{}
|
||||
userDoctor, err := userDoctorDao.GetUserDoctorPreloadById(doctorId)
|
||||
if err != nil || userDoctor == nil {
|
||||
return nil, errors.New("用户数据错误")
|
||||
}
|
||||
|
||||
userDoctorService := UserDoctorService{}
|
||||
doctorExpertise, err := userDoctorService.GetUserDoctorExpertiseByDoctorId(doctorId)
|
||||
if err != nil {
|
||||
return nil, errors.New(err.Error())
|
||||
}
|
||||
|
||||
// 处理返回值
|
||||
var userDoctorInfo *userDoctorInfoResponse.UserDoctorInfo
|
||||
if userDoctor.UserDoctorInfo != nil {
|
||||
userDoctorInfo = userDoctorInfoResponse.UserDoctorInfoResponse(userDoctor.UserDoctorInfo)
|
||||
}
|
||||
|
||||
// 医院
|
||||
var hospital *hospitalResponse.Hospital
|
||||
if userDoctor.Hospital != nil {
|
||||
hospital = hospitalResponse.HospitalResponse(userDoctor.Hospital)
|
||||
}
|
||||
|
||||
// 用户
|
||||
var user *userResponse.User
|
||||
if userDoctor.User != nil {
|
||||
user = userResponse.UserResponse(userDoctor.User)
|
||||
}
|
||||
|
||||
getUserDoctorResponse = &userDoctorResponse.GetUserDoctor{
|
||||
DoctorID: strconv.Itoa(int(userDoctor.DoctorId)),
|
||||
UserID: strconv.Itoa(int(userDoctor.UserId)),
|
||||
UserName: userDoctor.UserName,
|
||||
Status: userDoctor.Status,
|
||||
IDCardStatus: userDoctor.Status,
|
||||
IdenAuthStatus: userDoctor.IdenAuthStatus,
|
||||
IdenAuthTime: userDoctor.IdenAuthTime,
|
||||
IdenAuthFailReason: userDoctor.IdenAuthFailReason,
|
||||
MultiPointStatus: userDoctor.MultiPointStatus,
|
||||
MultiPointTime: userDoctor.MultiPointTime,
|
||||
MultiPointFailReason: userDoctor.MultiPointFailReason,
|
||||
IsBindBank: userDoctor.IsBindBank,
|
||||
IsRecommend: userDoctor.IsRecommend,
|
||||
Avatar: config.C.Oss.OssCustomDomainName + userDoctor.Avatar,
|
||||
DoctorTitle: userDoctor.DoctorTitle,
|
||||
DepartmentCustomID: strconv.Itoa(int(userDoctor.DepartmentCustomId)),
|
||||
DepartmentCustomName: userDoctor.DepartmentCustomName,
|
||||
DepartmentCustomMobile: userDoctor.DepartmentCustomMobile,
|
||||
HospitalID: strconv.Itoa(int(userDoctor.HospitalID)),
|
||||
ServedPatientsNum: userDoctor.ServedPatientsNum,
|
||||
PraiseRate: userDoctor.PraiseRate,
|
||||
AvgResponseTime: userDoctor.AvgResponseTime,
|
||||
NumberOfFans: userDoctor.NumberOfFans,
|
||||
IsImgExpertReception: userDoctor.IsImgExpertReception,
|
||||
IsImgWelfareReception: userDoctor.IsImgWelfareReception,
|
||||
IsImgQuickReception: userDoctor.IsImgQuickReception,
|
||||
IsPlatformDeepCooperation: userDoctor.IsPlatformDeepCooperation,
|
||||
QrCode: config.C.Oss.OssCustomDomainName + userDoctor.QrCode,
|
||||
BeGoodAt: userDoctor.BeGoodAt,
|
||||
BriefIntroduction: userDoctor.BriefIntroduction,
|
||||
CreatedAt: userDoctor.CreatedAt,
|
||||
UpdatedAt: userDoctor.UpdatedAt,
|
||||
User: user,
|
||||
Hospital: hospital,
|
||||
UserDoctorInfo: userDoctorInfo,
|
||||
DoctorExpertise: doctorExpertise, // 专长
|
||||
}
|
||||
|
||||
return getUserDoctorResponse, nil
|
||||
}
|
||||
|
||||
// PutUserDoctor 修改医生
|
||||
func (r *UserDoctorService) PutUserDoctor(doctorId int64, putUserDoctorRequest requests.PutUserDoctor) (bool, error) {
|
||||
|
||||
// 获取医生数据
|
||||
userDoctorDao := dao.UserDoctorDao{}
|
||||
userDoctor, err := userDoctorDao.GetUserDoctorById(doctorId)
|
||||
@@ -213,6 +292,24 @@ func (r *UserDoctorService) PutUserDoctor(doctorId int64, putUserDoctorRequest r
|
||||
}
|
||||
}
|
||||
|
||||
// 处理专长
|
||||
if len(putUserDoctorRequest.DoctorExpertise) > 0 {
|
||||
// 检测专长是否存在
|
||||
diseaseClassExpertiseDao := dao.DiseaseClassExpertiseDao{}
|
||||
for _, v := range putUserDoctorRequest.DoctorExpertise {
|
||||
expertiseId, err := strconv.ParseInt(v, 10, 64)
|
||||
if err != nil {
|
||||
return false, errors.New("专长错误")
|
||||
}
|
||||
|
||||
diseaseClassExpertise, err := diseaseClassExpertiseDao.GetDiseaseClassExpertiseById(expertiseId)
|
||||
if err != nil || diseaseClassExpertise == nil {
|
||||
return false, errors.New("专长数据错误")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 开始事务
|
||||
tx := global.Db.Begin()
|
||||
defer func() {
|
||||
@@ -259,6 +356,40 @@ func (r *UserDoctorService) PutUserDoctor(doctorId int64, putUserDoctorRequest r
|
||||
}
|
||||
}
|
||||
|
||||
// 修改专长数据
|
||||
if len(putUserDoctorRequest.DoctorExpertise) > 0 {
|
||||
doctorExpertiseDao := dao.DoctorExpertiseDao{}
|
||||
|
||||
// 删除原专长
|
||||
maps := make(map[string]interface{})
|
||||
maps["doctor_id"] = userDoctor.DoctorId
|
||||
err = doctorExpertiseDao.DeleteDoctorExpertise(tx, maps)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New("修改失败")
|
||||
}
|
||||
|
||||
for _, v := range putUserDoctorRequest.DoctorExpertise {
|
||||
expertiseId, err := strconv.ParseInt(v, 10, 64)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New("专长错误")
|
||||
}
|
||||
|
||||
// 新增专长表数据
|
||||
doctorExpertise := &model.DoctorExpertise{
|
||||
DoctorId: userDoctor.DoctorId,
|
||||
ExpertiseId: expertiseId,
|
||||
}
|
||||
|
||||
doctorExpertise, err = doctorExpertiseDao.AddDoctorExpertise(tx, doctorExpertise)
|
||||
if err != nil || doctorExpertise == nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New(err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 判断头像是否修改,同步修改im
|
||||
if userDoctor.Avatar != avatar {
|
||||
profileItem := []tencentIm.ProfileItem{
|
||||
@@ -519,6 +650,24 @@ func (r *UserDoctorService) AddUserDoctor(userId string, a requests.AddUserDocto
|
||||
multiPointStatus = 2
|
||||
}
|
||||
|
||||
// 处理专长
|
||||
if len(a.DoctorExpertise) > 0 {
|
||||
// 检测专长是否存在
|
||||
diseaseClassExpertiseDao := dao.DiseaseClassExpertiseDao{}
|
||||
for _, v := range a.DoctorExpertise {
|
||||
expertiseId, err := strconv.ParseInt(v, 10, 64)
|
||||
if err != nil {
|
||||
return false, errors.New("专长错误")
|
||||
}
|
||||
|
||||
diseaseClassExpertise, err := diseaseClassExpertiseDao.GetDiseaseClassExpertiseById(expertiseId)
|
||||
if err != nil || diseaseClassExpertise == nil {
|
||||
return false, errors.New("专长数据错误")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 开始事务
|
||||
tx := global.Db.Begin()
|
||||
defer func() {
|
||||
@@ -597,6 +746,66 @@ func (r *UserDoctorService) AddUserDoctor(userId string, a requests.AddUserDocto
|
||||
return false, err
|
||||
}
|
||||
|
||||
// 修改专长数据
|
||||
if len(a.DoctorExpertise) > 0 {
|
||||
doctorExpertiseDao := dao.DoctorExpertiseDao{}
|
||||
|
||||
for _, v := range a.DoctorExpertise {
|
||||
expertiseId, err := strconv.ParseInt(v, 10, 64)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New("专长错误")
|
||||
}
|
||||
|
||||
// 新增专长表数据
|
||||
doctorExpertise := &model.DoctorExpertise{
|
||||
DoctorId: userDoctor.DoctorId,
|
||||
ExpertiseId: expertiseId,
|
||||
}
|
||||
|
||||
doctorExpertise, err = doctorExpertiseDao.AddDoctorExpertise(tx, doctorExpertise)
|
||||
if err != nil || doctorExpertise == nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New(err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tx.Commit()
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// GetUserDoctorExpertiseByDoctorId 获取医生专长
|
||||
func (r *UserDoctorService) GetUserDoctorExpertiseByDoctorId(doctorId int64) ([]*doctorExpertiseResponse.DoctorExpertise, error) {
|
||||
DiseaseClassExpertiseDao := dao.DiseaseClassExpertiseDao{}
|
||||
|
||||
// 获取医生专长
|
||||
doctorExpertiseDao := dao.DoctorExpertiseDao{}
|
||||
doctorExpertises, err := doctorExpertiseDao.GetDoctorExpertiseListByDoctorId(doctorId)
|
||||
if err != nil {
|
||||
return nil, errors.New("用户数据错误")
|
||||
}
|
||||
|
||||
doctorExpertisesResponses := make([]*doctorExpertiseResponse.DoctorExpertise, len(doctorExpertises))
|
||||
|
||||
if len(doctorExpertises) > 0 {
|
||||
for i, v := range doctorExpertises {
|
||||
// 获取专长
|
||||
diseaseClassExpertise, err := DiseaseClassExpertiseDao.GetDiseaseClassExpertiseById(v.ExpertiseId)
|
||||
if err != nil || diseaseClassExpertise == nil {
|
||||
return nil, errors.New("专长数据错误")
|
||||
}
|
||||
|
||||
doctorExpertisesResponse := &doctorExpertiseResponse.DoctorExpertise{
|
||||
DoctorId: strconv.FormatInt(doctorId, 10),
|
||||
ExpertiseId: strconv.FormatInt(v.ExpertiseId, 10),
|
||||
ExpertiseName: diseaseClassExpertise.ExpertiseName,
|
||||
}
|
||||
|
||||
// 将转换后的结构体添加到新切片中
|
||||
doctorExpertisesResponses[i] = doctorExpertisesResponse
|
||||
}
|
||||
}
|
||||
|
||||
return doctorExpertisesResponses, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user