From f01cd9ec71d6081380c24bb4d7aaf5828861ca24 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=88=98=E6=B3=89=E4=BD=B3?= <1107186916@qq.com>
Date: Sun, 27 Sep 2026 22:47:40 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20HCS=E4=B8=BB=E6=95=B0=E6=8D=AE=E7=BC=93?=
=?UTF-8?q?=E5=AD=98=E4=B8=8E=E9=99=84=E4=BB=B6=E8=BD=AC=E4=BC=A0=E6=94=AF?=
=?UTF-8?q?=E6=92=91=EF=BC=88C103-6/7/12=E6=A8=A1=E6=9D=BF=E5=88=86?=
=?UTF-8?q?=E7=B1=BB=E5=B8=81=E7=A7=8D=E7=BC=93=E5=AD=98=E3=80=81C103-2?=
=?UTF-8?q?=E9=99=84=E4=BB=B6=E8=BD=AC=E4=BC=A0=E4=B8=8E=E5=90=88=E8=A7=84?=
=?UTF-8?q?=E9=99=84=E4=BB=B6ID=E6=98=A0=E5=B0=84=E7=BC=93=E5=AD=98?=
=?UTF-8?q?=EF=BC=89?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../support/hcs/HcsAttachmentSupport.java | 290 ++++++++++++++++++
.../support/hcs/HcsMasterDataSupport.java | 206 +++++++++++++
.../springblade/hcs/config/HcsProperties.java | 12 +
doc/nacos/third-party-api.yaml | 4 +
4 files changed, 512 insertions(+)
create mode 100644 blade-service/blade-transport/src/main/java/org/springblade/transport/support/hcs/HcsAttachmentSupport.java
create mode 100644 blade-service/blade-transport/src/main/java/org/springblade/transport/support/hcs/HcsMasterDataSupport.java
diff --git a/blade-service/blade-transport/src/main/java/org/springblade/transport/support/hcs/HcsAttachmentSupport.java b/blade-service/blade-transport/src/main/java/org/springblade/transport/support/hcs/HcsAttachmentSupport.java
new file mode 100644
index 00000000..e505f910
--- /dev/null
+++ b/blade-service/blade-transport/src/main/java/org/springblade/transport/support/hcs/HcsAttachmentSupport.java
@@ -0,0 +1,290 @@
+/**
+ * BladeX Commercial License Agreement
+ * Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
+ *
+ * Use of this software is governed by the Commercial License Agreement
+ * obtained after purchasing a license from BladeX.
+ *
+ * 1. This software is for development use only under a valid license
+ * from BladeX.
+ *
+ * 2. Redistribution of this software's source code to any third party
+ * without a commercial license is strictly prohibited.
+ *
+ * 3. Licensees may copyright their own code but cannot use segments
+ * from this software for such purposes. Copyright of this software
+ * remains with BladeX.
+ *
+ * Using this software signifies agreement to this License, and the software
+ * must not be used for illegal purposes.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
+ * not liable for any claims arising from secondary or illegal development.
+ *
+ * Author: Chill Zhuang (bladejava@qq.com)
+ */
+package org.springblade.transport.support.hcs;
+
+import cn.hutool.http.HttpUtil;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springblade.core.redis.cache.BladeRedis;
+import org.springblade.core.tool.jackson.JsonUtil;
+import org.springblade.core.tool.utils.StringUtil;
+import org.springblade.hcs.config.HcsProperties;
+import org.springblade.hcs.constant.HcsConstant;
+import org.springblade.hcs.dto.HcsAttachmentVO;
+import org.springblade.hcs.dto.HcsResult;
+import org.springblade.hcs.exception.HcsException;
+import org.springblade.hcs.feign.IHcsClient;
+import org.springblade.transport.constant.HcsSyncConstant;
+import org.springframework.http.MediaType;
+import org.springframework.stereotype.Component;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.time.Duration;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+
+/**
+ * HCS 附件转传支撑组件(C103-2 multipart 上传,设计文档 §6)
+ *
+ * 流程:解析单据附件 JSON 元素(去重键照 ContractManage#attachmentKey 惯例)→
+ * 按元数据 URL 从文件服务拉取流(基址可配 attachment.file-download-base)→
+ * C103-2 上传取得合规附件ID → Redis 映射缓存(blade:third:hcs:att:{attachmentKey},TTL 7 天),
+ * 未命中重传(重复上传仅浪费存储,无业务风险,故不做持久化映射表)。
+ * 任一附件转传失败 → 抛出异常由整单推送失败进补偿重试。
+ *
+ * TODO 待联调确认(§9-U8):v4 的 C103-1 入参未定义附件字段,合同附件向 HCS 的挂载方式待合规方确认,
+ * 本组件先建设通用转传能力并将合规附件ID 缓存备用,确认后按其要求挂载。
+ *
+ * @author Chill
+ */
+@Slf4j
+@Component
+@RequiredArgsConstructor
+public class HcsAttachmentSupport {
+
+ /**
+ * 附件元数据去重键候选字段(照 ContractManage#attachmentKey 既有惯例)
+ */
+ private static final List KEY_FIELDS = List.of("url", "link", "fileUrl", "downloadUrl", "uid", "originalName", "name");
+
+ private final IHcsClient hcsClient;
+ private final HcsProperties hcsProperties;
+ private final BladeRedis bladeRedis;
+
+ /**
+ * 解析单据附件 JSON 并转传,返回合规附件ID 列表(保持行序)
+ *
+ * @param attachmentsJson 附件元数据 JSON 数组
+ * @param operatorLoginName 操作人登录名(C103-2 fdLoginName)
+ * @return 合规附件ID 列表
+ */
+ public List transferAttachments(String attachmentsJson, String operatorLoginName) {
+ if (StringUtil.isBlank(attachmentsJson)) {
+ return List.of();
+ }
+ List