Beispiel #1
0
  @Override
  public Double handleSoItem(
      Tuple tuple, JumpMQOrderVo parentOrder, JumpMQOrderVo order, JumpMQOrderItemVo soItem) {
    // 业务逻辑,如果金额和积分同时为零,则不算成交
    if (!BusinessLogic.isTransation(soItem)) {
      return 0D;
    }

    // 积分兑换
    if (soItem.getOrderItemAmount().compareTo(new BigDecimal("0")) == 0) {
      return 0D;
    }

    // 成交净额口径
    double pmNetAmt =
        soItem.getOrderItemAmount().doubleValue()
            - soItem.getPromotionAmount().doubleValue()
            - soItem.getCouponAmount().doubleValue()
            - soItem.getOrderItemAmount().doubleValue()
                / order.getOrderAmount().doubleValue()
                * order.getOrderPaidByRebate().doubleValue();

    logger.info("pmNetAmt:" + pmNetAmt + soItem.baseInfo());
    return pmNetAmt;
  }
  @Override
  public void execute(Tuple input) {
    try {
      jumpMQOrderVo = (JumpMQOrderVo) input.getValue(0);
      if (jumpMQOrderVo == null) {
        logger.info("===元数据空消息体===");
        throw new Exception();
      }
      // 入库父单
      try {
        insertParentSo(con, jumpMQOrderVo);
      } catch (Exception e) {
        logger.info("===so insert failed ....===");
      }

      // 入库子单
      if (jumpMQOrderVo.getChildOrderList() != null
          && jumpMQOrderVo.getChildOrderList().size() > 0) {
        for (JumpMQOrderVo childOrder : jumpMQOrderVo.getChildOrderList()) {
          soItemList = childOrder.getSoItemList();
          for (JumpMQOrderItemVo soItemVo : soItemList) {
            insertItemSo(con, soItemVo);
          }
        }
      } else {
        soItemList = jumpMQOrderVo.getSoItemList();
        for (JumpMQOrderItemVo soItemVo : soItemList) {
          insertItemSo(con, soItemVo);
        }
      }
      _collector.ack(input);

    } catch (Exception e) {
      _collector.fail(input);
      e.printStackTrace();
    } finally {
    }
  }
Beispiel #3
0
  @Override
  public Double processSoItem(Tuple input, JumpMQOrderVo order) {
    double orderAmt = 0.0D;

    logger.info("Message successfully received: " + order.baseInfo());

    if (order.getChildOrderList() != null && !order.getChildOrderList().isEmpty()) {
      for (JumpMQOrderVo childOrder : order.getChildOrderList()) {
        logger.info("Order successfully received: " + childOrder.baseInfo());

        List<JumpMQOrderItemVo> soItemList = childOrder.getSoItemList();

        for (JumpMQOrderItemVo soItem : soItemList) {
          if (soItem.getSubSoItemList() != null && !soItem.getSubSoItemList().isEmpty()) {

            List<JumpMQOrderItemVo> subSoItemList = soItem.getSubSoItemList();

            for (JumpMQOrderItemVo subSoItem : subSoItemList) {

              logger.info("SoItem successfully received: " + subSoItem.baseInfo());
              orderAmt += handleSoItem(input, order, childOrder, subSoItem);
              logger.info("SoItem successfully processed: " + subSoItem.baseInfo());
            }
          } else {
            logger.info("SoItem successfully received: " + soItem.baseInfo());
            orderAmt += handleSoItem(input, order, childOrder, soItem);
            logger.info("SoItem successfully processed: " + soItem.baseInfo());
          }
        }
        logger.info("Order successfully processed: " + childOrder.baseInfo());
      }
    } else {
      logger.info("Order successfully received: " + order.baseInfo());

      List<JumpMQOrderItemVo> soItemList = order.getSoItemList();

      for (JumpMQOrderItemVo soItem : soItemList) {
        if (soItem.getSubSoItemList() != null && !soItem.getSubSoItemList().isEmpty()) {

          List<JumpMQOrderItemVo> subSoItemList = soItem.getSubSoItemList();

          for (JumpMQOrderItemVo subSoItem : subSoItemList) {

            logger.info("SoItem successfully received: " + subSoItem.baseInfo());
            orderAmt += handleSoItem(input, null, order, subSoItem);
            logger.info("SoItem successfully processed: " + subSoItem.baseInfo());
          }

        } else {
          logger.info("SoItem successfully received: " + soItem.baseInfo());
          orderAmt += handleSoItem(input, null, order, soItem);
          logger.info("SoItem successfully processed: " + soItem.baseInfo());
        }
      }
      logger.info("Order successfully processed: " + order.baseInfo());
    }

    return orderAmt;
  }
Beispiel #4
0
  @Override
  public void execute(Tuple input) {
    try {
      // 当前坐标点信息
      strLastXValue = CommonUtil.getCurFullXValueStr();
      jumpMQOrderVo =
          (JumpMQOrderVo) input.getValue(0); // 多线程下,input.getValue(0)的某个值不会被多个线程重复获取,即线程安全
      Double orderAmount = 0.0;
      // 获取订单创建时间
      if (jumpMQOrderVo == null) {
        logger.info("====空消息体===");
        throw new Exception();
      }

      // 跨天判断
      msgDate = jumpMQOrderVo.getMsgSendTime();
      if (msgDate.getDate() != curDate.getDate()) {
        if (msgDate.after(curDate)) { // 跨天
          logger.info("===跨天处理===" + orderCreateDate);

          curDate = msgDate;

          /** 跨天处理 */
          curTime = DateUtil.getFmtDate(msgDate, DateUtil.YYYYMMDD_STR);
          curHour = msgDate.getHours() + 1;

          /** 清空小时数据 */
          orderAmountHourTotal = 0.0;
          orderNumHourTotal = 0;

          orderAmountTotal = 0.0;
          rowkey_amount_last = "last_amount_" + curTime;
          rowkey_amount_col_data = "col_data_" + curTime;
          sFinal = "[]";

          orderNumTotal = 0;
          rowkey_ordr_num_last = "last_ordr_num_" + curTime;
          rowkey_ordr_num_col_data = "col_data_ordr_num_" + curTime;
          sFinalOrdrNum = "[]";

          discountItemTotal.set(0);
          discountPriceTotal.set(0);

          dealHourFlg = 0;
        } else if (msgDate.before(curDate)) { // 非当天的历史订单
          return;
        }
      }

      // 处理订单
      orderAmount = processSoItem(input, jumpMQOrderVo);

      Date orderDate = BusinessLogic.orderDate(jumpMQOrderVo);
      if (orderDate == null) throw new IllegalArgumentException("Order Date is NULL");
      orderCreateDate = DateUtil.getFmtDate(orderDate, DateUtil.YYYYMMDD_STR);
      orderCreateHour = orderDate.getHours() + 1;

      // 进行订单净额累加操作
      logger.info("orderAmount:" + orderAmount);
      orderAmountTotal += orderAmount;
      logger.info("orderAmountTotal:" + orderAmountTotal);
      orderNumTotal++;

      // 订单创建小时数和当前系统小时数相同则进行小时订单净额累加操作,否则进行跨小时处理
      if (curHour == orderCreateHour) {
        // 如果sFinal为空,则初始化
        if ("[]".equals(sFinal)) {
          sFinal = CommonUtil.appendNextHourStr(curHour, sFinal, "0");
        }
        orderAmountHourTotal += orderAmount;
        orderNumHourTotal++;

        // 柱状图当前小时数据更新,之后需要重新设值
        sFinal = CommonUtil.replaceNowHourStr(sFinal, orderAmountHourTotal.toString());
        colData = sFinal;

        if ("[]".equals(sFinalOrdrNum)) {
          sFinalOrdrNum = CommonUtil.appendNextHourStr(curHour, sFinalOrdrNum, "0");
        }
        sFinalOrdrNum =
            CommonUtil.replaceNowHourStr(sFinalOrdrNum, String.valueOf(orderNumHourTotal));
        colDataOrdrNum = sFinalOrdrNum;
      } else if (curHour < orderCreateHour) { // 需要强制入库,否则会丢失至多30秒的数据
        logger.info("===跨小时处理===" + orderCreateHour);
        /** 跨小时处理 */
        curHour = orderCreateHour;

        orderAmountHourTotal = 0.0;
        // 柱状图拼接新的小时数据
        sFinal = CommonUtil.appendNextHourStr(curHour, sFinal, orderAmountHourTotal.toString());
        colData = sFinal;

        orderNumHourTotal = 0;
        sFinalOrdrNum =
            CommonUtil.appendNextHourStr(curHour, sFinalOrdrNum, String.valueOf(orderNumHourTotal));
        colDataOrdrNum = sFinalOrdrNum;
      } else { // 当前时间大于订单创建时间,表示mq里面有之前阻塞的订单,需要特殊处理或忽略
        logger.info("===处理阻塞订单===订单id:" + jumpMQOrderVo.baseInfo());
      }

      /** 写habse */
      // 插入小时级最后累加值记录,30秒一次入库,如果期间有很多订单过来,30秒期间刚好碰到跨小时的情况的话,那部分数据就会丢失
      synchronized (this) {
        insertDB_last_point_endTime = System.currentTimeMillis();
        // 5秒写入一次最后的点,前端5秒读取一次刷新最新的值insertDB_last_point_startTime
        if (insertDB_last_point_endTime - insertDB_last_point_startTime >= Constant.SECOND_5) {
          /** 订单净额 */
          logger.info("orderAmountTotal : " + orderAmountTotal);
          logger.info("orderNumHourTotal:" + orderNumHourTotal);
          // 插入最后累加值记录,重启bolt的时候需要获取最后一次插入的金额,在此基础上再进行累加
          dao.insertGosOrder(
              Constant.TABLE_ORDER_INFO_RESULT,
              rowkey_amount_last,
              Constant.COMMON_FAMILY,
              new String[] {"order_amount", "xValue", "xTitle"},
              new String[] {orderAmountTotal + "", strLastXValue[1], strLastXValue[0]});

          // 插入拼接的柱状图数据,单条记录,后端重启和前端展示获取历史都从这里获取
          dao.insertGosOrder(
              Constant.TABLE_ORDER_INFO_RESULT,
              rowkey_amount_col_data,
              Constant.COMMON_FAMILY,
              "col_data",
              colData);

          /** 订单数 */
          dao.insertGosOrder(
              Constant.TABLE_ORDER_INFO_RESULT,
              rowkey_ordr_num_last,
              Constant.COMMON_FAMILY,
              new String[] {"order_num", "xValue", "xTitle"},
              new String[] {orderNumTotal + "", strLastXValue[1], strLastXValue[0]});

          dao.insertGosOrder(
              Constant.TABLE_ORDER_INFO_RESULT,
              rowkey_ordr_num_col_data,
              Constant.COMMON_FAMILY,
              "col_data_ordr_num",
              colDataOrdrNum);

          insertDB_last_point_startTime = System.currentTimeMillis();
        }
      }

      synchronized (this) {
        insertDB_endTime = System.currentTimeMillis();
        if (insertDB_endTime - insertDB_startTime >= Constant.SECOND_50) {
          /** 线图数据处理 */
          rowkey_amount = curTime + "_amount_" + strLastXValue[0].replace(".", "");
          // 插入点的历史数据,线图中用来拼接历史数据线条
          dao.insertGosOrder(
              Constant.TABLE_ORDER_INFO_RESULT,
              rowkey_amount,
              Constant.COMMON_FAMILY,
              new String[] {"order_amount", "xValue", "xTitle"},
              new String[] {orderAmountTotal + "", strLastXValue[1], strLastXValue[0]});

          rowkey_ordr_num = curTime + "_ordr_num_" + strLastXValue[0].replace(".", "");
          dao.insertGosOrder(
              Constant.TABLE_ORDER_INFO_RESULT,
              rowkey_ordr_num,
              Constant.COMMON_FAMILY,
              new String[] {"order_num", "xValue", "xTitle"},
              new String[] {orderNumTotal + "", strLastXValue[1], strLastXValue[0]});

          logger.info("===50秒入库成功===");
          insertDB_startTime = System.currentTimeMillis();

          // 写Oracle ,推送数据到手机端报表
          // insertOracle(con, orderAmountTotal, orderNumTotal);
        }
      }
    } catch (Exception e) {
      logger.info("ERROR. Caused by:", e);
    }
  }
 /** 插入父单信息 */
 private void insertParentSo(Connection con, JumpMQOrderVo jumpMQOrderVo) {
   PreparedStatement st = null;
   String sql =
       "insert into edw1_dev.REALTIME_METADATA_SO (ID, ENDUSERID, ORDERCODE, ORDERCREATETIME, ORDERTYPE, ORDERSTATUS, BIZTYPE, ORDERSOURCE, PARENTSOID, SITETYPE, ORDERAMOUNT, PRODUCTAMOUNT, ISLEAF, PAYSERVICETYPE, MSGSENDTIME, UPDT_TIME) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
   try {
     st = con.prepareStatement(sql);
     st.setLong(1, jumpMQOrderVo.getId());
     st.setLong(2, jumpMQOrderVo.getEndUserId());
     st.setString(3, jumpMQOrderVo.getOrderCode());
     //			st.setDate(4, new java.sql.Date(jumpMQOrderVo.getOrderCreateTime().getTime()));
     if (jumpMQOrderVo.getOrderCreateTime() != null) {
       st.setTimestamp(4, new Timestamp(jumpMQOrderVo.getOrderCreateTime().getTime()));
     } else {
       st.setTimestamp(4, new Timestamp(new Date().getTime()));
     }
     st.setInt(5, jumpMQOrderVo.getOrderType());
     st.setInt(6, jumpMQOrderVo.getOrderStatus());
     st.setInt(7, jumpMQOrderVo.getBizType());
     st.setInt(8, jumpMQOrderVo.getOrderSource());
     st.setLong(9, jumpMQOrderVo.getParentSoId());
     st.setInt(10, jumpMQOrderVo.getSiteType());
     if (jumpMQOrderVo.getOrderAmount() != null) {
       st.setDouble(11, jumpMQOrderVo.getOrderAmount().doubleValue());
     } else {
       st.setDouble(11, 0.0);
     }
     if (jumpMQOrderVo.getProductAmount() != null) {
       st.setDouble(12, jumpMQOrderVo.getProductAmount().doubleValue());
     } else {
       st.setDouble(12, 0.0);
     }
     st.setInt(13, jumpMQOrderVo.getIsLeaf());
     st.setInt(14, jumpMQOrderVo.getPayServiceType());
     //			st.setDate(15, new java.sql.Date(jumpMQOrderVo.getMsgSendTime().getTime()));
     if (jumpMQOrderVo.getMsgSendTime() != null) {
       st.setTimestamp(15, new Timestamp(jumpMQOrderVo.getMsgSendTime().getTime()));
     } else {
       st.setTimestamp(15, new Timestamp(new Date().getTime()));
     }
     st.setTimestamp(16, new Timestamp(new Date().getTime()));
     st.executeQuery();
   } catch (Exception e) {
     logger.info("error: Metadata insert error ! ");
   } finally {
     try {
       st.close();
     } catch (SQLException e) {
       e.printStackTrace();
     }
   }
 }