123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- package com.yihu.utils;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.OutputStream;
- import java.lang.reflect.Field;
- import java.lang.reflect.InvocationTargetException;
- import java.lang.reflect.Method;
- import java.math.BigDecimal;
- import java.nio.channels.FileChannel;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Timestamp;
- import java.text.DecimalFormat;
- import java.text.SimpleDateFormat;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import java.util.Set;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import net.sf.json.JSONObject;
- import net.sf.json.JsonConfig;
- import org.apache.log4j.Logger;
- public class BaseFunction {
- public static Logger logger=Logger.getLogger("myInfo");
- public static boolean isDebug=true;
-
- //去除空格,替换中文的横线、斜杠
- public static String trim(String val) {
- return val==null?val:val.trim().toUpperCase().replaceAll("-", "-");
- }
-
- public static JsonConfig getDefaultJSONConfig(){
- JsonConfig jsonConfig = new JsonConfig();
- jsonConfig.registerJsonValueProcessor(java.util.Date.class, new DateJsonValueProcessor());
- jsonConfig.registerJsonValueProcessor(java.sql.Timestamp.class, new DateJsonValueProcessor());
- jsonConfig.registerJsonValueProcessor(Integer.class, new DateJsonValueProcessor());
- jsonConfig.registerJsonValueProcessor(Double.class, new DateJsonValueProcessor());
-
- return jsonConfig;
- }
-
- // 用来判断两个对象的值的差异,map键值对为字段的英文-中文对照
- public static String makeCompareInfo(Object oldValue, Object newValue) {
- String info = "";
- try {
- info = makeCompareInfo(
- JSONObject.fromObject(oldValue,
- BaseFunction.getDefaultJSONConfig()),
- JSONObject.fromObject(newValue,
- BaseFunction.getDefaultJSONConfig()));
- } catch (Exception e) {
- e.printStackTrace();
- }
- return info;
- }
-
- // 用来判断两个对象的值的差异,map键值对为字段的英文-中文对照
- public static String makeCompareInfo(JSONObject oldValue, JSONObject newValue) {
- String info = "";
- try {
- Set<String> propertyNames = oldValue.keySet();
- for (String propertyName : propertyNames) {
- try {
- Object oldStr =oldValue.optString(propertyName,"");
- Object newStr =newValue.optString(propertyName,"");
-
- if (!oldStr.equals(newStr)) {
- if (info.length() > 0){
- info += ",";
- }
- info += propertyName + ":“" + oldStr + "”" + "->“" + newStr + "”";
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return info;
- }
- }
|