|
|
@@ -0,0 +1,205 @@
|
|
|
+package com.dgtly.wxportal.service.impl;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.dgtly.system.domain.*;
|
|
|
+import com.dgtly.wxportal.config.ESignConfig;
|
|
|
+import com.dgtly.wxportal.service.IEsignSignService;
|
|
|
+import com.dgtly.wxportal.utils.ESign.ESignHttpUtil;
|
|
|
+import com.dgtly.wxportal.utils.ESign.ESignUrl;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @description:签署服务API
|
|
|
+ * @author:qxm
|
|
|
+ * @date:2020/10/13 10:31
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class EsignSignServiceImpl implements IEsignSignService {
|
|
|
+ @Autowired
|
|
|
+ private ESignHttpUtil eSignHttpUtil;
|
|
|
+ @Autowired
|
|
|
+ private ESignConfig eSignConfig;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @description: 一步发起签署
|
|
|
+ * @param: [copierAccountId, fileId, fileName, signerAccountId]
|
|
|
+ * copierAccountId 抄送人id
|
|
|
+ * fileId 文档id
|
|
|
+ * fileName 文件名称
|
|
|
+ * signerAccountId 签署操作人个人账号标识,即操作本次签署的个人注:平台用户自动签署时,该参数需要传入签署主体账号id
|
|
|
+ * @return: java.lang.String
|
|
|
+ * @author: qxm
|
|
|
+ * @date: 2020/10/13 9:15
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public String oneStepFlow(String businessScene, String fileId, String fileName, String signerAccountId,String authorizedAccountId) {
|
|
|
+ JSONObject json = buildParam(businessScene, fileId, fileName, signerAccountId,authorizedAccountId);
|
|
|
+ JSONObject jsonObject = eSignHttpUtil.doPostGetJson(ESignUrl.CreateFlowOneStepUrl,json);
|
|
|
+ JSONObject result = (JSONObject)jsonObject.get("data");
|
|
|
+ return result.get("flowId").toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @description: 开启签署流程
|
|
|
+ * @param: [flowId]
|
|
|
+ * @return: java.lang.String
|
|
|
+ * @author: qxm
|
|
|
+ * @date: 2020/10/12 16:05
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public String processStart(String flowId) {
|
|
|
+ JSONObject json = new JSONObject();
|
|
|
+// json.put("flowId", flowId);
|
|
|
+ JSONObject jsonObject = eSignHttpUtil.doPutGetJson(ESignUrl.ProcessStartUrl, json,flowId);
|
|
|
+ return jsonObject.toJSONString();
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * @description: 查询签署人列表
|
|
|
+ * @param: [flowId]
|
|
|
+ * @return: java.lang.String
|
|
|
+ * @author: qxm
|
|
|
+ * @date: 2020/10/12 16:05
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public String processExecuteSigners(String flowId) {
|
|
|
+ JSONObject json = new JSONObject();
|
|
|
+// json.put("flowId", flowId);
|
|
|
+ JSONObject jsonObject = eSignHttpUtil.doGetGetJson(ESignUrl.ProcessExecuteSignersUrl, json,flowId);
|
|
|
+ return jsonObject.toJSONString();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @description: 获取签署地址
|
|
|
+ * @param: [flowId,accountId]
|
|
|
+ * @return: java.lang.String
|
|
|
+ * @author: qxm
|
|
|
+ * @date: 2020/10/12 16:05
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public String processExecuteUrl(String flowId,String accountId,String organizeId) {
|
|
|
+ JSONObject json = new JSONObject();
|
|
|
+// json.put("flowId", flowId);
|
|
|
+ JSONObject jsonObject = eSignHttpUtil.doGetGetJson(ESignUrl.ProcessExecuteUrl, json,flowId,accountId,organizeId);
|
|
|
+ return jsonObject.toJSONString();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @description: 流程归档
|
|
|
+ * @param: [flowId]
|
|
|
+ * @return: java.lang.String
|
|
|
+ * @author: qxm
|
|
|
+ * @date: 2020/10/12 16:05
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public String processArchiv(String flowId) {
|
|
|
+ JSONObject json = new JSONObject();
|
|
|
+// json.put("flowId", flowId);
|
|
|
+ JSONObject jsonObject = eSignHttpUtil.doPutGetJson(ESignUrl.ProcessArchivUrl, json,flowId);
|
|
|
+ return jsonObject.toJSONString();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @description: 流程文件下载
|
|
|
+ * @param: [flowId]
|
|
|
+ * @return: java.lang.String
|
|
|
+ * @author: qxm
|
|
|
+ * @date: 2020/10/12 16:05
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public String processDocumentDownload(String flowId) {
|
|
|
+ JSONObject json = new JSONObject();
|
|
|
+// json.put("flowId", flowId);
|
|
|
+ JSONObject jsonObject = eSignHttpUtil.doGetGetJson(ESignUrl.ProcessDocumentDownloadUrl, json,flowId);
|
|
|
+ JSONObject result1 = (JSONObject)jsonObject.get("data");
|
|
|
+ JSONArray jsonarray = (JSONArray)result1.get("docs");
|
|
|
+ JSONObject result = (JSONObject)jsonarray.get(0);
|
|
|
+ return result.get("fileUrl").toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @description 模拟构建一步发起请求参数
|
|
|
+ * <p>
|
|
|
+ * 这里模拟的场景是:无附件,一个抄送人,一个文件,一个平台方和一个待签署方
|
|
|
+ * <p>
|
|
|
+ * 实际使用时,可以根据贵司的业务场景,选择填入附件信息、抄送人列表、文件列表、签署方信息
|
|
|
+ * <p>
|
|
|
+ * 注意: 请求参数中的signers中的签署文件fileId,必须在待签文档信息docs中有填写,否则报错
|
|
|
+ *
|
|
|
+ * <p>
|
|
|
+ *
|
|
|
+ */
|
|
|
+ private JSONObject buildParam(String businessScene, String fileId, String fileName, String signerAccountId,String authorizedAccountId) {
|
|
|
+ // 附件信息列表 这里模拟没有附件的情况
|
|
|
+ List<Attachment> attachments = new ArrayList<>();
|
|
|
+
|
|
|
+ // 抄送人列表 这里模拟有一个抄送人
|
|
|
+ Copier copier = new Copier(signerAccountId, 0, null);
|
|
|
+ List<Copier> copiers = new ArrayList<>(); // Lists.newArrayList() 是guava 的写法
|
|
|
+ copiers.add(copier);
|
|
|
+
|
|
|
+ // 待签文件列表,这里模拟只有一个待签文件
|
|
|
+ Doc doc = new Doc(fileId, fileName);
|
|
|
+
|
|
|
+ List<Doc> docs = new ArrayList<>();//Lists.newArrayList(doc);
|
|
|
+ docs.add(doc);
|
|
|
+
|
|
|
+ // 流程配置,可以不配置,使用默认配置
|
|
|
+ String noticeDeveloperUrl = eSignConfig.getSignSuccessUrl();//回调通知URL
|
|
|
+ FlowConfigInfo flowConfigInfo = new FlowConfigInfo(noticeDeveloperUrl, "1,2", "www.baidu.com", null);
|
|
|
+ FlowInfo flowInfo = new FlowInfo(true,true,businessScene,flowConfigInfo);
|
|
|
+
|
|
|
+ // 签署方信息
|
|
|
+ // 平台方
|
|
|
+ PosBeanInfo posBean1 = new PosBeanInfo("1", 100F, 100F); // 签署位置
|
|
|
+// SignfieldInfo signfield1 = new SignfieldInfo(false,"2", fileId, null, null, null, posBean1, null); // 签署区(签署主体是公司)
|
|
|
+ SignfieldInfo signfield1 = new SignfieldInfo(false, fileId, null, null, null, posBean1, null); // 签署区(个人签署)
|
|
|
+ List<SignfieldInfo> signfields = new ArrayList<>();
|
|
|
+ signfields.add(signfield1);
|
|
|
+// SignerAccount signAccount = new SignerAccount(signerAccountId, signerAccountId);//签署方账号
|
|
|
+ SignerAccount signAccount = new SignerAccount(signerAccountId, authorizedAccountId);//签署方账号
|
|
|
+ Signer signer1 = new Signer(false, 1, signAccount, signfields, null); // 签署方
|
|
|
+ // 用户方
|
|
|
+// PosBeanInfo posBean2 = new PosBeanInfo("1", 200F, 100F); // 签署位置
|
|
|
+// SignfieldInfo signfield2 = new SignfieldInfo(false, null, fileId, null, null, null, posBean2, null); // 签署区
|
|
|
+// List<SignfieldInfo> signfields1 = new ArrayList<>();
|
|
|
+// signfields1.add(signfield2);
|
|
|
+// Signer signer2 = new Signer(false, 1, signAccount, signfields1, null); //用户方
|
|
|
+ List<Signer> signers = new ArrayList<>();//Lists.newArrayList(signer1, signer2);
|
|
|
+ signers.add(signer1);
|
|
|
+// signers.add(signer2);
|
|
|
+
|
|
|
+ //拼接参数
|
|
|
+ return buildOneStepFlowParam(attachments, copiers, docs, flowInfo, signers);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @description 一步发起签署 -- 构建请求参数
|
|
|
+ * <p>
|
|
|
+ *
|
|
|
+ * attachments:附件信息列表【可空】
|
|
|
+ * <p>
|
|
|
+ * copiers:抄送人列表【可空】
|
|
|
+ * <p>
|
|
|
+ * docs:待签文档信息【可空】
|
|
|
+ * <p>
|
|
|
+ * flowInfo:流程基本信息【可空】
|
|
|
+ * <p>
|
|
|
+ * signers:签署方信息列表【必填】
|
|
|
+ *
|
|
|
+ */
|
|
|
+ public static JSONObject buildOneStepFlowParam(List<Attachment> attachments, List<Copier> copiers, List<Doc> docs,
|
|
|
+ FlowInfo flowInfo, List<Signer> signers) {
|
|
|
+ JSONObject json = new JSONObject();
|
|
|
+// json.put("attachments", attachments);
|
|
|
+// json.put("copiers", copiers);
|
|
|
+ json.put("docs", docs);
|
|
|
+ json.put("flowInfo", flowInfo);
|
|
|
+ json.put("signers", signers);
|
|
|
+ return json;
|
|
|
+ }
|
|
|
+}
|