|
|
@@ -0,0 +1,401 @@
|
|
|
+package com.kingdee.eas.custom.esign.osf;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
+import com.google.common.collect.Maps;
|
|
|
+import com.kingdee.bos.BOSException;
|
|
|
+import com.kingdee.bos.Context;
|
|
|
+import com.kingdee.bos.bsf.service.app.IHRMsfService;
|
|
|
+import com.kingdee.eas.common.EASBizException;
|
|
|
+
|
|
|
+import com.kingdee.eas.custom.esign.tsign.hz.comm.EsignHttpResponse;
|
|
|
+import com.kingdee.eas.custom.esign.tsign.hz.exception.EsignException;
|
|
|
+import com.kingdee.eas.custom.esign.util.EsignConfig;
|
|
|
+import com.kingdee.eas.custom.esign.util.EsignHttpUtil;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+
|
|
|
+import java.net.URISyntaxException;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Set;
|
|
|
+
|
|
|
+/**
|
|
|
+ * description: Create_by_fileOSFService <br>
|
|
|
+ * date: 28/11/2025 上午 9:46 <br>
|
|
|
+ * author: lhbj <br>
|
|
|
+ * version: 1.0 <br>
|
|
|
+ */
|
|
|
+public class Create_by_fileOSFService implements IHRMsfService {
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+ JSONObject jsonObject = JSON.parseObject("{\"tableName\":\"3-信息安全承诺书.pdf\",\"tableId\":\"4b19400154d1444e969bf69a6ce0c83c\",\"fields\":{\"49e2cabb3fff4e0090d580f7d4d6e0fc\":{\"name\":\"单行文本1\",\"dataType\":\"单行文本\",\"dataFormat\":\"undefined\",\"value\":\"大王大大\"},\"700825a785484185a6e3fd02e358792c\":{\"name\":\"工号\",\"dataType\":\"单行文本\",\"dataFormat\":\"undefined\",\"value\":\"1234534\"},\"a95f4a5d491d473cbba755a9bb84a04a\":{\"name\":\"日期1\",\"dataType\":\"Date\",\"dataFormat\":\"undefined\",\"value\":\"2024-12-03 00:00:00\"},\"35e09954d6aa41538bd27ffc42da59aa\":{\"name\":\"部门\",\"dataType\":\"String\",\"dataFormat\":\"undefined\",\"value\":\"HR产品处\"},\"df8743514be54648a1bc755cd51e315c\":{\"name\":\"多行文本1\",\"dataType\":\"String\",\"dataFormat\":\"undefined\",\"value\":\"4-1-3\"}}}");
|
|
|
+ for (Map.Entry<String, Object> fileEntry : jsonObject.entrySet()) {
|
|
|
+ JSONObject fieldObject = (JSONObject) fileEntry.getValue();
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Object process(Context context, Map<String, Object> map) throws EASBizException, BOSException {
|
|
|
+ String mack = (String) map.get("mack");
|
|
|
+ String data = (String) map.get("data");
|
|
|
+ Map<String, Object> resul = Maps.newHashMap();
|
|
|
+ try {
|
|
|
+ JSONObject jsonObject = JSON.parseObject(data);
|
|
|
+ if ("preview".equals(mack)) {
|
|
|
+
|
|
|
+ EsignHttpResponse response = this.previewFile(context, jsonObject, "预览");
|
|
|
+ if (response.getStatus() >= 200 && response.getStatus() < 300) {
|
|
|
+ JSONObject body = JSON.parseObject(response.getBody());
|
|
|
+ resul.putAll(body);
|
|
|
+ } else {
|
|
|
+ resul.put("code", response.getStatus());
|
|
|
+ resul.put("message", "网络异常");
|
|
|
+ resul.put("data", null);
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ Map<String, Object> signMap = Maps.newHashMap();
|
|
|
+ String sourceId = jsonObject.getString("sourceId");
|
|
|
+ String signFlowTitle = jsonObject.getString("signFlowTitle");
|
|
|
+ //文件
|
|
|
+ JSONObject templateInfo = jsonObject.getJSONObject("templateInfo");
|
|
|
+ //设置待签署文件信息
|
|
|
+ List<Map<String, Object>> docs = this.addDocs(context, jsonObject, templateInfo);
|
|
|
+ signMap.put("docs", docs);
|
|
|
+ //签署流程配置项
|
|
|
+ Map<String, Object> signFlowConfig = this.addSignFlowConfig(context, signFlowTitle, jsonObject);
|
|
|
+ signMap.put("signFlowConfig", signFlowConfig);
|
|
|
+ //签署方信息
|
|
|
+ JSONObject signInfo = jsonObject.getJSONObject("signInfo");
|
|
|
+ JSONArray signs = signInfo.getJSONArray("signers");
|
|
|
+ List<Map<String, Object>> signers = this.addSigners(context, signs, docs, sourceId);
|
|
|
+ signMap.put("signers", signers);
|
|
|
+ //抄送方信息
|
|
|
+ JSONArray copis = signInfo.getJSONArray("copiers");
|
|
|
+ List<Map<String, Object>> copiers = this.addCopiers(context, copis);
|
|
|
+ if (copiers.size() > 0) {
|
|
|
+ signMap.put("copiers", copiers);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (EsignException | URISyntaxException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return resul;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 设置待签署文件信息
|
|
|
+ *
|
|
|
+ * @param context
|
|
|
+ * @param jsonObject
|
|
|
+ * @param templateInfo
|
|
|
+ * @return
|
|
|
+ * @throws EsignException
|
|
|
+ */
|
|
|
+ public List<Map<String, Object>> addDocs(Context context, JSONObject jsonObject, JSONObject templateInfo) throws EsignException {
|
|
|
+ //设置待签署文件信息
|
|
|
+ Map<String, Object> resul = Maps.newHashMap();
|
|
|
+ List<Map<String, Object>> docs = Lists.newArrayList();
|
|
|
+ for (Map.Entry<String, Object> fileEntry : templateInfo.entrySet()) {
|
|
|
+ JSONObject fieldObject = (JSONObject) fileEntry.getValue();
|
|
|
+ String docTemplateId = jsonObject.getString("id");
|
|
|
+ String fileName = jsonObject.getString("name");
|
|
|
+ Object order = jsonObject.get("order");
|
|
|
+ String sourceId = jsonObject.getString("sourceId");
|
|
|
+ EsignHttpResponse response = this.previewFile(context, fieldObject, sourceId);
|
|
|
+ if (response.getStatus() >= 200 && response.getStatus() < 300) {
|
|
|
+ JSONObject body = JSON.parseObject(response.getBody());
|
|
|
+ if ("0".equals(String.valueOf(body.get("code")))) {
|
|
|
+ JSONObject file = body.getJSONObject("data");
|
|
|
+ Map<String, Object> doc = Maps.newHashMap();
|
|
|
+ doc.put("fileId", file.get("fileId"));
|
|
|
+ doc.put("fileName", fileName);
|
|
|
+ if (null != order) {
|
|
|
+ doc.put("order", Integer.parseInt(String.valueOf(order)));
|
|
|
+ }
|
|
|
+ docs.add(doc);
|
|
|
+ } else {
|
|
|
+ //文件模板生成失败
|
|
|
+ resul.putAll(body);
|
|
|
+ throw new EsignException(JSON.toJSONString(resul));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new EsignException("网络异常:" + JSON.toJSONString(response));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return docs;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 抄送方信息
|
|
|
+ *
|
|
|
+ * @param copis
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<Map<String, Object>> addCopiers(Context context, JSONArray copis) {
|
|
|
+ List<Map<String, Object>> copiers = Lists.newArrayList();
|
|
|
+ for (int i = 0; i < copis.size(); i++) {
|
|
|
+ JSONObject cop = copis.getJSONObject(i);
|
|
|
+ Map<String, Object> copierPsn = Maps.newHashMap();
|
|
|
+ Map<String, Object> copierPsnInfo = Maps.newHashMap();
|
|
|
+ copierPsnInfo.put("psnAccount", cop.getString("psnAccount"));
|
|
|
+ copierPsn.put("copierPsnInfo", copierPsnInfo);
|
|
|
+ copiers.add(copierPsn);
|
|
|
+ }
|
|
|
+ return copiers;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param context
|
|
|
+ * @param orgSignerInfo
|
|
|
+ * @param docs
|
|
|
+ * @param sourceId
|
|
|
+ * @return
|
|
|
+ * @throws EsignException
|
|
|
+ * @throws URISyntaxException
|
|
|
+ */
|
|
|
+ public Map<String, Object> addOrgSignerInfo(Context context, JSONObject orgSignerInfo, List<Map<String, Object>> docs, String sourceId) throws EsignException, URISyntaxException {
|
|
|
+ Map<String, Object> resul = Maps.newHashMap();
|
|
|
+ Map<String, Object> signMapInfo = Maps.newHashMap();
|
|
|
+ Map<String, Object> orgPsnSignMap = Maps.newHashMap();
|
|
|
+ String orgName = orgSignerInfo.getString("orgName");
|
|
|
+ EsignHttpResponse response = EsignHttpUtil.getOrgIdentity_infoByOrgName(context, orgName);
|
|
|
+ if (response.getStatus() >= 200 && response.getStatus() < 300) {
|
|
|
+ JSONObject body = JSON.parseObject(response.getBody());
|
|
|
+ if ("0".equals(String.valueOf(body.get("code")))) {
|
|
|
+ JSONObject orgPsn = body.getJSONObject("data");
|
|
|
+ String orgId = orgPsn.getString("orgId");
|
|
|
+ orgName = orgPsn.getString("orgName");
|
|
|
+ orgPsnSignMap.put("orgId", orgId);
|
|
|
+ orgPsnSignMap.put("orgName", orgName);
|
|
|
+ orgPsnSignMap.put("orgInfo", orgPsn.getJSONObject("orgInfo"));
|
|
|
+ } else {
|
|
|
+ //失败
|
|
|
+ resul.putAll(body);
|
|
|
+ throw new EsignException(JSON.toJSONString(resul));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new EsignException("网络异常:" + JSON.toJSONString(response));
|
|
|
+ }
|
|
|
+ Integer signOrder = orgSignerInfo.getInteger("signOrder");
|
|
|
+ //设置签署方的签署顺序
|
|
|
+ if (null != signOrder) {
|
|
|
+ Map<String, Object> signConfig = Maps.newHashMap();
|
|
|
+ signConfig.put("signOrder", signOrder);
|
|
|
+ signMapInfo.put("signConfig", signConfig);
|
|
|
+ }
|
|
|
+ signMapInfo.put("orgSignerInfo", orgPsnSignMap);
|
|
|
+ //设置签署方的通知方式
|
|
|
+ String noticeTypes = orgSignerInfo.getString("noticeTypes");
|
|
|
+ Map<String, String> noticeConfig = Maps.newHashMap();
|
|
|
+ if (StringUtils.isNotBlank(noticeTypes)) {
|
|
|
+ noticeConfig.put("noticeTypes", noticeTypes);
|
|
|
+ } else {
|
|
|
+ noticeConfig.put("noticeTypes", "1,2");
|
|
|
+ }
|
|
|
+ signMapInfo.put("noticeConfig", noticeConfig);
|
|
|
+ //签署区信息
|
|
|
+ List<Map<String, Object>> signFields = Lists.newArrayList();
|
|
|
+ for (Map<String, Object> doc : docs) {
|
|
|
+ Map<String, Object> field = Maps.newHashMap();
|
|
|
+ field.put("fileId", doc.get("fileId"));
|
|
|
+ field.put("customBizNum", sourceId);
|
|
|
+ field.put("signFieldType", 0);
|
|
|
+ //签章区配置项(指定signFieldType为 0 - 签章区时,该参数为必传项)
|
|
|
+ Map<String, Object> normalSignFieldConfig = Maps.newHashMap();
|
|
|
+ normalSignFieldConfig.put("freeMode", true);
|
|
|
+ field.put("normalSignFieldConfig", normalSignFieldConfig);
|
|
|
+ signFields.add(field);
|
|
|
+ }
|
|
|
+ signMapInfo.put("signFields", signFields);
|
|
|
+ return signMapInfo;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param context
|
|
|
+ * @param psnSignerInfo
|
|
|
+ * @param docs
|
|
|
+ * @param sourceId
|
|
|
+ * @return
|
|
|
+ * @throws EsignException
|
|
|
+ * @throws URISyntaxException
|
|
|
+ */
|
|
|
+ public Map<String, Object> addPsnSignerInfo(Context context, JSONObject psnSignerInfo, List<Map<String, Object>> docs, String sourceId) throws EsignException, URISyntaxException {
|
|
|
+ Map<String, Object> resul = Maps.newHashMap();
|
|
|
+ Map<String, Object> signMapInfo = Maps.newHashMap();
|
|
|
+ Map<String, Object> orgPsnSignMap = Maps.newHashMap();
|
|
|
+ //个人签署方信息
|
|
|
+ String psnAccount = psnSignerInfo.getString("psnAccount");
|
|
|
+ String psnName = psnSignerInfo.getString("psnName");
|
|
|
+ Integer signOrder = psnSignerInfo.getInteger("signOrder");
|
|
|
+ //设置签署方的签署顺序
|
|
|
+ if (null != signOrder) {
|
|
|
+ Map<String, Object> signConfig = Maps.newHashMap();
|
|
|
+ signConfig.put("signOrder", signOrder);
|
|
|
+ signMapInfo.put("signConfig", signConfig);
|
|
|
+ }
|
|
|
+ orgPsnSignMap.put("psnAccount", psnAccount);
|
|
|
+ Map<String, String> psnInfo = Maps.newHashMap();
|
|
|
+ psnInfo.put("psnName", psnName);
|
|
|
+ orgPsnSignMap.put("psnInfo", psnInfo);
|
|
|
+ //个人签署方信息
|
|
|
+ signMapInfo.put("psnSignerInfo", orgPsnSignMap);
|
|
|
+ //设置签署方的通知方式
|
|
|
+ String noticeTypes = psnSignerInfo.getString("noticeTypes");
|
|
|
+ Map<String, String> noticeConfig = Maps.newHashMap();
|
|
|
+ if (StringUtils.isNotBlank(noticeTypes)) {
|
|
|
+ noticeConfig.put("noticeTypes", noticeTypes);
|
|
|
+ } else {
|
|
|
+ noticeConfig.put("noticeTypes", "1,2");
|
|
|
+ }
|
|
|
+ signMapInfo.put("noticeConfig", noticeConfig);
|
|
|
+ //签署区信息
|
|
|
+ List<Map<String, Object>> signFields = Lists.newArrayList();
|
|
|
+ for (Map<String, Object> doc : docs) {
|
|
|
+ Map<String, Object> field = Maps.newHashMap();
|
|
|
+ field.put("fileId", doc.get("fileId"));
|
|
|
+ field.put("customBizNum", sourceId);
|
|
|
+ field.put("signFieldType", 0);
|
|
|
+ //签章区配置项(指定signFieldType为 0 - 签章区时,该参数为必传项)
|
|
|
+ Map<String, Object> normalSignFieldConfig = Maps.newHashMap();
|
|
|
+ normalSignFieldConfig.put("freeMode", true);
|
|
|
+ field.put("normalSignFieldConfig", normalSignFieldConfig);
|
|
|
+ signFields.add(field);
|
|
|
+ }
|
|
|
+ signMapInfo.put("signFields", signFields);
|
|
|
+ return signMapInfo;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 签署方信息
|
|
|
+ *
|
|
|
+ * @param context
|
|
|
+ * @param signs
|
|
|
+ * @param docs
|
|
|
+ * @param sourceId
|
|
|
+ * @return
|
|
|
+ * @throws EsignException
|
|
|
+ * @throws URISyntaxException
|
|
|
+ */
|
|
|
+ public List<Map<String, Object>> addSigners(Context context, JSONArray signs, List<Map<String, Object>> docs, String sourceId) throws EsignException, URISyntaxException {
|
|
|
+ List<Map<String, Object>> signers = Lists.newArrayList();
|
|
|
+ for (int i = 0; i < signs.size(); i++) {
|
|
|
+ Map<String, Object> signMapInfo = Maps.newHashMap();
|
|
|
+ JSONObject sign = signs.getJSONObject(i);
|
|
|
+ Map<String, Object> orgPsnSignMap = Maps.newHashMap();
|
|
|
+ JSONObject orgSignerInfo = sign.getJSONObject("orgSignerInfo");
|
|
|
+ JSONObject psnSignerInfo = sign.getJSONObject("psnSignerInfo");
|
|
|
+ //企业/机构签署方信息
|
|
|
+ if (null != orgSignerInfo) {
|
|
|
+ signMapInfo = addOrgSignerInfo(context, orgSignerInfo, docs, sourceId);
|
|
|
+ } else {
|
|
|
+ //个人签署方信息
|
|
|
+ signMapInfo = addPsnSignerInfo(context, psnSignerInfo, docs, sourceId);
|
|
|
+ }
|
|
|
+ signers.add(signMapInfo);
|
|
|
+ }
|
|
|
+ return signers;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 签署流程配置项
|
|
|
+ *
|
|
|
+ * @param context
|
|
|
+ * @param signFlowTitle
|
|
|
+ * @param jsonObject
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Map<String, Object> addSignFlowConfig(Context context, String signFlowTitle, JSONObject jsonObject) {
|
|
|
+ Map<String, Object> signFlowConfig = Maps.newHashMap();
|
|
|
+ signFlowConfig.put("signFlowTitle", signFlowTitle);
|
|
|
+ Boolean autoStart = jsonObject.getBoolean("autoStart");
|
|
|
+ if (null != autoStart) {
|
|
|
+ signFlowConfig.put("autoStart", autoStart);
|
|
|
+ } else {
|
|
|
+ signFlowConfig.put("autoStart", true);
|
|
|
+ }
|
|
|
+ Boolean autoFinish = jsonObject.getBoolean("autoFinish");
|
|
|
+ if (null != autoFinish) {
|
|
|
+ signFlowConfig.put("autoFinish", autoFinish);
|
|
|
+ } else {
|
|
|
+ signFlowConfig.put("autoFinish", true);
|
|
|
+ }
|
|
|
+ String notifyUrl = jsonObject.getString("notifyUrl");
|
|
|
+ if (null != notifyUrl) {
|
|
|
+ signFlowConfig.put("notifyUrl", notifyUrl);
|
|
|
+ } else {
|
|
|
+ notifyUrl = EsignConfig.getInstance().get("notifyUrl");
|
|
|
+ signFlowConfig.put("notifyUrl", notifyUrl);
|
|
|
+ }
|
|
|
+ return signFlowConfig;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * {
|
|
|
+ * "name": "信息安全承诺书.html",
|
|
|
+ * "id": "c964cb6a67dd40f4a92d4f8e67462e17",
|
|
|
+ * "fields": {
|
|
|
+ * "5b5d7563808d457ea125b000ff2a8d1d": {
|
|
|
+ * "name": "部门",
|
|
|
+ * "dataType": "单行文本",
|
|
|
+ * "value": null
|
|
|
+ * },
|
|
|
+ * "5fcd7b97621c4cd1a5f514e7f06cb0da": {
|
|
|
+ * "name": "工号",
|
|
|
+ * "dataType": "单行文本",
|
|
|
+ * "value": null
|
|
|
+ * }
|
|
|
+ * }
|
|
|
+ * {
|
|
|
+ * "docTemplateId":"8726f6b***03a56d",
|
|
|
+ * "fileName":"某公司的交易协议签署文件",
|
|
|
+ * "components":[
|
|
|
+ * {
|
|
|
+ * "componentId":"59af7766***36ef41b",
|
|
|
+ * "componentKey":"",
|
|
|
+ * "componentValue":"这里是填充的文本"
|
|
|
+ * },
|
|
|
+ * {
|
|
|
+ * "componentId":"7315e9af**72d2dac40",
|
|
|
+ * "componentKey":"",
|
|
|
+ * "componentValue":"2022/01/01"
|
|
|
+ * }
|
|
|
+ * ]
|
|
|
+ * }
|
|
|
+ *
|
|
|
+ * @param jsonObject
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public EsignHttpResponse previewFile(Context context, JSONObject jsonObject, String sourceId) throws EsignException {
|
|
|
+ String docTemplateId = jsonObject.getString("id");
|
|
|
+ String fileName = jsonObject.getString("name");
|
|
|
+ if (StringUtils.isBlank(docTemplateId)) {
|
|
|
+ docTemplateId = jsonObject.getString("tableId");
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(fileName)) {
|
|
|
+ fileName = jsonObject.getString("tableName");
|
|
|
+ }
|
|
|
+ Map<String, Object> map = Maps.newHashMap();
|
|
|
+ map.put("docTemplateId", docTemplateId);
|
|
|
+ map.put("fileName", fileName);
|
|
|
+ List<Map<String, Object>> components = Lists.newArrayList();
|
|
|
+ JSONObject fields = jsonObject.getJSONObject("fields");
|
|
|
+ for (Map.Entry<String, Object> field : fields.entrySet()) {
|
|
|
+ Map<String, Object> component = Maps.newHashMap();
|
|
|
+ component.put("componentId", field.getKey());
|
|
|
+ JSONObject fieldInfo = (JSONObject) field.getValue();
|
|
|
+ component.put("componentValue", fieldInfo.get("value"));
|
|
|
+ components.add(component);
|
|
|
+ }
|
|
|
+ map.put("components", components);
|
|
|
+ EsignHttpResponse response = EsignHttpUtil.createByDocTemplate(context, JSON.toJSONString(map), sourceId);
|
|
|
+ //html 文件需要等待转换完成
|
|
|
+ return response;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|