Commit 0b2e1498 authored by Quxl's avatar Quxl
parents cb8e9f42 36fdc579
...@@ -29,9 +29,9 @@ public class DateUtil { ...@@ -29,9 +29,9 @@ public class DateUtil {
public static final String FMT_DATE_ISO = "yyyy-MM-ddTHH:mm:ss.SSSZ"; public static final String FMT_DATE_ISO = "yyyy-MM-ddTHH:mm:ss.SSSZ";
public static final String FMT_UTC_GMT = "EEE, dd MMM yyyy HH:mm:ss z"; public static final String FMT_UTC_GMT = "EEE, dd MMM yyyy HH:mm:ss z";
public static final String FMT_YYYYMMddHHMMSS = "yyyyMMddHHmmss"; public static final String FMT_YYYYMMddHHMMSS = "yyyyMMddHHmmss";
public static final String FMT_UTC_ALIYUN="yyyy-MM-dd'T'HH:mm:ss'Z'"; public static final String FMT_UTC_ALIYUN="YYYY-MM-DD'T'hh:mm:ss'Z'";
public static final String FMT_YYYY_MM = "yyyy/MM"; public static final String FMT_YYYY_MM = "yyyy-MM";
public static final Long SECOND = 1000L; public static final Long SECOND = 1000L;
public static final Long MINUTE = 1000L*60; public static final Long MINUTE = 1000L*60;
...@@ -448,7 +448,43 @@ public class DateUtil { ...@@ -448,7 +448,43 @@ public class DateUtil {
} }
return null; return null;
} }
public static String getLastMonth(String format,int month) {
try {
SimpleDateFormat sdf = new SimpleDateFormat(format);
//获取前一个月第一天
Calendar calendar1 = Calendar.getInstance();
calendar1.add(Calendar.MONTH, month);
calendar1.set(Calendar.DAY_OF_MONTH,1);
return sdf.format(calendar1.getTime());
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static String getTimeStamp() { public static String getTimeStamp() {
return String.valueOf(System.currentTimeMillis() / 1000); return String.valueOf(System.currentTimeMillis() / 1000);
} }
/**
* 获取指定小时前的日期
*/
public static String beforeHourDay(String fmt,int hour) {
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, calendar.get(Calendar.HOUR_OF_DAY) - hour);
return format(calendar.getTime(), fmt);
}
/**
* 取得当前时间向后或向前若干天的时间
*
* @param time
* @param offset
* @return
*/
public static String beforeDay(String fmt, Integer offset) {
Date date = new Date(new Date().getTime() + (offset * 86400000L));
return format(date, fmt);
}
} }
package com.egolm.common; package com.egolm.common;
import java.util.HashMap;
import java.util.List; import java.util.HashMap;
import java.util.Map; import java.util.List;
import java.util.Map;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder; import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException; import com.google.gson.GsonBuilder;
import com.google.gson.JsonSyntaxException;
public class GsonUtil {
public class GsonUtil {
public static final Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss").serializeNulls().disableHtmlEscaping().create();
public static final Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss").serializeNulls().disableHtmlEscaping().create();
public static String toJson(Object object) {
return GsonUtil.gson.toJson(object); public static String toJson(Object object) {
} return GsonUtil.gson.toJson(object);
}
public static Map<String, Object> toMap(String json) {
Map<String, Object> map = new HashMap<String, Object>(); public static Map<String, Object> toMap(String json) {
Map<?, ?> jsonMap = GsonUtil.gson.fromJson(json, Map.class); Map<String, Object> map = new HashMap<String, Object>();
if(jsonMap != null) { Map<?, ?> jsonMap = GsonUtil.gson.fromJson(json, Map.class);
for(Object key : jsonMap.keySet()) { if(jsonMap != null) {
map.put((String)key, jsonMap.get(key)); for(Object key : jsonMap.keySet()) {
} map.put((String)key, jsonMap.get(key));
} }
return map; }
} return map;
}
public static Map<?, ?> toMap(String json, Map<?, ?> defaultMap) {
try { public static Map<?, ?> toMap(String json, Map<?, ?> defaultMap) {
return GsonUtil.toMap(json); try {
} catch (JsonSyntaxException e) { return GsonUtil.toMap(json);
return defaultMap; } catch (JsonSyntaxException e) {
} return defaultMap;
} }
}
public static <T> T toObj(String json, Class<T> type) {
return GsonUtil.gson.fromJson(json, type); public static <T> T toObj(String json, Class<T> type) {
} return GsonUtil.gson.fromJson(json, type);
}
public static List<?> toList(String json) {
return GsonUtil.gson.fromJson(json, List.class); public static List<?> toList(String json) {
} return GsonUtil.gson.fromJson(json, List.class);
}
}
}
package com.egolm.common.jdbc.dialect; package com.egolm.common.jdbc.dialect;
import java.sql.Connection; import java.sql.Connection;
import java.sql.DriverManager; import java.sql.DriverManager;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
* 数据库工具类 * 数据库工具类
* *
* @author onedear * @author onedear
* @data:2010-10-21 下午06:12:39 * @data:2010-10-21 下午06:12:39
*/ */
public class SqlServerTo { public class SqlServerTo {
private String root; private String root;
private String pkg_name; private String pkg_name;
private String author; private String author;
private Connection conn; private Connection conn;
static { static {
try { try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
public SqlServerTo(String root, String pkg_name, String author, String db_host, String db_name, String db_user, String db_pass) throws SQLException { public SqlServerTo(String root, String pkg_name, String author, String db_host, String db_name, String db_user, String db_pass) throws SQLException {
this.root = root; this.root = root;
this.pkg_name = pkg_name; this.pkg_name = pkg_name;
this.author = author; this.author = author;
this.conn = DriverManager.getConnection("jdbc:sqlserver://" + db_host + ";instanceName=SQLSERVER;DatabaseName=" + db_name, db_user, db_pass); this.conn = DriverManager.getConnection("jdbc:sqlserver://" + db_host + ";instanceName=SQLSERVER;DatabaseName=" + db_name, db_user, db_pass);
} }
public void execute() { public void execute() {
try { try {
String sql = "SELECT D.name AS TABLE_NAME, 'REMARK' AS TABLE_COMMENT FROM sysobjects AS D WHERE D.XTYPE = 'U' AND D.NAME <> 'dtproperties'"; String sql = "SELECT D.name AS TABLE_NAME, 'REMARK' AS TABLE_COMMENT FROM sysobjects AS D WHERE D.XTYPE = 'U' AND D.NAME <> 'dtproperties'";
PreparedStatement pStemt = conn.prepareStatement(sql); PreparedStatement pStemt = conn.prepareStatement(sql);
ResultSet set = pStemt.executeQuery(); ResultSet set = pStemt.executeQuery();
while(set.next()) { while(set.next()) {
String name = set.getString("TABLE_NAME").trim(); String name = set.getString("TABLE_NAME").trim();
String comment = set.getString("TABLE_COMMENT"); String comment = set.getString("TABLE_COMMENT");
execute(name, comment); execute(name, comment);
} }
conn.close(); conn.close();
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
public void executeFilter(String sign) { public void executeView() {
try { try {
String sql = "SELECT D.name AS TABLE_NAME, 'REMARK' AS TABLE_COMMENT FROM sysobjects AS D WHERE D.XTYPE = 'U' AND D.NAME <> 'dtproperties'"; String sql = "SELECT TABLE_NAME , 'REMARK' AS TABLE_COMMENT FROM INFORMATION_SCHEMA.VIEWS";
PreparedStatement pStemt = conn.prepareStatement(sql); PreparedStatement pStemt = conn.prepareStatement(sql);
ResultSet set = pStemt.executeQuery(); ResultSet set = pStemt.executeQuery();
while(set.next()) { while(set.next()) {
String name = set.getString("TABLE_NAME").trim(); String name = set.getString("TABLE_NAME").trim();
if(name.contains(sign)) { String comment = set.getString("TABLE_COMMENT");
String comment = set.getString("TABLE_COMMENT"); execute(name, comment);
execute(name, comment); }
} conn.close();
} } catch (Exception e) {
conn.close(); throw new RuntimeException(e);
} catch (Exception e) { }
throw new RuntimeException(e); }
}
} public void executeFilter(String sign) {
try {
public void execute(String name, String comment) { String sql = "SELECT D.name AS TABLE_NAME, 'REMARK' AS TABLE_COMMENT FROM sysobjects AS D WHERE D.XTYPE = 'U' AND D.NAME <> 'dtproperties'";
try { PreparedStatement pStemt = conn.prepareStatement(sql);
ResultSet set = conn.prepareStatement("SELECT COL.NAME AS COLUMN_NAME, T.NAME AS COLUMN_TYPE, CAST(P.VALUE AS VARCHAR(999)) AS COLUMN_COMMENT, CASE WHEN EXISTS (SELECT 1 FROM dbo.sysindexes SI INNER JOIN dbo.sysindexkeys SIK ON SI.ID = SIK.ID AND SI.INDID = SIK.INDID INNER JOIN dbo.syscolumns SC ON SC.ID = SIK.ID AND SC.COLID = SIK.COLID INNER JOIN dbo.sysobjects SO ON SO.NAME = SI.NAME AND SO.XTYPE = 'PK' WHERE SC.ID = COL.ID AND SC.COLID = COL.COLID ) THEN 1 ELSE 0 END AS IS_PARAMY_KEY FROM syscolumns AS COL LEFT JOIN systypes T ON T.XUSERTYPE = COL.XTYPE LEFT JOIN sys.extended_properties P ON COL.ID = P.MAJOR_ID AND COL.COLID = P.MAJOR_ID WHERE COL.ID=OBJECT_ID('" + name + "')").executeQuery(); ResultSet set = pStemt.executeQuery();
List<String> names = new ArrayList<String>(); while(set.next()) {
List<String> types = new ArrayList<String>(); String name = set.getString("TABLE_NAME").trim();
List<String> comments = new ArrayList<String>(); if(name.contains(sign)) {
List<String> paramyKeys = new ArrayList<String>(); String comment = set.getString("TABLE_COMMENT");
while(set.next()) { execute(name, comment);
String columnName = set.getString("COLUMN_NAME").trim(); }
String columnType = set.getString("COLUMN_TYPE").trim(); }
String columnComment = set.getString("COLUMN_COMMENT"); conn.close();
Integer isParamyKey = set.getInt("IS_PARAMY_KEY"); } catch (Exception e) {
names.add(columnName); throw new RuntimeException(e);
types.add(columnType); }
comments.add(columnComment); }
if(isParamyKey == 1) {
paramyKeys.add(columnName); public void execute(String name, String comment) {
} try {
} ResultSet set = conn.prepareStatement("SELECT COL.NAME AS COLUMN_NAME, T.NAME AS COLUMN_TYPE, CAST(P.VALUE AS VARCHAR(999)) AS COLUMN_COMMENT, CASE WHEN EXISTS (SELECT 1 FROM dbo.sysindexes SI INNER JOIN dbo.sysindexkeys SIK ON SI.ID = SIK.ID AND SI.INDID = SIK.INDID INNER JOIN dbo.syscolumns SC ON SC.ID = SIK.ID AND SC.COLID = SIK.COLID INNER JOIN dbo.sysobjects SO ON SO.NAME = SI.NAME AND SO.XTYPE = 'PK' WHERE SC.ID = COL.ID AND SC.COLID = COL.COLID ) THEN 1 ELSE 0 END AS IS_PARAMY_KEY FROM syscolumns AS COL LEFT JOIN systypes T ON T.XUSERTYPE = COL.XTYPE LEFT JOIN sys.extended_properties P ON COL.ID = P.MAJOR_ID AND COL.COLID = P.MAJOR_ID WHERE COL.ID=OBJECT_ID('" + name + "')").executeQuery();
if(!name.startsWith("sys") && !name.startsWith("SYS")) { List<String> names = new ArrayList<String>();
ReverseUtil.parseEntity(pkg_name, author, root, name, comment, paramyKeys, names, types, comments); List<String> types = new ArrayList<String>();
} List<String> comments = new ArrayList<String>();
} catch (Exception e) { List<String> paramyKeys = new ArrayList<String>();
throw new RuntimeException(e); while(set.next()) {
} String columnName = set.getString("COLUMN_NAME").trim();
} String columnType = set.getString("COLUMN_TYPE").trim();
String columnComment = set.getString("COLUMN_COMMENT");
Integer isParamyKey = set.getInt("IS_PARAMY_KEY");
names.add(columnName);
types.add(columnType);
comments.add(columnComment);
if(isParamyKey == 1) {
paramyKeys.add(columnName);
}
}
if(!name.startsWith("sys") && !name.startsWith("SYS")) {
ReverseUtil.parseEntity(pkg_name, author, root, name, comment, paramyKeys, names, types, comments);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment