sys_log 表增加 execute_time 执行时间记录字段
This commit is contained in:
@@ -18,6 +18,7 @@ import com.jeesite.common.config.Global;
|
||||
import com.jeesite.common.web.http.ServletUtils;
|
||||
import com.jeesite.modules.sys.entity.Log;
|
||||
import com.jeesite.modules.sys.utils.LogUtils;
|
||||
import com.jeesite.modules.sys.utils.UserUtils;
|
||||
|
||||
/**
|
||||
* 登出过滤器
|
||||
@@ -36,7 +37,7 @@ public class LogoutFilter extends org.apache.shiro.web.filter.authc.LogoutFilter
|
||||
//try/catch added for SHIRO-298:
|
||||
try {
|
||||
// 记录用户退出日志
|
||||
LogUtils.saveLog(ServletUtils.getRequest(), "系统退出", Log.TYPE_LOGIN_LOGOUT);
|
||||
LogUtils.saveLog(UserUtils.getUser(), ServletUtils.getRequest(), "系统退出", Log.TYPE_LOGIN_LOGOUT);
|
||||
// 退出登录
|
||||
subject.logout();
|
||||
} catch (SessionException ise) {
|
||||
|
||||
@@ -58,13 +58,13 @@ public class AuthorizingRealm extends com.jeesite.common.shiro.realm.BaseAuthori
|
||||
userService.updateUserLoginInfo(user);
|
||||
|
||||
// 记录用户登录日志
|
||||
LogUtils.saveLog(ServletUtils.getRequest(), "系统登录", Log.TYPE_LOGIN_LOGOUT);
|
||||
LogUtils.saveLog(user, ServletUtils.getRequest(), "系统登录", Log.TYPE_LOGIN_LOGOUT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLogoutSuccess(User logoutUser, HttpServletRequest request) {
|
||||
// 记录用户退出日志
|
||||
LogUtils.saveLog(logoutUser, request, null, null, "系统退出", Log.TYPE_LOGIN_LOGOUT);
|
||||
LogUtils.saveLog(logoutUser, request, "系统退出", Log.TYPE_LOGIN_LOGOUT);
|
||||
}
|
||||
|
||||
public void setUserService(UserService userService) {
|
||||
|
||||
Binary file not shown.
@@ -13,6 +13,7 @@ import com.jeesite.common.collect.MapUtils;
|
||||
import com.jeesite.common.entity.BaseEntity;
|
||||
import com.jeesite.common.entity.DataEntity;
|
||||
import com.jeesite.common.lang.StringUtils;
|
||||
import com.jeesite.common.lang.TimeUtils;
|
||||
import com.jeesite.common.mybatis.annotation.Column;
|
||||
import com.jeesite.common.mybatis.annotation.Table;
|
||||
import com.jeesite.common.mybatis.mapper.query.QueryType;
|
||||
@@ -42,6 +43,7 @@ import com.jeesite.common.mybatis.mapper.query.QueryType;
|
||||
@Column(name="user_agent", attrName="userAgent", label="用户代理"),
|
||||
@Column(name="device_name", attrName="deviceName", label="设备名称/操作系统", queryType=QueryType.LIKE),
|
||||
@Column(name="browser_name", attrName="browserName", label="浏览器名称", queryType=QueryType.LIKE),
|
||||
@Column(name="execute_time", attrName="executeTime", label="执行时间"),
|
||||
}, orderBy="a.create_date DESC"
|
||||
)
|
||||
public class Log extends DataEntity<Log> {
|
||||
@@ -68,6 +70,7 @@ public class Log extends DataEntity<Log> {
|
||||
private String userAgent; // 用户代理
|
||||
private String deviceName; // 设备名称/操作系统
|
||||
private String browserName; // 浏览器名称
|
||||
private Long executeTime; // 执行时间
|
||||
|
||||
private Map<String, String[]> paramsMap; // 操作提交的数据,临时存储用
|
||||
|
||||
@@ -206,6 +209,18 @@ public class Log extends DataEntity<Log> {
|
||||
this.browserName = browserName;
|
||||
}
|
||||
|
||||
public Long getExecuteTime() {
|
||||
return executeTime;
|
||||
}
|
||||
|
||||
public void setExecuteTime(Long executeTime) {
|
||||
this.executeTime = executeTime;
|
||||
}
|
||||
|
||||
public String getExecuteTimeFormat(){
|
||||
return TimeUtils.formatDateAgo(executeTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置请求参数
|
||||
* @param paramMap
|
||||
|
||||
@@ -12,6 +12,7 @@ import org.springframework.core.NamedThreadLocal;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import com.jeesite.common.datasource.DataSourceHolder;
|
||||
import com.jeesite.common.lang.DateUtils;
|
||||
import com.jeesite.common.lang.TimeUtils;
|
||||
import com.jeesite.common.service.BaseService;
|
||||
@@ -31,9 +32,9 @@ public class LogInterceptor extends BaseService implements HandlerInterceptor {
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
|
||||
Object handler) throws Exception {
|
||||
long beginTime = System.currentTimeMillis();// 1、开始时间
|
||||
startTimeThreadLocal.set(beginTime); // 线程绑定变量(该数据只有当前请求的线程可见)
|
||||
if (logger.isDebugEnabled()){
|
||||
long beginTime = System.currentTimeMillis();//1、开始时间
|
||||
startTimeThreadLocal.set(beginTime); //线程绑定变量(该数据只有当前请求的线程可见)
|
||||
logger.debug("开始计时: {} URI: {}", new SimpleDateFormat("hh:mm:ss.SSS")
|
||||
.format(beginTime), request.getRequestURI());
|
||||
}
|
||||
@@ -51,19 +52,23 @@ public class LogInterceptor extends BaseService implements HandlerInterceptor {
|
||||
@Override
|
||||
public void afterCompletion(HttpServletRequest request, HttpServletResponse response,
|
||||
Object handler, Exception ex) throws Exception {
|
||||
long beginTime = startTimeThreadLocal.get();// 得到线程绑定的局部变量(开始时间)
|
||||
long endTime = System.currentTimeMillis(); // 2、结束时间
|
||||
long executeTime = endTime - beginTime; // 3、获取执行时间
|
||||
startTimeThreadLocal.remove(); // 用完之后销毁线程变量数据
|
||||
|
||||
// 恢复多数据源参数,使用默认数据源
|
||||
DataSourceHolder.clearDataSourceName();
|
||||
|
||||
// 保存日志
|
||||
LogUtils.saveLog(UserUtils.getUser(), request, handler, ex, null, null);
|
||||
LogUtils.saveLog(UserUtils.getUser(), request, handler, ex, null, null, executeTime);
|
||||
|
||||
// 打印JVM信息。
|
||||
if (logger.isDebugEnabled()){
|
||||
long beginTime = startTimeThreadLocal.get();//得到线程绑定的局部变量(开始时间)
|
||||
long endTime = System.currentTimeMillis(); //2、结束时间
|
||||
logger.debug("计时结束: {} 用时: {} URI: {} 最大内存: {}m 已分配内存: {}m 已分配内存中的剩余空间: {}m 最大可用内存: {}m",
|
||||
DateUtils.formatDate(endTime, "hh:mm:ss.SSS"), TimeUtils.formatDateAgo(endTime - beginTime),
|
||||
DateUtils.formatDate(endTime, "hh:mm:ss.SSS"), TimeUtils.formatDateAgo(executeTime),
|
||||
request.getRequestURI(), Runtime.getRuntime().maxMemory()/1024/1024, Runtime.getRuntime().totalMemory()/1024/1024, Runtime.getRuntime().freeMemory()/1024/1024,
|
||||
(Runtime.getRuntime().maxMemory()-Runtime.getRuntime().totalMemory()+Runtime.getRuntime().freeMemory())/1024/1024);
|
||||
startTimeThreadLocal.remove(); //用完之后销毁线程变量数据
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -54,14 +54,15 @@ public class LogUtils {
|
||||
/**
|
||||
* 保存日志
|
||||
*/
|
||||
public static void saveLog(HttpServletRequest request, String logTitle, String logType){
|
||||
saveLog(UserUtils.getUser(), request, null, null, logTitle, logType);
|
||||
public static void saveLog(User user, HttpServletRequest request, String logTitle, String logType){
|
||||
saveLog(user, request, null, null, logTitle, logType, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存日志
|
||||
* @param executeTime
|
||||
*/
|
||||
public static void saveLog(User user, HttpServletRequest request, Object handler, Exception ex, String logTitle, String logType){
|
||||
public static void saveLog(User user, HttpServletRequest request, Object handler, Exception ex, String logTitle, String logType, long executeTime){
|
||||
if (user == null || StringUtils.isBlank(user.getUserCode()) || request == null){
|
||||
return;
|
||||
}
|
||||
@@ -91,6 +92,7 @@ public class LogUtils {
|
||||
log.setCorpCode(user.getCorpCode());
|
||||
log.setCorpName(user.getCorpName());
|
||||
}
|
||||
log.setExecuteTime(executeTime);
|
||||
log.setCurrentUser(user);
|
||||
log.preInsert();
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
|
||||
-- 日志表新增执行时间字段
|
||||
ALTER TABLE [dbo].[${_prefix}sys_log] ADD [execute_time] decimal(19) NULL;
|
||||
|
||||
-- 更新模块数据库版本
|
||||
update ${_prefix}sys_module set current_version = '4.0.1' where module_code = 'core';
|
||||
commit;
|
||||
@@ -0,0 +1,8 @@
|
||||
|
||||
-- 日志表新增执行时间字段
|
||||
ALTER TABLE ${_prefix}sys_log
|
||||
ADD COLUMN `execute_time` decimal(19,0) NULL COMMENT '执行时间' AFTER `browser_name`;
|
||||
|
||||
-- 更新模块数据库版本
|
||||
update ${_prefix}sys_module set current_version = '4.0.1' where module_code = 'core';
|
||||
commit;
|
||||
@@ -0,0 +1,8 @@
|
||||
|
||||
-- 日志表新增执行时间字段
|
||||
ALTER TABLE ${_prefix}sys_log ADD execute_time NUMBER(19) NULL;
|
||||
COMMENT ON COLUMN ${_prefix}sys_log.execute_time IS '执行时间';
|
||||
|
||||
-- 更新模块数据库版本
|
||||
update ${_prefix}sys_module set current_version = '4.0.1' where module_code = 'core';
|
||||
commit;
|
||||
@@ -1,7 +0,0 @@
|
||||
|
||||
|
||||
|
||||
|
||||
-- 更新模块数据库版本
|
||||
update ${_prefix}sys_module set current_version = '4.0.xx' where module_code = 'core';
|
||||
commit;
|
||||
@@ -0,0 +1,8 @@
|
||||
|
||||
-- 日志表新增执行时间字段
|
||||
ALTER TABLE ${_prefix}sys_log ADD COLUMN execute_time decimal(19);
|
||||
COMMENT ON COLUMN ${_prefix}sys_log.execute_time IS '执行时间';
|
||||
|
||||
-- 更新模块数据库版本
|
||||
update ${_prefix}sys_module set current_version = '4.0.1' where module_code = 'core';
|
||||
commit;
|
||||
@@ -162,6 +162,17 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-xs-6">
|
||||
<div class="form-group">
|
||||
<label class="control-label col-sm-4" title="">
|
||||
<span class="required hide">*</span> 响应时间:<i class="fa icon-question hide"></i></label>
|
||||
<div class="col-sm-8">
|
||||
<#form:input path="executeTimeFormat" maxlength="100" class="form-control "/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="box-footer">
|
||||
<div class="row">
|
||||
|
||||
@@ -109,7 +109,8 @@ $('#dataGrid').dataGrid({
|
||||
{header:'操作时间', name:'createDate', index:'a.create_date', width:100, align:"center"},
|
||||
{header:'客户端IP', name:'remoteAddr', index:'a.remote_addr', width:100, align:"center"},
|
||||
{header:'设备名称', name:'deviceName', index:'a.device_name', width:100, align:"center"},
|
||||
{header:'浏览器名', name:'browserName', index:'a.browser_name', width:100, align:"center"}/* ,
|
||||
{header:'浏览器名', name:'browserName', index:'a.browser_name', width:100, align:"center"},
|
||||
{header:'响应时间', name:'executeTimeFormat', index:'a.execute_time', width:100, align:"center"}/* ,
|
||||
{header:'操作', name:'actions', width:130, sortable:false, title:false, formatter: function(val, obj, row, act){
|
||||
var actions = [];
|
||||
<% if(hasPermi('sys:log:edit')){ %>
|
||||
|
||||
Reference in New Issue
Block a user