Search in sources :

Example 1 with EvidenceSavePackageTask

use of com.itrus.portal.evidence.controller.threeAppAPIService.EvidenceSavePackageTask in project portal by ixinportal.

the class SaveTest method test.

@Test
public void test() throws Exception {
    String url = "http://192.168.100.104:5082/storage/save";
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("type", "ST_O");
    // map.put("nameSpace", "oss://hood/tcax");
    // map.put("bucketName", "hood"+File.separator+"CZQZicz201708101722191384196");
    map.put("bucketName", "test-cunzheng/CZQZicz201708101722191384196");
    map.put("objectName", "twcx.txt");
    map.put("contentType", "CT_MESSAGE");
    map.put("content", "123");
    // map.put("alias", "1ea0c251212556e8eb7be1c450b351e4ab94132a");
    // map.put("encAlg", "SM4");
    map.put("digestZValue ", false);
    Long startTime = System.currentTimeMillis();
    // String rep = HttpClientUtil.postForm(url, AuthService.getHeader(), map);
    String rep = OkHttpClientManagerSave.post(url, AuthService.getHeader().get("Authorization"), map);
    System.out.println("sync time is [" + (System.currentTimeMillis() - startTime) + "]");
    System.out.println("EntRep:" + rep);
    JSONObject ret_data = JSONObject.parseObject(rep);
    System.out.println("ret_data" + ret_data);
    Long startTime1 = System.currentTimeMillis();
    // String rep = HttpClientUtil.postForm(url, AuthService.getHeader(), map);
    OkHttpClientManagerSave.postAsyn(url, AuthService.getHeader().get("Authorization"), map, new EvidenceSavePackageTask(null, null, null, null, null, null, null, null, null));
    System.out.println("async time is [" + (System.currentTimeMillis() - startTime1) + "]");
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) HashMap(java.util.HashMap) JSONObject(com.alibaba.fastjson.JSONObject) EvidenceSavePackageTask(com.itrus.portal.evidence.controller.threeAppAPIService.EvidenceSavePackageTask) Test(org.junit.Test)

Example 2 with EvidenceSavePackageTask

use of com.itrus.portal.evidence.controller.threeAppAPIService.EvidenceSavePackageTask in project portal by ixinportal.

the class EvidenceSaveContractService method saveBody.

// 存证核验处理方法(pdf电子合同)
public Map<String, Object> saveBody(Map<String, Object> result1, ApplicationInfo applicationInfo1, AppService appService1, 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) {
    Map<String, Object> result = result1;
    ApplicationInfo applicationInfo = applicationInfo1;
    AppService appService = appService1;
    List<Object> objs = new ArrayList<Object>();
    String info = null;
    // 证据服务记录
    EvidenceBasicInformation basicInformation = null;
    // 本次证据包大小
    int fileSize = evidencePackage.getBytes().length;
    // 定义一个证据的提交次数
    int count = 0;
    String failureReason = null;
    String sn = genSn;
    if (StringUtils.isNotBlank(evidenceSn)) {
        sn = evidenceSn;
    }
    try {
        // 得到证据包json
        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.setEvidenceSn(sn);
        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");
                            param.put("content", HMACSHA1.getDigest(serviceConfiguration.getArithmetic(), evidencePackage));
                            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,
                    // sn,
                    // Long.parseLong(evidenceCertificate.getCert())));
                    // 异步处理p7签名
                    // OkHttpClientManagerSign.postAsyn(
                    // url,
                    // AuthService.getHeader().get("Authorization").toString(),
                    // param,
                    // new EvidenceSignTask(
                    // url,
                    // param,
                    // sn,
                    // Long.parseLong(evidenceCertificate.getCert())));
                    String strP7 = null;
                    try {
                        long p7Sign = System.currentTimeMillis();
                        strP7 = OkHttpClientManagerSign.post(url, AuthService.getHeader().get("Authorization").toString(), param);
                        log.error("p7Sign time is [" + (System.currentTimeMillis() - p7Sign) + "]");
                    } catch (Exception e) {
                        e.printStackTrace();
                        LogUtil.evidencelog(sqlSession, sn, "存证接口_天威签名", "天威签名失败,证据编号:" + sn + ", 请求参数:" + param.toString() + ", 请求地址:" + url + ", 返回结果:" + strP7 + ", 失败原因:" + e.toString());
                        result.put("status", 0);
                        result.put("message", "天威签名失败");
                        return result;
                    }
                    JSONObject jsonRepP7Sign = JSONObject.parseObject(strP7);
                    if (jsonRepP7Sign.getIntValue("code") != 0) {
                        // 天威签名失败
                        LogUtil.evidencelog(sqlSession, sn, "存证接口_天威签名", "天威签名失败,证据编号:" + sn + ", 请求参数:" + param.toString() + ", 请求地址:" + url + ", 返回结果:" + strP7 + ", 失败原因:" + jsonRepP7Sign);
                        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(sn);
                        signature.setSignatureType("2");
                        signature.setCertId(Long.parseLong(evidenceCertificate.getCert()));
                        signature.setHashvalue(param.get("content").toString());
                        signature.setSignaturevalue(jsonRepP7Sign.getString("signedData"));
                        signature.setCreateTime(new Date());
                        objs.add(signature);
                    }
                    evidenceCertificate = null;
                }
            }
            // 判断是否需要签名时间戳
            if (evidenceSaveService.getFixationWay() == 3 || evidenceSaveService.getFixationWay() == 4) {
                // 对证据包HASH
                String plainHash = HMACSHA1.getDigest(serviceConfiguration.getArithmetic(), evidencePackage);
                // 异步处理时间戳   ---  本期是实现新版本接口
                long timeSign = System.currentTimeMillis();
                Map<String, Object> retTime = EvidenceSaveServiceApi.genTimeStamp(realNameAuthenticationTime, plainHash, serviceConfiguration.getArithmetic(), sn, null);
                log.error("timeSign time is [" + (System.currentTimeMillis() - timeSign) + "]");
                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.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);
            }
            // 对要素 (接收 核验 必填) 操作进行处理
            long saveFactorTime = System.currentTimeMillis();
            retSaveMap = saveFactor(retSaveMap, evidenceSaveService, genSn, jsonEvidenceContent, basicInformation, realNameAuthentication, realNameAuthenticationOss, serviceConfiguration, true, applyDate.getTime());
            log.error("saveFactorTime time is [" + (System.currentTimeMillis() - saveFactorTime) + "]");
        } else {
            result.put("status", 0);
            result.put("message", "提交证据失败,系统暂不支持补交功能。");
            return result;
        }
        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() + "/" + sn + (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());
        String saveFactor = null;
        if (retSaveMap.get("saveFactor") != null) {
            saveFactor = retSaveMap.get("saveFactor").toString();
        }
        // 异步处理存储
        // long saveTime = System.currentTimeMillis();
        // HttpAsyncClientUtil.getInstance().execute(
        // urlSave,
        // AuthService.getHeader(),
        // mapSave,
        // new EvidenceSavePackageTask(
        // urlSave,
        // mapSave,
        // null,
        // (StringUtils.isEmpty(evidenceSn) ? genSn : evidenceSn),
        // fileSize,
        // null,
        // applyDate,
        // Integer.toString(evidenceSaveService.getSaveTime()),
        // saveFactor));
        // log.error("saveTime time is [" + (System.currentTimeMillis() - saveTime) + "]");
        log.error("save is " + (!(evidenceSaveService.getEncryptionWay() == null || evidenceSaveService.getEncryptionWay() == 0)));
        if (!(evidenceSaveService.getEncryptionWay() == null || evidenceSaveService.getEncryptionWay() == 0)) {
            // String retSave = null;
            // try {
            // long saveTime = System.currentTimeMillis();
            // retSave = OkHttpClientManagerSave.post(urlSave, AuthService.getHeader().get("Authorization").toString(), mapSave);
            // log.error("saveTime time is [" + (System.currentTimeMillis() - saveTime) + "]");
            // } catch (Exception e) {
            // e.printStackTrace();
            // LogUtil.evidencelog(sqlSession, sn, "存证接口_存储数据包", "存储数据包失败,证据编号:"
            // + sn +  ", 请求地址:"
            // + 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, sn, "存证接口_存储数据包", "存储数据包失败,证据编号:"
            // + sn + ", 请求地址:" + urlSave
            // + ",返回结果" + retSave + ", 失败原因:" + jsonSave.getString("message"));
            // 
            // result.put("status", 0);
            // result.put("message", "证据存储失败");
            // return result;
            // 
            // } else {
            // EvidenceEnclosure enclosure = new EvidenceEnclosure();
            // enclosure.setBuid(jsonSave.getString("buid"));
            // enclosure.setEvidenceSn(sn);
            // enclosure.setFilesize(Integer.toString(fileSize));
            // enclosure.setPdfType("1");
            // enclosure.setApplicationTime(applyDate);
            // enclosure.setCreateTime(new Date());
            // 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);
            // }
            // objs.add(enclosure);
            // }
            long saveTime = System.currentTimeMillis();
            OkHttpClientManagerSave.postAsyn(urlSave, AuthService.getHeader().get("Authorization").toString(), mapSave, new EvidenceSavePackageTask(urlSave, mapSave, null, sn, fileSize, null, applyDate, Integer.toString(evidenceSaveService.getSaveTime()), saveFactor));
            log.error("saveTime time is [" + (System.currentTimeMillis() - saveTime) + "]");
        }
        if ((int) result.get("status") == 1) {
        } 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());
                }
            }
        }
        objs.add(basicInformation);
        // 记录计费流水
        if ((int) mapCharging.get("retCode") == 1) {
            Map<String, Object> mapStoreCg = storeChargingService.storeCharging(appService.getServiceConfigName(), appService.getServiceConfigId(), applicationInfo, appService, null, "EvidenceBasicInformation", evidenceSaveService.getBaseSpace(), EvidenceSaveServiceApi.getSize(fileSize), StringUtils.isBlank(evidenceSn), sn);
            // + ",totalSize__ : " + EvidenceSaveServiceApi.getSize(fileSize));
            if ((int) mapStoreCg.get("retCode") != 1) {
                result.put("status", -4);
                result.put("message", "服务计费失败");
                return result;
            }
        }
        boolean l = false;
        for (Object o : objs) {
            if (o == null)
                l = true;
        }
        log.error("objs count is [" + objs.size() + "]" + ", objsIncNull is" + l);
        queueThread.putListQueue(objs);
    } catch (Exception e) {
        e.printStackTrace();
        if (null == info) {
            info = "系统处理异常!";
        }
        LogUtil.evidencelog(sqlSession, sn, "存证接口", "存证失败,证据编号:" + sn + ", 失败原因:" + e.toString());
        result.put("status", -5);
        result.put("message", "系统服务错误,请联系管理员");
        return result;
    } finally {
        result.remove("saveFactor");
        result.remove("basicInformation");
    }
    return result;
}
Also used : AppService(com.itrus.portal.db.AppService) EvidenceBasicInformation(com.itrus.portal.db.EvidenceBasicInformation) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ApplicationInfo(com.itrus.portal.db.ApplicationInfo) ArrayList(java.util.ArrayList) EvidenceSavePackageTask(com.itrus.portal.evidence.controller.threeAppAPIService.EvidenceSavePackageTask) Date(java.util.Date) EvidenceServiceConfiguration(com.itrus.portal.db.EvidenceServiceConfiguration) JSONObject(com.alibaba.fastjson.JSONObject) EvidenceCertificate(com.itrus.portal.db.EvidenceCertificate) JSONObject(com.alibaba.fastjson.JSONObject) List(java.util.List) ArrayList(java.util.ArrayList) EvidenceClientSignature(com.itrus.portal.db.EvidenceClientSignature)

Aggregations

JSONObject (com.alibaba.fastjson.JSONObject)2 EvidenceSavePackageTask (com.itrus.portal.evidence.controller.threeAppAPIService.EvidenceSavePackageTask)2 HashMap (java.util.HashMap)2 AppService (com.itrus.portal.db.AppService)1 ApplicationInfo (com.itrus.portal.db.ApplicationInfo)1 EvidenceBasicInformation (com.itrus.portal.db.EvidenceBasicInformation)1 EvidenceCertificate (com.itrus.portal.db.EvidenceCertificate)1 EvidenceClientSignature (com.itrus.portal.db.EvidenceClientSignature)1 EvidenceServiceConfiguration (com.itrus.portal.db.EvidenceServiceConfiguration)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 List (java.util.List)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Test (org.junit.Test)1