添加大量访问日志记录
This commit is contained in:
@@ -37,9 +37,6 @@ public class DataController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private HomeworkService homeworkService;
|
private HomeworkService homeworkService;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private FileService fileService;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private VUserfileService vUserfileService;
|
private VUserfileService vUserfileService;
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,13 @@
|
|||||||
package com.fjy.spring.controller;
|
package com.fjy.spring.controller;
|
||||||
|
|
||||||
import com.fjy.spring.domain.TbFile;
|
import com.fjy.spring.domain.TbFile;
|
||||||
|
import com.fjy.spring.domain.TbLog;
|
||||||
|
import com.fjy.spring.domain.TbUser;
|
||||||
import com.fjy.spring.enums.ResultEnum;
|
import com.fjy.spring.enums.ResultEnum;
|
||||||
import com.fjy.spring.exception.UserException;
|
import com.fjy.spring.exception.UserException;
|
||||||
import com.fjy.spring.service.FileService;
|
import com.fjy.spring.service.FileService;
|
||||||
|
import com.fjy.spring.service.LogService;
|
||||||
|
import com.fjy.spring.untils.GetIPAddrUtil;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
@@ -12,13 +16,28 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.ResponseBody;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import static com.fjy.spring.constant.GlobalConstant.USER_SESSION_KEY;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class DeleteController {
|
public class DeleteController {
|
||||||
|
/**
|
||||||
|
* 文件相关数据库操作
|
||||||
|
*/
|
||||||
@Autowired
|
@Autowired
|
||||||
private FileService fileService;//文件相关数据库操作
|
private FileService fileService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private LogService logService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
HttpServletRequest request;
|
||||||
|
|
||||||
@GetMapping("/home/findfile")
|
@GetMapping("/home/findfile")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
@@ -68,6 +87,22 @@ public class DeleteController {
|
|||||||
if (file.delete()) {
|
if (file.delete()) {
|
||||||
fileService.deleteFileById(tbFile);
|
fileService.deleteFileById(tbFile);
|
||||||
log.info("删除单个文件" + fileName + "成功!");
|
log.info("删除单个文件" + fileName + "成功!");
|
||||||
|
|
||||||
|
TbUser user =(TbUser)request.getSession().getAttribute(USER_SESSION_KEY);
|
||||||
|
//写入日志信息
|
||||||
|
Date date = new Date();
|
||||||
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
|
String dateNowStr = sdf.format(date);
|
||||||
|
TbLog log = new TbLog();
|
||||||
|
log.setUserid(user.getColuserid());
|
||||||
|
log.setColtime(dateNowStr);
|
||||||
|
log.setColheader("删除单个文件" + fileName + "成功!");
|
||||||
|
log.setRequestURL(request.getRequestURL().toString());
|
||||||
|
|
||||||
|
//解决nginx代理后IP地址获取问题
|
||||||
|
log.setColip(GetIPAddrUtil.getIpAddr(request));
|
||||||
|
logService.addLogRec(log);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
log.info("删除单个文件" + fileName + "失败!");
|
log.info("删除单个文件" + fileName + "失败!");
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
package com.fjy.spring.controller;
|
package com.fjy.spring.controller;
|
||||||
|
|
||||||
import com.fjy.spring.domain.TbFile;
|
import com.fjy.spring.domain.TbFile;
|
||||||
|
import com.fjy.spring.domain.TbLog;
|
||||||
import com.fjy.spring.domain.TbUser;
|
import com.fjy.spring.domain.TbUser;
|
||||||
import com.fjy.spring.enums.ResultEnum;
|
import com.fjy.spring.enums.ResultEnum;
|
||||||
import com.fjy.spring.exception.UserException;
|
import com.fjy.spring.exception.UserException;
|
||||||
import com.fjy.spring.properties.ServerProperties;
|
import com.fjy.spring.properties.ServerProperties;
|
||||||
import com.fjy.spring.service.FileService;
|
import com.fjy.spring.service.FileService;
|
||||||
|
import com.fjy.spring.service.LogService;
|
||||||
|
import com.fjy.spring.untils.LogUtil;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
@@ -28,12 +31,18 @@ import static com.fjy.spring.constant.GlobalConstant.USER_SESSION_KEY;
|
|||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
public class DownLoadController {
|
public class DownLoadController {
|
||||||
|
/**
|
||||||
|
* 服务器配置信息
|
||||||
|
*/
|
||||||
@Autowired
|
@Autowired
|
||||||
private ServerProperties serverProperties;//服务器配置信息
|
private ServerProperties serverProperties;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private FileService fileService;
|
private FileService fileService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private LogService logService;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
HttpServletRequest request;
|
HttpServletRequest request;
|
||||||
|
|
||||||
@@ -45,12 +54,12 @@ public class DownLoadController {
|
|||||||
@GetMapping("/home/admin/download/findall")
|
@GetMapping("/home/admin/download/findall")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public List<TbFile> toDownloadAll() {
|
public List<TbFile> toDownloadAll() {
|
||||||
List<TbFile> files = fileService.findAllFile();//此处做空指针判断并抛出错误
|
//此处做空指针判断并抛出错误
|
||||||
|
List<TbFile> files = fileService.findAllFile();
|
||||||
if (files != null) {
|
if (files != null) {
|
||||||
return files;
|
return files;
|
||||||
}
|
}
|
||||||
new UserException(ResultEnum.EMPTY_DATA);
|
throw new UserException(ResultEnum.EMPTY_DATA);
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/home/download/findone")
|
@GetMapping("/home/download/findone")
|
||||||
@@ -63,8 +72,7 @@ public class DownLoadController {
|
|||||||
if (files != null) {
|
if (files != null) {
|
||||||
return files;
|
return files;
|
||||||
}
|
}
|
||||||
new UserException(ResultEnum.EMPTY_DATA);
|
throw new UserException(ResultEnum.EMPTY_DATA);
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping("/home/download/dodownload")
|
@RequestMapping("/home/download/dodownload")
|
||||||
@@ -102,6 +110,10 @@ public class DownLoadController {
|
|||||||
while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
|
while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
|
||||||
bos.write(buff, 0, bytesRead);
|
bos.write(buff, 0, bytesRead);
|
||||||
}
|
}
|
||||||
|
//记录下载日志
|
||||||
|
addVisitLog("下载文件"+tbFile.getColrealname()+" "+tbFile.getColfilename());
|
||||||
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} finally {
|
} finally {
|
||||||
@@ -164,7 +176,7 @@ public class DownLoadController {
|
|||||||
for (int i = 0; i < path.length; i++) {
|
for (int i = 0; i < path.length; i++) {
|
||||||
File file = new File(path[i]);
|
File file = new File(path[i]);
|
||||||
//将需要压缩的文件格式化为输入流
|
//将需要压缩的文件格式化为输入流
|
||||||
if (!file.isDirectory()){
|
if (!file.isDirectory()) {
|
||||||
zipSource = new FileInputStream(file);
|
zipSource = new FileInputStream(file);
|
||||||
//压缩条目不是具体独立的文件,而是压缩包文件列表中的列表项,称为条目,就像索引一样
|
//压缩条目不是具体独立的文件,而是压缩包文件列表中的列表项,称为条目,就像索引一样
|
||||||
ZipEntry zipEntry = new ZipEntry(file.getName());
|
ZipEntry zipEntry = new ZipEntry(file.getName());
|
||||||
@@ -183,6 +195,9 @@ public class DownLoadController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//记录下载日志
|
||||||
|
addVisitLog("下载压缩文件"+zipFile.getName());
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} finally {
|
} finally {
|
||||||
@@ -281,4 +296,15 @@ public class DownLoadController {
|
|||||||
System.out.println(it1.next());
|
System.out.println(it1.next());
|
||||||
}
|
}
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 登陆后的访问日志记录
|
||||||
|
*
|
||||||
|
* @param content
|
||||||
|
*/
|
||||||
|
private void addVisitLog(String content) {
|
||||||
|
TbUser user = (TbUser) request.getSession().getAttribute(USER_SESSION_KEY);
|
||||||
|
TbLog log = LogUtil.addLog(user, content, request);
|
||||||
|
logService.addLogRec(log);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,11 @@
|
|||||||
package com.fjy.spring.controller;
|
package com.fjy.spring.controller;
|
||||||
|
|
||||||
|
import com.fjy.spring.domain.TbLog;
|
||||||
import com.fjy.spring.domain.TbUser;
|
import com.fjy.spring.domain.TbUser;
|
||||||
|
import com.fjy.spring.service.LogService;
|
||||||
|
import com.fjy.spring.untils.GetIPAddrUtil;
|
||||||
|
import com.fjy.spring.untils.LogUtil;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||||
@@ -10,6 +15,9 @@ import org.springframework.web.bind.support.SessionStatus;
|
|||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
import static com.fjy.spring.constant.GlobalConstant.USER_SESSION_KEY;
|
import static com.fjy.spring.constant.GlobalConstant.USER_SESSION_KEY;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
@@ -18,70 +26,108 @@ public class NavController {
|
|||||||
@Resource
|
@Resource
|
||||||
HttpServletRequest request;
|
HttpServletRequest request;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private LogService logService;
|
||||||
|
|
||||||
@GetMapping(value = {"index",""})
|
@GetMapping(value = {"index",""})
|
||||||
public String toLoginPage(){
|
public String toLoginPage(){
|
||||||
|
//获取访问头信息
|
||||||
|
addIndexLog(request.getHeader("user-agent"));
|
||||||
return "login";
|
return "login";
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping(value = {"testthymeleaf"})
|
@GetMapping(value = {"testthymeleaf"})
|
||||||
public String toTestPage(){
|
public String toTestPage(){
|
||||||
|
addVisitLog("测试页面 testthymeleaf");
|
||||||
return "/dist/thymeleafTest";
|
return "/dist/thymeleafTest";
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping(value = {"axiosTest"})
|
@GetMapping(value = {"axiosTest"})
|
||||||
public String toTestAxiosPage(){
|
public String toTestAxiosPage(){
|
||||||
|
addVisitLog("测试页面 axiosTest");
|
||||||
return "/dist/axiosTest";
|
return "/dist/axiosTest";
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping(value = {"/home"})
|
@GetMapping(value = {"/home"})
|
||||||
public String toHomePage(){
|
public String toHomePage(){
|
||||||
|
addVisitLog("首页 home");
|
||||||
return "home/home";
|
return "home/home";
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping(value = {"/logout"})
|
@GetMapping(value = {"/logout"})
|
||||||
public String toLogOut(SessionStatus status){
|
public String toLogOut(SessionStatus status){
|
||||||
//request.getSession().getAttribute(USER_SESSION_KEY).invalidate();
|
//request.getSession().getAttribute(USER_SESSION_KEY).invalidate();
|
||||||
|
addVisitLog("登出 logout");
|
||||||
status.setComplete();
|
status.setComplete();
|
||||||
return "login";
|
return "login";
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping(value = {"/home/feedback"})
|
@GetMapping(value = {"/home/feedback"})
|
||||||
public String toFeedbackPage(){
|
public String toFeedbackPage(){
|
||||||
|
addVisitLog("反馈页面 /home/feedback");
|
||||||
return "home/feedback";
|
return "home/feedback";
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping(value = {"/home/about"})
|
@GetMapping(value = {"/home/about"})
|
||||||
public String toAboutPage(){
|
public String toAboutPage(){
|
||||||
|
addVisitLog("关于页面 /home/about");
|
||||||
return "home/about";
|
return "home/about";
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping(value = {"/home/admin"})
|
@GetMapping(value = {"/home/admin"})
|
||||||
public String toAdminPage(){
|
public String toAdminPage(){
|
||||||
|
addVisitLog("管理员页面 /home/admin");
|
||||||
return "home/admin";
|
return "home/admin";
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping(value = {"/home/admin/managecourse"})
|
@GetMapping(value = {"/home/admin/managecourse"})
|
||||||
public String toManageCoursePage(){
|
public String toManageCoursePage(){
|
||||||
|
addVisitLog("课程管理页面 /home/admin/managecourse");
|
||||||
return "home/managecourse";
|
return "home/managecourse";
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping(value = {"/home/admin/manageuser"})
|
@GetMapping(value = {"/home/admin/manageuser"})
|
||||||
public String toManageUserPage(){
|
public String toManageUserPage(){
|
||||||
|
addVisitLog("用户管理页面 /home/admin/manageuser");
|
||||||
return "home/manageuser";
|
return "home/manageuser";
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping(value = {"/home/admin/homework"})
|
@GetMapping(value = {"/home/admin/homework"})
|
||||||
public String toHomeworkPage(){
|
public String toHomeworkPage(){
|
||||||
|
addVisitLog("作业管理页面 /home/admin/homework");
|
||||||
return "home/homework";
|
return "home/homework";
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping(value = {"/home/user"})
|
@GetMapping(value = {"/home/user"})
|
||||||
public String toUserPage(){
|
public String toUserPage(){
|
||||||
|
addVisitLog("个人中心页面 /home/user");
|
||||||
return "home/user";
|
return "home/user";
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping(value = {"/error"})
|
@GetMapping(value = {"/error"})
|
||||||
public String toErrorPage(){
|
public String toErrorPage(){
|
||||||
|
addVisitLog("404页面 error");
|
||||||
return "error";
|
return "error";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 首页的访问日志记录
|
||||||
|
* @param content
|
||||||
|
*/
|
||||||
|
private void addIndexLog(String content){
|
||||||
|
TbUser user = new TbUser();
|
||||||
|
user.setColname("访客");
|
||||||
|
TbLog log = LogUtil.addLog(user,content,request);
|
||||||
|
logService.addLogRec(log);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 登陆后的访问日志记录
|
||||||
|
* @param content
|
||||||
|
*/
|
||||||
|
private void addVisitLog(String content){
|
||||||
|
TbUser user =(TbUser)request.getSession().getAttribute(USER_SESSION_KEY);
|
||||||
|
TbLog log = LogUtil.addLog(user,content,request);
|
||||||
|
logService.addLogRec(log);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import com.fjy.spring.service.HomeworkService;
|
|||||||
import com.fjy.spring.service.LogService;
|
import com.fjy.spring.service.LogService;
|
||||||
import com.fjy.spring.untils.FormatFileSizeUtil;
|
import com.fjy.spring.untils.FormatFileSizeUtil;
|
||||||
import com.fjy.spring.untils.GetIPAddrUtil;
|
import com.fjy.spring.untils.GetIPAddrUtil;
|
||||||
|
import com.fjy.spring.untils.LogUtil;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -29,6 +30,8 @@ import java.util.Date;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static com.fjy.spring.constant.GlobalConstant.USER_SESSION_KEY;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class UpLoadController {
|
public class UpLoadController {
|
||||||
@@ -98,6 +101,10 @@ public class UpLoadController {
|
|||||||
file.setColuserid(user.getColuserid());
|
file.setColuserid(user.getColuserid());
|
||||||
if (fileService.addFile(file)) {
|
if (fileService.addFile(file)) {
|
||||||
log.info("记录写入数据库成功");
|
log.info("记录写入数据库成功");
|
||||||
|
|
||||||
|
// 记录上传日志
|
||||||
|
addVisitLog("上传文件" + file.getColrealname() + " " + file.getColfilename());
|
||||||
|
|
||||||
}
|
}
|
||||||
//System.out.println("记录写入数据库成功");
|
//System.out.println("记录写入数据库成功");
|
||||||
else {
|
else {
|
||||||
@@ -248,6 +255,9 @@ public class UpLoadController {
|
|||||||
|
|
||||||
if (fileService.addFile(tbFile)) {
|
if (fileService.addFile(tbFile)) {
|
||||||
log.info("记录写入数据库成功");
|
log.info("记录写入数据库成功");
|
||||||
|
|
||||||
|
// 记录上传日志
|
||||||
|
addVisitLog("上传文件" + tbFile.getColrealname() + " " + tbFile.getColfilename());
|
||||||
} else {
|
} else {
|
||||||
log.error("记录写入数据库失败");
|
log.error("记录写入数据库失败");
|
||||||
}
|
}
|
||||||
@@ -265,13 +275,21 @@ public class UpLoadController {
|
|||||||
request.getScheme() + "://" + request.getServerName() + ":"
|
request.getScheme() + "://" + request.getServerName() + ":"
|
||||||
+ serverProperties.getPortNum() + request.getContextPath() + "/upload/"
|
+ serverProperties.getPortNum() + request.getContextPath() + "/upload/"
|
||||||
+ file.getOriginalFilename());
|
+ file.getOriginalFilename());
|
||||||
} catch (IllegalStateException e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 登陆后的访问日志记录
|
||||||
|
*
|
||||||
|
* @param content
|
||||||
|
*/
|
||||||
|
private void addVisitLog(String content) {
|
||||||
|
TbUser user = (TbUser) httpServletRequest.getSession().getAttribute(USER_SESSION_KEY);
|
||||||
|
TbLog log = LogUtil.addLog(user, content, httpServletRequest);
|
||||||
|
logService.addLogRec(log);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,17 @@
|
|||||||
package com.fjy.spring.controller;
|
package com.fjy.spring.controller;
|
||||||
|
|
||||||
|
import com.fjy.spring.domain.TbLog;
|
||||||
import com.fjy.spring.domain.TbUser;
|
import com.fjy.spring.domain.TbUser;
|
||||||
import com.fjy.spring.domain.VUserinfo;
|
import com.fjy.spring.domain.VUserinfo;
|
||||||
import com.fjy.spring.enums.RegisteredEnum;
|
import com.fjy.spring.enums.RegisteredEnum;
|
||||||
import com.fjy.spring.enums.ResultEnum;
|
import com.fjy.spring.enums.ResultEnum;
|
||||||
import com.fjy.spring.exception.UserException;
|
import com.fjy.spring.exception.UserException;
|
||||||
import com.fjy.spring.properties.ServerProperties;
|
import com.fjy.spring.properties.ServerProperties;
|
||||||
|
import com.fjy.spring.service.LogService;
|
||||||
import com.fjy.spring.service.StudentService;
|
import com.fjy.spring.service.StudentService;
|
||||||
import com.fjy.spring.service.UserService;
|
import com.fjy.spring.service.UserService;
|
||||||
import com.fjy.spring.untils.CodingUtil;
|
import com.fjy.spring.untils.CodingUtil;
|
||||||
|
import com.fjy.spring.untils.LogUtil;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
@@ -20,6 +23,8 @@ import javax.annotation.Resource;
|
|||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
|
|
||||||
|
import static com.fjy.spring.constant.GlobalConstant.USER_SESSION_KEY;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class UpdateController {
|
public class UpdateController {
|
||||||
@@ -30,7 +35,7 @@ public class UpdateController {
|
|||||||
private StudentService studentService;
|
private StudentService studentService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ServerProperties serverProperties;
|
private LogService logService;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
HttpServletRequest request;
|
HttpServletRequest request;
|
||||||
@@ -52,11 +57,20 @@ public class UpdateController {
|
|||||||
studentService.UpdateStudentListRegistered(tbUser.getColrealname(),tbUser.getColstudentno(),
|
studentService.UpdateStudentListRegistered(tbUser.getColrealname(),tbUser.getColstudentno(),
|
||||||
RegisteredEnum.REGISTERED.getCode());
|
RegisteredEnum.REGISTERED.getCode());
|
||||||
log.info(tbUser.getColname()+" 信息更新成功");
|
log.info(tbUser.getColname()+" 信息更新成功");
|
||||||
|
//写入数据库日志
|
||||||
|
TbUser user =(TbUser)request.getSession().getAttribute(USER_SESSION_KEY);
|
||||||
|
TbLog tbLog = LogUtil.addLog(user,tbUser.getColname()+" 信息更新成功",request);
|
||||||
|
logService.addLogRec(tbLog);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
/*return "redirect:" + request.getScheme() + "://" + request.getServerName() + ":"
|
/*return "redirect:" + request.getScheme() + "://" + request.getServerName() + ":"
|
||||||
+ serverProperties.getPortNum() + request.getContextPath() + "/home/user";*/
|
+ serverProperties.getPortNum() + request.getContextPath() + "/home/user";*/
|
||||||
// return "login";
|
// return "login";
|
||||||
}
|
}
|
||||||
|
//写入数据库日志
|
||||||
|
TbUser user =(TbUser)request.getSession().getAttribute(USER_SESSION_KEY);
|
||||||
|
TbLog tbLog = LogUtil.addLog(user,tbUser.getColname()+" 信息更新失败",request);
|
||||||
|
logService.addLogRec(tbLog);
|
||||||
log.error(tbUser.getColname()+" 信息更新失败");
|
log.error(tbUser.getColname()+" 信息更新失败");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
41
src/main/java/com/fjy/spring/untils/LogUtil.java
Normal file
41
src/main/java/com/fjy/spring/untils/LogUtil.java
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
package com.fjy.spring.untils;
|
||||||
|
|
||||||
|
import com.fjy.spring.domain.TbLog;
|
||||||
|
import com.fjy.spring.domain.TbUser;
|
||||||
|
import com.fjy.spring.service.LogService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import static com.fjy.spring.constant.GlobalConstant.USER_SESSION_KEY;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author F嘉阳
|
||||||
|
* @date 2018-04-26 12:45
|
||||||
|
* 日志信息填充工具类
|
||||||
|
*/
|
||||||
|
public class LogUtil {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 写入日志记录
|
||||||
|
* @param user
|
||||||
|
* @param content
|
||||||
|
*/
|
||||||
|
public static TbLog addLog(TbUser user,String content,HttpServletRequest request){
|
||||||
|
//写入日志信息
|
||||||
|
Date date = new Date();
|
||||||
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
|
String dateNowStr = sdf.format(date);
|
||||||
|
TbLog log = new TbLog();
|
||||||
|
log.setUserid(user.getColuserid());
|
||||||
|
log.setColtime(dateNowStr);
|
||||||
|
log.setColheader(user.getColname()+" "+content);
|
||||||
|
log.setRequestURL(request.getRequestURL().toString());
|
||||||
|
|
||||||
|
//解决nginx代理后IP地址获取问题
|
||||||
|
log.setColip(GetIPAddrUtil.getIpAddr(request));
|
||||||
|
return log;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html xmlns:th="http://www.thymeleaf.org">
|
<html xmlns:th="http://www.thymeleaf.org">
|
||||||
<head th:fragment="header(title)">
|
<head th:fragment="header(title)">
|
||||||
|
<meta name="renderer" content="webkit">
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<title th:text="${title}"></title>
|
<title th:text="${title}"></title>
|
||||||
|
|||||||
@@ -81,6 +81,7 @@
|
|||||||
<el-card class="box-card hidden-xs-only" th:fragment="timelimit">
|
<el-card class="box-card hidden-xs-only" th:fragment="timelimit">
|
||||||
<div slot="header" class="clearfix">
|
<div slot="header" class="clearfix">
|
||||||
<span>作业提交倒计时</span>
|
<span>作业提交倒计时</span>
|
||||||
|
<!--超时后仍为正数-->
|
||||||
<span style="color: red"> 功能未完成</span>
|
<span style="color: red"> 功能未完成</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="text item">
|
<div class="text item">
|
||||||
|
|||||||
@@ -48,7 +48,7 @@
|
|||||||
<el-row>
|
<el-row>
|
||||||
<span>近期登陆日志</span><br>
|
<span>近期登陆日志</span><br>
|
||||||
<template>
|
<template>
|
||||||
<el-table :data="logData" height="300" :default-sort="{prop: 'time', order: 'descending'}">
|
<el-table :data="logData" height="350" :default-sort="{prop: 'time', order: 'descending'}">
|
||||||
<el-table-column prop="colname" label="用户名" sortable>
|
<el-table-column prop="colname" label="用户名" sortable>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column prop="coltime" label="时间" sortable>
|
<el-table-column prop="coltime" label="时间" sortable>
|
||||||
|
|||||||
@@ -103,7 +103,8 @@
|
|||||||
<el-col :span="23">
|
<el-col :span="23">
|
||||||
<div class="grid-content bg-purple-dark">
|
<div class="grid-content bg-purple-dark">
|
||||||
<template>
|
<template>
|
||||||
<el-table :data="tableHomeworkData" style="width: 100%">
|
<el-table :data="tableHomeworkData" style="width: 100%"
|
||||||
|
:default-sort="{prop: 'worktime', order: 'descending'}">
|
||||||
<el-table-column type="expand">
|
<el-table-column type="expand">
|
||||||
<template slot-scope="props">
|
<template slot-scope="props">
|
||||||
<el-form label-position="left" inline class="demo-table-expand">
|
<el-form label-position="left" inline class="demo-table-expand">
|
||||||
|
|||||||
@@ -26,7 +26,7 @@
|
|||||||
<el-button @click="togglePost()" type="warning" plain>设为管理员</el-button>
|
<el-button @click="togglePost()" type="warning" plain>设为管理员</el-button>
|
||||||
<el-button @click="togglePost()" type="danger" plain>删除用户</el-button>
|
<el-button @click="togglePost()" type="danger" plain>删除用户</el-button>
|
||||||
</div>
|
</div>
|
||||||
<el-table ref="multipleTable" :data="userData" @selection-change="handleSelectionChange"
|
<el-table ref="multipleTable" :data="userData" height="650" @selection-change="handleSelectionChange"
|
||||||
tooltip-effect="dark" style="width: 100%" >
|
tooltip-effect="dark" style="width: 100%" >
|
||||||
<el-table-column type="selection" prop='coluserid'>
|
<el-table-column type="selection" prop='coluserid'>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
|
|||||||
Reference in New Issue
Block a user