1498 lines
45 KiB
Go
1498 lines
45 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(err.Error())
|
||
}
|
||
|
||
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: utils.AddOssDomain(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: utils.AddOssDomain(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, req 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 && user == 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 := utils.RemoveOssDomain(req.Avatar)
|
||
if userDoctor.Avatar != avatar {
|
||
userDoctorData["avatar"] = avatar
|
||
userData["avatar"] = avatar
|
||
}
|
||
|
||
// 处理职称
|
||
if userDoctor.DoctorTitle != req.DoctorTitle {
|
||
userDoctorData["doctor_title"] = req.DoctorTitle
|
||
}
|
||
|
||
// 处理科室
|
||
departmentCustomId, err := strconv.ParseInt(req.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 != req.DepartmentCustomName {
|
||
// 获取科室数据
|
||
hospitalDepartmentCustomDao := dao.HospitalDepartmentCustom{}
|
||
hospitalDepartmentCustom, err := hospitalDepartmentCustomDao.GetHospitalDepartmentCustomById(departmentCustomId)
|
||
if err != nil || hospitalDepartmentCustom == nil {
|
||
return false, errors.New("科室错误")
|
||
}
|
||
|
||
userDoctorData["department_custom_id"] = req.DepartmentCustomId
|
||
userDoctorData["department_custom_name"] = hospitalDepartmentCustom.DepartmentCustomName
|
||
|
||
if req.DepartmentCustomName != "" {
|
||
userDoctorData["department_custom_name"] = req.DepartmentCustomName
|
||
}
|
||
}
|
||
|
||
// 修改科室数据,重新认定为未审核
|
||
if userDoctor.DepartmentCustomId != departmentCustomId {
|
||
// 检测是否存在正在审核中的处方
|
||
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"] = ""
|
||
}
|
||
|
||
// 处理科室电话
|
||
if userDoctor.DepartmentCustomMobile != req.DepartmentCustomMobile {
|
||
userDoctorData["department_custom_id"] = req.DepartmentCustomMobile
|
||
}
|
||
|
||
// 处理医院
|
||
hospitalId, err := strconv.ParseInt(req.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"] = req.HospitalId
|
||
}
|
||
|
||
// 处理深度合作医生
|
||
if userDoctor.IsPlatformDeepCooperation != req.IsPlatformDeepCooperation {
|
||
userDoctorData["is_platform_deep_cooperation"] = req.IsPlatformDeepCooperation
|
||
}
|
||
|
||
// 处理是否先思达合作医生
|
||
if userDoctor.IsSysDiagnoCooperation != req.IsSysDiagnoCooperation {
|
||
userDoctorData["is_sys_diagno_cooperation"] = req.IsSysDiagnoCooperation
|
||
}
|
||
|
||
// 是否推荐
|
||
if userDoctor.IsRecommend != req.IsRecommend {
|
||
userDoctorData["is_recommend"] = req.IsRecommend
|
||
}
|
||
|
||
// 处理擅长
|
||
if userDoctor.BeGoodAt != req.BeGoodAt {
|
||
userDoctorData["be_good_at"] = req.BeGoodAt
|
||
}
|
||
|
||
// 医生简介
|
||
if userDoctor.BriefIntroduction != req.BriefIntroduction {
|
||
userDoctorData["brief_introduction"] = req.BriefIntroduction
|
||
}
|
||
|
||
// 处理医师执业证
|
||
var licenseCert string
|
||
if len(req.LicenseCert) > 0 {
|
||
result := make([]string, len(req.LicenseCert))
|
||
for i, url := range req.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(req.QualificationCert) > 0 {
|
||
result := make([]string, len(req.QualificationCert))
|
||
for i, url := range req.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(req.WorkCert) > 0 {
|
||
result := make([]string, len(req.WorkCert))
|
||
for i, url := range req.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 != "" && req.IdCardFront == "" {
|
||
return false, errors.New("未上传新的身份证图片")
|
||
}
|
||
|
||
if req.IdCardFront != "" {
|
||
idCardFront := strings.Replace(req.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 != "" && req.IdCardBack == "" {
|
||
return false, errors.New("未上传新的身份证图片")
|
||
}
|
||
if req.IdCardBack != "" {
|
||
idCardBack := strings.Replace(req.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 != "" && req.SignImage == "" {
|
||
return false, errors.New("未上传新的签名图片")
|
||
}
|
||
if req.SignImage != "" {
|
||
signImage := utils.RemoveOssDomain(req.SignImage)
|
||
if signImage != userDoctorInfo.SignImage {
|
||
if userDoctor.MultiPointStatus == 2 {
|
||
return false, errors.New("多点执业审核中,请操作后进行修改")
|
||
}
|
||
|
||
userDoctorInfoData["sign_image"] = 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("存在审核中的处方,请勿修改签名数据")
|
||
}
|
||
}
|
||
}
|
||
|
||
// 处理专长
|
||
if len(req.DoctorExpertise) > 0 {
|
||
// 检测专长是否存在
|
||
diseaseClassExpertiseDao := dao.DiseaseClassExpertiseDao{}
|
||
for _, v := range req.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()
|
||
}
|
||
}()
|
||
|
||
// 修改医生数据
|
||
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(req.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 req.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: req.Avatar,
|
||
},
|
||
}
|
||
res, err := tencentIm.SetProfile(strconv.FormatInt(userDoctor.UserId, 10), profileItem)
|
||
if err != nil || res != true {
|
||
tx.Rollback()
|
||
return false, errors.New(err.Error())
|
||
}
|
||
}
|
||
|
||
// 处理签名图片-如果更改,查看是否已添加签章配置,会进行删除
|
||
if req.SignImage != "" {
|
||
signImage := utils.RemoveOssDomain(req.SignImage)
|
||
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, req requests.AddUserDoctor) (bool, error) {
|
||
userDoctorDao := dao.UserDoctorDao{}
|
||
userDao := dao.UserDao{}
|
||
userDoctorInfoDao := dao.UserDoctorInfoDao{}
|
||
|
||
// 检测手机号是否重复
|
||
maps := make(map[string]interface{})
|
||
maps["mobile"] = req.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(req.CardNum)
|
||
if !res || err != nil {
|
||
return false, errors.New("身份证号错误")
|
||
}
|
||
|
||
// 检测身份证号是否重复
|
||
maps = make(map[string]interface{})
|
||
maps["card_num"] = req.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(req.CardNum)
|
||
if err != nil {
|
||
return false, errors.New(err.Error())
|
||
}
|
||
|
||
// 处理性别
|
||
sex, err := utils.GetCardSex(req.CardNum)
|
||
if err != nil {
|
||
return false, errors.New(err.Error())
|
||
}
|
||
|
||
// 身份证号码脱敏
|
||
cardNumMask := utils.GetMaskCardNum(req.CardNum)
|
||
|
||
// 身份证名称脱敏
|
||
cardNameMask := utils.GetMaskCardName(req.CardName)
|
||
|
||
// 检测科室
|
||
departmentCustomId, err := strconv.ParseInt(req.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(req.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(req.Avatar)
|
||
|
||
// 处理医师执业证
|
||
var licenseCert string
|
||
if len(req.LicenseCert) > 0 {
|
||
result := make([]string, len(req.LicenseCert))
|
||
for i, url := range req.LicenseCert {
|
||
result[i] = utils.RemoveOssDomain(url)
|
||
}
|
||
|
||
licenseCert = strings.Join(result, ",")
|
||
}
|
||
|
||
// 处理医师资格证
|
||
var qualificationCert string
|
||
if len(req.QualificationCert) > 0 {
|
||
result := make([]string, len(req.QualificationCert))
|
||
for i, url := range req.QualificationCert {
|
||
result[i] = utils.RemoveOssDomain(url)
|
||
}
|
||
|
||
qualificationCert = strings.Join(result, ",")
|
||
}
|
||
|
||
// 处理医师资格证
|
||
var workCert string
|
||
if len(req.WorkCert) > 0 {
|
||
result := make([]string, len(req.WorkCert))
|
||
for i, url := range req.WorkCert {
|
||
result[i] = utils.RemoveOssDomain(url)
|
||
}
|
||
|
||
workCert = strings.Join(result, ",")
|
||
}
|
||
|
||
// 处理身份证图片
|
||
var idCardFront string
|
||
var idCardBack string
|
||
|
||
if req.IdCardFront != "" {
|
||
idCardFront = utils.RemoveOssDomain(req.IdCardFront)
|
||
}
|
||
if req.IdCardBack != "" {
|
||
idCardBack = utils.RemoveOssDomain(req.IdCardBack)
|
||
}
|
||
|
||
// 处理签名图片
|
||
var signImage string
|
||
if req.SignImage != "" {
|
||
signImage = utils.RemoveOssDomain(req.SignImage)
|
||
}
|
||
|
||
// 多点执业状态
|
||
var multiPointStatus int
|
||
if req.IdCardFront != "" && req.IdCardBack != "" && req.SignImage != "" && departmentCustomId != 0 {
|
||
multiPointStatus = 2
|
||
}
|
||
|
||
// 处理专长
|
||
if len(req.DoctorExpertise) > 0 {
|
||
// 检测专长是否存在
|
||
diseaseClassExpertiseDao := dao.DiseaseClassExpertiseDao{}
|
||
for _, v := range req.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("专长数据错误")
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
// 处理银行卡省市区
|
||
areaDao := dao.AreaDao{}
|
||
var province string
|
||
if req.BankCardProvinceId != 0 {
|
||
area, err := areaDao.GetAreaById(req.BankCardProvinceId)
|
||
if err != nil || area == nil {
|
||
return false, errors.New("银行卡省份数据错误")
|
||
}
|
||
province = area.AreaName
|
||
}
|
||
|
||
var city string
|
||
if req.BankCardCityId != 0 {
|
||
area, err := areaDao.GetAreaById(req.BankCardCityId)
|
||
if err != nil || area == nil {
|
||
return false, errors.New("银行卡城市数据错误")
|
||
}
|
||
city = area.AreaName
|
||
}
|
||
|
||
var county string
|
||
if req.BankCardCountyId != 0 {
|
||
area, err := areaDao.GetAreaById(req.BankCardCountyId)
|
||
if err != nil || area == nil {
|
||
return false, errors.New("银行卡城市数据错误")
|
||
}
|
||
county = area.AreaName
|
||
}
|
||
|
||
// 处理银行卡数据
|
||
if req.BankId != "" {
|
||
bankId, err := strconv.ParseInt(req.BankId, 10, 64)
|
||
if err != nil {
|
||
return false, errors.New("银行错误")
|
||
}
|
||
|
||
basicBankDao := dao.BasicBankDao{}
|
||
basicBank, err := basicBankDao.GetBasicBankById(bankId)
|
||
if err != nil || basicBank == nil {
|
||
return false, errors.New("银行数据错误")
|
||
}
|
||
}
|
||
|
||
// 处理银行卡号掩码
|
||
var bankCardCodeMask string
|
||
if req.BankCardCode != "" {
|
||
if len(req.BankCardCode) < 8 {
|
||
return false, errors.New("银行卡号错误")
|
||
}
|
||
|
||
// 获取银行卡号的前4位和后4位
|
||
start := req.BankCardCode[:4]
|
||
end := req.BankCardCode[len(req.BankCardCode)-4:]
|
||
// 拼接前4位、中间的 * 字符串和后4位
|
||
bankCardCodeMask = start + "****" + end
|
||
}
|
||
|
||
// 开始事务
|
||
tx := global.Db.Begin()
|
||
defer func() {
|
||
if r := recover(); r != nil {
|
||
tx.Rollback()
|
||
}
|
||
}()
|
||
|
||
// 新增用户表数据
|
||
user := &model.User{
|
||
UserName: req.CardName,
|
||
Mobile: req.Mobile,
|
||
WxMobile: req.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, errors.New(err.Error())
|
||
}
|
||
|
||
// 新增医生表
|
||
userDoctor := &model.UserDoctor{
|
||
UserId: user.UserId,
|
||
UserName: req.CardName,
|
||
Status: 1,
|
||
IdcardStatus: 1, // 身份证默认审核通过
|
||
IdenAuthStatus: 2,
|
||
MultiPointStatus: multiPointStatus,
|
||
IsBindBank: 0,
|
||
IsRecommend: req.IsRecommend,
|
||
Avatar: avatar,
|
||
DoctorTitle: req.DoctorTitle,
|
||
DepartmentCustomId: departmentCustomId,
|
||
DepartmentCustomName: req.DepartmentCustomName,
|
||
DepartmentCustomMobile: req.DepartmentCustomMobile,
|
||
HospitalID: hospitalId,
|
||
IsPlatformDeepCooperation: req.IsPlatformDeepCooperation,
|
||
IsSysDiagnoCooperation: req.IsSysDiagnoCooperation,
|
||
BeGoodAt: req.BeGoodAt,
|
||
BriefIntroduction: req.BriefIntroduction,
|
||
}
|
||
userDoctor, err = userDoctorDao.AddUserDoctor(tx, userDoctor)
|
||
if err != nil || userDoctor == nil {
|
||
tx.Rollback()
|
||
return false, errors.New(err.Error())
|
||
}
|
||
|
||
// 新增医生详情表
|
||
userDoctorInfo := &model.UserDoctorInfo{
|
||
UserId: user.UserId,
|
||
DoctorId: userDoctor.DoctorId,
|
||
CardType: 1,
|
||
CardName: req.CardName,
|
||
CardNameMask: cardNameMask,
|
||
CardNum: req.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, errors.New(err.Error())
|
||
}
|
||
|
||
// 新增医生银行卡表
|
||
if req.BankCardProvinceId != 0 && req.BankCardCityId != 0 && req.BankCardCountyId != 0 && req.BankId != "" && req.BankCardCode != "" {
|
||
bankId, err := strconv.ParseInt(req.BankId, 10, 64)
|
||
if err != nil {
|
||
return false, errors.New("银行错误")
|
||
}
|
||
|
||
doctorBankCard := &model.DoctorBankCard{
|
||
DoctorId: userDoctor.DoctorId,
|
||
BankId: bankId,
|
||
BankCardCode: req.BankCardCode,
|
||
BankCardCodeMask: bankCardCodeMask,
|
||
ProvinceId: req.BankCardProvinceId,
|
||
Province: province,
|
||
CityId: req.BankCardCityId,
|
||
City: city,
|
||
CountyId: req.BankCardCountyId,
|
||
County: county,
|
||
}
|
||
doctorBankCardDao := dao.DoctorBankCardDao{}
|
||
|
||
doctorBankCard, err = doctorBankCardDao.AddDoctorBankCard(tx, doctorBankCard)
|
||
if err != nil || doctorBankCard == nil {
|
||
tx.Rollback()
|
||
return false, errors.New(err.Error())
|
||
}
|
||
}
|
||
|
||
// 修改专长数据
|
||
if len(req.DoctorExpertise) > 0 {
|
||
doctorExpertiseDao := dao.DoctorExpertiseDao{}
|
||
|
||
for _, v := range req.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), req.CardName, req.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 && doctorBankCard == nil {
|
||
return nil, nil
|
||
}
|
||
|
||
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(err.Error())
|
||
}
|
||
|
||
var idenAuthFailReason userDoctorResponse.IdenAuthFailReason
|
||
|
||
if len(doctorIdenFail) > 0 {
|
||
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: utils.AddOssDomain(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,
|
||
IsPlatformDeepCooperation: userDoctor.IsPlatformDeepCooperation,
|
||
IsEnterpriseDeepCooperation: userDoctor.IsEnterpriseDeepCooperation,
|
||
IsSysDiagnoCooperation: userDoctor.IsSysDiagnoCooperation,
|
||
IsRecommend: userDoctor.IsRecommend,
|
||
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")
|
||
|
||
// 审核通过删除所有不通过原因数据
|
||
maps := make(map[string]interface{})
|
||
maps["doctor_id"] = doctorId
|
||
err = doctorIdenFailDao.DeleteDoctorIdenFail(tx, maps)
|
||
if err != nil {
|
||
tx.Rollback()
|
||
return false, errors.New("审核失败")
|
||
}
|
||
|
||
// 审核不通过
|
||
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",
|
||
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",
|
||
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",
|
||
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",
|
||
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
|
||
|
||
// 更新医生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("用户数据错误")
|
||
}
|
||
|
||
// 处理返回值
|
||
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: utils.AddOssDomain(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,
|
||
}
|
||
|
||
return g, nil
|
||
}
|
||
|
||
// PutMulti 多点-审核医生
|
||
func (r *UserDoctorService) PutMulti(doctorId int64, req requests.PutMulti) (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.MultiPointStatus == 1 {
|
||
return false, errors.New("已审核成功,无法进行操作")
|
||
}
|
||
|
||
if userDoctor.IdenAuthStatus != 1 {
|
||
return false, errors.New("请先通过身份认证")
|
||
}
|
||
|
||
userDoctorData := make(map[string]interface{}) // 医生数据
|
||
|
||
if userDoctor.MultiPointStatus == req.MultiPointStatus {
|
||
return false, errors.New("请勿重复操作")
|
||
}
|
||
|
||
// 开始事务
|
||
tx := global.Db.Begin()
|
||
defer func() {
|
||
if r := recover(); r != nil {
|
||
tx.Rollback()
|
||
}
|
||
}()
|
||
|
||
// 检测是否存在云证书
|
||
userCaCertDao := dao.UserCaCert{}
|
||
userCaCert, _ := userCaCertDao.GetUserCaCertByUserId(userDoctor.UserId)
|
||
|
||
// 获取自定义科室数据
|
||
hospitalDepartmentCustomDao := dao.HospitalDepartmentCustom{}
|
||
hospitalDepartmentCustom, err := hospitalDepartmentCustomDao.GetHospitalDepartmentCustomById(userDoctor.DepartmentCustomId)
|
||
if err != nil || hospitalDepartmentCustom == nil {
|
||
tx.Rollback()
|
||
return false, errors.New("科室错误")
|
||
}
|
||
|
||
// 获取标准科室数据
|
||
hospitalDepartmentDao := dao.HospitalDepartment{}
|
||
hospitalDepartment, err := hospitalDepartmentDao.GetHospitalDepartmentById(hospitalDepartmentCustom.DepartmentId)
|
||
if err != nil || hospitalDepartment == nil {
|
||
tx.Rollback()
|
||
return false, errors.New("科室错误")
|
||
}
|
||
|
||
// 处理审核拒绝的情况
|
||
if req.MultiPointStatus == 1 {
|
||
if userCaCert == nil {
|
||
// 申请云证书
|
||
cloudCertRequestData := &ca.AddCloudCertRequest{
|
||
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: hospitalDepartment.DepartmentName, // // 卫生证书:医院部门
|
||
Province: "四川省",
|
||
Locality: "成都市",
|
||
AuthType: "实人认证",
|
||
AuthTime: strconv.FormatInt(time.Now().Unix(), 10),
|
||
AuthResult: "认证通过",
|
||
AuthNoticeType: "数字证书申请告知",
|
||
}
|
||
|
||
cloudCertResponse, err := ca.AddCloudCert(cloudCertRequestData)
|
||
if err != nil || cloudCertResponse == nil {
|
||
tx.Rollback()
|
||
return false, errors.New(err.Error())
|
||
}
|
||
|
||
// 新增ca监管证书表
|
||
userCaCert := &model.UserCaCert{
|
||
UserId: &userDoctor.UserId,
|
||
IsSystem: 0,
|
||
Type: 1,
|
||
CertBase64: cloudCertResponse.CertBase64,
|
||
CertChainP7: cloudCertResponse.CertP7,
|
||
CertSerialNumber: cloudCertResponse.CertSerialnumber,
|
||
CaPin: strconv.FormatInt(userDoctor.UserId, 10),
|
||
IsSignConfig: 0,
|
||
SignConfig: "",
|
||
}
|
||
|
||
userCaCert, err = userCaCertDao.AddUserCaCert(tx, userCaCert)
|
||
if err != nil || userCaCert == nil {
|
||
tx.Rollback()
|
||
return false, errors.New(err.Error())
|
||
}
|
||
} else {
|
||
// 修改云证书
|
||
cloudCertRequestData := &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: hospitalDepartment.DepartmentName, // // 卫生证书:医院部门
|
||
Province: "四川省",
|
||
Locality: "成都市",
|
||
AuthType: "实人认证",
|
||
AuthTime: strconv.FormatInt(time.Now().Unix(), 10),
|
||
AuthResult: "认证通过",
|
||
AuthNoticeType: "数字证书变更告知",
|
||
}
|
||
|
||
cloudCertResponse, err := ca.EditCloudCert(cloudCertRequestData)
|
||
if err != nil || cloudCertResponse == nil {
|
||
tx.Rollback()
|
||
return false, errors.New(err.Error())
|
||
}
|
||
|
||
// 修改ca监管证书表
|
||
userCaCertDao := dao.UserCaCert{}
|
||
data := make(map[string]interface{})
|
||
data["cert_base64"] = cloudCertResponse.CertBase64
|
||
data["cert_chain_p7"] = cloudCertResponse.CertP7
|
||
data["cert_serial_number"] = cloudCertResponse.CertSerialnumber
|
||
err = userCaCertDao.EditUserCaCertById(tx, userCaCert.CertId, data)
|
||
if err != nil {
|
||
tx.Rollback()
|
||
return false, errors.New("审核失败")
|
||
}
|
||
}
|
||
}
|
||
|
||
userDoctorData["multi_point_time"] = time.Now().Format("2006-01-02 15:04:05")
|
||
|
||
// 审核不通过
|
||
if req.MultiPointStatus == 3 {
|
||
userDoctorData["multi_point_status"] = 3
|
||
userDoctorData["multi_point_fail_reason"] = req.MultiPointFailReason
|
||
}
|
||
|
||
// 审核通过
|
||
if req.MultiPointStatus == 1 {
|
||
userDoctorData["multi_point_status"] = 1
|
||
userDoctorData["multi_point_fail_reason"] = ""
|
||
|
||
}
|
||
|
||
// 修改医生数据
|
||
err = userDoctorDao.EditUserDoctorById(tx, doctorId, userDoctorData)
|
||
if err != nil {
|
||
tx.Rollback()
|
||
return false, errors.New("审核失败")
|
||
}
|
||
|
||
tx.Commit()
|
||
return true, nil
|
||
}
|