Authored by qinchao

用户操作记录拦截

... ... @@ -19,8 +19,6 @@
select
count(1)
from user_operate_logs
where
1=1
where 1=1
<if test="params.beginTime !=null &amp;&amp; params.beginTime !=''">
and create_time &gt;= #{params.beginTime,jdbcType=TIMESTAMP}
... ...
... ... @@ -8,13 +8,16 @@ import com.monitor.common.util.MD5Util;
import com.monitor.influxdb.mapper.UserOperateMapper;
import com.monitor.model.domain.Mail;
import com.monitor.model.domain.PageBean;
import com.monitor.model.domain.SqlOperateModel;
import com.monitor.model.domain.UserOperate;
import com.monitor.model.page.PageRequest;
import com.monitor.model.page.PageResponse;
import com.monitor.model.request.SqlOpLogsReq;
import com.monitor.model.request.UserOperateReq;
import com.monitor.model.response.BaseResponse;
import com.monitor.mysql.mapper.UserMapper;
import com.monitor.mysql.mapper.UserOperateLogMapper;
import com.monitor.user.service.UserOperateLogsServiceImpl;
import com.util.GetUsersInfoUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ... @@ -46,6 +49,9 @@ public class UserCtrl {
private UserOperateLogMapper userOperateLogMapper;
@Autowired
private UserOperateLogsServiceImpl userOperateLogsService;
@Autowired
private MailService mailService;
@Autowired
... ... @@ -213,6 +219,13 @@ public class UserCtrl {
}
@RequestMapping("/queryUserOperateLogList")
@ResponseBody
public BaseResponse<PageResponse<UserOperate>> queryUserOperateLogList( @RequestBody SqlOpLogsReq req) {
BaseResponse<PageResponse<UserOperate>> resp = userOperateLogsService.queryUserOperateLogsByPage(req);
return resp;
}
@RequestMapping("/operate")
@ResponseBody
public String operate(@RequestBody UserOperateReq userOperateReq) {
... ...
package com.monitor.user.service;
import com.monitor.model.domain.PageBean;
import com.monitor.model.domain.UserOperate;
import com.monitor.model.request.SqlOpLogsReq;
import com.monitor.model.response.BaseResponse;
import com.monitor.model.page.PageResponse;
import com.monitor.mysql.mapper.UserOperateLogMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.List;
/**
* Created by craig.qin on 2018/1/29.
*/
@Service
public class UserOperateLogsServiceImpl {
@Autowired
private UserOperateLogMapper userOperateLogMapper;
/**
* 分页查询sql操作日志
* @param request
* @return
*/
public BaseResponse<PageResponse<UserOperate>> queryUserOperateLogsByPage(SqlOpLogsReq request) {
try{
PageBean page = PageBean.initPageInfo(request.getCurrentPage(), request.getPageSize(), request);
// 先查询符合条件的总数量
int total = userOperateLogMapper.selectCount(page);
// 数量为0 直接返回
if (total == 0) {
return new BaseResponse<>();
}
// 获取列表
List<UserOperate> sqlOperateModels = userOperateLogMapper.selectByPage(page);
if (CollectionUtils.isEmpty(sqlOperateModels)) {
return new BaseResponse<>();
}
PageResponse<UserOperate> pageResp = new PageResponse<>();
pageResp.setCurrentPage(request.getCurrentPage());
pageResp.setPageSize(request.getPageSize());
pageResp.setTotal(total);
pageResp.setRows(sqlOperateModels);
return new BaseResponse<>(pageResp);
}catch(Exception e){
return new BaseResponse<>(e.getMessage());
}
}
}
... ...