Commit bec43210 by 吕明尚

Merge branch 'dev' into test

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