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