feat: 上传目录加入 issueDescription,Quote & Chassis 同时上传到自己目录

This commit is contained in:
afei A
2026-03-19 11:16:17 +08:00
parent b95fb23b3b
commit 1edabd6d3b

View File

@@ -305,21 +305,19 @@ def dsm_upload_downloaded_files(downloaded_files, ticket_id, serial_id, json_mod
print(f" DSM 登录失败: {e}", file=sys.stderr) print(f" DSM 登录失败: {e}", file=sys.stderr)
return [{"error": f"DSM 登录失败: {e}"}] return [{"error": f"DSM 登录失败: {e}"}]
def _upload_one(f): # 找出其他 issue 的 ID 列表(排除 "Quote & Chassis" issue
local_path = f["savedPath"] 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) 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}" full_remote_path = f"{remote_path}/{filename}"
entry = { entry = {
"file": filename, "file": filename,
"ticketId": ticket_id, "ticketId": ticket_id,
"serialId": serial_id, "serialId": serial_id,
"issueId": issue_id,
"remotePath": full_remote_path, "remotePath": full_remote_path,
} }
try: try:
@@ -336,8 +334,37 @@ def dsm_upload_downloaded_files(downloaded_files, ticket_id, serial_id, json_mod
print(f" 上传失败: {filename}: {e}") print(f" 上传失败: {filename}: {e}")
return entry 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: 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: if not json_mode:
ok = sum(1 for r in upload_results if r.get("success")) 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", f"{cfg.odata_cust}/BO_XSRIssueItemAttachmentFolderCollection",
json_mode, json_mode,
) )
for e in downloaded_entries:
e["issueDescription"] = issue_desc
return issue_entry, downloaded_entries return issue_entry, downloaded_entries