加入导出案件日志功能
This commit is contained in:
@@ -5189,59 +5189,13 @@ class ExportCaseLogExcel(APIView):
|
||||
if not logs.exists():
|
||||
return Response({'status': 'error', 'message': '该案件没有日志记录', 'code': 1}, status=status.HTTP_404_NOT_FOUND)
|
||||
|
||||
# 解析案件负责人信息
|
||||
responsiblefor_info = ""
|
||||
if case.responsiblefor:
|
||||
try:
|
||||
resp_data = json.loads(case.responsiblefor) if isinstance(case.responsiblefor, str) else case.responsiblefor
|
||||
if isinstance(resp_data, dict):
|
||||
parts = []
|
||||
for key, label in [('responsible_person', '承办人'), ('main_lawyer', '主办律师'),
|
||||
('assist_lawyer', '协办律师'), ('trainee_lawyer', '实习律师'), ('secretary', '秘书/助理')]:
|
||||
if resp_data.get(key):
|
||||
parts.append(f"{label}:{resp_data.get(key)}")
|
||||
responsiblefor_info = ";".join(parts)
|
||||
except:
|
||||
responsiblefor_info = str(case.responsiblefor) if case.responsiblefor else ""
|
||||
|
||||
# 获取案件标签
|
||||
tags_str = ""
|
||||
try:
|
||||
tags_str = "、".join(case.tags.filter(is_deleted=False).values_list('name', flat=True))
|
||||
except:
|
||||
pass
|
||||
|
||||
# 构建Excel数据
|
||||
# 构建Excel数据(只保留:记录人、记录时间、工作内容)
|
||||
excel_data = []
|
||||
for log in logs:
|
||||
# 解析附件
|
||||
file_info = ""
|
||||
if log.file:
|
||||
try:
|
||||
files = json.loads(log.file) if isinstance(log.file, str) else log.file
|
||||
if isinstance(files, list):
|
||||
file_info = ";".join([f.get('name', f.get('url', '')) if isinstance(f, dict) else str(f) for f in files])
|
||||
except:
|
||||
file_info = str(log.file) if log.file else ""
|
||||
|
||||
excel_data.append({
|
||||
'日志ID': log.id,
|
||||
'合同编号': case.contract_no or '',
|
||||
'项目类型': case.project_type or '',
|
||||
'客户名称': case.client_name or '',
|
||||
'相对方名称': case.party_name or '',
|
||||
'项目简述': case.project_description or '',
|
||||
'负责人信息': responsiblefor_info,
|
||||
'收费情况': case.charge or '',
|
||||
'立案时间': case.times or '',
|
||||
'案件状态': case.state or '',
|
||||
'案件标签': tags_str,
|
||||
'已开票金额': case.invoice_status or '0',
|
||||
'已收款金额': case.paymentcollection or '0',
|
||||
'日志内容': log.content or '',
|
||||
'记录时间': log.times or '',
|
||||
'记录人': log.username or '',
|
||||
'附件': file_info,
|
||||
'记录时间': log.times or '',
|
||||
'工作内容': log.content or '',
|
||||
})
|
||||
|
||||
# 生成Excel文件
|
||||
|
||||
Reference in New Issue
Block a user