Commit c651553d by 吕明尚

增加优惠卷日志提示

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