系统行为日志记录功能修改
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
package com.nis.util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
@@ -26,6 +28,7 @@ import com.sun.corba.se.impl.orbutil.closure.Constant;
|
||||
public class LogUtils {
|
||||
|
||||
public static final String CACHE_MENU_NAME_PATH_MAP = "menuNamePathMap";
|
||||
public static final String CACHE_MENU_NAME_PATH_MAP2 = "menuNamePathMap2";
|
||||
|
||||
private static SysLogDao logDao = SpringContextHolder.getBean(SysLogDao.class);
|
||||
private static SysMenuDao menuDao = SpringContextHolder.getBean(SysMenuDao.class);
|
||||
@@ -59,6 +62,12 @@ public class LogUtils {
|
||||
log.setMethod(request.getMethod());
|
||||
log.setCreateBy(user.getName());
|
||||
log.setCreateDate(new Date());
|
||||
if(StringUtil.isEmpty(request.getParameter("functionId"))){
|
||||
log.setFunctionId(0);
|
||||
}else{
|
||||
log.setFunctionId(Integer.parseInt(request.getParameter("functionId")));
|
||||
}
|
||||
|
||||
// 异步保存日志
|
||||
new SaveLogThread(log, handler, ex).start();
|
||||
}
|
||||
@@ -90,7 +99,8 @@ public class LogUtils {
|
||||
RequiresPermissions rp = m.getAnnotation(RequiresPermissions.class);
|
||||
permission = (rp != null ? StringUtils.join(rp.value(), ",") : "");
|
||||
}
|
||||
log.setTitle(getMenuNamePath(log.getRequestUri(), permission));
|
||||
Integer functionId = log.getFunctionId();
|
||||
log.setTitle(getMenuNamePath(log.getRequestUri(), permission,functionId));
|
||||
}
|
||||
// 如果有异常,设置异常信息
|
||||
log.setException(Exceptions.getStackTraceAsString(ex));
|
||||
@@ -132,12 +142,21 @@ public class LogUtils {
|
||||
/**
|
||||
* 获取菜单名称路径(如:系统设置-机构用户-用户管理-编辑)
|
||||
*/
|
||||
public static String getMenuNamePath(String requestUri, String permission){
|
||||
public static String getMenuNamePath(String requestUri, String permission,Integer functionId){
|
||||
String href = StringUtils.substringAfter(requestUri, Configurations.getStringProperty("adminPath", "/nis"));
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, String> menuMap = (Map<String, String>)CacheUtils.get(CACHE_MENU_NAME_PATH_MAP);
|
||||
//用于记录功能按钮的操作日志【新增,修改,删除,审核等】
|
||||
Map<String, String> menuMap2 = (Map<String, String>)CacheUtils.get(CACHE_MENU_NAME_PATH_MAP2);
|
||||
if (menuMap == null){
|
||||
menuMap = Maps.newHashMap();
|
||||
menuMap2 = Maps.newHashMap();
|
||||
Properties msgProp = new Properties();
|
||||
try {
|
||||
msgProp.load(Configurations.class.getResourceAsStream("/messages/message_en.properties"));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
List<SysMenu> menuList = menuDao.findAllList(new SysMenu());
|
||||
for (SysMenu menu : menuList){
|
||||
// 获取菜单名称路径(如:系统设置-机构用户-用户管理-编辑)
|
||||
@@ -152,30 +171,66 @@ public class LogUtils {
|
||||
}
|
||||
for (SysMenu m : menuList){
|
||||
if (m.getId().equals(Long.valueOf(id))){
|
||||
namePathList.add(m.getName());
|
||||
// namePathList.add(m.getName());
|
||||
namePathList.add(msgProp.getProperty(m.getCode())==null?m.getCode():msgProp.getProperty(m.getCode()));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
namePathList.add(menu.getName());
|
||||
// namePathList.add(menu.getName());
|
||||
namePathList.add(msgProp.getProperty(menu.getCode())==null?menu.getCode():msgProp.getProperty(menu.getCode()));
|
||||
namePath = StringUtils.join(namePathList, "-");
|
||||
}
|
||||
// 设置菜单名称路径
|
||||
if (StringUtils.isNotBlank(menu.getHref())){
|
||||
menuMap.put(menu.getHref(), namePath);
|
||||
if(!StringUtil.isEmpty(menu.getFunctionId())&&menu.getFunctionId()!=0){
|
||||
menuMap.put(menu.getHref()+"?functionId"+menu.getFunctionId(), namePath);
|
||||
menuMap2.put("functionId"+menu.getFunctionId(), namePath);//用于记录功能按钮的操作日志
|
||||
}else{
|
||||
menuMap.put(menu.getHref(), namePath);
|
||||
}
|
||||
}else if (StringUtils.isNotBlank(menu.getPermission())){
|
||||
for (String p : StringUtils.split(menu.getPermission())){
|
||||
menuMap.put(p, namePath);
|
||||
if(!StringUtil.isEmpty(menu.getFunctionId())&&menu.getFunctionId()!=0){
|
||||
menuMap.put(p+"?functionId"+menu.getFunctionId(), namePath);
|
||||
menuMap2.put("functionId"+menu.getFunctionId(), namePath);//用于记录功能按钮的操作日志
|
||||
}else{
|
||||
menuMap.put(p, namePath);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
CacheUtils.put(CACHE_MENU_NAME_PATH_MAP, menuMap);
|
||||
CacheUtils.put(CACHE_MENU_NAME_PATH_MAP2, menuMap2);
|
||||
}
|
||||
String menuNamePath = null;
|
||||
if(functionId==0){
|
||||
menuNamePath = menuMap.get(href);
|
||||
}else{
|
||||
menuNamePath = menuMap.get(href+"?functionId"+functionId);
|
||||
if(menuNamePath==null){
|
||||
menuNamePath = menuMap2.get("functionId"+functionId);
|
||||
/*String methodName = href.substring(href.lastIndexOf("/")+1).toLowerCase();
|
||||
if(!StringUtil.isEmpty(methodName)){
|
||||
if(methodName.contains("insert")||methodName.contains("save")||methodName.contains("update")||methodName.contains("edit")){
|
||||
menuNamePath +="-"+"Save or Update";
|
||||
}else if(methodName.contains("valid")){
|
||||
menuNamePath +="-"+"Delete";
|
||||
}else if(methodName.contains("audit")){
|
||||
menuNamePath +="-"+"Confirmation";
|
||||
}
|
||||
|
||||
}*/
|
||||
}
|
||||
}
|
||||
String menuNamePath = menuMap.get(href);
|
||||
if (menuNamePath == null){
|
||||
for (String p : StringUtils.split(permission)){
|
||||
if(functionId!=0){
|
||||
p += "?functionId"+functionId;
|
||||
}
|
||||
menuNamePath = menuMap.get(p);
|
||||
if (StringUtils.isNotBlank(menuNamePath)){
|
||||
break;
|
||||
@@ -185,6 +240,7 @@ public class LogUtils {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
System.out.println(menuNamePath);
|
||||
return menuNamePath;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user