/**
  * 检查指定对象是否存在
  *
  * @param termno
  * @param termdate 日期
  * @param stattime 时间
  * @return
  */
 @SuppressWarnings("unchecked")
 private boolean isEntityExist(String termno, String termdate, String stattime) {
   boolean exist = false;
   StringBuilder sqlStr = new StringBuilder();
   sqlStr.append("select * from tradePinnacle where termno = '").append(termno);
   sqlStr.append("' and statdate = '").append(termdate);
   sqlStr.append("' and stattime = '").append(stattime);
   sqlStr.append("'");
   List<Map<String, String>> tempList = DBTools.queryToMapList(sqlStr.toString());
   if (tempList != null && tempList.size() > 0) {
     exist = true;
   }
   return exist;
 }
  @SuppressWarnings("unchecked")
  public boolean doAction(String param, String cmdParam) {
    System.out.println("Start statistic of trade times");
    // 获得当前系统日期
    Date cdate = new Date();
    Calendar cd = Calendar.getInstance();
    cd.setTime(cdate);
    // 获得当前时间的前一天时间
    cd.add(Calendar.DAY_OF_MONTH, -1);
    // 获得日期字符串,格式按logh logrt要求
    String yearstr = Integer.toString(cd.get(Calendar.YEAR));
    String month =
        cd.get(Calendar.MONTH) + 1 >= 10
            ? Integer.toString(cd.get(Calendar.MONTH) + 1)
            : "0" + Integer.toString(cd.get(Calendar.MONTH) + 1);
    String day =
        cd.get(Calendar.DAY_OF_MONTH) >= 10
            ? Integer.toString(cd.get(Calendar.DAY_OF_MONTH))
            : "0" + cd.get(Calendar.DAY_OF_MONTH);
    String termdate = yearstr + month + day;

    // 获得时间字符串,格式按logh logrt要求
    String starttime = "";
    String endtime = "";

    for (int i = 0; i < 24; i++) {
      StringBuilder sqlStr = new StringBuilder();
      /** starttime 统计开始时间 为统计时点的第一分钟 如2:00:00 字符格式为020000; 24小时计时法 */
      starttime = i >= 10 ? i + "0000" : "0" + i + "0000";
      /** endtime 统计截止时间 为统计时点的最后一分钟 如2:59:59 字符格式为025959; 24小时计时法 */
      endtime = i > 10 ? i + "5959" : "0" + i + "5959";
      sqlStr
          .append("select termno, count(termno) count from logh where termdate = '")
          .append(termdate);
      sqlStr.append("' and termtime >= '").append(starttime);
      sqlStr.append("' and termtime <= '").append(endtime);
      sqlStr.append("' group by termno");
      // 统计出前一天每小时的交易数
      List<Map<String, String>> tempList1 = DBTools.queryToMapList(sqlStr.toString());
      if (tempList1 != null && tempList1.size() > 0) {
        for (int j = 0; j < tempList1.size(); j++) {
          Map<String, String> tempMap = tempList1.get(i);
          String termno = tempMap.get("TERMNO").trim();
          int count = Integer.valueOf(tempMap.get("COUNT").trim());
          // 将统计结果导入表
          StringBuilder sql2Str = new StringBuilder();
          String stattime = i > 10 ? i + "0000" : "0" + i + "0000";
          sql2Str
              .append("insert into tradePinnacle(termno, statdate, stattime, tradeCount) values('")
              .append(termno);
          sql2Str.append("', '").append(termdate);
          sql2Str.append("', '").append(stattime);
          sql2Str.append("', ").append(count);
          sql2Str.append(")");
          if (!isEntityExist(termno, termdate, stattime))
            try {
              DBTools.executeUpdate(sql2Str.toString());
            } catch (SQLException e) {
              e.printStackTrace();
            }
        }
      }
    }

    return true;
  }