Showing
2 changed files
with
23 additions
and
6 deletions
| ... | @@ -30,7 +30,9 @@ public enum ErrorCodeEnum implements BaseEnum { | ... | @@ -30,7 +30,9 @@ public enum ErrorCodeEnum implements BaseEnum { |
| 30 | 30 | ||
| 31 | QUERY_CLIENT_CUSTOMER_ERROR(406000006, "获取当日在住客户失败"), | 31 | QUERY_CLIENT_CUSTOMER_ERROR(406000006, "获取当日在住客户失败"), |
| 32 | 32 | ||
| 33 | - SKUS_SOLD_OUT_TODAY(406000007, "下单菜品今日售罄"), | 33 | + SKUS_SOLD_OUT_TODAY(406000007, "下单菜品\n{0}\n今日已售罄"), |
| 34 | + | ||
| 35 | + SKUS_STOCK_NO_ENOUGH_TODAY(406000007, "下单菜品\n{0}\n库存不足"), | ||
| 34 | 36 | ||
| 35 | ORDER_CANCEL(406000008, "订单已自动取消") | 37 | ORDER_CANCEL(406000008, "订单已自动取消") |
| 36 | ; | 38 | ; | ... | ... |
| 1 | package com.infoloop.tianting.service.client; | 1 | package com.infoloop.tianting.service.client; |
| 2 | 2 | ||
| 3 | import com.infoloop.tianting.SingleResponse; | 3 | import com.infoloop.tianting.SingleResponse; |
| 4 | +import com.infoloop.tianting.SingleSkuResponse; | ||
| 4 | import com.infoloop.tianting.SingleSpecialResponse; | 5 | import com.infoloop.tianting.SingleSpecialResponse; |
| 5 | import com.infoloop.tianting.clientcustomerorderservice.AddSkusSellQuantitiesRpcRequest; | 6 | import com.infoloop.tianting.clientcustomerorderservice.AddSkusSellQuantitiesRpcRequest; |
| 6 | import com.infoloop.tianting.clientcustomerorderservice.BatchCreateOrderOperationRecordsRequest; | 7 | import com.infoloop.tianting.clientcustomerorderservice.BatchCreateOrderOperationRecordsRequest; |
| ... | @@ -73,6 +74,7 @@ import javax.annotation.Nullable; | ... | @@ -73,6 +74,7 @@ import javax.annotation.Nullable; |
| 73 | import java.time.LocalDate; | 74 | import java.time.LocalDate; |
| 74 | import java.time.ZoneOffset; | 75 | import java.time.ZoneOffset; |
| 75 | import java.util.ArrayList; | 76 | import java.util.ArrayList; |
| 77 | +import java.util.HashMap; | ||
| 76 | import java.util.List; | 78 | import java.util.List; |
| 77 | import java.util.concurrent.TimeUnit; | 79 | import java.util.concurrent.TimeUnit; |
| 78 | import java.util.function.Function; | 80 | import java.util.function.Function; |
| ... | @@ -222,8 +224,7 @@ public class OrderServiceRpcClient { | ... | @@ -222,8 +224,7 @@ public class OrderServiceRpcClient { |
| 222 | final var skuAvoids = rpcSkus.get(0).getAvoidsList().stream().map(SingleResponse::getName).collect(Collectors.toList()); | 224 | final var skuAvoids = rpcSkus.get(0).getAvoidsList().stream().map(SingleResponse::getName).collect(Collectors.toList()); |
| 223 | final var tastes = rpcSkus.get(0).getTastesList().stream().map(SingleResponse::getName).collect(Collectors.toList()); | 225 | final var tastes = rpcSkus.get(0).getTastesList().stream().map(SingleResponse::getName).collect(Collectors.toList()); |
| 224 | final var efficacies = rpcSkus.get(0).getEfficaciesList().stream().map(SingleResponse::getName).collect(Collectors.toList()); | 226 | final var efficacies = rpcSkus.get(0).getEfficaciesList().stream().map(SingleResponse::getName).collect(Collectors.toList()); |
| 225 | - final var allergies = rpcSkus.get(0).getAllergiesList().stream().map( | 227 | + final var allergies = rpcSkus.get(0).getAllergiesList().stream().map(SingleSpecialResponse::getName).collect(Collectors.toList()); |
| 226 | - SingleSpecialResponse::getName).collect(Collectors.toList()); | ||
| 227 | final var skuDoctors = rpcSkus.get(0).getDoctorsList().stream().map(SingleSpecialResponse::getName).collect(Collectors.toList()); | 228 | final var skuDoctors = rpcSkus.get(0).getDoctorsList().stream().map(SingleSpecialResponse::getName).collect(Collectors.toList()); |
| 228 | mealDetail = MealDetail.newBuilder() | 229 | mealDetail = MealDetail.newBuilder() |
| 229 | .setBasicMaterials(rpcSkus.get(0).getBasicMaterials()) | 230 | .setBasicMaterials(rpcSkus.get(0).getBasicMaterials()) |
| ... | @@ -567,15 +568,29 @@ public class OrderServiceRpcClient { | ... | @@ -567,15 +568,29 @@ public class OrderServiceRpcClient { |
| 567 | final var skuIds = createOrderDto.getOrderDetailDtos().stream().map(CreateOrderDetailDto::getSkuId).collect(Collectors.toList()); | 568 | final var skuIds = createOrderDto.getOrderDetailDtos().stream().map(CreateOrderDetailDto::getSkuId).collect(Collectors.toList()); |
| 568 | final var skuSellQuantities = this.querySkuSellQuantitiesByStallAndSkuIds(createOrderDto.getEnterpriseId(), createOrderDto.getStallId(), skuIds); | 569 | final var skuSellQuantities = this.querySkuSellQuantitiesByStallAndSkuIds(createOrderDto.getEnterpriseId(), createOrderDto.getStallId(), skuIds); |
| 569 | final var skuSellQuantityMap = skuSellQuantities.stream().collect(Collectors.toMap(SingleSkuSellQuantityRpcResponse::getSkuId, Function.identity())); | 570 | final var skuSellQuantityMap = skuSellQuantities.stream().collect(Collectors.toMap(SingleSkuSellQuantityRpcResponse::getSkuId, Function.identity())); |
| 571 | + final var skuMap = skuServiceRpcClient.getSkusByIds(skuIds).stream().collect(Collectors.toMap(SingleSkuResponse::getId, Function.identity())); | ||
| 572 | + final var soldOutSkus = new ArrayList<String>(); | ||
| 573 | + final var skuStockMap = new HashMap<String, Integer>(); | ||
| 570 | for (var orderDetail : createOrderDto.getOrderDetailDtos()) { | 574 | for (var orderDetail : createOrderDto.getOrderDetailDtos()) { |
| 571 | final var skuSellQuantityRpcResponse = skuSellQuantityMap.get(orderDetail.getSkuId()); | 575 | final var skuSellQuantityRpcResponse = skuSellQuantityMap.get(orderDetail.getSkuId()); |
| 572 | if (skuSellQuantityRpcResponse == null) { | 576 | if (skuSellQuantityRpcResponse == null) { |
| 573 | - throw ClientEndExceptions.BusinessException.build(ErrorCodeEnum.SKUS_SOLD_OUT_TODAY); | 577 | + log.error("skuSellQuantityRpcResponse is null; stallId:{}, skuId:{}", createOrderDto.getStallId(), orderDetail.getSkuId()); |
| 578 | + soldOutSkus.add(skuMap.get(orderDetail.getSkuId()).getName()); | ||
| 579 | + continue; | ||
| 574 | } | 580 | } |
| 575 | - if ((skuSellQuantityRpcResponse.getTodaySellQuantity() + orderDetail.getSkuId()) > skuSellQuantityRpcResponse.getMaxSellQuantity()) { | 581 | + if ((skuSellQuantityRpcResponse.getTodaySellQuantity() + orderDetail.getCount()) > skuSellQuantityRpcResponse.getMaxSellQuantity()) { |
| 576 | - throw ClientEndExceptions.BusinessException.build(ErrorCodeEnum.SKUS_SOLD_OUT_TODAY); | 582 | + log.error("skuSellQuantityRpcResponse stock no enough; stallId:{}, skuId:{}, count:{}", createOrderDto.getStallId(), orderDetail.getSkuId(), orderDetail.getCount()); |
| 583 | + skuStockMap.put(skuMap.get(orderDetail.getSkuId()).getName(), skuSellQuantityRpcResponse.getMaxSellQuantity() - skuSellQuantityRpcResponse.getTodaySellQuantity()); | ||
| 584 | + continue; | ||
| 577 | } | 585 | } |
| 578 | } | 586 | } |
| 587 | + if (!soldOutSkus.isEmpty()) { | ||
| 588 | + throw ClientEndExceptions.BusinessException.build(ErrorCodeEnum.SKUS_SOLD_OUT_TODAY, String.join(",", soldOutSkus)); | ||
| 589 | + } | ||
| 590 | + if (!skuStockMap.isEmpty()) { | ||
| 591 | + final var noEnoughSkus = String.join(", ", skuStockMap.keySet()); | ||
| 592 | + throw ClientEndExceptions.BusinessException.build(ErrorCodeEnum.SKUS_STOCK_NO_ENOUGH_TODAY, noEnoughSkus); | ||
| 593 | + } | ||
| 579 | } | 594 | } |
| 580 | final var orderResponse = orderServiceRpcBlockingStub | 595 | final var orderResponse = orderServiceRpcBlockingStub |
| 581 | .createClientCustomerOrder(CreateClientCustomerOrderRpcRequest.newBuilder() | 596 | .createClientCustomerOrder(CreateClientCustomerOrderRpcRequest.newBuilder() | ... | ... |
-
Please register or login to post a comment