libushang преди 9 месеца
родител
ревизия
65c80e3969
променени са 2 файла, в които са добавени 13 реда и са изтрити 1 реда
  1. 8 1
      common/db/db_dept.py
  2. 5 0
      routers/api/emergencyPlans/contact.py

+ 8 - 1
common/db/db_dept.py

@@ -13,4 +13,11 @@ def get_dept_name_by_id(db: Session, dept_id: int) -> str:
     if row is not None:
         return row.dept_name
     
-    return ""
+    return ""
+
+def get_dept_id_by_name(db: Session, dept_name: str) -> int:
+    row = db.query(SysDept).filter(SysDept.dept_name == dept_name).first()
+    if row is not None:
+        return row.dept_id
+    
+    return 0

+ 5 - 0
routers/api/emergencyPlans/contact.py

@@ -370,7 +370,12 @@ async def create_contact(
 
         # 创建新的预案记录
         for contact in infos:
+            unit_id = db_dept.get_dept_id_by_name(db, contact['单位名称'])
+            if unit_id == '':
+                raise Exception('单位名称不正确')
+        
             new_contact = EmergencyContactInfo(
+                unit_id=unit_id,
                 unit_name=contact['单位名称'],
                 contact_name = contact['联系人'],
                 position = contact['职务'],