|
@@ -267,16 +267,71 @@ public class ESignServiceImpl implements IESignService {
|
|
|
*/
|
|
|
private JsonArray buildSigners(AppContractInfo contractInfo, FamilyMembers familyMembers,String orgId) throws EsignDemoException {
|
|
|
JsonArray signers = new JsonArray();
|
|
|
- EsignHttpResponse getComponentsInfo = getComponentsInfo("12f41e8f364946369b8d93bd8710df67");
|
|
|
+
|
|
|
+ // 获取模板组件信息
|
|
|
+ EsignHttpResponse getComponentsInfo = getComponentsInfo(contractInfo.getDocTemplateId());
|
|
|
JsonObject getComponentsInfoObject = gson.fromJson(getComponentsInfo.getBody(), JsonObject.class);
|
|
|
- System.err.println("查询模板详情返回:"+getComponentsInfoObject);
|
|
|
- // 个人签署人
|
|
|
+
|
|
|
+ if (!getComponentsInfoObject.has("data") || !getComponentsInfoObject.getAsJsonObject("data").has("components")) {
|
|
|
+ throw new EsignDemoException("模板组件信息缺失");
|
|
|
+ }
|
|
|
+
|
|
|
+ JsonArray components = getComponentsInfoObject.getAsJsonObject("data").getAsJsonArray("components");
|
|
|
+
|
|
|
+ // 构建签署人结构
|
|
|
JsonObject signer1 = new JsonObject();
|
|
|
- signer1.add("signConfig", buildSignConfig(1, 10));
|
|
|
- signer1.add("noticeConfig", buildNoticeConfig(""));
|
|
|
- signer1.addProperty("signerType", 0);
|
|
|
+ JsonObject signer2 = new JsonObject();
|
|
|
+ JsonArray personalSignFields = new JsonArray();
|
|
|
+ JsonArray enterpriseSignFields = new JsonArray();
|
|
|
|
|
|
- // 签署人信息
|
|
|
+ // 设置签署人基础信息
|
|
|
+ setupSignerBaseInfo(signer1, familyMembers, 0); // 个人签署人
|
|
|
+ if (orgId != null) {
|
|
|
+ setupEnterpriseSigner(signer2, orgId); // 企业签署人
|
|
|
+ }
|
|
|
+
|
|
|
+ // 遍历组件并分配签署区域
|
|
|
+ for (JsonElement element : components) {
|
|
|
+ JsonObject component = element.getAsJsonObject();
|
|
|
+ JsonObject specialAttribute = component.getAsJsonObject("componentSpecialAttribute");
|
|
|
+
|
|
|
+ if (specialAttribute != null && specialAttribute.has("signerRole")) {
|
|
|
+ String signerRole = specialAttribute.get("signerRole").getAsString();
|
|
|
+ JsonObject position = component.getAsJsonObject("componentPosition");
|
|
|
+ JsonObject size = component.getAsJsonObject("componentSize");
|
|
|
+
|
|
|
+ int x = position.get("componentPositionX").getAsInt();
|
|
|
+ int y = position.get("componentPositionY").getAsInt();
|
|
|
+ int width = size.get("componentWidth").getAsInt();
|
|
|
+ int height = size.get("componentHeight").getAsInt();
|
|
|
+
|
|
|
+ JsonObject signField = buildSignFieldFromComponent(contractInfo.getFileId(), x, y, width, height, "商户".equals(signerRole));
|
|
|
+
|
|
|
+ if ("用户".equals(signerRole)) {
|
|
|
+ personalSignFields.add(signField);
|
|
|
+ } else if ("商户".equals(signerRole)) {
|
|
|
+ enterpriseSignFields.add(signField);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 添加签署区域
|
|
|
+ if (!personalSignFields.isEmpty()) {
|
|
|
+ signer1.add("signFields", personalSignFields);
|
|
|
+ signers.add(signer1);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!enterpriseSignFields.isEmpty()) {
|
|
|
+ signer2.add("signFields", enterpriseSignFields);
|
|
|
+ signers.add(signer2);
|
|
|
+ }
|
|
|
+
|
|
|
+ return signers;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void setupSignerBaseInfo(JsonObject signer, FamilyMembers familyMembers, int signerType) {
|
|
|
+ signer.addProperty("signerType", signerType);
|
|
|
JsonObject psnSignerInfo = new JsonObject();
|
|
|
psnSignerInfo.addProperty("psnAccount", familyMembers.getPhone());
|
|
|
|
|
@@ -285,19 +340,18 @@ public class ESignServiceImpl implements IESignService {
|
|
|
psnInfo.addProperty("psnIDCardNum", familyMembers.getIdentityCard());
|
|
|
psnInfo.addProperty("psnIDCardType", "CRED_PSN_CH_IDCARD");
|
|
|
psnSignerInfo.add("psnInfo", psnInfo);
|
|
|
+ signer.add("psnSignerInfo", psnSignerInfo);
|
|
|
|
|
|
- signer1.add("psnSignerInfo", psnSignerInfo);
|
|
|
- signer1.add("signFields", buildSignFields(contractInfo.getFileId(), 100, 200, 96, 100, 100,false,""));
|
|
|
- // 企业签署人
|
|
|
- JsonObject signer2 = new JsonObject();
|
|
|
- signer2.addProperty("signerType", 1);
|
|
|
+ // 添加签署配置和通知配置
|
|
|
+ signer.add("signConfig", buildSignConfig(1, 10));
|
|
|
+ signer.add("noticeConfig", buildNoticeConfig(""));
|
|
|
+ }
|
|
|
+
|
|
|
+ private void setupEnterpriseSigner(JsonObject signer, String orgId) {
|
|
|
+ signer.addProperty("signerType", 1);
|
|
|
JsonObject orgSignerInfo = new JsonObject();
|
|
|
orgSignerInfo.addProperty("orgId", orgId);
|
|
|
- signer2.add("signFields", buildSignFields(contractInfo.getFileId(), 300, 200, 159, 300, 100,true,orgAuthorizedSeal(orgId)));
|
|
|
-
|
|
|
- signers.add(signer1);
|
|
|
- signers.add(signer2);
|
|
|
- return signers;
|
|
|
+ signer.add("orgSignerInfo", orgSignerInfo);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -319,16 +373,9 @@ public class ESignServiceImpl implements IESignService {
|
|
|
return noticeConfig;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 构建签署区域
|
|
|
- */
|
|
|
- private JsonArray buildSignFields(String fileId,
|
|
|
- int x, int y,
|
|
|
- int size,
|
|
|
- int dateX, int dateY,boolean autoSign,String signature) {
|
|
|
- JsonArray signFields = new JsonArray();
|
|
|
- JsonObject field = new JsonObject();
|
|
|
|
|
|
+ private JsonObject buildSignFieldFromComponent(String fileId, int x, int y, int width, int height, boolean autoSign) {
|
|
|
+ JsonObject field = new JsonObject();
|
|
|
field.addProperty("fileId", fileId);
|
|
|
field.addProperty("customBizNum", "自定义编码0001");
|
|
|
field.addProperty("signFieldType", 0);
|
|
@@ -339,9 +386,8 @@ public class ESignServiceImpl implements IESignService {
|
|
|
normalConfig.addProperty("freeMode", false);
|
|
|
normalConfig.addProperty("movableSignField", false);
|
|
|
normalConfig.addProperty("psnSealStyles", "0,1");
|
|
|
- normalConfig.addProperty("signFieldSize", String.valueOf(size));
|
|
|
+ normalConfig.addProperty("signFieldSize", String.valueOf(width)); // 使用组件宽度作为尺寸
|
|
|
normalConfig.addProperty("signFieldStyle", 1);
|
|
|
- normalConfig.addProperty("assignedSealId", signature);
|
|
|
|
|
|
// 位置配置
|
|
|
JsonObject position = new JsonObject();
|
|
@@ -350,20 +396,19 @@ public class ESignServiceImpl implements IESignService {
|
|
|
position.addProperty("positionY", y);
|
|
|
normalConfig.add("signFieldPosition", position);
|
|
|
|
|
|
- // 日期配置
|
|
|
+ // 日期配置(可选)
|
|
|
JsonObject dateConfig = new JsonObject();
|
|
|
dateConfig.addProperty("dateFormat", "yyyy-MM-dd");
|
|
|
dateConfig.addProperty("showSignDate", 1);
|
|
|
- dateConfig.addProperty("signDatePositionX", dateX);
|
|
|
- dateConfig.addProperty("signDatePositionY", dateY);
|
|
|
+ dateConfig.addProperty("signDatePositionX", x + width + 10); // 日期默认在签名右侧
|
|
|
+ dateConfig.addProperty("signDatePositionY", y);
|
|
|
|
|
|
field.add("normalSignFieldConfig", normalConfig);
|
|
|
field.add("signDateConfig", dateConfig);
|
|
|
-
|
|
|
- signFields.add(field);
|
|
|
- return signFields;
|
|
|
+ return field;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* 提取签署流程ID
|
|
|
*/
|