Authored by qinchao

用户操作记录拦截

... ... @@ -10,10 +10,18 @@ import java.io.Serializable;
@Data
public class UserOperate implements Serializable{
//用户名
private String user;
//操作uri
private String operate;
//操作uri名称
private String operateDesc;
//操作参数
private String params;
//操作时间
private String time;
private java.util.Date ts;
}
... ...
package com.model;
import lombok.Data;
/**
* Created by craig.qin on 2018/1/29.
*/
@Data
public class UserOperateLog {
private int id;
//用户名
private String userName;
//操作uri
private String operate;
//操作uri名称
private String operateDesc;
//操作参数
private String params;
//操作时间
private java.util.Date createTime;
}
... ...
package com.monitor.mysql.mapper;
import com.model.UserOperateLog;
import com.monitor.model.domain.PageBean;
import com.monitor.model.domain.UserOperate;
import java.util.List;
/**
* Created by craig.qin 2018/1/29
*/
public interface UserOperateLogMapper {
int selectCount(PageBean page);//查询总数量
List<UserOperate> selectByPage(PageBean page);
int insert(UserOperateLog userOperateLog);
}
... ...
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.monitor.mysql.mapper.UserOperateLogMapper" >
<resultMap id="BaseResultMap" type="com.model.UserOperateLog" >
<id column="id" property="id" jdbcType="INTEGER" />
<result column="user_name" property="userName" jdbcType="VARCHAR" />
<result column="operate" property="operate" jdbcType="VARCHAR" />
<result column="operate_desc" property="operateDesc" jdbcType="VARCHAR" />
<result column="params" property="params" jdbcType="VARCHAR" />
<result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
</resultMap>
<sql id="Base_Column_List" >
id, user_name, operate,operate_desc,params,create_time
</sql>
<select id="selectCount" resultType="java.lang.Integer">
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}
</if>
<if test="params.endTime !=null &amp;&amp; params.endTime !=''">
and create_time &lt;= #{params.endTime,jdbcType=TIMESTAMP}
</if>
</select>
<select id="selectByPage" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from user_operate_logs
where 1=1
<if test="params.beginTime !=null &amp;&amp; params.beginTime !=''">
and create_time &gt;= #{params.beginTime,jdbcType=TIMESTAMP}
</if>
<if test="params.endTime !=null &amp;&amp; params.endTime !=''">
and create_time &lt;= #{params.endTime,jdbcType=TIMESTAMP}
</if>
order by id desc
limit #{startIndex},#{pageSize}
</select>
<insert id="insert" parameterType="com.model.UserOperateLog" >
insert into user_operate_logs
(user_name, operate,operate_desc,params,create_time)
values
(#{userName,jdbcType=VARCHAR},#{operate,jdbcType=VARCHAR},#{operateDesc,jdbcType=VARCHAR},
#{params,jdbcType=VARCHAR},#{createTime,jdbcType=TIMESTAMP})
</insert>
</mapper>
\ No newline at end of file
... ...
package com.monitor.user.ctrl;
import com.model.User;
import com.model.UserOperateLog;
import com.monitor.common.service.AppRedisService;
import com.monitor.common.service.MailService;
import com.monitor.common.util.MD5Util;
... ... @@ -13,6 +14,7 @@ import com.monitor.model.page.PageResponse;
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.util.GetUsersInfoUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ... @@ -35,8 +37,13 @@ public class UserCtrl {
@Autowired
UserMapper userMapper;
/*
@Autowired
UserOperateMapper userOperateMapper;
*/
@Autowired
private UserOperateLogMapper userOperateLogMapper;
@Autowired
private MailService mailService;
... ... @@ -211,7 +218,14 @@ public class UserCtrl {
public String operate(@RequestBody UserOperateReq userOperateReq) {
List<UserOperate> list = userOperateReq.getList();
for (UserOperate userOperate : list) {
userOperateMapper.insert(userOperate);
// userOperateMapper.insert(userOperate);
UserOperateLog userOperateLog=new UserOperateLog();
userOperateLog.setUserName(userOperate.getUser());
userOperateLog.setOperate(userOperate.getOperate());
userOperateLog.setOperateDesc(userOperate.getOperateDesc());
userOperateLog.setParams(userOperate.getParams());
userOperateLog.setCreateTime(userOperate.getTs());
userOperateLogMapper.insert(userOperateLog);
}
return "";
}
... ...