feat: cms softdelet bug fix
This commit is contained in:
@@ -172,14 +172,15 @@ class CmsDepartmentViewSet(viewsets.ModelViewSet):
|
||||
except Exception:
|
||||
raise AppError('CMS_IMPORT_BAD_FILE', '文件解析失败,请使用导入模板', status_code=400)
|
||||
|
||||
existing = set(Department.objects.values_list('name', flat=True))
|
||||
# 含已停用科室:避免导入与软删科室同名而产生重复行
|
||||
existing = set(Department.all_objects.values_list('name', flat=True))
|
||||
success, errors = 0, []
|
||||
for idx, row in enumerate(rows, start=2):
|
||||
name = (row.get('科室名称') or '').strip()
|
||||
if not name:
|
||||
errors.append({'row': idx, 'reason': '科室名称为空'}); continue
|
||||
if name in existing:
|
||||
errors.append({'row': idx, 'reason': f'科室已存在:{name}'}); continue
|
||||
errors.append({'row': idx, 'reason': f'科室已存在(含已停用):{name}'}); continue
|
||||
Department.objects.create(name=name, category=(row.get('分类') or '').strip())
|
||||
existing.add(name)
|
||||
success += 1
|
||||
|
||||
Reference in New Issue
Block a user