Commit e15e7187 by zhanghj

V1.0.0--完善操作日志相关接口和功能

git-svn-id: svn://192.168.3.233/frms/code/car-service/trunk/car-service@17331 aeb6102e-e053-11e5-9fec-f9ebc45caf4b
1 parent 1aedcf17
...@@ -21,6 +21,7 @@ import org.springframework.web.context.request.ServletRequestAttributes; ...@@ -21,6 +21,7 @@ import org.springframework.web.context.request.ServletRequestAttributes;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.glsx.common.annotation.Log; import com.glsx.common.annotation.Log;
import com.glsx.common.constants.ResultObject;
import com.glsx.common.feign.client.OperateLogClient; import com.glsx.common.feign.client.OperateLogClient;
import com.glsx.common.pojo.OperateLog; import com.glsx.common.pojo.OperateLog;
import com.glsx.common.utils.UserUtils; import com.glsx.common.utils.UserUtils;
...@@ -37,13 +38,13 @@ import com.glsx.common.utils.UserUtils; ...@@ -37,13 +38,13 @@ import com.glsx.common.utils.UserUtils;
@Component @Component
@Aspect @Aspect
public class WebRequestLogAspect { public class LogAspect {
@Autowired @Autowired
private OperateLogClient operateLogClient; private OperateLogClient operateLogClient;
private static Logger logger = LoggerFactory private static Logger logger = LoggerFactory
.getLogger(WebRequestLogAspect.class); .getLogger(LogAspect.class);
private ThreadLocal<OperateLog> tlocal = new ThreadLocal<OperateLog>(); private ThreadLocal<OperateLog> tlocal = new ThreadLocal<OperateLog>();
...@@ -104,6 +105,7 @@ public class WebRequestLogAspect { ...@@ -104,6 +105,7 @@ public class WebRequestLogAspect {
@AfterReturning(returning = "result", pointcut = "webRequestLog()") @AfterReturning(returning = "result", pointcut = "webRequestLog()")
public void doAfterReturning(Object result) { public void doAfterReturning(Object result) {
try { try {
ResultObject res = (ResultObject) result;
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder
.getRequestAttributes(); .getRequestAttributes();
HttpServletRequest request = attributes.getRequest(); HttpServletRequest request = attributes.getRequest();
...@@ -112,7 +114,8 @@ public class WebRequestLogAspect { ...@@ -112,7 +114,8 @@ public class WebRequestLogAspect {
OperateLog optLog = tlocal.get(); OperateLog optLog = tlocal.get();
String username = UserUtils.getUserName(request); String username = UserUtils.getUserName(request);
optLog.setCreateBy(username); optLog.setCreateBy(username);
optLog.setOperateStatus(res.getCode());
optLog.setRemark(res.getMessage());
logger.debug("uri=" + optLog.getUri() + "; methodName=" logger.debug("uri=" + optLog.getUri() + "; methodName="
+ optLog.getMethodName() + "; ip=" + optLog.getIp() + optLog.getMethodName() + "; ip=" + optLog.getIp()
+ "; createBy=" + optLog.getCreateBy() + "; params=" + "; createBy=" + optLog.getCreateBy() + "; params="
......
package com.glsx.common.constants; package com.glsx.common.constants;
import java.io.Serializable;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
/** /**
...@@ -11,7 +13,12 @@ import com.alibaba.fastjson.JSON; ...@@ -11,7 +13,12 @@ import com.alibaba.fastjson.JSON;
* @date 2018年7月11日 上午10:26:46 * @date 2018年7月11日 上午10:26:46
* @version * @version
*/ */
public class ResultObject { public class ResultObject implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
private int code;//返回码 200成功,500系统异常 private int code;//返回码 200成功,500系统异常
private String message;//消息 private String message;//消息
......
package com.glsx.common.feign.client; package com.glsx.common.feign.client;
import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
...@@ -22,6 +23,6 @@ import com.glsx.common.pojo.OperateLog; ...@@ -22,6 +23,6 @@ import com.glsx.common.pojo.OperateLog;
@FeignClient(name="car-service-manager", configuration=FeignConfig.class) @FeignClient(name="car-service-manager", configuration=FeignConfig.class)
public interface OperateLogClient { public interface OperateLogClient {
@RequestMapping(method = RequestMethod.GET, value = "/carservice/manager/operateLog/save") @RequestMapping(method = RequestMethod.POST, value = "/carservice/manager/operateLog/save")
JSONObject save(OperateLog optLog); JSONObject save(@RequestBody OperateLog optLog);
} }
...@@ -15,6 +15,10 @@ import java.util.Date; ...@@ -15,6 +15,10 @@ import java.util.Date;
public class OperateLog implements Serializable{ public class OperateLog implements Serializable{
/** /**
*
*/
private static final long serialVersionUID = 1L;
/**
* id * id
*/ */
private Integer id; private Integer id;
...@@ -27,9 +31,9 @@ public class OperateLog implements Serializable{ ...@@ -27,9 +31,9 @@ public class OperateLog implements Serializable{
*/ */
private String operateType; private String operateType;
/** /**
* 操作状态,字典决定,成功、失败、未知 * 操作状态
*/ */
private String operateStatus; private Integer operateStatus;
/** /**
* 请求路径 * 请求路径
*/ */
...@@ -84,6 +88,11 @@ public class OperateLog implements Serializable{ ...@@ -84,6 +88,11 @@ public class OperateLog implements Serializable{
* 查询:结束时间 * 查询:结束时间
*/ */
private String endDate; private String endDate;
/**
* 操作类型名称
*
*/
private String operateTypeName;
public Integer getId() { public Integer getId() {
return id; return id;
...@@ -103,10 +112,10 @@ public class OperateLog implements Serializable{ ...@@ -103,10 +112,10 @@ public class OperateLog implements Serializable{
public void setOperateType(String operateType) { public void setOperateType(String operateType) {
this.operateType = operateType; this.operateType = operateType;
} }
public String getOperateStatus() { public Integer getOperateStatus() {
return operateStatus; return operateStatus;
} }
public void setOperateStatus(String operateStatus) { public void setOperateStatus(Integer operateStatus) {
this.operateStatus = operateStatus; this.operateStatus = operateStatus;
} }
public String getIp() { public String getIp() {
...@@ -187,5 +196,11 @@ public class OperateLog implements Serializable{ ...@@ -187,5 +196,11 @@ public class OperateLog implements Serializable{
public void setLogStatus(Integer logStatus) { public void setLogStatus(Integer logStatus) {
this.logStatus = logStatus; this.logStatus = logStatus;
} }
public String getOperateTypeName() {
return operateTypeName;
}
public void setOperateTypeName(String operateTypeName) {
this.operateTypeName = operateTypeName;
}
} }
...@@ -53,7 +53,7 @@ public class OperateLogController extends BaseController{ ...@@ -53,7 +53,7 @@ public class OperateLogController extends BaseController{
* *
*/ */
@RequestMapping(value="/save", method=RequestMethod.POST) @RequestMapping(value="/save", method=RequestMethod.POST)
public ResultObject save(OperateLog operateLog){ public ResultObject save(@RequestBody OperateLog operateLog){
int num = operateLogService.save(operateLog); int num = operateLogService.save(operateLog);
if (num > 0) { if (num > 0) {
return new ResultObject(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMsg()); return new ResultObject(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMsg());
......
...@@ -43,7 +43,7 @@ public class OperateLogServiceImpl implements OperateLogService { ...@@ -43,7 +43,7 @@ public class OperateLogServiceImpl implements OperateLogService {
@Override @Override
public List<OperateLog> list(OperateLog operateLog, Page page) { public List<OperateLog> list(OperateLog operateLog, Page page) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
PageHelper.startPage(page.getPageSize(), page.getPageSize()); PageHelper.startPage(page.getPageIndex(), page.getPageSize());
return operateLogDao.list(operateLog); return operateLogDao.list(operateLog);
} }
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<id column="id" jdbcType="INTEGER" property="id" /> <id column="id" jdbcType="INTEGER" property="id" />
<result column="menu_name" jdbcType="VARCHAR" property="menuName" /> <result column="menu_name" jdbcType="VARCHAR" property="menuName" />
<result column="operate_type" jdbcType="VARCHAR" property="operateType" /> <result column="operate_type" jdbcType="VARCHAR" property="operateType" />
<result column="operate_status" jdbcType="VARCHAR" property="operateStatus" /> <result column="operate_status" jdbcType="INTEGER" property="operateStatus" />
<result column="uri" jdbcType="VARCHAR" property="uri" /> <result column="uri" jdbcType="VARCHAR" property="uri" />
<result column="ip" jdbcType="VARCHAR" property="ip" /> <result column="ip" jdbcType="VARCHAR" property="ip" />
<result column="address" jdbcType="VARCHAR" property="address" /> <result column="address" jdbcType="VARCHAR" property="address" />
...@@ -14,11 +14,12 @@ ...@@ -14,11 +14,12 @@
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" /> <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
<result column="update_by" jdbcType="VARCHAR" property="updateBy" /> <result column="update_by" jdbcType="VARCHAR" property="updateBy" />
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" /> <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
<result column="operateTypeName" jdbcType="VARCHAR" property="operateTypeName" />
</resultMap> </resultMap>
<sql id="base_Column"> <sql id="base_Column">
id, menu_name, operate_type, operate_status, uri, ip, address, sol.id, menu_name, operate_type, operate_status, uri, ip, address,
remark, create_by, create_time, update_by, update_time sol.remark, sol.create_by, sol.create_time, sol.update_by, sol.update_time
</sql> </sql>
<select id="list" parameterType="com.glsx.common.pojo.OperateLog" resultMap="baseResultMap"> <select id="list" parameterType="com.glsx.common.pojo.OperateLog" resultMap="baseResultMap">
...@@ -30,50 +31,52 @@ ...@@ -30,50 +31,52 @@
</if> </if>
select select
<include refid="base_Column" /> <include refid="base_Column" />
from sys_operate_log ,sdd.data_value as operateTypeName
from sys_operate_log sol
left join sys_dict_data sdd on sol.operate_type = sdd.data_key
<where> <where>
dict_status != 2 log_status = 1
<if test="menuName != null and menuName != ''"> <if test="menuName != null and menuName != ''">
and menu_name like #{menuName} and menu_name like #{menuName}
</if> </if>
<if test="createBy != null and createBy != ''"> <if test="createBy != null and createBy != ''">
and create_by like #{createBy} and sol.create_by like #{createBy}
</if> </if>
<if test="operateStatus != null and operateStatus != ''"> <if test="operateType != null and operateType != ''">
and operate_status = #{operateStatus} and operate_type = #{operateType}
</if> </if>
<if test="beginDate != null"> <if test="beginDate != null">
and DATE_FORMAT(create_time, '%Y-%m-%d') &gt;= #{beginDate} and DATE_FORMAT(sol.create_time, '%Y-%m-%d') &gt;= #{beginDate}
</if> </if>
<if test="endDate != null"> <if test="endDate != null">
and DATE_FORMAT(create_time, '%Y-%m-%d') &lt;= #{endDate} and DATE_FORMAT(sol.create_time, '%Y-%m-%d') &lt;= #{endDate}
</if> </if>
</where> </where>
order by create_time desc, id asc order by sol.create_time desc, sol.id asc
</select> </select>
<insert id="save" parameterType="com.glsx.common.pojo.OperateLog" useGeneratedKeys="true"> <insert id="save" parameterType="com.glsx.common.pojo.OperateLog" useGeneratedKeys="true">
insert into sys_operate_log insert into sys_operate_log
<trim prefix="(" suffix=")" suffixOverrides=","> <trim prefix="(" suffix=")" suffixOverrides=",">
<if test="menuName != null"> <if test="menuName != null and menuName != ''">
menu_name, menu_name,
</if> </if>
<if test="operateType != null"> <if test="operateType != null and operateType != ''">
operate_type, operate_type,
</if> </if>
<if test="operateStatus != null"> <if test="operateStatus != null">
operate_status, operate_status,
</if> </if>
<if test="uri != null"> <if test="uri != null and uri != ''">
uri, uri,
</if> </if>
<if test="ip != null"> <if test="ip != null and ip != ''">
ip, ip,
</if> </if>
<if test="address != null"> <if test="address != null and address != ''">
address, address,
</if> </if>
<if test="remark != null"> <if test="remark != null and remark != ''">
remark, remark,
</if> </if>
<if test="createBy != null"> <if test="createBy != null">
...@@ -90,25 +93,25 @@ ...@@ -90,25 +93,25 @@
</if> </if>
</trim> </trim>
<trim prefix="values (" suffix=")" suffixOverrides=","> <trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="menuName != null"> <if test="menuName != null and menuName != ''">
#{menuName,jdbcType=VARCHAR}, #{menuName,jdbcType=VARCHAR},
</if> </if>
<if test="operateType != null"> <if test="operateType != null and operateType != ''">
#{operateType,jdbcType=VARCHAR}, #{operateType,jdbcType=VARCHAR},
</if> </if>
<if test="operateStatus != null"> <if test="operateStatus != null">
#{operateStatus,jdbcType=VARCHAR}, #{operateStatus,jdbcType=INTEGER},
</if> </if>
<if test="uri != null"> <if test="uri != null and uri != ''">
#{uri,jdbcType=VARCHAR}, #{uri,jdbcType=VARCHAR},
</if> </if>
<if test="ip != null"> <if test="ip != null and ip != ''">
#{ip,jdbcType=VARCHAR}, #{ip,jdbcType=VARCHAR},
</if> </if>
<if test="address != null"> <if test="address != null and address != ''">
#{address,jdbcType=VARCHAR}, #{address,jdbcType=VARCHAR},
</if> </if>
<if test="remark != null"> <if test="remark != null and remark != ''">
#{remark,jdbcType=VARCHAR}, #{remark,jdbcType=VARCHAR},
</if> </if>
<if test="createBy != null"> <if test="createBy != null">
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!