Commit 42e4ee18 authored by Quxl's avatar Quxl

x

parent 25180b48
...@@ -9,4 +9,6 @@ public interface LogService { ...@@ -9,4 +9,6 @@ public interface LogService {
List<Map<String, Object>> queryLogList(String type, String username, Page page); List<Map<String, Object>> queryLogList(String type, String username, Page page);
void saveErrorLog(Throwable ex);
} }
package com.egolm.film.api.service.impl; package com.egolm.film.api.service.impl;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -10,6 +11,7 @@ import com.egolm.common.StringUtil; ...@@ -10,6 +11,7 @@ import com.egolm.common.StringUtil;
import com.egolm.common.jdbc.JdbcTemplate; import com.egolm.common.jdbc.JdbcTemplate;
import com.egolm.common.jdbc.Page; import com.egolm.common.jdbc.Page;
import com.egolm.film.api.service.LogService; import com.egolm.film.api.service.LogService;
import com.egolm.film.bean.Fc_error;
import com.egolm.film.util.SqlWhere; import com.egolm.film.util.SqlWhere;
@Service @Service
...@@ -26,4 +28,18 @@ public class LogServiceImpl implements LogService { ...@@ -26,4 +28,18 @@ public class LogServiceImpl implements LogService {
return jdbcTemplate.limit(sql, page, where.getObjectArray()); return jdbcTemplate.limit(sql, page, where.getObjectArray());
} }
@Override
public void saveErrorLog(Throwable ex) {
StringBuffer stack = new StringBuffer();
stack.append(ex.getMessage()).append("\n");
StackTraceElement[] elms = ex.getStackTrace();
for(StackTraceElement elm : elms) {
stack.append(elm.getClassName() + "." + elm.getMethodName() + "(" + elm.getFileName() + " " + elm.getLineNumber() + ")").append("\n");
}
Fc_error error = new Fc_error();
error.setError(stack.toString());
error.setCreate_time(new Date());
jdbcTemplate.save(error);
}
} }
...@@ -29,7 +29,7 @@ public class Fc_review implements java.io.Serializable { ...@@ -29,7 +29,7 @@ public class Fc_review implements java.io.Serializable {
@Column(columnDefinition="int(11) COMMENT '评委分配状态 0未分配评委 1已分配评委评选中'") @Column(columnDefinition="int(11) COMMENT '评委分配状态 0未分配评委 1已分配评委评选中'")
private Integer allot_state; private Integer allot_state;
@Column(columnDefinition="int(11) COMMENT '审片结论 1通过 2否决 3参赛 4参赛备选 5参展'") @Column(columnDefinition="int(11) COMMENT '审片结论 0未评选 1通过 2否决 3参赛 4参赛备选 5参展'")
private Integer review_state; private Integer review_state;
@Column(columnDefinition="int(11) COMMENT '评选状态 0未评选 1有争议 2管理员分配 3审片完成'") @Column(columnDefinition="int(11) COMMENT '评选状态 0未评选 1有争议 2管理员分配 3审片完成'")
......
...@@ -4,21 +4,27 @@ import javax.servlet.http.HttpServletRequest; ...@@ -4,21 +4,27 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerExceptionResolver; import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.json.MappingJackson2JsonView; import org.springframework.web.servlet.view.json.MappingJackson2JsonView;
import com.egolm.common.bean.Rjx; import com.egolm.common.bean.Rjx;
import com.egolm.film.api.service.LogService;
@Component @Component
public class ExceptionHandler implements HandlerExceptionResolver { public class ExceptionHandler implements HandlerExceptionResolver {
private static final Logger logger = Logger.getLogger(ExceptionHandler.class); private static final Logger logger = Logger.getLogger(ExceptionHandler.class);
@Autowired
LogService logService;
@Override @Override
public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) { public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
boolean displayInLog = true; boolean displayInLog = true;
logService.saveErrorLog(ex);
ModelAndView mav = new ModelAndView(new MappingJackson2JsonView()); ModelAndView mav = new ModelAndView(new MappingJackson2JsonView());
try { try {
response.setContentType("application/json"); response.setContentType("application/json");
...@@ -30,7 +36,7 @@ public class ExceptionHandler implements HandlerExceptionResolver { ...@@ -30,7 +36,7 @@ public class ExceptionHandler implements HandlerExceptionResolver {
logger.debug(ex.getMessage()); logger.debug(ex.getMessage());
} }
} else { } else {
mav.addAllObjects(Rjx.jsonErr().setMessage("未处理异常[" + ex.getClass().getName() + ":" + ex.getMessage() + "]")); mav.addAllObjects(Rjx.jsonErr().setMessage("未处理异常"));
} }
} catch (Exception e) { } catch (Exception e) {
mav.addAllObjects(Rjx.jsonErr().setMessage("异常处理失败")); mav.addAllObjects(Rjx.jsonErr().setMessage("异常处理失败"));
......
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