新增添加医生
This commit is contained in:
parent
fa96649a43
commit
1e5a26b329
@ -29,7 +29,28 @@ func (b *Department) GetDepartmentCustomList(c *gin.Context) {
|
||||
|
||||
hospitalDepartmentCustomDao := dao.HospitalDepartmentCustom{}
|
||||
|
||||
hospitalDepartmentCustom, err := hospitalDepartmentCustomDao.GetHospitalDepartmentCustomList(departmentRequest.GetDepartmentCustomList)
|
||||
maps := make(map[string]interface{})
|
||||
if departmentRequest.DepartmentId != "" {
|
||||
maps["department_id"] = departmentRequest.DepartmentId
|
||||
}
|
||||
|
||||
if departmentRequest.DepartmentCustomName != "" {
|
||||
maps["department_custom_name"] = departmentRequest.DepartmentCustomName
|
||||
}
|
||||
|
||||
if departmentRequest.DepartmentName != "" {
|
||||
maps["department_name"] = departmentRequest.DepartmentName
|
||||
}
|
||||
|
||||
if departmentRequest.DepartmentCode != "" {
|
||||
maps["department_code"] = departmentRequest.DepartmentCode
|
||||
}
|
||||
|
||||
if departmentRequest.DepartmentStatus != 0 {
|
||||
maps["department_status"] = departmentRequest.DepartmentStatus
|
||||
}
|
||||
|
||||
hospitalDepartmentCustom, err := hospitalDepartmentCustomDao.GetHospitalDepartmentCustomList(maps)
|
||||
if err != nil {
|
||||
responses.Ok(c)
|
||||
return
|
||||
|
||||
@ -136,9 +136,18 @@ func (r *UserDoctor) AddUserDoctor(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// 获取当前登陆用户id
|
||||
userId := c.GetInt64("UserId")
|
||||
if userId == 0 {
|
||||
responses.FailWithMessage("角色错误", c)
|
||||
return
|
||||
}
|
||||
|
||||
userIdStr := strconv.FormatInt(userId, 10)
|
||||
|
||||
// 业务处理
|
||||
userDoctorService := service.UserDoctorService{}
|
||||
_, err := userDoctorService.AddUserDoctor(userDoctorRequest.AddUserDoctor)
|
||||
_, err := userDoctorService.AddUserDoctor(userIdStr, userDoctorRequest.AddUserDoctor)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
@ -146,3 +155,44 @@ func (r *UserDoctor) AddUserDoctor(c *gin.Context) {
|
||||
|
||||
responses.Ok(c)
|
||||
}
|
||||
|
||||
// GetUserDoctorPendingPage 获取医生待审核列表-分页
|
||||
func (r *UserDoctor) GetUserDoctorPendingPage(c *gin.Context) {
|
||||
userDoctorRequest := requests.UserDoctorRequest{}
|
||||
if err := c.ShouldBind(&userDoctorRequest.GetUserDoctorPendingPage); err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 参数验证
|
||||
if err := global.Validate.Struct(userDoctorRequest.GetUserDoctorPendingPage); err != nil {
|
||||
responses.FailWithMessage(utils.Translate(err), c)
|
||||
return
|
||||
}
|
||||
|
||||
if userDoctorRequest.GetUserDoctorPendingPage.Page == 0 {
|
||||
userDoctorRequest.GetUserDoctorPendingPage.Page = 1
|
||||
}
|
||||
|
||||
if userDoctorRequest.GetUserDoctorPendingPage.PageSize == 0 {
|
||||
userDoctorRequest.GetUserDoctorPendingPage.PageSize = 20
|
||||
}
|
||||
|
||||
userDoctorDao := dao.UserDoctorDao{}
|
||||
userDoctor, total, err := userDoctorDao.GetUserDoctorDaoPageSearch(userDoctorRequest.GetUserDoctorPage, userDoctorRequest.GetUserDoctorPage.Page, userDoctorRequest.GetUserDoctorPage.PageSize)
|
||||
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 处理返回值
|
||||
getUserDoctorPageResponses := userDoctorResponse.GetUserDoctorPageResponse(userDoctor)
|
||||
|
||||
result := make(map[string]interface{})
|
||||
result["page"] = userDoctorRequest.GetUserDoctorPage.Page
|
||||
result["page_size"] = userDoctorRequest.GetUserDoctorPage.PageSize
|
||||
result["total"] = total
|
||||
result["data"] = getUserDoctorPageResponses
|
||||
responses.OkWithData(result, c)
|
||||
}
|
||||
|
||||
@ -17,6 +17,7 @@ type User struct {
|
||||
Avatar string `gorm:"column:avatar;type:varchar(255);comment:头像" json:"avatar"`
|
||||
LoginIp string `gorm:"column:login_ip;type:varchar(255);comment:登陆ip" json:"login_ip"`
|
||||
LastLoginAt LocalTime `gorm:"column:last_login_at;type:datetime;comment:最后登陆时间" json:"last_login_at"`
|
||||
CreatedBy string `gorm:"column:created_by;type:varchar(100);comment:创建者id(后台用户表id null:自己注册)" json:"created_by"`
|
||||
Model
|
||||
}
|
||||
|
||||
|
||||
@ -1,9 +1,10 @@
|
||||
package requests
|
||||
|
||||
type UserDoctorRequest struct {
|
||||
GetUserDoctorPage // 获取医生列表-分页
|
||||
PutUserDoctor // 修改医生
|
||||
AddUserDoctor // 新增医生
|
||||
GetUserDoctorPage // 获取医生列表-分页
|
||||
PutUserDoctor // 修改医生
|
||||
AddUserDoctor // 新增医生
|
||||
GetUserDoctorPendingPage // 获取医生待审核列表-分页
|
||||
}
|
||||
|
||||
// GetUserDoctorPage 获取医生列表-分页
|
||||
@ -46,23 +47,35 @@ type PutUserDoctor struct {
|
||||
|
||||
// AddUserDoctor 新增医生
|
||||
type AddUserDoctor struct {
|
||||
CardName string `json:"card_name" form:"card_name" validate:"required" label:"姓名"`
|
||||
Mobile string `json:"mobile" form:"mobile" validate:"mobile" validate:"required" label:"手机号"`
|
||||
IsRecommend int `json:"is_recommend" form:"is_recommend" label:"是否首页推荐"` // (0:否 1:是)
|
||||
Avatar string `json:"avatar" form:"avatar" validate:"required" label:"头像"`
|
||||
DoctorTitle int `json:"doctor_title" form:"doctor_title" validate:"required,oneof=1 2 3 4 5 6" label:"医生职称"` // (1:主任医师 2:主任中医师 3:副主任医师 4:副主任中医师 5:主治医师 6:住院医师)
|
||||
DepartmentCustomId string `json:"department_custom_id" form:"department_custom_id" validate:"required" validate:"required" label:"科室"`
|
||||
DepartmentCustomName string `json:"department_custom_name" form:"department_custom_name" validate:"required" label:"科室名称"` // (如未自己输入,填入标准科室名称)
|
||||
DepartmentCustomMobile string `json:"department_custom_mobile" form:"department_custom_mobile" label:"科室电话"`
|
||||
HospitalId string `json:"hospital_id" form:"hospital_id" validate:"required" label:"所属医院id"`
|
||||
BeGoodAt string `json:"be_good_at" form:"be_good_at" validate:"required" label:"擅长"`
|
||||
BriefIntroduction string `json:"brief_introduction" form:"brief_introduction" validate:"required" label:"医生简介"`
|
||||
LicenseCert []string `json:"license_cert" form:"license_cert" validate:"required" label:"医师执业证"`
|
||||
QualificationCert []string `json:"qualification_cert" form:"qualification_cert" validate:"required" label:"医师资格证"`
|
||||
QualificationCertNum string `json:"qualification_cert_num" form:"qualification_cert_num" validate:"required" label:"医师资格证号"`
|
||||
WorkCert []string `json:"work_cert" form:"work_cert" validate:"required" label:"医师资格证"`
|
||||
IdCardFront string `json:"id_card_front" form:"id_card_front" label:"身份证正面图片"`
|
||||
IdCardBack string `json:"id_card_back" form:"id_card_back" label:"身份证背面图片"`
|
||||
SignImage string `json:"sign_image" form:"sign_image" label:"签名图片"`
|
||||
CardNum string `json:"card_num" form:"card_num" label:"证件号码"`
|
||||
CardName string `json:"card_name" form:"card_name" validate:"required" label:"姓名"`
|
||||
Mobile string `json:"mobile" form:"mobile" validate:"required,Mobile" label:"手机号"`
|
||||
IsRecommend int `json:"is_recommend" form:"is_recommend" label:"是否首页推荐"` // (0:否 1:是)
|
||||
Avatar string `json:"avatar" form:"avatar" validate:"required" label:"头像"`
|
||||
DoctorTitle int `json:"doctor_title" form:"doctor_title" validate:"required,oneof=1 2 3 4 5 6" label:"医生职称"` // (1:主任医师 2:主任中医师 3:副主任医师 4:副主任中医师 5:主治医师 6:住院医师)
|
||||
DepartmentCustomId string `json:"department_custom_id" form:"department_custom_id" validate:"required" validate:"required" label:"科室"`
|
||||
DepartmentCustomName string `json:"department_custom_name" form:"department_custom_name" validate:"required" label:"科室名称"` // (如未自己输入,填入标准科室名称)
|
||||
DepartmentCustomMobile string `json:"department_custom_mobile" form:"department_custom_mobile" label:"科室电话"`
|
||||
HospitalId string `json:"hospital_id" form:"hospital_id" validate:"required" label:"所属医院id"`
|
||||
IsPlatformDeepCooperation int `json:"is_platform_deep_cooperation" form:"is_platform_deep_cooperation" validate:"required" label:"平台深度合作医生"` // 是否平台深度合作医生(0:否 1:是)
|
||||
BeGoodAt string `json:"be_good_at" form:"be_good_at" validate:"required" label:"擅长"`
|
||||
BriefIntroduction string `json:"brief_introduction" form:"brief_introduction" validate:"required" label:"医生简介"`
|
||||
LicenseCert []string `json:"license_cert" form:"license_cert" validate:"required" label:"医师执业证"`
|
||||
QualificationCert []string `json:"qualification_cert" form:"qualification_cert" validate:"required" label:"医师资格证"`
|
||||
QualificationCertNum string `json:"qualification_cert_num" form:"qualification_cert_num" validate:"required" label:"医师资格证号"`
|
||||
WorkCert []string `json:"work_cert" form:"work_cert" validate:"required" label:"医师工作证"`
|
||||
IdCardFront string `json:"id_card_front" form:"id_card_front" label:"身份证正面图片"`
|
||||
IdCardBack string `json:"id_card_back" form:"id_card_back" label:"身份证背面图片"`
|
||||
SignImage string `json:"sign_image" form:"sign_image" label:"签名图片"`
|
||||
CardNum string `json:"card_num" form:"card_num" validate:"required" label:"证件号码"`
|
||||
}
|
||||
|
||||
// GetUserDoctorPendingPage 获取医生待审核列表-分页
|
||||
type GetUserDoctorPendingPage struct {
|
||||
Page int `json:"page" form:"page" label:"页码"`
|
||||
PageSize int `json:"page_size" form:"page_size" label:"每页个数"`
|
||||
Mobile string `json:"mobile" form:"mobile" label:"手机号"`
|
||||
UserName string `json:"user_name" form:"user_name" label:"用户名"`
|
||||
HospitalName string `json:"hospital_name" form:"hospital_name" label:"医院名称"`
|
||||
IdenAuthStatus int `json:"iden_auth_status" form:"iden_auth_status" label:"认证状态"` // (0:未认证 1:认证通过 2:审核中 3:认证失败)
|
||||
MultiPointStatus int `json:"multi_point_status" form:"multi_point_status" label:"多点执业状态"` // 医生多点执业认证状态(0:未认证 1:认证通过 2:审核中 3:认证失败)
|
||||
}
|
||||
|
||||
@ -20,6 +20,7 @@ type User struct {
|
||||
Avatar string `json:"avatar"` // 头像
|
||||
LoginIP string `json:"login_ip"` // 登陆ip
|
||||
LastLoginAt model.LocalTime `json:"last_login_at"` // 最后登陆时间
|
||||
CreatedBy string `json:"created_by"` // 创建者id(后台用户表id null:自己注册)
|
||||
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
|
||||
UpdatedAt model.LocalTime `json:"updated_at"` // 修改时间
|
||||
}
|
||||
@ -40,6 +41,7 @@ func UserResponse(user *model.User) *User {
|
||||
Avatar: config.C.Oss.OssCustomDomainName + "/" + user.Avatar,
|
||||
LoginIP: user.LoginIp,
|
||||
LastLoginAt: user.LastLoginAt,
|
||||
CreatedBy: user.CreatedBy,
|
||||
CreatedAt: user.CreatedAt,
|
||||
UpdatedAt: user.UpdatedAt,
|
||||
}
|
||||
|
||||
@ -238,6 +238,23 @@ func privateRouter(r *gin.Engine, api controller.Api) {
|
||||
|
||||
// 新增医生
|
||||
doctorGroup.POST("", api.UserDoctor.AddUserDoctor)
|
||||
|
||||
// 待审核列表
|
||||
doctorPendingGroup := adminGroup.Group("/pending")
|
||||
{
|
||||
// 获取医生列表-分页
|
||||
doctorPendingGroup.GET("", api.UserDoctor.GetUserDoctorPendingPage)
|
||||
|
||||
// 医生详情
|
||||
doctorPendingGroup.GET("/:doctor_id", api.UserDoctor.GetPostUserDoctor)
|
||||
|
||||
// 修改医生
|
||||
doctorPendingGroup.PUT("/:doctor_id", api.UserDoctor.PutUserDoctor)
|
||||
|
||||
// 新增医生
|
||||
doctorPendingGroup.POST("", api.UserDoctor.AddUserDoctor)
|
||||
|
||||
}
|
||||
//
|
||||
// // 医生详情
|
||||
// doctorGroup.GET("/:post_id", api.Post.GetPost)
|
||||
|
||||
@ -3,11 +3,13 @@ package service
|
||||
import (
|
||||
"errors"
|
||||
"hospital-admin-api/api/dao"
|
||||
"hospital-admin-api/api/model"
|
||||
"hospital-admin-api/api/requests"
|
||||
"hospital-admin-api/config"
|
||||
"hospital-admin-api/extend/ca"
|
||||
"hospital-admin-api/extend/tencentIm"
|
||||
"hospital-admin-api/global"
|
||||
"hospital-admin-api/utils"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
@ -16,7 +18,7 @@ type UserDoctorService struct {
|
||||
}
|
||||
|
||||
// PutUserDoctor 修改医生
|
||||
func (r *UserDoctorService) PutUserDoctor(doctorId int64, userDoctorRequest requests.PutUserDoctor) (bool, error) {
|
||||
func (r *UserDoctorService) PutUserDoctor(doctorId int64, putUserDoctorRequest requests.PutUserDoctor) (bool, error) {
|
||||
|
||||
// 获取医生数据
|
||||
userDoctorDao := dao.UserDoctorDao{}
|
||||
@ -44,19 +46,19 @@ func (r *UserDoctorService) PutUserDoctor(doctorId int64, userDoctorRequest requ
|
||||
userData := make(map[string]interface{}) // 用户数据
|
||||
|
||||
// 处理头像
|
||||
avatar := strings.Replace(userDoctorRequest.Avatar, config.C.Oss.OssCustomDomainName, "", 1)
|
||||
avatar := strings.Replace(putUserDoctorRequest.Avatar, config.C.Oss.OssCustomDomainName, "", 1)
|
||||
if userDoctor.Avatar != avatar {
|
||||
userDoctorData["avatar"] = avatar
|
||||
userData["avatar"] = avatar
|
||||
}
|
||||
|
||||
// 处理职称
|
||||
if userDoctor.DoctorTitle != userDoctorRequest.DoctorTitle {
|
||||
userDoctorData["doctor_title"] = userDoctorRequest.DoctorTitle
|
||||
if userDoctor.DoctorTitle != putUserDoctorRequest.DoctorTitle {
|
||||
userDoctorData["doctor_title"] = putUserDoctorRequest.DoctorTitle
|
||||
}
|
||||
|
||||
// 处理科室
|
||||
departmentCustomId, err := strconv.ParseInt(userDoctorRequest.DepartmentCustomId, 10, 64)
|
||||
departmentCustomId, err := strconv.ParseInt(putUserDoctorRequest.DepartmentCustomId, 10, 64)
|
||||
if err != nil {
|
||||
return false, errors.New("科室错误")
|
||||
}
|
||||
@ -64,7 +66,7 @@ func (r *UserDoctorService) PutUserDoctor(doctorId int64, userDoctorRequest requ
|
||||
if departmentCustomId == 0 && userDoctor.DepartmentCustomId != 0 {
|
||||
return false, errors.New("未选择新的科室")
|
||||
}
|
||||
if userDoctor.DepartmentCustomId != departmentCustomId || userDoctor.DepartmentCustomName != userDoctorRequest.DepartmentCustomName {
|
||||
if userDoctor.DepartmentCustomId != departmentCustomId || userDoctor.DepartmentCustomName != putUserDoctorRequest.DepartmentCustomName {
|
||||
// 获取科室数据
|
||||
hospitalDepartmentCustomDao := dao.HospitalDepartmentCustom{}
|
||||
hospitalDepartmentCustom, err := hospitalDepartmentCustomDao.GetHospitalDepartmentCustomById(departmentCustomId)
|
||||
@ -72,21 +74,21 @@ func (r *UserDoctorService) PutUserDoctor(doctorId int64, userDoctorRequest requ
|
||||
return false, errors.New("科室错误")
|
||||
}
|
||||
|
||||
userDoctorData["department_custom_id"] = userDoctorRequest.DepartmentCustomId
|
||||
userDoctorData["department_custom_id"] = putUserDoctorRequest.DepartmentCustomId
|
||||
userDoctorData["department_custom_name"] = hospitalDepartmentCustom.DepartmentCustomName
|
||||
|
||||
if userDoctorRequest.DepartmentCustomName != "" {
|
||||
userDoctorData["department_custom_name"] = userDoctorRequest.DepartmentCustomName
|
||||
if putUserDoctorRequest.DepartmentCustomName != "" {
|
||||
userDoctorData["department_custom_name"] = putUserDoctorRequest.DepartmentCustomName
|
||||
}
|
||||
}
|
||||
|
||||
// 处理科室电话
|
||||
if userDoctor.DepartmentCustomMobile != userDoctorRequest.DepartmentCustomMobile {
|
||||
userDoctorData["department_custom_id"] = userDoctorRequest.DepartmentCustomMobile
|
||||
if userDoctor.DepartmentCustomMobile != putUserDoctorRequest.DepartmentCustomMobile {
|
||||
userDoctorData["department_custom_id"] = putUserDoctorRequest.DepartmentCustomMobile
|
||||
}
|
||||
|
||||
// 处理医院
|
||||
hospitalId, err := strconv.ParseInt(userDoctorRequest.HospitalId, 10, 64)
|
||||
hospitalId, err := strconv.ParseInt(putUserDoctorRequest.HospitalId, 10, 64)
|
||||
if err != nil {
|
||||
return false, errors.New("科室错误")
|
||||
}
|
||||
@ -98,24 +100,24 @@ func (r *UserDoctorService) PutUserDoctor(doctorId int64, userDoctorRequest requ
|
||||
if err != nil || hospital == nil {
|
||||
return false, errors.New("医院错误")
|
||||
}
|
||||
userDoctorData["department_custom_id"] = userDoctorRequest.HospitalId
|
||||
userDoctorData["department_custom_id"] = putUserDoctorRequest.HospitalId
|
||||
}
|
||||
|
||||
// 处理擅长
|
||||
if userDoctor.BeGoodAt != userDoctorRequest.BeGoodAt {
|
||||
userDoctorData["be_good_at"] = userDoctorRequest.BeGoodAt
|
||||
if userDoctor.BeGoodAt != putUserDoctorRequest.BeGoodAt {
|
||||
userDoctorData["be_good_at"] = putUserDoctorRequest.BeGoodAt
|
||||
}
|
||||
|
||||
// 医生简介
|
||||
if userDoctor.BriefIntroduction != userDoctorRequest.BriefIntroduction {
|
||||
userDoctorData["brief_introduction"] = userDoctorRequest.BriefIntroduction
|
||||
if userDoctor.BriefIntroduction != putUserDoctorRequest.BriefIntroduction {
|
||||
userDoctorData["brief_introduction"] = putUserDoctorRequest.BriefIntroduction
|
||||
}
|
||||
|
||||
// 处理医师执业证
|
||||
var licenseCert string
|
||||
if len(userDoctorRequest.LicenseCert) > 0 {
|
||||
result := make([]string, len(userDoctorRequest.LicenseCert))
|
||||
for i, url := range userDoctorRequest.LicenseCert {
|
||||
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)
|
||||
}
|
||||
|
||||
@ -132,9 +134,9 @@ func (r *UserDoctorService) PutUserDoctor(doctorId int64, userDoctorRequest requ
|
||||
|
||||
// 处理医师资格证
|
||||
var qualificationCert string
|
||||
if len(userDoctorRequest.QualificationCert) > 0 {
|
||||
result := make([]string, len(userDoctorRequest.QualificationCert))
|
||||
for i, url := range userDoctorRequest.QualificationCert {
|
||||
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)
|
||||
}
|
||||
|
||||
@ -151,18 +153,18 @@ func (r *UserDoctorService) PutUserDoctor(doctorId int64, userDoctorRequest requ
|
||||
|
||||
// 处理医师资格证号
|
||||
if userDoctorInfo != nil {
|
||||
if userDoctorInfo.QualificationCertNum != userDoctorRequest.QualificationCertNum {
|
||||
userDoctorInfoData["qualification_cert_num"] = userDoctorRequest.QualificationCertNum
|
||||
if userDoctorInfo.QualificationCertNum != putUserDoctorRequest.QualificationCertNum {
|
||||
userDoctorInfoData["qualification_cert_num"] = putUserDoctorRequest.QualificationCertNum
|
||||
}
|
||||
} else {
|
||||
userDoctorInfoData["qualification_cert_num"] = userDoctorRequest.QualificationCertNum
|
||||
userDoctorInfoData["qualification_cert_num"] = putUserDoctorRequest.QualificationCertNum
|
||||
}
|
||||
|
||||
// 处理医师工作证
|
||||
var workCert string
|
||||
if len(userDoctorRequest.WorkCert) > 0 {
|
||||
result := make([]string, len(userDoctorRequest.WorkCert))
|
||||
for i, url := range userDoctorRequest.WorkCert {
|
||||
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)
|
||||
}
|
||||
|
||||
@ -178,34 +180,34 @@ func (r *UserDoctorService) PutUserDoctor(doctorId int64, userDoctorRequest requ
|
||||
}
|
||||
|
||||
// 处理身份证正面图片
|
||||
if userDoctorInfo.IdCardFront != "" && userDoctorRequest.IdCardFront == "" {
|
||||
if userDoctorInfo.IdCardFront != "" && putUserDoctorRequest.IdCardFront == "" {
|
||||
return false, errors.New("未上传新的身份证图片")
|
||||
}
|
||||
|
||||
if userDoctorRequest.IdCardFront != "" {
|
||||
idCardFront := strings.Replace(userDoctorRequest.IdCardFront, "https://img.applets.igandanyiyuan.com", "", 1)
|
||||
if putUserDoctorRequest.IdCardFront != "" {
|
||||
idCardFront := strings.Replace(putUserDoctorRequest.IdCardFront, "https://img.applets.igandanyiyuan.com", "", 1)
|
||||
if idCardFront != userDoctorInfo.IdCardFront {
|
||||
userDoctorInfoData["id_card_front"] = idCardFront
|
||||
}
|
||||
}
|
||||
|
||||
// 身份证背面图片
|
||||
if userDoctorInfo.IdCardBack != "" && userDoctorRequest.IdCardBack == "" {
|
||||
if userDoctorInfo.IdCardBack != "" && putUserDoctorRequest.IdCardBack == "" {
|
||||
return false, errors.New("未上传新的身份证图片")
|
||||
}
|
||||
if userDoctorRequest.IdCardBack != "" {
|
||||
idCardBack := strings.Replace(userDoctorRequest.IdCardBack, "https://img.applets.igandanyiyuan.com", "", 1)
|
||||
if putUserDoctorRequest.IdCardBack != "" {
|
||||
idCardBack := strings.Replace(putUserDoctorRequest.IdCardBack, "https://img.applets.igandanyiyuan.com", "", 1)
|
||||
if idCardBack != userDoctorInfo.IdCardBack {
|
||||
userDoctorInfoData["id_card_back"] = idCardBack
|
||||
}
|
||||
}
|
||||
|
||||
// 签名图片
|
||||
if userDoctorInfo.SignImage != "" && userDoctorRequest.SignImage == "" {
|
||||
if userDoctorInfo.SignImage != "" && putUserDoctorRequest.SignImage == "" {
|
||||
return false, errors.New("未上传新的签名图片")
|
||||
}
|
||||
if userDoctorRequest.SignImage != "" {
|
||||
signImage := strings.Replace(userDoctorRequest.SignImage, "https://img.applets.igandanyiyuan.com", "", 1)
|
||||
if putUserDoctorRequest.SignImage != "" {
|
||||
signImage := strings.Replace(putUserDoctorRequest.SignImage, "https://img.applets.igandanyiyuan.com", "", 1)
|
||||
if signImage != userDoctorInfo.SignImage {
|
||||
userDoctorInfoData["sign_image"] = signImage
|
||||
}
|
||||
@ -262,7 +264,7 @@ func (r *UserDoctorService) PutUserDoctor(doctorId int64, userDoctorRequest requ
|
||||
profileItem := []tencentIm.ProfileItem{
|
||||
{
|
||||
Tag: "Tag_Profile_IM_Image",
|
||||
Value: userDoctorRequest.Avatar,
|
||||
Value: putUserDoctorRequest.Avatar,
|
||||
},
|
||||
}
|
||||
res, err := tencentIm.SetProfile(strconv.FormatInt(userDoctor.UserId, 10), profileItem)
|
||||
@ -333,8 +335,8 @@ func (r *UserDoctorService) PutUserDoctor(doctorId int64, userDoctorRequest requ
|
||||
|
||||
// 判断签名图片是否修改,同步修改ca平台
|
||||
// 1、新用户,未存在证书
|
||||
if userDoctorRequest.SignImage != "" {
|
||||
signImage := strings.Replace(userDoctorRequest.SignImage, "https://img.applets.igandanyiyuan.com", "", 1)
|
||||
if putUserDoctorRequest.SignImage != "" {
|
||||
signImage := strings.Replace(putUserDoctorRequest.SignImage, "https://img.applets.igandanyiyuan.com", "", 1)
|
||||
if signImage != userDoctorInfo.SignImage {
|
||||
// 检测是否存在云证书
|
||||
userCaCertDao := dao.UserCaCert{}
|
||||
@ -379,6 +381,222 @@ func (r *UserDoctorService) PutUserDoctor(doctorId int64, userDoctorRequest requ
|
||||
}
|
||||
|
||||
// AddUserDoctor 新增医生
|
||||
func (r *UserDoctorService) AddUserDoctor(userDoctorRequest requests.AddUserDoctor) (bool, error) {
|
||||
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
|
||||
}
|
||||
|
||||
// 开始事务
|
||||
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,
|
||||
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,
|
||||
QualificationCertNum: a.QualificationCertNum,
|
||||
WorkCert: workCert,
|
||||
IdCardFront: idCardFront,
|
||||
IdCardBack: idCardBack,
|
||||
SignImage: signImage,
|
||||
}
|
||||
|
||||
userDoctorInfo, err = userDoctorInfoDao.AddUserDoctorInfo(tx, userDoctorInfo)
|
||||
if err != nil || userDoctor == nil {
|
||||
tx.Rollback()
|
||||
return false, err
|
||||
}
|
||||
|
||||
tx.Commit()
|
||||
return true, nil
|
||||
}
|
||||
|
||||
121
utils/idCard.go
Normal file
121
utils/idCard.go
Normal file
@ -0,0 +1,121 @@
|
||||
// Package utils 身份证处理
|
||||
package utils
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
// GetCardAge 获取身份证年龄
|
||||
func GetCardAge(cardNum string) (int, error) {
|
||||
// 获取当前时间
|
||||
now := time.Now()
|
||||
|
||||
// 解析身份证号中的出生日期
|
||||
birthDateStr := cardNum[6:14]
|
||||
birthYear, err := strconv.Atoi(birthDateStr[0:4])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
birthMonth, err := strconv.Atoi(birthDateStr[4:6])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
// 计算年龄
|
||||
age := now.Year() - birthYear
|
||||
if now.Month() < time.Month(birthMonth) {
|
||||
age--
|
||||
}
|
||||
|
||||
return age, nil
|
||||
}
|
||||
|
||||
// CheckCardNum 检测身份证号
|
||||
func CheckCardNum(cardNum string) (bool, error) {
|
||||
regex := `^(?:1[1-5]|2[1-3]|3[1-7]|4[1-6]|5[0-4]|6[1-5])\d{4}(?:1[89]|20)\d{2}(?:0[1-9]|1[0-2])(?:0[1-9]|[12]\d|3[01])\d{3}[\dxX]$`
|
||||
match, err := regexp.MatchString(regex, cardNum)
|
||||
if !match || err != nil {
|
||||
return false, errors.New("身份证号错误")
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// GetCardSex 获取身份证性别
|
||||
func GetCardSex(cardNum string) (int, error) {
|
||||
genderStr := cardNum[len(cardNum)-2 : len(cardNum)-1]
|
||||
genderNum, err := strconv.Atoi(genderStr)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
// 判断性别
|
||||
if genderNum%2 == 0 {
|
||||
return 2, nil
|
||||
} else {
|
||||
return 1, nil
|
||||
}
|
||||
}
|
||||
|
||||
// GetMaskCardNum 身份证号码脱敏
|
||||
func GetMaskCardNum(cardNum string) string {
|
||||
if len(cardNum) != 18 {
|
||||
return cardNum
|
||||
}
|
||||
|
||||
// 获取身份证号前后部分
|
||||
frontPart := cardNum[0:6]
|
||||
backPart := cardNum[14:]
|
||||
|
||||
// 替换中间部分数字为 *
|
||||
middlePart := "****"
|
||||
|
||||
// 拼接新的身份证号
|
||||
maskedIDCard := frontPart + middlePart + backPart
|
||||
|
||||
return maskedIDCard
|
||||
}
|
||||
|
||||
// GetMaskCardName 身份证名字脱敏
|
||||
func GetMaskCardName(cardName string) string {
|
||||
// 判断姓名长度
|
||||
length := utf8.RuneCountInString(cardName)
|
||||
|
||||
// 判断是否是英文姓名
|
||||
isEnglish := strings.ContainsAny(cardName, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
|
||||
|
||||
if length == 2 {
|
||||
// 两个字符的姓名
|
||||
if isEnglish {
|
||||
// 英文姓名
|
||||
return string(cardName[0]) + "*"
|
||||
} else {
|
||||
// 中文姓名
|
||||
return string([]rune(cardName)[0]) + "*"
|
||||
}
|
||||
} else if length == 3 {
|
||||
// 三个字符的姓名
|
||||
if isEnglish {
|
||||
// 英文姓名
|
||||
return string(cardName[0]) + "*" + string(cardName[2])
|
||||
} else {
|
||||
// 中文姓名
|
||||
return string([]rune(cardName)[0]) + "*" + string([]rune(cardName)[2])
|
||||
}
|
||||
} else if length >= 4 {
|
||||
// 四个及以上字符的姓名
|
||||
if isEnglish {
|
||||
// 英文姓名
|
||||
return string(cardName[0]) + "*" + string(cardName[length-1])
|
||||
} else {
|
||||
// 中文姓名
|
||||
return string([]rune(cardName)[0]) + "*" + string([]rune(cardName)[length-1])
|
||||
}
|
||||
}
|
||||
|
||||
return cardName
|
||||
}
|
||||
@ -4,7 +4,7 @@ import "regexp"
|
||||
|
||||
// RegexpMobile 手机号匹配
|
||||
func RegexpMobile(mobile string) bool {
|
||||
ok, err := regexp.MatchString(`^1[3-9][0-9]{9}$`, mobile)
|
||||
ok, err := regexp.MatchString(`^1(3\d|4[5-9]|5[0-35-9]|6[2567]|7[0-8]|8\d|9[0-35-9])\d{8}$`, mobile)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
11
utils/replace.go
Normal file
11
utils/replace.go
Normal file
@ -0,0 +1,11 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"hospital-admin-api/config"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// RemoveOssDomain 去除oss地址中的前缀
|
||||
func RemoveOssDomain(url string) string {
|
||||
return strings.Replace(url, config.C.Oss.OssCustomDomainName, "", 1)
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user