Commit f684fb7e by fsn

优化日志记录的详情显示

parent 2690c232
...@@ -19,4 +19,9 @@ public class DeptDict extends AbstractDictMap { ...@@ -19,4 +19,9 @@ public class DeptDict extends AbstractDictMap {
put("fullname","部门全称"); put("fullname","部门全称");
put("tips","备注"); put("tips","备注");
} }
@Override
protected void initBeWrapped() {
}
} }
...@@ -9,9 +9,15 @@ import com.stylefeng.guns.common.constant.dictmap.base.AbstractDictMap; ...@@ -9,9 +9,15 @@ import com.stylefeng.guns.common.constant.dictmap.base.AbstractDictMap;
* @date 2017-05-06 15:43 * @date 2017-05-06 15:43
*/ */
public class DictMap extends AbstractDictMap { public class DictMap extends AbstractDictMap {
@Override @Override
public void init() { public void init() {
put("dictId","字典id"); put("dictId","字典id");
put("dictName","字典名称"); put("dictName","字典名称");
} }
@Override
protected void initBeWrapped() {
}
} }
...@@ -14,4 +14,9 @@ public class LogDict extends AbstractDictMap { ...@@ -14,4 +14,9 @@ public class LogDict extends AbstractDictMap {
public void init() { public void init() {
put("tips","备注"); put("tips","备注");
} }
@Override
protected void initBeWrapped() {
}
} }
...@@ -26,4 +26,9 @@ public class MenuDict extends AbstractDictMap { ...@@ -26,4 +26,9 @@ public class MenuDict extends AbstractDictMap {
put("isopen","是否打开"); put("isopen","是否打开");
put("",""); put("","");
} }
@Override
protected void initBeWrapped() {
}
} }
...@@ -20,4 +20,9 @@ public class RoleDict extends AbstractDictMap { ...@@ -20,4 +20,9 @@ public class RoleDict extends AbstractDictMap {
put("deptid","部门id"); put("deptid","部门id");
put("tips","备注"); put("tips","备注");
} }
@Override
protected void initBeWrapped() {
}
} }
...@@ -23,4 +23,11 @@ public class UserDict extends AbstractDictMap { ...@@ -23,4 +23,11 @@ public class UserDict extends AbstractDictMap {
put("roleid","角色id"); put("roleid","角色id");
put("deptid","部门id"); put("deptid","部门id");
} }
@Override
protected void initBeWrapped() {
putFieldWrapperMethodName("sex","getSexName");
putFieldWrapperMethodName("deptid","getDeptName");
putFieldWrapperMethodName("roleid","getSingleRoleName");
}
} }
...@@ -11,12 +11,30 @@ import java.util.HashMap; ...@@ -11,12 +11,30 @@ import java.util.HashMap;
public abstract class AbstractDictMap { public abstract class AbstractDictMap {
protected HashMap<String, String> dictory = new HashMap<>(); protected HashMap<String, String> dictory = new HashMap<>();
protected HashMap<String, String> fieldWarpperDictory = new HashMap<>();
public AbstractDictMap(){ public AbstractDictMap(){
put("id","主键id"); put("id","主键id");
init(); init();
initBeWrapped();
} }
/**
* 初始化字段英文名称和中文名称对应的字典
*
* @author stylefeng
* @Date 2017/5/9 19:39
*/
public abstract void init();
/**
* 初始化需要被包装的字段(例如:性别为1:男,2:女,需要被包装为汉字)
*
* @author stylefeng
* @Date 2017/5/9 19:35
*/
protected abstract void initBeWrapped();
public String get(String key) { public String get(String key) {
return this.dictory.get(key); return this.dictory.get(key);
} }
...@@ -25,5 +43,11 @@ public abstract class AbstractDictMap { ...@@ -25,5 +43,11 @@ public abstract class AbstractDictMap {
this.dictory.put(key, value); this.dictory.put(key, value);
} }
public abstract void init(); public String getFieldWarpperMethodName(String key){
return this.fieldWarpperDictory.get(key);
}
public void putFieldWrapperMethodName(String key,String methodName){
this.fieldWarpperDictory.put(key,methodName);
}
} }
...@@ -12,4 +12,9 @@ public class SystemDict extends AbstractDictMap { ...@@ -12,4 +12,9 @@ public class SystemDict extends AbstractDictMap {
public void init() { public void init() {
} }
@Override
protected void initBeWrapped() {
}
} }
package com.stylefeng.guns.common.constant.dictmap.factory;
import com.stylefeng.guns.common.constant.factory.ConstantFactory;
import com.stylefeng.guns.common.exception.BizExceptionEnum;
import com.stylefeng.guns.common.exception.BussinessException;
import java.lang.reflect.Method;
/**
* 字段的包装创建工厂
*
* @author fengshuonan
* @date 2017-05-06 15:12
*/
public class DictFieldWarpperFactory {
public static Object createFieldWarpper(Object field, String methodName) {
ConstantFactory me = ConstantFactory.me();
try {
Method method = ConstantFactory.class.getMethod(methodName, field.getClass());
Object result = method.invoke(me, field);
return result;
} catch (Exception e) {
throw new BussinessException(BizExceptionEnum.ERROR_WRAPPER_FIELD);
}
}
}
...@@ -12,6 +12,7 @@ public enum BizExceptionEnum { ...@@ -12,6 +12,7 @@ public enum BizExceptionEnum {
*/ */
DICT_EXISTED(400,"字典已经存在"), DICT_EXISTED(400,"字典已经存在"),
ERROR_CREATE_DICT(500,"创建字典失败"), ERROR_CREATE_DICT(500,"创建字典失败"),
ERROR_WRAPPER_FIELD(500,"包装字典属性失败"),
/** /**
......
package com.stylefeng.guns.core.util; package com.stylefeng.guns.core.util;
import com.stylefeng.guns.common.constant.dictmap.base.AbstractDictMap; import com.stylefeng.guns.common.constant.dictmap.base.AbstractDictMap;
import com.stylefeng.guns.common.constant.dictmap.factory.DictFieldWarpperFactory;
import com.stylefeng.guns.common.constant.dictmap.factory.DictMapFactory; import com.stylefeng.guns.common.constant.dictmap.factory.DictMapFactory;
import com.stylefeng.guns.core.support.StrKit; import com.stylefeng.guns.core.support.StrKit;
...@@ -21,6 +22,12 @@ public class Contrast { ...@@ -21,6 +22,12 @@ public class Contrast {
//记录每个修改字段的分隔符 //记录每个修改字段的分隔符
public static final String separator = ";;;"; public static final String separator = ";;;";
/**
* 比较两个对象,并返回不一致的信息
*
* @author stylefeng
* @Date 2017/5/9 19:34
*/
public static String contrastObj(Object pojo1, Object pojo2) { public static String contrastObj(Object pojo1, Object pojo2) {
String str = ""; String str = "";
try { try {
...@@ -38,7 +45,7 @@ public class Contrast { ...@@ -38,7 +45,7 @@ public class Contrast {
if (o1 == null || o2 == null) { if (o1 == null || o2 == null) {
continue; continue;
} }
if(o1 instanceof Date){ if (o1 instanceof Date) {
o1 = DateUtil.getDay((Date) o1); o1 = DateUtil.getDay((Date) o1);
} }
if (!o1.toString().equals(o2.toString())) { if (!o1.toString().equals(o2.toString())) {
...@@ -55,6 +62,12 @@ public class Contrast { ...@@ -55,6 +62,12 @@ public class Contrast {
return str; return str;
} }
/**
* 比较两个对象pojo1和pojo2,并输出不一致信息
*
* @author stylefeng
* @Date 2017/5/9 19:34
*/
public static String contrastObj(String dictClass, String key, Object pojo1, Map<String, String> pojo2) { public static String contrastObj(String dictClass, String key, Object pojo1, Map<String, String> pojo2) {
AbstractDictMap dictMap = DictMapFactory.createDictMap(dictClass); AbstractDictMap dictMap = DictMapFactory.createDictMap(dictClass);
String value = pojo2.get(key); String value = pojo2.get(key);
...@@ -74,15 +87,24 @@ public class Contrast { ...@@ -74,15 +87,24 @@ public class Contrast {
if (o1 == null || o2 == null) { if (o1 == null || o2 == null) {
continue; continue;
} }
if(o1 instanceof Date){ if (o1 instanceof Date) {
o1 = DateUtil.getDay((Date) o1); o1 = DateUtil.getDay((Date) o1);
} else if (o1 instanceof Integer) {
o2 = Integer.parseInt(o2.toString());
} }
if (!o1.toString().equals(o2.toString())) { if (!o1.toString().equals(o2.toString())) {
if (i != 1) { if (i != 1) {
str += separator; str += separator;
} }
String fieldName = dictMap.get(field.getName()); String fieldName = dictMap.get(field.getName());
str += "字段名称:" + fieldName + ",旧值:" + o1 + ",新值:" + o2; String fieldWarpperMethodName = dictMap.getFieldWarpperMethodName(field.getName());
if (fieldWarpperMethodName != null) {
Object o1Warpper = DictFieldWarpperFactory.createFieldWarpper(o1, fieldWarpperMethodName);
Object o2Warpper = DictFieldWarpperFactory.createFieldWarpper(o2, fieldWarpperMethodName);
str += "字段名称:" + fieldName + ",旧值:" + o1Warpper + ",新值:" + o2Warpper;
} else {
str += "字段名称:" + fieldName + ",旧值:" + o1 + ",新值:" + o2;
}
i++; i++;
} }
} }
...@@ -91,4 +113,5 @@ public class Contrast { ...@@ -91,4 +113,5 @@ public class Contrast {
} }
return str; return str;
} }
} }
\ 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