Search in sources :

Example 46 with ApplicationInfo

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

the class EvidenceQueryQueue method run.

@Override
public void run() {
    // 回调
    while (true) {
        if (OBJECT_QUEUE.isEmpty()) {
            try {
                // 若队列中没有信息则等待10秒
                sleep(5 * 1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            continue;
        }
        String url = null;
        String app_id = null;
        String secret_key = null;
        // 需要回执报告 // TODO: 2018/3/15 有问题
        Map<Long, EvidenceBasicInformation> dataRet = new HashMap<Long, EvidenceBasicInformation>();
        // 不需要回执报告
        Map<Long, List<String>> data = new HashMap<Long, List<String>>();
        for (int i = 0; OBJECT_QUEUE != null && i < OBJECT_QUEUE.size() && i < 1000; i++) {
            EvidenceBasicInformation obj = (EvidenceBasicInformation) OBJECT_QUEUE.poll();
            if (obj.getOutAppService() == null || obj.getEvidenceType() == 1) {
                if (data.containsKey(obj.getApplicationInfo())) {
                    data.get(obj.getApplicationInfo()).add(obj.getEvidenceSn());
                } else {
                    List<String> sns = new ArrayList<String>();
                    sns.add(obj.getEvidenceSn());
                    data.put(obj.getApplicationInfo(), sns);
                }
            } else {
                dataRet.put(obj.getApplicationInfo(), obj);
            }
        }
        try {
            // <----------------------------    处理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) {
                    // TODO: 2018/3/15 从缓存取
                    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);
                final List<String> dataSn = entry.getValue();
                final Long appId = entry.getKey();
                // 判断是否成功  true ——> 失败
                if (retStr == null || ret_data.getInteger("status") != 1) {
                    log.error("EvidenceQueryQueue failure count [" + entry.getValue().size() + "]");
                    // 创建新线程 处理数据批量添加
                    List<String> sns = dataSn;
                    Long aId = appId;
                    List<EvidenceCallback> callbacks = new ArrayList<EvidenceCallback>();
                    ;
                    for (String sn : sns) {
                        EvidenceCallback evidenceCallback = new EvidenceCallback();
                        evidenceCallback.setAppId(aId);
                        evidenceCallback.setCounnt(1);
                        evidenceCallback.setEvidenceSn(sn);
                        callbacks.add(evidenceCallback);
                    }
                    sqlSession.insert("com.itrus.portal.db.EvidenceCallbackMapper.insert", callbacks.toArray());
                } else {
                    log.error("EvidenceQueryQueue success count [" + entry.getValue().size() + "]");
                    // 创建新线程 处理数据批量修改
                    List<String> sns = dataSn;
                    sqlSession.update("com.itrus.portal.db.EvidenceBasicInformationMapper.updates", sns.toArray());
                }
            }
            // <----------------------------    处理dataRet   start   ------------------------------>
            for (Entry<Long, EvidenceBasicInformation> entry : dataRet.entrySet()) {
                ApplicationInfo applicationInfo = CacheCustomer.getAPP_INFO_MAP_BY_ID().get(entry.getKey());
                if (applicationInfo == null) {
                    // TODO: 2018/3/15 从缓存取
                    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;
                    }
                }
                // 得到证据回执base64
                String reportBase64 = null;
                // reportBase64 = EvidenceSaveServiceApi.cacheReportBySnMap.get(entry.getValue().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(entry.getValue().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 = reportTemplate.returnreceipt(entry.getValue().getEvidenceSn(), applicationInfo, null);
                        log.error("EvidenceQueryQueue mapRet is " + mapRet.get("status"));
                        ;
                        if (mapRet.get("status") != null && (int) mapRet.get("status") == 0) {
                            // 修改证据基本信息回执状态为已出
                            reportBase64 = (String) mapRet.get("pdfBase64");
                            EvidenceBasicInformation basicInformation = informationService.getInformationBySn(entry.getValue().getEvidenceSn(), null);
                            basicInformation.setReceiptStatus(1);
                            sqlSession.update("com.itrus.portal.db.EvidenceBasicInformationMapper.updateByPrimaryKey", basicInformation);
                        }
                    }
                } else {
                // EvidenceSaveServiceApi.cacheReportBySnMap.remove(entry.getValue().getEvidenceSn());
                }
                Map<String, Object> param = new HashMap<String, Object>();
                param.put("status", 1);
                param.put("appId", app_id);
                param.put("evidenceSn", entry.getValue().getEvidenceSn());
                log.error("EvidenceQueryQueue reportBase64 is " + (reportBase64 == null) + ", evidenceSn is " + entry.getValue().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 + entry.getValue().getEvidenceSn(), secret_key), false);
                String retStr = OkHttpClientManagerCallback.post(url, header, param);
                JSONObject ret_data = JSONObject.parseObject(retStr);
                String dataSn = entry.getValue().getEvidenceSn();
                Long appId = entry.getKey();
                // 判断是否成功  true ——> 失败
                if (retStr == null || ret_data.getInteger("status") != 1) {
                    log.error("EvidenceQueryQueue failure sn is [" + entry.getValue().getEvidenceSn() + "]" + "retStr is [" + retStr + "]");
                    EvidenceCallback evidenceCallback = new EvidenceCallback();
                    evidenceCallback.setAppId(appId);
                    evidenceCallback.setCounnt(1);
                    evidenceCallback.setEvidenceSn(dataSn);
                    evidenceCallback.setAppServiceId(entry.getValue().getOutAppService());
                    sqlSession.insert("com.itrus.portal.db.EvidenceCallbackMapper.insert", evidenceCallback);
                } else {
                    log.error("EvidenceQueryQueue success sn is [" + entry.getValue().getEvidenceSn() + "]" + "retStr is [" + retStr + "]");
                    List<String> sns = new ArrayList<>();
                    sns.add(dataSn);
                    sqlSession.update("com.itrus.portal.db.EvidenceBasicInformationMapper.updates", sns.toArray());
                }
            }
        // <----------------------------    处理dataRet   end   ------------------------------>
        } catch (Exception e) {
            e.printStackTrace();
            LogUtil.evidencelog(sqlSession, null, "存证回调接口", "失败原因:" + e.toString());
        }
    }
}
Also used : EvidenceBasicInformation(com.itrus.portal.db.EvidenceBasicInformation) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ApplicationInfo(com.itrus.portal.db.ApplicationInfo) EvidenceEnclosure(com.itrus.portal.db.EvidenceEnclosure) RealNameAuthentication(com.itrus.portal.db.RealNameAuthentication) ArrayList(java.util.ArrayList) List(java.util.List) EvidenceEnclosureExample(com.itrus.portal.db.EvidenceEnclosureExample) EvidenceCallback(com.itrus.portal.db.EvidenceCallback) JSONObject(com.alibaba.fastjson.JSONObject) JSONObject(com.alibaba.fastjson.JSONObject) HashMap(java.util.HashMap) Map(java.util.Map)

Example 47 with ApplicationInfo

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

the class MobileApplyConfigController method creatForm.

// 返回新建页面
@RequestMapping(params = "form", produces = "text/html")
public String creatForm(Model uiModel) {
    // 得到所有应用
    List<ApplicationInfo> applicationInfos = applicationInfoService.selectByExample(new ApplicationInfoExample());
    uiModel.addAttribute("applicationInfos", applicationInfos);
    Iterator<ApplicationInfo> iterator = applicationInfos.iterator();
    while (iterator.hasNext()) {
        ApplicationInfo mobileApply = iterator.next();
        MobileApplyConfigManage appserviceChargings = mobileApplyConfigService.selectByappId(mobileApply.getAppId());
        if (null != appserviceChargings) {
            iterator.remove();
        }
    }
    uiModel.addAttribute("applicationInfos", applicationInfos);
    // 得到所有RA 服务信息
    List<RaAccount> accounts = raAccountService.getRaAccounts();
    uiModel.addAttribute("accounts", accounts);
    return "applyconfig/create";
}
Also used : ApplicationInfoExample(com.itrus.portal.db.ApplicationInfoExample) RaAccount(com.itrus.portal.db.RaAccount) ApplicationInfo(com.itrus.portal.db.ApplicationInfo) MobileApplyConfigManage(com.itrus.portal.db.MobileApplyConfigManage) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 48 with ApplicationInfo

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

the class MobileApplyConfigController method list.

// 列表显示
@RequestMapping(produces = "text/html")
public String list(@RequestParam(value = "appId", required = false) Long appId, @RequestParam(value = "queryDate1", required = false) Date queryDate1, @RequestParam(value = "queryDate2", required = false) Date queryDate2, @RequestParam(value = "page", required = false) Integer page, @RequestParam(value = "size", required = false) Integer size, Model uiModel) {
    if (queryDate1 == null && queryDate2 == null) {
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DATE, 1);
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        calendar.add(Calendar.MILLISECOND, -1);
        queryDate2 = calendar.getTime();
        calendar.add(Calendar.MILLISECOND, 1);
        calendar.add(Calendar.MONTH, -1);
        queryDate1 = calendar.getTime();
    }
    // 返回页面搜索条件
    uiModel.addAttribute("appId", appId);
    uiModel.addAttribute("queryDate1", queryDate1);
    uiModel.addAttribute("queryDate2", queryDate2);
    Map<String, Object> param = new HashMap<String, Object>();
    // page,size
    if (page == null || page < 1)
        page = 1;
    if (size == null || size < 1)
        size = 10;
    Integer offset = size * (page - 1);
    param.put("offset", offset);
    param.put("limit", size);
    param.put("appId", appId);
    param.put("queryDate1", queryDate1);
    param.put("queryDate2", queryDate2);
    Integer count = mobileApplyConfigService.selectMobileApplyConfigManageListCountByMap(param);
    uiModel.addAttribute("count", count);
    uiModel.addAttribute("pages", (count + size - 1) / size);
    // page, size
    if (page > 1 && size * (page - 1) >= count) {
        page = (count + size - 1) / size;
    }
    uiModel.addAttribute("page", page);
    uiModel.addAttribute("size", size);
    List<Map<String, Object>> applyConfigManages = mobileApplyConfigService.selectMobileApplyConfigManageListByMap(param);
    uiModel.addAttribute("applyConfigManages", applyConfigManages);
    // 得到所有应用
    List<ApplicationInfo> applicationInfos = applicationInfoService.selectByExample(new ApplicationInfoExample());
    uiModel.addAttribute("applicationInfos", applicationInfos);
    return "applyconfig/list";
}
Also used : ApplicationInfoExample(com.itrus.portal.db.ApplicationInfoExample) HashMap(java.util.HashMap) Calendar(java.util.Calendar) ApplicationInfo(com.itrus.portal.db.ApplicationInfo) HashMap(java.util.HashMap) Map(java.util.Map) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 49 with ApplicationInfo

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

the class MobileAppserviceChargingController method update.

// 返回修改页面
@RequestMapping(value = "/update/{id}")
public String update(@PathVariable("id") Long id, Model uiModel, HttpServletRequest request) {
    ApplicationInfo applicationInfo = sqlSession.selectOne("com.itrus.portal.db.ApplicationInfoMapper.selectByPrimaryKey", id);
    uiModel.addAttribute("applicationInfo", applicationInfo);
    List<MobileAppserviceCharging> appserviceChargings = new ArrayList<MobileAppserviceCharging>();
    appserviceChargings = appserviceChargingService.selectList(id);
    AppserviceChargingWrap appserviceChargingWrap = new AppserviceChargingWrap();
    List<AppserviceChargingList> appserviceChargingLists = new ArrayList<AppserviceChargingList>();
    for (int i = 0; i < appserviceChargings.size(); i++) {
        AppserviceChargingList appserviceChargingList = new AppserviceChargingList();
        List<MobileAppserviceName> appserviceNames = new ArrayList<MobileAppserviceName>();
        appserviceNames = appserviceNameService.selectListByAppserviceCharging(appserviceChargings.get(i));
        List<AppserviceNameList> appserviceNameLists = new ArrayList<AppserviceNameList>();
        for (int j = 0; j < appserviceNames.size(); j++) {
            List<MobileChargingPrice> chargingPrices = chargingPriceService.selectListByOneAppserviceName(appserviceNames.get(j));
            AppserviceNameList appserviceNameList = new AppserviceNameList();
            ChargingPriceList chargingPriceList = new ChargingPriceList();
            // 1
            chargingPriceList.setChargingPriceLists(chargingPrices);
            // 2
            appserviceNameList.setAppserviceName(appserviceNames.get(j));
            appserviceNameList.setChargingPriceList(chargingPriceList);
            appserviceNameLists.add(appserviceNameList);
        }
        appserviceChargingList.setAppserviceCharging(appserviceChargings.get(i));
        appserviceChargingList.setAppserviceNameLists(appserviceNameLists);
        appserviceChargingLists.add(appserviceChargingList);
    }
    appserviceChargingWrap.setAppserviceChargingLists(appserviceChargingLists);
    uiModel.addAttribute("acw", appserviceChargingWrap);
    // Map<Long, AppService> appServiceMap = sqlSession.selectMap(
    // "com.itrus.portal.db.AppServiceMapper.selectByExample", null,
    // "id");
    // uiModel.addAttribute("appServiceMap", appServiceMap);
    returnParam(request, uiModel);
    return "appservicecharging/update";
}
Also used : MobileAppserviceCharging(com.itrus.portal.db.MobileAppserviceCharging) AppserviceNameList(com.itrus.portal.mobile.entity.AppserviceNameList) MobileChargingPrice(com.itrus.portal.db.MobileChargingPrice) ApplicationInfo(com.itrus.portal.db.ApplicationInfo) ArrayList(java.util.ArrayList) ChargingPriceList(com.itrus.portal.mobile.entity.ChargingPriceList) AppserviceChargingWrap(com.itrus.portal.mobile.entity.AppserviceChargingWrap) MobileAppserviceName(com.itrus.portal.db.MobileAppserviceName) AppserviceChargingList(com.itrus.portal.mobile.entity.AppserviceChargingList) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 50 with ApplicationInfo

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

the class CertificationChargingServiceImpl 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)

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