| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890 |
- 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.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.eas.common.EASBizException;
- import com.kingdee.eas.custom.esign.bizEnum.ComponentTypeEnum;
- 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 org.apache.commons.lang3.StringUtils;
- import java.net.URISyntaxException;
- 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;
- @Override
- public Object process(Context context, Map 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)) {
- 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 {
- 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");
- //设置待签署文件信息
- List<Map<String, Object>> docs = null;
- try {
- 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);
- } catch (EsignException e) {
- e.printStackTrace();
- resul.putAll(JSON.parseObject(e.getMessage()));
- }
- 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) {
- 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", response.getStatus());
- resul.put("message", "网络异常");
- resul.put("data", null);
- }
- }
- }
- }
- } catch (EsignException | URISyntaxException 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, List<Map<String, Object>>> addsignAreaList(Context context, Map<String, Object> fields, String fileId, String sourceId) throws EsignException {
- Map<String, List<Map<String, Object>>> signListGroup = Maps.newHashMap();
- for (Map.Entry<String, Object> field : fields.entrySet()) {
- String componentId = field.getKey();
- JSONObject fieldInfo = (JSONObject) field.getValue();
- Object componentValue = fieldInfo.get("value");
- Double positionX = fieldInfo.getDouble("positionX");
- Double positionY = fieldInfo.getDouble("positionY");
- Object pageNum = fieldInfo.get("pageNum");
- String name = fieldInfo.getString("name");
- String dataType = fieldInfo.getString("dataType");
- if (ComponentTypeEnum.SIGN_AREA.getAlias().equals(dataType)) {
- Map<String, Object> signMap = Maps.newHashMap();
- String[] keys = name.split("_");
- String key = "签署方";
- for (String k : keys) {
- if (k.startsWith("签署方")) {
- key = k;
- break;
- }
- }
- signMap.put("key", key);
- signMap.put("fileId", fileId);
- signMap.put("signFieldType", 0);
- String keyword = keys[0];
- if (keyword.indexOf("骑缝") >= 0) {
- signMap.put("signFieldStyle", 2);
- } else {
- if (null == positionX || null == positionY) {
- signMap.put("signFieldStyle", 1);
- JSONObject coordinate = this.addPositions(context, fileId, keyword, sourceId);
- System.out.println("doc.coordinate:" + coordinate);
- if (null != coordinate) {
- double posX = coordinate.getDouble("positionX");
- double posY = coordinate.getDouble("positionY");
- for (String k : keys) {
- if (k.startsWith("X")) {
- String x = k.replace("X", "");
- posX = posX + Integer.parseInt(x);
- signMap.put("posX", posX);
- break;
- }
- }
- for (String k : keys) {
- if (k.startsWith("Y")) {
- String y = k.replace("Y", "");
- posY = posY + Integer.parseInt(y);
- signMap.put("posY", posY);
- break;
- }
- }
- signMap.put("positionX", coordinate.getDouble("positionX"));
- signMap.put("positionY", coordinate.getDouble("positionY"));
- signMap.put("positionPage", coordinate.get("positionPage"));
- }
- } else {
- double posX = positionX;
- double posY = positionY;
- for (String k : keys) {
- if (k.startsWith("X")) {
- String x = k.replace("X", "");
- posX = posX + Integer.parseInt(x);
- signMap.put("posX", posX);
- break;
- }
- }
- for (String k : keys) {
- if (k.startsWith("Y")) {
- String y = k.replace("Y", "");
- posY = posY + Integer.parseInt(y);
- signMap.put("posY", posY);
- break;
- }
- }
- signMap.put("positionX", positionX);
- signMap.put("positionY", positionY);
- signMap.put("positionPage", pageNum);
- }
- }
- List<Map<String, Object>> signList = signListGroup.get((String) signMap.get("key"));
- if (null == signList) {
- signList = Lists.newArrayList();
- signListGroup.put((String) signMap.get("key"), signList);
- }
- signList.add(signMap);
- } else if (ComponentTypeEnum.REMARK_SIGN_AREA.getAlias().equals(dataType)) {
- Map<String, Object> signMap = Maps.newHashMap();
- String[] keys = name.split("_");
- String key = "签署方";
- for (String k : keys) {
- if (k.startsWith("签署方")) {
- key = k;
- break;
- }
- }
- signMap.put("key", key);
- signMap.put("fileId", fileId);
- signMap.put("signFieldType", 1);
- String keyword = keys[0];
- if (keyword.indexOf("骑缝") >= 0) {
- signMap.put("signFieldStyle", 2);
- } else {
- if (null == positionX || null == positionY) {
- signMap.put("signFieldStyle", 1);
- JSONObject coordinate = this.addPositions(context, fileId, keyword, sourceId);
- System.out.println("doc.coordinate:" + coordinate);
- if (null != coordinate) {
- double posX = coordinate.getDouble("positionX");
- double posY = coordinate.getDouble("positionY");
- for (String k : keys) {
- if (k.startsWith("X")) {
- String x = k.replace("X", "");
- posX = posX + Integer.parseInt(x);
- signMap.put("posX", posX);
- break;
- }
- }
- for (String k : keys) {
- if (k.startsWith("Y")) {
- String y = k.replace("Y", "");
- posY = posY + Integer.parseInt(y);
- signMap.put("posY", posY);
- break;
- }
- }
- signMap.put("positionX", coordinate.getDouble("positionX"));
- signMap.put("positionY", coordinate.getDouble("positionY"));
- signMap.put("positionPage", coordinate.get("positionPage"));
- }
- } else {
- double posX = positionX;
- double posY = positionY;
- for (String k : keys) {
- if (k.startsWith("X")) {
- String x = k.replace("X", "");
- posX = posX + Integer.parseInt(x);
- signMap.put("posX", posX);
- break;
- }
- }
- for (String k : keys) {
- if (k.startsWith("Y")) {
- String y = k.replace("Y", "");
- posY = posY + Integer.parseInt(y);
- signMap.put("posY", posY);
- break;
- }
- }
- signMap.put("positionX", positionX);
- signMap.put("positionY", positionY);
- signMap.put("positionPage", pageNum);
- }
- }
- List<Map<String, Object>> signList = signListGroup.get((String) signMap.get("key"));
- if (null == signList) {
- signList = Lists.newArrayList();
- signListGroup.put((String) signMap.get("key"), signList);
- }
- signList.add(signMap);
- }
- }
- System.out.println("signListGroup:" + signListGroup);
- return signListGroup;
- }
- /**
- * 设置待签署文件信息
- *
- * @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 = fieldObject.getString("id");
- String fileName = fieldObject.getString("name");
- Object order = fieldObject.get("order");
- String sourceId = jsonObject.getString("sourceId");
- 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)));
- }
- doc.put("positionX", null);
- doc.put("positionY", null);
- doc.put("positionPage", null);
- System.out.println("addDocs:" + fieldObject);
- JSONObject fields = fieldObject.getJSONObject("fields");
- //取得这个文件的签署人的签署区
- Map<String, List<Map<String, Object>>> signAreaList = this.addsignAreaList(context, fields, (String) file.get("fileId"), sourceId);
- doc.put("signListGroup", signAreaList);
- 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");
- //自动落章只能传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, List<Map<String, Object>>> signListGroup = (Map<String, List<Map<String, Object>>>) doc.get("signListGroup");
- List<Map<String, Object>> fieldList = signListGroup.get(signName);
- if(null!=fieldList) {
- for (Map<String, Object> fieldMap : fieldList) {
- Map<String, Object> field = Maps.newHashMap();
- field.put("fileId", fieldMap.get("fileId"));
- field.put("customBizNum", sourceId);
- 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"));
- if (null != fieldMap.get("posX")) {
- signFieldPosition.put("positionX", fieldMap.get("posX"));
- }
- if (null != fieldMap.get("posY")) {
- signFieldPosition.put("positionY", fieldMap.get("posY"));
- }
- }
- } else {
- //骑缝章
- }
- normalSignFieldConfig.put("signFieldPosition", signFieldPosition);
- Map<String, Object> signDateConfig = Maps.newHashMap();
- signDateConfig.put("showSignDate", 1);
- field.put("signDateConfig", signDateConfig);
- } else {
- //手动签章
- normalSignFieldConfig.put("freeMode", true);
- normalSignFieldConfig.put("autoSign", false);
- }
- 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 {
- //失败
- resul.put("文件模板:"+doc.get("fileName"),signName+",未匹配到签署区,请检查模板的签署区命名规范。签署区命名规则:如(“甲方:(盖章)_签署方1_X50_Y50“)根据“_”分割字符串,第一个是要盖章的内容位置标识;第二个是签署方用来判断这个签署区是谁的;X50表示:印章位置向右移动50;Y50表示:印章位置向上移动50");
- // resul.put("data",signListGroup);
- throw new EsignException(JSON.toJSONString(resul));
- }
- }
- 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 {
- 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, List<Map<String, Object>>> signListGroup = (Map<String, List<Map<String, Object>>>) doc.get("signListGroup");
- List<Map<String, Object>> fieldList = signListGroup.get(signName);
- if(null!=fieldList) {
- for (Map<String, Object> fieldMap : fieldList) {
- Map<String, Object> field = Maps.newHashMap();
- field.put("fileId", fieldMap.get("fileId"));
- field.put("customBizNum", sourceId);
- if (0 == ((int) fieldMap.get("signFieldType"))) {
- field.put("signFieldType", fieldMap.get("signFieldType"));
- //签章区配置项(指定signFieldType为 0 - 签章区时,该参数为必传项)
- Map<String, Object> normalSignFieldConfig = Maps.newHashMap();
- //手动签章
- normalSignFieldConfig.put("freeMode", true);
- 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"));
- if (null != fieldMap.get("posX")) {
- signFieldPosition.put("positionX", fieldMap.get("posX"));
- }
- if (null != fieldMap.get("posY")) {
- signFieldPosition.put("positionY", fieldMap.get("posY"));
- }
- }
- } else {
- //骑缝章
- }
- normalSignFieldConfig.put("signFieldPosition", signFieldPosition);
- Map<String, Object> signDateConfig = Maps.newHashMap();
- signDateConfig.put("showSignDate", 1);
- field.put("signDateConfig", signDateConfig);
- 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 {
- //失败
- resul.put("文件模板:"+doc.get("fileName"),signName+",未匹配到签署区,请检查模板的签署区命名规范。签署区命名规则:如(“甲方:(盖章)_签署方1_X50_Y50“)根据“_”分割字符串,第一个是要盖章的内容位置标识;第二个是签署方用来判断这个签署区是谁的;X50表示:印章位置向右移动50;Y50表示:印章位置向上移动50");
- resul.put("data",signListGroup);
- throw new EsignException(JSON.toJSONString(resul));
- }
- }
- 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;
- }
- /**
- * 签署流程配置项
- *
- * @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;
- }
- /**
- * 根据传入数据调用 ”填写模板生成文件“ 接口
- *
- * @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;
- }
- component.put("componentValue", fieldInfo.get("value"));
- components.add(component);
- }
- map.put("components", components);
- EsignHttpResponse response = EsignHttpUtil.createByDocTemplate(context, JSON.toJSONString(map), sourceId);
- return response;
- }
- }
|