Commit 0b2e1498 authored by Quxl's avatar Quxl
parents cb8e9f42 36fdc579
......@@ -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_UTC_GMT = "EEE, dd MMM yyyy HH:mm:ss z";
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 MINUTE = 1000L*60;
......@@ -448,7 +448,43 @@ public class DateUtil {
}
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() {
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;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonSyntaxException;
public class GsonUtil {
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 Map<String, Object> toMap(String json) {
Map<String, Object> map = new HashMap<String, Object>();
Map<?, ?> jsonMap = GsonUtil.gson.fromJson(json, Map.class);
if(jsonMap != null) {
for(Object key : jsonMap.keySet()) {
map.put((String)key, jsonMap.get(key));
}
}
return map;
}
public static Map<?, ?> toMap(String json, Map<?, ?> defaultMap) {
try {
return GsonUtil.toMap(json);
} catch (JsonSyntaxException e) {
return defaultMap;
}
}
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);
}
}
package com.egolm.common;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonSyntaxException;
public class GsonUtil {
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 Map<String, Object> toMap(String json) {
Map<String, Object> map = new HashMap<String, Object>();
Map<?, ?> jsonMap = GsonUtil.gson.fromJson(json, Map.class);
if(jsonMap != null) {
for(Object key : jsonMap.keySet()) {
map.put((String)key, jsonMap.get(key));
}
}
return map;
}
public static Map<?, ?> toMap(String json, Map<?, ?> defaultMap) {
try {
return GsonUtil.toMap(json);
} catch (JsonSyntaxException e) {
return defaultMap;
}
}
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);
}
}
package com.egolm.common.jdbc.dialect;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
/**
* 数据库工具类
*
* @author onedear
* @data:2010-10-21 下午06:12:39
*/
public class SqlServerTo {
private String root;
private String pkg_name;
private String author;
private Connection conn;
static {
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
} catch (Exception e) {
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 {
this.root = root;
this.pkg_name = pkg_name;
this.author = author;
this.conn = DriverManager.getConnection("jdbc:sqlserver://" + db_host + ";instanceName=SQLSERVER;DatabaseName=" + db_name, db_user, db_pass);
}
public void execute() {
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'";
PreparedStatement pStemt = conn.prepareStatement(sql);
ResultSet set = pStemt.executeQuery();
while(set.next()) {
String name = set.getString("TABLE_NAME").trim();
String comment = set.getString("TABLE_COMMENT");
execute(name, comment);
}
conn.close();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public void executeFilter(String sign) {
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'";
PreparedStatement pStemt = conn.prepareStatement(sql);
ResultSet set = pStemt.executeQuery();
while(set.next()) {
String name = set.getString("TABLE_NAME").trim();
if(name.contains(sign)) {
String comment = set.getString("TABLE_COMMENT");
execute(name, comment);
}
}
conn.close();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
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();
List<String> names = new ArrayList<String>();
List<String> types = new ArrayList<String>();
List<String> comments = new ArrayList<String>();
List<String> paramyKeys = new ArrayList<String>();
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);
}
}
package com.egolm.common.jdbc.dialect;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
/**
* 数据库工具类
*
* @author onedear
* @data:2010-10-21 下午06:12:39
*/
public class SqlServerTo {
private String root;
private String pkg_name;
private String author;
private Connection conn;
static {
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
} catch (Exception e) {
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 {
this.root = root;
this.pkg_name = pkg_name;
this.author = author;
this.conn = DriverManager.getConnection("jdbc:sqlserver://" + db_host + ";instanceName=SQLSERVER;DatabaseName=" + db_name, db_user, db_pass);
}
public void execute() {
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'";
PreparedStatement pStemt = conn.prepareStatement(sql);
ResultSet set = pStemt.executeQuery();
while(set.next()) {
String name = set.getString("TABLE_NAME").trim();
String comment = set.getString("TABLE_COMMENT");
execute(name, comment);
}
conn.close();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public void executeView() {
try {
String sql = "SELECT TABLE_NAME , 'REMARK' AS TABLE_COMMENT FROM INFORMATION_SCHEMA.VIEWS";
PreparedStatement pStemt = conn.prepareStatement(sql);
ResultSet set = pStemt.executeQuery();
while(set.next()) {
String name = set.getString("TABLE_NAME").trim();
String comment = set.getString("TABLE_COMMENT");
execute(name, comment);
}
conn.close();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public void executeFilter(String sign) {
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'";
PreparedStatement pStemt = conn.prepareStatement(sql);
ResultSet set = pStemt.executeQuery();
while(set.next()) {
String name = set.getString("TABLE_NAME").trim();
if(name.contains(sign)) {
String comment = set.getString("TABLE_COMMENT");
execute(name, comment);
}
}
conn.close();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
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();
List<String> names = new ArrayList<String>();
List<String> types = new ArrayList<String>();
List<String> comments = new ArrayList<String>();
List<String> paramyKeys = new ArrayList<String>();
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