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(); + } }