hjg
2024-01-20 4a3404efc438b16044fd9170814e6545a3f86fae
提交 | 用户 | 时间
58d006 1 package com.mandi.springmvc.logs;
A 2
3 import javax.servlet.http.HttpServletRequest;
4 import javax.servlet.http.HttpServletResponse;
5
6 import org.springframework.context.ApplicationContext;
7 import org.springframework.web.method.HandlerMethod;
8 import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
9
10 import com.mandi.common.Jacksonmethod;
11 import com.mandi.common.SessionMethod;
12 import com.mandi.common.SpringContext;
13 import com.mandi.system.service.IMOpLogServie;
14 import com.mandi.system.service.impl.MOpLogServie;
15 import com.mandi.system.persist.Login;
16 import com.mandi.system.persist.ModuleEnum;
17
18 public class LogsInterceptor extends HandlerInterceptorAdapter {
19
20     @Override
21     public boolean preHandle(HttpServletRequest r,
22             HttpServletResponse re, Object handler) throws Exception {
23         if(handler.getClass().isAssignableFrom(HandlerMethod.class)){
24             OpLogs oplog= ((HandlerMethod)handler).getMethodAnnotation(OpLogs.class);
25             if(oplog==null){
26                 return true;
27             }
28             ApplicationContext ac= SpringContext.getAppContext();
29             if(ac==null){
30                 return true;
31             }
32             IMOpLogServie imlser=ac.getBean(MOpLogServie.class);
33             Login l=SessionMethod.getlogin(r.getSession());
34             if(l==null){
35                 l=new Login();
36                 l.setUsername("未登录");
37                 l.setWorkername(r.getRemoteAddr());
38                 l.setDepartname("不知道");
39             }
40             String name=oplog.name();
41             ModuleEnum module=oplog.module();
42             String note="";
43             try{
44                 note=Jacksonmethod.tojson(r.getParameterMap(), false);
45                 imlser.insert(l, module, name, note);
46             }catch(Exception e){
47                 e.printStackTrace();
48             }
49             
50         }
51         
52         return true;
53     }
54     
55 }