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
+87
View File
@@ -380,6 +380,21 @@ type ProductData struct {
CreatedAt string // 创建时间
}
// PharmacyDoctorData 药房关联医生
type PharmacyDoctorData struct {
PharmacyName string // 药房名称
PharmacyCode string // 药房代码
DoctorName string // 医生姓名
Mobile string // 手机号
DoctorTitle string // 医生职称
HospitalName string // 医院名称
DepartmentCustomName string // 科室名称
DepartmentCustomMobile string // 科室电话
IsDefault string // 是否默认药房(0:否 1:是)
Status string // 状态(0:禁用 1:正常)
CreatedAt string // 关联时间
}
// DoctorWithdrawal 提现记录
func (r *ExportService) DoctorWithdrawal(doctorWithdrawals []*model.DoctorWithdrawal) (string, error) {
header := []utils.HeaderCellData{
@@ -2052,3 +2067,75 @@ func (r *ExportService) Product(d []*model.Product) (string, error) {
ossPath = utils.AddOssDomain("/" + ossPath)
return ossPath, nil
}
// PharmacyDoctor 药房关联医生
func (r *ExportService) PharmacyDoctor(d []*model.DoctorPharmacy) (string, error) {
header := []utils.HeaderCellData{
{Value: "药房名称", CellType: "string", NumberFmt: "", ColWidth: 25},
{Value: "药房代码", CellType: "string", NumberFmt: "", ColWidth: 18},
{Value: "医生姓名", CellType: "string", NumberFmt: "", ColWidth: 18},
{Value: "手机号", CellType: "string", NumberFmt: "", ColWidth: 18},
{Value: "医生职称", CellType: "string", NumberFmt: "", ColWidth: 18},
{Value: "医院名称", CellType: "string", NumberFmt: "", ColWidth: 30},
{Value: "科室名称", CellType: "string", NumberFmt: "", ColWidth: 20},
{Value: "科室电话", CellType: "string", NumberFmt: "", ColWidth: 18},
{Value: "是否默认药房", CellType: "string", NumberFmt: "", ColWidth: 18},
{Value: "状态", CellType: "string", NumberFmt: "", ColWidth: 15},
{Value: "关联时间", CellType: "date", NumberFmt: "yyyy-mm-dd hh:mm:ss", ColWidth: 30},
}
var dataSlice []interface{}
for _, v := range d {
data := PharmacyDoctorData{
IsDefault: utils.IsDefaultToString(v.IsDefault),
Status: "正常",
}
if v.Status == 0 {
data.Status = "禁用"
}
if v.Pharmacy != nil {
data.PharmacyName = v.Pharmacy.PharmacyName
data.PharmacyCode = v.Pharmacy.PharmacyCode
}
if v.UserDoctor != nil {
data.DoctorName = v.UserDoctor.UserName
data.DoctorTitle = utils.DoctorTitleToString(v.UserDoctor.DoctorTitle)
data.DepartmentCustomName = v.UserDoctor.DepartmentCustomName
data.DepartmentCustomMobile = v.UserDoctor.DepartmentCustomMobile
if v.UserDoctor.Hospital != nil {
data.HospitalName = v.UserDoctor.Hospital.HospitalName
}
if v.UserDoctor.User != nil {
data.Mobile = v.UserDoctor.User.Mobile
}
}
if v.CreatedAt != (model.LocalTime{}) {
data.CreatedAt = time.Time(v.CreatedAt).Format("2006-01-02 15:04:05")
}
dataSlice = append(dataSlice, data)
}
file, err := utils.Export(header, dataSlice)
if err != nil {
return "", err
}
// 设置文件名字
now := time.Now()
dateTimeString := now.Format("20060102150405") // 当前时间字符串
rand.New(rand.NewSource(time.Now().UnixNano())) // 设置随机数
ossPath := "admin/export/药房关联医生" + dateTimeString + fmt.Sprintf("%d", rand.Intn(9000)+1000) + ".xlsx"
// 上传oss
_, err = aliyun.PutObjectByte(ossPath, file.Bytes())
if err != nil {
return "", err
}
ossPath = utils.AddOssDomain("/" + ossPath)
return ossPath, nil
}
+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 {