Example #1
0
 public static String getMess(String code) {
   return AutoProperties.getString(code, "", messConfig);
 }
Example #2
0
 public static String getConfig(String code) {
   return AutoProperties.getString(code, "", lbapConfig);
 }
Example #3
0
  @Override
  public void run() {
    logger.info(name + " is running...");
    String resource = "com.success.lottery.ticket.service.TicketRouter";
    if ("true"
        .equalsIgnoreCase(
            AutoProperties.getString("ticketSender.loadWhenStart", "false", resource).trim())) {
      logger.debug("TicketSender will load the to send ticket from database when start.");
      loadSendTicketWhenStart();
      logger.debug("TicketSender load the to send ticket from database completed when start.");
    }

    BetTicketServiceInterf lotteryBetTicketService =
        ApplicationContextUtils.getService("lotteryBetTicketService", BetTicketServiceInterf.class);
    // LotteryTermServiceInterf lotteryTermService =
    // ApplicationContextUtils.getService("lotteryTermService", LotteryTermServiceInterf.class);
    List<Integer> ticketStatus = new ArrayList<Integer>();
    ticketStatus.add(Integer.valueOf(0));
    ticketStatus.add(Integer.valueOf(3));
    ticketStatus.add(Integer.valueOf(4));
    ticketStatus.add(Integer.valueOf(5));

    while (!isStop) {
      try {
        List<BetTicketDomain> ticketes =
            lotteryBetTicketService.getTicketes(
                ticketStatus,
                "printStation='" + station + "'",
                AutoProperties.getInt("ticketSender.queryLimit", 1000, resource));

        List<String> ticketSequences = new ArrayList<String>();
        List<TicketLogInfo> logInfo = new ArrayList<TicketLogInfo>();
        if (ticketes != null && ticketes.size() > 0) {
          ticketCount = ticketCount + ticketes.size();
          for (BetTicketDomain ticket : ticketes) {
            logger.debug("TicketSender get a ticket(" + ticket.getTicketSequence() + ").");
            TicketLogInfo info = new TicketLogInfo();
            info.setName("TICKETSENDER");
            info.setInTime(System.currentTimeMillis());
            info.setProcessorName(this.getName());
            info.setTicketSequence(ticket.getTicketSequence());
            info.setOrderId(ticket.getOrderId());

            if (TicketDispatch.contains(ticket)) {
              logger.debug(
                  "TicketSender get the ticket("
                      + ticket.getTicketSequence()
                      + ") was already sent to the queue.");
              sendFail++;
              continue;
            } else {
              // 转换投注串格式
              String printCode =
                  EHandSplitTools.betCodeToPrintCode(
                      ticket.getLotteryId(),
                      ticket.getPlayType(),
                      ticket.getBetType(),
                      ticket.getBetCode());
              // 转换投注方式
              int printType =
                  EHandSplitTools.betTypeToPrintType(
                      ticket.getLotteryId(), ticket.getPlayType(), ticket.getBetType());
              logger.debug(
                  "TicketSender convert a ticket("
                      + ticket.getTicketSequence()
                      + ") betType from:"
                      + ticket.getBetType()
                      + " to:"
                      + printType
                      + " betCode from:"
                      + ticket.getBetCode()
                      + " to:"
                      + printCode);
              info.setRemark(
                  "convert betType from:"
                      + ticket.getBetType()
                      + " to:"
                      + printType
                      + " betCode from:"
                      + ticket.getBetCode()
                      + " to:"
                      + printCode);
              ticket.setBetType(printType);
              ticket.setBetCode(printCode);

              String rs = null;
              if ((rs = TicketDispatch.dispatch(ticket)) == null) {
                logger.debug(
                    "TicketSender send the ticket("
                        + ticket.getTicketSequence()
                        + ") to the queue success.");
                ticketSequences.add(ticket.getTicketSequence());
                info.addRemark("dispatch", "success");
                logInfo.add(info);
              } else {
                logger.debug(
                    "TicketSender send the ticket("
                        + ticket.getTicketSequence()
                        + ") to the queue failed:"
                        + rs
                        + ".");
                sendFail++;
              }
            }
          }
          String rs = null;
          if (ticketSequences.size() > 0) {
            try {
              int rc = 0;
              if ((rc =
                      lotteryBetTicketService.updateBetTicketesStatus(
                          ticketSequences, 1, ticketStatus))
                  == 0) {
                rs = "NoRowsUpdate";
                logger.debug(
                    "TicketSender update the ticketes("
                        + ticketSequences.toString()
                        + ") ticketStauts = 1 failed:"
                        + rs);
                sendFail = sendFail + ticketSequences.size();
              } else {
                logger.debug(
                    "TicketSender update "
                        + rc
                        + " ticketes("
                        + ticketSequences.toString()
                        + ") ticketStauts = 1 success.");
                sendSucc = sendSucc + ticketSequences.size();
                for (TicketLogInfo info : logInfo) {
                  info.setResult(rs);
                  info.setOutTime(System.currentTimeMillis());
                  TicketLogger.getInstance("TICKET").log(info);
                }
              }
            } catch (Exception e) {
              logger.error(
                  "TicketSender update the ticketes("
                      + ticketSequences.toString()
                      + ") ticketStatus = 1 occur exception:"
                      + e);
              if (logger.isDebugEnabled()) {
                e.printStackTrace();
              }
              sendFail = sendFail + ticketSequences.size();
              rs = e.toString();
            }
          }
        }
        int count = ticketSequences == null ? 0 : ticketSequences.size();
        logger.debug(
            "TicketSender get "
                + count
                + " ticketes, sleep "
                + AutoProperties.getInt("ticketSender.interval", 200, resource)
                + "ms.");
        try {
          Thread.sleep(AutoProperties.getInt("ticketSender.interval", 200, resource));
        } catch (Exception e) {
        }
      } catch (Exception e) {
        logger.error("TicketSender occur unknow exception:" + e);
        if (logger.isDebugEnabled()) {
          e.printStackTrace();
        }
        try {
          Thread.sleep(AutoProperties.getInt("ticketSender.interval", 200, resource));
        } catch (Exception e1) {
        }
      }
    }
    isExit = true;
    logger.info(name + " is shutdown!");
  }