Commit bec43210 by 吕明尚

Merge branch 'dev' into test

parents 48b295bd b447f2b4
......@@ -71,50 +71,47 @@ public class QPServiceImplAspect {
* @param result 返回结果
*/
@AfterReturning(value = "operLogPoinCut()", returning = "result")
public void saveOperLog(JoinPoint joinPoint, Object result) {
// 获取RequestAttributes
public void saveCouponOperationLog(JoinPoint joinPoint, Object result) {
try {
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
// 从获取RequestAttributes中获取HttpServletRequest的信息
if (requestAttributes == null) {
logger.warn("无法获取RequestAttributes");
return;
}
HttpServletRequest request = (HttpServletRequest) requestAttributes.resolveReference(RequestAttributes.REFERENCE_REQUEST);
if (request == null) {
logger.warn("无法获取HttpServletRequest");
return;
}
CouponLog couponLog = new CouponLog();
try {
// 从切面织入点处通过反射机制获取织入点处的方法
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
// 获取切入点所在的方法
Method method = signature.getMethod();
//获得方法名
String methodName = method.getName();
// 将入参转换成json // 请求参数
//获得请求参数名称
String[] paramNames = ((MethodSignature) joinPoint.getSignature()).getParameterNames();
String[] paramNames = signature.getParameterNames();
String params = argsArrayToString(paramNames, joinPoint.getArgs());
//转JSON
JSONObject jsonObject = JSON.parseObject(params);
//获得出参
String outParams = JSON.toJSONString(result);
saveLog(couponLog, jsonObject, UserStatusEnum.UNUSED.getCode());
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(() -> {
boolean i = couponLogService.save(couponLog);
if (i) {
boolean isSaved = couponLogService.save(couponLog);
if (isSaved) {
logger.info("新增日志成功");
return true;
} else {
logger.info("新增日志失败");
return false;
logger.warn("新增日志失败");
}
});
} catch (Exception e) {
logger.error("在保存优惠券操作日志时出错", e);
}
}
/**
* 异常返回通知,用于拦截异常日志信息 连接点抛出异常后执行
*/
/**
* 异常返回通知,用于拦截异常日志信息 连接点抛出异常后执行
*/
......@@ -128,52 +125,64 @@ public class QPServiceImplAspect {
Method method = signature.getMethod();
//获得方法名
String methodName = method.getName();
// 将入参转换成json // 请求参数
String[] paramNames = ((MethodSignature) joinPoint.getSignature()).getParameterNames();
String params = argsArrayToString(paramNames, joinPoint.getArgs());
//转JSON
JSONObject jsonObject = JSON.parseObject(params);
saveLog(couponLog, jsonObject, UserStatusEnum.UNUSED.getCode());
// 设置基本属性
couponLog.setStatus(YesNoEnum.no.getDisplay_3());
couponLog.setNumber(TRY_NUMBER);
couponLog.setCreateTime(new Date());
couponLog.setMessage(e.getMessage());
// 记录日志
saveLog(couponLog, jsonObject, UserStatusEnum.UNUSED.getCode());
} catch (Exception e2) {
e2.printStackTrace();
logger.error("Error while processing exception log", e2);
} finally {
logger.info("优惠卷操作日志:{}", couponLog);
logger.info("开始异步执行新增错误日志");
CompletableFuture.supplyAsync(() -> {
boolean i = couponLogService.save(couponLog);
if (i) {
logger.info("新增日志成功");
return true;
} else {
logger.info("新增日志失败");
return false;
}
});
}
}
private void saveLog(CouponLog couponLog, JSONObject jsonObject, Integer code) {
couponLog.setCode(jsonObject.getString("code"));
String couponCode = jsonObject.getString("code");
couponLog.setCode(couponCode);
// 查询SConsumerCoupon
LambdaQueryWrapper<SConsumerCoupon> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(SConsumerCoupon::getCouponCode, couponLog.getCode());
lambdaQueryWrapper.eq(SConsumerCoupon::getCouponCode, couponCode);
lambdaQueryWrapper.eq(SConsumerCoupon::getUseStatus, code);
SConsumerCoupon one = sConsumerCouponService.getOne(lambdaQueryWrapper);
if (one == null) {
// 处理查询不到SConsumerCoupon的情况,例如抛出异常或记录日志
logger.error("Failed to find SConsumerCoupon for code: " + couponCode);
}
couponLog.setConsumerId(one.getConsumerId());
couponLog.setCouponId(one.getId());
couponLog.setCouponName(one.getName());
couponLog.setCouponValue(one.getSubPrice());
// 查询SStore
LambdaQueryWrapper<SStore> sStoreLambdaQueryWrapper = new LambdaQueryWrapper<>();
sStoreLambdaQueryWrapper.eq(SStore::getOpenShopUuid, jsonObject.getString("openShopUuid"));
SStore sStore = sStoreService.getOne(sStoreLambdaQueryWrapper);
if (sStore == null) {
logger.error("Failed to find SStore for openShopUuid: " + jsonObject.getString("openShopUuid"));
// 处理查询不到SStore的情况,例如抛出异常或记录日志
}
couponLog.setStoreId(sStore.getId());
couponLog.setCouponName(one.getName());
couponLog.setCouponValue(one.getSubPrice());
// 设置其他属性
couponLog.setCouponType(jsonObject.getString("status"));
}
/**
* 参数拼装
*/
......@@ -197,19 +206,6 @@ public class QPServiceImplAspect {
return JSONUtil.toJsonStr(map);
}
/**
* 转换异常信息为字符串
*/
public String stackTraceToString(String exceptionName, String exceptionMessage, StackTraceElement[] elements) {
StringBuffer strbuff = new StringBuffer();
for (StackTraceElement stet : elements) {
strbuff.append(stet + "\n");
}
String message = exceptionName + ":" + exceptionMessage + "\n\t" + strbuff.toString();
message = substring(message, 0, 2000);
return message;
}
//字符串截取
public static String substring(String str, int start, int end) {
if (str == null) {
......
......@@ -300,7 +300,7 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
}
@Override
@Transactional
@Transactional(rollbackFor = Exception.class)
public OrderPayResultResponse createOrder(CreateOrderRequest request) {
SConsumer user = FrontTokenComponent.getWxSConsumerEntry();
if (ObjectUtil.isNull(user)) {
......
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