Selaa lähdekoodia

修复名称空格问题

liuq 2 kuukautta sitten
vanhempi
commit
cd4480fcbd
2 muutettua tiedostoa jossa 20 lisäystä ja 9 poistoa
  1. 5 0
      backend/app/api/v1/endpoints/users.py
  2. 15 9
      backend/app/services/import_service.py

+ 5 - 0
backend/app/api/v1/endpoints/users.py

@@ -127,6 +127,10 @@ def create_user(
     if user_in.password:
         user_in.password = user_in.password.strip()
 
+    # Remove spaces from name
+    if user_in.name:
+        user_in.name = user_in.name.replace(" ", "")
+
     # Generate default name if missing
     if not user_in.name:
         random_suffix = security.generate_alphanumeric_password(6)
@@ -366,6 +370,7 @@ def update_user(
         
     # Auto-generate english_name if name changed and english_name not provided
     if "name" in update_data and update_data["name"]:
+        update_data["name"] = update_data["name"].replace(" ", "")
         if "english_name" not in update_data or not update_data["english_name"]:
              update_data["english_name"] = generate_english_name(update_data["name"])
 

+ 15 - 9
backend/app/services/import_service.py

@@ -96,17 +96,23 @@ class UserImportService:
         for index, row in df_data.iterrows():
             row_num = index + 1 # 1-based row number for display
             
+            # Extract Data first to check for empty rows
+            mobile_col = mapping.get("mobile")
+            name_col = mapping.get("name")
+            en_name_col = mapping.get("english_name")
+            
+            mobile = str(row[mobile_col]).strip() if mobile_col is not None and pd.notna(row[mobile_col]) else None
+            name = str(row[name_col]).strip() if name_col is not None and pd.notna(row[name_col]) else None
+            if name:
+                name = name.replace(" ", "")
+            en_name = str(row[en_name_col]).strip() if en_name_col is not None and pd.notna(row[en_name_col]) else None
+            
+            # Skip empty rows (often generated by Excel at the end)
+            if not mobile and not name and not en_name:
+                continue
+            
             try:
                 with db.begin_nested():
-                    # 1. Extract Data
-                    mobile_col = mapping.get("mobile")
-                    name_col = mapping.get("name")
-                    en_name_col = mapping.get("english_name")
-                    
-                    mobile = str(row[mobile_col]).strip() if mobile_col is not None and pd.notna(row[mobile_col]) else None
-                    name = str(row[name_col]).strip() if name_col is not None and pd.notna(row[name_col]) else None
-                    en_name = str(row[en_name_col]).strip() if en_name_col is not None and pd.notna(row[en_name_col]) else None
-                    
                     if not mobile:
                         raise ValueError("Mobile is required")