use of com.itrus.portal.db.EvidenceEnclosure in project portal by ixinportal.
the class EvidenceCallbackTask method init.
public void init() {
try {
EvidenceCallbackExample callbackExample = new EvidenceCallbackExample();
EvidenceCallbackExample.Criteria criteria = callbackExample.createCriteria();
criteria.andCounntLessThan(3);
List<EvidenceCallback> callbacks = callbackService.selectAll(callbackExample);
if (callbacks == null || callbacks.isEmpty()) {
log.error("暂无需系统存证回调");
return;
}
String url = null;
String app_id = null;
String secret_key = null;
// 需要回执报告
Map<Long, String> dataRet = new HashMap<Long, String>();
Map<Long, List<String>> data = new HashMap<Long, List<String>>();
Map<String, EvidenceCallback> cacheCallBackBySnMap = new HashMap<>();
for (int i = 0; i < callbacks.size() && i < 1000; i++) {
EvidenceCallback callback = callbacks.get(i);
cacheCallBackBySnMap.put(callback.getEvidenceSn(), callback);
if (callback.getAppServiceId() == null) {
if (data.containsKey(callback.getAppId())) {
data.get(callback.getAppId()).add(callback.getEvidenceSn());
} else {
List<String> sns = new ArrayList<String>();
sns.add(callback.getEvidenceSn());
data.put(callback.getAppId(), sns);
}
} else {
dataRet.put(callback.getAppId(), callback.getEvidenceSn());
}
}
// <---------------------------- 处理data start ------------------------------>
for (Map.Entry<Long, List<String>> entry : data.entrySet()) {
ApplicationInfo applicationInfo = CacheCustomer.getAPP_INFO_MAP_BY_ID().get(entry.getKey());
if (applicationInfo == null) {
applicationInfo = infoService.selectById(entry.getKey());
}
if (applicationInfo.getAppId() != app_id || url == null || app_id == null || secret_key == null) {
if (StringUtils.isEmpty(applicationInfo.getCallback()) || StringUtils.isEmpty(applicationInfo.getAppId()) || StringUtils.isEmpty(applicationInfo.getSecretKey())) {
log.error("回调失败:缺少配置。");
return;
}
if (url == null) {
url = applicationInfo.getCallback().trim();
}
if (app_id == null) {
app_id = applicationInfo.getAppId();
}
if (secret_key == null) {
secret_key = applicationInfo.getSecretKey();
}
log.error("EvidenceQueryQueue : URL=" + url + ",APP_ID=" + app_id + ",SECRET_KEY=" + secret_key);
if (StringUtils.isEmpty(url) || StringUtils.isEmpty(app_id) || StringUtils.isEmpty(secret_key)) {
log.error("回调失败:缺少配置。");
return;
}
}
Map<String, Object> param = new HashMap<String, Object>();
param.put("status", 1);
param.put("message", "存证成功");
param.put("appId", app_id);
param.put("evidenceSns", JSONObject.toJSONString(entry.getValue()));
String header = "HMAC-SHA1 " + Base64.encode(HMACSHA1.getHmacSHA1(app_id + entry.getValue(), secret_key), false);
String retStr = OkHttpClientManagerCallback.post(url, header, param);
JSONObject ret_data = JSONObject.parseObject(retStr);
if (retStr == null || ret_data.getInteger("status") != 1) {
log.error("EvidenceCallbackTask failure count [" + entry.getValue().size() + "]");
for (String sn : entry.getValue()) {
EvidenceCallback callback = null;
if (cacheCallBackBySnMap.get(sn) == null) {
EvidenceCallbackExample callbackExample0 = new EvidenceCallbackExample();
EvidenceCallbackExample.Criteria criteria0 = callbackExample.createCriteria();
criteria0.andEvidenceSnEqualTo(sn);
callback = callbackService.selectAll(callbackExample0).get(0);
} else {
callback = cacheCallBackBySnMap.get(sn);
}
int counnt = callback.getCounnt() + 1;
if (counnt == 3) {
sqlSession.delete("com.itrus.portal.db.EvidenceCallbackMapper.deleteByPrimaryKey", callback.getId());
} else {
callback.setCounnt(counnt);
sqlSession.update("com.itrus.portal.db.EvidenceCallbackMapper.updateByPrimaryKeySelective", callback);
}
}
} else {
log.error("EvidenceCallbackTask success count [" + entry.getValue().size() + "]");
sqlSession.update("com.itrus.portal.db.EvidenceBasicInformationMapper.updates", entry.getValue().toArray());
EvidenceCallbackExample callbackExample1 = new EvidenceCallbackExample();
EvidenceCallbackExample.Criteria criteria1 = callbackExample.createCriteria();
criteria1.andEvidenceSnIn(entry.getValue());
sqlSession.delete("com.itrus.portal.db.EvidenceCallbackMapper.deleteByExample", callbackExample1);
// for(String sn:entry.getValue()) {
// EvidenceBasicInformation basicInformation = informationService
// .getInformationBySn(sn, null);
// basicInformation.setIsCallback(1);
// sqlSession.update("com.itrus.portal.db.EvidenceBasicInformationMapper.updateByPrimaryKeySelective",
// basicInformation);
//
// EvidenceCallbackExample callbackExample1 = new EvidenceCallbackExample();
// EvidenceCallbackExample.Criteria criteria1 = callbackExample.createCriteria();
// criteria1.andEvidenceSnEqualTo(sn);
// sqlSession.delete("com.itrus.portal.db.EvidenceCallbackMapper.deleteByExample",
// callbackExample1);
//
// }
}
}
// <---------------------------- 处理dataRet start ------------------------------>
for (Entry<Long, String> entry : dataRet.entrySet()) {
ApplicationInfo applicationInfo = CacheCustomer.getAPP_INFO_MAP_BY_ID().get(entry.getKey());
if (applicationInfo == null) {
applicationInfo = infoService.selectById(entry.getKey());
}
if (applicationInfo.getAppId() != app_id || url == null || app_id == null || secret_key == null) {
if (StringUtils.isEmpty(applicationInfo.getCallback()) || StringUtils.isEmpty(applicationInfo.getAppId()) || StringUtils.isEmpty(applicationInfo.getSecretKey())) {
log.error("回调失败:缺少配置。");
return;
}
if (url == null) {
url = applicationInfo.getCallback().trim();
}
if (app_id == null) {
app_id = applicationInfo.getAppId();
}
if (secret_key == null) {
secret_key = applicationInfo.getSecretKey();
}
log.error("EvidenceQueryQueue : URL=" + url + ",APP_ID=" + app_id + ",SECRET_KEY=" + secret_key);
if (StringUtils.isEmpty(url) || StringUtils.isEmpty(app_id) || StringUtils.isEmpty(secret_key)) {
log.error("回调失败:缺少配置。");
return;
}
}
EvidenceBasicInformation basicInformation = informationService.getInformationBySn(entry.getValue(), null);
// 得到证据回执base64
String reportBase64 = null;
// reportBase64 = EvidenceSaveServiceApi.cacheReportBySnMap.get(basicInformation.getEvidenceSn());
if (StringUtils.isEmpty(reportBase64)) {
// 获取原子服务地址 1.实名认证 2.密码服务 3.时间戳
RealNameAuthentication realNameAuthentication = CacheCustomer.getAUTH_CONFIG_MAP().get(2);
if (realNameAuthentication == null) {
try {
realNameAuthentication = realNameAuthenticationSerivce.getRealNameAuthenticationByTwo();
} catch (Exception e) {
e.printStackTrace();
}
}
// 获取回执报告附件表信息
EvidenceEnclosureExample enclosureExample = new EvidenceEnclosureExample();
EvidenceEnclosureExample.Criteria ec = enclosureExample.createCriteria();
ec.andEvidenceSnEqualTo(basicInformation.getEvidenceSn());
ec.andPdfTypeEqualTo("3");
List<EvidenceEnclosure> enclosures = sqlSession.selectList("com.itrus.portal.db.EvidenceEnclosureMapper.selectByExample", enclosureExample);
if (enclosures != null && !enclosures.isEmpty()) {
EvidenceEnclosure enclosure = enclosures.get(0);
// 调解密下载接口从原子服务拿到回执报告base64
reportBase64 = EvidenceSaveServiceApi.decryptedAndDownload(sqlSession, enclosure.getBuid(), realNameAuthentication.getRealNameddress());
} else {
// 调用生成回执报告方法
Map<String, Object> mapRet = null;
mapRet = reportTemplate.returnreceipt(basicInformation.getEvidenceSn(), applicationInfo, null);
if (mapRet.get("status") != null && (int) mapRet.get("status") == 0) {
// 修改证据基本信息回执状态为已出
reportBase64 = (String) mapRet.get("pdfBase64");
basicInformation.setReceiptStatus(1);
sqlSession.update("com.itrus.portal.db.EvidenceBasicInformationMapper.updateByPrimaryKey", basicInformation);
}
}
} else {
// EvidenceSaveServiceApi.cacheReportBySnMap.remove(basicInformation.getEvidenceSn());
}
Map<String, Object> param = new HashMap<String, Object>();
param.put("status", 1);
param.put("appId", app_id);
param.put("evidenceSn", basicInformation.getEvidenceSn());
if (reportBase64 == null) {
param.put("message", "存证成功,回执报告生成失败!");
} else {
param.put("message", "存证成功");
param.put("reportBase64", reportBase64);
}
String header = "HMAC-SHA1 " + Base64.encode(HMACSHA1.getHmacSHA1(app_id + basicInformation.getEvidenceSn(), secret_key), false);
String retStr = OkHttpClientManagerCallback.post(url, header, param);
JSONObject ret_data = JSONObject.parseObject(retStr);
String dataSn = basicInformation.getEvidenceSn();
Long appId = entry.getKey();
// 判断是否成功 true ——> 失败
if (retStr == null || ret_data.getInteger("status") != 1) {
EvidenceCallback callback = null;
if (cacheCallBackBySnMap.get(dataSn) == null) {
EvidenceCallbackExample callbackExample0 = new EvidenceCallbackExample();
EvidenceCallbackExample.Criteria criteria0 = callbackExample.createCriteria();
criteria0.andEvidenceSnEqualTo(dataSn);
callback = callbackService.selectAll(callbackExample0).get(0);
} else {
callback = cacheCallBackBySnMap.get(dataSn);
}
int counnt = callback.getCounnt() + 1;
if (counnt == 3) {
sqlSession.delete("com.itrus.portal.db.EvidenceCallbackMapper.deleteByPrimaryKey", callback.getId());
} else {
callback.setCounnt(counnt);
sqlSession.update("com.itrus.portal.db.EvidenceCallbackMapper.updateByPrimaryKeySelective", callback);
}
} else {
List<String> sns = new ArrayList<>();
sns.add(dataSn);
sqlSession.update("com.itrus.portal.db.EvidenceBasicInformationMapper.updates", sns.toArray());
EvidenceCallbackExample callbackExample1 = new EvidenceCallbackExample();
EvidenceCallbackExample.Criteria criteria1 = callbackExample.createCriteria();
criteria1.andEvidenceSnIn(sns);
sqlSession.delete("com.itrus.portal.db.EvidenceCallbackMapper.deleteByExample", callbackExample1);
}
}
// <---------------------------- 处理dataRet end ------------------------------>
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
LogUtil.evidencelog(sqlSession, null, "存证回调接口", "失败原因:" + e.toString());
}
}
use of com.itrus.portal.db.EvidenceEnclosure in project portal by ixinportal.
the class EvidenceOutTask method outBody.
/**
* 自动出证
* @param hisCertificate
* @param orderNumber
*/
private void outBody(String orderNumber, EvidenceOutServiceConfig outServiceConfig, ApplicationInfo applicationInfo, AppService appService, String evidenceSns, String businessSn, Date date, String code, Integer count) {
try {
// 定义错误原因字段
String hisCauseFailure = null;
// 得到出证模板信息
EvidenceOutTemplateExample outTemplateExample = new EvidenceOutTemplateExample();
EvidenceOutTemplateExample.Criteria tec = outTemplateExample.createCriteria();
tec.andIdEqualTo(outServiceConfig.getOutReportTemplate());
EvidenceOutTemplate outTemplate = sqlSession.selectOne("com.itrus.portal.db.EvidenceOutTemplateMapper.selectByExample", outTemplateExample);
// 整合证书需要的要素
String[] factorArr = outTemplate.getFactor().split(",");
// 整合出证信息表
EvidenceHisCertificate hisCertificate = new EvidenceHisCertificate();
hisCertificate.setServiceRequestPlatform(applicationInfo.getName());
hisCertificate.setApplicationInfo(applicationInfo.getId());
hisCertificate.setSisServiceName(appService.getAppServiceName());
hisCertificate.setSerialnumber(orderNumber);
hisCertificate.setHisAppService(appService.getId());
hisCertificate.setApplicationTime(date);
hisCertificate.setHisApplicant(code);
hisCertificate.setHisState("1");
hisCertificate.setOutState(0);
hisCertificate.setOutTemplate(outServiceConfig.getOutReportTemplate());
hisCertificate.setHisway(outServiceConfig.getOutWay().toString());
sqlSession.insert("com.itrus.portal.db.EvidenceHisCertificateMapper.insert", hisCertificate);
sqlSession.flushStatements();
// int count = 0;
if (StringUtils.isNotEmpty(evidenceSns)) {
String[] evidenceSnArr = evidenceSns.split(",");
for (String evidenceSn : evidenceSnArr) {
// 获得对应证据编号的信息
EvidenceBasicInformation basicInformation = basicInformationService.getInformationBySn(evidenceSn, 2);
if (basicInformation == null) {
if (StringUtils.isEmpty(hisCauseFailure))
hisCauseFailure = "提交的" + evidenceSn + "证据编号为无效的证据编码";
else
hisCauseFailure = hisCauseFailure + "," + "提交的" + evidenceSn + "证据编号为无效的证据编码";
continue;
}
// count++;
if (basicInformation.getEvidenceStatus() == 0 || StringUtils.isNotEmpty(basicInformation.getLackMainContent())) {
if (StringUtils.isEmpty(hisCauseFailure))
hisCauseFailure = "证据编号:" + evidenceSn + "核验未通过,不满足出证要求";
else
hisCauseFailure = hisCauseFailure + "," + "证据编号:" + evidenceSn + "核验未通过,不满足出证要求";
}
// 得到证据附件信息
EvidenceEnclosureExample enclosureExample = new EvidenceEnclosureExample();
EvidenceEnclosureExample.Criteria eec = enclosureExample.createCriteria();
eec.andEvidenceSnEqualTo(evidenceSn);
eec.andPdfTypeEqualTo("1");
List<EvidenceEnclosure> enclosures = sqlSession.selectList("com.itrus.portal.db.EvidenceEnclosureMapper.selectByExample", enclosureExample);
// 核验事件证据提交的要素
String subFactor = null;
String lackFactor = null;
for (EvidenceEnclosure enclosure : enclosures) {
if (StringUtils.isEmpty(subFactor))
subFactor = enclosure.getSaveFactor();
else
subFactor = subFactor + "," + enclosure.getSaveFactor();
}
for (String factor : factorArr) {
if (!subFactor.contains(factor) && !(factor.contains("主体身份") || factor.contains("身份实名认证") || factor.contains("身份意愿鉴别"))) {
if (StringUtils.isEmpty(lackFactor))
lackFactor = factor;
else
lackFactor = lackFactor + "," + factor;
}
}
if (StringUtils.isNotEmpty(lackFactor)) {
if (StringUtils.isEmpty(hisCauseFailure))
hisCauseFailure = "证据编号:" + evidenceSn + ",缺少必要要素信息:" + lackFactor;
else
hisCauseFailure = hisCauseFailure + "," + "证据编号:" + evidenceSn + ",缺少必要要素信息:" + lackFactor;
}
// 核验身份提交的要素
String idFactor = null;
for (String factor : factorArr) {
if (factor.contains("主体身份") || factor.contains("身份实名认证") || factor.contains("身份意愿鉴别")) {
if (StringUtils.isEmpty(idFactor))
idFactor = factor;
else
idFactor = idFactor + "," + factor;
}
}
log.debug("idFactor__ : " + idFactor);
if (StringUtils.isNotEmpty(idFactor)) {
EvidenceTrustedIdentityExample trustedIdentityExample = new EvidenceTrustedIdentityExample();
EvidenceTrustedIdentityExample.Criteria ttc = trustedIdentityExample.createCriteria();
ttc.andBasicInformationEqualTo(basicInformation.getId().toString());
ttc.andEventContentIsNull();
List<EvidenceTrustedIdentity> trustedIdentities = sqlSession.selectList("com.itrus.portal.db.EvidenceTrustedIdentityMapper.selectByExample", trustedIdentityExample);
if (trustedIdentities == null || trustedIdentities.isEmpty()) {
if (StringUtils.isEmpty(hisCauseFailure))
hisCauseFailure = "证据编号:" + evidenceSn + ",缺少必要要素信息:可信身份标识";
else
hisCauseFailure = hisCauseFailure + "," + "证据编号:" + evidenceSn + ",缺少必要要素信息:可信身份标识";
} else {
for (EvidenceTrustedIdentity trustedIdentity : trustedIdentities) {
// 得到主体身份信息
EvidenceMainInformationExample informationExample = new EvidenceMainInformationExample();
EvidenceMainInformationExample.Criteria iec = informationExample.createCriteria();
// iec.andIdEqualTo(trustedIdentity.getMainInformation());
EvidenceMainInformation mainInformation = sqlSession.selectOne("com.itrus.portal.db.EvidenceMainInformationMapper.selectByExample", informationExample);
// 整合没关联主体身份证据的信息
if (StringUtils.isEmpty(trustedIdentity.getEvidenceSn())) {
if (StringUtils.isEmpty(hisCauseFailure))
hisCauseFailure = "证据主体:" + mainInformation.getSubjectName() + ",编号:" + evidenceSn + ",缺少必要要素信息:" + idFactor;
else
hisCauseFailure = hisCauseFailure + "," + "证据主体:" + mainInformation.getSubjectName() + ",编号:" + evidenceSn + ",缺少必要要素信息:" + idFactor;
} else {
// 得到证据附件信息
EvidenceEnclosureExample enclosureExample1 = new EvidenceEnclosureExample();
EvidenceEnclosureExample.Criteria eec1 = enclosureExample1.createCriteria();
eec1.andEvidenceSnEqualTo(trustedIdentity.getEvidenceSn());
eec1.andPdfTypeEqualTo("1");
List<EvidenceEnclosure> enclosures1 = sqlSession.selectList("com.itrus.portal.db.EvidenceEnclosureMapper.selectByExample", enclosureExample1);
String subFactorId = null;
String lackFactorId = null;
for (EvidenceEnclosure enclosure : enclosures1) {
if (StringUtils.isEmpty(subFactorId))
subFactorId = enclosure.getSaveFactor();
else
subFactorId = subFactorId + "," + enclosure.getSaveFactor();
}
log.debug("subFactorId__ : " + subFactorId);
String[] factorIdArr = idFactor.split(",");
for (String factor : factorIdArr) {
if (!subFactorId.contains(factor)) {
if (StringUtils.isEmpty(lackFactorId))
lackFactorId = factor;
else
lackFactorId = lackFactorId + "," + factor;
}
}
log.debug("lackFactorId__ : " + lackFactorId);
if (StringUtils.isNotEmpty(lackFactorId)) {
if (StringUtils.isEmpty(hisCauseFailure))
hisCauseFailure = "证据主体:" + mainInformation.getSubjectName() + ",编号:" + evidenceSn + ",缺少必要要素信息:" + lackFactorId;
else
hisCauseFailure = hisCauseFailure + "," + "证据主体:" + mainInformation.getSubjectName() + ",编号:" + evidenceSn + ",缺少必要要素信息:" + lackFactorId;
}
}
}
}
}
// 存储出证与证据关系
EvidenceHisRelationship hisRelationship = new EvidenceHisRelationship();
hisRelationship.setBasicInformation(basicInformation.getId());
hisRelationship.setHisCertificate(hisCertificate.getId());
sqlSession.insert("com.itrus.portal.db.EvidenceHisRelationshipMapper.insert", hisRelationship);
}
} else {
List<EvidenceBasicInformation> basicInformations = basicInformationService.getInformationByBusinessSn(businessSn, 2);
if (basicInformations == null || basicInformations.isEmpty()) {
if (StringUtils.isEmpty(hisCauseFailure))
hisCauseFailure = "提交的业务单号有误";
else
hisCauseFailure = hisCauseFailure + "," + "提交的业务单号有误";
}
for (EvidenceBasicInformation basicInformation : basicInformations) {
// 得到证据附件信息
EvidenceEnclosureExample enclosureExample = new EvidenceEnclosureExample();
EvidenceEnclosureExample.Criteria eec = enclosureExample.createCriteria();
eec.andBasicInformationEqualTo(basicInformation.getId());
eec.andPdfTypeEqualTo("1");
List<EvidenceEnclosure> enclosures = sqlSession.selectList("com.itrus.portal.db.EvidenceEnclosureMapper.selectByExample", enclosureExample);
// 得到提交的要素
String subFactor = null;
String lackFactor = null;
for (EvidenceEnclosure enclosure : enclosures) {
if (StringUtils.isEmpty(subFactor))
subFactor = enclosure.getSaveFactor();
else
subFactor = subFactor + "," + enclosure.getSaveFactor();
}
for (String factor : factorArr) {
if (!subFactor.contains(factor)) {
if (StringUtils.isEmpty(lackFactor))
lackFactor = factor;
else
lackFactor = lackFactor + "," + factor;
}
}
if (StringUtils.isNotEmpty(lackFactor)) {
if (StringUtils.isEmpty(hisCauseFailure))
hisCauseFailure = "证据编号:" + basicInformation.getEvidenceSn() + ",缺少必要要素信息:" + lackFactor;
else
hisCauseFailure = hisCauseFailure + "," + "证据编号:" + basicInformation.getEvidenceSn() + ",缺少必要要素信息:" + lackFactor;
}
// count++;
if (basicInformation.getEvidenceStatus() == 0 || StringUtils.isNotEmpty(basicInformation.getLackMainContent())) {
if (StringUtils.isEmpty(hisCauseFailure))
hisCauseFailure = "证据编号:" + basicInformation.getEvidenceSn() + ",不满足出证要求";
else
hisCauseFailure = hisCauseFailure + "," + "证据编号:" + basicInformation.getEvidenceSn() + ",不满足出证要求";
}
// 存储出证与证据关系
EvidenceHisRelationship hisRelationship = new EvidenceHisRelationship();
hisRelationship.setBasicInformation(basicInformation.getId());
hisRelationship.setHisCertificate(hisCertificate.getId());
sqlSession.insert("com.itrus.portal.db.EvidenceHisRelationshipMapper.insert", hisRelationship);
}
}
// 判断出证模式
if (count == 1)
hisCertificate.setHis("0");
else
hisCertificate.setHis("1");
// 判断出证是否有错
if (StringUtils.isNotEmpty(hisCauseFailure)) {
// hisCertificate.setHisway("3");
hisCertificate.setOutState(1);
hisCertificate.setHisCauseFailure(hisCauseFailure);
}
sqlSession.update("com.itrus.portal.db.EvidenceHisCertificateMapper.updateByPrimaryKey", hisCertificate);
sqlSession.flushStatements();
// 判断是否为自动出证
if ("1".equals(hisCertificate.getHisway()) && hisCertificate.getOutState() == 0) {
String oper1 = "出证接口";
String info1 = "出证申请成功,流水号:" + orderNumber;
LogUtil.evidencelog(sqlSession, null, oper1, info1);
Map<String, Object> mapRet = null;
// 生成出证报告
try {
mapRet = reportTemplate.certificationReport(hisCertificate.getSerialnumber());
} catch (Exception e) {
StackTraceElement stackTraceElement = e.getStackTrace()[e.getStackTrace().length - 3];
String infoErr = stackTraceElement.getClassName() + stackTraceElement.getLineNumber() + e.toString();
String oper = "出证接口";
String info = "生成出证报告失败,流水号:" + orderNumber + ",失败原因:" + infoErr;
LogUtil.evidencelog(sqlSession, null, oper, info);
e.printStackTrace();
}
// 判断出证报告是否生成成功
if (mapRet != null) {
if ((int) mapRet.get("status") == 0) {
// hisCertificate.setOutState(0);
String oper = "出证接口";
String info = "生成出证报告成功,流水号:" + orderNumber;
LogUtil.evidencelog(sqlSession, null, oper, info);
hisCertificate.setHisState("0");
} else {
// hisCertificate.setOutState(1);
String oper = "出证接口";
String info = null;
if (mapRet.get("message") != null) {
info = "生成出证报告失败,流水号:" + orderNumber + ",失败原因:" + mapRet.get("message").toString();
// hisCertificate.setHisCauseFailure(mapRet.get("message").toString());
} else {
info = "生成出证报告失败,流水号:" + orderNumber;
// hisCertificate.setHisCauseFailure("出证失败");
}
LogUtil.evidencelog(sqlSession, null, oper, info);
}
}
} else {
String oper = "出证接口";
String info = "出证失败,流水号:" + orderNumber;
// 判断为自动出证失败后 转人工出证
if (hisCertificate.getHisway().equals("1")) {
hisCertificate.setHisway("3");
info = info + ",已自动转人工出证";
}
LogUtil.evidencelog(sqlSession, null, oper, info);
}
sqlSession.update("com.itrus.portal.db.EvidenceHisCertificateMapper.updateByPrimaryKeySelective", hisCertificate);
// 出证计费加流水
takeChargingService.takeCharing(appService.getServiceConfigName(), appService.getServiceConfigId(), applicationInfo, appService, hisCertificate.getId(), "EvidenceHisCertificate", count, applicationInfo.getName(), hisCertificate.getHisApplicant());
} catch (Exception e) {
e.printStackTrace();
StackTraceElement stackTraceElement = e.getStackTrace()[e.getStackTrace().length - 3];
String info = "出证失败,错误详情:" + stackTraceElement.getClassName() + stackTraceElement.getLineNumber() + e.toString();
String oper = "出证接口";
LogUtil.evidencelog(sqlSession, null, oper, info);
}
}
use of com.itrus.portal.db.EvidenceEnclosure in project portal by ixinportal.
the class EvidenceSaveServiceApi method searchStored.
/**
* 查询存证
* @param signature
* 签名值
* @param appId
* 应用标识
* @param evidenceSn
* 证据编号
* @param request
* @return
*/
@RequestMapping(value = "/searchStored")
@ResponseBody
public Map<String, Object> searchStored(@RequestHeader("Content-Signature") String signature, @RequestParam(value = "appId", required = false) String appId, @RequestParam(value = "evidenceSn", required = false) String evidenceSn, HttpServletRequest request) {
// TODO : 查询存证接口
Map<String, Object> result = new HashMap<String, Object>();
// 验证参数是否完整
if (StringUtils.isEmpty(signature) || StringUtils.isEmpty(appId) || StringUtils.isEmpty(evidenceSn)) {
result.put("status", 0);
result.put("message", "提交的参数信息不完整");
return result;
}
// 得到应用信息 改成service
Map<String, ApplicationInfo> appInfoMap = CacheCustomer.getAPP_INFO_MAP();
ApplicationInfo applicationInfo = appInfoMap.get(appId);
if (applicationInfo == null) {
ApplicationInfoExample applicationInfoExample = new ApplicationInfoExample();
ApplicationInfoExample.Criteria appInfoExampleCriteria = applicationInfoExample.createCriteria();
appInfoExampleCriteria.andAppIdEqualTo(appId);
applicationInfo = sqlSession.selectOne("com.itrus.portal.db.ApplicationInfoMapper.selectByExample", applicationInfoExample);
}
if (applicationInfo == null) {
result.put("status", -11);
result.put("message", "应用标识不存在");
return result;
}
if (applicationInfo.getIsAppStatus() == 0) {
result.put("status", -12);
result.put("message", "应用状态已关闭");
return result;
}
// 核验ip限制
if (!applicationInfo.getAccessIp().contains(request.getRemoteAddr()) && "1".equals(applicationInfo.getIsIpStatus())) {
result.put("status", -1);
result.put("message", "没有此服务权限");
log.debug("EvidenceSaveSeriveceTest_AccsessIp : " + request.getRemoteAddr());
return result;
}
// 验证hmac有效性
try {
String macVal = Base64.encode(HMACSHA1.getHmacSHA1(appId + evidenceSn, applicationInfo.getSecretKey()), false);
if (!signature.equals("HMAC-SHA1 " + macVal)) {
result.put("status", -2);
result.put("message", "服务密钥错误");
return result;
}
} catch (Exception e) {
result.put("status", -3);
result.put("message", "Hmac验证错误");
e.printStackTrace();
return result;
}
// 获得证据基础信息
EvidenceBasicInformationExample basicInformationExample = new EvidenceBasicInformationExample();
EvidenceBasicInformationExample.Criteria beCriteria = basicInformationExample.createCriteria();
beCriteria.andEvidenceSnEqualTo(evidenceSn);
List<EvidenceBasicInformation> basicInformationList = sqlSession.selectList("com.itrus.portal.db.EvidenceBasicInformationMapper.selectByExample", basicInformationExample);
if (basicInformationList == null || basicInformationList.isEmpty()) {
result.put("status", 0);
result.put("message", "未找到对应证据编号信息,请稍后重试。");
return result;
}
EvidenceBasicInformation basicInformation = basicInformationList.get(0);
// 判断该存储信息状态是否成功
if (basicInformation.getEvidenceStatus() == 1) {
// 判断业务类型为 身份认证 及 2,3 时 不需要返回回执报告 1:电子合同, 2:合同摘要数据, 3:图片摘要数据
if (basicInformation.getType().equals("2") || basicInformation.getType().equals("3") || basicInformation.getType().equals("4") || (basicInformation.getType().equals("1") && basicInformation.getEvidenceType() == 1)) {
result.put("status", 1);
result.put("message", "存证成功");
return result;
}
if (basicInformation.getReceiptStatus() == 1) {
// 获取原子服务地址 1.实名认证 2.密码服务 3.时间戳
RealNameAuthentication realNameAuthentication = CacheCustomer.getAUTH_CONFIG_MAP().get(2);
if (realNameAuthentication == null) {
try {
realNameAuthentication = realNameAuthenticationSerivce.getRealNameAuthenticationByTwo();
} catch (Exception e) {
e.printStackTrace();
result.put("status", -6);
result.put("message", "原子服务配置异常,请联系管理员");
return result;
}
}
if (realNameAuthentication == null) {
result.put("status", -6);
result.put("message", "缺少密码服务配置,请联系管理员");
return result;
}
// 获取回执报告附件表信息
EvidenceEnclosureExample enclosureExample = new EvidenceEnclosureExample();
EvidenceEnclosureExample.Criteria ec = enclosureExample.createCriteria();
ec.andEvidenceSnEqualTo(basicInformation.getEvidenceSn());
ec.andPdfTypeEqualTo("3");
List<EvidenceEnclosure> enclosures = sqlSession.selectList("com.itrus.portal.db.EvidenceEnclosureMapper.selectByExample", enclosureExample);
if (basicInformationList == null || basicInformationList.isEmpty()) {
result.put("status", 0);
result.put("message", "未找到对应回执报告信息");
return result;
}
EvidenceEnclosure enclosure = enclosures.get(0);
// 调解密下载接口从原子服务拿到回执报告base64
String base64 = decryptedAndDownload(sqlSession, enclosure.getBuid(), realNameAuthentication.getRealNameddress());
if (StringUtils.isNotEmpty(base64)) {
result.put("base64", base64);
} else {
result.put("status", 0);
result.put("message", "获取存证回执报告失败,请联系管理员");
return result;
}
} else {
// 调用生成回执报告方法
Map<String, Object> mapRet = null;
try {
mapRet = reportTemplate.returnreceipt(evidenceSn, applicationInfo, null);
} catch (Exception e) {
result.put("status", 0);
result.put("message", "生成存证回执报告失败,请重试或者联系管理员");
return result;
}
if (mapRet.get("status") != null && (int) mapRet.get("status") == 0) {
// 修改证据基本信息回执状态为已出
result.put("reportBase64", mapRet.get("pdfBase64"));
basicInformation.setReceiptStatus(1);
sqlSession.update("com.itrus.portal.db.EvidenceBasicInformationMapper.updateByPrimaryKey", basicInformation);
} else {
result.put("status", 0);
result.put("message", "生成存证回执报告失败,请重试或者联系管理员");
return result;
}
}
result.put("status", 1);
if (StringUtils.isEmpty(basicInformation.getLackMainContent()))
result.put("message", "存证回执报告生成成功");
else
result.put("message", "存证回执报告生成成功," + basicInformation.getLackMainContent());
} else {
if (StringUtils.isEmpty(basicInformation.getLackMainContent()))
result.put("message", basicInformation.getFailureReason());
else
result.put("message", basicInformation.getFailureReason() + "," + basicInformation.getLackMainContent());
result.put("status", 0);
}
return result;
}
use of com.itrus.portal.db.EvidenceEnclosure in project portal by ixinportal.
the class EvidenceSaveServiceApi method searchGenerated.
/**
* 查询出证
* @param signature
* 签名值
* @param appId
* 应用标识
* @param orderNumber
* 服务流水号
* @param request
* @return
*/
@RequestMapping(value = "/searchGenerated")
@ResponseBody
public Map<String, Object> searchGenerated(@RequestHeader("Content-Signature") String signature, @RequestParam(value = "appId", required = true) String appId, @RequestParam(value = "orderNumber", required = true) String orderNumber, HttpServletRequest request) {
// TODO : 查询出证接口
Map<String, Object> result = new HashMap<String, Object>();
// 验证参数是否完整
if (StringUtils.isEmpty(signature) || StringUtils.isEmpty(appId) || StringUtils.isEmpty(orderNumber)) {
result.put("status", 0);
result.put("message", "提交的参数信息不完整");
return result;
}
// 得到应用信息 改成service
Map<String, ApplicationInfo> appInfoMap = CacheCustomer.getAPP_INFO_MAP();
ApplicationInfo applicationInfo = appInfoMap.get(appId);
if (applicationInfo == null) {
ApplicationInfoExample applicationInfoExample = new ApplicationInfoExample();
ApplicationInfoExample.Criteria appInfoExampleCriteria = applicationInfoExample.createCriteria();
appInfoExampleCriteria.andAppIdEqualTo(appId);
applicationInfo = sqlSession.selectOne("com.itrus.portal.db.ApplicationInfoMapper.selectByExample", applicationInfoExample);
}
if (applicationInfo == null) {
result.put("status", -11);
result.put("message", "应用标识不存在");
return result;
}
if (applicationInfo.getIsAppStatus() == 0) {
result.put("status", -12);
result.put("message", "应用状态已关闭");
return result;
}
// 核验ip限制
if (!applicationInfo.getAccessIp().contains(request.getRemoteAddr()) && "1".equals(applicationInfo.getIsIpStatus())) {
result.put("status", -1);
result.put("message", "没有此服务权限");
log.debug("EvidenceSaveSeriveceTest_AccsessIp : " + request.getRemoteAddr());
return result;
}
// 验证hmac有效性
try {
String macVal = Base64.encode(HMACSHA1.getHmacSHA1(appId + orderNumber, applicationInfo.getSecretKey()), false);
if (!signature.equals("HMAC-SHA1 " + macVal)) {
result.put("status", -2);
result.put("message", "服务密钥错误");
return result;
}
} catch (Exception e) {
result.put("status", -3);
result.put("message", "Hmac验证错误");
e.printStackTrace();
return result;
}
EvidenceHisCertificateExample hisCertificateExample = new EvidenceHisCertificateExample();
EvidenceHisCertificateExample.Criteria hec = hisCertificateExample.createCriteria();
hec.andSerialnumberEqualTo(orderNumber);
List<EvidenceHisCertificate> hisCertificates = sqlSession.selectList("com.itrus.portal.db.EvidenceHisCertificateMapper.selectByExample", hisCertificateExample);
if (hisCertificates.size() == 0 || hisCertificates.isEmpty()) {
result.put("status", 0);
result.put("message", "流水号信息有误");
return result;
}
EvidenceHisCertificate hisCertificate = hisCertificates.get(0);
if (StringUtils.isNotEmpty(hisCertificate.getHisCauseFailure())) {
result.put("status", 0);
result.put("message", hisCertificate.getHisCauseFailure());
return result;
}
EvidenceHisRelationshipExample hisRelationshipExample = new EvidenceHisRelationshipExample();
EvidenceHisRelationshipExample.Criteria rec = hisRelationshipExample.createCriteria();
rec.andHisCertificateEqualTo(hisCertificate.getId());
List<EvidenceHisRelationship> hisRelationships = sqlSession.selectList("com.itrus.portal.db.EvidenceHisRelationshipMapper.selectByExample", hisCertificates);
for (EvidenceHisRelationship hisRelationship : hisRelationships) {
EvidenceBasicInformation basicInformation = sqlSession.selectOne("com.itrus.portal.db.EvidenceBasicInformationMapper.selectByPrimaryKey", hisRelationship.getBasicInformation());
Map<String, Object> map = evidenceSaveService.verifyFactor(basicInformation.getEvidenceSn());
if ((int) map.get("status") != 1) {
result.put("status", map.get("status"));
result.put("message", map.get("message"));
return result;
}
}
// 通过流水号得到证据附件信息
EvidenceEnclosureExample enclosurExample = new EvidenceEnclosureExample();
EvidenceEnclosureExample.Criteria ec = enclosurExample.createCriteria();
ec.andSerialnumberEqualTo(orderNumber);
ec.andPdfTypeEqualTo("4");
List<EvidenceEnclosure> enclosurs = sqlSession.selectList("com.itrus.portal.db.EvidenceEnclosureMapper.selectByExample", enclosurExample);
// 判断证据是否已出
if ("0".equals(hisCertificate.getHisState()) && enclosurs != null) {
EvidenceEnclosure enclosure = enclosurs.get(0);
try {
// 获取密码服务
RealNameAuthentication realNameAuthentication = CacheCustomer.getAUTH_CONFIG_MAP().get(2);
if (realNameAuthentication == null) {
realNameAuthentication = realNameAuthenticationSerivce.getRealNameAuthenticationByTwo();
}
if (realNameAuthentication == null) {
result.put("status", -6);
result.put("message", "缺少服务配置,请联系管理员");
return result;
}
// 下载出证报告base64
String str = decryptedAndDownload(sqlSession, enclosure.getBuid(), realNameAuthentication.getRealNameddress());
} catch (Exception e) {
result.put("status", -5);
result.put("message", "服务器出错,请联系管理员");
String oper = "查询出证接口-异常";
String info = "服务流水号: " + orderNumber + ",错误原因:" + e.toString();
LogUtil.evidencelog(sqlSession, null, oper, info);
}
} else {
// 生成出证报告
Map<String, Object> mapRet = null;
// 判断是否为自动出证
if (hisCertificate.getHisway().equals("1")) {
// 生成出证报告
try {
mapRet = reportTemplate.certificationReport(hisCertificate.getSerialnumber());
} catch (Exception e) {
result.put("status", 0);
result.put("message", "出证失败");
return result;
}
} else {
result.put("status", 0);
result.put("message", "无法自动出证");
return result;
}
// 判断出证报告是否生成成功
if (mapRet != null && (int) mapRet.get("status") == 0) {
result.put("status", 1);
result.put("message", "出证成功");
result.put("orderNumber", hisCertificate.getSerialnumber());
result.put("pdfBase64", mapRet.get("pdfBase64"));
hisCertificate.setHisState("0");
} else {
result.put("status", 0);
result.put("message", "出证失败");
hisCertificate.setHisCauseFailure(mapRet.get("message").toString());
// 判断为自动出证失败后 转人工出证
if (hisCertificate.getHisway().equals("1")) {
hisCertificate.setHisway("3");
result.put("message", "出证失败,已自动转人工出证");
}
}
sqlSession.update("com.itrus.portal.db.EvidenceHisCertificateMapper.updateByPrimaryKey", hisCertificate);
}
return result;
}
use of com.itrus.portal.db.EvidenceEnclosure in project portal by ixinportal.
the class EvidenceSaveTask method saveBody.
// private AtomicInteger counter = new AtomicInteger(0);
// private static final String CERT_VERIFY = "/cert/verify";
// 验证pdf文档签章
// private static final String PDF_VERIFY = "/pdf/verify";
// private Map<String, Object> result;
// private ApplicationInfo applicationInfo;
// private AppService appService;
// private EvidenceSaveService evidenceSaveService;
// private Date applyDate;
// private String evidenceSn;
// private String genSn;
// private String signedBase64;
// private String evidencePackage;
// private String hashAlg;
// private String hashvalue;
// private Date dateVp;
// private Date dateVc;
// private List<String> certs;
// private RealNameAuthentication realNameAuthentication;
// private RealNameAuthentication realNameAuthenticationTime;
// private RealNameAuthentication realNameAuthenticationOss;
// private Map<String, Object> mapCharging;
// private static EvidenceSaveTask evidenceSaveTask;
// public static EvidenceSaveTask getInstance() {
// if(evidenceSaveTask == null) {
// synchronized (EvidenceSaveTask.class) {
// evidenceSaveTask = new EvidenceSaveTask();
// }
// }
// return evidenceSaveTask;
// }
// public EvidenceSaveTask () {
// super();
// }
// private ScheduledTask scheduledTask = SpringContextHolder.getBean(ScheduledTask.class);
// public EvidenceSaveTask(Map<String, Object> result, ApplicationInfo applicationInfo, AppService appService,
// EvidenceSaveService evidenceSaveService, Date applyDate, String evidenceSn, String genSn,
// String signedBase64, String evidencePackage, String hashAlg, String hashvalue, Date dateVp,
// Date dateVc, List<String> certs, RealNameAuthentication realNameAuthentication,
// RealNameAuthentication realNameAuthenticationTime, RealNameAuthentication realNameAuthenticationOss,
// Map<String, Object> mapCharging) {
// this.result = result;
// this.applicationInfo = applicationInfo;
// this.appService = appService;
// this.evidenceSaveService = evidenceSaveService;
// this.applyDate = applyDate;
// this.evidenceSn = evidenceSn;
// this.genSn = genSn;
// this.signedBase64 = signedBase64;
// this.evidencePackage = evidencePackage;
// this.hashAlg = hashAlg;
// this.hashvalue = hashvalue;
// this.dateVp = dateVp;
// this.dateVc = dateVc;
// this.certs = certs;
// this.realNameAuthentication = realNameAuthentication;
// this.realNameAuthenticationTime = realNameAuthenticationTime;
// this.realNameAuthenticationOss = realNameAuthenticationOss;
// this.mapCharging = mapCharging;
// }
/**
* 删除证件包
* @param fileName
* @return
* @throws Exception
*/
// public boolean deleteEvidence(String fileName) throws Exception{
// try {
// File file = new File(systemConfigService.getpdfurl(), fileName);
// if(file.exists()) {
// return file.delete();
// }
// } catch (Exception e) {
// e.printStackTrace();
// }
// return false;
// }
/**
* 核验处理方法
* @param result
* 返回值
* @param applicationInfo
* 应用
* @param evidenceSaveService
* 服务配置
* @param evidenceSn
* 证据编号
* @param signedBase64
* 签名值
* @param evidencePackage
* 证据包
* @return
* @throws Exception
*/
public Map<String, Object> saveBody(Map<String, Object> result, ApplicationInfo applicationInfo, AppService appService, EvidenceSaveService evidenceSaveService, Date applyDate, String evidenceSn, String genSn, String signedBase64, String evidencePackage, String hashAlg, String hashvalue, Date dateVp, Date dateVc, List<String> certs, RealNameAuthentication realNameAuthentication, RealNameAuthentication realNameAuthenticationTime, RealNameAuthentication realNameAuthenticationOss, Map<String, Object> mapCharging) throws Exception {
List<Object> objs = new ArrayList<Object>();
String info = null;
// 证据服务记录
EvidenceBasicInformation basicInformation = null;
// 本次证据包大小
int fileSize = evidencePackage.getBytes().length;
// 定义一个证据的提交次数
int count = 0;
try {
// 定义时间戳固定时间
// Date genTime = null;
String failureReason = null;
JSONObject jsonEvidenceContent = JSONObject.parseObject(evidencePackage);
// 定义证书固定服务配置
EvidenceServiceConfiguration serviceConfiguration = null;
// 定义证书固定服务配置
serviceConfiguration = CacheCustomer.getEVIDENCE_SERVICE_CONFIG();
if (serviceConfiguration == null) {
// 得到证书固定服务配置
List<EvidenceServiceConfiguration> serviceconfig = sqlSession.selectList("com.itrus.portal.db.EvidenceServiceConfigurationMapper.selectByExample");
if (!serviceconfig.isEmpty()) {
serviceConfiguration = serviceconfig.get(0);
CacheCustomer.setEVIDENCE_SERVICE_CONFIG(serviceConfiguration);
} else {
result.put("status", -22);
result.put("message", "缺少服务配置");
return result;
}
}
// 验签信息入库
EvidenceClientSignature clientSignature = new EvidenceClientSignature();
clientSignature.setHashAlgorithm(hashAlg);
clientSignature.setHashvalue(hashvalue);
clientSignature.setName("0");
// ---- 关联证书
clientSignature.setCertId(Long.parseLong(applicationInfo.getCertBase64()));
clientSignature.setSignatureType("2");
clientSignature.setIdentiType("1");
clientSignature.setSignaturevalue(signedBase64);
clientSignature.setCreateTime(dateVp);
// clientSignature.setCreateTimeMs(applyDate.getTime());
if (StringUtils.isNotEmpty(evidenceSn))
clientSignature.setEvidenceSn(evidenceSn);
else
clientSignature.setEvidenceSn(genSn);
// queueThread.putObjectQueue(clientSignature);
objs.add(clientSignature);
clientSignature = null;
// 密钥别名定义
String alias = null;
// 判断是否需要签名或时间戳
if (evidenceSaveService.getFixationWay() != null && evidenceSaveService.getFixationWay() != 1) {
// 判断是否需要签名
if (evidenceSaveService.getFixationWay() == 2 || evidenceSaveService.getFixationWay() == 4) {
// 定义签名参数
Map<String, Object> param = new HashMap<String, Object>();
String url = null;
// 判断签名类型配置是否为空
if (StringUtils.isNotBlank(serviceConfiguration.getSignatureType())) {
// 得到配置证书
EvidenceCertificate evidenceCertificate = null;
evidenceCertificate = CacheCustomer.getEVIDENCE_CERTIFICATE_MAP().get((long) serviceConfiguration.getSignatureCertificate());
if (evidenceCertificate == null) {
evidenceCertificate = certificateService.selectById((long) serviceConfiguration.getSignatureCertificate());
}
// 得到服务配置的签名证书的密钥别名
alias = CacheCustomer.getMAP_COMFIG().get((long) serviceConfiguration.getSignatureCertificate());
if (StringUtils.isEmpty(alias)) {
alias = secretKeyService.getAliasByCertId((long) serviceConfiguration.getSignatureCertificate());
}
// 配置签名url 和 参数 1.裸签名 2.p7分离式签名 3.p7非分离式签名 (本期只做2)
switch(Integer.parseInt(serviceConfiguration.getSignatureType())) {
case 1:
param.put("alias", alias);
param.put("hashAlg", serviceConfiguration.getArithmetic());
param.put("contentType", "CT_HASH");
url = realNameAuthentication.getRealNameddress() + SIGNATURE_SIGN;
break;
case 2:
param.put("alias", alias);
param.put("hashAlg", serviceConfiguration.getArithmetic());
param.put("detached", true);
param.put("contentType", "CT_HASH");
param.put("content", HMACSHA1.getDigest(serviceConfiguration.getArithmetic(), evidencePackage));
url = realNameAuthentication.getRealNameddress() + P7_SIGN;
break;
case 3:
param.put("alias", alias);
param.put("hashAlg", serviceConfiguration.getArithmetic());
param.put("detached", false);
param.put("contentType", "CT_HASH");
param.put("content", HMACSHA1.getDigest(serviceConfiguration.getArithmetic(), evidencePackage));
url = realNameAuthentication.getRealNameddress() + P7_SIGN;
break;
}
// 异步处理p7签名
// HttpAsyncClientUtil.getInstance().execute(
// url,
// AuthService.getHeader(),
// param,
// new EvidenceSignTask(
// url,
// param,
// evidenceSn!=null?evidenceSn:genSn,
// Long.parseLong(evidenceCertificate.getCert())));
String strP7 = null;
try {
// strP7 = clientService.postForm(url, AuthService.getHeader(), param);
strP7 = OkHttpClientManagerSign.post(url, AuthService.getHeader().get("Authorization").toString(), param);
} catch (Exception e) {
e.printStackTrace();
LogUtil.evidencelog(sqlSession, (evidenceSn != null ? evidenceSn : genSn).toString(), "存证接口_天威签名", "天威签名失败,证据编号:" + (evidenceSn != null ? evidenceSn : genSn).toString() + ", 请求参数:" + param.toString() + ", 请求地址:" + url + ", 返回结果:" + strP7 + ", 失败原因:" + e.toString());
// TODO: handle exception
result.put("status", 0);
result.put("message", "天威签名失败");
return result;
}
// log.error("strP7 : " + strP7);
JSONObject jsonRepP7Sign = JSONObject.parseObject(strP7);
if (jsonRepP7Sign.getIntValue("code") != 0) {
// 天威签名失败
LogUtil.evidencelog(sqlSession, (evidenceSn != null ? evidenceSn : genSn).toString(), "存证接口_天威签名", "天威签名失败,证据编号:" + (evidenceSn != null ? evidenceSn : genSn).toString() + ", 请求参数:" + param.toString() + ", 请求地址:" + url + ", 返回结果:" + strP7 + ", 失败原因:" + jsonRepP7Sign.getString("message"));
result.put("status", 0);
result.put("message", "天威签名失败");
return result;
} else {
// 天威签名服务记录入库
EvidenceClientSignature signature = new EvidenceClientSignature();
signature.setHashAlgorithm(param.get("hashAlg").toString());
signature.setName("1");
signature.setEvidenceSn(evidenceSn != null ? evidenceSn : genSn);
signature.setSignatureType("2");
signature.setCertId(Long.parseLong(evidenceCertificate.getCert()));
signature.setHashvalue(param.get("content").toString());
signature.setSignaturevalue(jsonRepP7Sign.getString("signedData"));
signature.setCreateTime(new Date());
// signature.setCreateTimeMs(applyDate.getTime());
objs.add(signature);
}
evidenceCertificate = null;
}
}
// 判断是否需要签名时间戳
if (evidenceSaveService.getFixationWay() == 3 || evidenceSaveService.getFixationWay() == 4) {
// 对证据包HASH
String plainHash = HMACSHA1.getDigest(serviceConfiguration.getArithmetic(), evidencePackage);
// 异步处理时间戳 --- 本期是实现新版本接口
Map<String, Object> retTime = EvidenceSaveServiceApi.genTimeStamp(realNameAuthenticationTime, plainHash, serviceConfiguration.getArithmetic(), evidenceSn != null ? evidenceSn : genSn, null);
if (!(boolean) retTime.get("retStatus") && retTime.get("obj") != null) {
result.put("status", 0);
result.put("message", "天威时间戳签名失败");
return result;
}
objs.add(retTime.get("obj"));
}
}
alias = null;
Map<String, Object> retSaveMap = new HashMap<String, Object>();
// 判断证据编号是否为空 true -> 证据编码为空 代表第一次存证 ,false ->证据编码不为空 代表不是第一次存证
if (StringUtils.isEmpty(evidenceSn)) {
basicInformation = new EvidenceBasicInformation();
basicInformation.setReceiptStatus(0);
basicInformation.setStatus(0);
basicInformation.setIsCallback(0);
basicInformation.setCreateTime(new Date());
// basicInformation.setCreateTimeMs(applyDate.getTime());
basicInformation.setEndTime(EvidenceSaveServiceApi.convertDate(evidenceSaveService.getSaveTime()));
basicInformation.setEvidenceSize(fileSize);
basicInformation.setEvidenceSn(genSn);
basicInformation.setAppService(appService.getId());
basicInformation.setEvidenceStatus(1);
basicInformation.setApplicationInfo(applicationInfo.getId());
basicInformation.setOutAppService(evidenceSaveService.getAppServiceName());
basicInformation.setSaveServiceNmae(appService.getAppServiceName());
basicInformation.setServicePlatformName(applicationInfo.getName());
basicInformation.setServiceClientName(applicationInfo.getServiceClientName());
basicInformation.setServiceClientId(applicationInfo.getServiceClientId());
if (StringUtils.isNotEmpty(failureReason)) {
basicInformation.setFailureReason(failureReason);
basicInformation.setEvidenceStatus(0);
result.put("status", 0);
}
// 对要素 (接收 核验 必填) 操作进行处理
retSaveMap = saveFactor(retSaveMap, evidenceSaveService, genSn, jsonEvidenceContent, basicInformation, realNameAuthentication, realNameAuthenticationOss, serviceConfiguration, true);
} else {
EvidenceBasicInformationExample basicInformationExample = new EvidenceBasicInformationExample();
EvidenceBasicInformationExample.Criteria beCriteria = basicInformationExample.createCriteria();
beCriteria.andEvidenceSnEqualTo(evidenceSn);
List<EvidenceBasicInformation> basicInformationList = sqlSession.selectList("com.itrus.portal.db.EvidenceBasicInformationMapper.selectByExample", basicInformationExample);
if (basicInformationList.size() == 0 || basicInformationList.isEmpty()) {
result.put("status", 0);
result.put("message", "未找到对应证据编号信息");
return result;
}
basicInformation = basicInformationList.get(0);
if (basicInformation.getEvidenceStatus() != null && basicInformation.getEvidenceStatus() == 0) {
result.put("status", 0);
result.put("message", "本次证据补交失败。对应证据编号已存在核验失败信息,原因:" + basicInformation.getFailureReason());
return result;
}
// 得到提交次数
EvidenceEnclosureExample enclosureExample = new EvidenceEnclosureExample();
EvidenceEnclosureExample.Criteria eec = enclosureExample.createCriteria();
eec.andBasicInformationEqualTo(basicInformation.getId());
eec.andPdfTypeEqualTo("1");
List<EvidenceEnclosure> enclosures = sqlSession.selectList("com.itrus.portal.db.EvidenceEnclosureMapper.selectByExample", enclosureExample);
if (!enclosures.isEmpty()) {
count = enclosures.size();
}
basicInformation.setEvidenceSize(basicInformation.getEvidenceSize() + fileSize);
basicInformation.setAppService(appService.getId());
// 对要素 (接收 核验) 操作进行处理
retSaveMap = saveFactor(retSaveMap, evidenceSaveService, evidenceSn, jsonEvidenceContent, basicInformation, realNameAuthentication, realNameAuthenticationOss, serviceConfiguration, false);
}
String saveFactor = null;
if (retSaveMap.get("status") != null) {
result.put("status", retSaveMap.get("status"));
result.put("message", retSaveMap.get("message"));
return result;
} else {
List<Object> lists = (List<Object>) retSaveMap.get("objs");
for (Object obj : lists) {
objs.add(obj);
}
}
basicInformation = (EvidenceBasicInformation) retSaveMap.get("basicInformation");
if (basicInformation.getEvidenceStatus() != null && basicInformation.getEvidenceStatus() == 0) {
result.put("status", 0);
result.put("message", basicInformation.getEvidenceStatus());
return result;
}
// 得到加密证书别名
alias = CacheCustomer.getMAP_COMFIG().get((long) serviceConfiguration.getEncryptionCertificate());
if (StringUtils.isEmpty(alias)) {
alias = secretKeyService.getAliasByCertId((long) serviceConfiguration.getEncryptionCertificate());
}
// 内部加密存储证据包
String urlSave = realNameAuthentication.getRealNameddress() + "/storage/save";
Map<String, Object> mapSave = new HashMap<String, Object>();
mapSave.put("type", "ST_E");
mapSave.put("bucketName", realNameAuthenticationOss.getKeyCode());
mapSave.put("objectName", applicationInfo.getServiceClientId() + "/" + (StringUtils.isEmpty(evidenceSn) ? genSn : evidenceSn) + (count + 1));
mapSave.put("contentType", "CT_BASE64_DATA");
mapSave.put("content", Base64.encode(evidencePackage.getBytes("utf-8")));
mapSave.put("alias", alias);
mapSave.put("digestZValue", false);
mapSave.put("encAlg", serviceConfiguration.getEncryptionAlgorithm());
if (result.get("saveFactor") != null) {
saveFactor = retSaveMap.get("saveFactor").toString();
}
// 异步处理存储
// HttpAsyncClientUtil.getInstance().execute(
// urlSave,
// AuthService.getHeader(),
// mapSave,
// new EvidenceSavePackageTask(
// urlSave,
// mapSave,
// null,
// evidenceSn!=null?evidenceSn:genSn,
// Integer.toString(fileSize),
// genTime,
// applyDate,
// Integer.toString(evidenceSaveService.getSaveTime()),
// saveFactor));
// String retSave = clientService.postForm(urlSave, AuthService.getHeader(), mapSave);
String retSave = null;
try {
retSave = OkHttpClientManagerSave.post(urlSave, AuthService.getHeader().get("Authorization").toString(), mapSave);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
LogUtil.evidencelog(sqlSession, (evidenceSn != null ? evidenceSn : genSn).toString(), "存证接口_存储数据包", "存储数据包失败,证据编号:" + (evidenceSn != null ? evidenceSn : genSn).toString() + ", 请求参数:" + mapSave.toString() + ", 请求地址:" + urlSave + ",返回结果" + retSave + ", 失败原因:" + e.toString());
result.put("status", 0);
result.put("message", "证据存储失败");
return result;
}
JSONObject jsonSave = JSONObject.parseObject(retSave);
if (jsonSave.getIntValue("code") != 0) {
// 天威签名失败
LogUtil.evidencelog(sqlSession, (evidenceSn != null ? evidenceSn : genSn).toString(), "存证接口_存储数据包", "存储数据包失败,证据编号:" + (evidenceSn != null ? evidenceSn : genSn).toString() + ", 请求参数:" + mapSave.toString() + ", 请求地址:" + urlSave + ",返回结果" + retSave + ", 失败原因:" + jsonSave);
result.put("status", 0);
result.put("message", "证据存储失败");
return result;
} else {
EvidenceEnclosure enclosure = new EvidenceEnclosure();
enclosure.setBuid(jsonSave.getString("buid"));
enclosure.setEvidenceSn((evidenceSn != null ? evidenceSn : genSn).toString());
enclosure.setFilesize(Integer.toString(fileSize));
enclosure.setPdfType("1");
enclosure.setApplicationTime(applyDate);
enclosure.setCreateTime(new Date());
// enclosure.setCreateTimeMs(applyDate.getTime());
enclosure.setSaveTime(Integer.toString(evidenceSaveService.getSaveTime()));
if (mapSave.get("type") != null)
enclosure.setType(mapSave.get("type").toString());
if (mapSave.get("contentType") != null)
enclosure.setContentType(mapSave.get("contentType").toString());
if (mapSave.get("bucketName") != null)
enclosure.setBucketName(mapSave.get("bucketName").toString());
if (mapSave.get("objectName") != null)
enclosure.setObjectName(mapSave.get("objectName").toString());
if (mapSave.get("alias") != null)
enclosure.setAlias(mapSave.get("alias").toString());
enclosure.setFixationTime(new Date());
if (saveFactor != null) {
enclosure.setSaveFactor(saveFactor);
}
// queueThread.putObjectQueue(enclosure);
objs.add(enclosure);
}
// 判断是否为补交
if (count > 0) {
// 判断是否出过证据, true : 修改出证状态为部分出 ; 出证状态:0未出1待出2已出 3部分出 4出证失败
if (basicInformation.getStatus() == 2) {
basicInformation.setStatus(3);
}
}
// }
if ((int) result.get("status") == 1) {
// 判断是否需要生成存在回执
// if(evidenceSaveService.getAppServiceName() != null) {
// // 生成存证回执报告 查询存证时
// Map<String, Object> mapRet = reportTemplate.returnreceipt(basicInformation.getEvidenceSn(), applicationInfo);
// if(mapRet.get("status") != null && (int)mapRet.get("status") == 0) {
// basicInformation.setReceiptStatus(1);//存证回执状态1已出0未出
// } else {
// // throw new Exception("生成存证回执报告失败," + mapRet.get("message"));
// }
// }
// EvidenceSubmitDateExample dateExample = new EvidenceSubmitDateExample();
// EvidenceSubmitDateExample.Criteria criteria = dateExample.createCriteria();
// if(StringUtils.isNotBlank(evidenceSn))
// criteria.andEvidenceSnEqualTo(evidenceSn);
// else
// criteria.andEvidenceSnEqualTo(genSn);
// sqlSession.delete("com.itrus.portal.db.EvidenceClientTimeStampMapper.deleteByExample", dateExample);
} else {
basicInformation.setEvidenceStatus(0);
if (StringUtils.isEmpty(basicInformation.getFailureReason())) {
if (result.get("message") != null) {
basicInformation.setFailureReason(result.get("message").toString());
}
} else {
if (result.get("message") != null) {
basicInformation.setFailureReason(basicInformation.getFailureReason() + "," + result.get("message").toString());
}
}
}
// queueThread.putObjectQueue(basicInformation);
objs.add(basicInformation);
queueThread.putListQueue(objs);
// 记录计费流水
if ((int) mapCharging.get("retCode") == 1) {
// log.error("计费次数:" + counter.getAndIncrement());
// log.error("【计费】");
Map<String, Object> mapStoreCg = storeChargingService.storeCharging(appService.getServiceConfigName(), appService.getServiceConfigId(), applicationInfo, appService, null, "EvidenceBasicInformation", evidenceSaveService.getBaseSpace(), EvidenceSaveServiceApi.getSize(fileSize), StringUtils.isBlank(evidenceSn), (evidenceSn != null ? evidenceSn : genSn).toString());
// + ",totalSize__ : " + EvidenceSaveServiceApi.getSize(fileSize));
if ((int) mapStoreCg.get("retCode") != 1) {
result.put("status", -4);
result.put("message", "服务计费失败");
return result;
}
}
// sqlSession.update("com.itrus.portal.db.EvidenceBasicInformationMapper.updateByPrimaryKey", basicInformation);
// sqlSession.flushStatements();
// if((int)result.get("status") == 1) {
// LogUtil.evidencelog(sqlSession, "存证接口", "存证基础信息保存成功,证据编号:" + basicInformation.getEvidenceSn());
// } else {
// LogUtil.evidencelog(sqlSession, "存证接口", "存证失败,详情:"+ basicInformation.getEvidenceSn()
// + basicInformation.getFailureReason());
// }
} catch (Exception e) {
e.printStackTrace();
if (null == info) {
info = "系统处理异常!";
}
// StackTraceElement stackTraceElement = e.getStackTrace()[e.getStackTrace().length-2];
// info = stackTraceElement.getClassName() + stackTraceElement.getLineNumber() + e.toString();
LogUtil.evidencelog(sqlSession, (evidenceSn != null ? evidenceSn : genSn).toString(), "存证接口", "存证失败,证据编号:" + (evidenceSn != null ? evidenceSn : genSn).toString() + ", 失败原因:" + e.toString());
result.put("status", -5);
result.put("message", "系统服务错误,请联系管理员");
return result;
} finally {
result.remove("saveFactor");
result.remove("basicInformation");
}
return result;
}
Aggregations