1313 lines
41 KiB
Go
1313 lines
41 KiB
Go
package service
|
||
|
||
import (
|
||
"errors"
|
||
"hospital-admin-api/api/dao"
|
||
"hospital-admin-api/api/model"
|
||
"hospital-admin-api/api/requests"
|
||
"hospital-admin-api/api/responses/doctorBankCardResponse"
|
||
"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"
|
||
"hospital-admin-api/global"
|
||
"hospital-admin-api/utils"
|
||
"strconv"
|
||
"strings"
|
||
"time"
|
||
)
|
||
|
||
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())
|
||
}
|
||
|
||
// 获取医生银行卡
|
||
doctorBankCard, err := userDoctorService.GetUserDoctorBankByDoctorId(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,
|
||
IsSysDiagnoCooperation: userDoctor.IsSysDiagnoCooperation,
|
||
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, // 专长
|
||
DoctorBankCard: doctorBankCard, // 银行卡
|
||
}
|
||
|
||
return getUserDoctorResponse, nil
|
||
}
|
||
|
||
// PutUserDoctor 修改医生
|
||
func (r *UserDoctorService) PutUserDoctor(doctorId int64, putUserDoctorRequest requests.PutUserDoctor) (bool, error) {
|
||
// 获取医生数据
|
||
userDoctorDao := dao.UserDoctorDao{}
|
||
userDoctor, err := userDoctorDao.GetUserDoctorById(doctorId)
|
||
if err != nil || userDoctor == nil {
|
||
return false, errors.New("医生数据错误")
|
||
}
|
||
|
||
// 获取医生详情数据
|
||
userDoctorInfoDao := dao.UserDoctorInfoDao{}
|
||
userDoctorInfo, err := userDoctorInfoDao.GetUserDoctorInfoByDoctorId(doctorId)
|
||
if err != nil {
|
||
return false, errors.New("医生详情数据错误")
|
||
}
|
||
|
||
// 获取用户数据
|
||
userDao := dao.UserDao{}
|
||
user, err := userDao.GetUserById(userDoctor.UserId)
|
||
if err != nil {
|
||
return false, errors.New("医生数据错误")
|
||
}
|
||
|
||
if userDoctor.IdenAuthStatus == 2 {
|
||
return false, errors.New("医生身份审核中,不允许修改")
|
||
}
|
||
|
||
userDoctorData := make(map[string]interface{}) // 医生数据
|
||
userDoctorInfoData := make(map[string]interface{}) // 医生详情数据
|
||
userData := make(map[string]interface{}) // 用户数据
|
||
|
||
// 处理头像
|
||
avatar := strings.Replace(putUserDoctorRequest.Avatar, config.C.Oss.OssCustomDomainName, "", 1)
|
||
if userDoctor.Avatar != avatar {
|
||
userDoctorData["avatar"] = avatar
|
||
userData["avatar"] = avatar
|
||
}
|
||
|
||
// 处理职称
|
||
if userDoctor.DoctorTitle != putUserDoctorRequest.DoctorTitle {
|
||
userDoctorData["doctor_title"] = putUserDoctorRequest.DoctorTitle
|
||
}
|
||
|
||
// 处理科室
|
||
departmentCustomId, err := strconv.ParseInt(putUserDoctorRequest.DepartmentCustomId, 10, 64)
|
||
if err != nil {
|
||
return false, errors.New("科室错误")
|
||
}
|
||
|
||
if departmentCustomId == 0 && userDoctor.DepartmentCustomId != 0 {
|
||
return false, errors.New("未选择新的科室")
|
||
}
|
||
if userDoctor.DepartmentCustomId != departmentCustomId || userDoctor.DepartmentCustomName != putUserDoctorRequest.DepartmentCustomName {
|
||
// 获取科室数据
|
||
hospitalDepartmentCustomDao := dao.HospitalDepartmentCustom{}
|
||
hospitalDepartmentCustom, err := hospitalDepartmentCustomDao.GetHospitalDepartmentCustomById(departmentCustomId)
|
||
if err != nil || hospitalDepartmentCustom == nil {
|
||
return false, errors.New("科室错误")
|
||
}
|
||
|
||
userDoctorData["department_custom_id"] = putUserDoctorRequest.DepartmentCustomId
|
||
userDoctorData["department_custom_name"] = hospitalDepartmentCustom.DepartmentCustomName
|
||
|
||
if putUserDoctorRequest.DepartmentCustomName != "" {
|
||
userDoctorData["department_custom_name"] = putUserDoctorRequest.DepartmentCustomName
|
||
}
|
||
}
|
||
|
||
// 处理科室电话
|
||
if userDoctor.DepartmentCustomMobile != putUserDoctorRequest.DepartmentCustomMobile {
|
||
userDoctorData["department_custom_id"] = putUserDoctorRequest.DepartmentCustomMobile
|
||
}
|
||
|
||
// 处理医院
|
||
hospitalId, err := strconv.ParseInt(putUserDoctorRequest.HospitalId, 10, 64)
|
||
if err != nil {
|
||
return false, errors.New("科室错误")
|
||
}
|
||
|
||
if userDoctor.HospitalID != hospitalId {
|
||
// 获取医院数据
|
||
hospitalDao := dao.Hospital{}
|
||
hospital, err := hospitalDao.GetHospitalById(hospitalId)
|
||
if err != nil || hospital == nil {
|
||
return false, errors.New("医院错误")
|
||
}
|
||
userDoctorData["department_custom_id"] = putUserDoctorRequest.HospitalId
|
||
}
|
||
|
||
// 处理深度合作医生
|
||
if userDoctor.IsPlatformDeepCooperation != putUserDoctorRequest.IsPlatformDeepCooperation {
|
||
userDoctorData["is_platform_deep_cooperation"] = putUserDoctorRequest.IsPlatformDeepCooperation
|
||
}
|
||
|
||
// 处理是否先思达合作医生
|
||
if userDoctor.IsSysDiagnoCooperation != putUserDoctorRequest.IsSysDiagnoCooperation {
|
||
userDoctorData["is_sys_diagno_cooperation"] = putUserDoctorRequest.IsSysDiagnoCooperation
|
||
}
|
||
|
||
// 处理擅长
|
||
if userDoctor.BeGoodAt != putUserDoctorRequest.BeGoodAt {
|
||
userDoctorData["be_good_at"] = putUserDoctorRequest.BeGoodAt
|
||
}
|
||
|
||
// 医生简介
|
||
if userDoctor.BriefIntroduction != putUserDoctorRequest.BriefIntroduction {
|
||
userDoctorData["brief_introduction"] = putUserDoctorRequest.BriefIntroduction
|
||
}
|
||
|
||
// 处理医师执业证
|
||
var licenseCert string
|
||
if len(putUserDoctorRequest.LicenseCert) > 0 {
|
||
result := make([]string, len(putUserDoctorRequest.LicenseCert))
|
||
for i, url := range putUserDoctorRequest.LicenseCert {
|
||
result[i] = strings.TrimPrefix(url, config.C.Oss.OssCustomDomainName)
|
||
}
|
||
|
||
licenseCert = strings.Join(result, ",")
|
||
}
|
||
|
||
if userDoctorInfo != nil {
|
||
if userDoctorInfo.LicenseCert != licenseCert {
|
||
userDoctorInfoData["license_cert"] = licenseCert
|
||
}
|
||
} else {
|
||
userDoctorInfoData["license_cert"] = licenseCert
|
||
}
|
||
|
||
// 处理医师资格证
|
||
var qualificationCert string
|
||
if len(putUserDoctorRequest.QualificationCert) > 0 {
|
||
result := make([]string, len(putUserDoctorRequest.QualificationCert))
|
||
for i, url := range putUserDoctorRequest.QualificationCert {
|
||
result[i] = strings.TrimPrefix(url, config.C.Oss.OssCustomDomainName)
|
||
}
|
||
|
||
qualificationCert = strings.Join(result, ",")
|
||
}
|
||
|
||
if userDoctorInfo != nil {
|
||
if userDoctorInfo.QualificationCert != qualificationCert {
|
||
userDoctorInfoData["qualification_cert"] = qualificationCert
|
||
}
|
||
} else {
|
||
userDoctorInfoData["qualification_cert"] = qualificationCert
|
||
}
|
||
|
||
// 处理医师工作证
|
||
var workCert string
|
||
if len(putUserDoctorRequest.WorkCert) > 0 {
|
||
result := make([]string, len(putUserDoctorRequest.WorkCert))
|
||
for i, url := range putUserDoctorRequest.WorkCert {
|
||
result[i] = strings.TrimPrefix(url, config.C.Oss.OssCustomDomainName)
|
||
}
|
||
|
||
workCert = strings.Join(result, ",")
|
||
}
|
||
|
||
if userDoctorInfo != nil {
|
||
if userDoctorInfo.WorkCert != workCert {
|
||
userDoctorInfoData["work_cert"] = workCert
|
||
}
|
||
} else {
|
||
userDoctorInfoData["work_cert"] = workCert
|
||
}
|
||
|
||
// 处理身份证正面图片
|
||
if userDoctorInfo.IdCardFront != "" && putUserDoctorRequest.IdCardFront == "" {
|
||
return false, errors.New("未上传新的身份证图片")
|
||
}
|
||
|
||
if putUserDoctorRequest.IdCardFront != "" {
|
||
idCardFront := strings.Replace(putUserDoctorRequest.IdCardFront, "https://img.applets.igandanyiyuan.com", "", 1)
|
||
if idCardFront != userDoctorInfo.IdCardFront {
|
||
if userDoctor.MultiPointStatus == 2 {
|
||
return false, errors.New("多点执业审核中,请操作后进行修改")
|
||
}
|
||
userDoctorInfoData["id_card_front"] = idCardFront
|
||
}
|
||
}
|
||
|
||
// 身份证背面图片
|
||
if userDoctorInfo.IdCardBack != "" && putUserDoctorRequest.IdCardBack == "" {
|
||
return false, errors.New("未上传新的身份证图片")
|
||
}
|
||
if putUserDoctorRequest.IdCardBack != "" {
|
||
idCardBack := strings.Replace(putUserDoctorRequest.IdCardBack, "https://img.applets.igandanyiyuan.com", "", 1)
|
||
if idCardBack != userDoctorInfo.IdCardBack {
|
||
if userDoctor.MultiPointStatus == 2 {
|
||
return false, errors.New("多点执业审核中,请操作后进行修改")
|
||
}
|
||
|
||
userDoctorInfoData["id_card_back"] = idCardBack
|
||
}
|
||
}
|
||
|
||
// 签名图片
|
||
if userDoctorInfo.SignImage != "" && putUserDoctorRequest.SignImage == "" {
|
||
return false, errors.New("未上传新的签名图片")
|
||
}
|
||
if putUserDoctorRequest.SignImage != "" {
|
||
signImage := strings.Replace(putUserDoctorRequest.SignImage, "https://img.applets.igandanyiyuan.com", "", 1)
|
||
if signImage != userDoctorInfo.SignImage {
|
||
if userDoctor.MultiPointStatus == 2 {
|
||
return false, errors.New("多点执业审核中,请操作后进行修改")
|
||
}
|
||
|
||
userDoctorInfoData["sign_image"] = signImage
|
||
}
|
||
}
|
||
|
||
// 处理专长
|
||
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("专长数据错误")
|
||
}
|
||
}
|
||
}
|
||
|
||
// 处理多点问题
|
||
fieldsToCheck := []string{"id_card_front", "id_card_back", "sign_image"}
|
||
|
||
exists := false
|
||
for _, field := range fieldsToCheck {
|
||
if _, ok := userDoctorInfoData[field]; ok {
|
||
exists = true
|
||
break
|
||
}
|
||
}
|
||
|
||
if exists {
|
||
idCardFront := userDoctorInfo.IdCardFront
|
||
idCardBack := userDoctorInfo.IdCardBack
|
||
signImage := userDoctorInfo.SignImage
|
||
|
||
if _, ok := userDoctorInfoData["id_card_front"]; ok {
|
||
idCardFront = userDoctorInfoData["id_card_front"].(string)
|
||
}
|
||
|
||
if _, ok := userDoctorInfoData["id_card_back"]; ok {
|
||
idCardBack = userDoctorInfoData["id_card_back"].(string)
|
||
}
|
||
|
||
if _, ok := userDoctorInfoData["sign_image"]; ok {
|
||
signImage = userDoctorInfoData["sign_image"].(string)
|
||
}
|
||
|
||
if idCardFront != "" && idCardBack != "" && signImage != "" {
|
||
// 检测是否存在正在审核中的处方
|
||
orderPrescriptionDao := dao.OrderPrescriptionDao{}
|
||
|
||
maps := make(map[string]interface{})
|
||
maps["doctor_id"] = doctorId
|
||
maps["prescription_status"] = 1
|
||
orderPrescription, err := orderPrescriptionDao.GetList(maps)
|
||
if err != nil {
|
||
return false, errors.New("修改失败")
|
||
}
|
||
|
||
if len(orderPrescription) > 0 {
|
||
return false, errors.New("存在审核中的处方,请勿修改签名数据")
|
||
}
|
||
|
||
// 修改签名数据,重新认定为未审核
|
||
userDoctorData["multi_point_status"] = 2
|
||
userDoctorData["multi_point_fail_reason"] = ""
|
||
}
|
||
}
|
||
|
||
// 开始事务
|
||
tx := global.Db.Begin()
|
||
defer func() {
|
||
if r := recover(); r != nil {
|
||
tx.Rollback()
|
||
}
|
||
}()
|
||
|
||
// 修改医生数据
|
||
if len(userDoctorData) != 0 {
|
||
err = userDoctorDao.EditUserDoctorById(tx, doctorId, userDoctorData)
|
||
if err != nil {
|
||
tx.Rollback()
|
||
return false, errors.New("修改失败")
|
||
}
|
||
}
|
||
|
||
// 修改医生详情数据
|
||
if userDoctorInfo == nil {
|
||
// 新增医生详情表
|
||
if len(userDoctorInfoData) != 0 {
|
||
userDoctorInfo, err := userDoctorInfoDao.AddUserDoctorInfoByMap(tx, userDoctorInfoData)
|
||
if userDoctorInfo == nil || err != nil {
|
||
tx.Rollback()
|
||
return false, errors.New("修改失败")
|
||
}
|
||
}
|
||
} else {
|
||
if len(userDoctorInfoData) != 0 {
|
||
err = userDoctorInfoDao.EditUserDoctorInfoById(tx, userDoctorInfo.DoctorInfoId, userDoctorInfoData)
|
||
if err != nil {
|
||
tx.Rollback()
|
||
return false, errors.New("修改失败")
|
||
}
|
||
}
|
||
}
|
||
|
||
// 修改用户数据
|
||
if len(userDoctorData) != 0 {
|
||
err = userDao.EditUserById(tx, userDoctor.UserId, userData)
|
||
if err != nil {
|
||
tx.Rollback()
|
||
return false, errors.New("修改失败")
|
||
}
|
||
}
|
||
|
||
// 修改专长数据
|
||
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{
|
||
{
|
||
Tag: "Tag_Profile_IM_Image",
|
||
Value: putUserDoctorRequest.Avatar,
|
||
},
|
||
}
|
||
res, err := tencentIm.SetProfile(strconv.FormatInt(userDoctor.UserId, 10), profileItem)
|
||
if err != nil || res != true {
|
||
tx.Rollback()
|
||
return false, errors.New(err.Error())
|
||
}
|
||
}
|
||
|
||
// 判断科室是否修改,同步修改ca平台
|
||
if userDoctor.DepartmentCustomId != departmentCustomId {
|
||
// 获取科室数据
|
||
hospitalDepartmentCustomDao := dao.HospitalDepartmentCustom{}
|
||
hospitalDepartmentCustom, err := hospitalDepartmentCustomDao.GetHospitalDepartmentCustomById(departmentCustomId)
|
||
if err != nil || hospitalDepartmentCustom == nil {
|
||
tx.Rollback()
|
||
return false, errors.New("科室错误")
|
||
}
|
||
|
||
// 获取云证书数据
|
||
userCaCertDao := dao.UserCaCert{}
|
||
userCaCerts, err := userCaCertDao.GetUserCaCertListByUserId(userDoctor.UserId)
|
||
if err != nil {
|
||
tx.Rollback()
|
||
return false, errors.New("修改失败")
|
||
}
|
||
|
||
if userCaCerts != nil && len(userCaCerts) > 0 {
|
||
// 修改云证书
|
||
editCloudCertRequestData := &ca.EditCloudCertRequestData{
|
||
EntityId: strconv.FormatInt(userDoctor.UserId, 10),
|
||
EntityType: "Personal",
|
||
PersonalPhone: user.Mobile,
|
||
PersonalName: userDoctorInfo.CardName,
|
||
PersonalIdNumber: userDoctorInfo.CardNum,
|
||
OrgName: "",
|
||
OrgNumber: "",
|
||
Pin: strconv.FormatInt(userDoctor.UserId, 10),
|
||
OrgDept: hospitalDepartmentCustom.DepartmentName, // // 卫生证书:医院部门
|
||
Province: "四川省",
|
||
Locality: "成都市",
|
||
AuthType: "实人认证",
|
||
// AuthTime: strconv.FormatInt(time.Now().Unix(), 10),
|
||
AuthTime: "1688694270",
|
||
AuthResult: "认证通过",
|
||
AuthNoticeType: "数字证书变更告知",
|
||
}
|
||
|
||
editCloudCertResponse, err := ca.EditCloudCert(editCloudCertRequestData)
|
||
if err != nil || editCloudCertResponse == nil {
|
||
tx.Rollback()
|
||
return false, errors.New(err.Error())
|
||
}
|
||
|
||
// 修改ca监管证书表
|
||
userCaCertDao := dao.UserCaCert{}
|
||
data := make(map[string]interface{})
|
||
data["cert_base64"] = editCloudCertResponse.CertBase64
|
||
data["cert_chain_p7"] = editCloudCertResponse.CertP7
|
||
data["cert_serial_number"] = editCloudCertResponse.CertP7
|
||
err = userCaCertDao.EditUserCaCertById(tx, userCaCerts[0].CertId, data)
|
||
if err != nil {
|
||
tx.Rollback()
|
||
return false, errors.New("删除失败")
|
||
}
|
||
}
|
||
}
|
||
|
||
// 判断签名图片是否修改,同步修改ca平台
|
||
// 1、新用户,未存在证书
|
||
// if putUserDoctorRequest.SignImage != "" {
|
||
// signImage := strings.Replace(putUserDoctorRequest.SignImage, "https://img.applets.igandanyiyuan.com", "", 1)
|
||
// if signImage != userDoctorInfo.SignImage {
|
||
// // 检测是否存在云证书
|
||
// userCaCertDao := dao.UserCaCert{}
|
||
// userCaCerts, err := userCaCertDao.GetUserCaCertListByUserId(userDoctor.UserId)
|
||
// if err != nil {
|
||
// tx.Rollback()
|
||
// return false, errors.New("修改失败")
|
||
// }
|
||
//
|
||
// if userCaCerts != nil && len(userCaCerts) > 0 {
|
||
// userCaCert := userCaCerts[0]
|
||
// // 检测是否已经添加签章配置
|
||
// if userCaCert.IsSignConfig == 1 {
|
||
// // 修改签章配置为未添加
|
||
// data := make(map[string]interface{})
|
||
// data["is_sign_config"] = 0
|
||
// err = userCaCertDao.EditUserCaCertById(tx, userCaCert.CertId, data)
|
||
// if err != nil {
|
||
// tx.Rollback()
|
||
// return false, errors.New(err.Error())
|
||
// }
|
||
//
|
||
// // 删除签章配置
|
||
// deleteUserSignConfigRequestData := &ca.DeleteUserSignConfigRequestData{
|
||
// UserId: strconv.FormatInt(userDoctor.UserId, 10),
|
||
// ConfigKey: strconv.FormatInt(userDoctor.UserId, 10),
|
||
// }
|
||
//
|
||
// _, err := ca.DeleteUserSignConfig(deleteUserSignConfigRequestData)
|
||
// if err != nil {
|
||
// tx.Rollback()
|
||
// return false, errors.New(err.Error())
|
||
// }
|
||
// }
|
||
// }
|
||
//
|
||
// }
|
||
// }
|
||
|
||
tx.Commit()
|
||
return true, nil
|
||
}
|
||
|
||
// AddUserDoctor 新增医生
|
||
func (r *UserDoctorService) AddUserDoctor(userId string, a requests.AddUserDoctor) (bool, error) {
|
||
userDoctorDao := dao.UserDoctorDao{}
|
||
userDao := dao.UserDao{}
|
||
userDoctorInfoDao := dao.UserDoctorInfoDao{}
|
||
|
||
// 检测手机号是否重复
|
||
maps := make(map[string]interface{})
|
||
maps["mobile"] = a.Mobile
|
||
users, err := userDao.GetUserList(maps)
|
||
if err != nil {
|
||
return false, errors.New("新增失败")
|
||
}
|
||
|
||
if len(users) != 0 {
|
||
return false, errors.New("手机号重复")
|
||
}
|
||
|
||
// 检测身份证号码
|
||
res, err := utils.CheckCardNum(a.CardNum)
|
||
if !res || err != nil {
|
||
return false, errors.New("身份证号错误")
|
||
}
|
||
|
||
// 检测身份证号是否重复
|
||
maps = make(map[string]interface{})
|
||
maps["card_num"] = a.CardNum
|
||
userDoctorInfos, err := userDoctorInfoDao.GetUserDoctorInfoList(maps)
|
||
if err != nil {
|
||
return false, errors.New("新增失败")
|
||
}
|
||
|
||
if len(userDoctorInfos) != 0 {
|
||
return false, errors.New("证件号码重复")
|
||
}
|
||
|
||
// 处理年龄
|
||
age, err := utils.GetCardAge(a.CardNum)
|
||
if err != nil {
|
||
return false, errors.New(err.Error())
|
||
}
|
||
|
||
// 处理性别
|
||
sex, err := utils.GetCardSex(a.CardNum)
|
||
if err != nil {
|
||
return false, errors.New(err.Error())
|
||
}
|
||
|
||
// 身份证号码脱敏
|
||
cardNumMask := utils.GetMaskCardNum(a.CardNum)
|
||
|
||
// 身份证名称脱敏
|
||
cardNameMask := utils.GetMaskCardName(a.CardName)
|
||
|
||
// 检测科室
|
||
departmentCustomId, err := strconv.ParseInt(a.DepartmentCustomId, 10, 64)
|
||
if err != nil {
|
||
return false, errors.New("科室错误")
|
||
}
|
||
|
||
// 获取科室数据
|
||
hospitalDepartmentCustomDao := dao.HospitalDepartmentCustom{}
|
||
hospitalDepartmentCustom, err := hospitalDepartmentCustomDao.GetHospitalDepartmentCustomById(departmentCustomId)
|
||
if err != nil || hospitalDepartmentCustom == nil {
|
||
return false, errors.New("科室错误")
|
||
}
|
||
|
||
// 检测医院
|
||
hospitalId, err := strconv.ParseInt(a.HospitalId, 10, 64)
|
||
if err != nil {
|
||
return false, errors.New("医院错误")
|
||
}
|
||
|
||
// 获取医院数据
|
||
hospitalDao := dao.Hospital{}
|
||
hospital, err := hospitalDao.GetHospitalById(hospitalId)
|
||
if err != nil || hospital == nil {
|
||
return false, errors.New("医院错误")
|
||
}
|
||
|
||
// 处理头像
|
||
avatar := utils.RemoveOssDomain(a.Avatar)
|
||
|
||
// 处理医师执业证
|
||
var licenseCert string
|
||
if len(a.LicenseCert) > 0 {
|
||
result := make([]string, len(a.LicenseCert))
|
||
for i, url := range a.LicenseCert {
|
||
result[i] = utils.RemoveOssDomain(url)
|
||
}
|
||
|
||
licenseCert = strings.Join(result, ",")
|
||
}
|
||
|
||
// 处理医师资格证
|
||
var qualificationCert string
|
||
if len(a.QualificationCert) > 0 {
|
||
result := make([]string, len(a.QualificationCert))
|
||
for i, url := range a.QualificationCert {
|
||
result[i] = utils.RemoveOssDomain(url)
|
||
}
|
||
|
||
qualificationCert = strings.Join(result, ",")
|
||
}
|
||
|
||
// 处理医师资格证
|
||
var workCert string
|
||
if len(a.WorkCert) > 0 {
|
||
result := make([]string, len(a.WorkCert))
|
||
for i, url := range a.WorkCert {
|
||
result[i] = utils.RemoveOssDomain(url)
|
||
}
|
||
|
||
workCert = strings.Join(result, ",")
|
||
}
|
||
|
||
// 处理身份证图片
|
||
var idCardFront string
|
||
var idCardBack string
|
||
|
||
if a.IdCardFront != "" {
|
||
idCardFront = utils.RemoveOssDomain(a.IdCardFront)
|
||
}
|
||
if a.IdCardBack != "" {
|
||
idCardBack = utils.RemoveOssDomain(a.IdCardBack)
|
||
}
|
||
|
||
// 处理签名图片
|
||
var signImage string
|
||
if a.SignImage != "" {
|
||
signImage = utils.RemoveOssDomain(a.SignImage)
|
||
}
|
||
|
||
// 多点执业状态
|
||
var multiPointStatus int
|
||
if a.IdCardFront != "" && a.IdCardBack != "" && a.SignImage != "" {
|
||
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() {
|
||
if r := recover(); r != nil {
|
||
tx.Rollback()
|
||
}
|
||
}()
|
||
|
||
// 新增用户表数据
|
||
user := &model.User{
|
||
UserName: a.CardName,
|
||
Mobile: a.Mobile,
|
||
WxMobile: a.Mobile,
|
||
UserType: 2,
|
||
UserStatus: 1,
|
||
RegisterMethod: 2,
|
||
Age: uint(age),
|
||
Sex: sex,
|
||
Avatar: avatar,
|
||
CreatedBy: userId,
|
||
}
|
||
user, err = userDao.AddUser(tx, user)
|
||
if err != nil || user == nil {
|
||
tx.Rollback()
|
||
return false, err
|
||
}
|
||
|
||
// 新增医生表
|
||
userDoctor := &model.UserDoctor{
|
||
UserId: user.UserId,
|
||
UserName: a.CardName,
|
||
Status: 1,
|
||
IdcardStatus: 1, // 身份证默认审核通过
|
||
IdenAuthStatus: 2,
|
||
MultiPointStatus: multiPointStatus,
|
||
IsBindBank: 0,
|
||
IsRecommend: a.IsRecommend,
|
||
Avatar: avatar,
|
||
DoctorTitle: a.DoctorTitle,
|
||
DepartmentCustomId: departmentCustomId,
|
||
DepartmentCustomName: a.DepartmentCustomName,
|
||
DepartmentCustomMobile: a.DepartmentCustomMobile,
|
||
HospitalID: hospitalId,
|
||
IsPlatformDeepCooperation: a.IsPlatformDeepCooperation,
|
||
IsSysDiagnoCooperation: a.IsSysDiagnoCooperation,
|
||
BeGoodAt: a.BeGoodAt,
|
||
BriefIntroduction: a.BriefIntroduction,
|
||
}
|
||
|
||
userDoctor, err = userDoctorDao.AddUserDoctor(tx, userDoctor)
|
||
if err != nil || userDoctor == nil {
|
||
tx.Rollback()
|
||
return false, err
|
||
}
|
||
|
||
// 新增医生详情表
|
||
userDoctorInfo := &model.UserDoctorInfo{
|
||
UserId: user.UserId,
|
||
DoctorId: userDoctor.DoctorId,
|
||
CardType: 1,
|
||
CardName: a.CardName,
|
||
CardNameMask: cardNameMask,
|
||
CardNum: a.CardNum,
|
||
CardNumMask: cardNumMask,
|
||
LicenseCert: licenseCert,
|
||
QualificationCert: qualificationCert,
|
||
WorkCert: workCert,
|
||
IdCardFront: idCardFront,
|
||
IdCardBack: idCardBack,
|
||
SignImage: signImage,
|
||
}
|
||
|
||
userDoctorInfo, err = userDoctorInfoDao.AddUserDoctorInfo(tx, userDoctorInfo)
|
||
if err != nil || userDoctor == nil {
|
||
tx.Rollback()
|
||
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())
|
||
}
|
||
}
|
||
}
|
||
|
||
// 创建im账户
|
||
res, err = tencentIm.CreateAccount(strconv.FormatInt(userDoctor.UserId, 10), a.CardName, a.Avatar)
|
||
if err != nil || res != true {
|
||
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
|
||
}
|
||
|
||
// GetUserDoctorBankByDoctorId 获取医生银行卡
|
||
func (r *UserDoctorService) GetUserDoctorBankByDoctorId(doctorId int64) (*doctorBankCardResponse.DoctorBankCard, error) {
|
||
// 获取医生银行卡
|
||
doctorBankCardDao := dao.DoctorBankCardDao{}
|
||
doctorBankCard, err := doctorBankCardDao.GetDoctorBankCardByDoctorId(doctorId)
|
||
if err != nil {
|
||
return nil, errors.New("用户数据错误")
|
||
}
|
||
|
||
doctorExpertisesResponse := &doctorBankCardResponse.DoctorBankCard{
|
||
BankCardId: strconv.FormatInt(doctorBankCard.BankCardId, 10),
|
||
DoctorId: strconv.FormatInt(doctorBankCard.DoctorId, 10),
|
||
BankId: strconv.FormatInt(doctorBankCard.BankId, 10),
|
||
BankCardCodeMask: doctorBankCard.BankCardCodeMask,
|
||
ProvinceId: doctorBankCard.ProvinceId,
|
||
Province: doctorBankCard.Province,
|
||
CityId: doctorBankCard.CityId,
|
||
City: doctorBankCard.City,
|
||
CountyId: doctorBankCard.CountyId,
|
||
County: doctorBankCard.County,
|
||
}
|
||
|
||
return doctorExpertisesResponse, nil
|
||
}
|
||
|
||
// GetDoctorIdenFailReasonByDoctorId 获取医生审核失败原因
|
||
func (r *UserDoctorService) GetDoctorIdenFailReasonByDoctorId(doctorId int64) (*userDoctorResponse.IdenAuthFailReason, error) {
|
||
doctorIdenFailDao := dao.DoctorIdenFailDao{}
|
||
doctorIdenFail, err := doctorIdenFailDao.GetDoctorIdenFailListByDoctorId(doctorId)
|
||
if err != nil {
|
||
return nil, errors.New("审核失败原因数据错误")
|
||
}
|
||
|
||
var idenAuthFailReason userDoctorResponse.IdenAuthFailReason
|
||
|
||
if doctorIdenFail != nil {
|
||
for _, v := range doctorIdenFail {
|
||
switch v.FieldName {
|
||
case "avatar":
|
||
idenAuthFailReason.AvatarReason = v.FailReason
|
||
case "department_custom_mobile":
|
||
idenAuthFailReason.DepartmentCustomMobileReason = v.FailReason
|
||
case "department_custom_name":
|
||
idenAuthFailReason.DepartmentCustomNameReason = v.FailReason
|
||
case "brief_introduction":
|
||
idenAuthFailReason.BriefIntroductionReason = v.FailReason
|
||
case "be_good_at":
|
||
idenAuthFailReason.BeGoodAtReason = v.FailReason
|
||
case "license_cert":
|
||
idenAuthFailReason.LicenseCertReason = v.FailReason
|
||
case "qualification_cert":
|
||
idenAuthFailReason.QualificationCertReason = v.FailReason
|
||
case "work_cert":
|
||
idenAuthFailReason.WorkCertReason = v.FailReason
|
||
default:
|
||
return nil, errors.New("审核失败原因数据错误")
|
||
}
|
||
}
|
||
}
|
||
|
||
return &idenAuthFailReason, nil
|
||
}
|
||
|
||
// GetUserDoctorPending 身份审核-医生详情
|
||
func (r *UserDoctorService) GetUserDoctorPending(doctorId int64) (g *userDoctorResponse.GetUserDoctorPending, 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 IdenAuthFailReason *userDoctorResponse.IdenAuthFailReason
|
||
if userDoctor.IdenAuthStatus == 3 {
|
||
IdenAuthFailReason, err = userDoctorService.GetDoctorIdenFailReasonByDoctorId(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)
|
||
}
|
||
|
||
g = &userDoctorResponse.GetUserDoctorPending{
|
||
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: IdenAuthFailReason,
|
||
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)),
|
||
BeGoodAt: userDoctor.BeGoodAt,
|
||
BriefIntroduction: userDoctor.BriefIntroduction,
|
||
CreatedAt: userDoctor.CreatedAt,
|
||
UpdatedAt: userDoctor.UpdatedAt,
|
||
User: user,
|
||
Hospital: hospital,
|
||
UserDoctorInfo: userDoctorInfo,
|
||
DoctorExpertise: doctorExpertise, // 专长
|
||
}
|
||
|
||
return g, nil
|
||
}
|
||
|
||
// PutUserDoctorPending 身份审核-审核医生
|
||
func (r *UserDoctorService) PutUserDoctorPending(doctorId int64, req requests.PutUserDoctorPending) (bool, error) {
|
||
// 获取医生数据
|
||
userDoctorDao := dao.UserDoctorDao{}
|
||
userDoctor, err := userDoctorDao.GetUserDoctorById(doctorId)
|
||
if err != nil || userDoctor == nil {
|
||
return false, errors.New("医生数据错误")
|
||
}
|
||
|
||
// 获取医生详情数据
|
||
userDoctorInfoDao := dao.UserDoctorInfoDao{}
|
||
userDoctorInfo, err := userDoctorInfoDao.GetUserDoctorInfoByDoctorId(doctorId)
|
||
if err != nil {
|
||
return false, errors.New("医生详情数据错误")
|
||
}
|
||
|
||
// 获取用户数据
|
||
userDao := dao.UserDao{}
|
||
user, err := userDao.GetUserById(userDoctor.UserId)
|
||
if err != nil || user == nil {
|
||
return false, errors.New("医生数据错误")
|
||
}
|
||
|
||
if userDoctor.IdenAuthStatus == 1 {
|
||
return false, errors.New("已审核成功,无法进行操作")
|
||
}
|
||
|
||
// 获取医院名称
|
||
hospitalDao := dao.Hospital{}
|
||
hospital, err := hospitalDao.GetHospitalById(userDoctor.HospitalID)
|
||
if err != nil {
|
||
return false, errors.New("审核失败")
|
||
}
|
||
|
||
userDoctorData := make(map[string]interface{}) // 医生数据
|
||
userDoctorInfoData := make(map[string]interface{}) // 医生详情数据
|
||
|
||
if req.IdenAuthStatus == 1 && req.QualificationCertNum == "" {
|
||
return false, errors.New("缺少医师资格证号,无法审核通过")
|
||
}
|
||
|
||
if userDoctor.IdenAuthStatus == req.IdenAuthStatus {
|
||
return false, errors.New("请勿重复操作")
|
||
}
|
||
|
||
// 开始事务
|
||
tx := global.Db.Begin()
|
||
defer func() {
|
||
if r := recover(); r != nil {
|
||
tx.Rollback()
|
||
}
|
||
}()
|
||
|
||
doctorIdenFailDao := dao.DoctorIdenFailDao{}
|
||
|
||
userDoctorData["iden_auth_time"] = time.Now().Format("2006-01-02 15:04:05")
|
||
|
||
// 审核不通过
|
||
if req.IdenAuthStatus == 3 {
|
||
userDoctorData["iden_auth_status"] = 3
|
||
|
||
if req.AvatarReason != "" {
|
||
doctorIdenFail := &model.DoctorIdenFail{
|
||
DoctorId: doctorId,
|
||
FieldName: "avatar",
|
||
FailReason: req.AvatarReason,
|
||
}
|
||
doctorIdenFail, err = doctorIdenFailDao.AddDoctorIdenFail(tx, doctorIdenFail)
|
||
if err != nil || doctorIdenFail == nil {
|
||
tx.Rollback()
|
||
return false, err
|
||
}
|
||
}
|
||
|
||
if req.DepartmentCustomMobileReason != "" {
|
||
doctorIdenFail := &model.DoctorIdenFail{
|
||
DoctorId: doctorId,
|
||
FieldName: "department_custom_mobile",
|
||
FailReason: req.DepartmentCustomMobileReason,
|
||
}
|
||
doctorIdenFail, err = doctorIdenFailDao.AddDoctorIdenFail(tx, doctorIdenFail)
|
||
if err != nil || doctorIdenFail == nil {
|
||
tx.Rollback()
|
||
return false, err
|
||
}
|
||
}
|
||
|
||
if req.DepartmentCustomNameReason != "" {
|
||
doctorIdenFail := &model.DoctorIdenFail{
|
||
DoctorId: doctorId,
|
||
FieldName: "department_custom_name",
|
||
FailReason: req.DepartmentCustomNameReason,
|
||
}
|
||
doctorIdenFail, err = doctorIdenFailDao.AddDoctorIdenFail(tx, doctorIdenFail)
|
||
if err != nil || doctorIdenFail == nil {
|
||
tx.Rollback()
|
||
return false, err
|
||
}
|
||
}
|
||
|
||
if req.BriefIntroductionReason != "" {
|
||
doctorIdenFail := &model.DoctorIdenFail{
|
||
DoctorId: doctorId,
|
||
FieldName: "brief_introduction",
|
||
FailReason: req.BriefIntroductionReason,
|
||
}
|
||
doctorIdenFail, err = doctorIdenFailDao.AddDoctorIdenFail(tx, doctorIdenFail)
|
||
if err != nil || doctorIdenFail == nil {
|
||
tx.Rollback()
|
||
return false, err
|
||
}
|
||
}
|
||
|
||
if req.BeGoodAtReason != "" {
|
||
doctorIdenFail := &model.DoctorIdenFail{
|
||
DoctorId: doctorId,
|
||
FieldName: "be_good_at_reason",
|
||
FailReason: req.BeGoodAtReason,
|
||
}
|
||
doctorIdenFail, err = doctorIdenFailDao.AddDoctorIdenFail(tx, doctorIdenFail)
|
||
if err != nil || doctorIdenFail == nil {
|
||
tx.Rollback()
|
||
return false, err
|
||
}
|
||
}
|
||
|
||
if req.LicenseCertReason != "" {
|
||
doctorIdenFail := &model.DoctorIdenFail{
|
||
DoctorId: doctorId,
|
||
FieldName: "license_cert_reason",
|
||
FailReason: req.LicenseCertReason,
|
||
}
|
||
doctorIdenFail, err = doctorIdenFailDao.AddDoctorIdenFail(tx, doctorIdenFail)
|
||
if err != nil || doctorIdenFail == nil {
|
||
tx.Rollback()
|
||
return false, err
|
||
}
|
||
}
|
||
|
||
if req.QualificationCertReason != "" {
|
||
doctorIdenFail := &model.DoctorIdenFail{
|
||
DoctorId: doctorId,
|
||
FieldName: "qualification_cert_reason",
|
||
FailReason: req.QualificationCertReason,
|
||
}
|
||
doctorIdenFail, err = doctorIdenFailDao.AddDoctorIdenFail(tx, doctorIdenFail)
|
||
if err != nil || doctorIdenFail == nil {
|
||
tx.Rollback()
|
||
return false, err
|
||
}
|
||
}
|
||
|
||
if req.WorkCertReason != "" {
|
||
doctorIdenFail := &model.DoctorIdenFail{
|
||
DoctorId: doctorId,
|
||
FieldName: "work_cert_reason",
|
||
FailReason: req.WorkCertReason,
|
||
}
|
||
doctorIdenFail, err = doctorIdenFailDao.AddDoctorIdenFail(tx, doctorIdenFail)
|
||
if err != nil || doctorIdenFail == nil {
|
||
tx.Rollback()
|
||
return false, err
|
||
}
|
||
}
|
||
}
|
||
|
||
// 审核通过
|
||
if req.IdenAuthStatus == 1 {
|
||
userDoctorData["iden_auth_status"] = 1
|
||
userDoctorInfoData["qualification_cert_num"] = req.QualificationCertNum
|
||
|
||
// 审核通过删除所有不通过原因数据
|
||
maps := make(map[string]interface{})
|
||
maps["doctor_id"] = doctorId
|
||
err := doctorIdenFailDao.DeleteDoctorIdenFail(tx, maps)
|
||
if err != nil {
|
||
tx.Rollback()
|
||
return false, errors.New("审核失败")
|
||
}
|
||
|
||
// 更新医生im资料
|
||
profileItem := []tencentIm.ProfileItem{
|
||
{
|
||
Tag: "Tag_Profile_Custom_Hname", // 医院
|
||
Value: hospital.HospitalName,
|
||
},
|
||
{
|
||
Tag: "Tag_Profile_Custom_Title", // 职称
|
||
Value: strconv.Itoa(userDoctor.DoctorTitle),
|
||
},
|
||
}
|
||
|
||
res, err := tencentIm.SetProfile(strconv.FormatInt(userDoctor.UserId, 10), profileItem)
|
||
if err != nil || res != true {
|
||
tx.Rollback()
|
||
return false, errors.New(err.Error())
|
||
}
|
||
|
||
}
|
||
|
||
// 修改医生数据
|
||
err = userDoctorDao.EditUserDoctorById(tx, doctorId, userDoctorData)
|
||
if err != nil {
|
||
tx.Rollback()
|
||
return false, errors.New("审核失败")
|
||
}
|
||
|
||
// 修改医生详情数据
|
||
if len(userDoctorInfoData) != 0 {
|
||
err = userDoctorInfoDao.EditUserDoctorInfoById(tx, userDoctorInfo.DoctorInfoId, userDoctorInfoData)
|
||
if err != nil {
|
||
tx.Rollback()
|
||
return false, errors.New("审核失败")
|
||
}
|
||
}
|
||
|
||
tx.Commit()
|
||
return true, nil
|
||
}
|
||
|
||
// GetMulti 多点-医生详情
|
||
func (r *UserDoctorService) GetMulti(doctorId int64) (g *userDoctorResponse.GetMulti, 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)
|
||
}
|
||
|
||
g = &userDoctorResponse.GetMulti{
|
||
DoctorID: strconv.Itoa(int(userDoctor.DoctorId)),
|
||
UserID: strconv.Itoa(int(userDoctor.UserId)),
|
||
UserName: userDoctor.UserName,
|
||
Status: userDoctor.Status,
|
||
IDCardStatus: userDoctor.Status,
|
||
MultiPointStatus: userDoctor.MultiPointStatus,
|
||
MultiPointTime: userDoctor.MultiPointTime,
|
||
MultiPointFailReason: userDoctor.MultiPointFailReason,
|
||
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)),
|
||
BeGoodAt: userDoctor.BeGoodAt,
|
||
BriefIntroduction: userDoctor.BriefIntroduction,
|
||
CreatedAt: userDoctor.CreatedAt,
|
||
UpdatedAt: userDoctor.UpdatedAt,
|
||
User: user,
|
||
Hospital: hospital,
|
||
UserDoctorInfo: userDoctorInfo,
|
||
DoctorExpertise: doctorExpertise, // 专长
|
||
}
|
||
|
||
return g, nil
|
||
}
|