Example #1
0
  public boolean doAction(String param, String cmdParam) {
    logger.info("开始执行当天交易数据转移");
    String s_sql = "";
    try {
      s_sql = "insert into logh select * from logrt ";
      DBTools.executeUpdate(s_sql);
    } catch (Exception ex) {
      System.out.println("error in TransferLogrt" + ex.getMessage());
    }
    try {
      s_sql = "delete from logrt";
      DBTools.executeUpdate(s_sql);
    } catch (Exception ex) {
      System.out.println("error in TransferLogrt" + ex.getMessage());
    }
    logger.info("当天交易数据转移执行成功");
    /*java.util.Date d_date = new java.util.Date();
    SimpleDateFormat bartDateFormat = new SimpleDateFormat("yyyyMMdd");
    String s_date=bartDateFormat.format(d_date);
    String s_termtime="";
    String s_trancount="";
    int i_trancount=1000;
    String s_sql="select paraval from syspara where paraname='trancount'";
    List<Map<String, String>> tempList = DBTools.queryToMapList(s_sql);
    if(tempList.size()>0){
    	Map<String, String> tempMap = tempList.get(0);
    	s_trancount=tempMap.get("PARAVAL");
    	if(s_trancount==null || s_trancount.compareTo("")==0){
    		i_trancount=1000;
    	}else{
    		if(s_trancount.trim().compareTo("")==0){
    			i_trancount=1000;
    		}else{
    			i_trancount=Integer.parseInt(s_trancount.trim());
    		}
    	}
    }else{
    	i_trancount=1000;
    }

    s_sql="select min(termtime) termtime from logrt where termdate='"+s_date+"' and "
    	+"termno+termtrace+termdate+termtime in (select top "+i_trancount+" termno+termtrace+termdate+termtime from logrt "
    	+"where termdate='"+s_date+"' order by termtime desc)";
    List<Map<String, String>> tempList1 = DBTools.queryToMapList(s_sql);
    s_sql="select * from logrt where termdate='"+s_date+"'";
    List<Map<String, String>> tempList2 = DBTools.queryToMapList(s_sql);
    if(tempList1.size()>0 && tempList2.size()>i_trancount){
    	Map<String, String> tempMap1 = tempList1.get(0);
    	s_termtime=tempMap1.get("TERMTIME");
    	s_sql="insert into logrt_temp select * from logrt where termtime<'"+s_termtime+"'";
    	DBTools.queryToMapList(s_sql);
    	s_sql="delete from logrt where termtime<'"+s_termtime+"'";
    	DBTools.queryToMapList(s_sql);
    }*/
    return true;
  }
 /**
  * 检查指定对象是否存在
  *
  * @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;
  }