Browse Source

1.增加基础工具类2.增加异常处理

will.chen 7 years ago
parent
commit
e90c6d6c35

+ 7 - 0
pom.xml

@@ -51,6 +51,13 @@
 		    <artifactId>log4j</artifactId>
 		    <version>1.2.17</version>
 		</dependency>
+		
+		<dependency>
+			<groupId>com.alibaba</groupId>
+			<artifactId>fastjson</artifactId>
+			<version>1.2.15</version>
+		</dependency>
+		
 	</dependencies>
 
 	<build>

+ 0 - 1
src/main/java/com/uas/eis/UasEisApplication.java

@@ -4,7 +4,6 @@ import org.springframework.beans.factory.annotation.Configurable;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 
-@Configurable
 @SpringBootApplication
 public class UasEisApplication {
 

+ 2 - 2
src/main/java/com/uas/eis/utils/WebAppConfig.java → src/main/java/com/uas/eis/core/WebAppConfig.java

@@ -1,10 +1,10 @@
-package com.uas.eis.utils;
+package com.uas.eis.core;
 
 import org.springframework.context.annotation.Configuration;
 import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
 import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
 
-import com.uas.eis.utils.support.InterceptorConfig;
+import com.uas.eis.core.support.InterceptorConfig;
 
 @Configuration
 public class WebAppConfig extends WebMvcConfigurationSupport{

+ 1 - 1
src/main/java/com/uas/eis/utils/support/InterceptorConfig.java → src/main/java/com/uas/eis/core/support/InterceptorConfig.java

@@ -1,4 +1,4 @@
-package com.uas.eis.utils.support;
+package com.uas.eis.core.support;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;

+ 476 - 0
src/main/java/com/uas/eis/dao/BaseDao.java

@@ -0,0 +1,476 @@
+package com.uas.eis.dao;
+
+import java.sql.CallableStatement;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.springframework.dao.DataAccessException;
+import org.springframework.dao.EmptyResultDataAccessException;
+import org.springframework.jdbc.core.BeanPropertyRowMapper;
+import org.springframework.jdbc.core.CallableStatementCallback;
+import org.springframework.jdbc.core.CallableStatementCreator;
+import org.springframework.jdbc.core.support.JdbcDaoSupport;
+
+import com.uas.eis.utils.BaseUtil;
+import com.uas.eis.utils.Constant;
+import com.uas.eis.utils.DateUtil;
+
+public class BaseDao extends JdbcDaoSupport{
+
+	
+	public List<Map<String, Object>> queryForList(String sql) {
+		try {
+			return this.getJdbcTemplate().queryForList(sql);
+		} catch (EmptyResultDataAccessException e) {
+			return null;
+		}
+	}
+
+	public <T> List<T> queryForList(String sql, Class<T> elementType) {
+		try {
+			return this.getJdbcTemplate().queryForList(sql, elementType);
+		} catch (EmptyResultDataAccessException e) {
+			return null;
+		}
+	}
+	
+	public List<Map<String, Object>> queryForList(String sql, Object... args) {
+		try {
+			return this.getJdbcTemplate().queryForList(sql, args);
+		} catch (EmptyResultDataAccessException e) {
+			return null;
+		}
+	}
+
+	public <T> List<T> queryForList(String sql, Object[] args, Class<T> elementType) {
+		try {
+			return this.getJdbcTemplate().queryForList(sql, args, elementType);
+		} catch (EmptyResultDataAccessException e) {
+			return null;
+		}
+	}
+
+	public <T> List<T> queryForList(String sql, Class<T> elementType, Object... args) {
+		try {
+			return this.getJdbcTemplate().queryForList(sql, elementType, args);
+		} catch (EmptyResultDataAccessException e) {
+			return null;
+		}
+	}
+	
+	public <T> List<T> query(String sql, Object[] args, Class<T> elementType) {
+		try {
+			return this.getJdbcTemplate().query(sql, args, new BeanPropertyRowMapper<T>(elementType));
+		} catch (EmptyResultDataAccessException e) {
+			return null;
+		}
+	}
+
+	public <T> List<T> query(String sql, Class<T> elementType) {
+		try {
+			return this.getJdbcTemplate().query(sql, new BeanPropertyRowMapper<T>(elementType));
+		} catch (EmptyResultDataAccessException e) {
+			return null;
+		}
+	}
+
+	public <T> List<T> query(String sql, Class<T> elementType, Object... args) {
+		try {
+			return this.getJdbcTemplate().query(sql, new BeanPropertyRowMapper<T>(elementType), args);
+		} catch (EmptyResultDataAccessException e) {
+			return null;
+		}
+	}
+
+	public <T> T queryForObject(String sql, Class<T> elementType, Object... args) {
+		try {
+			return this.getJdbcTemplate().queryForObject(sql, elementType, args);
+		} catch (EmptyResultDataAccessException e) {
+			return null;
+		}
+	}
+	
+	public void execute(String sql) {
+		getJdbcTemplate().execute(sql);
+	}
+
+	public synchronized boolean execute(String sql, Object... objs) {
+		try {
+			getJdbcTemplate().update(sql, objs);
+			return true;
+		} catch (Exception e) {
+			return false;
+		}
+	}
+
+	public void execute(List<String> sqls) {
+		if (sqls.size() > 0) {
+			StringBuffer sb = new StringBuffer("begin ");
+			for (String sql : sqls) {
+				sb.append("execute immediate '").append(sql.replace("'", "''")).append("';");
+			}
+			sb.append("end;");
+			getJdbcTemplate().execute(sb.toString());
+		}
+	}
+	
+	/**
+	 * 批量执行Sql
+	 * 
+	 * @param sqls
+	 * @param callbackSqls
+	 */
+	public void batchExecute(List<SqlMap> sqls, List<String> callbackSqls) {
+		if (sqls.size() > 0) {
+			StringBuffer sb = new StringBuffer("begin ");
+			for (SqlMap sql : sqls) {
+				sb.append("execute immediate '").append(sql.getSql(false).replace("'", "''")).append("';");
+			}
+			for (String sql : callbackSqls) {
+				sb.append("execute immediate '").append(sql.replace("'", "''")).append("';");
+			}
+			sb.append("end;");
+			getJdbcTemplate().execute(sb.toString());
+		}
+	}
+	
+	public void deleteById(String tablename, String keyField, long id) {
+		deleteByCondition(tablename, keyField + "=" + id);
+	}
+
+	public void deleteByCondition(String tablename, String condition, Object... params) {
+		StringBuffer sb = new StringBuffer();
+		sb.append("DELETE FROM ");
+		sb.append(tablename);
+		sb.append(" WHERE ");
+		sb.append(condition);
+		execute(sb.toString(), params);
+	}
+	
+	/**
+	 * 一个字段,多条结果
+	 * 
+	 * @param tableName
+	 *            对应要查询的表
+	 * @param field
+	 *            要查询的字段
+	 * @param condition
+	 *            查询条件
+	 * @return field对应的数据
+	 */
+	public List<Object> getFieldDatasByCondition(String tableName, String field, String condition) {
+		StringBuffer sb = new StringBuffer("SELECT ");
+		sb.append(field);
+		sb.append(" FROM ");
+		sb.append(tableName);
+		sb.append(((condition == null || "".equals(condition)) ? "" : (" WHERE " + condition)));
+		SqlRowList srs = queryForRowSet(sb.toString());
+		List<Object> list = new ArrayList<Object>();
+		while (srs.next()) {
+			list.add(srs.getObject(1));
+		}
+		return list;
+	}
+
+	/**
+	 * 多个字段,<=1条结果
+	 * 
+	 * @param tableName
+	 *            对应要查询的表
+	 * @param fields
+	 *            要查询的字段,用逗号隔开
+	 * @param condition
+	 *            查询条件
+	 * @return fields对应的数据
+	 */
+	public Object[] getFieldsDataByCondition(String tableName, String fields, String condition) {
+		StringBuffer sql = new StringBuffer("SELECT ");
+		sql.append(fields);
+		sql.append(" FROM ");
+		sql.append(tableName);
+		sql.append(" WHERE ");
+		sql.append(condition);
+		String[] strs = fields.split(",");
+		int length = strs.length;
+		List<Map<String, Object>> list = getJdbcTemplate().queryForList(sql.toString());
+		Iterator<Map<String, Object>> iter = list.iterator();
+		Object[] results = new Object[length];
+		Object value = null;
+		if (iter.hasNext()) {
+			Map<String, Object> m = iter.next();
+			for (int i = 0; i < length; i++) {
+				value = m.get(strs[i].toUpperCase());
+				if (value != null && value.getClass().getSimpleName().toUpperCase().equals("TIMESTAMP")) {
+					Timestamp time = (Timestamp) value;
+					try {
+						value = DateUtil.parseDateToString(new Date(time.getTime()), Constant.YMD_HMS);
+					} catch (Exception e) {
+						e.printStackTrace();
+					}
+				}
+				results[i] = value;
+			}
+			return results;
+		}
+		return null;
+	}
+	
+	/**
+	 * if resultSet is null return true
+	 */
+	public boolean checkByCondition(String caller, String condition) {
+		int count = getCountByCondition(caller, condition);
+		if (count == 0) {
+			return true;
+		}
+		return false;
+	}
+	
+	/**
+	 * if resultSet not null return true
+	 */
+	public boolean checkIf(String table, String condition) {
+		int count = getCountByCondition(table, condition);
+		if (count > 0) {
+			return true;
+		}
+		return false;
+	}
+	
+	/**
+	 * 修改操作
+	 * 
+	 * @param tableName
+	 *            表
+	 * @param update
+	 *            修改内容
+	 * @param condition
+	 *            条件语句
+	 */
+	public void updateByCondition(String tableName, String update, String condition) {
+		StringBuffer sb = new StringBuffer("UPDATE ");
+		sb.append(tableName);
+		sb.append(" SET ");
+		sb.append(update);
+		sb.append(" WHERE ");
+		sb.append(condition);
+		execute(sb.toString());
+	}
+	
+	/**
+	 * 调用存储过程 无返回值
+	 * 
+	 * @param procedureName
+	 *            存储过程名称
+	 * @param args
+	 *            参数
+	 */
+	public void procedure(String procedureName, Object[] args) {
+		StringBuffer sql = new StringBuffer("{call ").append(procedureName).append("(");
+		for (int i = 0; i < args.length; i++) {
+			if (i > 0) {
+				sql.append(",");
+			}
+			sql.append("?");
+		}
+		sql.append(")}");
+		getJdbcTemplate().update(sql.toString(), args);
+	}
+
+	/**
+	 * 调用存储过程
+	 * 
+	 * @param procedureName
+	 *            存储过程名称
+	 * @param args
+	 *            参数
+	 * @return varchar类型结果
+	 */
+	public List<String> callProcedureWithOut(final String procedureName, final Object[] args, final Integer[] inIndex,
+			final Integer[] outIndex) {
+
+		StringBuffer sql = new StringBuffer("{call " + procedureName + "(");
+
+		for (int i = 0; i < inIndex.length + outIndex.length; i++) {
+			if (sql.toString().contains("?")) {
+				sql.append(",?");
+			} else {
+				sql.append("?");
+			}
+		}
+		sql.append(")}");
+
+		List<String> listR = getJdbcTemplate().execute(sql.toString(), new CallableStatementCallback<List<String>>() {
+
+			@Override
+			public List<String> doInCallableStatement(CallableStatement cs) throws SQLException, DataAccessException {
+				for (int i = 0; i < inIndex.length; i++) {
+					cs.setObject(inIndex[i], args[i]);
+				}
+
+				for (int i = 0; i < outIndex.length; i++) {
+					cs.registerOutParameter(outIndex[i], java.sql.Types.VARCHAR);
+				}
+
+				cs.execute();
+				List<String> list = new ArrayList<String>();
+				for (int i = 0; i < outIndex.length; i++) {
+
+					list.add(cs.getString(outIndex[i]));
+				}
+
+				return list;
+			}
+		});
+		return listR;
+
+	}
+
+	/**
+	 * 调用存储过程
+	 * 
+	 * @param procedureName
+	 *            存储过程名称
+	 * @param args
+	 *            参数
+	 * @return varchar类型结果
+	 */
+	public String callProcedure(final String procedureName, final Object... args) {
+		try {
+			return getJdbcTemplate().execute(new CallableStatementCreator() {
+				@Override
+				public CallableStatement createCallableStatement(Connection conn) throws SQLException {
+					StringBuffer storedProcName = new StringBuffer("{call ");
+					int i = 0;
+					storedProcName.append(procedureName + "(");
+					for (i = 0; i < args.length; i++) {
+						if (storedProcName.toString().contains("?")) {
+							storedProcName.append(",");
+						}
+						storedProcName.append("?");
+					}
+					if (storedProcName.toString().contains("?")) {
+						storedProcName.append(",");
+					}
+					storedProcName.append("?");
+					storedProcName.append(")}");
+					CallableStatement cs = conn.prepareCall(storedProcName.toString());
+					for (i = 0; i < args.length; i++) {
+						cs.setObject(i + 1, args[i]);
+					}
+					cs.registerOutParameter(args.length + 1, java.sql.Types.VARCHAR);
+					return cs;
+				}
+			}, new CallableStatementCallback<String>() {
+				@Override
+				public String doInCallableStatement(CallableStatement cs) throws SQLException, DataAccessException {
+					cs.execute();
+					return cs.getString(args.length + 1);
+				}
+
+			});
+		} catch (Exception e) {
+			BaseUtil.showError(e.getMessage());
+		}
+		return null;
+	}
+
+	/**
+	 * 调用存储过程
+	 * 
+	 * @param procedureName
+	 *            存储过程名称
+	 * @param cls
+	 *            返回结果java类型
+	 * @param sqlType
+	 *            返回结果的sql类型
+	 * @param args
+	 *            参数
+	 * @return varchar类型结果
+	 */
+	public <T> T callbackProcedure(final String procedureName, final Class<T> cls, final int sqlType, final Object... args) {
+		try {
+			return getJdbcTemplate().execute(new CallableStatementCreator() {
+				@Override
+				public CallableStatement createCallableStatement(Connection conn) throws SQLException {
+					StringBuffer storedProcName = new StringBuffer("{call ");
+					int i = 0;
+					storedProcName.append(procedureName + "(");
+					for (i = 0; i < args.length; i++) {
+						if (storedProcName.toString().contains("?")) {
+							storedProcName.append(",");
+						}
+						storedProcName.append("?");
+					}
+					if (storedProcName.toString().contains("?")) {
+						storedProcName.append(",");
+					}
+					storedProcName.append("?");
+					storedProcName.append(")}");
+					CallableStatement cs = conn.prepareCall(storedProcName.toString());
+					for (i = 0; i < args.length; i++) {
+						cs.setObject(i + 1, args[i]);
+					}
+					cs.registerOutParameter(args.length + 1, sqlType);
+					return cs;
+				}
+			}, new CallableStatementCallback<T>() {
+				@SuppressWarnings("unchecked")
+				@Override
+				public T doInCallableStatement(CallableStatement cs) throws SQLException, DataAccessException {
+					cs.execute();
+					// do not use method: getObject(paramInt, paramClass)
+					return (T) cs.getObject(args.length + 1);
+				}
+
+			});
+		} catch (Exception e) {
+			e.printStackTrace();
+			BaseUtil.showError(e.getMessage());
+		}
+		return null;
+	}
+
+	/**
+	 * 查询结果集
+	 * 
+	 * @param sql
+	 *            查询语句
+	 */
+	public SqlRowList queryForRowSet(String sql) {
+		SqlRowList rs = new SqlRowList();
+		rs.setResultList(getJdbcTemplate().queryForList(sql));
+		return rs;
+	}
+	
+	/**
+	 * @param tableName
+	 *            对应要查询的表
+	 * @param condition
+	 *            查询条件
+	 * @return Count
+	 */
+	public int getCountByCondition(String tableName, String condition) {
+		StringBuffer sql = new StringBuffer("SELECT count(1) FROM ");
+		sql.append(tableName);
+		sql.append(" WHERE ");
+		sql.append(condition);
+		SqlRowList srs = queryForRowSet(sql.toString());
+		if (srs.next()) {
+			return srs.getInt(1);
+		} else {
+			try {
+				throw new Exception("Condition:" + condition + " is wrong!");
+			} catch (Exception e) {
+				return -1;
+			}
+		}
+	}
+	
+}

+ 36 - 0
src/main/java/com/uas/eis/dao/RowConvert.java

@@ -0,0 +1,36 @@
+package com.uas.eis.dao;
+
+import org.springframework.util.NumberUtils;
+
+public class RowConvert<T>{
+
+	private Class<T> requiredType;
+
+	public RowConvert(Class<T> requiredType) {
+		this.requiredType = requiredType;
+	}
+
+	@SuppressWarnings("unchecked")
+	protected Object convertValueToRequiredType(Object value, @SuppressWarnings("rawtypes") Class requiredType) {
+		if (String.class.equals(requiredType)) {
+			return value.toString();
+		}
+		if (Number.class.isAssignableFrom(requiredType)) {
+			if (value instanceof Number) {
+				return NumberUtils.convertNumberToTargetClass((Number) value, requiredType);
+			}
+			return NumberUtils.parseNumber(value.toString(), requiredType);
+		}
+		throw new IllegalArgumentException(
+				"Value [" + value + "] is of type [" + value.getClass().getName() +
+						"] and cannot be converted to required type [" + requiredType.getName() + "]");
+	}
+
+	@SuppressWarnings("unchecked")
+	public T convert(Object value) {
+		if (value != null && this.requiredType != null && !this.requiredType.isInstance(value)) {
+			return (T) convertValueToRequiredType(value, this.requiredType);
+		}
+		return (T) value;
+	}
+}

+ 473 - 0
src/main/java/com/uas/eis/dao/SqlMap.java

@@ -0,0 +1,473 @@
+package com.uas.eis.dao;
+
+import java.io.Serializable;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.springframework.dao.DataAccessException;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.jdbc.core.support.AbstractLobCreatingPreparedStatementCallback;
+import org.springframework.jdbc.support.lob.LobCreator;
+import org.springframework.jdbc.support.lob.LobHandler;
+import org.springframework.util.StringUtils;
+
+import com.uas.eis.utils.BaseUtil;
+import com.uas.eis.utils.Constant;
+import com.uas.eis.utils.ContextUtil;
+import com.uas.eis.utils.DateUtil;
+
+/**
+ * 封装sql操作,提供对特殊类型的值的灵活处理
+ * 
+ * @author yingp
+ * 
+ * @since 2015-11-26
+ *        <p>
+ *        增加更新功能,参考构造函数;增加对lob数据的处理
+ *        </p>
+ * 
+ */
+public class SqlMap implements Serializable {
+
+	/**
+	 * 
+	 */
+	private static final long serialVersionUID = 7665440776209042811L;
+
+	/**
+	 * 如果sysdate,getdate()等符合该正则表达式的字符串不需要特殊处理<br>
+	 * 就调用set(String, Object, boolean)方法,第三个参数为false
+	 */
+	private static final String REG_SPECIAL = "(?:sysdate|getdate\\(\\))";
+
+	private static final int longStringBytes = 4000;// 字符串最长字节数,超过了就得使用lob类型
+
+	private String table;
+
+	/**
+	 * 主键
+	 */
+	private String primaryKey;
+	/**
+	 * 主键值
+	 */
+	private Object primaryValue;
+
+	private boolean isNew = true;
+
+	private List<String> fields;
+
+	private Object[] values;
+
+	private Set<String> specialKeys;
+
+	public SqlMap() {
+		fields = new ArrayList<String>();
+		values = new Object[] {};
+		specialKeys = new HashSet<String>();
+	}
+
+	/**
+	 * 新增模式
+	 * 
+	 * @param table
+	 *            待插入的表
+	 */
+	public SqlMap(String table) {
+		this();
+		this.table = table;
+	}
+
+	/**
+	 * 修改模式
+	 * 
+	 * @param table
+	 *            待插入的表
+	 * @param primaryKey
+	 *            主键
+	 */
+	public SqlMap(String table, String primaryKey) {
+		this(table);
+		this.primaryKey = primaryKey;
+		isNew = false;
+	}
+
+	/**
+	 * 修改模式
+	 * 
+	 * @param table
+	 *            待插入的表
+	 * @param primaryKey
+	 *            主键
+	 * @param primaryValue
+	 *            主键值
+	 */
+	public SqlMap(String table, String primaryKey, Object primaryValue) {
+		this(table);
+		this.primaryKey = primaryKey;
+		this.primaryValue = primaryValue;
+		isNew = false;
+	}
+
+	/**
+	 * 添加要插入的字段
+	 * 
+	 * @param field
+	 *            toSql字段
+	 * @param value
+	 *            字段的值
+	 * @param type
+	 *            字段的类型
+	 */
+	public void set(String field, Object value) {
+		if (!isNew && field.equals(primaryKey)) {
+			primaryValue = value;
+		} else {
+			if (isSpecial(value)) {
+				setSpecial(field, value);
+			} else {
+				if (value != null) {
+					if (value.toString().matches(Constant.REG_DATE)) {
+						setDate(field, value.toString(), Constant.YMD);
+					} else if (value.toString().matches(Constant.REG_DATETIME)) {
+						setDate(field, value.toString(), Constant.YMD_HMS);
+					} else {
+						setObject(field, value);
+					}
+				} else {
+					setObject(field, value);
+				}
+			}
+		}
+	}
+
+	public void setObject(String field, Object value) {
+		if (fields.contains(field)) {
+			int index = fields.indexOf(field);
+			values[index] = value;
+		} else {
+			fields.add(field);
+			values = Arrays.copyOf(values, values.length + 1);
+			values[values.length - 1] = value;
+		}
+	}
+
+	/**
+	 * 添加要插入的字段
+	 * 
+	 * @param field
+	 *            toSql字段
+	 * @param value
+	 *            字段的值
+	 * @param special
+	 *            是否是特殊字符,比如调用数据库函数,参数等
+	 */
+	public void set(String field, Object value, boolean special) {
+		if (!isNew && field.equals(primaryKey)) {
+			primaryValue = value;
+		} else {
+			if (special) {
+				setSpecial(field, value);
+			} else {
+				if (value != null) {
+					if (value.toString().matches(Constant.REG_DATE)) {
+						setDate(field, value.toString(), Constant.YMD);
+					} else if (value.toString().matches(Constant.REG_DATETIME)) {
+						setDate(field, value.toString(), Constant.YMD_HMS);
+					} else {
+						setObject(field, value);
+					}
+				} else {
+					setObject(field, value);
+				}
+			}
+		}
+	}
+
+	/**
+	 * 添加要插入的字段
+	 * 
+	 * @param field
+	 *            toSql字段
+	 * @param value
+	 *            字段的值
+	 */
+	public void setSpecial(String field, Object value) {
+		if (!isNew && field.equals(primaryKey)) {
+			primaryValue = value;
+		} else {
+			setObject(field, value);
+			specialKeys.add(field);
+		}
+	}
+
+	/**
+	 * 添加要插入的字段 <b>字段值为空</b>
+	 * 
+	 * @param field
+	 *            toSql字段
+	 * @param value
+	 *            字段的值
+	 */
+	public void setNull(String field) {
+		setSpecial(field, "null");
+	}
+
+	/**
+	 * 添加要插入的字段<b>Double型</b>
+	 * 
+	 * @param field
+	 *            toSql字段
+	 * @param value
+	 *            {Double}字段的值
+	 */
+	public void setDouble(String field, Double value) {
+		value = value == null ? 0 : value;
+		setSpecial(field, value);
+	}
+
+	/**
+	 * 添加要插入的字段<b>日期型</b>
+	 * 
+	 * @param to
+	 *            toSql字段
+	 * @param value
+	 *            {Date}字段的值
+	 */
+	public void setDate(String field, Date value) {
+		setDate(field, value, Constant.YMD_HMS);
+	}
+
+	/**
+	 * 添加要插入的字段<b>日期型</b>
+	 * 
+	 * @param to
+	 *            toSql字段
+	 * @param value
+	 *            {Date}字段的值
+	 * @param format
+	 *            格式
+	 */
+	public void setDate(String field, Date value, String format) {
+		if (value == null)
+			setNull(field);
+		else
+			setSpecial(field, DateUtil.parseDateToOracleString(format, value));
+	}
+
+	/**
+	 * 添加要插入的字段<b>日期型</b>
+	 * 
+	 * @param to
+	 *            toSql字段
+	 * @param value
+	 *            {Date}字段的值
+	 */
+	public void setDate(String field, String value) {
+		setDate(field, value, Constant.YMD_HMS);
+	}
+
+	/**
+	 * 添加要插入的字段<b>日期型</b>
+	 * 
+	 * @param to
+	 *            toSql字段
+	 * @param value
+	 *            {Date}字段的值
+	 * @param format
+	 *            格式
+	 */
+	public void setDate(String field, String value, String format) {
+		if (value == null)
+			setNull(field);
+		else
+			setSpecial(field, DateUtil.parseDateToOracleString(format, value));
+	}
+
+	private static boolean isSpecial(Object value) {
+		if (value != null) {
+			return value.toString().matches(REG_SPECIAL);
+		}
+		return false;
+	}
+
+	/**
+	 * 是否lob类型
+	 * 
+	 * @param value
+	 * @return
+	 */
+	private static boolean isLob(Object value) {
+		return value != null && value.toString().getBytes().length > longStringBytes;
+	}
+
+	/**
+	 * insert语句
+	 * 
+	 * @param mark
+	 *            {true: value以参数形式传入}
+	 * @return
+	 */
+	public String getInsertSql(boolean mark) {
+		StringBuffer sb = new StringBuffer();
+		sb.append("INSERT INTO ").append(table).append("(").append(BaseUtil.parseList2Str(fields, ",", true)).append(") VALUES (")
+				.append(getEnd(mark)).append(")");
+		return sb.toString();
+	}
+
+	/**
+	 * update语句
+	 * 
+	 * @param mark
+	 *            {true: value以参数形式传入}
+	 * @return
+	 */
+	public String getUpdateSql(boolean mark) {
+		StringBuffer sb = new StringBuffer();
+		sb.append("UPDATE ").append(table).append(" SET ").append(getEnd(mark));
+		return sb.toString();
+	}
+
+	/**
+	 * 行复制语句
+	 * 
+	 * @param mark
+	 *            {true: value以参数形式传入}
+	 * @return
+	 */
+	public String getCopySql(String condition) {
+		StringBuffer sb = new StringBuffer("begin ");
+		sb.append("for rs in (select * from ");
+		sb.append(table);
+		if (!StringUtils.isEmpty(condition))
+			sb.append(" where ").append(condition);
+		else if (primaryValue != null)
+			sb.append(" where ").append(primaryKey).append("=").append(primaryValue);
+		sb.append(") loop");
+		int i = 0;
+		for (String f : fields) {
+			sb.append(" rs.");
+			sb.append(f);
+			sb.append(":=");
+			if (specialKeys.contains(f)) {
+				sb.append(values[i++]);
+			} else {
+				sb.append("'").append(values[i++]).append("'");
+			}
+			sb.append(";");
+		}
+		sb.append(" insert into ");
+		sb.append(table);
+		sb.append(" values rs;");
+		sb.append(" end loop; ");
+		sb.append(" end;");
+		return sb.toString();
+	}
+
+	/**
+	 * insertOrUpdate语句
+	 * 
+	 * @param mark
+	 *            {true: value以参数形式传入}
+	 * @return
+	 */
+	public String getSql(boolean mark) {
+		return isNew ? getInsertSql(mark) : getUpdateSql(mark);
+	}
+
+	/**
+	 * 执行sql
+	 */
+	public void execute() {
+		BaseDao baseDao = (BaseDao) ContextUtil.getBean("baseDao");
+		baseDao.getJdbcTemplate().update(getSql(true), values);
+	}
+
+	/**
+	 * 执行sql
+	 */
+	public void executeCopy(String condition) {
+		BaseDao baseDao = (BaseDao) ContextUtil.getBean("baseDao");
+		baseDao.getJdbcTemplate().update(getCopySql(condition));
+	}
+
+	/**
+	 * 执行sql
+	 * 
+	 * @param jdbcTemplate
+	 */
+	public void execute(JdbcTemplate jdbcTemplate, LobHandler lobHandler) {
+		jdbcTemplate.execute(getSql(true), new AbstractLobCreatingPreparedStatementCallback(lobHandler) {
+			@Override
+			protected void setValues(PreparedStatement ps, LobCreator lob) throws SQLException, DataAccessException {				
+				/*int j=1;
+				for (int i=0;i<values.length-1 ;i++) {
+					if(!specialKeys.contains(fields.get(i))){
+						if (isLob(values[i]))
+							lob.setClobAsString(ps, j, values[i].toString());
+						else
+							ps.setObject(j, values[i]);
+						j++;
+					}		
+				}
+				ps.setObject(j, primaryValue);*/
+				int i = 0;
+				for (Object value : values) {
+					i++;
+					if (isLob(value))
+						lob.setClobAsString(ps, i, value.toString());
+					else
+						ps.setObject(i, value);
+				}
+			}
+		});
+	}	
+	/**
+	 * @param mark
+	 *            {true: value以参数形式传入}
+	 * @return
+	 */
+	private String getEnd(boolean mark) {
+		int len = fields.size();
+		StringBuffer sb = new StringBuffer();
+		String field = null;
+		Object[] tmp = new Object[values.length -specialKeys.size()];
+        int k=0;
+		for (int i = 0; i < len; i++) {
+			if (sb.length() > 0)
+				sb.append(",");
+			field = fields.get(i);
+			if (!isNew)
+				sb.append(field).append("=");
+			if (specialKeys.contains(field)) {
+				sb.append(values[i]);				
+			} else {
+				tmp[k]=values[i];
+				k++;
+				if (mark)
+					sb.append("?");
+				else
+					sb.append("'").append(values[i]).append("'");
+			}
+		}
+		if (!isNew) {
+			sb.append(" WHERE ").append(primaryKey).append("=");
+			if (mark) {
+				sb.append("?");
+				tmp=Arrays.copyOf(tmp, tmp.length+1);
+				tmp[tmp.length-1]=primaryValue;
+			} else {
+				sb.append("'").append(primaryValue).append("'");
+			}
+		}
+		values=Arrays.copyOf(tmp, tmp.length);
+		return sb.toString();
+	}
+
+}

+ 436 - 0
src/main/java/com/uas/eis/dao/SqlRowList.java

@@ -0,0 +1,436 @@
+package com.uas.eis.dao;
+
+import java.math.BigDecimal;
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import com.alibaba.fastjson.JSONObject;
+import com.uas.eis.utils.Constant;
+import com.uas.eis.utils.DateUtil;
+import com.uas.eis.utils.NumberUtil;
+
+/**
+ * org.springframework.jdbc.support.rowset.SqlRowSet有jdk版本问题
+ * 
+ * @author yingp 2013-1-10 11:50:08
+ */
+public class SqlRowList {
+
+	private List<Map<String, Object>> resultList;// 结果集
+	private Iterator<Map<String, Object>> iterator;
+	private Map<String, Object> currentMap;// 当前Map
+	private int currentIndex = -1;// 当前index,从0开始
+	private List<String> keys;// 字段名集
+
+	public SqlRowList() {
+		this.resultList = new ArrayList<Map<String, Object>>();
+	}
+
+	public List<Map<String, Object>> getResultList() {
+		return resultList;
+	}
+
+	public int size() {
+		return getResultList().size();
+	}
+
+	public void setResultList(List<Map<String, Object>> resultList) {
+		this.resultList = resultList;
+	}
+
+	public Map<String, Object> getCurrentMap() {
+		return currentMap;
+	}
+
+	public void setCurrentMap(Map<String, Object> currentMap) {
+		this.currentMap = currentMap;
+	}
+
+	public int getCurrentIndex() {
+		return currentIndex;
+	}
+
+	public void setCurrentIndex(int currentIndex) {
+		this.currentIndex = currentIndex;
+	}
+
+	public List<String> getKeys() {
+		if (this.keys == null) {
+			this.keys = new ArrayList<String>();
+			if (this.resultList != null) {
+				Iterator<Map<String, Object>> iterator = resultList.iterator();
+				if (iterator.hasNext()) {
+					Map<String, Object> map = iterator.next();
+					Iterator<String> fields = map.keySet().iterator();
+					while (fields.hasNext()) {
+						this.keys.add(fields.next());
+					}
+				}
+			}
+		}
+		return keys;
+	}
+
+	public void setKeys(List<String> keys) {
+		this.keys = keys;
+	}
+
+	/**
+	 * 取ResultSet的第index条Map
+	 * 
+	 * @param index
+	 * @return
+	 */
+	public Map<String, Object> getAt(int index) {
+		if (this.resultList != null) {
+			Iterator<Map<String, Object>> iterator = resultList.iterator();
+			Map<String, Object> map = null;
+			int idx = 0;
+			while (iterator.hasNext() && (map = iterator.next()) != null) {
+				if (index == idx)
+					return map;
+				idx++;
+			}
+		}
+		return null;
+	}
+
+	public <T> List<T> queryForList(String field, Class<T> requiredType) {
+		if (this.resultList != null) {
+			Iterator<Map<String, Object>> iterator = resultList.iterator();
+			Map<String, Object> map = null;
+			List<T> list = new ArrayList<T>();
+			RowConvert<T> convert = new RowConvert<T>(requiredType);
+			field = field.toUpperCase();
+			while (iterator.hasNext() && (map = iterator.next()) != null) {
+				Object result = map.get(field);
+				if (result != null) {
+					list.add(convert.convert(result));
+				}
+			}
+			return list;
+		}
+		return null;
+	}
+
+	public <T> Set<T> queryForSet(String field, Class<T> requiredType) {
+		if (this.resultList != null) {
+			Iterator<Map<String, Object>> iterator = resultList.iterator();
+			Map<String, Object> map = null;
+			Set<T> set = new java.util.HashSet<T>();
+			RowConvert<T> convert = new RowConvert<T>(requiredType);
+			field = field.toUpperCase();
+			while (iterator.hasNext() && (map = iterator.next()) != null) {
+				Object result = map.get(field);
+				if (result != null) {
+					set.add(convert.convert(result));
+				}
+			}
+			return set;
+		}
+		return null;
+	}
+
+	public boolean hasNext() {
+		if (this.resultList != null) {
+			if (this.iterator == null) {
+				this.iterator = resultList.iterator();
+			}
+			if (this.iterator.hasNext()) {
+				return true;
+			}
+		}
+		return false;
+	}
+
+	public boolean next(int count) {
+		for (int i = 0; i < count; i++) {
+			if (!next())
+				return false;
+		}
+		return true;
+	}
+
+	public boolean next() {
+		if (this.resultList != null) {
+			if (this.iterator == null) {
+				this.iterator = resultList.iterator();
+				this.currentIndex = -1;
+			}
+			if (this.iterator.hasNext()) {
+				this.currentMap = iterator.next();
+				this.currentIndex += 1;
+				if (this.keys == null) {
+					this.keys = new ArrayList<String>();
+					Iterator<String> fields = currentMap.keySet().iterator();
+					while (fields.hasNext()) {
+						this.keys.add(fields.next());
+					}
+				}
+				return true;
+			}
+		}
+		return false;
+	}
+
+	public int getInt(int index) {
+		Object obj = getObject(index);
+		return obj == null ? -1 : Integer.parseInt(obj.toString());
+	}
+
+	public int getInt(String field) {
+		Object obj = getObject(field);
+		return obj == null ? -1 : Integer.parseInt(obj.toString());
+	}
+
+	public int getGeneralInt(int index) {
+		Object obj = getObject(index);
+		return obj == null ? 0 : Integer.parseInt(obj.toString());
+	}
+
+	public int getGeneralInt(String field) {
+		Object obj = getObject(field);
+		return obj == null ? 0 : Integer.parseInt(obj.toString());
+	}
+
+	public float getFloat(int index) {
+		Object obj = getObject(index);
+		return obj == null ? -1 : Float.parseFloat(obj.toString());
+	}
+
+	public float getFloat(String field) {
+		Object obj = getObject(field);
+		return obj == null ? -1 : Float.parseFloat(obj.toString());
+	}
+
+	public float getGeneralFloat(int index) {
+		Object obj = getObject(index);
+		return obj == null ? 0 : Float.parseFloat(obj.toString());
+	}
+
+	public float getGeneralFloat(String field) {
+		Object obj = getObject(field);
+		return obj == null ? 0 : Float.parseFloat(obj.toString());
+	}
+
+	public double getDouble(int index) {
+		Object obj = getObject(index);
+		return obj == null ? -1 : Double.parseDouble(obj.toString());
+	}
+
+	public double getDouble(String field) {
+		Object obj = getObject(field);
+		return obj == null ? -1 : Double.parseDouble(obj.toString());
+	}
+
+	public BigDecimal getBigDecimal(int index) {
+		Object obj = getObject(index);
+		return obj == null ? null : BigDecimal.valueOf(Double.parseDouble(obj.toString()));
+	}
+
+	public BigDecimal getBigDecimal(String field) {
+		Object obj = getObject(field);
+		return obj == null ? null : BigDecimal.valueOf(Double.parseDouble(obj.toString()));
+	}
+
+	public double getGeneralDouble(int index) {
+		Object obj = getObject(index);
+		return obj == null ? 0 : Double.parseDouble(obj.toString());
+	}
+
+	/**
+	 * @param index
+	 * @param sub
+	 *            保留小数位数
+	 * @return
+	 */
+	public double getGeneralDouble(int index, int sub) {
+		return NumberUtil.formatDouble(getGeneralDouble(index), sub);
+	}
+
+	public double getGeneralDouble(String field) {
+		Object obj = getObject(field);
+		return obj == null || String.valueOf(obj).trim().equals("") ? 0 : Double.parseDouble(String.valueOf(obj).trim());
+	}
+
+	/**
+	 * @param field
+	 * @param sub
+	 *            保留小数位数
+	 * @return
+	 */
+	public double getGeneralDouble(String field, int sub) {
+		return NumberUtil.formatDouble(getGeneralDouble(field), sub);
+	}
+
+	public BigDecimal getGeneralBigDecimal(int index) {
+		Object obj = getObject(index);
+		return obj == null ? new BigDecimal(0) : BigDecimal.valueOf(Double.parseDouble(obj.toString()));
+	}
+
+	public BigDecimal getGeneralBigDecimal(String field) {
+		Object obj = getObject(field);
+		return obj == null ? new BigDecimal(0) : BigDecimal.valueOf(Double.parseDouble(obj.toString()));
+	}
+
+	public long getLong(int index) {
+		Object obj = getObject(index);
+		return obj == null ? -1 : Long.parseLong(obj.toString());
+	}
+
+	public long getLong(String field) {
+		Object obj = getObject(field);
+		return obj == null ? -1 : Long.parseLong(obj.toString());
+	}
+
+	public long getGeneralLong(int index) {
+		Object obj = getObject(index);
+		return obj == null ? 0 : Long.parseLong(obj.toString());
+	}
+
+	public long getGeneralLong(String field) {
+		Object obj = getObject(field);
+		return obj == null ? 0 : Long.parseLong(obj.toString());
+	}
+
+	public String getString(int index) {
+		Object obj = getObject(index);
+		return obj == null ? null : obj.toString();
+	}
+
+	public String getString(String field) {
+		Object obj = getObject(field);
+		return obj == null ? null : obj.toString();
+	}
+
+	public String getGeneralString(int index) {
+		Object obj = getObject(index);
+		return obj == null ? "" : obj.toString();
+	}
+
+	public String getGeneralString(String field) {
+		Object obj = getObject(field);
+		return obj == null ? "" : obj.toString();
+	}
+
+	public Object getObject(int index) {
+		if (this.iterator == null || this.currentMap == null || this.keys == null || index <= 0 || index > this.keys.size()) {
+			return null;
+		}
+		return this.currentMap.get(this.keys.get(index - 1));
+	}
+
+	public Object getObject(String field) {
+		if (this.iterator == null || this.currentMap == null) {
+			return null;
+		}
+		return this.currentMap.get(field.toUpperCase());
+	}
+
+	/**
+	 * currentMap的JSON格式
+	 */
+	public JSONObject getJSONObject() {
+		if (this.iterator == null || this.currentMap == null) {
+			return null;
+		}
+		JSONObject json = new JSONObject();
+		Object value = null;
+		for (String k : this.keys) {
+			value = parseValue(this.getObject(k));
+			json.put(k, value);
+		}
+		return json;
+	}
+
+	public static Object parseValue(Object value) {
+		if (value != null) {
+			// 以字符串格式表示时间
+			if ("TIMESTAMP".equals(value.getClass().getSimpleName().toUpperCase())) {
+				Timestamp time = (Timestamp) value;
+				value = DateUtil.parseDateToString(new Date(time.getTime()), Constant.YMD_HMS);
+			}
+			// 科学计数法改为js处理
+		}
+		return value;
+	}
+
+	/**
+	 * currentMap的JSONString格式
+	 */
+	public String getJSON() {
+		if (this.iterator == null || this.currentMap == null) {
+			return null;
+		}
+		return getJSONObject().toString();
+	}
+
+	public Date getDate(int index) {
+		Object obj = getObject(index);
+		return obj == null ? null : (Date) obj;
+	}
+
+	public Date getDate(String field) {
+		Object obj = getObject(field);
+		return obj == null ? null : (Date) obj;
+	}
+
+	public Timestamp getTimestamp(int index) {
+		Object obj = getObject(index);
+		return obj == null ? null : (Timestamp) obj;
+	}
+
+	public Timestamp getTimestamp(String field) {
+		Object obj = getObject(field);
+		return obj == null ? null : (Timestamp) obj;
+	}
+
+	public String getGeneralTimestamp(int index, String format) {
+		Timestamp time = getTimestamp(index);
+		if (time != null)
+			return DateUtil.parseDateToString(new Date(time.getTime()), format);
+		return "";
+	}
+
+	public String getGeneralTimestamp(int index) {
+		return getGeneralTimestamp(index, Constant.YMD_HMS);
+	}
+
+	public String getGeneralTimestamp(String field, String format) {
+		Timestamp time = getTimestamp(field);
+		if (time != null)
+			return DateUtil.parseDateToString(new Date(time.getTime()), format);
+		return "";
+	}
+
+	public String getGeneralTimestamp(String field) {
+		return getGeneralTimestamp(field, Constant.YMD_HMS);
+	}
+
+	public double getSummary(String field) {
+		if (hasNext()) {
+			Iterator<Map<String, Object>> iterator = resultList.iterator();
+			Map<String, Object> map = null;
+			double sum = 0;
+			Object obj = null;
+			while ((map = iterator.next()) != null) {
+				obj = map.get(field.toUpperCase());
+				sum += obj == null ? 0 : Double.parseDouble(obj.toString());
+			}
+			return sum;
+		}
+		return 0;
+	}
+
+	public double getSummary(int index) {
+		if (index <= 0 || index > this.getKeys().size()) {
+			return 0;
+		}
+		return getSummary(this.keys.get(index - 1));
+	}
+}

+ 1 - 88
src/main/java/com/uas/eis/exception/ExceptionHandlerAdvice.java

@@ -1,15 +1,9 @@
 package com.uas.eis.exception;
 
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.sql.SQLRecoverableException;
-
 import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpSession;
 
 import org.apache.log4j.Logger;
 import org.springframework.http.HttpStatus;
-import org.springframework.jdbc.BadSqlGrammarException;
 import org.springframework.ui.ModelMap;
 import org.springframework.web.bind.annotation.ControllerAdvice;
 import org.springframework.web.bind.annotation.ExceptionHandler;
@@ -32,90 +26,9 @@ public class ExceptionHandlerAdvice {
 	@ResponseBody
 	public ModelMap handleUnexpectedServerError(RuntimeException ex, HttpServletRequest request) {
 		ModelMap map = new ModelMap();
-		if (!"ERR_NETWORK_SESSIONOUT".equals(ex.getMessage())) {
-			logger.error(ex);
-			ex.printStackTrace();
-			map.put("exceptionInfo", getErrorStack(request, ex, "程序错误"));
-		} else {
-			map.put("exceptionInfo", ex.getMessage());
-		}
+		map.put("exceptionInfo", ex.getMessage());
 		return map;
 	}
 	
 	
-	/**
-	 * 处理连接池的连接失效抛出异常
-	 * 
-	 * @see SQLRecoverableException
-	 * @param ex
-	 * @return
-	 */
-	@ExceptionHandler(SQLRecoverableException.class)
-	@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
-	@ResponseBody
-	public ModelMap handleSQLRecoverableExceptionError(SQLRecoverableException ex, HttpServletRequest request) {
-		ModelMap map = new ModelMap();
-		map.put("exceptionInfo", getErrorStack(request, ex, "连接异常"));
-		return map;
-	}
-	
-	/**
-	 * 处理参数错误抛出异常
-	 * 
-	 * @see IllegalArgumentException
-	 * @param ex
-	 * @return
-	 */
-	@ExceptionHandler(IllegalArgumentException.class)
-	@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
-	@ResponseBody
-	public ModelMap handleIllegalArgumentExceptionError(IllegalArgumentException ex, HttpServletRequest request) {
-		logger.error(ex.getCause());
-		ex.printStackTrace();
-		ModelMap map = new ModelMap();
-		map.put("exceptionInfo", getErrorStack(request, ex, "参数错误"));
-		return map;
-	}
-	
-	/**
-	 * SQL语法错误
-	 * 
-	 * @param ex
-	 * @return
-	 */
-	@ExceptionHandler(BadSqlGrammarException.class)
-	@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
-	@ResponseBody
-	public ModelMap handleBadSqlGrammarExceptionError(BadSqlGrammarException ex, HttpServletRequest request) {
-		logger.error(ex);
-		ModelMap map = new ModelMap();
-		ex.printStackTrace();
-		map.put("exceptionInfo", getErrorStack(request, ex, "程序错误"));
-		return map;
-	}
-	
-	/**
-	 * 封装错误信息,按用户设置是否显示栈信息
-	 * 
-	 * @param e
-	 * @param defaultText
-	 * @return
-	 */
-	private String getErrorStack(HttpServletRequest request, Exception e, String defaultText) {
-		HttpSession session = request.getSession(false);
-		if (session != null) {
-			Object debug = session.getAttribute("user.setting.debug");
-			if (debug != null && Boolean.valueOf(debug.toString())) {
-				StringWriter writer = new StringWriter();
-				e.printStackTrace(new PrintWriter(writer));
-				return "<div class=\"error-container\">"
-						+ "<a class=\"error-toggle\" onclick=\"document.getElementById('_error_stack').style.display='block';\">"
-						+ defaultText + "</a>" + "<div id=\"_error_stack\" class=\"error-body\" style=\"display:none;\">"
-						+ writer.toString() + "</div>" + "</div>";
-			}
-		}
-		return defaultText;
-	}
-	
-	
 }

+ 31 - 0
src/main/java/com/uas/eis/exception/SystemException.java

@@ -0,0 +1,31 @@
+package com.uas.eis.exception;
+
+/**
+ * 系统程序执行异常
+ * 
+ * @author yingp
+ * 
+ */
+public class SystemException extends RuntimeException {
+
+	/**
+	 * 
+	 */
+	private static final long serialVersionUID = 4218425517031998401L;
+
+	public SystemException() {
+	}
+
+	public SystemException(String paramString) {
+		super(paramString);
+	}
+
+	public SystemException(String paramString, Throwable paramThrowable) {
+		super(paramString, paramThrowable);
+	}
+
+	public SystemException(Throwable paramThrowable) {
+		super(paramThrowable);
+	}
+
+}

+ 82 - 0
src/main/java/com/uas/eis/utils/BaseUtil.java

@@ -0,0 +1,82 @@
+package com.uas.eis.utils;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import com.alibaba.fastjson.JSONObject;
+import com.uas.eis.exception.SystemException;
+
+
+public class BaseUtil {
+
+	
+	
+	/**
+	 * 以抛出异常的方式将信息交给MyExceptionHandler MyExceptionHandler会捕捉信息并传给前台
+	 * 前台捕捉错误信息,并显示给用户
+	 * 
+	 * @param error
+	 *            要在前台显示的信息
+	 */
+	public static void showError(String error) {
+		if (error != null && error.length() > 0)
+			throw new SystemException(error);
+	}
+	
+	/**
+	 * List集合转化成字符串, null和空字符自动去掉
+	 * 
+	 * @param list
+	 *            待转化集合
+	 * @param ch
+	 *            分割符
+	 * @param repeat
+	 *            是否去重 {true-是、false-否}
+	 */
+	public static String parseList2Str(List<?> list, String ch, boolean repeat) {
+		StringBuffer sb = new StringBuffer();
+		for (Object s : list) {
+			if (s != null && !s.toString().trim().equals("")) {
+				if (repeat) {
+					if (!sb.toString().contains(s + ch)) {
+						sb.append(s);
+						sb.append(ch);
+					}
+				} else {
+					sb.append(s);
+					sb.append(ch);
+				}
+			}
+		}
+		if (sb.length() > 0 && ch.length() > 0) {
+			return sb.substring(0, sb.lastIndexOf(ch));
+		}
+		return sb.toString();
+	}
+	
+	
+	/**
+	 * 数据转换,将传入的数据转成需要调用接口规定的数据格式
+	 * @param jsonStr	传入的数据
+	 * @param keyMap	UAS与外部系统的键 映射
+	 * @return
+	 */
+	public static Map<String, Object> JsonToMap(String jsonStr, Map<String, String> keyMap){
+		Map<String, Object> map = new HashMap<String, Object>();
+		Map<String, Object> jsonMap = JSONObject.parseObject(jsonStr);
+		Set<String> set = jsonMap.keySet();
+		Iterator<String> it = set.iterator();
+		while(it.hasNext()){
+			String key = it.next();
+			if(keyMap.containsKey(key)){
+				map.put(keyMap.get(key), jsonMap.get(key));
+			}
+		}
+		return map;
+	}
+	
+	
+}

+ 122 - 0
src/main/java/com/uas/eis/utils/Constant.java

@@ -0,0 +1,122 @@
+package com.uas.eis.utils;
+
+/**
+ * 系统常量
+ * 
+ * @author yingp
+ * 
+ */
+public class Constant {
+
+	// 日期格式
+
+	public final static String YM = "yyyy-MM";
+
+	public final static String ym = "yyyyMM";
+
+	public final static String YMD = "yyyy-MM-dd";
+
+	public final static String YMD_HM = "yyyy-MM-dd HH:mm";
+
+	public final static String YMD_HMS = "yyyy-MM-dd HH:mm:ss";
+
+	public final static String ORACLE_YMD = "yyyy-MM-dd";
+
+	public final static String ORACLE_YMD_HMS = "yyyy-MM-dd HH24:mi:ss";
+
+	public static final String REGEXP_MOBILE = "^[1|8][3-8]\\d{9}$|^([6|9])\\d{7}$|^[0][9]\\d{8}$|^[6]([8|6])\\d{5}$|^(886|0)[9]\\d{8}$";
+
+	public static final String REGEXP_EMAIL = "^([\\w-])+(\\.\\w+)*@([\\w-])+((\\.\\w{2,3}){1,3})$";
+
+	/**
+	 * 求和
+	 * */
+	public final static String SUMMARY_SUM = "sum";
+
+	/**
+	 * 最大值
+	 * */
+	public final static String SUMMARY_MAX = "max";
+	/**
+	 * 最小值
+	 * */
+	public final static String SUMMARY_MIN = "min";
+	/**
+	 * 平均值
+	 * */
+	public final static String SUMMARY_AVERAGE = "average";
+
+	/**
+	 * 是
+	 */
+	public static final short YES = 1;
+	/**
+	 * 是
+	 */
+	public static final short yes = -1;
+	/**
+	 * 是
+	 */
+	public static final String TRUE = "T";
+	/**
+	 * 否
+	 */
+	public static final short NO = 0;
+	/**
+	 * 否
+	 */
+	public static final String FALSE = "F";
+
+	public static final int ORACLE_MAX_TABLE_SIZE = 999;
+
+	/**
+	 * 优软云
+	 * */
+	public static final String UAS_CLOUD = "CLOUD";
+
+	/**
+	 * 类型--"是否"字段
+	 */
+	public static final String TYPE_YN = "yn";
+
+	/**
+	 * 类型--"下拉框"
+	 */
+	public static final String TYPE_COMBO = "combo";
+
+	/**
+	 * 正则表达式:数字
+	 */
+	public static final String REG_NUM = "^-?[0-9]+(.[0-9]+)?";
+
+	/**
+	 * 正则表达式:日期
+	 */
+	public static final String REG_DATE = "\\d{2,4}-\\d{1,2}-\\d{1,2}";
+
+	/**
+	 * 正则表达式:时间
+	 */
+	public static final String REG_DATETIME = "\\d{2,4}-\\d{1,2}-\\d{1,2} \\d{1,2}:\\d{1,2}:\\d{1,2}";
+
+	/**
+	 * excel导出阈值
+	 */
+	public static final int EXCEL_LG_SIZE = 5000;
+
+	/**
+	 * excel导出最大条数
+	 */
+	public static final int EXCEL_MAX_SIZE = 100000;
+
+	/**
+	 * 正则表达式:ipv4
+	 */
+	public static final String REG_IPV4 = "((?:(?:25[0-5]|2[0-4]\\d|((1\\d{2})|([1-9]?\\d)))\\.){3}(?:25[0-5]|2[0-4]\\d|((1\\d{2})|([1-9]?\\d))))";
+	
+	/**
+	 * 临时表名称
+	 */
+	public static final String TEMP_TABLE_NAME = "TEMP_TABLE";
+
+}

+ 82 - 0
src/main/java/com/uas/eis/utils/ContextUtil.java

@@ -0,0 +1,82 @@
+package com.uas.eis.utils;
+
+import org.springframework.beans.BeansException;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationEvent;
+
+public class ContextUtil {
+	private static ApplicationContext applicationContext;
+	public static void setApplicationContext(ApplicationContext applicationContext) {
+		synchronized (ContextUtil.class) {
+			ContextUtil.applicationContext = applicationContext;
+			ContextUtil.class.notifyAll();
+		}
+	}
+
+	public static ApplicationContext getApplicationContext() {
+		synchronized (ContextUtil.class) {
+			while (applicationContext == null) {
+				try {
+					ContextUtil.class.wait(6000);
+				} catch (InterruptedException ex) {
+				}
+			}
+			return applicationContext;
+		}
+	}
+
+	/**
+	 * 获取bean
+	 * 
+	 * @param name
+	 * @return
+	 */
+	public static Object getBean(String name) {
+		try {
+			return getApplicationContext().getBean(name);
+		} catch (Exception e) {
+			return null;
+		}
+		
+	}
+
+	/**
+	 * 获取bean
+	 * 
+	 * @param cls
+	 * @return
+	 */
+	public static <T> T getBean(Class<T> cls) {
+		return getApplicationContext().getBean(cls);
+	}
+
+	/**
+	 * 动态注册bean
+	 * 
+	 * @param beanName
+	 *            bean组件名称
+	 * @param className
+	 *            类名
+	 */
+	public static void registerBean(String beanName, String className) {
+		try {
+			getApplicationContext().getAutowireCapableBeanFactory().createBean(Class.forName(className));
+		} catch (BeansException e) {
+			BaseUtil.showError("组件注册失败");
+		} catch (IllegalStateException e) {
+			BaseUtil.showError("组件注册失败");
+		} catch (ClassNotFoundException e) {
+			BaseUtil.showError("组件注册失败");
+		}
+	}
+
+	/**
+	 * 触发事件
+	 * 
+	 * @param event
+	 */
+	public static void publishEvent(ApplicationEvent event) {
+		getApplicationContext().publishEvent(event);
+	}
+
+}

+ 570 - 0
src/main/java/com/uas/eis/utils/DateUtil.java

@@ -0,0 +1,570 @@
+package com.uas.eis.utils;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.GregorianCalendar;
+import java.util.List;
+
+public class DateUtil {
+	static final SimpleDateFormat ym = new SimpleDateFormat("yyyyMM");
+	static final SimpleDateFormat YM = new SimpleDateFormat("yyyy-MM");
+	static final SimpleDateFormat YMD = new SimpleDateFormat("yyyy-MM-dd");
+	static final SimpleDateFormat YMD_HMS = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+
+	public static String format(Date date, String f) {
+		if (date == null) {
+			date = new Date();
+		}
+		if (f == null) {
+			return YMD.format(date);
+		}
+		SimpleDateFormat sdf = new SimpleDateFormat(f);
+		return sdf.format(date);
+	}
+
+	public static String format(java.sql.Date date, String f) {
+		if (date == null) {
+			return currentDateString(f);
+		} else {
+			if (f == null) {
+				return YMD.format(date);
+			}
+			SimpleDateFormat sdf = new SimpleDateFormat(f);
+			return sdf.format(date);
+		}
+	}
+
+	public static Date parse(String date, String f) {
+		if (date == null) {
+			return new Date();
+		}
+		if (f == null) {
+			try {
+				return date.contains(" ") ? YMD_HMS.parse(date) : YMD.parse(date);
+			} catch (ParseException e) {
+				return new Date();
+			}
+		}
+		SimpleDateFormat sdf = new SimpleDateFormat(f);
+		try {
+			return sdf.parse(date);
+		} catch (ParseException e) {
+			return new Date();
+		}
+	}
+
+	/**
+	 * 获取日期年份
+	 * 
+	 * @param date
+	 * @return
+	 * @throws ParseException
+	 */
+	public static int getYear(String date) throws ParseException {
+		date = date == null ? format(null, null) : date;
+		Calendar calendar = Calendar.getInstance();
+		calendar.setTime(YMD.parse(date));
+		return calendar.get(Calendar.YEAR);
+	}
+
+	/**
+	 * 获取日期年份
+	 * 
+	 * @param date
+	 * @return
+	 * @throws ParseException
+	 */
+	public static int getYear(Date date) throws ParseException {
+		date = date == null ? parse(null, null) : date;
+		Calendar calendar = Calendar.getInstance();
+		calendar.setTime(date);
+		return calendar.get(Calendar.YEAR);
+	}
+
+	/**
+	 * 获取日期月份
+	 * 
+	 * @param date
+	 * @return
+	 * @throws ParseException
+	 */
+	public static int getMonth(String date) throws ParseException {
+		date = date == null ? format(null, null) : date;
+		Calendar calendar = Calendar.getInstance();
+		calendar.setTime(YMD.parse(date));
+		return (calendar.get(Calendar.MONTH) + 1);
+	}
+
+	/**
+	 * 获取日期月份
+	 * 
+	 * @param date
+	 * @return
+	 * @throws ParseException
+	 */
+	public static int getMonth(Date date) throws ParseException {
+		date = date == null ? parse(null, null) : date;
+		Calendar calendar = Calendar.getInstance();
+		calendar.setTime(date);
+		return (calendar.get(Calendar.MONTH) + 1);
+	}
+
+	/**
+	 * 获取日期号
+	 * 
+	 * @param date
+	 * @return
+	 * @throws ParseException
+	 */
+	public static int getDay(String date) throws ParseException {
+		date = date == null ? format(null, null) : date;
+		Calendar calendar = Calendar.getInstance();
+		calendar.setTime(YMD.parse(date));
+		return calendar.get(Calendar.DAY_OF_MONTH);
+	}
+
+	/**
+	 * 获取日期号
+	 * 
+	 * @param date
+	 * @return
+	 * @throws ParseException
+	 */
+	public static int getDay(Date date) throws ParseException {
+		date = date == null ? parse(null, null) : date;
+		Calendar calendar = Calendar.getInstance();
+		calendar.setTime(date);
+		return calendar.get(Calendar.DAY_OF_MONTH);
+	}
+
+	/**
+	 * 获取日期前一年日期
+	 * 
+	 * @param date
+	 * @return
+	 * @throws ParseException
+	 */
+	public static String getLastYearDay(String date) throws ParseException {
+		date = date == null ? format(null, null) : date;
+		Calendar calendar = Calendar.getInstance();
+		try {
+			calendar.setTime(YMD.parse(date));
+		} catch (ParseException e) {
+			calendar.setTime(new Date());
+		}
+		calendar.set(Calendar.YEAR, calendar.get(Calendar.YEAR) - 1);
+		return YMD.format(calendar.getTime());
+
+	}
+
+	/**
+	 * 获取月份起始日期
+	 * 
+	 * @param date
+	 * @return
+	 * @throws ParseException
+	 */
+	public static String getMinMonthDate(String date) {
+		date = date == null ? format(null, null) : date;
+		Calendar calendar = Calendar.getInstance();
+		try {
+			calendar.setTime(YMD.parse(date));
+		} catch (ParseException e) {
+			calendar.setTime(new Date());
+		}
+		calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMinimum(Calendar.DAY_OF_MONTH));
+		return YMD.format(calendar.getTime());
+	}
+
+	/**
+	 * 获取月份起始日期
+	 * 
+	 * @param date
+	 * @return
+	 * @throws ParseException
+	 */
+	public static String getMinMonthDate(Date date) {
+		date = date == null ? parse(null, null) : date;
+		Calendar calendar = Calendar.getInstance();
+		calendar.setTime(date);
+		calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMinimum(Calendar.DAY_OF_MONTH));
+		return YMD.format(calendar.getTime());
+	}
+
+	/**
+	 * 获取月份最后日期
+	 * 
+	 * @param date
+	 * @return
+	 * @throws ParseException
+	 */
+	public static String getMaxMonthDate(String date) {
+		date = date == null ? format(null, null) : date;
+		Calendar calendar = Calendar.getInstance();
+		try {
+			calendar.setTime(YMD.parse(date));
+		} catch (ParseException e) {
+			calendar.setTime(new Date());
+		}
+		calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
+		return YMD.format(calendar.getTime());
+	}
+
+	/**
+	 * 获取月份最后日期
+	 * 
+	 * @param date
+	 * @return
+	 * @throws ParseException
+	 */
+	public static String getMaxMonthDate(Date date) {
+		date = date == null ? parse(null, null) : date;
+		Calendar calendar = Calendar.getInstance();
+		calendar.setTime(date);
+		calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
+		return YMD.format(calendar.getTime());
+	}
+
+	/**
+	 * 当前时间
+	 * 
+	 * @return <h3>String</h3>
+	 */
+	public static String getCurrentDate() {
+		return format(new Date(), null);
+	}
+
+	/**
+	 * 截取指定日期的年月
+	 * 
+	 * @param date
+	 * @return
+	 */
+	public static Integer getYearmonth(Date date) {
+		if (date == null) {
+			date = new Date();
+		}
+		return Integer.parseInt(ym.format(date));
+	}
+
+	/**
+	 * 截取指定日期的年月
+	 * 
+	 * @param date
+	 * @return
+	 */
+	public static Integer getYearmonth(String date) {
+		return Integer.parseInt(ym.format(parse(date, null)));
+	}
+
+	/**
+	 * 获取当前年月
+	 * 
+	 * @return
+	 */
+	public static Integer getYearmonth() {
+		return Integer.parseInt(ym.format(new Date()));
+	}
+
+	public static int compare(String date1, String date2) {
+		try {
+			Date dt1 = YMD.parse(date1);
+			Date dt2 = YMD.parse(date2);
+			if (dt1.getTime() > dt2.getTime()) {
+				return 1;
+			} else if (dt1.getTime() < dt2.getTime()) {
+				return -1;
+			} else {
+				return 0;
+			}
+		} catch (Exception exception) {
+			exception.printStackTrace();
+		}
+		return 0;
+	}
+
+	/**
+	 * 获取特定日期是星期几
+	 * 
+	 * @return
+	 */
+	public static String getWeekDay(String DateStr) {
+		SimpleDateFormat formatYMD = new SimpleDateFormat("yyyy-MM-dd");// formatYMD表示的是yyyy-MM-dd格式
+		SimpleDateFormat formatD = new SimpleDateFormat("E");// "E"表示"day in week"
+		Date d = null;
+		String weekDay = "";
+		try {
+			d = formatYMD.parse(DateStr);// 将String 转换为符合格式的日期
+			weekDay = formatD.format(d);
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+		// System.out.println("日期:"+DateStr+" : "+weekDay);
+		return weekDay;
+	}
+
+	public static int getWeekDay1(String DateStr) {// 返回日期对应数字
+		SimpleDateFormat formatYMD = new SimpleDateFormat("yyyy-MM-dd");// formatYMD表示的是yyyy-MM-dd格式
+		Date d = null;
+		int weekDay = 0;
+		try {
+			d = formatYMD.parse(DateStr);// 将String 转换为符合格式的日期
+			Calendar calendar = Calendar.getInstance();
+			calendar.setTime(d);
+			weekDay = calendar.get(Calendar.DAY_OF_WEEK) - 1;
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+		return weekDay;
+	}
+
+	/**
+	 * 获取特定时间段内有哪几日
+	 * 
+	 * @return
+	 */
+	public static List<Object> findDates(String start_time, String end_time) throws ParseException {
+		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
+		Date date1 = df.parse(start_time);
+		Date date2 = df.parse(end_time);
+		int s = (int) ((date2.getTime() - date1.getTime()) / (24 * 60 * 60 * 1000));
+		List<Object> objects = new ArrayList<Object>();
+		String value = "";
+		if (s + 1 > 0) {
+			for (int i = 0; i <= s; i++) {
+				long todayDate = date1.getTime() + (long) i * 24 * 60 * 60 * 1000;
+				Date tmDate = new Date(todayDate);
+				value = new SimpleDateFormat("yyyy-MM-dd").format(tmDate);
+				objects.add(value);
+			}
+		}
+		return objects;
+	}
+
+	/**
+	 * 获取特定时间段内有多少天
+	 * 
+	 * @return
+	 */
+	public static int countDates(String start_time, String end_time) throws ParseException {
+		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
+		Date date1 = df.parse(start_time);
+		Date date2 = df.parse(end_time);
+		int s = (int) ((date2.getTime() - date1.getTime()) / (24 * 60 * 60 * 1000));
+		return s;
+	}
+
+	/**
+	 * 日期转化成oracle格式to_date('2012-12-12', 'yyyy-MM-dd')
+	 * 
+	 * @param format
+	 *            format type,for example: 'yyyy-MM-dd', 'yyyy-MM-dd HH:mm:ss'
+	 * @param date
+	 *            date{type=java.util.Date}
+	 */
+	public static String parseDateToOracleString(String format, Date date) {
+		if (format == null) {
+			format = Constant.YMD;
+		}
+		SimpleDateFormat sdf = new SimpleDateFormat(format);
+		if (date == null) {
+			date = new Date();
+		}
+		if (Constant.YMD_HMS.toUpperCase().equals(format.toUpperCase())) {
+			format = Constant.ORACLE_YMD_HMS;
+		} else {
+			format = Constant.ORACLE_YMD;
+		}
+		return "to_date('" + sdf.format(date) + "','" + format + "')";
+	}
+
+	/**
+	 * 日期转化成oracle格式to_date('2012-12-12', 'yyyy-MM-dd')
+	 * 
+	 * @param format
+	 *            format type,for example: 'yyyy-MM-dd', 'yyyy-MM-dd HH:mm:ss'
+	 * @param dateString
+	 *            date{type=string}
+	 */
+	public static String parseDateToOracleString(String format, String dateString) {
+		if (format == null) {
+			format = Constant.YMD;
+		}
+		if (dateString == null || "".equals(dateString) || "null".equals(dateString)) {
+			SimpleDateFormat sdf = new SimpleDateFormat(format);
+			dateString = sdf.format(new Date());
+		}
+		if (Constant.YMD_HMS.toUpperCase().equals(format.toUpperCase())) {
+			format = Constant.ORACLE_YMD_HMS;
+		} else {
+			format = Constant.ORACLE_YMD;
+		}
+		return "to_date('" + dateString + "','" + format + "')";
+	}
+
+	/**
+	 * Date转化成字符串格式
+	 * 
+	 * @param f
+	 *            format格式;若为空,则默认为yyyy-MM-dd
+	 */
+	public static String parseDateToString(Date date, String f) {
+		if (f == null) {
+			f = Constant.YMD;
+		}
+		SimpleDateFormat sdf = new SimpleDateFormat(f);
+		if (date == null) {
+			date = new Date();
+		}
+		return sdf.format(date);
+	}
+
+	/**
+	 * 形如{2012-12-21}或{2012-12-21 12:12:12}字符串格式的日期转化成java.util.Date类型
+	 * 
+	 * @param date
+	 *            string日期;若为空或格式错误,则返回当前时间
+	 * @param f
+	 *            format格式;若为空,则默认为yyyy-MM-dd
+	 * @return java.util.Date类型日期
+	 */
+	public static Date parseStringToDate(String date, String f) {
+		if (f == null) {
+			f = Constant.YMD;
+		}
+		SimpleDateFormat sdf = new SimpleDateFormat(f);
+		if (date == null) {
+			return new Date();
+		}
+		try {
+			return sdf.parse(date);
+		} catch (ParseException e) {
+			return new Date();
+		}
+	}
+
+	/**
+	 * 当前时间的字符串格式
+	 * 
+	 * @param f
+	 *            format格式;若为空,则默认为yyyy-MM-dd
+	 */
+	public static String currentDateString(String f) {
+		if (f == null) {
+			f = Constant.YMD;
+		}
+		SimpleDateFormat sdf = new SimpleDateFormat(f);
+		return sdf.format(new Date());
+	}
+
+	/**
+	 * 借贷合同月份处理
+	 */
+	public static int getMonthSpace(Date date1, Date date2) throws ParseException {
+		int iMonth = 0;
+		int flag = 0;
+		try {
+			Calendar objCalendarDate1 = Calendar.getInstance();
+			objCalendarDate1.setTime(date1);
+
+			Calendar objCalendarDate2 = Calendar.getInstance();
+			objCalendarDate2.setTime(date2);
+
+			if (objCalendarDate2.equals(objCalendarDate1))
+				return 0;
+			if (objCalendarDate1.after(objCalendarDate2)) {
+				Calendar temp = objCalendarDate1;
+				objCalendarDate1 = objCalendarDate2;
+				objCalendarDate2 = temp;
+			}
+			if (objCalendarDate2.get(Calendar.DAY_OF_MONTH) > objCalendarDate1.get(Calendar.DAY_OF_MONTH))
+				flag = 1;
+
+			if (objCalendarDate2.get(Calendar.YEAR) > objCalendarDate1.get(Calendar.YEAR)) {
+				iMonth = ((objCalendarDate2.get(Calendar.YEAR) - objCalendarDate1.get(Calendar.YEAR)) * 12
+						+ objCalendarDate2.get(Calendar.MONTH) + flag)
+						- objCalendarDate1.get(Calendar.MONTH);
+			} else {
+				iMonth = objCalendarDate2.get(Calendar.MONTH) + flag - objCalendarDate1.get(Calendar.MONTH);
+			}
+
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+		return iMonth;
+	}
+
+	/**
+	 * 月份往前或往后n天
+	 */
+	public static Date overDate(Date date, int num) {
+		date = date == null ? new Date() : date;
+		Calendar calendar = new GregorianCalendar();
+		calendar.setTime(date);
+		calendar.add(Calendar.DATE, num);
+		date = calendar.getTime();
+		return date;
+	}
+
+	/**
+	 * 月份加减
+	 * 
+	 * @param date
+	 * @param increase
+	 * @return
+	 */
+	public static Integer addMonth(Date date, int increase) {
+		if (date == null)
+			date = new Date();
+		Calendar calendar = new GregorianCalendar();
+		calendar.setTime(date);
+		calendar.add(Calendar.MONTH, increase);
+		return getYearmonth(calendar.getTime());
+	}
+
+	/**
+	 * 月份加减
+	 * 
+	 * @param month
+	 * @param increase
+	 * @return
+	 */
+	public static Integer addMonth(Integer month, int increase) {
+		Calendar calendar = new GregorianCalendar();
+		try {
+			calendar.setTime(ym.parse(String.valueOf(month)));
+		} catch (ParseException e) {
+			e.printStackTrace();
+		}
+		calendar.add(Calendar.MONTH, increase);
+		return getYearmonth(calendar.getTime());
+	}
+
+	/**
+	 * 时间添加小时数
+	 * */
+	public static Date addHours(Date date, float hours) {
+		Calendar ca = Calendar.getInstance();
+		ca.setTime(date);
+		ca.add(Calendar.MINUTE, (int) (hours * 60));
+		return ca.getTime();
+	}
+
+	/**
+	 * 判断日期是否合法
+	 */
+	public static boolean isValidDate(String dateString, String f) {
+		SimpleDateFormat sdf = new SimpleDateFormat(f);
+		sdf.setLenient(false);
+		try {
+			sdf.parse(dateString);
+		} catch (ParseException e) {
+			e.printStackTrace();
+			return false;
+		}
+		return true;
+	}
+}

+ 270 - 0
src/main/java/com/uas/eis/utils/NumberUtil.java

@@ -0,0 +1,270 @@
+package com.uas.eis.utils;
+
+import java.math.BigDecimal;
+import java.text.DecimalFormat;
+
+/**
+ * 数值处理工具
+ * 
+ * @author yingp
+ * 
+ */
+public class NumberUtil {
+
+	/**
+	 * 是否为空、0
+	 * 
+	 * @param numberObj
+	 * @return
+	 */
+	public static boolean isEmpty(Object numberObj) {
+		try {
+			return numberObj == null || "0".equals(String.valueOf(numberObj)) || Integer.parseInt(numberObj.toString()) == 0;
+		} catch (Exception e) {
+			return false;
+		}
+	}
+
+	/**
+	 * format double类型
+	 * 
+	 * @param number
+	 *            需要format的数据
+	 * @param f
+	 *            保留f位的小数
+	 * @return format之后的double类型的数据
+	 */
+	public static double formatDouble(double number, int f) {
+		if (f > 0) {
+			BigDecimal b = new BigDecimal(Double.toString(number));
+			BigDecimal one = new BigDecimal("1");
+			return b.divide(one, f, BigDecimal.ROUND_HALF_UP).doubleValue();
+		} else {
+			return Math.floor(number);
+		}
+	}
+
+	/**
+	 * format double类型
+	 * 
+	 * @param number
+	 *            需要format的数据
+	 * @param f
+	 *            保留f位的小数
+	 * @return format之后的double类型的数据
+	 */
+	public static double formatDouble(String number, int f) {
+		double n = Double.parseDouble(number);
+		if (f > 0) {
+			BigDecimal b = new BigDecimal(number);
+			BigDecimal one = new BigDecimal("1");
+			return b.divide(one, f, BigDecimal.ROUND_HALF_UP).doubleValue();
+		} else {
+			return Math.floor(n);
+		}
+	}
+
+	/**
+	 * 浮点型转成BigDecimal
+	 * 
+	 * @param number
+	 * @return
+	 */
+	public static String parseBigDecimal(double number) {
+		int scale = BigDecimal.valueOf(number).scale();
+		if (scale == -1) {
+			scale = 0;
+		}
+		return String.valueOf(BigDecimal.valueOf(number).setScale(scale, BigDecimal.ROUND_HALF_UP));
+	}
+
+	/**
+	 * 数字格式化
+	 * 
+	 * @param number
+	 * @param f
+	 * @return
+	 */
+	public static String formatNumber(Object number, int f) {
+		if ("0".equals(String.valueOf(number)))
+			return "0";
+		if (number instanceof String)
+			number = Double.parseDouble(number.toString());
+		DecimalFormat df = (DecimalFormat) DecimalFormat.getInstance();
+		df.setGroupingSize(3);
+		int len = number.toString().length();
+		if (number.toString().indexOf(".") > 0)
+			len = number.toString().indexOf(".");
+		String pattern = len > 3 ? "0,000" : "0";
+		for (int i = 0; i < f; i++) {
+			if (i == 0)
+				pattern += ".";
+			pattern += "0";
+		}
+		df.applyPattern(pattern);
+		try {
+			return df.format(number);
+		} catch (Exception e) {
+			return null;
+		}
+	}
+
+	/**
+	 * 设置小数点保留位数
+	 * */
+	public static float subFloat(float f, int length) {
+		String fStr = String.valueOf(f);
+		int i = fStr.indexOf(".");
+		String returnStr = null;
+		if (fStr.length() > i + 1 + length) {
+			returnStr = fStr.substring(0, i + 1 + length);
+		} else
+			returnStr = fStr;
+		float returnf = (Float.valueOf(returnStr)).floatValue();
+		return returnf;
+	}
+
+	/**
+	 * int数组转化成Integer数组
+	 */
+	public static Integer[] toIntegerArray(int[] arr) {
+		int n = arr.length;
+		Integer[] iarr = new Integer[n];
+		for (int i = 0; i < n; i++) {
+			iarr[i] = new Integer(arr[i]);
+		}
+		return iarr;
+	}
+
+	public static Number nvl(Number number, Number ifNullNumber) {
+		return number == null ? ifNullNumber : number;
+	}
+
+	public static int compare(Double paramDouble1, Double paramDouble2) {
+		if (paramDouble1 == null)
+			paramDouble1 = 0.0;
+		if (paramDouble2 == null)
+			paramDouble2 = 0.0;
+		return Double.compare(paramDouble1, paramDouble2);
+	}
+
+	/**
+	 * Double型加法运算
+	 * 
+	 * @param d1
+	 *            第一个加数
+	 * @param ds
+	 *            若干个加数
+	 * @return 相加的结果
+	 * @author suntg
+	 */
+	public static double add(Double d1, Double... ds) {
+		BigDecimal bd = new BigDecimal(Double.toString(d1));
+		for (Double d : ds) {
+			bd = bd.add(new BigDecimal(Double.toString(d)));
+		}
+		return bd.doubleValue();
+	}
+
+	/**
+	 * Double型加法运算
+	 * 
+	 * @param d1
+	 *            第一个加数
+	 * @param ds
+	 *            若干个加数
+	 * @return 相加的结果
+	 * @author suntg
+	 */
+	public static double add(String ds1, String... dss) {
+		BigDecimal bd = new BigDecimal(ds1);
+		for (String ds : dss) {
+			bd = bd.add(new BigDecimal(ds));
+		}
+		return bd.doubleValue();
+	}
+
+	/**
+	 * Double型减法运算
+	 * 
+	 * @param d1
+	 *            被减数
+	 * @param d2
+	 *            减数
+	 * @return 运算结果
+	 * @author suntg
+	 */
+	public static double sub(Double d1, Double d2) {
+		BigDecimal b1 = new BigDecimal(Double.toString(d1));
+		BigDecimal b2 = new BigDecimal(Double.toString(d2));
+		return b1.subtract(b2).doubleValue();
+	}
+
+	/**
+	 * Double 型乘法运算
+	 * 
+	 * @param d1
+	 *            第一个乘数
+	 * @param d2
+	 *            第二个乘数
+	 * @return 运算结果
+	 * @author suntg
+	 */
+	public static double mul(Double d1, Double d2) {
+		BigDecimal b1 = new BigDecimal(Double.toString(d1));
+		BigDecimal b2 = new BigDecimal(Double.toString(d2));
+		return b1.multiply(b2).doubleValue();
+	}
+
+	/**
+	 * Double 型除法运算
+	 * 
+	 * @param d1
+	 *            被除数
+	 * @param d2
+	 *            除数
+	 * @param scale
+	 *            小数点四舍五入精度
+	 * @return 运算结果
+	 * @author suntg
+	 */
+	public static double div(Double d1, Double d2, int scale) {
+		if (scale < 0) {
+			throw new IllegalArgumentException("四舍五入精度必须大于0");
+		}
+		if (d2.doubleValue() == 0) {
+			throw new IllegalArgumentException("被除数不能为0");
+		}
+		BigDecimal b1 = new BigDecimal(Double.toString(d1));
+		BigDecimal b2 = new BigDecimal(Double.toString(d2));
+		return b1.divide(b2, scale, BigDecimal.ROUND_HALF_UP).doubleValue();
+	}
+
+	/**
+	 * 默认小数点四舍五入精度为6的Double型除法运算
+	 * 
+	 * @param d1
+	 *            被除数
+	 * @param d2
+	 *            除数
+	 * @return 运算结果
+	 * @author suntg
+	 */
+	public static double div(Double d1, Double d2) {
+		return div(d1, d2, 6);
+	}
+
+	/**
+	 * 比较浮点型数值
+	 * 
+	 * @param paramDouble1
+	 * @param paramDouble2
+	 * @param paramInt
+	 *            精度
+	 * @return
+	 */
+	public static int compare(double paramDouble1, double paramDouble2, int paramInt) {
+		return Double.compare(formatDouble(paramDouble1, paramInt), formatDouble(paramDouble2, paramInt));
+	}
+
+}