Beispiel #1
0
  public static void main(String[] args) {
    Logger logger = Logger.getLogger(Main.class);
    Date fTime = new Date();
    Date tTime = new Date();
    if (args.length == 2) {
      fTime = MyUtil.StringToDate(args[0]);
      tTime = MyUtil.StringToDate(args[1]);
    }
    if (args.length == 0) {
      Calendar fromWhen = Calendar.getInstance();
      fromWhen.setTime(fTime);
      GregorianCalendar gc =
          new GregorianCalendar(
              fromWhen.get(Calendar.YEAR),
              fromWhen.get(Calendar.MONTH),
              fromWhen.get(Calendar.DAY_OF_MONTH));
      tTime = (Date) gc.getTime();
      gc.add(Calendar.DATE, -1);
      fTime = (Date) gc.getTime();
    }
    logger.info("Stats process start " + new Date());

    long flag = (tTime.getTime() - fTime.getTime()) / 1000 / 3600 / 24;
    for (long temp = 0; temp < flag; temp++) {
      Calendar fromWhen = Calendar.getInstance();
      fromWhen.setTime(fTime);
      GregorianCalendar gc =
          new GregorianCalendar(
              fromWhen.get(Calendar.YEAR),
              fromWhen.get(Calendar.MONTH),
              fromWhen.get(Calendar.DAY_OF_MONTH));
      gc.add(Calendar.DATE, 1);
      tTime = (Date) gc.getTime();

      System.out.print(fTime);
      System.out.print("----");
      System.out.println(tTime);

      GoldStats.setAllGold(fTime);
      GoldStats.setAllPearl(fTime);
      GoldStats.setAllCredit(fTime);
      StockStats.StartStats(fTime);
      // 家族等级分布
      TribeStats.setAllTribeLevel(fTime);

      fTime = tTime;
    }
    logger.info("Stats process end " + new Date());
  }
 /**
  * 获得数据库中所有表的集合
  *
  * @param DBName 数据库名,区分大小写
  * @return
  * @throws Exception
  */
 public static List<Table> getTables(String DBName) throws Exception {
   String sql =
       "select TABLE_SCHEMA,TABLE_NAME,COLUMN_NAME,COLUMN_DEFAULT,"
           + "IS_NULLABLE,DATA_TYPE,COLUMN_TYPE,COLUMN_KEY,COLUMN_COMMENT "
           + "from information_schema.columns where table_schema = '"
           + DBName
           + "'";
   PreparedStatement ps = DBUtil.getPS(sql);
   ResultSet rs = ps.executeQuery();
   List<Table> list = new ArrayList<Table>();
   List<TableStructure> colNames = new ArrayList<TableStructure>();
   String tableName = "";
   while (rs.next()) {
     TableStructure ts = new TableStructure();
     java.lang.reflect.Field[] fields = ts.getClass().getDeclaredFields();
     for (java.lang.reflect.Field f : fields) {
       Type type = f.getType();
       String name = f.getName();
       Method m = ts.getClass().getDeclaredMethod("set" + MyUtil.initcap(name), (Class<?>) type);
       m.invoke(ts, rs.getString(name));
     }
     if (!tableName.equalsIgnoreCase(ts.getTable_name()) && tableName != "") {
       Table table = new Table();
       table.setDBName(DBName);
       table.setName(tableName);
       table.setTableStructures(colNames);
       list.add(table);
       colNames = new ArrayList<TableStructure>();
     }
     colNames.add(ts);
     tableName = ts.getTable_name();
   }
   DBUtil.closeCon();
   return list;
 }
 // 新版开始
 private void getColumn(String tableName, Object... className) throws Exception {
   String sql =
       "select TABLE_SCHEMA,TABLE_NAME,COLUMN_NAME,COLUMN_DEFAULT,"
           + "IS_NULLABLE,DATA_TYPE,COLUMN_TYPE,COLUMN_KEY,COLUMN_COMMENT "
           + "from information_schema.columns where table_name='"
           + tableName
           + "' and table_schema = '"
           + DBName
           + "'";
   PreparedStatement ps = DBUtil.getPS(sql);
   ResultSet rs = ps.executeQuery();
   while (rs.next()) {
     TableStructure ts = new TableStructure();
     java.lang.reflect.Field[] fields = ts.getClass().getDeclaredFields();
     for (java.lang.reflect.Field f : fields) {
       Type type = f.getType();
       String name = f.getName();
       Method m = ts.getClass().getDeclaredMethod("set" + MyUtil.initcap(name), (Class<?>) type);
       m.invoke(ts, rs.getString(name));
     }
     colNames.add(ts);
   }
   giveValue(tableName, className);
   DBUtil.closeCon();
 }
Beispiel #4
0
 public static int getStep(String log) {
   String sign = "user get current step , step = ";
   log = log.substring(log.indexOf(sign) + sign.length());
   if (MyUtil.isMonetid(log.trim())) {
     return Integer.parseInt(log.trim());
   }
   return 1;
 }
 // 生成JAVA文件
 private String writeJavaString(String tableName, Object... className) {
   StringBuilder sb = new StringBuilder();
   sb.append("package " + entityPath + ";\r\n\n");
   if (f_util) {
     sb.append("import java.sql.Date;\r\n");
     sb.append("import java.sql.Timestamp;\r\n");
     sb.append("import java.text.ParseException;\r\n");
     sb.append("import java.text.SimpleDateFormat;\r\n");
   }
   if (f_sql) {
     sb.append("import java.sql.*;\r\n");
   }
   sb.append("import java.io.Serializable;\r\n");
   sb.append("import javax.persistence.Column;\r\n");
   sb.append("import javax.persistence.Entity;\r\n");
   sb.append("import javax.persistence.GeneratedValue;\r\n");
   sb.append("import javax.persistence.GenerationType;\r\n");
   sb.append("import javax.persistence.Id;\r\n");
   sb.append("import javax.persistence.Transient;\r\n");
   sb.append("import javax.persistence.Table;\r\n\n");
   sb.append("@Entity\r\n");
   sb.append("@Table(name=\"" + tableName + "\")\r\n");
   if (className.length != 0) {
     sb.append(
         "public class "
             + MyUtil.humpcap(className[0].toString())
             + " implements Serializable {\r\n\n");
   } else {
     sb.append("public class " + MyUtil.humpcap(tableName) + " implements Serializable {\r\n\n");
   }
   sb.append("\t@Transient");
   sb.append("\tprivate static final long serialVersionUID = 1L;\r\n\n");
   writeAllAttrs(sb);
   writeAllMethod(sb);
   if (className.length != 0) {
     writeHashCodeAndEquals(sb, MyUtil.humpcap(className[0].toString()));
   } else {
     writeHashCodeAndEquals(sb, MyUtil.humpcap(tableName));
   }
   sb.append("}\r\n");
   return sb.toString();
 }
 private void writeAllMethod(StringBuilder sb) {
   for (int i = 0; i < colNames.size(); i++) {
     String name = colNames.get(i).getColumn_name().trim();
     String type = colNames.get(i).getData_type().trim();
     String attr = MyUtil.initsmallcap(MyUtil.humpcap(name));
     sb.append(
         "\t\r\n\tpublic void set"
             + MyUtil.humpcap(name)
             + "("
             + castTpye(type)
             + " "
             + attr
             + "){\r\n");
     sb.append("\t\tthis." + attr + "=" + attr + ";\r\n");
     sb.append("\t}\r\n");
     sb.append("\t\r\n\tpublic " + castTpye(type) + " get" + MyUtil.humpcap(name) + "(){\r\n");
     sb.append("\t\treturn " + attr + ";\r\n");
     sb.append("\t}\r\n");
   }
 }
 // 为判断条件赋值
 private void giveValue(String tableName, Object... className) {
   for (int i = 1; i < colNames.size(); i++) {
     String type = colNames.get(i).getData_type().trim();
     if ("datetime".equalsIgnoreCase(type)
         || "date".equalsIgnoreCase(type)
         || "timestamp".equalsIgnoreCase(type)) {
       f_util = true;
     }
     if ("image".equalsIgnoreCase(type)
         || "text".equalsIgnoreCase(type)
         || "blob".equalsIgnoreCase(type)) {
       f_sql = true;
     }
   }
   if (className.length != 0) {
     writeFile(writeJavaString(tableName, className), MyUtil.humpcap(className[0].toString()));
   } else {
     writeFile(writeJavaString(tableName), MyUtil.humpcap(tableName));
   }
 }
Beispiel #8
0
 public static int getActionOwner(String log) {
   if (log != null) {
     if (log.length() > 0) {
       if (log.indexOf("user get") != -1) {
         log = log.substring(0, log.indexOf("user get"));
         log = log.substring(log.lastIndexOf("-"), log.length());
         if (MyUtil.isMonetid(log.trim())) {
           return Integer.parseInt(log.trim());
         }
       }
     }
   }
   return 0;
 }
Beispiel #9
0
 public static int getNewUserId(String log) {
   if (log != null) {
     if (log.length() > 0) {
       if (log.indexOf("new fisher") != -1) {
         log = log.substring(0, log.indexOf("new fisher"));
         log = log.substring(log.lastIndexOf("-"), log.length());
         if (MyUtil.isMonetid(log.trim())) {
           return Integer.parseInt(log.trim());
         }
       }
     }
   }
   return 0;
 }
 private void writeHashCodeAndEquals(StringBuilder sb, String className) {
   for (int i = 0; i < colNames.size(); i++) {
     String key = colNames.get(i).getColumn_key().trim();
     String name = colNames.get(i).getColumn_name().trim();
     String attr = MyUtil.initsmallcap(MyUtil.humpcap(name));
     if ("PRI".equalsIgnoreCase(key)) {
       sb.append("\t@Override\r\n");
       sb.append("\tpublic int hashCode() {\r\n");
       sb.append("\t\tfinal int prime = 31;\r\n");
       sb.append("\t\tint result = 1;\r\n");
       sb.append(
           "\t\tresult = prime * result + (("
               + attr
               + " == null) ? 0 : "
               + attr
               + ".hashCode());\r\n");
       sb.append("\t\treturn result;\r\n");
       sb.append("\t}\r\n\n");
       sb.append("\t@Override\r\n");
       sb.append("\tpublic boolean equals(Object obj) {\r\n");
       sb.append("\t\tif (this == obj) return true;\r\n");
       sb.append("\t\tif (obj == null) return false;\r\n");
       sb.append("\t\tif (getClass() != obj.getClass()) return false;\r\n");
       sb.append("\t\t" + className + " other = (" + className + ") obj;\r\n");
       sb.append(
           "\t\tif ("
               + attr
               + " == null) {\r\n\t\t\tif (other."
               + attr
               + " != null) return false;\r\n");
       sb.append("\t\t} else if (!" + attr + ".equals(other." + attr + ")) return false;\r\n");
       sb.append("\t\treturn true;\r\n");
       sb.append("\t}\r\n\n");
       break;
     }
   }
 }
 private void writeAllAttrs(StringBuilder sb) {
   for (int i = 0; i < colNames.size(); i++) {
     TableTypeLength ttl = getTpye(colNames.get(i).getColumn_type().trim());
     String name = colNames.get(i).getColumn_name().trim();
     String type = ttl.getType().trim();
     boolean isNull =
         "NO".equalsIgnoreCase(colNames.get(i).getIs_nullable().trim()) ? false : true;
     Object defVal = colNames.get(i).getColumn_default();
     String comment = colNames.get(i).getColumn_comment().trim();
     Integer length = ttl.getLength();
     String key = colNames.get(i).getColumn_key().trim();
     String str = castTpye(type);
     String attr = MyUtil.initsmallcap(MyUtil.humpcap(name));
     if ("PRI".equalsIgnoreCase(key)) {
       sb.append("\t@Id\r\n");
       sb.append("\t@GeneratedValue(strategy = GenerationType.IDENTITY)\r\n");
       sb.append(
           "\t@Column(name=\""
               + name
               + "\""
               + (length == null ? "" : ",length=" + length)
               + ",nullable="
               + isNull
               + ")"
               + (defVal == null ? "" : "//default=\"" + defVal + "\"")
               + "\r\n");
     } else {
       boolean b = "UNI".equalsIgnoreCase(key);
       if ("decimal".equalsIgnoreCase(type)
           || "numeric".equalsIgnoreCase(type)
           || "smallmoney".equalsIgnoreCase(type)
           || "real".equalsIgnoreCase(type)
           || "double".equalsIgnoreCase(type)
           || "number".equalsIgnoreCase(type)
           || "binary_double".equalsIgnoreCase(type)
           || "money".equalsIgnoreCase(type)) {
         Integer pre = ttl.getPrecision();
         if (pre != null && pre != 0) {
           sb.append(
               "\t@Column(name=\""
                   + name
                   + "\",precision="
                   + pre
                   + ",scale="
                   + ttl.getScale()
                   + ",nullable="
                   + isNull
                   + (b == true ? ",unique=true" : "")
                   + ")"
                   + (defVal == null ? "" : "//default=\"" + defVal + "\"")
                   + "\r\n");
         } else {
           sb.append(
               "\t@Column(name=\""
                   + name
                   + "\",nullable="
                   + isNull
                   + (b == true ? ",unique=true" : "")
                   + ")"
                   + (defVal == null ? "" : "//default=\"" + defVal + "\"")
                   + "\r\n");
         }
       } else {
         sb.append(
             "\t@Column(name=\""
                 + name
                 + "\""
                 + (length == null ? "" : ",length=" + length)
                 + ",nullable="
                 + isNull
                 + (b == true ? ",unique=true" : "")
                 + ")"
                 + (defVal == null ? "" : "//default=\"" + defVal + "\"")
                 + "\r\n");
       }
     }
     sb.append(
         "\tprivate "
             + str
             + " "
             + attr
             + ";"
             + (comment.trim() == "" || comment == null ? "" : "//" + comment)
             + "\r\n\n");
   }
 }