新增问诊管理-问诊配置-医生问诊配置-获取开启问诊配置医生列表-分页接口
This commit is contained in:
@@ -3,6 +3,7 @@ package dao
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"hospital-admin-api/api/model"
|
||||
"hospital-admin-api/api/requests"
|
||||
"hospital-admin-api/global"
|
||||
)
|
||||
|
||||
@@ -61,3 +62,73 @@ func (r *DoctorInquiryConfigDao) GetDoctorInquiryConfig(maps interface{}) (m *mo
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetUserDoctorPageSearch 获取医生列表-分页
|
||||
func (r *DoctorInquiryConfigDao) GetUserDoctorPageSearch(req requests.GetDoctorInquiryConfigPage, page, pageSize int) (m []*model.DoctorInquiryConfig, total int64, err error) {
|
||||
var totalRecords int64
|
||||
|
||||
// 构建查询条件
|
||||
query := global.Db.Model(&model.DoctorInquiryConfig{})
|
||||
|
||||
// 医生
|
||||
query = query.Preload("UserDoctor", func(db *gorm.DB) *gorm.DB {
|
||||
return db.Omit("open_id", "union_id", "wx_session_key")
|
||||
})
|
||||
|
||||
// 用户表
|
||||
query = query.Preload("UserDoctor.User", func(db *gorm.DB) *gorm.DB {
|
||||
return db.Omit("user_password", "salt")
|
||||
})
|
||||
|
||||
// 手机号
|
||||
if req.Mobile != "" {
|
||||
// 医生
|
||||
doctorUserSubQuery := global.Db.Model(&model.User{}).
|
||||
Select("user_id").
|
||||
Where("mobile = ?", req.Mobile)
|
||||
|
||||
doctorSubQuery := global.Db.Model(&model.UserDoctor{}).
|
||||
Select("doctor_id").
|
||||
Where(gorm.Expr("user_id IN (?)", doctorUserSubQuery))
|
||||
|
||||
query = query.Where("doctor_id IN (?)", doctorSubQuery)
|
||||
}
|
||||
|
||||
// 医生姓名
|
||||
if req.DoctorName != "" {
|
||||
subQuery := global.Db.Model(&model.UserDoctor{}).
|
||||
Select("doctor_id").
|
||||
Where("user_name LIKE ?", "%"+req.DoctorName+"%")
|
||||
|
||||
query = query.Where("doctor_id IN (?)", subQuery)
|
||||
}
|
||||
|
||||
// 问诊类型
|
||||
if req.InquiryType != nil {
|
||||
query = query.Where("inquiry_type = ?", req.InquiryType)
|
||||
}
|
||||
|
||||
// 问诊方式
|
||||
if req.InquiryMode != nil {
|
||||
query = query.Where("inquiry_mode = ?", req.InquiryMode)
|
||||
}
|
||||
|
||||
// 是否启用
|
||||
if req.IsEnable != nil {
|
||||
query = query.Where("is_enable = ?", req.IsEnable)
|
||||
}
|
||||
|
||||
// 排序
|
||||
query = query.Order("created_at desc")
|
||||
|
||||
// 查询总数量
|
||||
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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user