/**
   * 回调通知信息入库
   *
   * @param notifyParams 支付宝回调信息
   */
  private void insertPayNotify(Map<String, String> notifyParams) throws Exception {
    PayNotify payNotify = new PayNotify();

    payNotify.setNotifyText(notifyParams.toString());
    payNotify.setCreateTime(new Date());
    payNotify.setTradeNo(notifyParams.get("transaction_id"));

    if (!daoService.insertPayNotify(payNotify)) {
      LOGGER.error("insertPayNotify fail: notifyParams=" + notifyParams);
    }
  }
  public String umpNotify(HttpServletRequest request, NotifyReq reqParam) {
    try {
      // 记录回调日志
      PayNotify payNotify = new PayNotify();
      payNotify.setNotifyText(reqParam.toString());
      if (!daoService.insertPayNotify(payNotify)) {
        LOGGER.error("insertPayNotify fail: notifyText=" + reqParam.toString());
      }

      // 验证签名
      if (!UmpUtils.validateNotifySign(request, reqParam)) {
        return UmpUtils.buildNotifyResponse(
            reqParam, Constants.UMP_CODE_VERIFY_SIGN_FAIL, Constants.UMP_MSG_VERIFY_SIGN_FAIL);
      }

      // 查询该订单号是否存在
      String outOrderId = reqParam.getOrderId();
      String outSysId = Constants.OUT_SYS_ID_UMP;

      PayOrder payOrder = daoService.queryPayOrderByOutOrderIdAndOutSysId(outOrderId, outSysId);
      if (payOrder == null) {
        return UmpUtils.buildNotifyResponse(
            reqParam,
            Constants.UMP_CODE_QUERY_BY_OUT_ORDER_ID_NOT_EXIT,
            Constants.UMP_MSG_QUERY_BY_OUT_ORDER_ID_NOT_EXIT);
      }

      // 用户首次支付, 则记录用户协议编号
      if (reqParam.getUsrPayAgreementId() != null) {
        String userId = payOrder.getMerUserId();
        PayAgreement userPayAgreement = daoService.queryPayAgreementByUserId(userId);
        // 未签订协议,则插入协议表
        if (userPayAgreement == null) {
          // 插入失败,则记录日志信息
          if (!daoService.insertPayAgreement(userId, reqParam)) {
            LOGGER.error("notify insert pay_agreement fail");
          }
        }
      }

      // 更新交易状态
      String tradeStatus = reqParam.getTradeState();
      String tradeCode = CommonUtils.getTransCodeByTradeStatus(tradeStatus);
      PayOrder payOrderUpdate = UmpUtils.buildNotifyUpdatePayOrder(tradeCode, tradeStatus);

      if (!daoService.updatePayOrderByOutOrderIdAndOutSysId(payOrderUpdate, outOrderId, outSysId)) {
        return UmpUtils.buildNotifyResponse(
            reqParam, Constants.UMP_CODE_UPDATE_ORDER_FAIL, Constants.UMP_MSG_UPDATE_ORDER_FAIL);
      }

      // 通知O2O
      String retCode = payOrderUpdate.getPayStatus();
      String retMsg = payOrderUpdate.getPayChnDesc();
      String outNotifyUrl = payOrder.getOutNotifyUrl();
      int payId = payOrder.getPayId();
      String merPriv = payOrder.getMerPriv();

      notifyService.notifyO2O(outNotifyUrl, payId, outOrderId, retCode, retMsg, merPriv);

      // 构建返回信息
      return UmpUtils.buildNotifyResponse(
          reqParam,
          Constants.UMP_RETURN_CODE_CLIENT_SUCCESS,
          Constants.UMP_RETURN_MSG_CLIENT_SUCCESS);
    } catch (Exception e) {
      LOGGER.error("umpNotify error: reqParam=" + reqParam, e);
      return UmpUtils.buildNotifyResponse(
          reqParam, Constants.UMP_RETURN_CODE_CLIENT_FAIL, Constants.UMP_RETURN_MSG_CLIENT_FAIL);
    }
  }