优化日志模块,增加登录日志

This commit is contained in:
季圣华
2019-08-15 00:13:01 +08:00
parent 4a6a4b4e92
commit 630394c7ed
5 changed files with 31 additions and 8 deletions

View File

@@ -120,12 +120,11 @@
{title: '操作模块', field: 'operation', width: 120}, {title: '操作模块', field: 'operation', width: 120},
{title: '操作人员', field: 'username', width: 80, align: "center"}, {title: '操作人员', field: 'username', width: 80, align: "center"},
{title: '操作IP', field: 'clientip', width: 90, align: "center"}, {title: '操作IP', field: 'clientip', width: 90, align: "center"},
{title: '操作时间', field: 'createtime', width: 130, align: "center"}, {title: '操作时间', field: 'createTimeStr', width: 130, align: "center"},
{title: '操作详情', field: 'remark', width: 260}, {title: '操作详情', field: 'remark', width: 350},
{title: '操作状态',field: 'status',width:70,align:"center",formatter:function(value){ {title: '操作状态',field: 'status',width:70,align:"center",formatter:function(value){
return value? "失败":"成功"; return value? "失败":"成功";
}}, }}
{title: '备注', field: 'remark', width: 150}
]], ]],
onLoadError: function () { onLoadError: function () {
$.messager.alert('页面加载提示', '页面加载异常,请稍后再试!', 'error'); $.messager.alert('页面加载提示', '页面加载异常,请稍后再试!', 'error');

View File

@@ -137,12 +137,13 @@ public class BusinessConstants {
public static final byte USER_STATUS_BANNED = 2; public static final byte USER_STATUS_BANNED = 2;
/** /**
* 日志操作 * 日志操作
* 新增、修改、删除 * 新增、修改、删除、登录、导入
* */ * */
public static final String LOG_OPERATION_TYPE_ADD = "新增"; public static final String LOG_OPERATION_TYPE_ADD = "新增";
public static final String LOG_OPERATION_TYPE_BATCH_ADD = "批量新增"; public static final String LOG_OPERATION_TYPE_BATCH_ADD = "批量新增";
public static final String LOG_OPERATION_TYPE_EDIT = "修改,id:"; public static final String LOG_OPERATION_TYPE_EDIT = "修改,id:";
public static final String LOG_OPERATION_TYPE_DELETE = "删除,id:"; public static final String LOG_OPERATION_TYPE_DELETE = "删除,id:";
public static final String LOG_OPERATION_TYPE_LOGIN = "登录,id:";
public static final String LOG_OPERATION_TYPE_IMPORT = "导入"; public static final String LOG_OPERATION_TYPE_IMPORT = "导入";
/** /**

View File

@@ -12,6 +12,7 @@ import com.jsh.erp.datasource.entities.User;
import com.jsh.erp.datasource.entities.UserEx; import com.jsh.erp.datasource.entities.UserEx;
import com.jsh.erp.datasource.vo.TreeNodeEx; import com.jsh.erp.datasource.vo.TreeNodeEx;
import com.jsh.erp.exception.BusinessParamCheckingException; import com.jsh.erp.exception.BusinessParamCheckingException;
import com.jsh.erp.service.log.LogService;
import com.jsh.erp.service.tenant.TenantService; import com.jsh.erp.service.tenant.TenantService;
import com.jsh.erp.service.user.UserService; import com.jsh.erp.service.user.UserService;
import com.jsh.erp.utils.*; import com.jsh.erp.utils.*;
@@ -19,6 +20,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
@@ -51,6 +54,9 @@ public class UserController {
@Resource @Resource
private TenantService tenantService; private TenantService tenantService;
@Resource
private LogService logService;
private static String message = "成功"; private static String message = "成功";
private static final String HTTP = "http://"; private static final String HTTP = "http://";
private static final String CODE_OK = "200"; private static final String CODE_OK = "200";
@@ -100,11 +106,9 @@ public class UserController {
break; break;
default: default:
try { try {
msgTip = "user can login";
//验证通过 可以登录放入session记录登录日志 //验证通过 可以登录放入session记录登录日志
user = userService.getUserByUserName(username); user = userService.getUserByUserName(username);
// logService.create(new Logdetails(user, "登录系统", model.getClientIp(),
// new Timestamp(System.currentTimeMillis()), (short) 0, "管理用户:" + username + " 登录系统", username + " 登录系统"));
msgTip = "user can login";
request.getSession().setAttribute("user",user); request.getSession().setAttribute("user",user);
if(("open").equals(mybatisPlusStatus)) { if(("open").equals(mybatisPlusStatus)) {
if(user.getTenantId()!=null) { if(user.getTenantId()!=null) {
@@ -122,6 +126,9 @@ public class UserController {
} }
} }
request.getSession().setAttribute("mybatisPlusStatus",mybatisPlusStatus); //开启状态 request.getSession().setAttribute("mybatisPlusStatus",mybatisPlusStatus); //开启状态
logService.insertLog(BusinessConstants.LOG_INTERFACE_NAME_USER,
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_LOGIN).append(user.getId()).toString(),
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
logger.error(">>>>>>>>>>>>>>>查询用户名为:" + username + " ,用户信息异常", e); logger.error(">>>>>>>>>>>>>>>查询用户名为:" + username + " ,用户信息异常", e);

View File

@@ -6,6 +6,8 @@ public class LogVo4List extends Log {
private String username; private String username;
private String createTimeStr;
public String getUsername() { public String getUsername() {
return username; return username;
} }
@@ -13,4 +15,12 @@ public class LogVo4List extends Log {
public void setUsername(String username) { public void setUsername(String username) {
this.username = username; this.username = username;
} }
public String getCreateTimeStr() {
return createTimeStr;
}
public void setCreateTimeStr(String createTimeStr) {
this.createTimeStr = createTimeStr;
}
} }

View File

@@ -11,6 +11,7 @@ import com.jsh.erp.datasource.mappers.LogMapperEx;
import com.jsh.erp.datasource.vo.LogVo4List; import com.jsh.erp.datasource.vo.LogVo4List;
import com.jsh.erp.exception.BusinessRunTimeException; import com.jsh.erp.exception.BusinessRunTimeException;
import com.jsh.erp.utils.StringUtil; import com.jsh.erp.utils.StringUtil;
import com.jsh.erp.utils.Tools;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@@ -65,6 +66,11 @@ public class LogService {
try{ try{
list=logMapperEx.selectByConditionLog(operation, usernameID, clientIp, status, beginTime, endTime, list=logMapperEx.selectByConditionLog(operation, usernameID, clientIp, status, beginTime, endTime,
contentdetails, offset, rows); contentdetails, offset, rows);
if (null != list) {
for (LogVo4List log : list) {
log.setCreateTimeStr(Tools.getCenternTime(log.getCreatetime()));
}
}
}catch(Exception e){ }catch(Exception e){
logger.error("异常码[{}],异常提示[{}],异常[{}]", logger.error("异常码[{}],异常提示[{}],异常[{}]",
ExceptionConstants.DATA_READ_FAIL_CODE,ExceptionConstants.DATA_READ_FAIL_MSG,e); ExceptionConstants.DATA_READ_FAIL_CODE,ExceptionConstants.DATA_READ_FAIL_MSG,e);