Search in sources :

Example 11 with ApplicationInfo

use of com.itrus.portal.db.ApplicationInfo in project portal by ixinportal.

the class StoreChargingServiceImpl method getApplicationInfoByAppId.

/**
 * 根据appid,获取ApplicationInfo
 *
 * @param appId
 * @return
 */
public ApplicationInfo getApplicationInfoByAppId(String appId) {
    ApplicationInfo applicationInfo = new ApplicationInfo();
    ApplicationInfoExample aie = new ApplicationInfoExample();
    ApplicationInfoExample.Criteria criteria = aie.or();
    criteria.andAppIdEqualTo(appId);
    applicationInfo = sqlSession.selectOne("com.itrus.portal.db.ApplicationInfoMapper.selectByExample", aie);
    return applicationInfo;
}
Also used : ApplicationInfoExample(com.itrus.portal.db.ApplicationInfoExample) ApplicationInfo(com.itrus.portal.db.ApplicationInfo)

Example 12 with ApplicationInfo

use of com.itrus.portal.db.ApplicationInfo in project portal by ixinportal.

the class MobileChargingFailTask method ChargingAgain.

/**
 * 遍历所有计费失败的记录,重新计费
 *
 * @Scheduled(fixedRate = 1000 * 60 * 60 * 24) 设置为每天凌晨2点触发
 * @Scheduled(cron = "0 0 2 * * ?")
 */
@Scheduled(cron = "0 0/45 * * * ?")
public void ChargingAgain() {
    // start------------处理双机互斥----------
    // 系统是否配置同步任务的主机名
    SysConfig sysConfigHost = sqlSession.selectOne("com.itrus.portal.db.SysConfigMapper.selectByType", "raInfoHost");
    if (null == sysConfigHost) {
        // 没有配置,直接返回
        return;
    }
    String host = sysConfigHost.getConfig();
    host = host.replaceAll(" ", "");
    String[] hosts = host.split(",");
    // 获取本机主机名称
    InetAddress ia = null;
    try {
        ia = ia.getLocalHost();
    } catch (UnknownHostException e1) {
        e1.printStackTrace();
        return;
    }
    String hostName = ia.getHostName();
    boolean flag_check = false;
    for (String str : hosts) {
        if (hostName.equals(str.replaceAll(" ", ""))) {
            flag_check = true;
        }
    }
    // 判断本地主机名称是否与系统配置的同步主机名称一致,不一致则返回
    if (!flag_check) {
        return;
    }
    // end------------处理双机互斥----------
    List<MobileChargingFail> chargingFails = chargingFailService.geChargingFails();
    if (null == chargingFails || chargingFails.size() == 0) {
        return;
    }
    for (int i = 0; i < chargingFails.size(); i++) {
        MobileChargingFail chargingFail = chargingFails.get(i);
        Map<String, Object> retMap = new HashMap<String, Object>();
        ApplicationInfo applicationInfo = appServiceChargingService.getApplicationInfoByAppId(chargingFail.getAppId());
        // AppService appService = certificationChargingService.getAppServiceByAppServiceId(chargingFail.getAppServiceId());
        retMap = appServiceChargingService.charging(chargingFail.getAppId(), /* chargingFail.getAppServiceId(),
					chargingFail.getTransinfoName(),
					chargingFail.getTransinfoId(),*/
        applicationInfo, /*chargingFail.getTransinfoPrimaryId(),*/
        chargingFail.getTransinfoTableName());
        Integer flag = (Integer) retMap.get("retCode");
        // 若插入成功
        if (null != flag && flag == 1) {
            chargingFail.setIsValidity(false);
            chargingFail.setModifyTime(new Date());
            Charging charging = (Charging) retMap.get("charging");
            chargingFail.setChargingId(charging.getChargingId());
            chargingFailService.update(chargingFail);
        }
    }
}
Also used : SysConfig(com.itrus.portal.db.SysConfig) Charging(com.itrus.portal.db.Charging) UnknownHostException(java.net.UnknownHostException) HashMap(java.util.HashMap) ApplicationInfo(com.itrus.portal.db.ApplicationInfo) MobileChargingFail(com.itrus.portal.db.MobileChargingFail) Date(java.util.Date) InetAddress(java.net.InetAddress) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Example 13 with ApplicationInfo

use of com.itrus.portal.db.ApplicationInfo in project portal by ixinportal.

the class MobileChargingFlowTask method charging.

/**
 * 遍历所有计费失败的记录,重新计费
 *
 * @Scheduled(fixedRate = 1000 * 60 * 60 * 24) 设置为每天凌晨2点触发
 * @Scheduled(cron = "0 0 2 * * ?")
 * "0 0 12 * * ?" 每天中午12点触发
 * 	@Scheduled(cron = "0/10 * * * * ?")
 */
// @Scheduled(fixedRate = 1000 * 60 * 60 * 24) //设置为每天凌晨2点触发
@Scheduled(cron = "0 0 2 * * ?")
public void charging() {
    synchronized (ChargingFlowTaskLock) {
        // start------------处理双机互斥----------
        if (null == taskFlag) {
            taskFlag = systemConfigService.isTimedTaskHost();
        }
        if (taskFlag.equals(false)) {
            return;
        }
        // end------------处理双机互斥----------
        // 计算没有记账的总数
        ChargingFlowExample cfe = new ChargingFlowExample();
        ChargingFlowExample.Criteria criteria = cfe.or();
        criteria.andIsChargingEqualTo(false);
        Integer count = sqlSession.selectOne("com.itrus.portal.db.ChargingFlowMapper.countByExample", cfe);
        if (count == 0) {
            return;
        }
        Map<Long, ApplicationInfo> applicationInfoMap = applicationInfoService.selectAppInformationMap();
        /*Map<Long, AppService> appServiceMap = appServiceExt
					.selectAppServicerMap();*/
        // 分页查询信息
        Integer page = 1;
        Integer size = 50;
        Integer offset = size * (page - 1);
        // 循环的次数
        Integer time = 0;
        // 批帐成功次数
        Integer successNum = 0;
        // 清空失败次数
        failTotalNum = 0;
        time = (count + size - 1) / size;
        for (int i = time; i > 0; i--) {
            // 查询条件设置一次即可,因为每次循环,都会把前面的false
            MobileChargingFlowExample cfe2 = new MobileChargingFlowExample();
            MobileChargingFlowExample.Criteria criteria2 = cfe2.or();
            criteria2.andIsChargingEqualTo(false);
            cfe2.setLimit(size);
            // 当失败次数大于0的时候,设置将失败次数加入偏移量中,避免失败很多的时候,全部在循环那些失败的.
            if (failTotalNum > 0) {
                cfe2.setOffset(offset + failTotalNum);
            } else {
                cfe2.setOffset(offset);
            }
            List<MobileChargingFlow> chargingFlows = chargingFlowService.selectListByExample(cfe2);
            for (MobileChargingFlow chargingFlow : chargingFlows) {
                DefaultTransactionDefinition dtd = new DefaultTransactionDefinition();
                // 事物的传播行为,使用同一个事物
                dtd.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
                TransactionStatus status = transactionManager.getTransaction(dtd);
                try {
                    ApplicationInfo applicationInfo = applicationInfoMap.get(chargingFlow.getApplicationInfo());
                    /*AppService appService = appServiceMap.get(chargingFlow
								.getAppService());*/
                    Map<String, Object> retMap = new HashMap<>();
                    if (chargingFlow.getChargingType().equals(ComNames.SERVICE_TYPE_FOUR)) {
                        // 移动端计费
                        retMap = appSeviceChargingService.chargingTask(// chargingFlow.getTransinfoId(),
                        applicationInfo, // chargingFlow.getTransinfoPrimaryId(),
                        chargingFlow.getTransinfoTableName(), chargingFlow.getId());
                    }
                    Integer retCode = (Integer) retMap.get("retCode");
                    if (null != retCode && retCode == 1) {
                        successNum++;
                        Map<String, Long> map = new HashMap<>();
                        Charging charging = (Charging) retMap.get("charging");
                        chargingFlowService.recoderHasCharing(chargingFlow, charging.getId());
                        transactionManager.commit(status);
                    } else {
                        transactionManager.rollback(status);
                        // 失败总数加1
                        failTotalNum++;
                        // 获取失败记录的流水号id和上次记录的失败时间
                        Date date = failFlowIdMap.get(chargingFlow.getId());
                        if (null != date) {
                            long timeInMS = compareDate(date);
                            if (timeInMS > HALF_OF_THE_DAY) {
                                LogUtil.syslog(sqlSession, "计费批帐,单条流水失败", "错误信息:" + retMap.get("retMsg") + "流水号为:" + chargingFlow.getId());
                                // 更新失败记录时间
                                failFlowIdMap.put(chargingFlow.getId(), new Date());
                            }
                        } else {
                            // 流水号第一次失败
                            failFlowIdMap.put(chargingFlow.getId(), new Date());
                            LogUtil.syslog(sqlSession, "计费批帐,单条流水失败", "错误信息:" + retMap.get("retMsg") + "流水号为:" + chargingFlow.getId());
                        }
                    }
                } catch (Exception e) {
                    transactionManager.rollback(status);
                    // 失败总数加1
                    failTotalNum++;
                    // 获取失败记录的流水号id和上次记录的失败时间
                    Date date = failFlowIdMap.get(chargingFlow.getId());
                    if (null != date) {
                        long timeInMS = compareDate(date);
                        if (timeInMS > HALF_OF_THE_DAY) {
                            LogUtil.syslog(sqlSession, "计费批帐,单条流水失败", "异常信息:" + e.getMessage() + "流水号为:" + chargingFlow.getId());
                            // 更新失败记录时间
                            failFlowIdMap.put(chargingFlow.getId(), new Date());
                        }
                    } else {
                        // 流水号第一次失败
                        failFlowIdMap.put(chargingFlow.getId(), new Date());
                        LogUtil.syslog(sqlSession, "计费批帐,单条流水失败", "异常信息:" + e.getMessage() + "流水号为:" + chargingFlow.getId());
                    }
                }
            }
        }
        // 当有成功批帐的记录,就记录
        if (successNum > 0) {
            LogUtil.syslog(sqlSession, "计费批帐", "本次批帐成功的流水总数量为:" + successNum + ", 未批帐的流水总量为:" + (count - successNum >= 0 ? count - successNum : 0));
            // 批帐完成,本机重新初始化缓存,通知另外一台机器从数据库加载缓存数据
            cacheCustomer.initChargeRule();
            CertificationChargingHandler cch = new CertificationChargingHandler();
            QueueThread.buildCertificationTask(cch);
        } else {
            // 当全部是失败的时候,则判断失败总数和上次记录全部是失败的时间
            // 获取失败记录的流水号id和上次记录的失败时间
            Date date = failFlowTotalMap.get(failTotalNum);
            if (null != date) {
                long timeInMS = compareDate(date);
                if (timeInMS > HALF_OF_THE_DAY) {
                    LogUtil.syslog(sqlSession, "计费批帐,多条流水失败", "失败流水总量为:" + failTotalNum);
                    // 更新失败记录时间
                    failFlowTotalMap.put(failTotalNum, new Date());
                    return;
                }
            } else {
                // 流水失败总数第一次出现
                failFlowTotalMap.put(failTotalNum, new Date());
                LogUtil.syslog(sqlSession, "计费批帐,多条流水失败", "失败流水总量为:" + failTotalNum);
                return;
            }
        }
    }
}
Also used : Charging(com.itrus.portal.db.Charging) DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) HashMap(java.util.HashMap) ChargingFlowExample(com.itrus.portal.db.ChargingFlowExample) MobileChargingFlowExample(com.itrus.portal.db.MobileChargingFlowExample) ApplicationInfo(com.itrus.portal.db.ApplicationInfo) TransactionStatus(org.springframework.transaction.TransactionStatus) Date(java.util.Date) MobileChargingFlowExample(com.itrus.portal.db.MobileChargingFlowExample) MobileChargingFlow(com.itrus.portal.db.MobileChargingFlow) CertificationChargingHandler(com.itrus.portal.service.CertificationChargingHandler) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Example 14 with ApplicationInfo

use of com.itrus.portal.db.ApplicationInfo in project portal by ixinportal.

the class ChargingFailTask method ChargingAgain.

/**
 * 遍历所有计费失败的记录,重新计费
 *
 * @Scheduled(fixedRate = 1000 * 60 * 60 * 24) 设置为每天凌晨2点触发
 * @Scheduled(cron = "0 0 2 * * ?")
 */
@Scheduled(cron = "0 0/45 * * * ?")
public void ChargingAgain() {
    // start------------处理双机互斥----------
    // 系统是否配置同步任务的主机名
    SysConfig sysConfigHost = sqlSession.selectOne("com.itrus.portal.db.SysConfigMapper.selectByType", "raInfoHost");
    if (null == sysConfigHost) {
        // 没有配置,直接返回
        return;
    }
    String host = sysConfigHost.getConfig();
    host = host.replaceAll(" ", "");
    String[] hosts = host.split(",");
    // 获取本机主机名称
    InetAddress ia = null;
    try {
        ia = ia.getLocalHost();
    } catch (UnknownHostException e1) {
        e1.printStackTrace();
        return;
    }
    String hostName = ia.getHostName();
    boolean flag_check = false;
    for (String str : hosts) {
        if (hostName.equals(str.replaceAll(" ", ""))) {
            flag_check = true;
        }
    }
    // 判断本地主机名称是否与系统配置的同步主机名称一致,不一致则返回
    if (!flag_check) {
        return;
    }
    // end------------处理双机互斥----------
    List<ChargingFail> chargingFails = chargingFailService.geChargingFails();
    if (null == chargingFails || chargingFails.size() == 0) {
        return;
    }
    for (int i = 0; i < chargingFails.size(); i++) {
        ChargingFail chargingFail = chargingFails.get(i);
        Map<String, Object> retMap = new HashMap<String, Object>();
        ApplicationInfo applicationInfo = certificationChargingService.getApplicationInfoByAppId(chargingFail.getAppId());
        AppService appService = certificationChargingService.getAppServiceByAppServiceId(chargingFail.getAppServiceId());
        retMap = certificationChargingService.charging(chargingFail.getAppId(), chargingFail.getAppServiceId(), chargingFail.getTransinfoName(), chargingFail.getTransinfoId(), applicationInfo, appService, chargingFail.getTransinfoPrimaryId(), chargingFail.getTransinfoTableName());
        Integer flag = (Integer) retMap.get("retCode");
        // 若插入成功
        if (null != flag && flag == 1) {
            chargingFail.setIsValidity(false);
            chargingFail.setModifyTime(new Date());
            Charging charging = (Charging) retMap.get("charging");
            chargingFail.setChargingId(charging.getChargingId());
            chargingFailService.update(chargingFail);
        }
    }
}
Also used : SysConfig(com.itrus.portal.db.SysConfig) AppService(com.itrus.portal.db.AppService) Charging(com.itrus.portal.db.Charging) UnknownHostException(java.net.UnknownHostException) HashMap(java.util.HashMap) ApplicationInfo(com.itrus.portal.db.ApplicationInfo) Date(java.util.Date) ChargingFail(com.itrus.portal.db.ChargingFail) InetAddress(java.net.InetAddress) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Example 15 with ApplicationInfo

use of com.itrus.portal.db.ApplicationInfo 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

ApplicationInfo (com.itrus.portal.db.ApplicationInfo)59 HashMap (java.util.HashMap)36 ApplicationInfoExample (com.itrus.portal.db.ApplicationInfoExample)25 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)25 JSONObject (com.alibaba.fastjson.JSONObject)19 AppService (com.itrus.portal.db.AppService)19 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)16 Date (java.util.Date)13 EvidenceBasicInformation (com.itrus.portal.db.EvidenceBasicInformation)11 ArrayList (java.util.ArrayList)11 IOException (java.io.IOException)8 PostMapping (org.springframework.web.bind.annotation.PostMapping)8 Map (java.util.Map)7 Bill (com.itrus.portal.db.Bill)6 RealNameAuthentication (com.itrus.portal.db.RealNameAuthentication)6 Enterprise (com.itrus.portal.db.Enterprise)4 UserInfoServiceException (com.itrus.portal.exception.UserInfoServiceException)4 JSONException (org.json.JSONException)4 TransactionStatus (org.springframework.transaction.TransactionStatus)4 DefaultTransactionDefinition (org.springframework.transaction.support.DefaultTransactionDefinition)4