Search in sources :

Example 41 with ApplicationInfo

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

the class EvidenceSaveServiceApi method saveCallBack1.

@RequestMapping("/savecallback1")
@ResponseBody
public Map<String, Object> saveCallBack1(@RequestParam(value = "evidenceSn", required = false) String evidenceSn, HttpServletRequest request) throws Exception {
    EvidenceBasicInformation basicInformation = informationService.getInformationBySn(evidenceSn, null);
    // 调用生成回执报告方法
    ApplicationInfo applicationInfo = CacheCustomer.getAPP_INFO_MAP_BY_ID().get(basicInformation.getApplicationInfo());
    if (applicationInfo == null) {
        // TODO: 2018/3/15 从缓存取
        applicationInfo = infoService.selectById(basicInformation.getApplicationInfo());
    }
    Map<String, Object> mapRet = reportTemplate.returnreceipt(evidenceSn, applicationInfo, null);
    log.error("EvidenceQueryQueue mapRet is " + mapRet.get("status"));
    ;
    if (mapRet.get("status") != null && (int) mapRet.get("status") == 0) {
        // 修改证据基本信息回执状态为已出
        String reportBase64 = (String) mapRet.get("pdfBase64");
        basicInformation.setReceiptStatus(1);
        sqlSession.update("com.itrus.portal.db.EvidenceBasicInformationMapper.updateByPrimaryKey", basicInformation);
    }
    Map<String, Object> retMap = new HashMap<>();
    retMap.put("code", "1");
    retMap.put("message", "回调申请成功。");
    return retMap;
}
Also used : EvidenceBasicInformation(com.itrus.portal.db.EvidenceBasicInformation) HashMap(java.util.HashMap) ApplicationInfo(com.itrus.portal.db.ApplicationInfo) JSONObject(com.alibaba.fastjson.JSONObject) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 42 with ApplicationInfo

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

the class EvidenceSaveServiceApi method save.

// @Autowired
// private ProducerService producerService;
// 回执报告缓存Map key:证据编号  value:回执base64
// public static ConcurrentHashMap<String, String> cacheReportBySnMap = new ConcurrentHashMap<>();
/**
 * 存证接口
 * @param signature
 * 			签名值
 * @param appId
 * 			应用id
 * @param serviceCode
 * 			服务编号
 * @param evidenceSn
 * 			证据编号
 * @param signedBase64
 * 			签名值base64
 * @param evidencePackage
 * 			证据包
 * @param request
 * @return
 */
@RequestMapping("/save")
@ResponseBody
public Map<String, Object> save(@RequestHeader("Content-Signature") String signature, @RequestParam(value = "appId", required = false) String appId, @RequestParam(value = "serviceCode", required = false) String serviceCode, @RequestParam(value = "evidenceSn", required = false) String evidenceSn, @RequestParam(value = "hashAlg", required = false) String hashAlg, @RequestParam(value = "signedBase64", required = false) String signedBase64, @RequestParam(value = "evidencePackage", required = false) String evidencePackage, HttpServletRequest request) {
    // 返回值
    Map<String, Object> result = new HashMap<String, Object>();
    result.put("status", 1);
    // 申请时间
    Date date = new Date();
    // 验证参数是否完整
    if (StringUtils.isEmpty(signature) || StringUtils.isEmpty(appId) || StringUtils.isEmpty(serviceCode) || StringUtils.isEmpty(evidencePackage) || StringUtils.isEmpty(hashAlg) || StringUtils.isEmpty(signedBase64)) {
        result.put("status", 0);
        result.put("message", "提交的参数信息不完整");
        return result;
    }
    // 获取对应应用信息
    ApplicationInfo applicationInfo = applicationInfoService.getApplicationInfo(appId);
    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 + serviceCode + evidenceSn + hashAlg + signedBase64 + evidencePackage, 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;
    }
    // 获取对应应用信息
    EvidenceSaveService evidenceSaveService = null;
    AppService appService = appServiceExt.getAppService(serviceCode);
    if (appService != null && "EvidenceSaveService".equals(appService.getServiceConfigName())) {
        evidenceSaveService = saveServiceImpl.selectById(appService.getServiceConfigId());
    } else {
        result.put("status", -21);
        result.put("message", "应用服务不存在");
        return result;
    }
    if (evidenceSaveService == null) {
        result.put("status", -21);
        result.put("message", "应用服务不存在");
        return result;
    }
    if (appService.getIsAppServiceStatus() == 0) {
        result.put("status", -22);
        result.put("message", "服务已关闭");
        return result;
    }
    // 获取存证回执模版
    if (evidenceSaveService.getAppServiceName() != null) {
        AppService appServiceOut = CacheCustomer.APP_SERVICE_MAP_BY_ID().get(evidenceSaveService.getAppServiceName());
        if (appServiceOut == null) {
            appServiceOut = appServiceExt.selectById(evidenceSaveService.getAppServiceName());
            if (appServiceOut == null) {
                result.put("status", -22);
                result.put("message", "回执模版不存在");
                return result;
            }
        }
    }
    if (StringUtils.isNotEmpty(evidenceSn)) {
        EvidenceBasicInformation basicInformation = basicInformationService.getInformationBySn(evidenceSn, 1);
        if (basicInformation != null) {
            result.put("status", 0);
            result.put("message", "该证据不可补交");
            return result;
        }
    }
    RealNameAuthentication realNameAuthentication = null;
    RealNameAuthentication realNameAuthenticationTime = null;
    RealNameAuthentication realNameAuthenticationOss = null;
    try {
        // 获取原子服务地址  1.实名认证  2.密码服务  3.时间戳  4.OSS
        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;
        }
        // 获取原子服务地址  1.实名认证  2.密码服务  3.时间戳  4.OSS
        realNameAuthenticationTime = CacheCustomer.getAUTH_CONFIG_MAP().get(3);
        if (realNameAuthenticationTime == null) {
            realNameAuthenticationTime = realNameAuthenticationSerivce.getRealNameAuthenticationByThree();
        }
        if (realNameAuthenticationTime == null) {
            result.put("status", -6);
            result.put("message", "缺少时间戳服务配置,请联系管理员");
            return result;
        }
        // 获取原子服务地址  1.实名认证  2.密码服务  3.时间戳  4.OSS
        realNameAuthenticationOss = CacheCustomer.getAUTH_CONFIG_MAP().get(4);
        if (realNameAuthenticationOss == null) {
            realNameAuthenticationOss = realNameAuthenticationSerivce.getRealNameAuthenticationByOss();
        }
        if (realNameAuthenticationOss == null) {
            result.put("status", -6);
            result.put("message", "缺少OSS配置,请联系管理员");
            return result;
        }
        // 本次证据包大小
        int fileSize = evidencePackage.getBytes("utf-8").length;
        // 存证计费校验接口
        Map<String, Object> mapCharging = storeChargingService.checkStoreCharging(StringUtils.isBlank(evidenceSn), applicationInfo, appService, evidenceSaveService.getBaseSpace(), getSize(fileSize));
        // log.debug("存证计费校验   mapCharging__ : " + mapCharging);
        if ((int) mapCharging.get("retCode") == 0) {
            result.put("status", -4);
            if (mapCharging.get("retMsg") != null)
                result.put("message", mapCharging.get("retMsg"));
            else
                result.put("message", "服务计费失败");
            return result;
        }
        // 证据包申请
        String hashvalue = HMACSHA1.getDigest(hashAlg, evidencePackage);
        // 1.验签之后返回
        List<String> certs = verifySign(result, applicationInfo, evidenceSaveService, hashvalue, signedBase64, realNameAuthentication);
        Date dateVp = (Date) result.get("dateVp");
        Date dateVc = (Date) result.get("dateVc");
        result.remove("dateVp");
        result.remove("dateVc");
        if (null != certs) {
            String genSn = null;
            if (StringUtils.isEmpty(evidenceSn)) {
                genSn = UniqueIDUtils.genAppServiceUID(applicationInfo, appService.getAppServiceName(), sqlSession, 3);
            }
            result = saveTask.saveBody(result, applicationInfo, appService, evidenceSaveService, date, evidenceSn, genSn, signedBase64, evidencePackage, hashAlg, hashvalue, dateVp, dateVc, certs, realNameAuthentication, realNameAuthenticationTime, realNameAuthenticationOss, mapCharging);
            if ((int) result.get("status") == 1) {
                result.put("message", "申请存证成功,请稍后通过查询存证接口查看存证结果!");
                if (StringUtils.isNotEmpty(evidenceSn))
                    result.put("evidenceSn", evidenceSn);
                else
                    result.put("evidenceSn", genSn);
            }
        } else {
            result.put("status", -8);
            result.put("message", "验证证书失败");
        }
        return result;
    } catch (Exception e) {
        e.printStackTrace();
        if (e instanceof IllegalStateException) {
            result.put("status", -100);
            result.put("message", "当前系统忙,请稍后再尝试!");
            return result;
        }
        StackTraceElement stackTraceElement = e.getStackTrace()[e.getStackTrace().length - 2];
        String info = stackTraceElement.getClassName() + stackTraceElement.getLineNumber() + e.toString();
        LogUtil.evidencelog(sqlSession, null, "存证接口", "申请存证失败,失败原因:" + info);
        result = new HashMap<String, Object>();
        result.put("status", -5);
        result.put("message", "系统服务错误,请联系管理员");
        return result;
    } finally {
        if (realNameAuthentication != null) {
            realNameAuthentication = null;
        }
        if (realNameAuthenticationOss != null) {
            realNameAuthenticationOss = null;
        }
        if (realNameAuthenticationTime != null) {
            realNameAuthenticationTime = null;
        }
    }
}
Also used : AppService(com.itrus.portal.db.AppService) HashMap(java.util.HashMap) EvidenceBasicInformation(com.itrus.portal.db.EvidenceBasicInformation) ApplicationInfo(com.itrus.portal.db.ApplicationInfo) EvidenceSaveService(com.itrus.portal.db.EvidenceSaveService) RealNameAuthentication(com.itrus.portal.db.RealNameAuthentication) Date(java.util.Date) IOException(java.io.IOException) JSONObject(com.alibaba.fastjson.JSONObject) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 43 with ApplicationInfo

use of com.itrus.portal.db.ApplicationInfo 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;
}
Also used : ApplicationInfoExample(com.itrus.portal.db.ApplicationInfoExample) HashMap(java.util.HashMap) EvidenceBasicInformation(com.itrus.portal.db.EvidenceBasicInformation) EvidenceHisRelationship(com.itrus.portal.db.EvidenceHisRelationship) ApplicationInfo(com.itrus.portal.db.ApplicationInfo) EvidenceHisCertificate(com.itrus.portal.db.EvidenceHisCertificate) EvidenceEnclosureExample(com.itrus.portal.db.EvidenceEnclosureExample) EvidenceEnclosure(com.itrus.portal.db.EvidenceEnclosure) RealNameAuthentication(com.itrus.portal.db.RealNameAuthentication) IOException(java.io.IOException) EvidenceHisRelationshipExample(com.itrus.portal.db.EvidenceHisRelationshipExample) EvidenceHisCertificateExample(com.itrus.portal.db.EvidenceHisCertificateExample) JSONObject(com.alibaba.fastjson.JSONObject) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 44 with ApplicationInfo

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

the class EvidenceSaveServiceApi method saveCallBack.

@RequestMapping("/savecallback")
@ResponseBody
public Map<String, Object> saveCallBack(@RequestParam(value = "evidenceSn", required = false) String evidenceSn, HttpServletRequest request) {
    long startTime = System.currentTimeMillis();
    Map<String, Object> retMap = new HashMap<>();
    retMap.put("code", "0");
    try {
        EvidenceBasicInformation basicInformation = basicInformationService.getInformationBySn(evidenceSn, null);
        ApplicationInfo applicationInfo = CacheCustomer.getAPP_INFO_MAP_BY_ID().get(basicInformation.getApplicationInfo());
        Map<String, Object> param = new HashMap<String, Object>();
        param.put("status", 1);
        param.put("appId", applicationInfo.getAppId());
        param.put("evidenceSns", evidenceSn);
        param.put("message", "存证成功");
        String header = "HMAC-SHA1 " + Base64.encode(HMACSHA1.getHmacSHA1(applicationInfo.getAppId() + evidenceSn, applicationInfo.getSecretKey()), false);
        long callbackTime = System.currentTimeMillis();
        // http://124.205.224.179:9018/km/evidencetest/tttt
        String retStr = OkHttpClientManagerCallback.post(applicationInfo.getCallback(), header, param);
        log.error("callbackTime is [" + (System.currentTimeMillis() - callbackTime) + "]");
        // JSONObject ret_data = JSONObject.parseObject(retStr);
        // if(retStr == null || ret_data.getInteger("status") != 1) {
        // retMap.put("code", "0");
        // retMap.put("message", "回调失败。");
        // return retMap;
        // }
        sqlSession.update("com.itrus.portal.db.EvidenceBasicInformationMapper.updateByPrimaryKey", basicInformation);
    } catch (Exception e) {
        // TODO: handle exception
        e.printStackTrace();
        return retMap;
    }
    retMap.put("status", "1");
    retMap.put("message", "回调申请成功。");
    log.error("saveCallBackTime is [" + (System.currentTimeMillis() - startTime) + "]");
    return retMap;
}
Also used : HashMap(java.util.HashMap) EvidenceBasicInformation(com.itrus.portal.db.EvidenceBasicInformation) ApplicationInfo(com.itrus.portal.db.ApplicationInfo) JSONObject(com.alibaba.fastjson.JSONObject) IOException(java.io.IOException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 45 with ApplicationInfo

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

the class EvidenceSaveServiceApi method generateTask.

/**
 * 出证
 * @param signature
 * 			签名值
 * @param appId
 * 			应用标识
 * @param serviceCode
 * 			服务编码
 * @param evidenceSns
 * 			要出证的证据编号(多个用逗号隔开)
 * @param businessSn
 * 			事件发生平台业务单号
 * @param request
 * @return
 */
@RequestMapping(value = "/generate")
@ResponseBody
public Map<String, Object> generateTask(@RequestHeader("Content-Signature") String signature, @RequestParam(value = "appId", required = true) String appId, @RequestParam(value = "serviceCode", required = true) String serviceCode, @RequestParam(value = "evidenceSns", required = false) String evidenceSns, @RequestParam(value = "businessSn", required = false) String businessSn, @RequestParam(value = "name", required = true) String name, @RequestParam(value = "code", required = true) String code, HttpServletRequest request) {
    log.equals("【提交出证申请日志】appId=" + appId + ",serviceCode=" + serviceCode + ",evidenceSns=" + evidenceSns + ",businessSn=" + businessSn + ",name=" + name + ",code=" + code);
    // 申请时间
    Date date = new Date();
    // TODO : 出证接口
    Map<String, Object> result = new HashMap<String, Object>();
    result.put("status", 1);
    // 验证参数是否完整
    if (StringUtils.isEmpty(signature) || StringUtils.isEmpty(appId) || StringUtils.isEmpty(serviceCode) || StringUtils.isEmpty(code) || StringUtils.isEmpty(name) || (evidenceSns == null && StringUtils.isEmpty(businessSn))) {
        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 + serviceCode + evidenceSns + businessSn + name + code, 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;
    }
    // 获取对应应用信息
    EvidenceOutServiceConfig outServiceConfig = null;
    AppService appService = appServiceExt.getAppService(serviceCode);
    if (appService != null && "EvidenceOutServiceConfig".equals(appService.getServiceConfigName())) {
        outServiceConfig = configService.selectById(appService.getServiceConfigId());
    } else {
        result.put("status", -21);
        result.put("message", "应用服务不存在");
        return result;
    }
    if (outServiceConfig == null) {
        result.put("status", -21);
        result.put("message", "应用服务不存在");
        return result;
    }
    if (appService.getIsAppServiceStatus() == 0) {
        result.put("status", -22);
        result.put("message", "服务已关闭");
        return result;
    }
    if (outServiceConfig.getOutWay() == null) {
        result.put("status", 0);
        result.put("message", "请联系管理员配置出证方式");
        return result;
    }
    // 得到出证份数
    int count = 0;
    if (StringUtils.isNotEmpty(evidenceSns)) {
        count = evidenceSns.split(",").length;
    } else {
        List<EvidenceBasicInformation> basicInformations = basicInformationService.getInformationByBusinessSn(businessSn, 2);
        count = basicInformations.size();
    }
    // 核验计费
    boolean blCharing = takeChargingService.checkTakeCharing(applicationInfo, appService, count);
    if (!blCharing) {
        result.put("status", -4);
        result.put("message", "服务计费失败");
        return result;
    }
    // 生成流水号
    String orderNumber = UniqueIDUtils.genAppServiceUID(applicationInfo, appService.getAppServiceName(), sqlSession, 3);
    // 修改需要出证的证据为待出征状态
    if (StringUtils.isNotEmpty(evidenceSns)) {
        String[] evidenceSnArr = evidenceSns.split(",");
        for (String evidenceSn : evidenceSnArr) {
            EvidenceBasicInformation basicInformation = basicInformationService.getInformationBySn(evidenceSn, 2);
            if (basicInformation != null) {
                basicInformation.setStatus(1);
                sqlSession.update("com.itrus.portal.db.EvidenceBasicInformationMapper.updateByPrimaryKey", basicInformation);
                sqlSession.flushStatements();
            }
        }
    } else {
        List<EvidenceBasicInformation> basicInformations = basicInformationService.getInformationByBusinessSn(businessSn, 2);
        if (basicInformations != null) {
            for (EvidenceBasicInformation basicInformation : basicInformations) {
                basicInformation.setStatus(1);
                sqlSession.update("com.itrus.portal.db.EvidenceBasicInformationMapper.updateByPrimaryKey", basicInformation);
                sqlSession.flushStatements();
            }
        }
    }
    // 判断是否为自动出证
    if ((int) result.get("status") == 1 && outServiceConfig.getOutWay() == 1) {
        // queueTask.putObjectQueue(new EvidenceLog(orderNumber, outServiceConfig, applicationInfo, appService, evidenceSns, businessSn, date, code, count, true));
        result.put("status", 1);
        result.put("message", "申请自动出证成功,请稍后通过查询出证接口查看出证结果!");
        result.put("orderNumber", orderNumber);
    } else {
        queueTask.putObjectQueue(new EvidenceOutTask(orderNumber, outServiceConfig, applicationInfo, appService, evidenceSns, businessSn, date, code, count, false));
        result.put("status", 0);
        result.put("message", "已转入人工出证");
    }
    return result;
}
Also used : ApplicationInfoExample(com.itrus.portal.db.ApplicationInfoExample) AppService(com.itrus.portal.db.AppService) HashMap(java.util.HashMap) EvidenceBasicInformation(com.itrus.portal.db.EvidenceBasicInformation) ApplicationInfo(com.itrus.portal.db.ApplicationInfo) EvidenceOutServiceConfig(com.itrus.portal.db.EvidenceOutServiceConfig) Date(java.util.Date) IOException(java.io.IOException) JSONObject(com.alibaba.fastjson.JSONObject) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

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