From 49d27cfcec940ecd6c57f420169db162e1709a28 Mon Sep 17 00:00:00 2001 From: lulz1 Date: Sun, 7 Apr 2024 17:26:10 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E6=90=BA=E7=A8=8B=E9=85=92?= =?UTF-8?q?=E5=BA=97=E7=BB=93=E7=AE=97=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../factoriy/order/RouteOrderFactory.java | 2 ++ .../chint/infrastructure/util/OrderNo.java | 22 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/main/java/com/chint/domain/factoriy/order/RouteOrderFactory.java b/src/main/java/com/chint/domain/factoriy/order/RouteOrderFactory.java index 11b3c59c..b752d15f 100644 --- a/src/main/java/com/chint/domain/factoriy/order/RouteOrderFactory.java +++ b/src/main/java/com/chint/domain/factoriy/order/RouteOrderFactory.java @@ -26,6 +26,7 @@ public class RouteOrderFactory implements OrderFactory { private String envMark; + @Override public RouteOrder createRoute(OrderSaveData orderData) { User currentUser = BaseContext.getCurrentUser(); @@ -84,6 +85,7 @@ public class RouteOrderFactory implements OrderFactory { @Override public RouteRequest createRequestByRoute(RouteOrder routeOrder) { RouteRequest routeRequest = new RouteRequest(); + routeRequest.setRouteRequestNo(OrderNo.generateRouteRequestNo(routeOrder.getRouteOrderNo())); return null; } } diff --git a/src/main/java/com/chint/infrastructure/util/OrderNo.java b/src/main/java/com/chint/infrastructure/util/OrderNo.java index f6921390..2bd2019c 100644 --- a/src/main/java/com/chint/infrastructure/util/OrderNo.java +++ b/src/main/java/com/chint/infrastructure/util/OrderNo.java @@ -5,6 +5,9 @@ import java.time.format.DateTimeFormatter; import java.util.Random; public class OrderNo { + + private static final String chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; + public static String generate() { // 获取当前时间 LocalDateTime now = LocalDateTime.now(); @@ -33,4 +36,23 @@ public class OrderNo { // 拼接最终的订单号 return "L" + datePart + randomPart; } + + public static String generateRouteRequestNo(String routeOrderNo) { + return routeOrderNo + "#" + randomStr(6); + } + + private static String randomStr(Integer length) { + StringBuilder sb = new StringBuilder(); + Random random = new Random(); + // 生成六位随机字符串 + for (int i = 0; i < length; i++) { + // 生成一个随机索引 + int index = random.nextInt(chars.length()); + // 从chars中获取字符 + char randomChar = chars.charAt(index); + // 将字符添加到StringBuilder中 + sb.append(randomChar); + } + return sb.toString(); + } }