根据药房查询医生列表
This commit is contained in:
@@ -96,3 +96,52 @@ func (r *DoctorPharmacyDao) SetDefaultPharmacyById(tx *gorm.DB, doctorPharmacyId
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetPharmacyDoctorPageSearch 获取药房绑定的医生列表-分页
|
||||
func (r *DoctorPharmacyDao) GetPharmacyDoctorPageSearch(pharmacyId int64, req requests.GetPharmacyDoctorPage, page, pageSize int) (m []*model.DoctorPharmacy, total int64, err error) {
|
||||
var totalRecords int64
|
||||
|
||||
query := global.Db.Model(&model.DoctorPharmacy{}).
|
||||
Where("gdxz_doctor_pharmacy.pharmacy_id = ? AND gdxz_doctor_pharmacy.status = 1", pharmacyId)
|
||||
|
||||
// 如果有医生姓名或手机号筛选,做表连接
|
||||
needJoinDoctor := req.DoctorName != "" || req.Mobile != ""
|
||||
if needJoinDoctor {
|
||||
query = query.Joins("JOIN gdxz_user_doctor ON gdxz_user_doctor.doctor_id = gdxz_doctor_pharmacy.doctor_id")
|
||||
if req.DoctorName != "" {
|
||||
query = query.Where("gdxz_user_doctor.user_name LIKE ?", "%"+req.DoctorName+"%")
|
||||
}
|
||||
if req.Mobile != "" {
|
||||
query = query.Joins("JOIN gdxz_user ON gdxz_user.user_id = gdxz_user_doctor.user_id").
|
||||
Where("gdxz_user.mobile LIKE ?", "%"+req.Mobile+"%")
|
||||
}
|
||||
}
|
||||
|
||||
if err := query.Count(&totalRecords).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
err = query.Order("gdxz_doctor_pharmacy.is_default desc, gdxz_doctor_pharmacy.created_at desc").
|
||||
Preload("UserDoctor.User").
|
||||
Preload("UserDoctor.Hospital").
|
||||
Scopes(model.Paginate(page, pageSize)).
|
||||
Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
return m, totalRecords, nil
|
||||
}
|
||||
|
||||
// GetPharmacyDoctorListByPharmacyId 获取药房绑定的所有医生列表
|
||||
func (r *DoctorPharmacyDao) GetPharmacyDoctorListByPharmacyId(pharmacyId int64) (m []*model.DoctorPharmacy, err error) {
|
||||
err = global.Db.Preload("UserDoctor.User").
|
||||
Preload("UserDoctor.Hospital").
|
||||
Where("pharmacy_id = ? AND status = 1", pharmacyId).
|
||||
Order("is_default desc, created_at desc").
|
||||
Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user