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
* date: 28/11/2025 上午 9:46
* author: lhbj
* version: 1.0
*/
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 getSign_templates_detail(Context context, String signTemplateId) throws EsignException, URISyntaxException {
Map 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 resul = Maps.newHashMap();
try {
JSONObject jsonObject = JSON.parseObject(data);
if ("preview".equals(mack)) {
for (Map.Entry 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 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 signMapInfo = Maps.newHashMap();
JSONObject sign = signs.getJSONObject(i);
Map orgPsnSignMap = Maps.newHashMap();
JSONObject orgSignerInfo = sign.getJSONObject("orgSignerInfo");
JSONObject psnSignerInfo = sign.getJSONObject("psnSignerInfo");
//企业/机构签署方信息
if (null != orgSignerInfo) {
//isRadio = orgSignerInfo.getBoolean("isRadio");
}
}
if (isRadio) {
List