Commit a48b99e0 authored by Quxl's avatar Quxl

x

parent 36ab5c1f
package com.egolm.oms; package com.egolm.oms;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching; import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.transaction.annotation.EnableTransactionManagement; import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@EnableCaching
@EnableSwagger2 @EnableAsync
@SpringBootApplication @EnableCaching
@EnableTransactionManagement @EnableSwagger2
public class OmsApplication { @SpringBootApplication
@EnableTransactionManagement
private static ApplicationContext applicationContext; public class OmsApplication {
public static void main(String[] args) { private static ApplicationContext applicationContext;
System.setProperty("java.io.tmpdir", "temp");
applicationContext = SpringApplication.run(OmsApplication.class, args); public static void main(String[] args) {
} System.setProperty("java.io.tmpdir", "temp");
applicationContext = SpringApplication.run(OmsApplication.class, args);
public static ApplicationContext getApplicationContext() { }
return applicationContext;
} public static ApplicationContext getApplicationContext() {
return applicationContext;
public static Object getBean(String name){ }
return getApplicationContext().getBean(name);
public static Object getBean(String name){
} return getApplicationContext().getBean(name);
public static <T> T getBean(Class<T> clazz){ }
return getApplicationContext().getBean(clazz);
} public static <T> T getBean(Class<T> clazz){
return getApplicationContext().getBean(clazz);
public static <T> T getBean(String name, Class<T> clazz){ }
return getApplicationContext().getBean(name, clazz);
} public static <T> T getBean(String name, Class<T> clazz){
return getApplicationContext().getBean(name, clazz);
} }
}
package com.egolm.oms.config.interceptor; package com.egolm.oms.config.interceptor;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component; import org.springframework.scheduling.annotation.Async;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; 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.alibaba.fastjson.JSON;
import com.egolm.common.web.ServletUtil; import com.egolm.common.jdbc.JdbcTemplate;
import com.egolm.common.web.ServletUtil;
@Component
public class LogInterceptor extends HandlerInterceptorAdapter { @Component
public class LogInterceptor extends HandlerInterceptorAdapter {
@Value("${log.isOpen}")
private Boolean isOpen; @Value("${log.isOpen}")
private Boolean isOpen;
@Override
public boolean preHandle(HttpServletRequest req, HttpServletResponse resp, Object handler) throws Exception { @Override
this.exec(req); public boolean preHandle(HttpServletRequest req, HttpServletResponse resp, Object handler) throws Exception {
return super.preHandle(req, resp, handler); this.exec(req);
} return super.preHandle(req, resp, handler);
}
@Autowired
@Qualifier("log") @Autowired
private JdbcTemplate jdbcTemplate; @Qualifier("log")
private JdbcTemplate jdbcTemplate;
private void exec(HttpServletRequest req) {
if(isOpen) { @Async
try { private void exec(HttpServletRequest req) {
String contextPath = req.getContextPath(); if(isOpen) {
String uri = req.getRequestURI().substring(contextPath.length()); try {
String remoteIp = ServletUtil.remoteIp(req); String contextPath = req.getContextPath();
String params = JSON.toJSONString(req.getParameterMap()); String uri = req.getRequestURI().substring(contextPath.length());
Map<String, Object> map = new HashMap<String,Object>(); String remoteIp = ServletUtil.remoteIp(req);
map.put("sProjectID", "ORDER"); String params = JSON.toJSONString(req.getParameterMap());
map.put("sURI", uri); Map<String, Object> map = new HashMap<String,Object>();
map.put("sClientIP", remoteIp); map.put("sProjectID", "ORDER");
map.put("sParams", params); map.put("sURI", uri);
map.put("dCreateTime", new Date()); map.put("sClientIP", remoteIp);
jdbcTemplate.save("tLog", map); map.put("sParams", params);
} catch (Throwable e) { map.put("dCreateTime", new Date());
e.printStackTrace(); jdbcTemplate.save("tLog", map);
} } catch (Throwable e) {
} e.printStackTrace();
} }
}
} }
}
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