| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299 |
- package com.kingdee.eas.custom.esign.osf;
- import com.alibaba.fastjson.JSON;
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- import com.alibaba.fastjson.TypeReference;
- import com.alibaba.fastjson.serializer.SerializerFeature;
- import com.cloudera.impala.jdbc4.internal.fasterxml.jackson.core.JsonProcessingException;
- import com.cloudera.impala.jdbc4.internal.fasterxml.jackson.databind.ObjectMapper;
- import com.google.common.collect.Lists;
- import com.google.common.collect.Maps;
- import com.google.common.collect.Sets;
- import com.kingdee.bos.BOSException;
- import com.kingdee.bos.Context;
- import com.kingdee.bos.bsf.service.app.IHRMsfService;
- import com.kingdee.bos.dao.ormapping.ObjectUuidPK;
- import com.kingdee.bos.metadata.entity.SelectorItemCollection;
- import com.kingdee.bos.metadata.entity.SelectorItemInfo;
- import com.kingdee.eas.common.EASBizException;
- import com.kingdee.eas.custom.esign.*;
- import com.kingdee.eas.custom.esign.bizEnum.ComponentTypeEnum;
- import com.kingdee.eas.custom.esign.bizEnum.EsignConfigEnum;
- import com.kingdee.eas.custom.esign.bizEnum.EsignStatusEnum;
- 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 com.kingdee.eas.util.app.DbUtil;
- import com.kingdee.jdbc.rowset.IRowSet;
- import org.apache.commons.lang3.StringUtils;
- import java.net.URISyntaxException;
- import java.sql.SQLException;
- import java.util.*;
- import java.util.concurrent.TimeUnit;
- /**
- * 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 {
- private static final String SUCCESS_CODE = "0";
- private static final String PREVIEW_OPERATION = "预览";
- private static final int MAX_RETRY_COUNT = 20;
- private static final int RETRY_INTERVAL_SECONDS = 3;
- public Map<String, Object> getSign_templates_detail(Context context, String signTemplateId) throws EsignException, URISyntaxException {
- Map<String, Object> resul = Maps.newHashMap();
- String orgName = EsignConfig.getInstance().get("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");
- //自动落章只能传orgId
- EsignHttpResponse std = EsignHttpUtil.getSign_templates_detail(context, signTemplateId, orgId, false, null);
- if (std.getStatus() >= 200 && std.getStatus() < 300) {
- JSONObject stdbody = JSON.parseObject(std.getBody());
- if (SUCCESS_CODE.equals(String.valueOf(stdbody.get("code")))) {
- JSONObject stdData = stdbody.getJSONObject("data");
- JSONArray participants = stdData.getJSONArray("participants");
- JSONArray copiers = stdData.getJSONArray("copiers");
- for (int x = 0; null != copiers && x < copiers.size(); x++) {
- JSONObject stdCopier = copiers.getJSONObject(x);
- stdCopier.put("participantType", 3);
- participants.add(stdCopier);
- }
- resul.put("data", participants);
- } else {
- resul.put("code", response.getStatus());
- resul.put("message", "网络异常");
- resul.put("data", null);
- }
- } else {
- resul.put("code", response.getStatus());
- resul.put("message", "网络异常");
- resul.put("data", null);
- }
- }
- } else {
- resul.put("code", response.getStatus());
- resul.put("message", "网络异常");
- resul.put("data", null);
- }
- return resul;
- }
- @Override
- public Object process(Context context, Map map) throws EASBizException, BOSException {
- String mack = (String) map.get("mack");
- String data = (String) map.get("data");
- String signTemplateId = (String) map.get("eSignTemplateNum");
- Map<String, Object> resul = Maps.newHashMap();
- try {
- JSONObject jsonObject = JSON.parseObject(data);
- if ("preview".equals(mack)) {
- for (Map.Entry<String, Object> fileEntry : jsonObject.entrySet()) {
- JSONObject fieldObject = (JSONObject) fileEntry.getValue();
- EsignHttpResponse response = this.previewFile(context, fieldObject, "预览");
- if (response.getStatus() >= 200 && response.getStatus() < 300) {
- resul.putAll(this.processFileResponse(response, context));
- } else {
- resul.put("code", response.getStatus());
- resul.put("message", "网络异常");
- resul.put("data", null);
- }
- }
- } else if ("getTemplate".equals(mack)) {
- resul.putAll(this.getSign_templates_detail(context, signTemplateId));
- } else {
- Map<String, Object> signMap = Maps.newHashMap();
- String sourceId = jsonObject.getString("sourceId");
- String signFlowTitle = jsonObject.getString("signFlowTitle");
- String personId = jsonObject.getString("personId");
- String operatorId = jsonObject.getString("operatorId");
- //文件
- JSONObject templateInfo = jsonObject.getJSONObject("templateInfo");
- //签署方信息
- JSONObject signInfo = jsonObject.getJSONObject("signInfo");
- JSONArray signs = signInfo.getJSONArray("signers");
- Boolean isRadio = false;
- 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) {
- //isRadio = orgSignerInfo.getBoolean("isRadio");
- }
- }
- if (isRadio) {
- List<Map<String, Object>> docs = this.addDocs(context, jsonObject, templateInfo);
- List<Map<String, Object>> signDocs = Lists.newArrayList();
- for (Map<String, Object> doc : docs) {
- Map<String, Object> docNew = new HashMap<>(doc);
- docNew.remove("signListGroup");
- signDocs.add(docNew);
- }
- signMap.put("docs", signDocs);
- if (null != docs && docs.size() > 0) {
- //签署流程配置项
- Map<String, Object> signFlowConfig = this.addSignFlowConfig(context, signFlowTitle, jsonObject);
- signMap.put("signFlowConfig", signFlowConfig);
- //签署方信息
- 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);
- }
- System.out.println("--------------------------------------------------------------------------------------");
- System.out.println("signMap:" + JSON.toJSONString(signMap));
- System.out.println("--------------------------------------------------------------------------------------");
- EsignHttpResponse response = EsignHttpUtil.create_by_file(context, personId, signFlowTitle, operatorId, sourceId, JSON.toJSONString(signMap));
- if (response.getStatus() >= 200 && response.getStatus() < 300) {
- JSONObject body = JSON.parseObject(response.getBody());
- resul.putAll(body);
- } else {
- resul.put("code", 403);
- resul.put("message", "参数异常,没有模版id");
- resul.put("data", null);
- }
- }
- } else {
- //处理文件字段
- Map<String, List<Map<String, Object>>> pDocs = this.addPreviewDocs(context, jsonObject, templateInfo);
- List<Map<String, Object>> components = pDocs.get("components");
- //设置待签署文件信息
- List<Map<String, Object>> docs = pDocs.get("docs");
- List<Map<String, Object>> signDocs = Lists.newArrayList();
- for (Map<String, Object> doc : docs) {
- Map<String, Object> docNew = new HashMap<>(doc);
- docNew.remove("signListGroup");
- signDocs.add(docNew);
- }
- signMap.put("docs", signDocs);
- String eSignTemplateNum = jsonObject.getString("eSignTemplateNum");
- if (null != 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);
- // }
- //
- //必须要存在签署文件才能签署
- if (docs.size() > 0) {
- if (StringUtils.isNotBlank(eSignTemplateNum)) {
- String sealId = "";
- Map<String, List<Map<String, Object>>> pMap = this.addParticipants(context, signInfo, eSignTemplateNum, sealId, sourceId);
- signMap.put("signTemplateId", eSignTemplateNum);
- signMap.put("components", components);
- List<Map<String, Object>> participants = Lists.newArrayList();
- for (int x = 0; x < pMap.get("participants").size(); x++) {
- Map<String, Object> participant = Maps.newHashMap();
- participant.putAll(pMap.get("participants").get(x));
- Integer participantSetMode = (Integer) participant.get("participantSetMode");
- Map<String, Object> psnParticipant = (Map<String, Object>) participant.get("psnParticipant");
- if (null != psnParticipant) {
- psnParticipant.remove("psnId");
- }
- Map<String, Object> orgParticipant = (Map<String, Object>) participant.get("orgParticipant");
- if (null != orgParticipant) {
- orgParticipant.remove("orgId");
- Map<String, Object> transactor = (Map<String, Object>) orgParticipant.get("transactor");
- transactor.remove("transactorPsnId");
- }
- if (null != participantSetMode && (participantSetMode.compareTo(1) == 0 || participantSetMode.compareTo(4) == 0)) {
- participants.add(participant);
- }
- }
- signMap.putAll(pMap);
- signMap.put("participants", participants);
- ObjectMapper mapper = new ObjectMapper();
- // 从 pMap 中取出原始的 participants 列表
- List<Map<String, Object>> originalList = (List<Map<String, Object>>) pMap.get("participants");
- // 从 JSON 反序列化为新的列表(独立副本)
- // 使用 fastjson 深拷贝:序列化时禁用循环引用检测,确保 JSON 完全展开
- String jsonString = JSON.toJSONString(originalList, SerializerFeature.DisableCircularReferenceDetect);
- List<Map> copiedList = JSON.parseArray(jsonString, Map.class);
- signMap.put("stubborn_participants", copiedList);
- System.out.println("--------------------------------------------------------------------------------------");
- System.out.println("signMap:" + JSON.toJSONString(signMap));
- System.out.println("--------------------------------------------------------------------------------------");
- EsignHttpResponse response = EsignHttpUtil.createBySignTemplate(context, personId, signFlowTitle, operatorId, sourceId, JSON.toJSONString(signMap));
- 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 {
- // System.out.println("--------------------------------------------------------------------------------------");
- // System.out.println("signMap:" + JSON.toJSONString(signMap));
- // System.out.println("--------------------------------------------------------------------------------------");
- // EsignHttpResponse response = EsignHttpUtil.create_by_file(context, personId, signFlowTitle, operatorId, sourceId, JSON.toJSONString(signMap));
- // if (response.getStatus() >= 200 && response.getStatus() < 300) {
- // JSONObject body = JSON.parseObject(response.getBody());
- // resul.putAll(body);
- // } else {
- resul.put("code", 403);
- resul.put("message", "参数异常,没有模版id");
- resul.put("data", null);
- // }
- }
- }
- }
- }
- }
- } catch (EsignException | URISyntaxException | SQLException e) {
- e.printStackTrace();
- resul.put("code", 400);
- resul.put("message", e.getMessage());
- resul.put("data", null);
- }
- return resul;
- }
- /**
- * 根据”填写模板生成文件“返回的文件id查询文件处理状态
- * 需要阻塞等待这个状态变为2或者5才能调用发起签署接口
- *
- * @param response
- * @param context
- * @return
- */
- public Map<String, Object> processFileResponse(EsignHttpResponse response, Context context) {
- Map<String, Object> result = Maps.newHashMap();
- JSONObject body = JSON.parseObject(response.getBody());
- if (!SUCCESS_CODE.equals(String.valueOf(body.get("code")))) {
- result.putAll(body);
- return result;
- }
- JSONObject jsonData = body.getJSONObject("data");
- String fileId = jsonData.getString("fileId");
- JSONObject pollData = pollFileDownloadUrl(context, fileId);
- if (null != pollData && StringUtils.isNotBlank(pollData.getString("fileDownloadUrl"))) {
- jsonData.putAll(pollData);
- }
- result.putAll(body);
- System.out.println("processFileResponse:" + result);
- return result;
- }
- /**
- * 阻塞循环调用获取文件信息接口
- *
- * @param context
- * @param fileId
- * @return
- */
- private JSONObject pollFileDownloadUrl(Context context, String fileId) {
- for (int i = MAX_RETRY_COUNT; i > 0; i--) {
- try {
- JSONObject data = tryGetFileDownloadUrl(context, fileId);
- if (null != data && StringUtils.isNotBlank(data.getString("fileDownloadUrl"))) {
- return data;
- }
- TimeUnit.SECONDS.sleep(RETRY_INTERVAL_SECONDS);
- } catch (InterruptedException e) {
- Thread.currentThread().interrupt();
- break;
- } catch (Exception e) {
- // 记录日志,继续重试
- e.printStackTrace();
- }
- }
- return null;
- }
- /**
- * 等待这个状态变为2或者5才返回
- *
- * @param context
- * @param fileId
- * @return
- */
- private JSONObject tryGetFileDownloadUrl(Context context, String fileId) {
- try {
- EsignHttpResponse response = EsignHttpUtil.getFileStatus(context, fileId, PREVIEW_OPERATION);
- if (response.getStatus() < 200 || response.getStatus() >= 300) {
- return null;
- }
- JSONObject responseBody = JSON.parseObject(response.getBody());
- if (!SUCCESS_CODE.equals(String.valueOf(responseBody.get("code")))) {
- return null;
- }
- JSONObject data = responseBody.getJSONObject("data");
- String fileStatus = data.getString("fileStatus");
- Set<String> COMPLETED_STATUS = Sets.newHashSet();
- COMPLETED_STATUS.add("2");
- COMPLETED_STATUS.add("5");
- if (COMPLETED_STATUS.contains(fileStatus)) {
- return data;
- }
- } catch (EsignException e) {
- e.printStackTrace();
- }
- return null;
- }
- /**
- * 设置待签署文件位置信息
- *
- * @param context
- * @param fileId
- * @param keyword
- * @param sourceId
- * @return
- * @throws EsignException
- */
- public JSONObject addPositions(Context context, String fileId, String keyword, String sourceId) throws EsignException {
- List<String> keywords = Lists.newArrayList();
- keywords.add(keyword);
- JSONObject coordinate = null;
- System.out.println("respPosition:fileId:" + fileId);
- System.out.println("respPosition:keywords:" + keywords);
- EsignHttpResponse respPosition = EsignHttpUtil.keyword_positions(context, fileId, keywords, sourceId);
- System.out.println("respPosition:" + respPosition.getBody());
- if (respPosition.getStatus() >= 200 && respPosition.getStatus() < 300) {
- JSONObject resp = JSON.parseObject(respPosition.getBody());
- if ("0".equals(String.valueOf(resp.get("code")))) {
- JSONObject keywordData = (JSONObject) resp.get("data");
- if (null != keywordData) {
- JSONArray keywordPositions = keywordData.getJSONArray("keywordPositions");
- if (null != keywordPositions && keywordPositions.size() > 0) {
- JSONObject keywordPs = keywordPositions.getJSONObject(keywordPositions.size() - 1);
- if (keywordPs.getBoolean("searchResult")) {
- if (null != keywordPs) {
- JSONArray positions = keywordPs.getJSONArray("positions");
- if (null != positions && positions.size() > 0) {
- JSONObject position = positions.getJSONObject(positions.size() - 1);
- if (null != position) {
- Object pageNum = position.get("pageNum");
- JSONArray coordinates = position.getJSONArray("coordinates");
- if (null != coordinates && coordinates.size() > 0) {
- coordinate = coordinates.getJSONObject(coordinates.size() - 1);
- if (null != coordinate) {
- coordinate.put("positionPage", pageNum);
- }
- }
- }
- }
- }
- }
- }
- }
- }
- System.out.println("coordinate:" + coordinate);
- }
- return coordinate;
- }
- /**
- * 获取签署人的签署区
- *
- * @param context
- * @param fields
- * @param fileId
- * @param sourceId
- * @return
- * @throws EsignException
- */
- public Map<String, Map<String, Map<String, Object>>> addsignAreaList(Context context, Map<String, Object> fields, String fileId, String sourceId, String docTemplateId) throws EsignException, BOSException, EASBizException, SQLException {
- //Map<String, List<Map<String, Object>>> signListGroup = Maps.newHashMap();
- Map<String, Map<String, Map<String, Object>>> signMapGroup = Maps.newHashMap();
- //获取文件模版字段
- IESignTemplateFileEntry ieSignTemplateFileEntry = ESignTemplateFileEntryFactory.getLocalInstance(context);
- SelectorItemCollection selColl = new SelectorItemCollection();
- selColl.add(new SelectorItemInfo("*"));
- selColl.add(new SelectorItemInfo("fields.*"));
- selColl.add(new SelectorItemInfo("fields.relatedControl.*"));
- String sel = "select fid from CT_ESI_ESignTemplateFileEntry where cfeSignTemplateId = ?";
- IRowSet rs = DbUtil.executeQuery(context, sel.toString(), new Object[]{docTemplateId});
- String Entryid = "";
- if (rs.next()) {
- Entryid = rs.getString("fid");
- }
- ESignTemplateFileEntryInfo eSignTemplateFileEntry = ieSignTemplateFileEntry.getESignTemplateFileEntryInfo(new ObjectUuidPK(Entryid), selColl);
- Map<String, ESignTemplateFileEntryFieldInfo> fieldsMap = Maps.newHashMap();
- ESignTemplateFileEntryFieldCollection entryFieldCollection = eSignTemplateFileEntry.getFields();
- for (int i = 0; i < entryFieldCollection.size(); i++) {
- ESignTemplateFileEntryFieldInfo fieldInfo = entryFieldCollection.get(i);
- //失效的控件跳过
- if (fieldInfo.isInvalid()) {
- continue;
- }
- String fieldId = fieldInfo.getTemplateFieldId().toString();
- JSONObject field = (JSONObject) fields.get(fieldId);
- if (ComponentTypeEnum.SIGN_AREA.equals(fieldInfo.getComponentType())) {
- Map<String, Object> signMap = Maps.newHashMap();
- if (StringUtils.isBlank(fieldInfo.getSigningParty())) {
- Map<String, Object> errMap = Maps.newHashMap();
- errMap.put("模版", eSignTemplateFileEntry.getName());
- errMap.put("控件", fieldInfo.getTemplateFieldName());
- errMap.put("内容", "签署方为空请维护!");
- throw new EsignException(JSON.toJSONString(errMap));
- }
- signMap.put("key", fieldInfo.getSigningParty());
- signMap.put("fileId", fileId);
- signMap.put("fieldId", fieldInfo.getTemplateFieldId());
- signMap.put("signFieldType", 0);
- String keyword = fieldInfo.getTemplateFieldName();
- if (keyword.indexOf("骑缝") >= 0) {
- signMap.put("signFieldStyle", 2);
- signMap.put("positionX", fieldInfo.getPositionX());
- signMap.put("positionY", fieldInfo.getPositionY());
- signMap.put("positionPage", fieldInfo.getPageNum());
- } else {
- signMap.put("signFieldStyle", 1);
- if (null == fieldInfo.getPositionX() && null == fieldInfo.getPositionY()) {
- Map<String, Object> errMap = Maps.newHashMap();
- errMap.put("模版", eSignTemplateFileEntry.getName());
- errMap.put("控件", fieldInfo.getTemplateFieldName());
- errMap.put("内容", "印章坐标为空请维护!");
- throw new EsignException(JSON.toJSONString(errMap));
- }
- signMap.put("positionX", fieldInfo.getPositionX());
- signMap.put("positionY", fieldInfo.getPositionY());
- signMap.put("positionPage", fieldInfo.getPageNum());
- }
- Map<String, Map<String, Object>> skMap = signMapGroup.get((String) signMap.get("key"));
- if (null == skMap) {
- skMap = Maps.newHashMap();
- signMapGroup.put((String) signMap.get("key"), skMap);
- }
- skMap.put(fieldInfo.getTemplateFieldId(), signMap);
- }
- //签署日期
- if (ComponentTypeEnum.DATESIGNATURE.equals(fieldInfo.getComponentType())) {
- fieldsMap.put(fieldId, fieldInfo);
- }
- }
- //签署日期
- for (Map.Entry<String, ESignTemplateFileEntryFieldInfo> fieldLinkEntry : fieldsMap.entrySet()) {
- //签署日期
- ESignTemplateFileEntryFieldInfo fieldLink = fieldLinkEntry.getValue();
- //签署方
- ESignTemplateFileEntryFieldInfo fieldInfo = fieldLink.getRelatedControl();
- if (null == fieldInfo) {
- Map<String, Object> errMap = Maps.newHashMap();
- errMap.put("模版", eSignTemplateFileEntry.getName());
- errMap.put("控件", fieldLink.getTemplateFieldName());
- errMap.put("内容", "签署方关联关系为空请维护!");
- throw new EsignException(JSON.toJSONString(errMap));
- }
- if (!ComponentTypeEnum.SIGN_AREA.equals(fieldInfo.getComponentType())) {
- Map<String, Object> errMap = Maps.newHashMap();
- errMap.put("模版", eSignTemplateFileEntry.getName());
- errMap.put("控件", fieldLink.getTemplateFieldName());
- errMap.put("内容", "关联关系不为签署区,请检查!");
- throw new EsignException(JSON.toJSONString(errMap));
- }
- Map<String, Object> signMap = Maps.newHashMap();
- //签署日期坐标
- Map<String, Object> signDateConfig = Maps.newHashMap();
- signDateConfig.put("showSignDate", 1);
- if (null != fieldLink.getPositionX() && null != fieldLink.getPositionY()) {
- signDateConfig.put("signDatePositionX", fieldLink.getPositionX());
- signDateConfig.put("signDatePositionY", fieldLink.getPositionY());
- }
- if (null != fieldLink.get("fontSize")) {
- signDateConfig.put("fontSize", fieldLink.get("fontSize"));
- }
- if (null != fieldLink.get("dateFormat")) {
- signDateConfig.put("dateFormat", fieldLink.get("dateFormat"));
- }
- signMap.put("signDateConfig", signDateConfig);
- signMap.put("key", fieldInfo.getSigningParty());
- signMap.put("fileId", fileId);
- signMap.put("signFieldType", 0);
- String keyword = fieldInfo.getTemplateFieldName();
- if (keyword.indexOf("骑缝") >= 0) {
- signMap.put("signFieldStyle", 2);
- signMap.put("positionX", fieldInfo.getPositionX());
- signMap.put("positionY", fieldInfo.getPositionY());
- signMap.put("positionPage", fieldInfo.getPageNum());
- } else {
- signMap.put("signFieldStyle", 1);
- if (null == fieldInfo.getPositionX() && null == fieldInfo.getPositionY()) {
- Map<String, Object> errMap = Maps.newHashMap();
- errMap.put("模版", eSignTemplateFileEntry.getName());
- errMap.put("控件", fieldInfo.getTemplateFieldName());
- errMap.put("内容", "印章坐标为空请维护!");
- throw new EsignException(JSON.toJSONString(errMap));
- }
- signMap.put("positionX", fieldInfo.getPositionX());
- signMap.put("positionY", fieldInfo.getPositionY());
- signMap.put("positionPage", fieldInfo.getPageNum());
- }
- Map<String, Map<String, Object>> skMap = signMapGroup.get((String) signMap.get("key"));
- if (null == skMap) {
- skMap = Maps.newHashMap();
- signMapGroup.put((String) signMap.get("key"), skMap);
- }
- skMap.remove(fieldInfo.getTemplateFieldId());
- skMap.put(fieldLink.getTemplateFieldId(), signMap);
- }
- System.out.println("signMapGroup:" + signMapGroup);
- return signMapGroup;
- }
- /**
- * 设置待签署文件信息
- *
- * @param context
- * @param jsonObject
- * @param templateInfo
- * @return
- * @throws EsignException
- */
- public List<Map<String, Object>> addDocs(Context context, JSONObject jsonObject, JSONObject templateInfo) throws EsignException, EASBizException, BOSException, SQLException {
- //设置待签署文件信息
- 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 = fieldObject.getString("id");
- String fileName = fieldObject.getString("name");
- String eSignTemplateNum = fieldObject.getString("eSignTemplateNum");
- if (StringUtils.isBlank(docTemplateId)) {
- docTemplateId = fieldObject.getString("tableId");
- }
- if (StringUtils.isBlank(fileName)) {
- fileName = fieldObject.getString("tableName");
- }
- if (StringUtils.isNotBlank(eSignTemplateNum)) {
- jsonObject.put("eSignTemplateNum", eSignTemplateNum);
- }
- Object order = fieldObject.get("order");
- String sourceId = jsonObject.getString("sourceId");
- this.initDocAndSignAreaList(context, resul, docs, fieldObject, docTemplateId, fileName, order, sourceId);
- }
- return docs;
- }
- /**
- * 设置待签署文件信息
- *
- * @param context
- * @param jsonObject
- * @param templateInfo
- * @return
- * @throws EsignException
- */
- public Map<String, List<Map<String, Object>>> addPreviewDocs(Context context, JSONObject jsonObject, JSONObject templateInfo) throws EsignException, EASBizException, BOSException, SQLException {
- //设置待签署文件信息
- Map<String, List<Map<String, Object>>> resul = Maps.newHashMap();
- List<Map<String, Object>> docs = Lists.newArrayList();
- List<Map<String, Object>> components = Lists.newArrayList();
- for (Map.Entry<String, Object> fileEntry : templateInfo.entrySet()) {
- JSONObject fieldObject = (JSONObject) fileEntry.getValue();
- String docTemplateId = fieldObject.getString("id");
- String fileName = fieldObject.getString("name");
- String eSignTemplateNum = fieldObject.getString("eSignTemplateNum");
- if (StringUtils.isBlank(docTemplateId)) {
- docTemplateId = fieldObject.getString("tableId");
- }
- if (StringUtils.isBlank(fileName)) {
- fileName = fieldObject.getString("tableName");
- }
- if (StringUtils.isNotBlank(eSignTemplateNum)) {
- jsonObject.put("eSignTemplateNum", eSignTemplateNum);
- }
- Object order = fieldObject.get("order");
- String sourceId = jsonObject.getString("sourceId");
- Map<String, Object> doc = Maps.newHashMap();
- doc.put("fileId", docTemplateId);
- doc.put("fileName", fileName);
- if (null != order) {
- doc.put("order", Integer.parseInt(String.valueOf(order)));
- }
- System.out.println("addDocs:" + fieldObject);
- JSONObject fields = fieldObject.getJSONObject("fields");
- for (Map.Entry<String, Object> field : fields.entrySet()) {
- Map<String, Object> component = Maps.newHashMap();
- component.put("componentId", field.getKey());
- component.put("fileId", docTemplateId);
- JSONObject fieldInfo = (JSONObject) field.getValue();
- String dataType = (String) fieldInfo.get("dataType");
- if (ComponentTypeEnum.SIGN_AREA.getAlias().equals(dataType)) {
- continue;
- }
- if (ComponentTypeEnum.DATESIGNATURE.getAlias().equals(dataType)) {
- continue;
- }
- if (null == fieldInfo.get("value")) {
- continue;
- }
- component.put("componentValue", fieldInfo.get("value"));
- components.add(component);
- }
- //取得这个文件的签署人的签署区
- //Map<String, Map<String, Map<String, Object>>> signAreaList = this.addsignAreaList(context, fields, (String) docTemplateId, sourceId, docTemplateId);
- //doc.put("signListGroup", signAreaList);
- docs.add(doc);
- }
- resul.put("docs", docs);
- resul.put("components", components);
- return resul;
- }
- private void initDocAndSignAreaList(Context context, Map<String, Object> resul, List<Map<String, Object>> docs, JSONObject fieldObject, String docTemplateId, String fileName, Object order, String sourceId) throws EsignException, BOSException, EASBizException, SQLException {
- EsignHttpResponse response = this.previewFile(context, fieldObject, sourceId);
- resul.put("id", docTemplateId);
- resul.put("name", fileName);
- if (response.getStatus() >= 200 && response.getStatus() < 300) {
- Map<String, Object> body = this.processFileResponse(response, context);
- if ("0".equals(String.valueOf(body.get("code")))) {
- JSONObject file = (JSONObject) body.get("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)));
- }
- System.out.println("addDocs:" + fieldObject);
- JSONObject fields = fieldObject.getJSONObject("fields");
- //取得这个文件的签署人的签署区
- Map<String, Map<String, Map<String, Object>>> signAreaList = this.addsignAreaList(context, fields, (String) file.get("fileId"), sourceId, docTemplateId);
- doc.put("signListGroup", signAreaList);
- docs.add(doc);
- } else {
- //文件模板生成失败
- resul.putAll(body);
- throw new EsignException(JSON.toJSONString(resul));
- }
- } else {
- throw new EsignException(JSON.toJSONString(response));
- }
- }
- /**
- * 抄送方信息
- *
- * @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 {
- List<Map<String, Object>> resulList = Lists.newArrayList();
- List<Map<String, Object>> resulErrList = Lists.newArrayList();
- 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");
- //自动落章只能传orgId
- if (true == orgSignerInfo.getBoolean("isRadio")) {
- orgPsnSignMap.put("orgId", orgId);
- } else {
- orgPsnSignMap.put("orgName", orgName);
- Map<String, Object> transactorInfo = Maps.newHashMap();
- transactorInfo.put("psnAccount", orgSignerInfo.getString("psnAccount"));
- Map<String, Object> psnInfo = Maps.newHashMap();
- psnInfo.put("psnName", orgSignerInfo.getString("psnName"));
- transactorInfo.put("psnInfo", psnInfo);
- orgPsnSignMap.put("transactorInfo", transactorInfo);
- 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);
- //签署区信息
- String signName = orgSignerInfo.getString("signName");
- if (StringUtils.isBlank(signName)) {
- signName = "签署方" + signOrder;
- }
- List<Map<String, Object>> signFields = Lists.newArrayList();
- for (Map<String, Object> doc : docs) {
- Map<String, Map<String, Map<String, Object>>> signListGroup = (Map<String, Map<String, Map<String, Object>>>) doc.get("signListGroup");
- //判断是否存在签署区
- if (null != signListGroup && signListGroup.size() > 0) {
- Map<String, Map<String, Object>> fieldList = signListGroup.get(signName);
- if (null != fieldList) {
- for (Map<String, Object> fieldMap : fieldList.values()) {
- Map<String, Object> field = Maps.newHashMap();
- field.put("fileId", fieldMap.get("fileId"));
- field.put("customBizNum", doc.get("fileName"));
- if (0 == ((int) fieldMap.get("signFieldType"))) {
- field.put("signFieldType", fieldMap.get("signFieldType"));
- //签章区配置项(指定signFieldType为 0 - 签章区时,该参数为必传项)
- Map<String, Object> normalSignFieldConfig = Maps.newHashMap();
- if (true == orgSignerInfo.getBoolean("isRadio")) {
- //企业/机构自动落章(autoSign为true),请不要传该参数。
- orgPsnSignMap.remove("transactorInfo");
- //自动落章
- normalSignFieldConfig.put("freeMode", false);
- normalSignFieldConfig.put("autoSign", true);
- //印章id
- normalSignFieldConfig.put("assignedSealId", orgSignerInfo.getString("sealId"));
- //印章类型:1印章,2骑缝章
- normalSignFieldConfig.put("signFieldStyle", fieldMap.get("signFieldStyle"));
- Map<String, Object> signFieldPosition = Maps.newHashMap();
- if (1 == ((int) fieldMap.get("signFieldStyle"))) {
- //正常章
- if (null != fieldMap.get("positionPage") && null != fieldMap.get("positionX") && null != fieldMap.get("positionY")) {
- signFieldPosition.put("positionPage", fieldMap.get("positionPage"));
- signFieldPosition.put("positionX", fieldMap.get("positionX"));
- signFieldPosition.put("positionY", fieldMap.get("positionY"));
- Map<String, Object> signDateConfig = (Map<String, Object>) fieldMap.get("signDateConfig");
- if (null == signDateConfig) {
- signDateConfig = Maps.newHashMap();
- //signDateConfig.put("showSignDate", 1);
- }
- field.put("signDateConfig", signDateConfig);
- } else {
- Map<String, Object> res = Maps.newHashMap();
- //失败
- res.put("文件模板:" + doc.get("fileName"), signName + ",未匹配到签署区,请检查模板的签署区命名规范。签署区命名规则:如(“甲方:(盖章)_签署方1_X50_Y50“)根据“_”分割字符串,第一个是要盖章的内容位置标识;第二个是签署方用来判断这个签署区是谁的;X50表示:印章位置向右移动50;Y50表示:印章位置向上移动50");
- resulErrList.add(res);
- }
- } else {
- //骑缝章
- signFieldPosition.put("positionY", fieldMap.get("positionY"));
- }
- normalSignFieldConfig.put("signFieldPosition", signFieldPosition);
- } else {
- //手动签章
- normalSignFieldConfig.put("freeMode", false);
- normalSignFieldConfig.put("autoSign", false);
- //印章id
- normalSignFieldConfig.put("assignedSealId", orgSignerInfo.getString("sealId"));
- //印章类型:1印章,2骑缝章
- normalSignFieldConfig.put("signFieldStyle", fieldMap.get("signFieldStyle"));
- Map<String, Object> signFieldPosition = Maps.newHashMap();
- if (1 == ((int) fieldMap.get("signFieldStyle"))) {
- //正常章
- if (null != fieldMap.get("positionPage") && null != fieldMap.get("positionX") && null != fieldMap.get("positionY")) {
- signFieldPosition.put("positionPage", fieldMap.get("positionPage"));
- signFieldPosition.put("positionX", fieldMap.get("positionX"));
- signFieldPosition.put("positionY", fieldMap.get("positionY"));
- Map<String, Object> signDateConfig = (Map<String, Object>) fieldMap.get("signDateConfig");
- if (null == signDateConfig) {
- signDateConfig = Maps.newHashMap();
- //signDateConfig.put("showSignDate", 1);
- }
- field.put("signDateConfig", signDateConfig);
- } else {
- Map<String, Object> res = Maps.newHashMap();
- //失败
- res.put("文件模板:" + doc.get("fileName"), signName + ",未匹配到签署区,请检查模板的签署区命名规范。签署区命名规则:如(“甲方:(盖章)_签署方1_X50_Y50“)根据“_”分割字符串,第一个是要盖章的内容位置标识;第二个是签署方用来判断这个签署区是谁的;X50表示:印章位置向右移动50;Y50表示:印章位置向上移动50");
- resulErrList.add(res);
- }
- } else {
- //骑缝章
- signFieldPosition.put("positionY", fieldMap.get("positionY"));
- }
- normalSignFieldConfig.put("signFieldPosition", signFieldPosition);
- }
- field.put("normalSignFieldConfig", normalSignFieldConfig);
- } else {
- field.put("signFieldType", fieldMap.get("signFieldType"));
- //签章区配置项(指定signFieldType为 0 - 签章区时,该参数为必传项)
- Map<String, Object> remarkSignFieldConfig = Maps.newHashMap();
- remarkSignFieldConfig.put("freeMode", true);
- remarkSignFieldConfig.put("inputType", 2);
- field.put("remarkSignFieldConfig", remarkSignFieldConfig);
- }
- signFields.add(field);
- }
- } else {
- Map<String, Object> res = Maps.newHashMap();
- //失败
- res.put("文件模板:" + doc.get("fileName"), signName + ",未匹配到签署区,请检查模板的签署区命名规范。签署区命名规则:如(“甲方:(盖章)_签署方1_X50_Y50“)根据“_”分割字符串,第一个是要盖章的内容位置标识;第二个是签署方用来判断这个签署区是谁的;X50表示:印章位置向右移动50;Y50表示:印章位置向上移动50");
- resulList.add(res);
- }
- }
- }
- if (signFields.size() <= 0) {
- throw new EsignException(JSON.toJSONString(resulList));
- }
- if (resulErrList.size() > 0) {
- throw new EsignException(JSON.toJSONString(resulErrList));
- }
- signMapInfo.put("signFields", signFields);
- signMapInfo.put("signerType", 1);
- 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 {
- List<Map<String, Object>> resulList = Lists.newArrayList();
- 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);
- // normalSignFieldConfig.put("movableSignField", false);
- //
- // field.put("normalSignFieldConfig", normalSignFieldConfig);
- // signFields.add(field);
- // }
- //签署区信息
- String signName = psnSignerInfo.getString("signName");
- if (StringUtils.isBlank(signName)) {
- signName = "签署方" + signOrder;
- }
- for (Map<String, Object> doc : docs) {
- Map<String, Map<String, Map<String, Object>>> signListGroup = (Map<String, Map<String, Map<String, Object>>>) doc.get("signListGroup");
- Map<String, Map<String, Object>> fieldList = signListGroup.get(signName);
- if (null != fieldList) {
- for (Map<String, Object> fieldMap : fieldList.values()) {
- Map<String, Object> field = Maps.newHashMap();
- field.put("fileId", fieldMap.get("fileId"));
- field.put("customBizNum", doc.get("fileName"));
- if (0 == ((int) fieldMap.get("signFieldType"))) {
- field.put("signFieldType", fieldMap.get("signFieldType"));
- //签章区配置项(指定signFieldType为 0 - 签章区时,该参数为必传项)
- Map<String, Object> normalSignFieldConfig = Maps.newHashMap();
- //手动签章
- normalSignFieldConfig.put("freeMode", false);
- normalSignFieldConfig.put("autoSign", false);
- //印章id
- //normalSignFieldConfig.put("assignedSealId", orgSignerInfo.getString("sealId"));
- //印章类型:1印章,2骑缝章
- normalSignFieldConfig.put("signFieldStyle", fieldMap.get("signFieldStyle"));
- Map<String, Object> signFieldPosition = Maps.newHashMap();
- if (1 == ((int) fieldMap.get("signFieldStyle"))) {
- //正常章
- if (null != fieldMap.get("positionPage") && null != fieldMap.get("positionX") && null != fieldMap.get("positionY")) {
- signFieldPosition.put("positionPage", fieldMap.get("positionPage"));
- signFieldPosition.put("positionX", fieldMap.get("positionX"));
- signFieldPosition.put("positionY", fieldMap.get("positionY"));
- Map<String, Object> signDateConfig = (Map<String, Object>) fieldMap.get("signDateConfig");
- if (null == signDateConfig) {
- signDateConfig = Maps.newHashMap();
- }
- field.put("signDateConfig", signDateConfig);
- }
- } else {
- //骑缝章
- signFieldPosition.put("positionY", fieldMap.get("positionY"));
- }
- normalSignFieldConfig.put("signFieldPosition", signFieldPosition);
- field.put("normalSignFieldConfig", normalSignFieldConfig);
- } else {
- field.put("signFieldType", fieldMap.get("signFieldType"));
- //签章区配置项(指定signFieldType为 0 - 签章区时,该参数为必传项)
- Map<String, Object> remarkSignFieldConfig = Maps.newHashMap();
- remarkSignFieldConfig.put("freeMode", true);
- remarkSignFieldConfig.put("inputType", 2);
- field.put("remarkSignFieldConfig", remarkSignFieldConfig);
- }
- signFields.add(field);
- }
- } else {
- Map<String, Object> res = Maps.newHashMap();
- //失败
- res.put("文件模板:" + doc.get("fileName"), signName + ",未匹配到签署区,请检查模板的签署区命名规范。签署区命名规则:如(“甲方:(盖章)_签署方1_X50_Y50“)根据“_”分割字符串,第一个是要盖章的内容位置标识;第二个是签署方用来判断这个签署区是谁的;X50表示:印章位置向右移动50;Y50表示:印章位置向上移动50");
- resulList.add(res);
- }
- }
- if (signFields.size() <= 0) {
- throw new EsignException(JSON.toJSONString(resulList));
- }
- signMapInfo.put("signFields", signFields);
- signMapInfo.put("signerType", 0);
- 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;
- }
- /**
- * todo查询流程模板详情 https://open.esign.cn/doc/opendoc/file-and-template3/pfzut7ho9obc7c5r
- * 处理签署方信息
- *
- * @param context
- * @param signTemplateId
- * @param sealOwnerId
- * @param sourceId
- * @return
- * @throws EsignException
- * @throws URISyntaxException
- */
- public Map<String, List<Map<String, Object>>> addParticipants(Context context, JSONObject signInfo, String signTemplateId, String sealOwnerId, String sourceId) throws EsignException, URISyntaxException {
- Map<String, List<Map<String, Object>>> participants_addCopiers = Maps.newHashMap();
- List<Map<String, Object>> participants = Lists.newArrayList();
- List<Map<String, Object>> addCopiers = Lists.newArrayList();
- String orgName = EsignConfig.getInstance().get("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");
- //自动落章只能传orgId
- EsignHttpResponse std = EsignHttpUtil.getSign_templates_detail(context, signTemplateId, orgId, true, sourceId);
- if (std.getStatus() >= 200 && std.getStatus() < 300) {
- JSONObject bodyStd = JSON.parseObject(std.getBody());
- if ("0".equals(String.valueOf(bodyStd.get("code")))) {
- JSONObject orgPsnStd = bodyStd.getJSONObject("data");
- JSONArray parts = orgPsnStd.getJSONArray("participants");
- if (null != parts) {
- for (int i = 0; i < parts.size(); i++) {
- JSONObject p = parts.getJSONObject(i);
- JSONObject orgParticipant = p.getJSONObject("orgParticipant");
- JSONObject psnParticipant = p.getJSONObject("psnParticipant");
- JSONArray components = p.getJSONArray("components");
- String participantFlag = p.getString("participantFlag");
- JSONArray signs = signInfo.getJSONArray("signers");
- for (int x = 0; x < signs.size(); x++) {
- JSONObject sign = signs.getJSONObject(x);
- JSONObject orgSignerInfo = sign.getJSONObject("orgSignerInfo");
- if (null != orgSignerInfo) {
- String signName = orgSignerInfo.getString("signName");
- if (participantFlag.equals(signName)) {
- orgParticipant = new JSONObject();
- p.put("orgParticipant", orgParticipant);
- for (int k = 0; k < components.size(); k++) {
- JSONObject component = components.getJSONObject(k);
- JSONObject normalSignField = component.getJSONObject("normalSignField");
- if (null != normalSignField) {
- JSONArray designatedSealIds = normalSignField.getJSONArray("designatedSealIds");
- //添加印章
- if (StringUtils.isNotBlank(sealOwnerId)) {
- for (int j = 0; j < designatedSealIds.size(); j++) {
- JSONObject designated = designatedSealIds.getJSONObject(j);
- String sealId = designated.getString("sealId");
- String dorgId = designated.getString("orgId");
- if (sealId.equals(sealOwnerId)) {
- orgParticipant.put("sealOwnerId", dorgId);
- }
- }
- }
- }
- }
- //orgParticipant.put("orgId",orgId);
- orgParticipant.put("orgName", orgSignerInfo.getString("orgName"));
- JSONObject transactor = new JSONObject();
- transactor.put("transactorName", orgSignerInfo.getString("psnName"));
- transactor.put("transactorPsnAccount", orgSignerInfo.getString("psnAccount"));
- orgParticipant.put("transactor", transactor);
- //orgParticipant.put("sealOwnerId",sealOwnerId);
- //orgParticipant.put("sealOwnerId",sealOwnerId);
- }
- } else {
- JSONObject psnSignerInfo = sign.getJSONObject("psnSignerInfo");
- if (null != psnSignerInfo) {
- String signName = psnSignerInfo.getString("signName");
- if (participantFlag.equals(signName)) {
- psnParticipant = new JSONObject();
- p.put("psnParticipant", psnParticipant);
- //orgParticipant.put("sealOwnerId",sealOwnerId);
- psnParticipant.put("psnAccount", psnSignerInfo.get("psnAccount"));
- psnParticipant.put("psnName", psnSignerInfo.get("psnName"));
- //orgParticipant.put("orgName",orgName);
- //orgParticipant.put("sealOwnerId",sealOwnerId);
- //orgParticipant.put("sealOwnerId",sealOwnerId);
- }
- }
- }
- }
- participants.add(p);
- }
- }
- JSONArray copiers = orgPsnStd.getJSONArray("copiers");
- if (null != copiers) {
- for (int i = 0; i < copiers.size(); i++) {
- addCopiers.add((Map<String, Object>) copiers.get(i));
- }
- }
- }
- }
- }
- }
- for (int i = 0; i < participants.size(); i++) {
- JSONObject p = (JSONObject) participants.get(i);
- p.remove("components");
- }
- for (int i = 0; i < addCopiers.size(); i++) {
- JSONObject copier = (JSONObject) addCopiers.get(i);
- JSONObject p = (JSONObject) copier.get("copierPsnInfo");
- p.remove("psnId");
- }
- participants_addCopiers.put("participants", participants);
- participants_addCopiers.put("addCopiers", addCopiers);
- return participants_addCopiers;
- }
- /**
- * 签署流程配置项
- *
- * @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);
- }
- Map<String, Object> signConfig = Maps.newHashMap();
- signConfig.put("availableSignClientTypes", "1,2");
- signConfig.put("autoFillAndSubmit", "false");
- signConfig.put("editComponentValue", "true");
- Map<String, Object> noticeConfig = Maps.newHashMap();
- noticeConfig.put("noticeTypes", "1,2");
- noticeConfig.put("examineNotice", "true");
- signFlowConfig.put("signConfig", signConfig);
- signFlowConfig.put("noticeConfig", noticeConfig);
- return signFlowConfig;
- }
- /**
- * 根据传入数据调用 ”填写模板生成文件“ 接口
- *
- * @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();
- String dataType = (String) fieldInfo.get("dataType");
- if (ComponentTypeEnum.SIGN_AREA.getAlias().equals(dataType)) {
- continue;
- }
- if (ComponentTypeEnum.DATESIGNATURE.getAlias().equals(dataType)) {
- continue;
- }
- if (null == fieldInfo.get("value")) {
- continue;
- }
- component.put("componentValue", fieldInfo.get("value"));
- components.add(component);
- }
- map.put("components", components);
- EsignHttpResponse response = EsignHttpUtil.createByDocTemplate(context, JSON.toJSONString(map), sourceId);
- return response;
- }
- }
|