药房下线(禁用/删除)医生分流迁移
This commit is contained in:
@@ -192,6 +192,44 @@ func (r *DoctorPharmacyDao) GetDoctorPharmacyCountsByPharmacyId(pharmacyId int64
|
||||
return totalCount, defaultCount, nil
|
||||
}
|
||||
|
||||
// GetOtherPharmaciesByDoctorIds 批量获取一组医生绑定的其他有效药房
|
||||
func (r *DoctorPharmacyDao) GetOtherPharmaciesByDoctorIds(doctorIds []int64, excludePharmacyId int64) (m []*model.DoctorPharmacy, err error) {
|
||||
if len(doctorIds) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
err = global.Db.Preload("Pharmacy").
|
||||
Where("doctor_id IN (?) AND status = 1 AND pharmacy_id != ?", doctorIds, excludePharmacyId).
|
||||
Order("is_default desc, created_at desc").
|
||||
Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// GORM 在外键为 0 时会自动跳过 Preload,因此针对未能预加载的记录进行兜底补全
|
||||
var zeroPharmacy *model.Pharmacy
|
||||
for _, dp := range m {
|
||||
if dp.Pharmacy == nil {
|
||||
if dp.PharmacyId == 0 {
|
||||
if zeroPharmacy == nil {
|
||||
var ph model.Pharmacy
|
||||
if err := global.Db.Where("pharmacy_id = 0").First(&ph).Error; err == nil {
|
||||
zeroPharmacy = &ph
|
||||
}
|
||||
}
|
||||
dp.Pharmacy = zeroPharmacy
|
||||
} else {
|
||||
var ph model.Pharmacy
|
||||
if err := global.Db.Where("pharmacy_id = ?", dp.PharmacyId).First(&ph).Error; err == nil {
|
||||
dp.Pharmacy = &ph
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetPharmacyDoctorExportListSearch 获取药房关联医生列表-导出
|
||||
func (r *DoctorPharmacyDao) GetPharmacyDoctorExportListSearch(req requests.PharmacyDoctorExportList) (m []*model.DoctorPharmacy, err error) {
|
||||
query := global.Db.Model(&model.DoctorPharmacy{}).
|
||||
|
||||
Reference in New Issue
Block a user