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

微调

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