Commit 183f9bd4 authored by Quxl's avatar Quxl

x

parent 52092ba6
......@@ -9,7 +9,7 @@ public interface LogService {
List<Map<String, Object>> queryLogList(String type, String username, Page page);
void saveErrorLog(String path, Throwable ex);
void saveErrorLog(String path, Object params, Throwable ex);
List<Map<String, Object>> queryErrorList(Page page);
......
......@@ -7,6 +7,7 @@ import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.alibaba.fastjson.JSON;
import com.egolm.common.StringUtil;
import com.egolm.common.jdbc.JdbcTemplate;
import com.egolm.common.jdbc.Page;
......@@ -29,10 +30,11 @@ public class LogServiceImpl implements LogService {
}
@Override
public void saveErrorLog(String path, Throwable ex) {
public void saveErrorLog(String path, Object params, Throwable ex) {
Fc_logs_error error = new Fc_logs_error();
error.setTitle(ex.getMessage());
error.setPath(path);
error.setParams(JSON.toJSONString(params));
error.setError(this.toStackString(ex).toString());
error.setCreate_time(new Date());
jdbcTemplate.save(error);
......
......@@ -20,6 +20,9 @@ public class Fc_logs_error implements java.io.Serializable {
@Column(columnDefinition="varchar(255)")
private String path;
@Column(columnDefinition="text")
private String params;
@Column(columnDefinition="text")
private String title;
......@@ -46,6 +49,14 @@ public class Fc_logs_error implements java.io.Serializable {
return path;
}
public void setParams(String params) {
this.params = params;
}
public String getParams() {
return params;
}
public void setTitle(String title) {
this.title = title;
}
......
......@@ -29,7 +29,7 @@ public class Fc_member_film implements java.io.Serializable {
@Column(columnDefinition="varchar(255) COMMENT '中文片名'")
private String cn_name;
@Column(columnDefinition="tinyint(10) COMMENT '类型 1 电影 2电视'")
@Column(columnDefinition="tinyint(10) COMMENT '类型 1 电影 2电视'")
private Integer type;
@Column(columnDefinition="bigint(20) COMMENT '影片内容分组id'")
......
......@@ -15,10 +15,10 @@ public class Fc_member_film_ext implements java.io.Serializable {
@Column(columnDefinition="int(11) COMMENT '影片ID'")
private Integer id;
@Column(columnDefinition="varchar(255) COMMENT '影片简介中文'")
@Column(columnDefinition="text COMMENT '影片简介中文'")
private String synopsis_cn;
@Column(columnDefinition="varchar(255) COMMENT '影片简介英文'")
@Column(columnDefinition="text COMMENT '影片简介英文'")
private String synopsis_en;
@Column(columnDefinition="varchar(255) COMMENT '导演中文名'")
......@@ -27,10 +27,10 @@ public class Fc_member_film_ext implements java.io.Serializable {
@Column(columnDefinition="varchar(255) COMMENT '导演英文名'")
private String director_en;
@Column(columnDefinition="varchar(255) COMMENT '导演中文简介'")
@Column(columnDefinition="text COMMENT '导演中文简介'")
private String director_biography_cn;
@Column(columnDefinition="varchar(255) COMMENT '导演英文简介'")
@Column(columnDefinition="text COMMENT '导演英文简介'")
private String director_biography_en;
@Column(columnDefinition="varchar(255) COMMENT '制片人中文名'")
......
......@@ -18,7 +18,7 @@ public class Fc_review_record_ext implements java.io.Serializable {
@Column(columnDefinition="int(11) COMMENT '评委评审记录ID'")
private Integer record_id;
@Column(columnDefinition="varchar(255) COMMENT '获奖标题 例如: 最佳男演员-张三'")
@Column(columnDefinition="varchar(255) COMMENT '获奖标题 例如: 最佳男演员-张三'")
private String ext_title;
@Column(columnDefinition="double(10,2) COMMENT '奖项评分'")
......
......@@ -43,7 +43,7 @@ public class ExceptionHandler implements HandlerExceptionResolver {
if(displayInLog) {
logger.error("", ex);
try {
logService.saveErrorLog(request.getRequestURI().replace(request.getContextPath(), ""), ex);
logService.saveErrorLog(request.getRequestURI().replace(request.getContextPath(), ""), request.getParameterMap(), ex);
} catch (Exception e) {
logger.error("错误日志保存失败", e);
}
......
......@@ -22,6 +22,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
import com.egolm.common.StringUtil;
import com.egolm.film.config.interceptor.AdminLoginInterceptor;
import com.egolm.film.config.interceptor.LocaleInterceptor;
import com.egolm.film.config.interceptor.LogInterceptor;
import com.egolm.film.config.interceptor.MemberLoginInterceptor;
import com.egolm.film.config.interceptor.UserLoginInterceptor;
import com.fasterxml.jackson.databind.ObjectMapper;
......@@ -41,8 +42,12 @@ public class WebMvcConfig extends WebMvcConfigurerAdapter {
@Autowired
private LocaleInterceptor localeSessionInterceptor;
@Autowired
private LogInterceptor logInterceptor;
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(logInterceptor).addPathPatterns("/**");
registry.addInterceptor(localeSessionInterceptor).addPathPatterns("/**");
registry.addInterceptor(adminLoginInterceptor).addPathPatterns("/admin/**").excludePathPatterns("/admin/login");
registry.addInterceptor(userLoginInterceptor).addPathPatterns("/user/**").excludePathPatterns("/user/login");
......
package com.egolm.film.config.interceptor;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import com.alibaba.fastjson.JSON;
import com.egolm.common.jdbc.JdbcTemplate;
import com.egolm.common.web.ServletUtil;
import com.egolm.film.api.service.AdminTokenService;
import com.egolm.film.api.service.MemberTokenService;
import com.egolm.film.api.service.UserTokenService;
import com.egolm.film.model.LoginToken;
@Component
public class LogInterceptor extends HandlerInterceptorAdapter {
@Autowired
JdbcTemplate jdbcTemplate;
@Autowired
MemberTokenService memberTokenService;
@Autowired
AdminTokenService adminTokenService;
@Autowired
UserTokenService userTokenService;
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
Date now = new Date();
String path = request.getRequestURI().replace(request.getContextPath(), "");
String prefix = path.split("/")[1];
Map<String, Object> tokenMap = new HashMap<String, Object>();
LoginToken token = null;
if(prefix.equals("admin")) {
token = adminTokenService.getToken();
} else if(prefix.equals("user")) {
token = userTokenService.getToken();
} else if(prefix.equals("member")) {
token = memberTokenService.getToken();
} else {
tokenMap.put("memberToken", memberTokenService.getToken());
tokenMap.put("adminToken", adminTokenService.getToken());
tokenMap.put("userToken", userTokenService.getToken());
}
String content = JSON.toJSONString(request.getParameterMap());
String ip = ServletUtil.remoteIp(request);
String user_agent = request.getHeader("User-Agent");
String sql = "insert into fc_logs (type, loginid, prefix, path, ip, content, user_agent, create_time) values (?, ?, ?, ?, ?, ?, ?, ?)";
Object[] objs = new Object[]{prefix, token == null ? JSON.toJSONString(tokenMap) : String.valueOf(token.getId()), prefix, path, ip, content, user_agent, now};
jdbcTemplate.executeUpdate(sql, objs);
super.afterCompletion(request, response, handler, ex);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment