239 lines
6.2 KiB
Go
239 lines
6.2 KiB
Go
package dao
|
|
|
|
import (
|
|
"gorm.io/gorm"
|
|
"gorm.io/gorm/clause"
|
|
"hospital-open-api/api/model"
|
|
requestsV1 "hospital-open-api/api/requests/v1"
|
|
"hospital-open-api/global"
|
|
"strings"
|
|
)
|
|
|
|
type UserDoctorDao struct {
|
|
}
|
|
|
|
// GetUserDoctorById 获取医生数据-医生id
|
|
func (r *UserDoctorDao) GetUserDoctorById(doctorId int64) (m *model.UserDoctor, err error) {
|
|
err = global.Db.First(&m, doctorId).Error
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return m, nil
|
|
}
|
|
|
|
// GetUserDoctorPreloadById 获取医生数据-加载全部关联-医生id
|
|
func (r *UserDoctorDao) GetUserDoctorPreloadById(doctorId int64) (m *model.UserDoctor, err error) {
|
|
err = global.Db.Preload(clause.Associations).First(&m, doctorId).Error
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return m, nil
|
|
}
|
|
|
|
// GetMultiUserDoctor 获取多点医生详情
|
|
func (r *UserDoctorDao) GetMultiUserDoctor(req requestsV1.GetMultiDoctor) (m *model.UserDoctor, err error) {
|
|
// 构建查询条件
|
|
query := global.Db.Model(&model.UserDoctor{}).Omit("open_id", "union_id", "wx_session_key")
|
|
|
|
// 用户
|
|
query = query.Preload("User", func(db *gorm.DB) *gorm.DB {
|
|
return db.Omit("user_password", "salt")
|
|
})
|
|
|
|
// 医院
|
|
query = query.Preload("Hospital", func(db *gorm.DB) *gorm.DB {
|
|
return db.Select("hospital_id,hospital_name,hospital_level_name")
|
|
})
|
|
|
|
// 问诊配置
|
|
query = query.Preload("DoctorInquiryConfig")
|
|
|
|
// 状态
|
|
query = query.Where("status = ?", 1)
|
|
|
|
// 实名认证状态
|
|
query = query.Where("idcard_status = ?", 1)
|
|
|
|
// 身份认证状态
|
|
query = query.Where("iden_auth_status = ?", 1)
|
|
|
|
// 是否已绑定结算银行卡
|
|
query = query.Where("is_bind_bank = ?", 1)
|
|
|
|
// 姓名
|
|
if req.UserName != "" {
|
|
query = query.Where("user_name = ?", req.UserName)
|
|
}
|
|
|
|
// 手机号
|
|
if req.Mobile != "" {
|
|
subQuery := global.Db.Model(&model.User{}).
|
|
Select("user_id").
|
|
Where("mobile = ?", req.Mobile)
|
|
|
|
query = query.Where(gorm.Expr("user_id IN (?)", subQuery))
|
|
}
|
|
|
|
err = query.First(&m).Error
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return m, nil
|
|
}
|
|
|
|
// GetUserDoctor 获取医生详情
|
|
func (r *UserDoctorDao) GetUserDoctor(req requestsV1.GetDoctor) (m *model.UserDoctor, err error) {
|
|
// 构建查询条件
|
|
query := global.Db.Model(&model.UserDoctor{}).Omit("open_id", "union_id", "wx_session_key")
|
|
|
|
// 用户
|
|
query = query.Preload("User", func(db *gorm.DB) *gorm.DB {
|
|
return db.Omit("user_password", "salt")
|
|
})
|
|
|
|
// 医院
|
|
query = query.Preload("Hospital", func(db *gorm.DB) *gorm.DB {
|
|
return db.Select("hospital_id,hospital_name,hospital_level_name")
|
|
})
|
|
|
|
// 问诊配置
|
|
query = query.Preload("DoctorInquiryConfig")
|
|
|
|
// 状态
|
|
query = query.Where("status = ?", 1)
|
|
|
|
// 实名认证状态
|
|
query = query.Where("idcard_status = ?", 1)
|
|
|
|
// 身份认证状态
|
|
query = query.Where("iden_auth_status = ?", 1)
|
|
|
|
// 是否已绑定结算银行卡
|
|
query = query.Where("is_bind_bank = ?", 1)
|
|
|
|
// 姓名
|
|
if req.UserName != "" {
|
|
query = query.Where("user_name = ?", req.UserName)
|
|
}
|
|
|
|
// 手机号
|
|
if req.Mobile != "" {
|
|
subQuery := global.Db.Model(&model.User{}).
|
|
Select("user_id").
|
|
Where("mobile = ?", req.Mobile)
|
|
|
|
query = query.Where(gorm.Expr("user_id IN (?)", subQuery))
|
|
}
|
|
|
|
err = query.First(&m).Error
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return m, nil
|
|
}
|
|
|
|
// GetUserDoctorPageSearch 获取医生列表-分页
|
|
func (r *UserDoctorDao) GetUserDoctorPageSearch(req requestsV1.GetUserDoctorPage, page, pageSize int) (m []*model.UserDoctor, total int64, err error) {
|
|
var totalRecords int64
|
|
|
|
// 构建查询条件
|
|
query := global.Db.Model(&model.UserDoctor{}).Omit("open_id", "union_id", "wx_session_key")
|
|
|
|
query = query.Where("status = ?", 1)
|
|
query = query.Where("idcard_status = ?", 1)
|
|
query = query.Where("iden_auth_status = ?", 1)
|
|
query = query.Where("is_bind_bank = ?", 1)
|
|
|
|
// 用户
|
|
query = query.Preload("User", func(db *gorm.DB) *gorm.DB {
|
|
return db.Omit("user_password", "salt")
|
|
})
|
|
|
|
// 医院
|
|
query = query.Preload("Hospital", func(db *gorm.DB) *gorm.DB {
|
|
return db.Select("hospital_id,hospital_name,hospital_level_name")
|
|
})
|
|
|
|
// 医生问诊配置
|
|
query = query.Preload("DoctorInquiryConfig")
|
|
|
|
// 医生问诊配置
|
|
if req.InquiryType != "" && req.InquiryMode != "" {
|
|
inquiryType := strings.Split(req.InquiryType, ",")
|
|
inquiryMode := strings.Split(req.InquiryMode, ",")
|
|
|
|
if len(inquiryType) > 0 {
|
|
subQuery := global.Db.Model(&model.DoctorInquiryConfig{}).
|
|
Where("gdxz_doctor_inquiry_config.doctor_id = gdxz_user_doctor.doctor_id").
|
|
Where("gdxz_doctor_inquiry_config.inquiry_type IN (?)", inquiryType).
|
|
Where("gdxz_doctor_inquiry_config.inquiry_mode IN (?)", inquiryMode).
|
|
Where("gdxz_doctor_inquiry_config.is_enable = ?", 1).Select("1")
|
|
|
|
query = query.Where("EXISTS (?)", subQuery)
|
|
}
|
|
}
|
|
|
|
// 手机号
|
|
if req.Mobile != "" {
|
|
subQuery := global.Db.Model(&model.User{}).
|
|
Select("user_id").
|
|
Where("mobile LIKE ?", "%"+req.Mobile+"%")
|
|
|
|
query = query.Where(gorm.Expr("user_id IN (?)", subQuery))
|
|
}
|
|
|
|
// 用户名称
|
|
if req.UserName != "" {
|
|
query = query.Where("user_name LIKE ?", "%"+req.UserName+"%")
|
|
}
|
|
|
|
// 医院名称
|
|
if req.HospitalName != "" {
|
|
subQuery := global.Db.Model(&model.Hospital{}).
|
|
Select("hospital_id").
|
|
Where("hospital_name LIKE ?", "%"+req.HospitalName+"%")
|
|
|
|
query = query.Where(gorm.Expr("hospital_id IN (?)", subQuery))
|
|
}
|
|
|
|
// 科室名称
|
|
if req.DepartmentCustomName != "" {
|
|
query = query.Where("department_custom_name = ?", req.DepartmentCustomName)
|
|
}
|
|
|
|
// 是否首页推荐
|
|
if req.IsRecommend != nil {
|
|
query = query.Where("is_recommend = ?", req.IsRecommend)
|
|
}
|
|
|
|
if req.DoctorTitle != nil {
|
|
query = query.Where("doctor_title = ?", req.DoctorTitle)
|
|
}
|
|
|
|
// 排序
|
|
query = query.Order("created_at desc")
|
|
|
|
if req.IsEnterpriseDeepCooperation != nil {
|
|
query = query.Where("is_enterprise_deep_cooperation = ?", req.IsEnterpriseDeepCooperation)
|
|
}
|
|
|
|
if req.IsPlatformDeepCooperation != nil {
|
|
query = query.Where("is_platform_deep_cooperation = ?", req.IsPlatformDeepCooperation)
|
|
}
|
|
|
|
if req.IsSysDiagnoCooperation != nil {
|
|
query = query.Where("is_sys_diagno_cooperation = ?", req.IsSysDiagnoCooperation)
|
|
}
|
|
|
|
// 查询总数量
|
|
if err := query.Count(&totalRecords).Error; err != nil {
|
|
return nil, 0, err
|
|
}
|
|
|
|
err = query.Scopes(model.Paginate(page, pageSize)).Find(&m).Error
|
|
if err != nil {
|
|
return nil, 0, err
|
|
}
|
|
return m, totalRecords, nil
|
|
}
|