Commit c651553d by 吕明尚

增加优惠卷日志提示

parent 513d2852
...@@ -8,6 +8,8 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; ...@@ -8,6 +8,8 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.aspectj.lang.JoinPoint; import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.*; import org.aspectj.lang.annotation.*;
import org.aspectj.lang.reflect.MethodSignature; import org.aspectj.lang.reflect.MethodSignature;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestAttributes; import org.springframework.web.context.request.RequestAttributes;
...@@ -31,6 +33,7 @@ import java.util.concurrent.CompletableFuture; ...@@ -31,6 +33,7 @@ import java.util.concurrent.CompletableFuture;
@Aspect @Aspect
@Component @Component
public class QPServiceImplAspect { public class QPServiceImplAspect {
private static final Logger logger = LoggerFactory.getLogger(QPServiceImplAspect.class);
@Autowired @Autowired
private CouponLogService couponLogService; private CouponLogService couponLogService;
...@@ -73,6 +76,7 @@ public class QPServiceImplAspect { ...@@ -73,6 +76,7 @@ public class QPServiceImplAspect {
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes(); RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
// 从获取RequestAttributes中获取HttpServletRequest的信息 // 从获取RequestAttributes中获取HttpServletRequest的信息
HttpServletRequest request = (HttpServletRequest) requestAttributes.resolveReference(RequestAttributes.REFERENCE_REQUEST); HttpServletRequest request = (HttpServletRequest) requestAttributes.resolveReference(RequestAttributes.REFERENCE_REQUEST);
CouponLog couponLog = new CouponLog();
try { try {
// 从切面织入点处通过反射机制获取织入点处的方法 // 从切面织入点处通过反射机制获取织入点处的方法
MethodSignature signature = (MethodSignature) joinPoint.getSignature(); MethodSignature signature = (MethodSignature) joinPoint.getSignature();
...@@ -80,8 +84,6 @@ public class QPServiceImplAspect { ...@@ -80,8 +84,6 @@ public class QPServiceImplAspect {
Method method = signature.getMethod(); Method method = signature.getMethod();
//获得方法名 //获得方法名
String methodName = method.getName(); String methodName = method.getName();
// 获取操作
CouponLog couponLog = new CouponLog();
// 将入参转换成json // 请求参数 // 将入参转换成json // 请求参数
//获得请求参数名称 //获得请求参数名称
String[] paramNames = ((MethodSignature) joinPoint.getSignature()).getParameterNames(); String[] paramNames = ((MethodSignature) joinPoint.getSignature()).getParameterNames();
...@@ -94,18 +96,22 @@ public class QPServiceImplAspect { ...@@ -94,18 +96,22 @@ public class QPServiceImplAspect {
couponLog.setStatus(YesNoEnum.yes.getDisplay_3()); couponLog.setStatus(YesNoEnum.yes.getDisplay_3());
couponLog.setMessage(outParams); couponLog.setMessage(outParams);
couponLog.setCreateTime(new Date()); couponLog.setCreateTime(new Date());
} catch (Exception e) {
e.printStackTrace();
} finally {
logger.info("优惠卷操作日志:{}", couponLog);
logger.info("开始异步执行新增正常日志");
// 异步执行 // 异步执行
CompletableFuture.supplyAsync(() -> { CompletableFuture.supplyAsync(() -> {
int i = couponLogService.insertCouponLog(couponLog); boolean i = couponLogService.save(couponLog);
if (i > 0) { if (i) {
logger.info("新增日志成功");
return true; return true;
} else { } else {
logger.info("新增日志失败");
return false; return false;
} }
}); });
// }
} catch (Exception e) {
e.printStackTrace();
} }
} }
...@@ -135,13 +141,16 @@ public class QPServiceImplAspect { ...@@ -135,13 +141,16 @@ public class QPServiceImplAspect {
couponLog.setMessage(e.getMessage()); couponLog.setMessage(e.getMessage());
} catch (Exception e2) { } catch (Exception e2) {
e2.printStackTrace(); e2.printStackTrace();
} finally { } finally {
logger.info("优惠卷操作日志:{}", couponLog);
logger.info("开始异步执行新增错误日志");
CompletableFuture.supplyAsync(() -> { CompletableFuture.supplyAsync(() -> {
int i = couponLogService.insertCouponLog(couponLog); boolean i = couponLogService.save(couponLog);
if (i > 0) { if (i) {
logger.info("新增日志成功");
return true; return true;
} else { } else {
logger.info("新增日志失败");
return false; return false;
} }
}); });
......
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