新增操作日志查询及批量删除

This commit is contained in:
RuoYi 2018-03-02 17:02:48 +08:00
parent 9e2e65e69f
commit acdf964aa8
23 changed files with 446 additions and 132 deletions

View File

@ -180,8 +180,8 @@ insert into sys_role_menu values ('1', '10');
drop table if exists sys_oper_log;
create table sys_oper_log (
oper_id int(11) not null auto_increment comment '日志主键',
title varchar(50) default '' comment '功能请求',
action varchar(100) default '' comment '模块标题',
title varchar(50) default '' comment '模块标题',
action varchar(100) default '' comment '功能请求',
method varchar(100) default '' comment '方法名称',
channel varchar(20) default '' comment '来源渠道',
login_name varchar(50) default '' comment '登录名称',
@ -189,13 +189,13 @@ create table sys_oper_log (
opert_url varchar(255) default '' comment '请求URL',
opert_ip varchar(30) default '' comment '操作地址',
oper_param varchar(255) default '' comment '请求参数',
status int(1) default 0 comment '状态0正常 1异常',
status int(1) default 0 comment '操作状态 0正常 1异常',
error_msg varchar(255) default '' comment '错误消息',
oper_time timestamp default current_timestamp comment '操作时间',
primary key (oper_id)
) engine=innodb auto_increment=100 default charset=utf8;
insert into sys_oper_log values(1, '监控管理', '在线用户-踢出用户', 'com.ruoyi.xxx.xxx', 'web', 'admin', '研发部门', 'delete.do?id=1', '127.0.0.1', 'JSON参数', 0, '错误描述', '2018-01-01');
insert into sys_oper_log values(1, '监控管理', '在线用户-踢出用户', 'com.ruoyi.project.monitor.online.controller.UserOnlineController()', 'web', 'admin', '研发部门', 'delete.do?id=1', '127.0.0.1', 'JSON参数', 0, '错误描述', '2018-01-01');
-- ----------------------------
-- 8、数据字典表

View File

@ -6,15 +6,12 @@ import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionTemplate;
import com.ruoyi.common.exception.base.DaoException;
import lombok.extern.slf4j.Slf4j;
/**
* 数据DAO层通用数据处理
*
* @author ruoyi
*/
@Slf4j
public class DynamicObjectBaseDao
{
@Resource(name = "sqlSessionTemplate")
@ -23,78 +20,48 @@ public class DynamicObjectBaseDao
/**
* 保存对象
*
* @param str
* @param obj
* @return
* @param str mapper 节点
* @param obj 对象
* @return 结果
* @throws Exception
*/
public int save(String str, Object obj)
{
int rows;
try
{
rows = sqlSessionTemplate.insert(str, obj);
}
catch (Exception e)
{
log.error(e.getMessage());
throw new DaoException("插入失败");
}
return rows;
return sqlSessionTemplate.insert(str, obj);
}
/**
* 批量更新
*
* @param str
* @param obj
* @return
* @param str mapper 节点
* @param obj 对象
* @return 结果
* @throws Exception
*/
public int batchSave(String str, List<?> objs)
{
int rows;
try
{
rows = sqlSessionTemplate.insert(str, objs);
}
catch (Exception e)
{
log.error(e.getMessage());
throw new DaoException("批量更新失败");
}
return rows;
return sqlSessionTemplate.insert(str, objs);
}
/**
* 修改对象
*
* @param str
* @param obj
* @return
* @param str mapper 节点
* @param obj 对象
* @return 结果
* @throws Exception
*/
public int update(String str, Object obj)
{
int rows;
try
{
rows = sqlSessionTemplate.update(str, obj);
}
catch (Exception e)
{
log.error(e.getMessage());
throw new DaoException("修改失败");
}
return rows;
return sqlSessionTemplate.update(str, obj);
}
/**
* 批量更新
*
* @param str
* @param obj
* @return
* @param str mapper 节点
* @param obj 对象
* @return 结果
* @throws Exception
*/
public void batchUpdate(String str, List<?> objs) throws Exception
@ -122,118 +89,81 @@ public class DynamicObjectBaseDao
}
/**
* 批量删除
* 批量删除 根据对象
*
* @param str
* @param obj
* @return
* @param str mapper 节点
* @param obj 对象
* @return 结果
* @throws Exception
*/
public int batchDelete(String str, List<?> objs) throws Exception
{
int rows;
try
{
rows = sqlSessionTemplate.update(str, objs);
}
catch (Exception e)
{
log.error(e.getMessage());
throw new DaoException("批量删除失败");
}
return rows;
return sqlSessionTemplate.delete(str, objs);
}
/**
* 批量删除 根据数组
*
* @param str mapper 节点
* @param obj 对象
* @return 结果
* @throws Exception
*/
public int batchDelete(String str, Long[] objs) throws Exception
{
return sqlSessionTemplate.delete(str, objs);
}
/**
* 删除对象
*
* @param str
* @param obj
* @return
* @param str mapper 节点
* @param obj 对象
* @return 结果
* @throws Exception
*/
public int delete(String str, Object obj)
{
int rows;
try
{
rows = sqlSessionTemplate.delete(str, obj);
}
catch (Exception e)
{
log.error(e.getMessage());
throw new DaoException("删除失败");
}
return rows;
return sqlSessionTemplate.delete(str, obj);
}
/**
* 查找单条对象
*
* @param str
* @param obj
* @return
* @param str mapper 节点
* @param obj 对象
* @return 结果
* @throws Exception
*/
public <T> T findForObject(String str, Object obj)
{
T t;
try
{
t = sqlSessionTemplate.selectOne(str, obj);
}
catch (Exception e)
{
log.error(e.getMessage());
throw new DaoException("查找单条对象失败");
}
return t;
return sqlSessionTemplate.selectOne(str, obj);
}
/**
* 查找对象 - 无条件
*
* @param str
* @param obj
* @return
* @param str mapper 节点
* @param obj 对象
* @return 结果
* @throws Exception
*/
public <E> List<E> findForList(String str) throws Exception
{
List<E> list;
try
{
list = sqlSessionTemplate.selectList(str);
}
catch (Exception e)
{
log.error(e.getMessage());
throw new DaoException("查找所有对象-无条件。失败");
}
return list;
return sqlSessionTemplate.selectList(str);
}
/**
* 查找对象 - 有条件
*
* @param str
* @param obj
* @return
* @param str mapper 节点
* @param obj 对象
* @return 结果
* @throws Exception
*/
public <E> List<E> findForList(String str, Object obj)
public <E> List<E> findForList(String str, Object obj) throws Exception
{
List<E> list;
try
{
list = sqlSessionTemplate.selectList(str, obj);
}
catch (Exception e)
{
log.error(e.getMessage());
throw new DaoException("查找所有对象-有条件。失败");
}
return list;
return sqlSessionTemplate.selectList(str, obj);
}
public Object findForMap(String str, Object obj, String key, String value) throws Exception

View File

@ -4,9 +4,13 @@ import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.JSON;
import com.ruoyi.framework.web.page.PageUtilEntity;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.monitor.logininfor.domain.Logininfor;
@ -41,4 +45,16 @@ public class LogininforController extends BaseController
TableDataInfo tableDataInfo = new TableDataInfo(list, pageUtilEntity.getTotalResult());
return tableDataInfo;
}
@Log(title = "监控管理", action = "登录日志-批量删除")
@PostMapping("/batchRemove")
@ResponseBody
public JSON batchRemove(@RequestParam("ids[]") Long[] ids)
{
int rows = logininforService.batchDeleteLogininfor(ids);
if (rows > 0) {
return JSON.ok();
}
return JSON.error();
}
}

View File

@ -25,4 +25,12 @@ public interface ILogininforDao
* @return 登录记录集合
*/
public List<Logininfor> pageInfoQuery(PageUtilEntity pageUtilEntity);
/**
* 批量删除系统登录日志
*
* @param ids 需要删除的数据
* @return
*/
public int batchDeleteLogininfor(Long[] ids);
}

View File

@ -46,4 +46,23 @@ public class LogininforDaoImpl extends DynamicObjectBaseDao implements ILogininf
return logininforList;
}
/**
* 批量删除系统登录日志
*
* @param ids 需要删除的数据
* @return
*/
public int batchDeleteLogininfor(Long[] ids)
{
int rows = 0;
try
{
rows = this.batchDelete("SystemLogininforMapper.batchDeleteLogininfor", ids);
}
catch (Exception e)
{
e.printStackTrace();
}
return rows;
}
}

View File

@ -26,4 +26,12 @@ public interface ILogininforService
* @return 登录记录集合
*/
public List<Logininfor> pageInfoQueryLogininfor(PageUtilEntity pageUtilEntity);
/**
* 批量删除系统登录日志
*
* @param ids 需要删除的数据
* @return
*/
public int batchDeleteLogininfor(Long[] ids);
}

View File

@ -40,4 +40,15 @@ public class LogininforServiceImpl implements ILogininforService
{
return logininforDao.pageInfoQuery(pageUtilEntity);
}
/**
* 批量删除系统登录日志
*
* @param ids 需要删除的数据
* @return
*/
public int batchDeleteLogininfor(Long[] ids)
{
return logininforDao.batchDeleteLogininfor(ids);
}
}

View File

@ -54,7 +54,7 @@ public class UserOnlineController extends BaseController
return tableDataInfo;
}
@Log(title = "监控管理", action = "在线用户-批量踢出用户")
@Log(title = "监控管理", action = "在线用户-批量强退用户")
@PostMapping("/batchForceLogout")
@ResponseBody
public JSON batchForceLogout(@RequestParam("ids[]") String[] ids)

View File

@ -53,7 +53,7 @@ public interface IUserOnlineService
public List<UserOnline> pageInfoQueryUserOnline(PageUtilEntity pageUtilEntity);
/**
* 读取Session信息
* 强退用户
*
* @param sessionId 会话ID
*/

View File

@ -97,7 +97,7 @@ public class UserOnlineServiceImpl implements IUserOnlineService
}
/**
* 读取Session信息
* 强退用户
*
* @param sessionId 会话ID
*/

View File

@ -0,0 +1,61 @@
package com.ruoyi.project.monitor.operlog.controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.JSON;
import com.ruoyi.framework.web.page.PageUtilEntity;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.monitor.operlog.domain.OperLog;
import com.ruoyi.project.monitor.operlog.service.IOperLogService;
/**
* 操作日志记录
*
* @author ruoyi
*/
@Controller
@RequestMapping("/monitor/operlog")
public class OperlogController extends BaseController
{
private String prefix = "monitor/operlog";
@Autowired
private IOperLogService operLogService;
@GetMapping()
public String logininfor()
{
return prefix + "/operlog";
}
@GetMapping("/list")
@ResponseBody
public TableDataInfo list()
{
PageUtilEntity pageUtilEntity = this.getPageUtilEntity();
List<OperLog> list = operLogService.pageInfoQueryOperLog(pageUtilEntity);
TableDataInfo tableDataInfo = new TableDataInfo(list, pageUtilEntity.getTotalResult());
return tableDataInfo;
}
@Log(title = "监控管理", action = "操作日志-批量删除")
@PostMapping("/batchRemove")
@ResponseBody
public JSON batchRemove(@RequestParam("ids[]") Long[] ids)
{
int rows = operLogService.batchDeleteOperLog(ids);
if (rows > 0)
{
return JSON.ok();
}
return JSON.error();
}
}

View File

@ -1,5 +1,7 @@
package com.ruoyi.project.monitor.operlog.dao;
import java.util.List;
import com.ruoyi.framework.web.page.PageUtilEntity;
import com.ruoyi.project.monitor.operlog.domain.OperLog;
/**
@ -15,4 +17,20 @@ public interface IOperLogDao
* @param operLog 系统日志对象
*/
public void insertOperlog(OperLog operLog);
/**
* 查询系统操作日志集合
*
* @param pageUtilEntity 分页参数
* @return 操作日志集合
*/
public List<OperLog> pageInfoQuery(PageUtilEntity pageUtilEntity);
/**
* 批量删除系统操作日志
*
* @param ids 需要删除的数据
* @return
*/
public int batchDeleteOperLog(Long[] ids);
}

View File

@ -1,8 +1,9 @@
package com.ruoyi.project.monitor.operlog.dao;
import java.util.List;
import org.springframework.stereotype.Repository;
import com.ruoyi.framework.web.dao.DynamicObjectBaseDao;
import com.ruoyi.framework.web.page.PageUtilEntity;
import com.ruoyi.project.monitor.operlog.domain.OperLog;
/**
@ -23,4 +24,44 @@ public class OperLogDaoImpl extends DynamicObjectBaseDao implements IOperLogDao
{
this.save("SystemOperLogMapper.insertOperlog", operLog);
}
/**
* 查询系统操作日志集合
*
* @param pageUtilEntity 分页参数
* @return 操作日志集合
*/
public List<OperLog> pageInfoQuery(PageUtilEntity pageUtilEntity)
{
List<OperLog> logininforList = null;
try
{
logininforList = this.findForList("SystemOperLogMapper.pageInfoQueryOperLog", pageUtilEntity);
}
catch (Exception e)
{
e.printStackTrace();
}
return logininforList;
}
/**
* 批量删除系统操作日志
*
* @param ids 需要删除的数据
* @return
*/
public int batchDeleteOperLog(Long[] ids)
{
int rows = 0;
try
{
rows = this.batchDelete("SystemOperLogMapper.batchDeleteOperLog", ids);
}
catch (Exception e)
{
e.printStackTrace();
}
return rows;
}
}

View File

@ -1,5 +1,7 @@
package com.ruoyi.project.monitor.operlog.service;
import java.util.List;
import com.ruoyi.framework.web.page.PageUtilEntity;
import com.ruoyi.project.monitor.operlog.domain.OperLog;
/**
@ -15,4 +17,20 @@ public interface IOperLogService
* @param operLog 系统日志对象
*/
public void insertOperlog(OperLog operLog);
/**
* 查询系统操作日志集合
*
* @param pageUtilEntity 分页参数
* @return 操作日志集合
*/
public List<OperLog> pageInfoQueryOperLog(PageUtilEntity pageUtilEntity);
/**
* 批量删除系统操作日志
*
* @param ids 需要删除的数据
* @return
*/
public int batchDeleteOperLog(Long[] ids);
}

View File

@ -1,7 +1,11 @@
package com.ruoyi.project.monitor.operlog.service;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.framework.web.page.PageUtilEntity;
import com.ruoyi.project.monitor.operlog.dao.IOperLogDao;
import com.ruoyi.project.monitor.operlog.domain.OperLog;
@ -26,4 +30,26 @@ public class OperLogServiceImpl implements IOperLogService
{
operLogDao.insertOperlog(operLog);
}
/**
* 查询系统操作日志集合
*
* @param pageUtilEntity 分页参数
* @return 操作日志集合
*/
public List<OperLog> pageInfoQueryOperLog(PageUtilEntity pageUtilEntity)
{
return operLogDao.pageInfoQuery(pageUtilEntity);
}
/**
* 批量删除系统操作日志
*
* @param ids 需要删除的数据
* @return
*/
public int batchDeleteOperLog(Long[] ids)
{
return operLogDao.batchDeleteOperLog(ids);
}
}

View File

@ -29,4 +29,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</where>
</select>
<delete id="batchDeleteLogininfor" parameterType="java.lang.String">
delete from sys_logininfor where info_id in
<foreach collection="array" item="infoId" open="(" separator="," close=")">
#{infoId}
</foreach>
</delete>
</mapper>

View File

@ -25,4 +25,20 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
values (#{operId}, #{title}, #{action}, #{method}, #{channel}, #{loginName}, #{deptName}, #{opertUrl}, #{opertIp}, #{opertParam}, #{status}, #{errorMsg})
</insert>
<select id="pageInfoQueryOperLog" parameterType="PageUtilEntity" resultMap="OperLogResult">
select * from sys_oper_log
<where>
<if test="searchValue != null">
AND login_name = #{searchValue}
</if>
</where>
</select>
<delete id="batchDeleteOperLog" parameterType="java.lang.String">
delete from sys_oper_log where oper_id in
<foreach collection="array" item="operId" open="(" separator="," close=")">
#{operId}
</foreach>
</delete>
</mapper>

View File

@ -1,7 +1,10 @@
var prefix = "/monitor/logininfor"
$(function() {
var columns = [{
var columns = [{
checkbox: true
},
{
field: 'infoId',
// 列字段名
title: '访问编号' // 列标题
@ -24,7 +27,7 @@ $(function() {
},
{
field: 'status',
title: '状态',
title: '登录状态',
align: 'center',
formatter: function(value, row, index) {
if (value == 0) {
@ -41,3 +44,26 @@ $(function() {
var url = prefix + "/list";
initTable(columns, url);
});
function batchRemove() {
var rows = getIdSelections("infoId");
if (rows.length == 0) {
layer.msg("请选择要删除的数据");
return;
}
layer.confirm("确认要删除选中的" + rows.length + "条数据吗?",{icon: 3, title:'提示'},function(index){
$.ajax({
type: 'POST',
data: { "ids": rows },
url: prefix + '/batchRemove',
success: function(r) {
if (r.code == 0) {
layer.msg(r.msg, { icon: 1, time: 1000 });
refresh();
} else {
layer.alert(r.msg, {icon: 2, title:"系统提示"});
}
}
});
});
}

View File

@ -51,7 +51,6 @@ $(function() {
},
{
title: '操作',
field: 'id',
align: 'center',
formatter: function(value, row, index) {
var d = '<a class="btn btn-warning btn-sm" href="#" title="删除" onclick="forceLogout(\'' + row.sessionId + '\')"><i class="fa fa-remove"></i></a> ';

View File

@ -0,0 +1,84 @@
var prefix = "/monitor/operlog"
$(function() {
var columns = [{
checkbox: true
},
{
field: 'operId',
// 列字段名
title: '日志编号' // 列标题
},
{
field: 'title',
title: '模块'
},
{
field: 'action',
title: '功能'
},
{
field: 'loginName',
title: '登录名称'
},
{
field: 'deptName',
title: '部门名称'
},
{
field: 'opertIp',
title: '主机'
},
{
field: 'status',
title: '操作状态',
align: 'center',
formatter: function(value, row, index) {
if (value == 0) {
return '<span class="label label-success">成功</span>';
} else if (value == 1) {
return '<span class="label label-primary">异常</span>';
}
}
},
{
field: 'operTime',
title: '操作时间'
},
{
title: '操作',
align: 'center',
formatter: function(value, row, index) {
var d = '<a class="btn btn-warning btn-sm" href="#" title="详细" onclick="view(\'' + row.operId + '\')"><i class="fa fa-search"></i></a> ';
return d;
}
}];
var url = prefix + "/list";
initTable(columns, url);
});
function view(id) {
}
function batchRemove() {
var rows = getIdSelections("operId");
if (rows.length == 0) {
layer.msg("请选择要删除的数据");
return;
}
layer.confirm("确认要删除选中的" + rows.length + "条数据吗?",{icon: 3, title:'提示'},function(index){
$.ajax({
type: 'POST',
data: { "ids": rows },
url: prefix + '/batchRemove',
success: function(r) {
if (r.code == 0) {
layer.msg(r.msg, { icon: 1, time: 1000 });
refresh();
} else {
layer.alert(r.msg, {icon: 2, title:"系统提示"});
}
}
});
});
}

View File

@ -5,6 +5,11 @@
<head th:include="include :: header"></head>
<body class="gray-bg">
<div class="wrapper wrapper-content">
<div class="btn-group hidden-xs" id="tableToolbar" role="group">
<button type="button" class="btn btn-outline btn-default" th:onclick="'javascript:batchRemove()'">
<i class="glyphicon glyphicon-trash"></i>
</button>
</div>
<table class="bootstrap-table" data-mobile-responsive="true"
data-sort-name="login_time" data-sort-order="desc">
</table>

View File

@ -12,7 +12,7 @@
</button>
-->
<button type="button" class="btn btn-outline btn-default" th:onclick="'javascript:batchForceLogout()'">
<i class="glyphicon glyphicon-trash""></i>
<i class="glyphicon glyphicon-trash"></i>
</button>
</div>

View File

@ -0,0 +1,21 @@
<!DOCTYPE html>
<html lang="zh_CN" xmlns:th="http://www.thymeleaf.org"
xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">
<div class="wrapper wrapper-content">
<div class="btn-group hidden-xs" id="tableToolbar" role="group">
<button type="button" class="btn btn-outline btn-default" th:onclick="'javascript:batchRemove()'">
<i class="glyphicon glyphicon-trash"></i>
</button>
</div>
<table class="bootstrap-table" data-mobile-responsive="true"
data-sort-name="oper_time" data-sort-order="desc">
</table>
</div>
<div th:include="include :: footer"></div>
<script type="text/javascript" src="/ruoyi/monitor/operlog/operlog.js"></script>
</body>
</html>