48f95dcea1d4c0df11585699f325522806781603.svn-base 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. package com.yihu.utils;
  2. import java.io.File;
  3. import java.io.FileInputStream;
  4. import java.io.FileOutputStream;
  5. import java.io.IOException;
  6. import java.io.OutputStream;
  7. import java.lang.reflect.Field;
  8. import java.lang.reflect.InvocationTargetException;
  9. import java.lang.reflect.Method;
  10. import java.math.BigDecimal;
  11. import java.nio.channels.FileChannel;
  12. import java.sql.ResultSet;
  13. import java.sql.SQLException;
  14. import java.sql.Timestamp;
  15. import java.text.DecimalFormat;
  16. import java.text.SimpleDateFormat;
  17. import java.util.ArrayList;
  18. import java.util.Date;
  19. import java.util.HashMap;
  20. import java.util.List;
  21. import java.util.Map;
  22. import java.util.Set;
  23. import javax.servlet.http.HttpServletRequest;
  24. import javax.servlet.http.HttpServletResponse;
  25. import net.sf.json.JSONObject;
  26. import net.sf.json.JsonConfig;
  27. import org.apache.log4j.Logger;
  28. public class BaseFunction {
  29. public static Logger logger=Logger.getLogger("myInfo");
  30. public static boolean isDebug=true;
  31. //去除空格,替换中文的横线、斜杠
  32. public static String trim(String val) {
  33. return val==null?val:val.trim().toUpperCase().replaceAll("-", "-");
  34. }
  35. public static JsonConfig getDefaultJSONConfig(){
  36. JsonConfig jsonConfig = new JsonConfig();
  37. jsonConfig.registerJsonValueProcessor(java.util.Date.class, new DateJsonValueProcessor());
  38. jsonConfig.registerJsonValueProcessor(java.sql.Timestamp.class, new DateJsonValueProcessor());
  39. jsonConfig.registerJsonValueProcessor(Integer.class, new DateJsonValueProcessor());
  40. jsonConfig.registerJsonValueProcessor(Double.class, new DateJsonValueProcessor());
  41. return jsonConfig;
  42. }
  43. // 用来判断两个对象的值的差异,map键值对为字段的英文-中文对照
  44. public static String makeCompareInfo(Object oldValue, Object newValue) {
  45. String info = "";
  46. try {
  47. info = makeCompareInfo(
  48. JSONObject.fromObject(oldValue,
  49. BaseFunction.getDefaultJSONConfig()),
  50. JSONObject.fromObject(newValue,
  51. BaseFunction.getDefaultJSONConfig()));
  52. } catch (Exception e) {
  53. e.printStackTrace();
  54. }
  55. return info;
  56. }
  57. // 用来判断两个对象的值的差异,map键值对为字段的英文-中文对照
  58. public static String makeCompareInfo(JSONObject oldValue, JSONObject newValue) {
  59. String info = "";
  60. try {
  61. Set<String> propertyNames = oldValue.keySet();
  62. for (String propertyName : propertyNames) {
  63. try {
  64. Object oldStr =oldValue.optString(propertyName,"");
  65. Object newStr =newValue.optString(propertyName,"");
  66. if (!oldStr.equals(newStr)) {
  67. if (info.length() > 0){
  68. info += ",";
  69. }
  70. info += propertyName + ":“" + oldStr + "”" + "->“" + newStr + "”";
  71. }
  72. } catch (Exception e) {
  73. e.printStackTrace();
  74. }
  75. }
  76. } catch (Exception e) {
  77. e.printStackTrace();
  78. }
  79. return info;
  80. }
  81. }