feat: hrm-views 修改employee 人员导入
This commit is contained in:
parent
743c724d79
commit
c3605ff1db
|
|
@ -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})
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue