|
@@ -203,6 +203,21 @@ public class CwPracticeSignatureService extends ServiceImpl<CwPracticeSignatureM
|
|
|
private static final String DETAIL_GATE_KEY = "cwPracticeSignature:detailGate:";
|
|
private static final String DETAIL_GATE_KEY = "cwPracticeSignature:detailGate:";
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
|
|
+ * 签署过程回调核对契约锁详情的独立节流窗口(秒)。
|
|
|
|
|
+ *
|
|
|
|
|
+ * 与前端轮询的 DETAIL_GATE_COOLDOWN_SECONDS 用不同的键、互不阻塞:回调是"每位注师每次签署才一次"的
|
|
|
|
|
+ * 离散事件,必须当场核对落库 —— 若复用前端那把 60 秒键,前端 2 秒轮询会在注师签完前一刻把窗口续上,
|
|
|
|
|
+ * 导致紧随其后的回调命中"本次不核对"、不写库,链中注师(非末位)要等窗口自然过期才由前端复查反映,
|
|
|
|
|
+ * 实测慢约一分钟。这里只防契约锁对同一签署动作的重投把详情接口打爆,故取一个短窗口。
|
|
|
|
|
+ */
|
|
|
|
|
+ private static final int CALLBACK_DETAIL_COOLDOWN_SECONDS = 10;
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 签署过程回调专用详情节流键前缀(与前端轮询键分开,互不影响)
|
|
|
|
|
+ */
|
|
|
|
|
+ private static final String CALLBACK_DETAIL_GATE_KEY = "cwPracticeSignature:callbackDetailGate:";
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
* OSS 目录前缀配置(与存量签章同源:realPath 用它起头,附件表存的 url 是不带盘符的相对路径)
|
|
* OSS 目录前缀配置(与存量签章同源:realPath 用它起头,附件表存的 url 是不带盘符的相对路径)
|
|
|
*/
|
|
*/
|
|
|
private static final String DIRECTORY = Global.getConfig("directory");
|
|
private static final String DIRECTORY = Global.getConfig("directory");
|
|
@@ -1281,6 +1296,36 @@ public class CwPracticeSignatureService extends ServiceImpl<CwPracticeSignatureM
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
|
|
+ * 签署过程回调是否处在它自己的短节流窗口内(与前端轮询键独立)
|
|
|
|
|
+ *
|
|
|
|
|
+ * Redis 取不到时按"不在窗口内"处理:宁可多核对一次当场落库,也不要把签署结论卡住。
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param contractId
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ private boolean isCallbackDetailCooling(String contractId) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ return Boolean.TRUE.equals(stringRedisTemplate.hasKey(CALLBACK_DETAIL_GATE_KEY + contractId));
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.warn("报告执业签章回调:详情节流键读取失败,按不节流处理,contractId={}", contractId);
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 回调核对过一次契约锁详情后开一个短窗口(成功或失败都开,挡住紧随的重投)
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param contractId
|
|
|
|
|
+ */
|
|
|
|
|
+ private void startCallbackDetailCooldown(String contractId) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ stringRedisTemplate.opsForValue().set(CALLBACK_DETAIL_GATE_KEY + contractId, "1", CALLBACK_DETAIL_COOLDOWN_SECONDS, TimeUnit.SECONDS);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.warn("报告执业签章回调:详情节流键写入失败,contractId={}", contractId);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
* 契约锁详情回退查询:判当前登录注师本人这一条 PRACTICE 动作到底签没签
|
|
* 契约锁详情回退查询:判当前登录注师本人这一条 PRACTICE 动作到底签没签
|
|
|
*
|
|
*
|
|
|
* 只回结论,不写库 —— 写库由调用方决定(门禁查到就回填,markSigned 查到才推状态),
|
|
* 只回结论,不写库 —— 写库由调用方决定(门禁查到就回填,markSigned 查到才推状态),
|
|
@@ -1428,7 +1473,8 @@ public class CwPracticeSignatureService extends ServiceImpl<CwPracticeSignatureM
|
|
|
*
|
|
*
|
|
|
* signProcess 只写"这一位注师已签"到签署人链:契约锁的过程推送到底代表动作开始还是动作完成、
|
|
* signProcess 只写"这一位注师已签"到签署人链:契约锁的过程推送到底代表动作开始还是动作完成、
|
|
|
* status 取什么值厂商文档没写(待实测 #4 / #9),所以这里不解析回调状态字符串,
|
|
* status 取什么值厂商文档没写(待实测 #4 / #9),所以这里不解析回调状态字符串,
|
|
|
- * 改为拿回调提供的人去契约锁详情核对一次(共享 60 秒节流),核对到已签才写库 —— 猜值会把门禁写歪。
|
|
|
|
|
|
|
+ * 改为拿回调提供的人去契约锁详情核对一次(用回调自己的短节流键,与前端轮询 60 秒键互不阻塞,
|
|
|
|
|
+ * 保证签署动作第一次回调就当场落库;只挡同一动作的重投),核对到已签才写库 —— 猜值会把门禁写歪。
|
|
|
* accomplish 走已盖章件落库 + 状态结算(下载→解压→传OSS→写附件表→写文件行引用,见 handleAccomplishCallBack)。
|
|
* accomplish 走已盖章件落库 + 状态结算(下载→解压→传OSS→写附件表→写文件行引用,见 handleAccomplishCallBack)。
|
|
|
*
|
|
*
|
|
|
* 回调线程没有登录态:不取当前用户、不依赖租户上下文(AGENTS"异步与上下文"),
|
|
* 回调线程没有登录态:不取当前用户、不依赖租户上下文(AGENTS"异步与上下文"),
|
|
@@ -1490,13 +1536,13 @@ public class CwPracticeSignatureService extends ServiceImpl<CwPracticeSignatureM
|
|
|
result.append(";库中已是已签,不重复写");
|
|
result.append(";库中已是已签,不重复写");
|
|
|
return result.toString();
|
|
return result.toString();
|
|
|
}
|
|
}
|
|
|
- if (isDetailCooling(contractId)) {
|
|
|
|
|
- result.append(";契约锁详情核对正处在").append(DETAIL_GATE_COOLDOWN_SECONDS).append("秒节流窗口内,本次不核对");
|
|
|
|
|
|
|
+ if (isCallbackDetailCooling(contractId)) {
|
|
|
|
|
+ result.append(";同一签署动作在").append(CALLBACK_DETAIL_COOLDOWN_SECONDS).append("秒内已核对过契约锁详情(多为重投),本次不重复核对");
|
|
|
return result.toString();
|
|
return result.toString();
|
|
|
}
|
|
}
|
|
|
String operatorMobile = StringUtils.defaultIfBlank(presignCallBack.getOperatorMobile(), presignCallBack.getContact());
|
|
String operatorMobile = StringUtils.defaultIfBlank(presignCallBack.getOperatorMobile(), presignCallBack.getContact());
|
|
|
DetailJudge detailJudge = judgeSignedByContractDetail(cwPracticeSignature, operatorMobile, matchedSigner.getSerialNo());
|
|
DetailJudge detailJudge = judgeSignedByContractDetail(cwPracticeSignature, operatorMobile, matchedSigner.getSerialNo());
|
|
|
- startDetailCooldown(contractId);
|
|
|
|
|
|
|
+ startCallbackDetailCooldown(contractId);
|
|
|
if (SignJudge.SIGNED == detailJudge.judge) {
|
|
if (SignJudge.SIGNED == detailJudge.judge) {
|
|
|
markSignerSigned(matchedSigner);
|
|
markSignerSigned(matchedSigner);
|
|
|
result.append(";已把该签署人置为已签");
|
|
result.append(";已把该签署人置为已签");
|
|
@@ -1571,14 +1617,25 @@ public class CwPracticeSignatureService extends ServiceImpl<CwPracticeSignatureM
|
|
|
}
|
|
}
|
|
|
List<CwPracticeSignatureFile> fileList = queryFileList(signatureId);
|
|
List<CwPracticeSignatureFile> fileList = queryFileList(signatureId);
|
|
|
int savedCount = 0;
|
|
int savedCount = 0;
|
|
|
|
|
+ String singleSignedOssPath = null;
|
|
|
for (File item : signedFiles) {
|
|
for (File item : signedFiles) {
|
|
|
if (!item.isFile()) {
|
|
if (!item.isFile()) {
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
File renamed = renameBracketFile(item);
|
|
File renamed = renameBracketFile(item);
|
|
|
- saveSignedAttachment(signatureId, creator, fileList, renamed == null ? item : renamed);
|
|
|
|
|
|
|
+ String ossPath = saveSignedAttachment(signatureId, creator, fileList, renamed == null ? item : renamed);
|
|
|
|
|
+ if (savedCount == 0) {
|
|
|
|
|
+ // 暂存第一份的现成 OSS 路径,仅当最终只有 1 份时直接复用
|
|
|
|
|
+ singleSignedOssPath = ossPath;
|
|
|
|
|
+ }
|
|
|
savedCount++;
|
|
savedCount++;
|
|
|
}
|
|
}
|
|
|
|
|
+ // 下载件落 signed_zip_url:单文件直出原件(复用上面已传好的那份,不再打包/重传),多文件才传整包 zip
|
|
|
|
|
+ if (savedCount == 1) {
|
|
|
|
|
+ setSignedDownloadUrl(signatureId, singleSignedOssPath);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ uploadSignedZipToOss(signatureId, srcFile);
|
|
|
|
|
+ }
|
|
|
// 完成事件本身就代表全员签完:签署人链在这里补齐,兜住 signProcess 丢推送的情况。
|
|
// 完成事件本身就代表全员签完:签署人链在这里补齐,兜住 signProcess 丢推送的情况。
|
|
|
// 这一批人的 sign_time 取回调时间,不是真实落章时刻,只用于门禁与展示,不当审计依据。
|
|
// 这一批人的 sign_time 取回调时间,不是真实落章时刻,只用于门禁与展示,不当审计依据。
|
|
|
markAllSignerSigned(signatureId);
|
|
markAllSignerSigned(signatureId);
|
|
@@ -1610,9 +1667,10 @@ public class CwPracticeSignatureService extends ServiceImpl<CwPracticeSignatureM
|
|
|
* @param creator 单据发起人(回调线程没有登录态,附件表的创建人按发起人写,与存量一致)
|
|
* @param creator 单据发起人(回调线程没有登录态,附件表的创建人按发起人写,与存量一致)
|
|
|
* @param fileList 文件行清单(内存对象,落库后就地把引用改进去,同一事务里再查一次可能读到改前的值)
|
|
* @param fileList 文件行清单(内存对象,落库后就地把引用改进去,同一事务里再查一次可能读到改前的值)
|
|
|
* @param signedFile 已盖章文件
|
|
* @param signedFile 已盖章文件
|
|
|
|
|
+ * @return 该已盖章原件的 OSS 路径(与 work_attachment.url 同值,供单文件直出复用,避免再打包/重传)
|
|
|
* @throws Exception
|
|
* @throws Exception
|
|
|
*/
|
|
*/
|
|
|
- private void saveSignedAttachment(String signatureId, UserDTO creator, List<CwPracticeSignatureFile> fileList, File signedFile) throws Exception {
|
|
|
|
|
|
|
+ private String saveSignedAttachment(String signatureId, UserDTO creator, List<CwPracticeSignatureFile> fileList, File signedFile) throws Exception {
|
|
|
String realPath = DIRECTORY.replaceFirst("/", "") + "/" + SIGNED_OSS_DIRECTORY
|
|
String realPath = DIRECTORY.replaceFirst("/", "") + "/" + SIGNED_OSS_DIRECTORY
|
|
|
+ SpringUtil.getBean(IWorkAttachmentApi.class).datePath() + "/" + System.currentTimeMillis();
|
|
+ SpringUtil.getBean(IWorkAttachmentApi.class).datePath() + "/" + System.currentTimeMillis();
|
|
|
String newName = signedFile.getName();
|
|
String newName = signedFile.getName();
|
|
@@ -1652,7 +1710,7 @@ public class CwPracticeSignatureService extends ServiceImpl<CwPracticeSignatureM
|
|
|
newRow.setSignedFileName(newName);
|
|
newRow.setSignedFileName(newName);
|
|
|
cwPracticeSignatureFileMapper.insert(newRow);
|
|
cwPracticeSignatureFileMapper.insert(newRow);
|
|
|
fileList.add(newRow);
|
|
fileList.add(newRow);
|
|
|
- return;
|
|
|
|
|
|
|
+ return filepath;
|
|
|
}
|
|
}
|
|
|
CwPracticeSignatureFile update = new CwPracticeSignatureFile();
|
|
CwPracticeSignatureFile update = new CwPracticeSignatureFile();
|
|
|
update.setId(fileRow.getId());
|
|
update.setId(fileRow.getId());
|
|
@@ -1661,6 +1719,71 @@ public class CwPracticeSignatureService extends ServiceImpl<CwPracticeSignatureM
|
|
|
cwPracticeSignatureFileMapper.updateById(update);
|
|
cwPracticeSignatureFileMapper.updateById(update);
|
|
|
fileRow.setSignedAttachmentId(workAttachment.getId());
|
|
fileRow.setSignedAttachmentId(workAttachment.getId());
|
|
|
fileRow.setSignedFileName(newName);
|
|
fileRow.setSignedFileName(newName);
|
|
|
|
|
+ return filepath;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 单文件直出:把已盖章原件现成的 OSS 路径写进 signed_zip_url,不再打包、不再重传
|
|
|
|
|
+ *
|
|
|
|
|
+ * 该路径就是 saveSignedAttachment 内部算出并写进 work_attachment.url 的那个值,文件已经在 OSS 上。
|
|
|
|
|
+ * 回调重投时 saveSignedAttachment 会重新传、换新 key,这里覆盖引用即可;上一轮若是多文件留下的旧 zip 不删
|
|
|
|
|
+ * (与 uploadSignedZipToOss 的"同名覆盖、不主动删旧"同策略,OSS 不堆积)。
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param signatureId 单据id
|
|
|
|
|
+ * @param ossPath 已盖章原件的 OSS 路径(saveSignedAttachment 的返回值)
|
|
|
|
|
+ */
|
|
|
|
|
+ private void setSignedDownloadUrl(String signatureId, String ossPath) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ if (StringUtils.isBlank(ossPath)) {
|
|
|
|
|
+ log.warn("报告执业签章单文件直出:已盖章原件 OSS 路径为空,不写 signed_zip_url,signatureId={}", signatureId);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ CwPracticeSignature old = this.getById(signatureId);
|
|
|
|
|
+ if (old != null && StringUtils.isNotBlank(old.getSignedZipUrl()) && !StringUtils.equals(old.getSignedZipUrl(), ossPath)) {
|
|
|
|
|
+ log.info("报告执业签章单文件直出覆盖旧下载件引用,signatureId={},旧url={}", signatureId, old.getSignedZipUrl());
|
|
|
|
|
+ }
|
|
|
|
|
+ CwPracticeSignature update = new CwPracticeSignature();
|
|
|
|
|
+ update.setId(signatureId);
|
|
|
|
|
+ update.setSignedZipUrl(ossPath);
|
|
|
|
|
+ this.updateById(update);
|
|
|
|
|
+ log.info("报告执业签章单文件直出,signed_zip_url 复用已盖章原件路径,signatureId={},url={}", signatureId, ossPath);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ // 写下载件失败不影响主流程(单个文件已落住),只记日志
|
|
|
|
|
+ log.error("报告执业签章单文件直出写 signed_zip_url 失败,signatureId=" + signatureId, e);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 把契约锁回调下载的原始 zip 上传 OSS,URL 写入 cw_practice_signature.signed_zip_url
|
|
|
|
|
+ *
|
|
|
|
|
+ * 前端列表页下载时直接用这个 URL 走 getTemporaryUrl 拿签名地址,不再跨服务调 downBytesByStream。
|
|
|
|
|
+ * 回调重投时先删旧 zip 再传新的(与单个文件"删旧插新"同策略)。
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param signatureId 单据id
|
|
|
|
|
+ * @param zipFile 本地 zip 文件(契约锁回调下载的原始压缩包)
|
|
|
|
|
+ */
|
|
|
|
|
+ private void uploadSignedZipToOss(String signatureId, File zipFile) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ CwPracticeSignature old = this.getById(signatureId);
|
|
|
|
|
+ if (old != null && StringUtils.isNotBlank(old.getSignedZipUrl())) {
|
|
|
|
|
+ // 回调重投:旧 zip 不删(OSS 按 key 覆盖,同名文件不会堆积),只更新 DB 引用
|
|
|
|
|
+ log.info("报告执业签章zip重投覆盖,signatureId={},旧url={}", signatureId, old.getSignedZipUrl());
|
|
|
|
|
+ }
|
|
|
|
|
+ String realPath = DIRECTORY.replaceFirst("/", "") + "/" + SIGNED_OSS_DIRECTORY
|
|
|
|
|
+ + SpringUtil.getBean(IWorkAttachmentApi.class).datePath() + "/" + System.currentTimeMillis();
|
|
|
|
|
+ String zipName = "signed_" + signatureId + ".zip";
|
|
|
|
|
+ SpringUtil.getBean(IWorkAttachmentApi.class).uploadFileSignatureOSS(zipFile.getPath(), realPath, zipName);
|
|
|
|
|
+ String filepath = "/" + realPath + zipName;
|
|
|
|
|
+
|
|
|
|
|
+ CwPracticeSignature update = new CwPracticeSignature();
|
|
|
|
|
+ update.setId(signatureId);
|
|
|
|
|
+ update.setSignedZipUrl(filepath);
|
|
|
|
|
+ this.updateById(update);
|
|
|
|
|
+ log.info("报告执业签章zip上传OSS成功,signatureId={},url={}", signatureId, filepath);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ // zip 上传失败不影响主流程(单个文件已落住),只记日志
|
|
|
|
|
+ log.error("报告执业签章zip上传OSS失败,signatureId=" + signatureId, e);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -2075,7 +2198,7 @@ public class CwPracticeSignatureService extends ServiceImpl<CwPracticeSignatureM
|
|
|
// 单文件:直接下载原文件
|
|
// 单文件:直接下载原文件
|
|
|
WorkAttachmentInfoDTO attachmentDto = signedAttachmentDtoList.get(0);
|
|
WorkAttachmentInfoDTO attachmentDto = signedAttachmentDtoList.get(0);
|
|
|
String fileName = StringUtils.defaultIfBlank(attachmentDto.getName(), "已盖章文件");
|
|
String fileName = StringUtils.defaultIfBlank(attachmentDto.getName(), "已盖章文件");
|
|
|
- String ossKey = attachmentDto.getUrl();
|
|
|
|
|
|
|
+ String ossKey = StringUtils.stripStart(attachmentDto.getUrl(), "/");
|
|
|
log.info("下载已盖章文件(单文件):ossKey={}, fileName={}, id={}", ossKey, fileName, id);
|
|
log.info("下载已盖章文件(单文件):ossKey={}, fileName={}, id={}", ossKey, fileName, id);
|
|
|
byte[] fileBytes = workAttachmentApi.downBytesByStream(ossKey, fileName);
|
|
byte[] fileBytes = workAttachmentApi.downBytesByStream(ossKey, fileName);
|
|
|
if (ArrayUtil.isEmpty(fileBytes)) {
|
|
if (ArrayUtil.isEmpty(fileBytes)) {
|
|
@@ -2100,7 +2223,7 @@ public class CwPracticeSignatureService extends ServiceImpl<CwPracticeSignatureM
|
|
|
try (ZipOutputStream zos = new ZipOutputStream(response.getOutputStream())) {
|
|
try (ZipOutputStream zos = new ZipOutputStream(response.getOutputStream())) {
|
|
|
for (WorkAttachmentInfoDTO attachmentDto : signedAttachmentDtoList) {
|
|
for (WorkAttachmentInfoDTO attachmentDto : signedAttachmentDtoList) {
|
|
|
String fileName = StringUtils.defaultIfBlank(attachmentDto.getName(), "已盖章文件");
|
|
String fileName = StringUtils.defaultIfBlank(attachmentDto.getName(), "已盖章文件");
|
|
|
- String ossKey = attachmentDto.getUrl();
|
|
|
|
|
|
|
+ String ossKey = StringUtils.stripStart(attachmentDto.getUrl(), "/");
|
|
|
log.info("下载已盖章文件(zip):ossKey={}, fileName={}, id={}", ossKey, fileName, id);
|
|
log.info("下载已盖章文件(zip):ossKey={}, fileName={}, id={}", ossKey, fileName, id);
|
|
|
byte[] fileBytes = workAttachmentApi.downBytesByStream(ossKey, fileName);
|
|
byte[] fileBytes = workAttachmentApi.downBytesByStream(ossKey, fileName);
|
|
|
if (ArrayUtil.isEmpty(fileBytes)) {
|
|
if (ArrayUtil.isEmpty(fileBytes)) {
|