public void initParam() {
    if (logger.isInfoEnabled()) {
      logger.info("**************卡库不平分析线程初始化**************"); // $NON-NLS-1$
    }
    try {
      Session session = HibernateSessionFactory.currentSession();
      Query queryTime =
          session.createQuery(
              "from MapAnalysisPoint as point where point.analysisname=:analysisName");
      queryTime.setString("analysisName", "UNBALANCE_ERROR");
      Iterator iterTime = queryTime.iterate();
      if (iterTime.hasNext()) {
        MapAnalysisPoint mapAnalysisPoint = (MapAnalysisPoint) iterTime.next();
        this.startTime = mapAnalysisPoint.getAnalysispoint();
      }

      if (!"20050101000000".equals(this.startTime)) {
        this.endTime = DateUtil.getNewTime(startTime, doubleCycle);
      } else {
        this.endTime = DateUtil.getNow();
        this.startTime = DateUtil.getNewTime(this.endTime, -doubleCycle);
      }

    } catch (HibernateException e) {
      logger.error("卡库不平分析线程初始化失败!", e); // $NON-NLS-1$
    } finally {
      HibernateSessionFactory.closeSession();
    }
    if (logger.isInfoEnabled()) {
      logger.info("**************卡库不平分析线程初始化成功**************"); // $NON-NLS-1$
    }
  }
  public void anaylize() {
    if (logger.isInfoEnabled()) {
      logger.info("卡库不平分析线程开始分析任务"); // $NON-NLS-1$
    }
    Transaction tx = null;
    try {
      Session session = HibernateSessionFactory.currentSession();
      tx = session.beginTransaction();
      this.accelateParam = Integer.parseInt(BgMonitor.getIntance().accelateParam);
      endTime = DateUtil.getNewTime(endTime, accelateParam * 60);
      if (logger.isInfoEnabled()) {
        logger.info("卡库不平分析线程开始分析时间:" + DateUtil.getNow("yyyy/MM/dd/HH:mm:ss")); // $NON-NLS-1$
      }
      if (1 > DateUtil.checkTimeSequence(endTime, DateUtil.getNow())) {
        if (logger.isInfoEnabled()) {
          logger.info("卡库不平分析线程分析时间段:" + startTime + " -- " + endTime);
        }
      } else {
        endTime = DateUtil.getNow();
        if (logger.isInfoEnabled()) {
          logger.info("卡库不平分析线程分析时间段:" + startTime + " -- " + endTime);
        }
      }
      getParameter(session);
      // analysis time record
      recordTime = DateUtil.getNow();
      BgMonitor.monitorThreadStatusReport(
          "com.kingstargroup.action.bgAnalysis.UnbalanceAnalysisThread",
          "卡库不平分析线程",
          DateUtil.getNow("yyyy/MM/dd/HH:mm:ss"),
          String.valueOf(this.doubleCycle),
          "运行中...");
      Query query =
          session
              .createSQLQuery(
                  "select {a.*} from ykt_cur.t_aif_account as a "
                      + "where a.cur_freebala<>a.card_balance "
                      + "and a.current_state=1 and (a.act_type=1 or a.act_type=3) "
                      + "order by a.account_id with ur ")
              .addEntity("a", TAifAccount.class);
      List list = query.list();
      Iterator iter = list.iterator();
      while (iter.hasNext()) {
        TAifAccount account = (TAifAccount) iter.next();
        if (true == recordOrNot) {
          MapCaunbalanceTable caUnbalance = new MapCaunbalanceTable();
          MapCaunbalanceTableKey unbalanceKey = new MapCaunbalanceTableKey();
          unbalanceKey.setAccountId(account.getAccountId());
          unbalanceKey.setAnalysisTime(recordTime);
          caUnbalance.setActType(account.getActType());
          caUnbalance.setCardBalance(account.getCardBalance());
          caUnbalance.setCardId(account.getCardId());
          caUnbalance.setCardType(account.getCardType());
          caUnbalance.setConsumeCount(account.getConsumeCount());
          caUnbalance.setCurBala(account.getCurBala());
          caUnbalance.setCurFreebala(account.getCurFreebala());
          caUnbalance.setCurFrozebala(account.getCurFrozebala());
          caUnbalance.setCurrentState(account.getCurrentState());
          caUnbalance.setCustomerId(account.getCustomerId());
          caUnbalance.setCutName(account.getCutName());
          caUnbalance.setCutType(account.getCutType());
          caUnbalance.setId(unbalanceKey);
          caUnbalance.setInBala(account.getInBala());
          caUnbalance.setInCount(account.getInCount());
          caUnbalance.setLastBala(account.getLastBala());
          caUnbalance.setLastFreebala(account.getLastFreebala());
          caUnbalance.setLastFrozebala(account.getLastFrozebala());
          caUnbalance.setOutBala(account.getOutBala());
          caUnbalance.setOutCount(account.getOutCount());
          caUnbalance.setPurseId(account.getPurseId());
          caUnbalance.setStuempNo(account.getStuempNo());
          caUnbalance.setSubno(account.getSubno());
          session.save(caUnbalance);
        }
        mailRecord++;
        if (!"".equals(mailList)) {
          // buffer.append(StringUtil.solidStringGenerate(account.getCardId().toString(),account.getCutName(),account.getStuempNo(),
          // "UNBALANCE_ERROR"));
        }
      }

      // record timepoint analysis
      Object tempAnalysis = session.get(MapAnalysisPoint.class, "UNBALANCE_ERROR");
      MapAnalysisPoint analysisPoint = null;
      if (tempAnalysis == null) {
        analysisPoint = new MapAnalysisPoint();
        analysisPoint.setAnalysisname("UNBALANCE_ERROR");
        analysisPoint.setAnalysispoint(endTime);
        session.save(analysisPoint);
      } else {
        analysisPoint = (MapAnalysisPoint) tempAnalysis;
        analysisPoint.setAnalysispoint(endTime);
        session.update(analysisPoint);
      }
      tx.commit();

      // mail
      sendMail();
      // SMG
      sendSMG();
    } catch (HibernateException e) {
      logger.error("卡库不平分析线程出现以下异常:", e); // $NON-NLS-1$

      if (tx != null) {
        tx.rollback();
      }
    } catch (Exception e) {
      logger.error("卡库不平分析线程出现以下异常:", e); // $NON-NLS-1$
      if (tx != null) {
        tx.rollback();
      }
    } finally {
      HibernateSessionFactory.closeSession();
    }

    // sleep thread follows the setting
    try {
      long sleepTime =
          Long.parseLong(String.valueOf(doubleCycle * 1000))
              - DateUtil.getIntervalTime(DateUtil.getNow(), recordTime);
      if (logger.isInfoEnabled()) {
        logger.info(
            "卡库不平分析线程结束进入休眠状态!"
                + " 休眠开始时间:"
                + DateUtil.getNow("yyyy/MM/dd/HH:mm:ss")
                + ", 休眠时间:"
                + sleepTime
                + " 毫秒"); //$NON-NLS-1$
      }
      this.startTime = this.endTime;
      this.endTime = DateUtil.getNewTime(this.endTime, doubleCycle);
      if (sleepTime <= 0) {
        sleep(600000);
      } else {
        sleep(sleepTime);
      }
    } catch (InterruptedException e) {
      logger.error("卡库不平分析线程出现以下异常:可能被强行停止! ", e); // $NON-NLS-1$
    } catch (Exception e) {
      logger.error("卡库不平分析线程出现以下异常:可能被强行停止! ", e); // $NON-NLS-1$
    }
  }