瀏覽代碼

no message

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['职务'],