From 1edabd6d3b7753c6e49d9cf356537acf7fa15495 Mon Sep 17 00:00:00 2001 From: afei A <57030625+NewHubBoy@users.noreply.github.com> Date: Thu, 19 Mar 2026 11:16:17 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=B8=8A=E4=BC=A0=E7=9B=AE=E5=BD=95?= =?UTF-8?q?=E5=8A=A0=E5=85=A5=20issueDescription=EF=BC=8CQuote=20&=20Chass?= =?UTF-8?q?is=20=E5=90=8C=E6=97=B6=E4=B8=8A=E4=BC=A0=E5=88=B0=E8=87=AA?= =?UTF-8?q?=E5=B7=B1=E7=9B=AE=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sap-c4c-AttachmentFolder.py | 49 +++++++++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 10 deletions(-) diff --git a/sap-c4c-AttachmentFolder.py b/sap-c4c-AttachmentFolder.py index 2fdb308..b820905 100644 --- a/sap-c4c-AttachmentFolder.py +++ b/sap-c4c-AttachmentFolder.py @@ -305,21 +305,19 @@ def dsm_upload_downloaded_files(downloaded_files, ticket_id, serial_id, json_mod print(f" DSM 登录失败: {e}", file=sys.stderr) return [{"error": f"DSM 登录失败: {e}"}] - def _upload_one(f): - local_path = f["savedPath"] + # 找出其他 issue 的 ID 列表(排除 "Quote & Chassis" issue) + other_issue_ids = list({ + f["issueId"] for f in files_to_upload + if f.get("issueId") and "Quote & Chassis" not in (f.get("issueDescription") or "") + }) + + def _upload_one(local_path, remote_path): filename = os.path.basename(local_path) - issue_id = f.get("issueId", "") - remote_path = ( - f"{cfg.dsm_path}/{folder_name}/{issue_id}" - if issue_id else - f"{cfg.dsm_path}/{folder_name}" - ) full_remote_path = f"{remote_path}/{filename}" entry = { "file": filename, "ticketId": ticket_id, "serialId": serial_id, - "issueId": issue_id, "remotePath": full_remote_path, } try: @@ -336,8 +334,37 @@ def dsm_upload_downloaded_files(downloaded_files, ticket_id, serial_id, json_mod print(f" 上传失败: {filename}: {e}") return entry + # 构建上传任务列表 + # 构建 issue_id -> issue 文件夹名 的映射 + issue_folder_map = {} + for f in files_to_upload: + oid = f.get("issueId", "") + if oid and oid not in issue_folder_map: + desc = f.get("issueDescription", "") + issue_folder_map[oid] = f"{oid}_{desc}" if desc else oid + + upload_tasks = [] + for f in files_to_upload: + local_path = f["savedPath"] + issue_id = f.get("issueId", "") + issue_desc = f.get("issueDescription", "") + issue_folder = issue_folder_map.get(issue_id, issue_id) + if "Quote & Chassis" in (issue_desc or ""): + # 上传到自己的目录 + upload_tasks.append((local_path, f"{cfg.dsm_path}/{folder_name}/{issue_folder}")) + # 同时分发到所有其他 issue 目录 + for oid in other_issue_ids: + upload_tasks.append((local_path, f"{cfg.dsm_path}/{folder_name}/{issue_folder_map.get(oid, oid)}")) + else: + remote_path = ( + f"{cfg.dsm_path}/{folder_name}/{issue_folder}" + if issue_id else + f"{cfg.dsm_path}/{folder_name}" + ) + upload_tasks.append((local_path, remote_path)) + with ThreadPoolExecutor(max_workers=cfg.max_workers) as executor: - upload_results = list(executor.map(_upload_one, files_to_upload)) + upload_results = list(executor.map(lambda t: _upload_one(*t), upload_tasks)) if not json_mode: ok = sum(1 for r in upload_results if r.get("success")) @@ -513,6 +540,8 @@ def _process_issue_item(session, item, list_only, json_mode): f"{cfg.odata_cust}/BO_XSRIssueItemAttachmentFolderCollection", json_mode, ) + for e in downloaded_entries: + e["issueDescription"] = issue_desc return issue_entry, downloaded_entries