private void addComLog(PassCode passCode, String logContent, String logName) { ComLog log = new ComLog(); log.setObjectType("PASS_CODE"); log.setParentId(passCode.getOrderId()); log.setObjectId(passCode.getCodeId()); log.setOperatorName("SYSTEM"); log.setLogType(Constant.COM_LOG_ORDER_EVENT.systemApprovePass.name()); log.setLogName(logName); log.setContent(logContent); comLogService.addComLog(log); }
@SuppressWarnings({"unchecked", "rawtypes"}) private Map<String, List<String>> checkAllApplySuccess(PassCode passCode) { /* * 检查订单中所有由非服务商发送短信、独立申码、并且开通了凭证短信合并功能 * 的所有短信是否都已经生成,然后按服务商分组passCode * * 按服务商分组passCode的目的是,各服务商的凭证短信单独发送 */ Map params = new HashMap(); params.put("orderId", passCode.getOrderId()); List<PassPortCode> passportcodeList = passCodeService.selectAllMergeSmsByParams(params); int mergeCount = 0; if (passCode.getCodeTotal().intValue() == passportcodeList.size()) { for (PassPortCode passportcode : passportcodeList) { // 剔除非合并凭证短信的通关码 if (!passportcode.isMergeCertificateSMS()) { if (otherPassportcodeList == null) { otherPassportcodeList = new ArrayList(); } otherPassportcodeList.add(passportcode); continue; } mergeCount++; } } else { return null; } params.put("checkSmsContent", "true"); List<PassPortCode> passportcodeStatusList = passCodeService.selectAllMergeSmsByParams(params); log.info(passportcodeStatusList.size()); // 所有的合并凭证短信的码,都已经申码成功、生成短信内容片段成功 if (mergeCount == passportcodeStatusList.size()) { Map<String, List<String>> groupPassPortCode = new HashMap<String, List<String>>(); for (PassPortCode passportcode : passportcodeStatusList) { String providerName = passportcode.getProviderName(); Long codeId = passportcode.getCodeId(); List<String> codeList = groupPassPortCode.get(providerName); if (codeList == null) { codeList = new ArrayList<String>(); } codeList.add(codeId.toString()); groupPassPortCode.put(providerName, codeList); } return groupPassPortCode; } return null; }
private String getProductName(PassCode passCode) { List<OrdOrderItemMeta> ordItemMetaList = null; OrdOrderItemMeta itemMeta = null; if (passCode.isForOrder()) { ordItemMetaList = orderServiceProxy.queryOrdOrderItemMetaByOrderId(passCode.getOrderId()); itemMeta = ordItemMetaList.get(0); } else { itemMeta = orderServiceProxy.queryOrdOrderItemMetaBy(passCode.getObjectId()); } OrdOrderItemProd ordItemProd = orderServiceProxy.queryOrdOrderItemProdById(itemMeta.getOrderItemId()); ProdProductBranch prodProductBranch = prodProductBranchDAO.selectByPrimaryKey(ordItemProd.getProdBranchId()); ProdProduct product = prodProductService.getProdProduct(prodProductBranch.getProductId()); return product.getProductName(); }
private String buildOrderInfo(PassCode passCode) { OrdOrder ordorder = orderServiceProxy.queryOrdOrderByOrderId(passCode.getOrderId()); // 取票人/联系人的证件号 cardNum = ordorder.getContact().getCertNo(); List<PayPayment> payList = payPaymentService.selectByObjectIdAndBizType( ordorder.getOrderId(), Constant.PAYMENT_BIZ_TYPE.SUPER_ORDER.name()); for (PayPayment payment : payList) { if (payment.isSuccess()) { GugongOrder gugongorder = new GugongOrder(payment, ordorder, passCode.getSerialNo()); return gugongorder.getJSON(); } } return null; }
private MergedSmsContentCreator(PassCode passCode, String mobile, boolean mergeCertificateSMS) { log.info("mergeCertificateSMS:" + mergeCertificateSMS); this.objectId = passCode.getOrderId(); log.info("orderId:" + objectId); order = orderServiceProxy.queryOrdOrderByOrderId(objectId); this.passCode = passCode; this.mobile = mobile; }
@Override public Passport apply(PassCode passCode) { log.info("Gugong Apply Code: " + passCode.getSerialNo()); Passport passport = new Passport(); passport.setEventType(PassportConstant.PASSCODE_TYPE.APPLAYCODE.name()); passport.setSendSms(PassportConstant.PASSCODE_SMS_SENDER.LVMAMA.name()); try { sendOrder(passCode, passport); } catch (Exception e) { passport.setStatus(PassportConstant.PASSCODE_STATUS.FAILED.name()); passport.setErrorNO(PassportConstant.PASSCODE_ERROR.APPLY.name()); passport.setComLogContent(e.getMessage()); this.reapplySet(passport, passCode.getReapplyCount()); log.error("Gugong Apply Exception message:", e); } return passport; }
@Override Map<String, Object> getContentData() { Map<String, Object> data = new HashMap<String, Object>(); StringBuffer content = new StringBuffer(); content.append(productName); Map<String, Object> params = new HashMap<String, Object>(); params.put("codeList", codeIds); List<PassCode> passCodeList = passCodeService.queryPassCodeByParam(params); for (PassCode passCode : passCodeList) { content.append(passCode.getSmsContent()); } data.put("orderId", objectId); data.put("visitDate", DateUtil.formatDate(order.getVisitTime(), "yyyy-MM-dd")); data.put("content", content.toString()); return data; }
@Override public Passport destroy(PassCode passCode) { log.info("Gugong Destroy Code: " + passCode.getSerialNo()); Passport passport = new Passport(); passport.setEventType(PassportConstant.PASSCODE_TYPE.DESTROYCODE.name()); passport.setSerialno(passCode.getSerialNo()); try { GugongOrderResponse response = GugongHTTPUtil.getRefundResponse(passCode); if (response.getStatus() == 0) { passport.setStatus(PassportConstant.PASSCODE_STATUS.SUCCESS.name()); } else { passport.setComLogContent( "供应商返回异常:" + GugongConstant.getInstance().getCodeMsg(response.getResultcode())); passport.setStatus(PassportConstant.PASSCODE_STATUS.FAILED.name()); passport.setErrorNO(PassportConstant.PASSCODE_ERROR.DESTROY.name()); } } catch (Exception e) { passport.setStatus(PassportConstant.PASSCODE_STATUS.FAILED.name()); passport.setErrorNO(PassportConstant.PASSCODE_ERROR.DESTROY.name()); passport.setComLogContent(e.getMessage()); log.error("Gugong Destroy Exception:".concat(e.getMessage())); } return passport; }
@Override public Passport perform(PassCode passCode) { log.info("Gugong perform serialNo: " + passCode.getSerialNo()); log.info("Gugong getOrder: " + passCode.getSerialNo()); Passport passport = null; GugongOrderResponse response = null; try { response = GugongHTTPUtil.getOrderStatus(passCode); } catch (Exception e) { log.error(e); } if (response != null) { // 永乐方已经出票,驴妈妈自动履行 if (response.isSuccess() && response.getStatus() == 2) { passport = new Passport(); passport.setChild("0"); passport.setAdult("0"); passport.setUsedDate(new Date()); passport.setDeviceId("Gugong"); } else { String codeMsg = GugongConstant.getInstance().getOrderStatus(response.getStatus()); log.error("Gugong auto perform failed: ".concat(codeMsg)); } } else { this.addComLog( passCode, GugongConstant.getInstance().getCodeMsg(response.getResultcode()), "查询永乐方订单状态失败"); log.error( "Gugong auto perform failed: " .concat(GugongConstant.getInstance().getCodeMsg(response.getResultcode()))); } return passport; }
private void singleSmsInMerged(PassCode passCode, boolean mergeCertificateSMS) { List<OrdOrderItemMeta> ordItemMetaList = null; OrdOrderItemMeta itemMeta = null; if (passCode.isForOrder()) { ordItemMetaList = orderServiceProxy.queryOrdOrderItemMetaByOrderId(passCode.getOrderId()); itemMeta = ordItemMetaList.get(0); } else { itemMeta = orderServiceProxy.queryOrdOrderItemMetaBy(passCode.getObjectId()); } OrdOrderItemProd ordItemProd = orderServiceProxy.queryOrdOrderItemProdById(itemMeta.getOrderItemId()); ProdProductBranch prodProductBranch = prodProductBranchDAO.selectByPrimaryKey(ordItemProd.getProdBranchId()); // 凭证短信合并发送,并且是各子子项独立申码 if (mergeCertificateSMS && passCode.isForOrderItemMeta() && generateSMS) { // 【${销售类别} 取票码 ${code},辅助码xxxx ,含${adult} ${chaild}】 String formatString = "【%s %s,%s,%s】"; String branchName = prodProductBranch.getBranchName(); String code = ""; if (!"BASE64".equalsIgnoreCase(passCode.getCode())) { code = "取票码 " + passCode.getCode(); } String addCode = passCode.getAddCode(); if (StringUtils.isNotEmpty(addCode)) { addCode = "辅助码 " + addCode; } else { addCode = ""; } long adult = ordItemProd.getQuantity() * prodProductBranch.getAdultQuantity(); long child = ordItemProd.getQuantity() * prodProductBranch.getChildQuantity(); StringBuilder quantity = new StringBuilder(); if (itemMeta.isStudent()) { quantity.append("学生人数:" + (adult + child)); } else { quantity.append("含"); if (adult > 0) { quantity.append(adult + "成人 "); } if (child > 0) { quantity.append(child + "儿童"); } } String smsContent = String.format(formatString, branchName, code, addCode, quantity); log.info("=====singleSmsInMerged smsContent===========" + smsContent); PassCode temp = new PassCode(); temp.setCodeId(passCode.getCodeId()); temp.setSmsContent(smsContent); passCodeService.updatePassCode(temp); } }
private Passport sendOrder(PassCode passCode, Passport passport) { String orderInfo = buildOrderInfo(passCode); log.info("GugongOrderRequest:" + orderInfo); GugongOrderResponse response = null; Long startTime = 0L; try { if (orderInfo.isEmpty()) { throw new RuntimeException("由于未获取到支付信息,未生成订单信息"); } startTime = System.currentTimeMillis(); response = GugongHTTPUtil.sendOrder(orderInfo); log.info( "Gugong Apply serialNo :" + passCode.getSerialNo() + " UseTime:" + (System.currentTimeMillis() - startTime) / 1000); } catch (ClientProtocolException e) { this.reapplySet(passport, passCode.getReapplyCount()); passport.setComLogContent( "故宫对接推单:地址" + GugongConstant.GUGONG_URLS.GUGONG_URLS_ORDER.getUrl() + " 客户端协议异常" + e); log.error(e); } catch (ParseException e) { this.reapplySet(passport, passCode.getReapplyCount()); passport.setComLogContent("解析永乐方返回的推单结果:异常" + e); log.error(e); } catch (IOException e) { this.reapplySet(passport, passCode.getReapplyCount()); passport.setComLogContent( "故宫对接推单:地址" + GugongConstant.GUGONG_URLS.GUGONG_URLS_ORDER.getUrl() + " 网络异常" + e); log.error(e); } catch (Exception e) { log.error( "Gugong Apply serialNo Error :" + passCode.getSerialNo() + " UseTime:" + (System.currentTimeMillis() - startTime) / 1000); this.reapplySet(passport, passCode.getReapplyCount()); passport.setComLogContent(e.getMessage()); log.error(e); } boolean flag = false; if (response != null) { if (response.isSuccess()) { String ylorderId = response.getYlorderid(); passport.setStatus(PassportConstant.PASSCODE_STATUS.SUCCESS.name()); passport.setSerialno(passCode.getSerialNo()); passport.setAddCode(ylorderId); passport.setExtId(ylorderId); passport.setCode(cardNum); // 故宫产品code则存放证件号 passport.setMessageWhenApplySuccess(""); // 清空状态描述信息 flag = true; } } if (!flag) { passport.setErrorNO(PassportConstant.PASSCODE_ERROR.APPLY.name()); // 如果推单失败原因是由永乐方业务代码不成功,而非系统异常,申码失败且不重申码 passport.setStatus(PassportConstant.PASSCODE_STATUS.FAILED.name()); if (response != null) { passport.setComLogContent( GugongConstant.getInstance().getCodeMsg(response.getResultcode())); } else { passport.setComLogContent("供应商返回信息为空"); } } return passport; }