e签宝发起签署流程,多个方法调整

This commit is contained in:
Jack 2025-03-14 00:08:50 +08:00
parent 7ab60e5f57
commit 2914644441
7 changed files with 112 additions and 260 deletions

View File

@ -62,6 +62,9 @@ public class EsignContractFillingFile implements Serializable {
@ApiModelProperty(value = "乙方(平台方)签署印章XY位置")
private String plat_sign_position;
@ApiModelProperty(value = "代理商签署印章XY位置")
private String distri_sign_position;
@ApiModelProperty(value = "合同排序")
private Integer seq;

View File

@ -152,6 +152,9 @@ public class ShopMerchEntry implements Serializable {
@ApiModelProperty(value = "审核时无效字段集合,如:[`bank_name`,`license_number`,…]")
private String approval_invalid_col;
@ApiModelProperty(value = "商家的代理商ID")
private Long distributor_id;
@ApiModelProperty(value = "合同签署状态0-无任何签署1-一方签署2-双方已签署;")
private Integer signed_status;

View File

@ -10,7 +10,8 @@ package com.suisung.mall.shop.esign.service;
import cn.hutool.json.JSONArray;
import com.suisung.mall.common.modules.esign.EsignContractFillingFile;
import org.springframework.data.util.Pair;
import java.util.Map;
public interface EsignContractFillingFileService {
@ -30,7 +31,7 @@ public interface EsignContractFillingFileService {
* @param fileId
* @return
*/
Pair<JSONArray, JSONArray> getSignPosition(String docTemplateId, String fileId);
Map<String, JSONArray> getSignPosition(String docTemplateId, String fileId);
/**
* 根据注册手机号禁用合同

View File

@ -16,6 +16,14 @@ import org.springframework.data.util.Pair;
*/
public interface EsignPlatformInfoService {
/**
* 根据ID获取代理商信息
*
* @param id
* @return
*/
EsignPlatformInfo getDistributorInfoById(Long id);
/**
* 根据分类和营业执照号获取平台方信息
*

View File

@ -35,7 +35,6 @@ import com.suisung.mall.shop.store.service.ShopMerchEntryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Lazy;
import org.springframework.data.util.Pair;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
@ -113,6 +112,9 @@ public class EsignContractFillingFileServiceImpl extends BaseServiceImpl<EsignCo
return null;
}
// 代理商信息
EsignPlatformInfo distributor = esignPlatformInfoService.getDistributorInfoById(shopMerchEntry.getDistributor_id());
String apiaddr = "/v3/files/create-by-doc-template";
EsignRequestType requestType = EsignRequestType.POST;
@ -248,6 +250,37 @@ public class EsignContractFillingFileServiceImpl extends BaseServiceImpl<EsignCo
put("componentValue", finalEsignPlatformInfo.getEmail());
}});
// 代理商相关
if (distributor != null) {
// 有代理商的时候才填充代理商的信息
list.add(new HashMap<String, Object>() {{
put("componentKey", "distr_company1");
put("componentValue", distributor.getLicense_company());
}});
list.add(new HashMap<String, Object>() {{
put("componentKey", "distr_mobile1");
put("componentValue", distributor.getLegal_person_mobile());
}});
list.add(new HashMap<String, Object>() {{
put("componentKey", "distr_company2");
put("componentValue", distributor.getLicense_company());
}});
list.add(new HashMap<String, Object>() {{
put("componentKey", "distr_bank1");
put("componentValue", distributor.getRec_acc_bank_name());
}});
list.add(new HashMap<String, Object>() {{
put("componentKey", "distr_account_number1");
put("componentValue", distributor.getRec_acc_card_no());
}});
list.add(new HashMap<String, Object>() {{
put("componentKey", "distr_sign_date1");
put("componentValue", today);
}});
}
fillJson.put("components", list);
String jsonParma = fillJson.toString();
@ -288,12 +321,22 @@ public class EsignContractFillingFileServiceImpl extends BaseServiceImpl<EsignCo
esignContractFillingFile.setStatus(CommonConstant.Enable);
// 获取印章的位置信息写入数据库
Pair<JSONArray, JSONArray> signPositionPair = getSignPosition(templateId, fileId);
if (signPositionPair != null) {
esignContractFillingFile.setMch_sign_position(signPositionPair.getFirst().toString());
esignContractFillingFile.setPlat_sign_position(signPositionPair.getSecond().toString());
Map<String, JSONArray> signPositionMap = getSignPosition(templateId, fileId);
if (signPositionMap != null) {
if (distributor != null && signPositionMap.get("mch") != null) {
esignContractFillingFile.setMch_sign_position(signPositionMap.get("mch").toString());
}
if (distributor != null && signPositionMap.get("plat") != null) {
esignContractFillingFile.setPlat_sign_position(signPositionMap.get("plat").toString());
}
if (distributor != null && signPositionMap.get("distr") != null) {
// 如果有代理商则把代理商的印章位置信息写入数据库
esignContractFillingFile.setDistri_sign_position(signPositionMap.get("distr").toString());
}
}
if (esignContractFillingFileService.trySaveRecord(esignContractFillingFile)) {
successCnt += 1;
@ -317,7 +360,7 @@ public class EsignContractFillingFileServiceImpl extends BaseServiceImpl<EsignCo
* @return
*/
@Override
public Pair<JSONArray, JSONArray> getSignPosition(String docTemplateId, String fileId) {
public Map<String, JSONArray> getSignPosition(String docTemplateId, String fileId) {
String apiaddr = "/v3/doc-templates/" + docTemplateId;
//请求参数body体,json格式get或者delete请求时jsonString传空json:"{}"或者null
@ -341,6 +384,7 @@ public class EsignContractFillingFileServiceImpl extends BaseServiceImpl<EsignCo
// 处理符合的数据
JSONArray retMchArr = new JSONArray();
JSONArray retPlatArr = new JSONArray();
JSONArray retDistrArr = new JSONArray();
for (JSONObject component : components.jsonIter()) {
String componentName = component.getStr("componentName");
String customBizNum = StringUtils.genLklOrderNo(4);
@ -370,264 +414,34 @@ public class EsignContractFillingFileServiceImpl extends BaseServiceImpl<EsignCo
signFieldPosition.put("positionY", component.getByPath("componentPosition.componentPositionY"));
signFields.putByPath("normalSignFieldConfig.signFieldPosition", signFieldPosition);
retPlatArr.add(signFields);
} else if (componentName.equals("代理商签署区")) {
// 丙方签署区
JSONObject signFields = new JSONObject();
signFields.put("customBizNum", customBizNum);
signFields.put("fileId", fileId);
signFields.put("normalSignFieldConfig", component.getJSONArray("signFields"));
signFields.putByPath("normalSignFieldConfig.signFieldStyle", 1); //签章区样式 1 - 单页签章2 - 骑缝签章点击了解 骑缝盖章
JSONObject signFieldPosition = new JSONObject();
signFieldPosition.put("positionPage", component.getByPath("componentPosition.componentPageNum"));
signFieldPosition.put("positionX", component.getByPath("componentPosition.componentPositionX"));
signFieldPosition.put("positionY", component.getByPath("componentPosition.componentPositionY"));
signFields.putByPath("normalSignFieldConfig.signFieldPosition", signFieldPosition);
retDistrArr.add(signFields);
}
}
return Pair.of(retMchArr, retPlatArr);
return new HashMap<String, JSONArray>() {{
put("mch", retMchArr);
put("plat", retPlatArr);
put("distr", retDistrArr);
}};
} catch (EsignDemoException e) {
log.error("获取模版的印章XY位置数据失败", e);
return null;
}
}
/**
* 更加双方营业执照号码填充合同模版生成合同文件地址
*
* @param mchLicenseNumber 入驻商家(甲方)的营业执照号
* @param platLicenseNumber 平台方代理商方乙方营业执照号
* @return
*/
public Boolean fillDocTemplate2(String mchLicenseNumber, String platLicenseNumber) {
// 获取平台方的信息
EsignPlatformInfo esignPlatformInfo = new EsignPlatformInfo();
if (StrUtil.isNotEmpty(platLicenseNumber)) {
esignPlatformInfo = esignPlatformInfoService.getEsignPlatformInfo(null, platLicenseNumber);
}
if (ObjectUtils.isEmpty(esignPlatformInfo)) {
esignPlatformInfo = esignPlatformInfoService.getEsignPlatformInfo(0, "");
}
if (ObjectUtils.isEmpty(esignPlatformInfo)) {
log.error("缺少平台方(代理商方)信息");
return null;
}
// 获取入驻商家(审批通过的)的信息
ShopMerchEntry shopMerchEntry = shopMerchEntryService.getShopMerchEntryByLicenseNumber("", mchLicenseNumber, CommonConstant.MCH_APPR_STA_PASS);
if (shopMerchEntry == null) {
log.error("缺少商家入驻信息");
return null;
}
String apiaddr = "/v3/files/create-by-doc-template";
EsignRequestType requestType = EsignRequestType.POST;
// 获取平台方代理商方合同模版信息
JSONArray templates = JSONUtil.parseArray(esignPlatformInfo.getDoc_template());
if (ObjectUtils.isEmpty(templates) || templates.size() != 3) {
log.error("缺少平台方(代理商方)合同模版信息");
return null;
}
String today = DateUtil.format(new Date(), "yyyy年MM月dd日");
String mchCompany = shopMerchEntry.getBiz_license_company();
String platCompany = esignPlatformInfo.getLicense_company();
String legalPersonName = shopMerchEntry.getLegal_person_name();
String mchMobile = shopMerchEntry.getLogin_mobile();
String contractNumber = StringUtils.genLklOrderNo(4);
int successCnt = 0;
// 模版文件里有三份合同顺序排列的: 1.平台商户入驻服务框架协议 2.小发同城服务费结算 3.结算授权委托书
for (Object template : templates) {
// 从商家信息里获取模版的信息
JSONObject templateJson = (JSONObject) template;
String templateId = templateJson.getStr("template_id");
String fileName = templateJson.getStr("template_name");
int seq = templateJson.getInt("seq");
// 获取填充模版的数据
JSONObject fillJson = new JSONObject();
fillJson.put("docTemplateId", templateId)
.put("fileName", fileName);
if (seq == 1) {
JSONArray list = new JSONArray();
EsignPlatformInfo finalEsignPlatformInfo = esignPlatformInfo;
list.add(new HashMap<String, Object>() {{
put("componentKey", "mch_addr");
put("componentValue", "《平台商户入驻服务框架协议》和《小发同城服务费结算》");
}});
for (int i = 1; i <= 3; i++) {
int finalI = i;
list.add(new HashMap<String, Object>() {{
put("componentKey", "legal_person_name" + finalI);
put("componentValue", legalPersonName);
}});
}
list.add(new HashMap<String, Object>() {{
put("componentKey", "legal_person_id_number");
put("componentValue", shopMerchEntry.getLegal_person_id_number());
}});
list.add(new HashMap<String, Object>() {{
put("componentKey", "legal_person_mobile");
put("componentValue", shopMerchEntry.getLegal_person_mobile());
}});
list.add(new HashMap<String, Object>() {{
put("componentKey", "legal_person_mobile2");
put("componentValue", shopMerchEntry.getLegal_person_mobile());
}});
list.add(new HashMap<String, Object>() {{
put("componentKey", "plat_mobile");
put("componentValue", finalEsignPlatformInfo.getLegal_person_mobile());
}});
list.add(new HashMap<String, Object>() {{
put("componentKey", "plat_email");
put("componentValue", finalEsignPlatformInfo.getEmail());
}});
list.add(new HashMap<String, Object>() {{
put("componentKey", "mch_sign_date");
put("componentValue", today);
}});
list.add(new HashMap<String, Object>() {{
put("componentKey", "plat_sign_date");
put("componentValue", today);
}});
for (int i = 1; i <= 14; i++) {
int finalI = i;
list.add(new HashMap<String, Object>() {{
put("componentKey", "mch_name" + finalI);
put("componentValue", mchCompany);
}});
}
fillJson.put("components", list);
} else if (seq == 2) {
// 小发同城服务费结算
JSONArray list = new JSONArray();
list.add(new HashMap<String, Object>() {{
put("componentKey", "mch_store_name");
put("componentValue", shopMerchEntry.getStore_name());
}});
list.add(new HashMap<String, Object>() {{
put("componentKey", "mch_name15");
put("componentValue", mchCompany);
}});
list.add(new HashMap<String, Object>() {{
put("componentKey", "mch_sign_date2");
put("componentValue", today);
}});
fillJson.put("components", list);
} else if (seq == 3) {
JSONArray list = new JSONArray();
list.add(new HashMap<String, Object>() {{
put("componentKey", "plat_name1");
put("componentValue", platCompany + "和代理商");
}});
for (int i = 2; i <= 3; i++) {
int finalI = i;
list.add(new HashMap<String, Object>() {{
put("componentKey", "plat_name" + finalI);
put("componentValue", platCompany);
}});
}
list.add(new HashMap<String, Object>() {{
put("componentKey", "contracts");
put("componentValue", "《平台商户入驻服务框架协议》和《小发同城服务费结算》");
}});
list.add(new HashMap<String, Object>() {{
put("componentKey", "rule_no");
put("componentValue", 3);
}});
list.add(new HashMap<String, Object>() {{
put("componentKey", "mch_name16");
put("componentValue", "本商户");
}});
list.add(new HashMap<String, Object>() {{
put("componentKey", "mch_name17");
put("componentValue", mchCompany);
}});
list.add(new HashMap<String, Object>() {{
put("componentKey", "mch_ratio");
put("componentValue", shopMerchEntry.getSplit_ratio());
}});
list.add(new HashMap<String, Object>() {{
put("componentKey", "settlement_method");
put("componentValue", shopMerchEntry.getSettlement_method());
}});
list.add(new HashMap<String, Object>() {{
put("componentKey", "plat_choice");
put("componentValue", true);
}});
list.add(new HashMap<String, Object>() {{
put("componentKey", "legal_person_name4");
put("componentValue", shopMerchEntry.getLegal_person_name());
}});
list.add(new HashMap<String, Object>() {{
put("componentKey", "mch_sign_date3");
put("componentValue", today);
}});
fillJson.put("components", list);
}
String jsonParma = fillJson.toString();
//生成签名鉴权方式的的header
Map<String, String> header = null;
try {
header = EsignHttpHelper.signAndBuildSignAndJsonHeader(appId, appSecret, jsonParma, requestType.name(), apiaddr, debug);
//发起接口请求
EsignHttpResponse createByDocTemplate = EsignHttpHelper.doCommHttp(serverUrl, apiaddr, requestType, jsonParma, header, debug);
log.info("合同生成数据:{}", createByDocTemplate);
if (createByDocTemplate.getStatus() != 200) {
return false;
}
EsignContractFillingFile esignContractFillingFile = new EsignContractFillingFile();
JSONObject jsonObject = JSONUtil.parseObj(createByDocTemplate.getBody()).getJSONObject("data");
esignContractFillingFile.setUnsigned_contract_url(jsonObject.getStr("fileDownloadUrl"));
// 把合同文件 url 上传到cos服务器
String cosFileName = TENGXUN_DEFAULT_DIR.concat("/").concat("contract")
.concat("/").concat(mchLicenseNumber).concat("/")
.concat(jsonObject.getStr("fileId")).concat(".pdf");
// 上传到cos服务器
String localFileUrl = ossService.uploadObject4OSS(esignContractFillingFile.getUnsigned_contract_url(), cosFileName);
esignContractFillingFile.setUnsigned_contract_local_url(localFileUrl);
esignContractFillingFile.setDoc_template_id(templateId);
esignContractFillingFile.setContract_number(contractNumber + seq);
esignContractFillingFile.setContract_name(fileName);
esignContractFillingFile.setStore_id(contractNumber);
esignContractFillingFile.setMobile(mchMobile);
esignContractFillingFile.setDoc_template_filling_values(jsonParma);
esignContractFillingFile.setSeq(seq);
esignContractFillingFile.setStatus(CommonConstant.Enable);
if (esignContractFillingFileService.trySaveRecord(esignContractFillingFile)) {
successCnt += 1;
}
} catch (EsignDemoException e) {
throw new RuntimeException(e);
}
}
return successCnt == 3;
}
/**
* 根据注册手机号禁用合同

View File

@ -422,7 +422,7 @@ public class EsignContractServiceImpl extends BaseServiceImpl<EsignContractMappe
// 未签合同文件ID
String fileId = esignContractFillingFile.getFile_id();
// 组织生成签署合同的请求参数
// (重要)组织生成签署合同的请求参数
String reqParams = buildSignReqParams(shopMerchEntry, esignPlatformInfo, esignContractFillingFile);
// 保存签署合同记录
@ -490,7 +490,7 @@ public class EsignContractServiceImpl extends BaseServiceImpl<EsignContractMappe
//请求方法
EsignRequestType requestType = EsignRequestType.GET;
//生成签名鉴权方式的的header
Map<String, String> header = EsignHttpHelper.signAndBuildSignAndJsonHeader(appId, appSecret, null, requestType.name(), apiAddr, true);
Map<String, String> header = EsignHttpHelper.signAndBuildSignAndJsonHeader(appId, appSecret, null, requestType.name(), apiAddr, debug);
//发起接口请求
EsignHttpResponse esignHttpResponse = EsignHttpHelper.doCommHttp(serverUrl, apiAddr, requestType, null, header, debug);
@ -512,7 +512,6 @@ public class EsignContractServiceImpl extends BaseServiceImpl<EsignContractMappe
return files.getJSONObject(0).getStr("downloadUrl");
} catch (EsignDemoException e) {
// throw new RuntimeException(e);
log.error(e.getMessage(), e);
return null;
}
@ -616,6 +615,8 @@ public class EsignContractServiceImpl extends BaseServiceImpl<EsignContractMappe
// 加入乙方平台方信息
signers.add(platSigner);
// 丙方(代理商)信息
reqParams.put("signers", signers);
return reqParams.toString();

View File

@ -25,6 +25,28 @@ import java.util.List;
@Service
public class EsignPlatformInfoServiceImpl extends BaseServiceImpl<EsignPlatformInfoMapper, EsignPlatformInfo> implements EsignPlatformInfoService {
/**
* 根据ID获取代理商信息
*
* @param id
* @return
*/
@Override
public EsignPlatformInfo getDistributorInfoById(Long id) {
if (ObjectUtils.isEmpty(id)) {
return null;
}
QueryWrapper<EsignPlatformInfo> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("id", id).gt("type", 0).eq("status", CommonConstant.Enable);
List<EsignPlatformInfo> esignPlatformInfos = list(queryWrapper);
if (CollectionUtil.isEmpty(esignPlatformInfos)) {
return null;
}
return esignPlatformInfos.get(0);
}
/**
* 根据分类和营业执照号获取平台方信息
*