提交 6a1a6460 authored 作者: inroi's avatar inroi

微调

上级 5a027702
......@@ -32,6 +32,7 @@ public class LogAop {
private Logger log = LoggerFactory.getLogger(this.getClass());
@Pointcut(value = "@annotation(com.shr.annotion.AccessLog)")
public void cutService() {
}
......@@ -67,7 +68,6 @@ public class LogAop {
LogManager.me().executeLog(LogTaskFactory.log(content, systemType, new Gson().toJson(result)));
}
private String getSystemType(ProceedingJoinPoint point) {
Object[] args = point.getArgs();
Object[] arguments = new Object[args.length];
......
......@@ -15,7 +15,6 @@ public class HttpContext {
/**
* 获取当前请求的Request对象
*
*/
public static HttpServletRequest getRequest() {
ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
......@@ -28,7 +27,6 @@ public class HttpContext {
/**
* 获取当前请求的Response对象
*
*/
public static HttpServletResponse getResponse() {
ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
......@@ -39,4 +37,5 @@ public class HttpContext {
}
}
}
......@@ -10,6 +10,7 @@ import org.springframework.context.ApplicationContextAware;
* @author Inori
*/
public class SpringContextHolder implements ApplicationContextAware {
private static ApplicationContext applicationContext;
......@@ -18,26 +19,22 @@ public class SpringContextHolder implements ApplicationContextAware {
SpringContextHolder.applicationContext = applicationContext;
}
public static ApplicationContext getApplicationContext() {
assertApplicationContext();
return applicationContext;
}
@SuppressWarnings("unchecked")
public static <T> T getBean(String beanName) {
assertApplicationContext();
return (T) applicationContext.getBean(beanName);
}
public static <T> T getBean(Class<T> requiredType) {
assertApplicationContext();
return applicationContext.getBean(requiredType);
}
private static void assertApplicationContext() {
if (SpringContextHolder.applicationContext == null) {
throw new RuntimeException("applicationContext属性为null,请检查是否注入了SpringContextHolder!");
......
......@@ -80,4 +80,6 @@ public class RestResponse {
public void setData(Object data) {
this.data = data;
}
}
......@@ -13,6 +13,7 @@ public class ShrException extends RuntimeException {
*/
private Integer code;
public ShrException(String message) {
super(message);
}
......
......@@ -31,6 +31,7 @@ public class BlogExceptionHandler {
private static final Logger log = LoggerFactory.getLogger(BlogExceptionHandler.class);
/**
* 参数校验异常
*/
......@@ -50,7 +51,6 @@ public class BlogExceptionHandler {
return RestResponse.fail(errorMsg);
}
/**
* 运行时异常
*/
......@@ -63,7 +63,6 @@ public class BlogExceptionHandler {
return new ErrorResponseData(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase(), request.getRequestURI());
}
/**
* SHR返回异常
*/
......
......@@ -12,6 +12,7 @@ import java.util.concurrent.TimeUnit;
* @author Inori
*/
public class LogManager {
/**
* 日志记录操作延时
*/
......@@ -19,7 +20,6 @@ public class LogManager {
public static LogManager logManager = new LogManager();
/**
* 异步操作记录日志的线程池
*/
......@@ -29,12 +29,10 @@ public class LogManager {
private LogManager() {
}
public static LogManager me() {
return logManager;
}
public void executeLog(TimerTask task) {
executor.schedule(task, OPERATE_DELAY_TIME, TimeUnit.MILLISECONDS);
}
......
......@@ -24,4 +24,6 @@ public class LogFactory {
log.setCreateTime(DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
return log;
}
}
......@@ -15,9 +15,12 @@ import java.util.TimerTask;
* @author Inori
*/
public class LogTaskFactory {
private static Logger logger = LoggerFactory.getLogger(LogTaskFactory.class);
private static LogMapper logMapper = SpringContextHolder.getBean(LogMapper.class);
public static TimerTask log(final String content, final String systemType, final String result) {
return new TimerTask() {
@Override
......@@ -32,4 +35,5 @@ public class LogTaskFactory {
};
}
}
......@@ -18,6 +18,7 @@ import java.util.Map;
*/
@Slf4j
public class JsonUtil {
private static final ObjectMapper MAPPER = new ObjectMapper();
......@@ -36,7 +37,6 @@ public class JsonUtil {
}
}
public static <T> T toBean(String json, Class<T> tClass) {
try {
return MAPPER.readValue(json, tClass);
......@@ -52,7 +52,6 @@ public class JsonUtil {
}
}
public static <T> String listToJson(List<T> list) {
if (null != list && list.size() > 0) {
JSONArray jsonArray = JSONArray.fromObject(list);
......@@ -61,7 +60,6 @@ public class JsonUtil {
return "";
}
public static <E> List<E> toList(String json, Class<E> eClass) {
try {
return MAPPER.readValue(json, MAPPER.getTypeFactory().constructCollectionType(List.class, eClass));
......@@ -71,7 +69,6 @@ public class JsonUtil {
}
}
public static <K, V> Map<K, V> toMap(String json, Class<K> kClass, Class<V> vClass) {
try {
return MAPPER.readValue(json, MAPPER.getTypeFactory().constructMapType(Map.class, kClass, vClass));
......@@ -81,7 +78,6 @@ public class JsonUtil {
}
}
public static <T> T nativeRead(String json, TypeReference<T> type) {
try {
return MAPPER.readValue(json, type);
......
......@@ -3,8 +3,6 @@ package com.shr.utils;
import java.util.Collection;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* 字符串工具类
......@@ -12,6 +10,7 @@ import java.util.regex.Pattern;
* @author ruoyi
*/
public class StringUtil extends org.apache.commons.lang3.StringUtils {
/**
* 空字符串
*/
......@@ -22,11 +21,6 @@ public class StringUtil extends org.apache.commons.lang3.StringUtils {
*/
private static final char SEPARATOR = '_';
/**
* 正则验证字符串是否是数字
*/
private static final Pattern NUM_PATTERN = Pattern.compile("^[0-9]*$");
/**
* 获取参数不为空值
......@@ -38,7 +32,6 @@ public class StringUtil extends org.apache.commons.lang3.StringUtils {
return value != null ? value : defaultValue;
}
/**
* * 判断一个Collection是否为空, 包含List,Set,Queue
*
......@@ -49,7 +42,6 @@ public class StringUtil extends org.apache.commons.lang3.StringUtils {
return isNull(coll) || coll.isEmpty();
}
/**
* * 判断一个Collection是否非空,包含List,Set,Queue
*
......@@ -60,7 +52,6 @@ public class StringUtil extends org.apache.commons.lang3.StringUtils {
return !isEmpty(coll);
}
/**
* * 判断一个对象数组是否为空
*
......@@ -71,7 +62,6 @@ public class StringUtil extends org.apache.commons.lang3.StringUtils {
return isNull(objects) || (objects.length == 0);
}
/**
* * 判断一个对象数组是否非空
*
......@@ -82,7 +72,6 @@ public class StringUtil extends org.apache.commons.lang3.StringUtils {
return !isEmpty(objects);
}
/**
* * 判断一个Map是否为空
*
......@@ -93,7 +82,6 @@ public class StringUtil extends org.apache.commons.lang3.StringUtils {
return isNull(map) || map.isEmpty();
}
/**
* * 判断一个Map是否为空
*
......@@ -104,7 +92,6 @@ public class StringUtil extends org.apache.commons.lang3.StringUtils {
return !isEmpty(map);
}
/**
* * 判断一个字符串是否为空串
*
......@@ -115,7 +102,6 @@ public class StringUtil extends org.apache.commons.lang3.StringUtils {
return isNull(str) || NULL_STRING.equals(str.trim());
}
/**
* * 判断一个字符串是否为非空串
*
......@@ -126,7 +112,6 @@ public class StringUtil extends org.apache.commons.lang3.StringUtils {
return !isEmpty(str);
}
/**
* * 判断一个对象是否为空
*
......@@ -137,7 +122,6 @@ public class StringUtil extends org.apache.commons.lang3.StringUtils {
return object == null;
}
/**
* * 判断一个对象是否非空
*
......@@ -148,7 +132,6 @@ public class StringUtil extends org.apache.commons.lang3.StringUtils {
return !isNull(object);
}
/**
* * 判断一个对象是否是数组类型(Java基本型别的数组)
*
......@@ -159,7 +142,6 @@ public class StringUtil extends org.apache.commons.lang3.StringUtils {
return isNotNull(object) && object.getClass().isArray();
}
/**
* 去空格
*/
......@@ -167,7 +149,6 @@ public class StringUtil extends org.apache.commons.lang3.StringUtils {
return (str == null ? "" : str.trim());
}
/**
* 截取字符串
*
......@@ -194,7 +175,6 @@ public class StringUtil extends org.apache.commons.lang3.StringUtils {
return str.substring(start);
}
/**
* 截取字符串
*
......@@ -233,7 +213,6 @@ public class StringUtil extends org.apache.commons.lang3.StringUtils {
return str.substring(start, end);
}
/**
* 下划线转驼峰命名
*/
......@@ -273,7 +252,6 @@ public class StringUtil extends org.apache.commons.lang3.StringUtils {
return sb.toString();
}
/**
* 是否包含字符串
*
......@@ -292,7 +270,6 @@ public class StringUtil extends org.apache.commons.lang3.StringUtils {
return false;
}
/**
* 将下划线大写方式命名的字符串转换为驼峰式。如果转换前的下划线大写方式命名的字符串为空,则返回空字符串。 例如:HELLO_WORLD->HelloWorld
*
......@@ -323,7 +300,6 @@ public class StringUtil extends org.apache.commons.lang3.StringUtils {
return result.toString();
}
/**
* 驼峰式命名法 例如:user_name->userName
*/
......@@ -350,13 +326,4 @@ public class StringUtil extends org.apache.commons.lang3.StringUtils {
}
/**
* 判断字符串是否是数字
*/
public static boolean isStr2Num(String str) {
Matcher matcher = NUM_PATTERN.matcher(str);
return matcher.matches();
}
}
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论