1、增加导出药房关联医生列表导出

2、检测到有绑定/默认医生时直接报错,强制要求管理员先手动处理;
This commit is contained in:
haomingming
2026-09-16 17:21:31 +08:00
parent 3f5807aad2
commit b349acb4b4
6 changed files with 297 additions and 7 deletions
+37
View File
@@ -109,6 +109,18 @@ func (r *PharmacyService) PutPharmacy(pharmacyId int64, req requests.PutPharmacy
}
}
// 若修改为禁用,校验是否有医生设为默认药房
if req.Status != nil && *req.Status == 0 && pharmacy.Status == 1 {
doctorPharmacyDao := dao.DoctorPharmacyDao{}
totalCount, defaultCount, err := doctorPharmacyDao.GetDoctorPharmacyCountsByPharmacyId(pharmacyId)
if err != nil {
return false, errors.New("查询药房关联医生失败")
}
if defaultCount > 0 {
return false, fmt.Errorf("该药房已被 %d 位医生设为默认药房(共 %d 位医生绑定),无法禁用。请先在【药房关联医生】中调整默认药房或解除绑定后再试", defaultCount, totalCount)
}
}
tx := global.Db.Begin()
defer func() {
if rec := recover(); rec != nil {
@@ -201,6 +213,18 @@ func (r *PharmacyService) PutPharmacyStatus(pharmacyId int64, req requests.PutPh
return false, errors.New("药房不存在或已删除")
}
// 若修改为禁用,校验是否有医生设为默认药房
if req.Status != nil && *req.Status == 0 {
doctorPharmacyDao := dao.DoctorPharmacyDao{}
totalCount, defaultCount, err := doctorPharmacyDao.GetDoctorPharmacyCountsByPharmacyId(pharmacyId)
if err != nil {
return false, errors.New("查询药房关联医生失败")
}
if defaultCount > 0 {
return false, fmt.Errorf("该药房已被 %d 位医生设为默认药房(共 %d 位医生绑定),无法禁用。请先在【药房关联医生】中调整默认药房或解除绑定后再试", defaultCount, totalCount)
}
}
data := map[string]interface{}{
"status": *req.Status,
}
@@ -230,6 +254,19 @@ func (r *PharmacyService) DeletePharmacy(pharmacyId int64) (bool, error) {
return false, errors.New("药房不存在或已删除")
}
// 删除药房前校验:若有关联医生(特别是默认药房),拦截禁止删除
doctorPharmacyDao := dao.DoctorPharmacyDao{}
totalCount, defaultCount, err := doctorPharmacyDao.GetDoctorPharmacyCountsByPharmacyId(pharmacyId)
if err != nil {
return false, errors.New("查询药房关联医生失败")
}
if defaultCount > 0 {
return false, fmt.Errorf("该药房已被 %d 位医生设为默认药房(共 %d 位医生绑定),无法删除。请先在【药房关联医生】中调整默认药房或解除绑定后再试", defaultCount, totalCount)
}
if totalCount > 0 {
return false, fmt.Errorf("该药房仍有 %d 位医生绑定,无法删除。请先在【药房关联医生】中解除绑定后再试", totalCount)
}
tx := global.Db.Begin()
defer func() {
if rec := recover(); rec != nil {