From 2755f1dc638af2d08fc6c3a0f6b315cd6c6adc4f Mon Sep 17 00:00:00 2001 From: Sum1Dream <418471657@qq.com> Date: Thu, 1 Jun 2023 14:40:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E5=AE=9E=E7=89=A9=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/hai/order/utils/OrderUtil.java | 14 +++++++++----- .../service/impl/OutRechargeOrderServiceImpl.java | 8 ++++++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/hai-service/src/main/java/com/hai/order/utils/OrderUtil.java b/hai-service/src/main/java/com/hai/order/utils/OrderUtil.java index c5bb47bb..b8b3bce9 100644 --- a/hai-service/src/main/java/com/hai/order/utils/OrderUtil.java +++ b/hai-service/src/main/java/com/hai/order/utils/OrderUtil.java @@ -51,11 +51,15 @@ public class OrderUtil { * @return * @throws Exception */ - public static String generateOrderNo() throws Exception { - // 5位随机数 + 1位线程生成数 - String randomNum = (new Random().nextInt(8999) + 1000) + IDGenerator.nextId(1); - // 生成订单号 - return DateUtil.date2String(new Date(),"yyyyMMddHHmmss") + randomNum; + public static String generateOrderNo(){ + try { + // 5位随机数 + 1位线程生成数 + String randomNum = (new Random().nextInt(8999) + 1000) + IDGenerator.nextId(1); + // 生成订单号 + return DateUtil.date2String(new Date(),"yyyyMMddHHmmss") + randomNum; + } catch (Exception e) { + return null; + } } /** diff --git a/hai-service/src/main/java/com/hai/service/impl/OutRechargeOrderServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/OutRechargeOrderServiceImpl.java index 725e60e3..1c393aaa 100644 --- a/hai-service/src/main/java/com/hai/service/impl/OutRechargeOrderServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/OutRechargeOrderServiceImpl.java @@ -409,6 +409,10 @@ public class OutRechargeOrderServiceImpl implements OutRechargeOrderService { String key = "recharge_" + outRechargeOrder.getId(); + if (outRechargeOrderService.rechargeOrderAbnormal(outRechargeOrder)) { + return; + } + try { // 分布式锁占坑 @@ -550,6 +554,10 @@ public class OutRechargeOrderServiceImpl implements OutRechargeOrderService { @Override public void getPrepaidRechargeApi(OutRechargeOrder outRechargeOrder) { + if (rechargeOrderAbnormal(outRechargeOrder)) { + return; + } + JSONObject object = new JSONObject(); object.put("rechargePrice" , outRechargeOrder.getRechargePrice()); object.put("rechargeMobile" , outRechargeOrder.getRechargeContent());