Commit c8d6c5b0 authored by 周健威's avatar 周健威

Merge branch 'dev' into base-modify

parents dc092f8f 702ff965
...@@ -35,7 +35,14 @@ public interface CommonLogService { ...@@ -35,7 +35,14 @@ public interface CommonLogService {
* @param xxLogEntity * @param xxLogEntity
* @param result * @param result
*/ */
void initCommonLogLastPart(XxLogEntity xxLogEntity, BaseResponse result); void initCommonLogLastPart(XxLogEntity xxLogEntity, Object result);
/**
* 初始化日志后半部分(String)
* @param xxLogEntity
* @param result
*/
void initCommonLogLastPart(XxLogEntity xxLogEntity, String result);
/** /**
......
...@@ -103,10 +103,15 @@ public class CommonLogServiceImpl implements CommonLogService { ...@@ -103,10 +103,15 @@ public class CommonLogServiceImpl implements CommonLogService {
} }
@Override @Override
public void initCommonLogLastPart(XxLogEntity xxLogEntity, BaseResponse result) { public void initCommonLogLastPart(XxLogEntity xxLogEntity, Object result) {
initCommonLogLastPart(xxLogEntity, JSON.toJSONString(result));
}
@Override
public void initCommonLogLastPart(XxLogEntity xxLogEntity, String result) {
LocalDateTime endTime = LocalDateTime.now();//结束时间 LocalDateTime endTime = LocalDateTime.now();//结束时间
xxLogEntity.setEndDate(endTime.toString()); xxLogEntity.setEndDate(endTime.toString());
xxLogEntity.setResponseData(JSON.toJSONString(result)); xxLogEntity.setResponseData(result);
} }
@Override @Override
......
package com.github.wxiaoqi.security.common.log; package com.github.wxiaoqi.security.common.log;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.github.wxiaoqi.security.common.exception.BaseException;
import com.github.wxiaoqi.security.common.log.CommonLogService; import com.github.wxiaoqi.security.common.log.CommonLogService;
import com.github.wxiaoqi.security.common.log.entity.XxLogEntity; import com.github.wxiaoqi.security.common.log.entity.XxLogEntity;
import com.github.wxiaoqi.security.common.msg.BaseResponse; import com.github.wxiaoqi.security.common.msg.BaseResponse;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse; import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Aspect;
...@@ -26,6 +29,7 @@ import javax.servlet.http.HttpServletResponse; ...@@ -26,6 +29,7 @@ import javax.servlet.http.HttpServletResponse;
*/ */
@Aspect @Aspect
@Component @Component
@Slf4j
public class XxLogInterceptor{ public class XxLogInterceptor{
@Autowired @Autowired
...@@ -46,22 +50,32 @@ public class XxLogInterceptor{ ...@@ -46,22 +50,32 @@ public class XxLogInterceptor{
Object[] params = pjp.getArgs();//获取请求参数 Object[] params = pjp.getArgs();//获取请求参数
MethodSignature signature = (MethodSignature) pjp.getSignature(); MethodSignature signature = (MethodSignature) pjp.getSignature();
if(params != null && params.length > 0) { if(params != null && params.length > 0) {
xxLogEntity.setRequestData(JSON.toJSONString(params[0])); try{
xxLogEntity.setRequestData(JSON.toJSONString(params[0]));
}catch (Exception e) {
log.error(e.getMessage(), e);
}
} }
Object result = new Object(); Object result = new Object();
try{ try{
//###################上面代码为方法执行前##################### //###################上面代码为方法执行前#####################
result = pjp.proceed();//执行方法,获取返回参数 result = pjp.proceed();//执行方法,获取返回参数
//###################下面代码为方法执行后##################### //###################下面代码为方法执行后#####################
commonLogService.initCommonLogLastPart(xxLogEntity, (BaseResponse) result); if(result instanceof JSONObject) {
commonLogService.initCommonLogLastPart(xxLogEntity, ((JSONObject) result).toJSONString());
}else{
commonLogService.initCommonLogLastPart(xxLogEntity, result);
}
}catch (BaseException e){
commonLogService.initCommonLogLastPart(xxLogEntity, ObjectRestResponse.createFailedResult(e.getStatus(), e.getMessage()));
}catch (Exception e){ }catch (Exception e){
commonLogService.initCommonLogLastPart(xxLogEntity, (BaseResponse) result); commonLogService.initCommonLogLastPart(xxLogEntity, ObjectRestResponse.createFailedResult(500, e.getMessage()));
xxLogEntity.setResponseData(JSON.toJSONString(ObjectRestResponse.createDefaultFail()));
throw e; throw e;
}finally { }finally {
commonLogService.commonLog(xxLogEntity); commonLogService.commonLog(xxLogEntity);
} }
return result; return result;
} }
......
...@@ -24,6 +24,7 @@ import org.springframework.stereotype.Service; ...@@ -24,6 +24,7 @@ import org.springframework.stereotype.Service;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
...@@ -347,18 +348,29 @@ public class CertificationService { ...@@ -347,18 +348,29 @@ public class CertificationService {
return ObjectRestResponse.succ(); return ObjectRestResponse.succ();
} }
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd"); Date expirationDate = new Date();
formatter.setLenient(false); if (!Validation.isDate(endDate)) {
Date expirationDate = null; Date date = new Date();
try { Calendar c = Calendar.getInstance();
expirationDate = formatter.parse(endDate); c.setTime(date);
} catch (ParseException e) { c.add(Calendar.YEAR, 100);
expirationDate = c.getTime();
e.printStackTrace(); } else {
return ObjectRestResponse.createDefaultFail(); SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
formatter.setLenient(false);
try {
expirationDate = formatter.parse(endDate);
} catch (ParseException e) {
e.printStackTrace();
return ObjectRestResponse.createDefaultFail();
}
} }
idInformation.setExpirationDate(expirationDate); idInformation.setExpirationDate(expirationDate);
Boolean aBoolean = addIdInformation(idInformation); Boolean aBoolean = addIdInformation(idInformation);
......
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