From 992f25a224657233bc301df53ac164955f8f9400 Mon Sep 17 00:00:00 2001 From: Jack <46790855@qq.com> Date: Fri, 5 Dec 2025 21:34:47 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=97=A5=E5=BF=97=E6=89=93?= =?UTF-8?q?=E5=8D=B0=EF=BC=8Ce=E7=AD=BE=E5=AE=9D=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../EsignContractFillingFileServiceImpl.java | 196 +++++++++--------- .../impl/EsignContractServiceImpl.java | 81 +++++--- .../impl/ShopNumberSeqServiceImpl.java | 52 +++-- .../impl/ShopOrderBaseServiceImpl.java | 2 +- 4 files changed, 181 insertions(+), 150 deletions(-) diff --git a/mall-shop/src/main/java/com/suisung/mall/shop/esign/service/impl/EsignContractFillingFileServiceImpl.java b/mall-shop/src/main/java/com/suisung/mall/shop/esign/service/impl/EsignContractFillingFileServiceImpl.java index f39b49d3..75350f7e 100644 --- a/mall-shop/src/main/java/com/suisung/mall/shop/esign/service/impl/EsignContractFillingFileServiceImpl.java +++ b/mall-shop/src/main/java/com/suisung/mall/shop/esign/service/impl/EsignContractFillingFileServiceImpl.java @@ -91,7 +91,7 @@ public class EsignContractFillingFileServiceImpl extends BaseServiceImpl @@ -109,47 +109,47 @@ public class EsignContractFillingFileServiceImpl extends BaseServiceImpl() {{ + componentList.add(new HashMap() {{ put("componentKey", "plat_contracts"); put("componentValue", "《平台商户入驻服务框架协议》和《小发同城服务费结算》"); }}); @@ -207,7 +207,7 @@ public class EsignContractFillingFileServiceImpl extends BaseServiceImpl() {{ + componentList.add(new HashMap() {{ put("componentKey", "mch_sign_date" + finalI); put("componentValue", today); }}); @@ -216,34 +216,34 @@ public class EsignContractFillingFileServiceImpl extends BaseServiceImpl() {{ + componentList.add(new HashMap() {{ put("componentKey", "plat_sign_date" + finalI); put("componentValue", today); }}); } // 甲方公司名称 - int mchCompanyCount = CommonConstant.MCH_ENTITY_TYPE_QY.equals(shopMchEntry.getEntity_type()) ? 17 : 16; + int mchCompanyCount = CommonConstant.MCH_ENTITY_TYPE_QY.equals(mchEntry.getEntity_type()) ? 17 : 16; for (int i = 1; i <= mchCompanyCount; i++) { int finalI = i; - list.add(new HashMap() {{ + componentList.add(new HashMap() {{ put("componentKey", "mch_company" + finalI); put("componentValue", mchCompany); }}); } // 特殊处理:甲方收款账户方(企业是公司名,个人是个人实名) - if (!CommonConstant.MCH_ENTITY_TYPE_QY.equals(shopMchEntry.getEntity_type())) { - list.add(new HashMap() {{ + if (!CommonConstant.MCH_ENTITY_TYPE_QY.equals(mchEntry.getEntity_type())) { + componentList.add(new HashMap() {{ put("componentKey", "mch_company17"); - put("componentValue", shopMchEntry.getContact_name()); + put("componentValue", mchEntry.getContact_name()); }}); } // 甲方法人姓名 for (int i = 1; i <= 4; i++) { int finalI = i; - list.add(new HashMap() {{ + componentList.add(new HashMap() {{ put("componentKey", "mch_legal_person_name" + finalI); put("componentValue", legalPersonName); }}); @@ -252,63 +252,63 @@ public class EsignContractFillingFileServiceImpl extends BaseServiceImpl() {{ + componentList.add(new HashMap() {{ put("componentKey", "mch_legal_person_mobile" + finalI); put("componentValue", legalPersonMobile); }}); } // 甲方身份证号码 - list.add(new HashMap() {{ + componentList.add(new HashMap() {{ put("componentKey", "mch_legal_person_id_number1"); put("componentValue", legalPersonIdNumber); }}); // 甲方店铺名称 - list.add(new HashMap() {{ + componentList.add(new HashMap() {{ put("componentKey", "mch_store_name1"); - put("componentValue", shopMchEntry.getStore_name()); + put("componentValue", mchEntry.getStore_name()); }}); // 规则编号 - list.add(new HashMap() {{ + componentList.add(new HashMap() {{ put("componentKey", "rule_no"); put("componentValue", 3); }}); // 分账比例 BigDecimal finalSplitRatio = splitRatio; - list.add(new HashMap() {{ + componentList.add(new HashMap() {{ put("componentKey", "mch_ratio"); put("componentValue", finalSplitRatio); }}); // 结算方式 - list.add(new HashMap() {{ + componentList.add(new HashMap() {{ put("componentKey", "settlement_method"); - put("componentValue", shopMchEntry.getSettlement_method()); + put("componentValue", mchEntry.getSettlement_method()); }}); // 甲方地址 - list.add(new HashMap() {{ + componentList.add(new HashMap() {{ put("componentKey", "mch_address1"); - put("componentValue", shopMchEntry.getStore_address()); + put("componentValue", mchEntry.getStore_address()); }}); // 甲方银行 - list.add(new HashMap() {{ + componentList.add(new HashMap() {{ put("componentKey", "mch_bank1"); - put("componentValue", shopMchEntry.getBank_name()); + put("componentValue", mchEntry.getBank_name()); }}); // 甲方账户号 - list.add(new HashMap() {{ + componentList.add(new HashMap() {{ put("componentKey", "mch_account_number1"); - put("componentValue", shopMchEntry.getAccount_number()); + put("componentValue", mchEntry.getAccount_number()); }}); // 乙方公司名称 - list.add(new HashMap() {{ + componentList.add(new HashMap() {{ put("componentKey", "plat_company1"); put("componentValue", platCompany + "和代理商"); }}); @@ -316,7 +316,7 @@ public class EsignContractFillingFileServiceImpl extends BaseServiceImpl() {{ + componentList.add(new HashMap() {{ put("componentKey", "plat_company" + finalI); put("componentValue", platCompany); }}); @@ -325,58 +325,58 @@ public class EsignContractFillingFileServiceImpl extends BaseServiceImpl() {{ + componentList.add(new HashMap() {{ put("componentKey", "plat_mobile" + finalI); - put("componentValue", esignPlatformInfo.getLegal_person_mobile()); + put("componentValue", platformInfo.getLegal_person_mobile()); }}); } // 乙方邮箱(重复填充,但保持原逻辑) for (int i = 0; i < 6; i++) { - list.add(new HashMap() {{ + componentList.add(new HashMap() {{ put("componentKey", "plat_email1"); - put("componentValue", esignPlatformInfo.getEmail()); + put("componentValue", platformInfo.getEmail()); }}); } // 乙方银行 - list.add(new HashMap() {{ + componentList.add(new HashMap() {{ put("componentKey", "plat_bank1"); - put("componentValue", esignPlatformInfo.getRec_acc_bank_name()); + put("componentValue", platformInfo.getRec_acc_bank_name()); }}); // 乙方账户号 - list.add(new HashMap() {{ + componentList.add(new HashMap() {{ put("componentKey", "plat_account_number1"); - put("componentValue", esignPlatformInfo.getRec_acc_card_no()); + put("componentValue", platformInfo.getRec_acc_card_no()); }}); // 11. 处理代理商相关数据 if (distributor != null) { // 有代理商的时候,填充代理商的信息 - list.add(new HashMap() {{ + componentList.add(new HashMap() {{ put("componentKey", "distr_company1"); put("componentValue", distributor.getLicense_company()); }}); - list.add(new HashMap() {{ + componentList.add(new HashMap() {{ put("componentKey", "distr_mobile1"); put("componentValue", distributor.getLegal_person_mobile()); }}); - list.add(new HashMap() {{ + componentList.add(new HashMap() {{ put("componentKey", "distr_company2"); put("componentValue", distributor.getLicense_company()); }}); - list.add(new HashMap() {{ + componentList.add(new HashMap() {{ put("componentKey", "distr_bank1"); put("componentValue", distributor.getRec_acc_bank_name()); }}); - list.add(new HashMap() {{ + componentList.add(new HashMap() {{ put("componentKey", "distr_account_number1"); put("componentValue", distributor.getRec_acc_card_no()); }}); - list.add(new HashMap() {{ + componentList.add(new HashMap() {{ put("componentKey", "distr_sign_date1"); put("componentValue", today); }}); @@ -384,24 +384,24 @@ public class EsignContractFillingFileServiceImpl extends BaseServiceImpl() {{ + componentList.add(new HashMap() {{ put("componentKey", "distr_company1"); put("componentValue", "无"); }}); - list.add(new HashMap() {{ + componentList.add(new HashMap() {{ put("componentKey", "distr_mobile1"); put("componentValue", "无"); }}); - list.add(new HashMap() {{ + componentList.add(new HashMap() {{ put("componentKey", "distr_company2"); put("componentValue", "无"); }}); - list.add(new HashMap() {{ + componentList.add(new HashMap() {{ put("componentKey", "distr_bank1"); put("componentValue", "无"); }}); - list.add(new HashMap() {{ + componentList.add(new HashMap() {{ put("componentKey", "distr_account_number1"); put("componentValue", "无"); }}); @@ -409,7 +409,7 @@ public class EsignContractFillingFileServiceImpl extends BaseServiceImpl signPositionMap = getSignPosition(templateId, fileId); if (signPositionMap != null) { if (signPositionMap.get("mch") != null) { - esignContractFillingFile.setMch_sign_position(signPositionMap.get("mch").toString()); + contractFillingFile.setMch_sign_position(signPositionMap.get("mch").toString()); } if (signPositionMap.get("plat") != null) { - esignContractFillingFile.setPlat_sign_position(signPositionMap.get("plat").toString()); + contractFillingFile.setPlat_sign_position(signPositionMap.get("plat").toString()); } if (distributor != null && signPositionMap.get("distr") != null) { // 如果有代理商,则把代理商的印章位置信息写入数据库 - esignContractFillingFile.setDistri_sign_position(signPositionMap.get("distr").toString()); + contractFillingFile.setDistri_sign_position(signPositionMap.get("distr").toString()); } } // 17. 保存合同填充记录并预创建签署流程 - if (esignContractFillingFileService.trySaveRecord(esignContractFillingFile)) { + if (esignContractFillingFileService.trySaveRecord(contractFillingFile)) { successCnt += 1; log.debug("[合同生成] 合同记录保存成功, fileId: {}", fileId); // 预新增一个签署合同记录 boolean preCreateResult = esignContractService.preCreateSignFlow( - esignContractFillingFile.getMobile(), esignContractFillingFile.getDoc_template_id()); + contractFillingFile.getMobile(), contractFillingFile.getDoc_template_id()); log.debug("[合同生成] 预创建签署流程结果: {}, 商家手机号: {}, 模板ID: {}", - preCreateResult, esignContractFillingFile.getMobile(), esignContractFillingFile.getDoc_template_id()); + preCreateResult, contractFillingFile.getMobile(), contractFillingFile.getDoc_template_id()); } else { log.error("[合同生成] 保存合同记录失败, fileId: {}", fileId); } diff --git a/mall-shop/src/main/java/com/suisung/mall/shop/esign/service/impl/EsignContractServiceImpl.java b/mall-shop/src/main/java/com/suisung/mall/shop/esign/service/impl/EsignContractServiceImpl.java index e5147939..142dd5a7 100644 --- a/mall-shop/src/main/java/com/suisung/mall/shop/esign/service/impl/EsignContractServiceImpl.java +++ b/mall-shop/src/main/java/com/suisung/mall/shop/esign/service/impl/EsignContractServiceImpl.java @@ -167,61 +167,77 @@ public class EsignContractServiceImpl extends BaseServiceImpl innerSignFlowCreateByFile(Integer storeId) { + // 1. 参数校验 if (CheckUtil.isEmpty(storeId)) { return Pair.of(false, "缺少必要参数!"); } - // 组织和填充商家店铺的模版数据 + // 2. 组织和填充商家店铺的模版数据 Boolean isFill = esignContractFillingFileService.fillDocTemplate(storeId); if (!isFill) { return Pair.of(false, "合同信息未准备好,请检查商家入驻手续是否已完成!"); } + // 3. 获取商家合同信息 EsignContract esignContract = getEsignContractByStoreId(storeId); if (esignContract == null) { return Pair.of(false, "未找到商家合同信息"); } - // 检查商户入驻信息是否被审核通过 - // 检查店铺是否已经申请过入驻 + // 4. 检查商户入驻信息是否被审核通过 Integer apprStatus = shopMchEntryService.getApprovalStatus(esignContract.getMch_mobile()); if (!CommonConstant.MCH_APPR_STA_PASS.equals(apprStatus)) { return Pair.of(false, "请先审核商家入驻信息"); } - //"{\"docs\":[{\"fileId\":\"ab30d2c5600441f4a7daf512e4d69157\",\"fileName\":\"小发同城平台商户合作协议.pdf\"}],\"signFlowConfig\":{\"signFlowTitle\":\"小发同城平台商户合作协议\",\"signFlowExpireTime\":1746844718000,\"autoFinish\":true,\"notifyUrl\":\"https://mall.gpxscs.cn/asyn/notify\",\"redirectConfig\":{\"redirectUrl\":\"https://mall.gpxscs.cn/\"}},\"signers\":[{\"signConfig\":{\"signOrder\":1},\"noticeConfig\":{\"noticeTypes\":\"1\"},\"signerType\":0,\"psnSignerInfo\":{\"psnAccount\":\"13128997057\",\"psnInfo\":{\"psnName\":\"潘军杰\"}},\"signFields\":[{\"fileId\":\"ab30d2c5600441f4a7daf512e4d69157\",\"normalSignFieldConfig\":{\"signFieldStyle\":1,\"signFieldPosition\":{\"positionPage\":40,\"positionX\":472.3607,\"positionY\":277.19104}}},{\"fileId\":\"ab30d2c5600441f4a7daf512e4d69157\",\"normalSignFieldConfig\":{\"signFieldStyle\":1,\"signFieldPosition\":{\"positionPage\":5,\"positionX\":470.58798,\"positionY\":589.14496}}}]},{\"signConfig\":{\"signOrder\":2},\"noticeConfig\":{\"noticeTypes\":\"1\"},\"signerType\":1,\"orgSignerInfo\":{\"orgName\":\"桂平发发网络有限公司\",\"orgInfo\":{\"orgIDCardNum\":\"91450881MADEQ92533\",\"orgIDCardType\":\"CRED_ORG_USCC\"},\"transactorInfo\":{\"psnAccount\":\"17777525395\",\"psnInfo\":{\"psnName\":\"谢能坤\"}}},\"signFields\":[{\"fileId\":\"ab30d2c5600441f4a7daf512e4d69157\",\"normalSignFieldConfig\":{\"signFieldStyle\":1,\"signFieldPosition\":{\"positionPage\":2,\"positionX\":479.04996,\"positionY\":357.2327}}},{\"fileId\":\"ab30d2c5600441f4a7daf512e4d69157\",\"normalSignFieldConfig\":{\"signFieldStyle\":1,\"signFieldPosition\":{\"positionPage\":5,\"positionX\":255.96832,\"positionY\":588.4553}}}]}]}"; -// esignContractService. + // 5. 获取签署请求参数 String jsonParams = esignContract.getReq_params(); + if (StrUtil.isBlank(jsonParams)) { + return Pair.of(false, "合同请求参数为空"); + } try { - //请求方法 + // 6. 调用E签宝API创建签署流程 EsignRequestType requestType = EsignRequestType.POST; - String apiAddr = "/v3/sign-flow/create-by-file"; - Map header = EsignHttpHelper.signAndBuildSignAndJsonHeader(appId, appSecret, jsonParams, requestType.name(), apiAddr, true); - //发起接口请求 - EsignHttpResponse createByDocTemplate = EsignHttpHelper.doCommHttp(serverUrl, apiAddr, requestType, jsonParams, header, debug); - log.info("发起合同签署流程返回消息:{},{}", createByDocTemplate.getStatus(), createByDocTemplate.getBody()); - if (createByDocTemplate.getStatus() != 200) { - if (createByDocTemplate.getBody() != null) { - JSONObject resBody = JSONUtil.parseObj(createByDocTemplate.getBody()); - log.error("e签宝请求失败,返回状态码:{}, {}", createByDocTemplate.getStatus(), resBody.getStr("message")); - return Pair.of(false, "e签宝请求失败,{}" + resBody.getStr("message")); + Map header = EsignHttpHelper.signAndBuildSignAndJsonHeader( + appId, appSecret, jsonParams, requestType.name(), apiAddr, true); + + EsignHttpResponse response = EsignHttpHelper.doCommHttp( + serverUrl, apiAddr, requestType, jsonParams, header, debug); + + log.info("发起合同签署流程返回消息:status={}, body={}", response.getStatus(), response.getBody()); + + // 7. 处理API响应结果 + if (response.getStatus() != HttpStatus.OK.value()) { + String errorMsg = "E签宝请求失败"; + if (response.getBody() != null) { + try { + JSONObject resBody = JSONUtil.parseObj(response.getBody()); + errorMsg += "," + resBody.getStr("message", "未知错误"); + } catch (Exception parseException) { + log.warn("解析E签宝错误响应失败:{}", response.getBody()); + } } - return Pair.of(false, "e签宝请求失败!"); + log.error("E签宝请求失败,返回状态码:{}", response.getStatus()); + return Pair.of(false, errorMsg); } - JSONObject jsonObject = JSONUtil.parseObj(createByDocTemplate.getBody()); + // 8. 解析成功响应数据 + JSONObject jsonObject = JSONUtil.parseObj(response.getBody()); Integer code = jsonObject.getInt("code"); - String signFlowId = (String) jsonObject.getByPath("data.signFlowId"); + String signFlowId = jsonObject.getByPath("data.signFlowId", String.class); + if (code == null || code != 0 || StrUtil.isBlank(signFlowId)) { - log.error("e签宝请求失败,返回status码:{}", code); - return Pair.of(false, "e签宝请求失败!"); + log.error("E签宝请求失败,返回 code 码:{}", code); + return Pair.of(false, "E签宝请求失败!"); } - //合同签署状态:-1:预备数据阶段;0-等待签署;1-已部分签署;2-已完成(所有签署方完成签署)3-已撤销(发起方撤销签署任务)5-已过期(签署截止日到期后触发)7-已拒签(签署方拒绝签署) - Boolean success = updateContractFlowIdAndFileUrl(esignContract.getId(), signFlowId, CommonConstant.CONTRACT_SIGN_STA_ING, null); + // 9. 更新合同流程状态 + Boolean success = updateContractFlowIdAndFileUrl( + esignContract.getId(), signFlowId, CommonConstant.CONTRACT_SIGN_STA_ING, null); + if (!success) { log.error("更新合同流程状态失败"); return Pair.of(false, "更新合同流程状态失败"); @@ -229,12 +245,13 @@ public class EsignContractServiceImpl extends BaseServiceImpl>>>>> {}", signature); if (!mySignature.equals(signature)) { - log.warn("e签宝异步通知签名校验失败: 计算签名={}, 请求签名={}", mySignature, signature); + log.warn("E签宝异步通知签名校验失败: 计算签名={}, 请求签名={}", mySignature, signature); return ResponseEntity.status(HttpStatus.BAD_REQUEST) .body(new JSONObject().put("code", 400).put("msg", "签名校验失败").toString()); } @@ -288,7 +305,7 @@ public class EsignContractServiceImpl extends BaseServiceImpl * 收到异步通知,签署完成之后,获取合同文件地址,保存并上传到 oss * @@ -837,7 +854,7 @@ public class EsignContractServiceImpl extends BaseServiceImpl createNextSeqPair(String prefix) { - String ymd = DateUtil.format(new Date(), "yyyyMMdd"); - String id = String.format("%s_%s_", prefix, ymd); - ShopNumberSeq shopNumberSeq = this.baseMapper.selectById(id); - if (shopNumberSeq == null) { - shopNumberSeq = new ShopNumberSeq(); - shopNumberSeq.setPrefix(id); - shopNumberSeq.setNumber(1L); - if (!save(shopNumberSeq)) { - return null; + // 参数校验 + if (prefix == null || prefix.trim().isEmpty()) { + return null; + } + + try { + String ymd = DateUtil.format(new Date(), "yyyyMMdd"); + String seqId = String.format("%s_%s_", prefix, ymd); + + // 查询或创建序列记录 + ShopNumberSeq shopNumberSeq = this.baseMapper.selectById(seqId); + if (shopNumberSeq == null) { + shopNumberSeq = new ShopNumberSeq(); + shopNumberSeq.setPrefix(seqId); + shopNumberSeq.setNumber(1L); + if (!save(shopNumberSeq)) { + return null; + } } - } - String order_id = String.format("%s_%s_%s", prefix, ymd, shopNumberSeq.getNumber()); - shopNumberSeq.setPrefix(id); - boolean flag = edit(shopNumberSeq); - if (flag) { - return Pair.of(shopNumberSeq.getNumber(), order_id); - } + // 获取当前序列号 + Long number = shopNumberSeq.getNumber(); + String orderId = String.format("%s_%s_%s", prefix, ymd, number); - return null; + // 增加序列号并更新 + // shopNumberSeq.setNumber(number + 1); + shopNumberSeq.setPrefix(seqId); + return edit(shopNumberSeq) ? Pair.of(number, orderId) : null; + + } catch (Exception e) { + log.error("生成序列号失败,prefix: {}", prefix, e); + return null; + } } + /** * 得到下一个Id * diff --git a/mall-shop/src/main/java/com/suisung/mall/shop/order/service/impl/ShopOrderBaseServiceImpl.java b/mall-shop/src/main/java/com/suisung/mall/shop/order/service/impl/ShopOrderBaseServiceImpl.java index aece29b9..13a0e99d 100644 --- a/mall-shop/src/main/java/com/suisung/mall/shop/order/service/impl/ShopOrderBaseServiceImpl.java +++ b/mall-shop/src/main/java/com/suisung/mall/shop/order/service/impl/ShopOrderBaseServiceImpl.java @@ -6421,7 +6421,7 @@ public class ShopOrderBaseServiceImpl extends BaseServiceImpl seqPair = shopNumberSeqService.createNextSeqPair(type_code);// 位数的序号: DD_20251205_1 2025-12-05 1 + Pair seqPair = shopNumberSeqService.createNextSeqPair(type_code);// 位数的序号: DD_20251205_12-> pair 12, 2025-12-05 String order_id = seqPair.getSecond(); Long seqNo = seqPair.getFirst(); // 序号: DD_20251205_1 得出 1 RootContext.bind(xid);