feat: hrm-views 修改employee 人员导入

This commit is contained in:
TianyangZhang 2026-03-04 13:56:00 +08:00
parent 743c724d79
commit c3605ff1db
1 changed files with 9 additions and 8 deletions

View File

@ -311,11 +311,12 @@ class EmployeeViewSet(CustomModelViewSet):
@action(methods=['post'], detail=False, perms_map={'post': 'employee.import_excel'},
serializer_class=serializers.Serializer)
def import_excel(self, request, pk=None):
import logging
myLogger = logging.getLogger('log')
"""导入excel"""
file_path = request.data.get('file_path')
if file_path:
file_path = r"C:\Users\11825\Desktop\0303光芯花名册.xlsx"
# if file_path:
# file_path = r"C:\Users\11825\Desktop\0303光芯花名册.xlsx"
abs_path = os.path.join(settings.BASE_DIR, file_path)
wb = load_workbook(abs_path, data_only=True)
sheet = wb.active
@ -363,7 +364,7 @@ class EmployeeViewSet(CustomModelViewSet):
if not id_number or not name:
raise ParseError(f'{row_num}行,身份证号或姓名为空')
print(f"处理第{row_num}行:{name} - {id_number}")
myLogger.info(f"处理第{row_num}行:{name} - {id_number}")
# 处理人员类型
if 'type' in data and data['type']:
excel_type = data['type']
@ -398,18 +399,18 @@ class EmployeeViewSet(CustomModelViewSet):
except Exception as e:
raise
if created:
print(f"✅ 第{row_num}行新增成功:{name}")
myLogger.info(f"✅ 第{row_num}行新增成功:{name}")
else:
print(f"✅ 第{row_num}行更新成功:{name}")
myLogger.info(f"✅ 第{row_num}行更新成功:{name}")
success += 1
except Exception as e:
error_msg = f'{row_num}行处理失败:{str(e)}'
print(f"{error_msg}")
myLogger.error(f"{error_msg}")
errors.append({'row': row_num, 'error': str(e)})
print(f"\n处理完成:成功{success}条,失败{len(errors)}")
myLogger.info(f"\n处理完成:成功{success}条,失败{len(errors)}")
return Response({'success': success, 'errors': errors})