优化日志模块,增加登录日志
This commit is contained in:
@@ -137,12 +137,13 @@ public class BusinessConstants {
|
||||
public static final byte USER_STATUS_BANNED = 2;
|
||||
/**
|
||||
* 日志操作
|
||||
* 新增、修改、删除
|
||||
* 新增、修改、删除、登录、导入
|
||||
* */
|
||||
public static final String LOG_OPERATION_TYPE_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_DELETE = "删除,id:";
|
||||
public static final String LOG_OPERATION_TYPE_LOGIN = "登录,id:";
|
||||
public static final String LOG_OPERATION_TYPE_IMPORT = "导入";
|
||||
|
||||
/**
|
||||
|
||||
@@ -12,6 +12,7 @@ import com.jsh.erp.datasource.entities.User;
|
||||
import com.jsh.erp.datasource.entities.UserEx;
|
||||
import com.jsh.erp.datasource.vo.TreeNodeEx;
|
||||
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.user.UserService;
|
||||
import com.jsh.erp.utils.*;
|
||||
@@ -19,6 +20,8 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
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.servlet.http.HttpServletRequest;
|
||||
@@ -51,6 +54,9 @@ public class UserController {
|
||||
@Resource
|
||||
private TenantService tenantService;
|
||||
|
||||
@Resource
|
||||
private LogService logService;
|
||||
|
||||
private static String message = "成功";
|
||||
private static final String HTTP = "http://";
|
||||
private static final String CODE_OK = "200";
|
||||
@@ -100,11 +106,9 @@ public class UserController {
|
||||
break;
|
||||
default:
|
||||
try {
|
||||
msgTip = "user can login";
|
||||
//验证通过 ,可以登录,放入session,记录登录日志
|
||||
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);
|
||||
if(("open").equals(mybatisPlusStatus)) {
|
||||
if(user.getTenantId()!=null) {
|
||||
@@ -122,6 +126,9 @@ public class UserController {
|
||||
}
|
||||
}
|
||||
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) {
|
||||
e.printStackTrace();
|
||||
logger.error(">>>>>>>>>>>>>>>查询用户名为:" + username + " ,用户信息异常", e);
|
||||
|
||||
@@ -6,6 +6,8 @@ public class LogVo4List extends Log {
|
||||
|
||||
private String username;
|
||||
|
||||
private String createTimeStr;
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
@@ -13,4 +15,12 @@ public class LogVo4List extends Log {
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getCreateTimeStr() {
|
||||
return createTimeStr;
|
||||
}
|
||||
|
||||
public void setCreateTimeStr(String createTimeStr) {
|
||||
this.createTimeStr = createTimeStr;
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import com.jsh.erp.datasource.mappers.LogMapperEx;
|
||||
import com.jsh.erp.datasource.vo.LogVo4List;
|
||||
import com.jsh.erp.exception.BusinessRunTimeException;
|
||||
import com.jsh.erp.utils.StringUtil;
|
||||
import com.jsh.erp.utils.Tools;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -65,6 +66,11 @@ public class LogService {
|
||||
try{
|
||||
list=logMapperEx.selectByConditionLog(operation, usernameID, clientIp, status, beginTime, endTime,
|
||||
contentdetails, offset, rows);
|
||||
if (null != list) {
|
||||
for (LogVo4List log : list) {
|
||||
log.setCreateTimeStr(Tools.getCenternTime(log.getCreatetime()));
|
||||
}
|
||||
}
|
||||
}catch(Exception e){
|
||||
logger.error("异常码[{}],异常提示[{}],异常[{}]",
|
||||
ExceptionConstants.DATA_READ_FAIL_CODE,ExceptionConstants.DATA_READ_FAIL_MSG,e);
|
||||
|
||||
Reference in New Issue
Block a user