apzl_leasing/src/com/tenwa/app/manage/qiyuesuo/v2/ContractSignVtwoUtils.java
2021-04-22 18:53:51 +08:00

667 lines
34 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.tenwa.app.manage.qiyuesuo.v2;
import com.alibaba.fastjson.JSONObject;
import com.amarsoft.are.jbo.JBOException;
import com.amarsoft.awe.util.ASResultSet;
import com.amarsoft.awe.util.SqlObject;
import com.amarsoft.awe.util.Transaction;
import com.amarsoft.dict.als.cache.CacheLoaderFactory;
import com.tenwa.app.manage.qiyuesuo.v2.ContractSignEnums.ContractSignTypeEnum;
import com.tenwa.app.manage.qiyuesuo.v2.ContractSignEnums.SignatoryTypeEnum;
import com.qiyuesuo.sdk.v2.SdkClient;
import com.qiyuesuo.sdk.v2.bean.*;
import com.qiyuesuo.sdk.v2.http.StreamFile;
import com.qiyuesuo.sdk.v2.json.JSONUtils;
import com.qiyuesuo.sdk.v2.param.SignParam;
import com.qiyuesuo.sdk.v2.request.*;
import com.qiyuesuo.sdk.v2.response.ContractPageResult;
import com.qiyuesuo.sdk.v2.response.DocumentAddResult;
import com.qiyuesuo.sdk.v2.response.SdkResponse;
import com.qiyuesuo.sdk.v2.utils.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.CollectionUtils;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;
public class ContractSignVtwoUtils {
private static final Logger logger = LoggerFactory.getLogger(ContractSignVtwoUtils.class);
private static final ResourceBundle resourceBunlde = ResourceBundle.getBundle("qiyuesuo");
//深圳公司参数
private static final String sZ_Url = resourceBunlde.getString("SZ_Url");
private static final String sZ_Key = resourceBunlde.getString("SZ_Key");
private static final String sZ_Secret = resourceBunlde.getString("SZ_Secret");
private static final String sZ_OfficialSealId = resourceBunlde.getString("SZ_OfficialSealId");
private static final String sZ_CompanyName = resourceBunlde.getString("SZ_CompanyName");
//天津公司参数
private static final String tJ_Url = resourceBunlde.getString("TJ_Url");
private static final String tJ_Key = resourceBunlde.getString("TJ_Key");
private static final String tJ_Secret = resourceBunlde.getString("TJ_Secret");
private static final String tJ_OfficialSealId = resourceBunlde.getString("TJ_OfficialSealId");
private static final String tJ_CompanyName = resourceBunlde.getString("TJ_CompanyName");
//子公司参数(辉煌)
public static final String HH_CHILD_SUBJECT_TYPE = "0";
private static final String hH_CompanyName = resourceBunlde.getString("HH_CompanyName");
private static final String hH_OfficialSealId = resourceBunlde.getString("HH_OfficialSealId");
//子公司参数(凯捷)
public static final String KJ_CHILD_SUBJECT_TYPE = "1";
private static final String kJ_CompanyName = resourceBunlde.getString("KJ_CompanyName");
private static final String kJ_OfficialSealId = resourceBunlde.getString("KJ_OfficialSealId");
private SdkClient getSdkClient(String subjectId){
if (SubjectConstant.SZ_SUBJECT_ID.equals(subjectId)) {
return new SdkClient(sZ_Url, sZ_Key, sZ_Secret);
} else if (SubjectConstant.TJ_SUBJECT_ID.equals(subjectId)) {
return new SdkClient(sZ_Url, sZ_Key, sZ_Secret);//应客户要求,现在都是以深圳主体发起
}
return null;
}
/**
* 简单公司盖章
* @param qysParams
* @return
* @throws Exception
*/
public JSONObject sign(QYSParams qysParams) throws Exception {
JSONObject resJson = null;
try{
logger.info("ContractSignVtwoUtils#sign 开始调用契约锁合同签章流程 20210207");
logger.info("ContractSignVtwoUtils#sign 校验参数信息 20210207");
String checkRes = checkParams(qysParams);
if(null != checkRes){
logger.error("ContractSignVtwoUtils#sign 校验参数信息【失败】--errorMsg=" + checkRes);
throw new Exception(checkRes);
}
//获取契约锁客户端,等待发起接口调用
SdkClient client = this.getSdkClient(qysParams.getSubjectId());
// 1、创建合同
// 1.4、调用契约锁【创建合同】接口
logger.info("ContractSignVtwoUtils#sign 创建合同 20201224");
SdkResponse<Contract> createContract = this.createContract(qysParams, client);
logger.info("ContractSignVtwoUtils#sign 创建合同【结束】 20201224");
Long contractId = createContract.getResult().getId();
List<Signatory> signatoryList = createContract.getResult().getSignatories();
//赋值更新Volist为发起合同做准备
updateVoList(signatoryList, qysParams);
//添加本地生成的合同文件
logger.info("ContractSignVtwoUtils#sign 添加本地生成的合同文件 20201224");
SdkResponse<DocumentAddResult> addDocumentByFile = this.addDocumentByFile(qysParams, contractId, client);
logger.info("ContractSignVtwoUtils#sign 添加本地生成的合同文件【结束】 20201224");
Long documentId = addDocumentByFile.getResult().getDocumentId();
//发起合同
logger.info("ContractSignVtwoUtils#sign 发起合同");
this.send(qysParams, contractId, documentId, client);
logger.info("ContractSignVtwoUtils#sign 发起合同【结束】");
//调用公司盖章
logger.info("ContractSignVtwoUtils#sign 调用公司盖章");
this.companySealSign(qysParams.getSubjectId(), contractId, client);
logger.info("ContractSignVtwoUtils#sign 调用公司盖章【结束】");
logger.info("ContractSignVtwoUtils#sign 合同下载");
String downStatus = this.contractDownload(qysParams, documentId, client);
logger.info("ContractSignVtwoUtils#sign 合同下载【结束】");
logger.info("ContractSignVtwoUtils#sign 合同下载log===" + downStatus);
resJson = new JSONObject();
resJson.put("contractId", contractId);
resJson.put("documentId", documentId);
}catch (Exception e){
logger.error("ContractSignVtwoUtils#sign error={} ", e.getMessage(), e);
throw new Exception(e);
}
return resJson;
}
/**
* 校验参数信息
* @param qysParams
* @return
*/
private String checkParams(QYSParams qysParams){
if(StringUtils.isEmpty(qysParams.getFileName())){
return "qysParams.fileName 不能为空";
}else if (StringUtils.isEmpty(qysParams.getSubjectId())){
return "qysParams.subjectId 不能为空";
}else if (StringUtils.isEmpty(qysParams.getFilePath())){
return "qysParams.filePath 不能为空";
}else if (StringUtils.isEmpty(qysParams.getTempId())){
return "qysParams.tempId 不能为空";
}else if (null == qysParams.getContractSignTypeEnum()){
return "qysParams.contractSignTypeEnum 不能为空";
}else if (!SubjectConstant.SZ_SUBJECT_ID.equals(qysParams.getSubjectId()) && !SubjectConstant.TJ_SUBJECT_ID.equals(qysParams.getSubjectId())){
return "qysParams.subjectId 当前主体id不存在";
}else if(ContractSignTypeEnum.SIGNATURE_JOINT.getSubType().equals(qysParams.getContractSignTypeEnum().getSubType())){//联合租赁
if(StringUtils.isEmpty(qysParams.getFileName())) {
return "qysParams.childSubject 联合租赁时,子公司类型不能为空";
}else if (!HH_CHILD_SUBJECT_TYPE.equals(qysParams.getChildSubject()) && !KJ_CHILD_SUBJECT_TYPE.equals(qysParams.getChildSubject())) {
return "qysParams.childSubject 联合租赁时,当前子公司类型不存在";
}
}else if (ContractSignTypeEnum.ELECTRONIC_JOINT.getType().equals(qysParams.getContractSignTypeEnum().getType())){//电子签约 需要包含用户信息
return "qysParams.list 电子签约时,签署方信息应包含用户信息,不能为空";
}
return null;
}
/**
* 创建合同
* @param qysParams
* @return
* @throws Exception
*/
public SdkResponse<Contract> createContract(QYSParams qysParams, SdkClient client) throws Exception {
logger.info("ContractSignVtwoUtils#createContract 保险委托授权书 -- 创建合同 20201223");
logger.info("ContractSignVtwoUtils#createContract 【开始】遍历签署方信息");
//公司签署方
String response = null;
try {
Contract contract = new Contract();
//合同主题(合同名称)
contract.setSubject(qysParams.getFileName());
//是否顺序签署默认为true
contract.setOrdinal(false);
//是否发起合同;发起合同后不能再进行添加文档、指定签署位置等操作
contract.setSend(false);
// 1.1、初始化生成公司签署方信息
List<SignatoryVo> signatoryVos = initCompanySignatoryVoList(qysParams);
// 1.2、判断是否包含用户信息
if(CollectionUtils.isEmpty(qysParams.getList())){
qysParams.setList(signatoryVos);
}else {
qysParams.getList().addAll(signatoryVos);
}
// 1.3、整理符合契约锁规范的签署方信息
List<Signatory> signatories = signatoryInitList(qysParams);
contract.setSignatories(signatories);
logger.info("ContractSignVtwoUtils#createContract 开始创建合同 contract={} ", JSONUtils.toJson(contract));
response = client.service(new ContractDraftRequest(contract));
logger.info("ContractSignVtwoUtils#createContract 创建合同结束 response={} ", response);
} catch (Exception e) {
logger.error("ContractSignVtwoUtils#createContract error={} ", e.getMessage(), e);
throw new Exception("创建合同草稿请求服务/器失败,失败原因:" + e.getMessage());
}
SdkResponse<Contract> sdkResponse = JSONUtils.toQysResponse(response, Contract.class);
if (!sdkResponse.getCode().equals(0)) {
logger.error("ContractSignVtwoUtils#createContract 契约锁返回错误 sdkResponse.getMessage={} ", sdkResponse.getMessage());
throw new Exception("创建合同草稿失败,失败原因:" + sdkResponse.getMessage());
}
return sdkResponse;
}
/**
* 初始化签署方的公司信息
* @param qysParams
* @return
*/
public List<SignatoryVo> initCompanySignatoryVoList(QYSParams qysParams){
logger.info("ContractSignVtwoUtils#initBaseCompanySignatoryList 开始初始化签署方信息subjectId={}", qysParams.getSubjectId());
List<SignatoryVo> signatories = new ArrayList<>();
//初始化当前公司签署方信息
SignatoryVo signatoryVo = createCompanySignatoryVo(qysParams.getSubjectId());
signatories.add(signatoryVo);
if(ContractSignTypeEnum.SIGNATURE_JOINT.getSubType().equals(qysParams.getContractSignTypeEnum().getSubType())){//联合租赁
SignatoryVo subCompany = new SignatoryVo();
subCompany.setSignatoryType(SignatoryTypeEnum.SUB_COMPANY.getType());
subCompany.setSignatorySubType(SignatoryTypeEnum.SUB_COMPANY.getSubType());
subCompany.setMobile("12599998888");
Action action = new Action();
action.setType(SignatoryTypeEnum.SUB_COMPANY.getType());
if(qysParams.getChildSubject().equals(HH_CHILD_SUBJECT_TYPE)){ //当前联合租赁为卡尔时
logger.info("ContractSignVtwoUtils#initBaseCompanySignatoryList 当前签署类型为联合签约【卡尔】");
subCompany.setName(hH_CompanyName);
action.setName(hH_CompanyName);
action.setSealId(new Long(hH_OfficialSealId));
logger.info("ContractSignVtwoUtils#initBaseCompanySignatoryList 加载联合签约信息【卡尔】");
}else if(qysParams.getChildSubject().equals(KJ_CHILD_SUBJECT_TYPE)){ //当前联合租赁为凯捷时
logger.info("ContractSignVtwoUtils#initBaseCompanySignatoryList 当前签署类型为联合签约【凯捷】");
subCompany.setName(kJ_CompanyName);
action.setName(kJ_CompanyName);
action.setSealId(new Long(kJ_OfficialSealId));
logger.info("ContractSignVtwoUtils#initBaseCompanySignatoryList 加载联合签约信息【凯捷】");
}
subCompany.addAction(action);
signatories.add(subCompany);
}
logger.info("ContractSignVtwoUtils#initBaseCompanySignatoryList 初始化签署方信息【结束】signatories={}", JSONUtils.toJson(signatories));
return signatories;
}
/**
* 初始化当前主体的签署方公司信息
* @param subjectId
* @return
*/
private SignatoryVo createCompanySignatoryVo(String subjectId){
SignatoryVo signatoryVo = new SignatoryVo();
signatoryVo.setSignatoryType(SignatoryTypeEnum.PARENT_COMPANY.getType());
signatoryVo.setSignatorySubType(SignatoryTypeEnum.PARENT_COMPANY.getSubType());
signatoryVo.setMobile("12599996666");
Action action = new Action();
action.setType(SignatoryTypeEnum.PARENT_COMPANY.getType());
if(SubjectConstant.SZ_SUBJECT_ID.equals(subjectId)){
signatoryVo.setName(sZ_CompanyName);
action.setName(sZ_CompanyName);
action.setSealId(new Long(sZ_OfficialSealId));
}else if (SubjectConstant.TJ_SUBJECT_ID.equals(subjectId)){
signatoryVo.setName(tJ_CompanyName);
action.setName(tJ_CompanyName);
action.setSealId(new Long(tJ_OfficialSealId));
}
signatoryVo.addAction(action);
return signatoryVo;
}
/**
* 合同签署方信息转换为契约锁可调用信息
* @param qysParams
* @return List
*/
private List<Signatory> signatoryInitList(QYSParams qysParams) throws Exception{
logger.info("ContractSignVtwoUtils#signatoryInitList 合同签署方信息转换subjectId={}", qysParams.getSubjectId());
//初始化公司信息
List<Signatory> list = new ArrayList<>();
boolean checkData = true;//参数是否符合要求
if(ContractSignTypeEnum.ELECTRONIC_JOINT.getType().equals(qysParams.getContractSignTypeEnum().getType())){//电子签约 需要包含用户信息
logger.info("ContractSignVtwoUtils#signatoryInitList 合同签署方信息 list={}", JSONUtils.toJson(list));
logger.info("ContractSignVtwoUtils#signatoryInitList 合同签署方信息【用户信息】signatories={}", JSONUtils.toJson(qysParams.getList()));
if(CollectionUtils.isEmpty(qysParams.getList())){
logger.error("ContractSignVtwoUtils#signatoryInitList 参数校验失败 电子签约 不包含签署方信息");
throw new Exception(" 参数校验失败 电子签约 不包含签署方信息 ");
}
for(SignatoryVo signatoryVo : qysParams.getList()) {
if (SignatoryTypeEnum.PERSON_CZ.getType().equals(signatoryVo.getSignatoryType())) {//电子签约 && 个人
if (SignatoryTypeEnum.PERSON_CZ.getSubType().equals(signatoryVo.getSignatorySubType())) {//电子签约 && 承租人信息
checkData = false;
}
//个人信息转化
Signatory signatory = signatoryPersonInit(signatoryVo);
list.add(signatory);
}
}
if(checkData){
logger.error("ContractSignVtwoUtils#signatoryInitList 参数校验失败 电子签约 不包含承租人信息");
throw new Exception("ContractSignVtwoUtils#signatoryInitList 参数校验失败 电子签约 不包含承租人信息 ");
}
}
for(SignatoryVo signatoryVo : qysParams.getList()) {
if (SignatoryTypeEnum.PARENT_COMPANY.getType().equals(signatoryVo.getSignatoryType())) {//公司信息
//公司信息转化
Signatory signatory = signatoryCompanyInit(signatoryVo, qysParams.getSubjectId());
list.add(signatory);
}
}
logger.info("ContractSignVtwoUtils#signatoryInitList 初始化签署方信息【结束】list={}", JSONUtils.toJson(list));
return list;
}
/**
* 初始化为契约锁个人签署方信息
* @param signatoryVo
* @return
* @throws Exception
*/
private Signatory signatoryPersonInit(SignatoryVo signatoryVo) throws Exception{
Signatory personSignatory = new Signatory();
personSignatory.setTenantType(signatoryVo.getSignatoryType());
personSignatory.setTenantName(signatoryVo.getName());
personSignatory.setReceiver(new User(signatoryVo.getSignatorySubType(), signatoryVo.getMobile(), "MOBILE"));
return personSignatory;
}
/**
* 初始化为契约锁公司签署方信息
* @param signatoryVo
* @return
* @throws Exception
*/
private Signatory signatoryCompanyInit(SignatoryVo signatoryVo, String subjectId) throws Exception{
Signatory companySignatory = new Signatory();
companySignatory.setTenantType(signatoryVo.getSignatoryType());
companySignatory.setTenantName(signatoryVo.getName());
if(!SubjectConstant.SZ_SUBJECT_ID.equals(subjectId)){//如果当前的订单不是深圳,要增加接收方信息
companySignatory.setReceiver(new User(signatoryVo.getSignatorySubType(), signatoryVo.getMobile(), "MOBILE"));
}
companySignatory.setActions(signatoryVo.getActions());
return companySignatory;
}
/**
* 用文件添加合同文件
* @param qysParams
* @param contractId
* @return
* @throws Exception
*/
public SdkResponse<DocumentAddResult> addDocumentByFile(QYSParams qysParams, Long contractId, SdkClient client)throws Exception {
logger.info("ContractSignVtwoUtils#addDocumentByFile 本地文件转化为文件流 filePath={} ", qysParams.getFilePath());
// 进入本地文件
StreamFile file = new StreamFile(new FileInputStream(new File(qysParams.getFilePath())));
logger.info("ContractSignVtwoUtils#addDocumentByFile 本地文件转化为文件流【结束】 filePath={} ", qysParams.getFilePath());
String response = null;
try {
logger.info("ContractSignVtwoUtils#addDocumentByFile 开始上传合同文件 contractId={} ", contractId);
// PDF为本地文件的类型请修改为对应的本地文件类型
response = client.service(new DocumentAddByFileRequest(contractId, file, "pdf", "由文件创建文档"));
logger.info("ContractSignVtwoUtils#addDocumentByFile 上传合同文件【结束】 response={} ", response);
} catch (Exception e) {
logger.error("ContractSignVtwoUtils#addDocumentByFile 上传合同文件 error={} ", e.getMessage(), e);
throw new Exception("根据文件添加文档请求服务器失败,失败原因:" + e.getMessage());
}
SdkResponse<DocumentAddResult> sdkResponse = JSONUtils.toQysResponse(response, DocumentAddResult.class);
if (!sdkResponse.getCode().equals(0)) {
logger.error("ContractSignVtwoUtils#addDocumentByFile 上传合同文件返回结果解析,根据文件添加文档失败,失败原因: error={} ", sdkResponse.getMessage());
throw new Exception("根据文件添加文档失败,失败原因:" + sdkResponse.getMessage());
}
return sdkResponse;
}
/**
* 公司盖章
* @param subjectId
* @param contractId
* @return
* @throws Exception
*/
public SdkResponse companySealSign(String subjectId, Long contractId, SdkClient client) throws Exception {
String response = null;
try {
logger.info("ContractSignVtwoUtils#companySealSign 公司盖章 contractId={} ", contractId);
Contract contract = this.getContract(subjectId, contractId, client).getResult();
logger.info("ContractSignVtwoUtils#companySealSign 获取契约锁合同信息 contract={} ", JSONUtils.toJson(contract));
List<Signatory> signatories = contract.getSignatories();
logger.info("ContractSignVtwoUtils#companySealSign 解析契约锁合同信息中的签署方信息");
if(signatories!=null && signatories.size()>0){
logger.info("ContractSignVtwoUtils#companySealSign 遍历签署方信息");
for (Signatory signatory : signatories) {
String tenantType = signatory.getTenantType();
String status = signatory.getStatus();
if(tenantType!=null && "COMPANY".equals(tenantType) && status!=null && "SIGNING".equals(status)){
logger.info("ContractSignVtwoUtils#companySealSign 当签署方信息为公司,并且状态为签署中,盖章公司名称:"+signatory.getTenantName());
SignParam param = new SignParam();
param.setContractId(contractId);
String company = signatory.getTenantName();
param.setTenantName(company);
if(sZ_CompanyName.equals(company)){
param.setSealId(new Long(sZ_OfficialSealId));
}else if(tJ_CompanyName.equals(company)){
param.setSealId(new Long(tJ_OfficialSealId));
}else if(hH_CompanyName.equals(company)){//联合租赁时,卡尔
param.setSealId(new Long(hH_OfficialSealId));
}else if(kJ_CompanyName.equals(company)){//联合租赁时,凯捷 2021-02-07
param.setSealId(new Long(kJ_OfficialSealId));
}
logger.info("ContractSignVtwoUtils#companySealSign 开始公司遍历签署");
response = client.service(new ContractSignCompanyRequest(param));
logger.info("ContractSignVtwoUtils#companySealSign 公司遍历签署【结束】");
}
}
logger.info("ContractSignVtwoUtils#companySealSign 遍历签署方信息【结束】");
}
} catch (Exception e) {
logger.error("ContractSignVtwoUtils#companySealSign 公章签署请求服务器失败,失败原因: error={} ", e.getMessage(), e);
throw new Exception("公章签署请求服务器失败,失败原因:" + e.getMessage());
}
SdkResponse sdkResponse = JSONUtils.toQysResponse(response);
if (!sdkResponse.getCode().equals(0)) {
logger.error("ContractSignVtwoUtils#companySealSign 公章签署失败,失败原因: error={} ", sdkResponse.getMessage());
throw new Exception("公章签署失败,失败原因:" + sdkResponse.getMessage());
}
return sdkResponse;
}
/**
* 合同信息查询
* @param subjectId
* @param contractId
* @return
* @throws Exception
*/
public SdkResponse<Contract> getContract(String subjectId, Long contractId, SdkClient client) throws Exception {
ContractDetailRequest request = new ContractDetailRequest(contractId);
String response;
try {
logger.info("ContractSignVtwoUtils#getContract 获取契约锁合同信息 contractId={} ", contractId);
response = client.service(request);
logger.info("ContractSignVtwoUtils#getContract 获取契约锁合同信息 contract={} ", response);
} catch (Exception e) {
logger.error("ContractSignVtwoUtils#getContract 合同详情查询,失败原因: error={} ", e.getMessage(), e);
throw new Exception("合同详情查询,失败原因:" + e.getMessage());
}
SdkResponse<Contract> sdkResponse = JSONUtils.toQysResponse(response, Contract.class);
if (!sdkResponse.getCode().equals(0)) {
logger.error("ContractSignVtwoUtils#getContract 合同详情查询,失败原因: error={} ", sdkResponse.getMessage());
throw new Exception("合同详情查询,失败原因:" + sdkResponse.getMessage());
}
return sdkResponse;
}
/**
* 合同下载
* @param qysParams
* @param documentId
* @param client
* @return
* @throws Exception
*/
public String contractDownload(QYSParams qysParams, Long documentId, SdkClient client) throws Exception {
logger.info("ContractSignVtwoUtils#contractDownload 合同下载 documentId={} ", documentId);
DocumentDownloadRequest request = new DocumentDownloadRequest(documentId);
FileOutputStream fos = null;
try {
logger.info("ContractSignVtwoUtils#contractDownload 创建文件输出流 filePath={} ", qysParams.getFilePath());
fos = new FileOutputStream(qysParams.getFilePath());
logger.info("ContractSignVtwoUtils#contractDownload 开始合同下载");
client.download(request, fos);
logger.info("ContractSignVtwoUtils#contractDownload 合同下载【结束】");
IOUtils.safeClose(fos);
} catch (FileNotFoundException e) {
logger.error("ContractSignVtwoUtils#contractDownload 合同文件下载,失败原因: error={} ", e.getMessage(), e);
throw new Exception("合同文件下载,失败原因:" + e.getMessage());
}finally{
fos.close();
}
logger.info("ContractSignVtwoUtils#contractDownload 合同下载成功!");
return "合同下载成功!";
}
/**
* 合同页面链接查询
* @param documentId
* @param client
* @return
* @throws Exception
*/
public String contractPageUrl(Long documentId, SdkClient client) throws Exception {
logger.info("ContractSignVtwoUtils#contractPageUrl 合同页面链接查询 documentId={} ", documentId);
String pageUrl = null;
ContractViewPageRequest request=new ContractViewPageRequest(documentId);
String response = client.service(request);
SdkResponse<ContractPageResult> responseObj = JSONUtils.toQysResponse(response, ContractPageResult.class);
if(responseObj.getCode() == 0) {
ContractPageResult result = responseObj.getResult();
logger.info("合同页面地址为:{}", result.getPageUrl());
logger.info("ContractSignVtwoUtils#contractPageUrl 合同页面地址为 PageUrl={} ", result.getPageUrl());
pageUrl = result.getPageUrl();
} else {
logger.info("ContractSignVtwoUtils#contractPageUrl 请求失败,错误码:{},错误信息:{}", responseObj.getCode(), responseObj.getMessage());
}
return pageUrl;
}
// public static void main(String[] args) {
// // 初始化sdkClient
// String serverUrl = "https://openapi.qiyuesuo.cn";
// String accessKey = "fjHd9oRRkQ";
// String accessSecret = "PZXX3xiQbjRfzPqGlXv8BwRbo9FVnl";
// SdkClient sdkClient = new SdkClient(serverUrl, accessKey, accessSecret);
// ContractViewPageRequest request=new ContractViewPageRequest(2806190588519518413L);
// String response = sdkClient.service(request);
// SdkResponse<ContractPageResult> responseObj = JSONUtils.toQysResponse(response, ContractPageResult.class);
// if(responseObj.getCode() == 0) {
// ContractPageResult result = responseObj.getResult();
// logger.info("合同页面地址为:{}", result.getPageUrl());
// } else {
// logger.info("请求失败,错误码:{},错误信息:{}", responseObj.getCode(), responseObj.getMessage());
// }
// }
/**
* 发起合同
* @param qysParams
* @param contractId
* @param documentId
* @return
* @throws Exception
*/
public SdkResponse send(QYSParams qysParams, Long contractId, Long documentId, SdkClient client) throws Exception {
logger.info("ContractSignVtwoUtils#send 发起合同 contractId={} ", contractId);
Contract draft = this.getContract(qysParams.getSubjectId(), contractId, client).getResult();
logger.info("ContractSignVtwoUtils#send 获取契约锁合同信息 contract={} ", JSONUtils.toJson(draft));
String contractName = draft.getSubject();
logger.info("ContractSignVtwoUtils#send 查询数据库签署配置信息 lb_contract_sign_stamper tempId={} ", qysParams.getTempId());
List<StamperVo> listVo = initQuerySql(qysParams.getTempId(), documentId);
logger.info("ContractSignVtwoUtils#send 遍历合并签署位置信息 contractName={} ", contractName);
logger.info("ContractSignVtwoUtils#send 完成组装遍历合并签署位置信息 SignatoryVo.list={}", JSONUtils.toJson(qysParams.getList()));
logger.info("ContractSignVtwoUtils#send 完成组装遍历合并签署位置信息 StamperVo.listVo={}", JSONUtils.toJson(listVo));
List<Stamper> stampers = updateStamperList(qysParams, listVo);
logger.info("ContractSignVtwoUtils#send 完成组装遍历合并签署位置信息 stampers={}", JSONUtils.toJson(stampers));
String response = null;
try {
logger.info("ContractSignVtwoUtils#send 开始发起合同 stampers={}", JSONUtils.toJson(stampers));
response = client.service(new ContractSendRequest(draft.getId(),stampers));
logger.info("ContractSignVtwoUtils#send 发起合同【结束】 response={}", response);
} catch (Exception e) {
logger.error("ContractSignVtwoUtils#send 发起合同请求服务器失败,失败原因: error={} ", e.getMessage(), e);
throw new Exception("发起合同请求服务器失败,失败原因:" + e.getMessage());
}
SdkResponse sdkResponse = JSONUtils.toQysResponse(response);
if (!sdkResponse.getCode().equals(0)) {
logger.error("ContractSignVtwoUtils#send 发起合同失败失败原因error={} ", sdkResponse.getMessage());
throw new Exception("发起合同失败,失败原因:" + sdkResponse.getMessage());
}
logger.info("ContractSignVtwoUtils#send 发起合同【结束】");
return sdkResponse;
}
/**
* 遍历合并签署位置信息
* @param qysParams
* @param listVo
* @return
*/
private List<Stamper> updateStamperList(QYSParams qysParams, List<StamperVo> listVo) {
List<Stamper> listStamper = new ArrayList<>();
for(StamperVo stamperVo : listVo){
for(SignatoryVo signatoryVo : qysParams.getList()){
if(stamperVo.getStamperSubType().equals(signatoryVo.getSignatorySubType())){
Stamper stamper = stamperVo.getStamper();
stamper.setSignatoryId(signatoryVo.getSignatoryId());
stamper.setActionId(signatoryVo.getActionId());
listStamper.add(stamper);
}
}
}
return listStamper;
}
/**
* Stamper 签署位置
* 公司签署位置需要指定ActionId
* 个人签署位置需要指定SignatoryId
*/
private List<StamperVo> initQuerySql(String tempId, Long documentId) throws Exception{
Transaction Sqlca=null;
List<StamperVo> list = new ArrayList<>();
try {
logger.info("ContractSignVtwoUtils#initQuerySql 签署位置sql查询 tempId={}", tempId);
Sqlca = Transaction.createTransaction(CacheLoaderFactory.getDataSource());
String selSql = " select stamper_type, stamper_sub_type, keyword, offsetX, offsetY, keywordIndex from lb_contract_sign_stamper where temp_id='"+ tempId +"' " ;
logger.info("ContractSignVtwoUtils#initQuerySql 签署位置sql查询结果 selSql={}", selSql);
ASResultSet rs = Sqlca.getASResultSet(new SqlObject(selSql));
while(rs.next()) {
logger.info("ContractSignVtwoUtils#initQuerySql 签署位置sql查询结果 stamper_sub_type={}", rs.getString("stamper_sub_type"));
logger.info("ContractSignVtwoUtils#initQuerySql 签署位置sql查询结果 keyword={}", rs.getString("keyword"));
StamperVo stamperVo = new StamperVo();
stamperVo.setStamperSubType(rs.getString("stamper_sub_type")); // 签署位置类型母公司子公司承租人共同申请人担保人1担保人2
Stamper stamper = new Stamper();
stamper.setPage(0);// 坐标页码0代表所有
stamper.setDocumentId(documentId);//合同文档ID
// 获取接口推送所需数据
stamper.setType(rs.getString("stamper_type")); // 签署类型COMPANY公章PERSONAL个人签名LP法人章TIMESTAMP时间戳ACROSS_PAGE骑缝章
stamper.setKeyword(rs.getString("keyword")); // 关键字
stamper.setOffsetX(Double.parseDouble(rs.getString("offsetX"))); // 横坐标/关键字偏移量
stamper.setOffsetY(Double.parseDouble(rs.getString("offsetY"))); // 纵坐标/关键字偏移量
stamper.setKeywordIndex(Integer.parseInt(rs.getString("keywordIndex"))); // 关键字索引1代表第1个关键字0代表所有关键字-1代表倒数第1个关键字默认为1
stamperVo.setStamper(stamper);
list.add(stamperVo);
}
}catch (Exception e){
logger.error("ContractSignVtwoUtils#initQuerySql 签署位置sql查询失败原因 error={} ", e.getMessage(), e);
e.printStackTrace();
throw new Exception("ContractSignVtwoUtils#initQuerySql 签署位置sql查询失败原因" + e.getMessage());
}finally {
if(Sqlca!=null) {
try {
Sqlca.commit();
Sqlca.disConnect();
} catch (JBOException e) {
e.printStackTrace();
logger.error("ContractSignVtwoUtils#initQuerySql 签署位置sql查询失败原因 error={} ", e.getMessage(), e);
throw new Exception("ContractSignVtwoUtils#initQuerySql 签署位置sql查询失败原因" + e.getMessage());
}
}
}
return list;
}
/**
* 赋值操作更新 actionId SignatoryId
* @param signatoryList
* @param qysParams
* @return
*/
private void updateVoList(List<Signatory> signatoryList, QYSParams qysParams) {
logger.info("ContractSignVtwoUtils#updateVoList 开始赋值操作更新Vo listVo= {}", JSONUtils.toJson(qysParams.getList()));
for(SignatoryVo signatoryVo : qysParams.getList()){
for (Signatory signatory : signatoryList) {
logger.info("ContractSignVtwoUtils#updateVoList signatoryVo.Name={} ", signatoryVo.getName());
logger.info("ContractSignVtwoUtils#updateVoList signatory.getTenantName={} ", signatory.getTenantName());
logger.info("ContractSignVtwoUtils#updateVoList signatoryVo.getSignatoryType={}", signatoryVo.getSignatoryType());
logger.info("ContractSignVtwoUtils#updateVoList signatory.getTenantType={}", signatory.getTenantType());
if(signatoryVo.getName().equals(signatory.getTenantName()) && signatoryVo.getSignatoryType().equals(signatory.getTenantType())){
logger.info("ContractSignVtwoUtils#updateVoList model vo 配对成功");
signatoryVo.setSignatoryId(signatory.getId());
if (signatory.getTenantType().equals(SignatoryTypeEnum.PARENT_COMPANY.getType())) {
logger.info("ContractSignVtwoUtils#updateVoList 当签署方信息为公司时");
logger.info("ContractSignVtwoUtils#updateVoList 开始遍历签署方信息中的签署流程");
for (Action action : signatory.getActions()) {
signatoryVo.setActionId(action.getId());//公司签署位置必传项
}
}
}
}
}
logger.info("ContractSignVtwoUtils#updateVoList 赋值操作更新Vo【结束】 listVo= {}", JSONUtils.toJson(qysParams.getList()));
}
}