|
@@ -119,7 +119,8 @@ public class SealServiceImpl implements SealService {
|
|
|
instanceId, formUuid, targetContent == null ? 0 : targetContent.size());
|
|
instanceId, formUuid, targetContent == null ? 0 : targetContent.size());
|
|
|
|
|
|
|
|
String approvalDate = resolveApprovalDate(request.getApprovalTime(), properties.getTimeZone());
|
|
String approvalDate = resolveApprovalDate(request.getApprovalTime(), properties.getTimeZone());
|
|
|
- String existingUrl = findExistingUrl(targetContent, properties.getTargetImageField());
|
|
|
|
|
|
|
+ String targetImageField = selectTargetImageField(request.getCodeid(), properties.getTargetImageField());
|
|
|
|
|
+ String existingUrl = findExistingUrl(targetContent, targetImageField);
|
|
|
if (existingUrl != null && existingUrl.startsWith(trimTrailingSlash(properties.getPublicBaseUrl()))) {
|
|
if (existingUrl != null && existingUrl.startsWith(trimTrailingSlash(properties.getPublicBaseUrl()))) {
|
|
|
// 已存在本服务生成的文件时执行幂等返回,不重复下载、绘图和回写。
|
|
// 已存在本服务生成的文件时执行幂等返回,不重复下载、绘图和回写。
|
|
|
log.info("[seal] 检测到已生成的印章 URL,跳过重复处理,instanceId={}, fileUrl={}", instanceId, existingUrl);
|
|
log.info("[seal] 检测到已生成的印章 URL,跳过重复处理,instanceId={}, fileUrl={}", instanceId, existingUrl);
|
|
@@ -133,8 +134,8 @@ public class SealServiceImpl implements SealService {
|
|
|
log.info("[seal] 日期绘制完成,approvalDate={}, outputBytes={}", approvalDate, stampedBytes.length);
|
|
log.info("[seal] 日期绘制完成,approvalDate={}, outputBytes={}", approvalDate, stampedBytes.length);
|
|
|
StoredFile storedFile = store(stampedBytes, instanceId, approvalDate);
|
|
StoredFile storedFile = store(stampedBytes, instanceId, approvalDate);
|
|
|
log.info("[seal] 印章文件保存完成,path={}, url={}", storedFile.path, storedFile.url);
|
|
log.info("[seal] 印章文件保存完成,path={}, url={}", storedFile.path, storedFile.url);
|
|
|
- updateTarget(appType, formUuid, instanceId, storedFile, accessToken);
|
|
|
|
|
- log.info("[seal] 印章 URL 回写宜搭完成,instanceId={}, fieldId={}", instanceId, properties.getTargetImageField());
|
|
|
|
|
|
|
+ updateTarget(appType, formUuid, instanceId, targetImageField, storedFile, accessToken);
|
|
|
|
|
+ log.info("[seal] 印章 URL 回写宜搭完成,instanceId={}, fieldId={}", instanceId, targetImageField);
|
|
|
return new SealResult(instanceId, formUuid, storedFile.path.toString(), storedFile.url, approvalDate);
|
|
return new SealResult(instanceId, formUuid, storedFile.path.toString(), storedFile.url, approvalDate);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -504,9 +505,10 @@ public class SealServiceImpl implements SealService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/** 使用宜搭 UpdateFormData 接口,把公网图片地址写入图片上传字段。 */
|
|
/** 使用宜搭 UpdateFormData 接口,把公网图片地址写入图片上传字段。 */
|
|
|
- private void updateTarget(String appType, String formUuid, String instanceId, StoredFile file, String accessToken) {
|
|
|
|
|
|
|
+ private void updateTarget(String appType, String formUuid, String instanceId, String targetImageField,
|
|
|
|
|
+ StoredFile file, String accessToken) {
|
|
|
log.info("[seal.yida] UpdateFormData 开始,appType={}, formUuid={}, instanceId={}, fieldId={}, fileUrl={}",
|
|
log.info("[seal.yida] UpdateFormData 开始,appType={}, formUuid={}, instanceId={}, fieldId={}, fileUrl={}",
|
|
|
- appType, formUuid, instanceId, properties.getTargetImageField(), file.url);
|
|
|
|
|
|
|
+ appType, formUuid, instanceId, targetImageField, file.url);
|
|
|
// 图片字段使用宜搭兼容的数组对象结构,保留名称、大小和各类访问地址。
|
|
// 图片字段使用宜搭兼容的数组对象结构,保留名称、大小和各类访问地址。
|
|
|
Map<String, Object> image = new LinkedHashMap<>();
|
|
Map<String, Object> image = new LinkedHashMap<>();
|
|
|
image.put("name", file.name);
|
|
image.put("name", file.name);
|
|
@@ -518,7 +520,7 @@ public class SealServiceImpl implements SealService {
|
|
|
List<Map<String, Object>> images = new ArrayList<>();
|
|
List<Map<String, Object>> images = new ArrayList<>();
|
|
|
images.add(image);
|
|
images.add(image);
|
|
|
Map<String, Object> formData = new HashMap<>();
|
|
Map<String, Object> formData = new HashMap<>();
|
|
|
- formData.put(properties.getTargetImageField(), images);
|
|
|
|
|
|
|
+ formData.put(targetImageField, images);
|
|
|
try {
|
|
try {
|
|
|
com.aliyun.dingtalkyida_2_0.Client client = createClientV2();
|
|
com.aliyun.dingtalkyida_2_0.Client client = createClientV2();
|
|
|
UpdateFormDataHeaders headers = new UpdateFormDataHeaders();
|
|
UpdateFormDataHeaders headers = new UpdateFormDataHeaders();
|
|
@@ -540,11 +542,19 @@ public class SealServiceImpl implements SealService {
|
|
|
}
|
|
}
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
log.error("[seal.yida] UpdateFormData 失败,instanceId={}, fieldId={}, error={}",
|
|
log.error("[seal.yida] UpdateFormData 失败,instanceId={}, fieldId={}, error={}",
|
|
|
- instanceId, properties.getTargetImageField(), summarize(e), e);
|
|
|
|
|
|
|
+ instanceId, targetImageField, summarize(e), e);
|
|
|
throw new IllegalStateException("回写宜搭印章图片失败:" + e.getMessage(), e);
|
|
throw new IllegalStateException("回写宜搭印章图片失败:" + e.getMessage(), e);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /** 请求传入控件编码时优先使用;未传时保持原固定字段配置。 */
|
|
|
|
|
+ static String selectTargetImageField(String codeid, String configuredField) {
|
|
|
|
|
+ if (codeid != null && !codeid.trim().isEmpty()) {
|
|
|
|
|
+ return codeid.trim();
|
|
|
|
|
+ }
|
|
|
|
|
+ return configuredField;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/** 读取业务表单中已有的印章 URL,用于幂等判断。 */
|
|
/** 读取业务表单中已有的印章 URL,用于幂等判断。 */
|
|
|
private String findExistingUrl(JSONObject content, String fieldId) {
|
|
private String findExistingUrl(JSONObject content, String fieldId) {
|
|
|
JSONObject formData = getFieldContainer(content);
|
|
JSONObject formData = getFieldContainer(content);
|