fix(order): optimize dish replacement logic and update payment transaction ID
Showing
11 changed files
with
82 additions
and
5 deletions
| ... | @@ -60,4 +60,5 @@ public class PayController { | ... | @@ -60,4 +60,5 @@ public class PayController { |
| 60 | public String cancel(@Valid @RequestBody PayDTO.PayRefundRequestDto payRefundRequestDto) { | 60 | public String cancel(@Valid @RequestBody PayDTO.PayRefundRequestDto payRefundRequestDto) { |
| 61 | return payServiceClient.orderPayRefund(payRefundRequestDto); | 61 | return payServiceClient.orderPayRefund(payRefundRequestDto); |
| 62 | } | 62 | } |
| 63 | + | ||
| 63 | } | 64 | } |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| 1 | +package com.infoloop.tianting.model.bo; | ||
| 2 | + | ||
| 3 | +import com.infoloop.tianting.clientcustomerorderservice.ServeStatusEnum; | ||
| 4 | +import lombok.Data; | ||
| 5 | + | ||
| 6 | +@Data | ||
| 7 | +public class OrderDetailBO { | ||
| 8 | + | ||
| 9 | + private int id; | ||
| 10 | + | ||
| 11 | + public int skuId; | ||
| 12 | + | ||
| 13 | + private String skuName; | ||
| 14 | + | ||
| 15 | + private Integer price; | ||
| 16 | + | ||
| 17 | + private int count; | ||
| 18 | + | ||
| 19 | + private String adjustSkuRemark; | ||
| 20 | + | ||
| 21 | + private ServeStatusEnum serveStatus; | ||
| 22 | +} |
| ... | @@ -520,6 +520,7 @@ public class OrderDbDTO { | ... | @@ -520,6 +520,7 @@ public class OrderDbDTO { |
| 520 | private Integer count; | 520 | private Integer count; |
| 521 | private String adjustSkuRemark; | 521 | private String adjustSkuRemark; |
| 522 | private String serveStatus; | 522 | private String serveStatus; |
| 523 | + private Integer price; | ||
| 523 | } | 524 | } |
| 524 | 525 | ||
| 525 | 526 | ||
| ... | @@ -730,6 +731,10 @@ public class OrderDbDTO { | ... | @@ -730,6 +731,10 @@ public class OrderDbDTO { |
| 730 | @Builder.Default | 731 | @Builder.Default |
| 731 | private Boolean shouldUpdateServeStatus = false; | 732 | private Boolean shouldUpdateServeStatus = false; |
| 732 | 733 | ||
| 734 | + @ApiModelProperty(value = "价格") | ||
| 735 | + @Builder.Default | ||
| 736 | + private Integer price = null; | ||
| 737 | + | ||
| 733 | @ApiModelProperty(value = "出餐状态: 默认未出餐=1; 不出餐=2; 已出餐=3") | 738 | @ApiModelProperty(value = "出餐状态: 默认未出餐=1; 不出餐=2; 已出餐=3") |
| 734 | @Builder.Default | 739 | @Builder.Default |
| 735 | private ServeStatusEnum serveStatus = ServeStatusEnum.SERVE_NOT_START; | 740 | private ServeStatusEnum serveStatus = ServeStatusEnum.SERVE_NOT_START; | ... | ... |
| ... | @@ -9,6 +9,8 @@ import lombok.Builder; | ... | @@ -9,6 +9,8 @@ import lombok.Builder; |
| 9 | import lombok.Data; | 9 | import lombok.Data; |
| 10 | import lombok.NoArgsConstructor; | 10 | import lombok.NoArgsConstructor; |
| 11 | 11 | ||
| 12 | +import java.util.List; | ||
| 13 | + | ||
| 12 | @Data | 14 | @Data |
| 13 | @ApiModel(description = "支付DTO") | 15 | @ApiModel(description = "支付DTO") |
| 14 | public class PayDTO { | 16 | public class PayDTO { |
| ... | @@ -31,6 +33,7 @@ public class PayDTO { | ... | @@ -31,6 +33,7 @@ public class PayDTO { |
| 31 | @AllArgsConstructor | 33 | @AllArgsConstructor |
| 32 | public static class PayRefundRequestDto { | 34 | public static class PayRefundRequestDto { |
| 33 | private Integer orderId; | 35 | private Integer orderId; |
| 36 | + private List<Integer> orderDetailIds; | ||
| 34 | private String hospitalCode; | 37 | private String hospitalCode; |
| 35 | } | 38 | } |
| 36 | 39 | ... | ... |
| ... | @@ -18,6 +18,9 @@ public class PaymentCallbackResult { | ... | @@ -18,6 +18,9 @@ public class PaymentCallbackResult { |
| 18 | @JacksonXmlProperty(localName = "TransSN") | 18 | @JacksonXmlProperty(localName = "TransSN") |
| 19 | private String transSN; | 19 | private String transSN; |
| 20 | 20 | ||
| 21 | + @JacksonXmlProperty(localName = "TradeReferenceNo") | ||
| 22 | + private String tradeReferenceNo; | ||
| 23 | + | ||
| 21 | @JacksonXmlProperty(localName = "TransType") | 24 | @JacksonXmlProperty(localName = "TransType") |
| 22 | private String transType; | 25 | private String transType; |
| 23 | 26 | ... | ... |
| ... | @@ -103,6 +103,8 @@ public class SettlementDTO { | ... | @@ -103,6 +103,8 @@ public class SettlementDTO { |
| 103 | private String remark; | 103 | private String remark; |
| 104 | private String avoidRemark; | 104 | private String avoidRemark; |
| 105 | private String onlinePay; | 105 | private String onlinePay; |
| 106 | + private String operationType; | ||
| 107 | + private String transactionId; | ||
| 106 | } | 108 | } |
| 107 | 109 | ||
| 108 | @Data | 110 | @Data | ... | ... |
| ... | @@ -22,6 +22,8 @@ import com.infoloop.tianting.clientcustomerorderservice.GetClientCustomerOrderBy | ... | @@ -22,6 +22,8 @@ import com.infoloop.tianting.clientcustomerorderservice.GetClientCustomerOrderBy |
| 22 | import com.infoloop.tianting.clientcustomerorderservice.GetClientCustomerOrderDetailsByIdsRpcRequest; | 22 | import com.infoloop.tianting.clientcustomerorderservice.GetClientCustomerOrderDetailsByIdsRpcRequest; |
| 23 | import com.infoloop.tianting.clientcustomerorderservice.GetClientCustomerOrderDetailsByOrderIdsRpcRequest; | 23 | import com.infoloop.tianting.clientcustomerorderservice.GetClientCustomerOrderDetailsByOrderIdsRpcRequest; |
| 24 | import com.infoloop.tianting.clientcustomerorderservice.GetClientCustomerOrdersByCustomerIdRpcRequest; | 24 | import com.infoloop.tianting.clientcustomerorderservice.GetClientCustomerOrdersByCustomerIdRpcRequest; |
| 25 | +import com.infoloop.tianting.clientcustomerorderservice.GetOrderOperationRecordsByOrderIdsRequest; | ||
| 26 | +import com.infoloop.tianting.clientcustomerorderservice.GetOrderOperationRecordsByOrderIdsResponse; | ||
| 25 | import com.infoloop.tianting.clientcustomerorderservice.MealDetail; | 27 | import com.infoloop.tianting.clientcustomerorderservice.MealDetail; |
| 26 | import com.infoloop.tianting.clientcustomerorderservice.OnlinePayEnum; | 28 | import com.infoloop.tianting.clientcustomerorderservice.OnlinePayEnum; |
| 27 | import com.infoloop.tianting.clientcustomerorderservice.OrderOperationRecordCreation; | 29 | import com.infoloop.tianting.clientcustomerorderservice.OrderOperationRecordCreation; |
| ... | @@ -240,8 +242,10 @@ public class OrderServiceRpcClient { | ... | @@ -240,8 +242,10 @@ public class OrderServiceRpcClient { |
| 240 | final var operator = operatorServiceRpcClient.getCOperatorById(operatorLoginInfo.getId()); | 242 | final var operator = operatorServiceRpcClient.getCOperatorById(operatorLoginInfo.getId()); |
| 241 | final var idsOfNeedUpdateMenuDetails = new ArrayList<Integer>(); | 243 | final var idsOfNeedUpdateMenuDetails = new ArrayList<Integer>(); |
| 242 | final var idsOfAddCount = new ArrayList<Integer>(); | 244 | final var idsOfAddCount = new ArrayList<Integer>(); |
| 245 | + final var idsOfNoReject = new ArrayList<Integer>(); | ||
| 243 | List<OrderDetailDto> originalOrderDetails = new ArrayList<>(); | 246 | List<OrderDetailDto> originalOrderDetails = new ArrayList<>(); |
| 244 | List<OrderDetailDto> newOrderDetails; | 247 | List<OrderDetailDto> newOrderDetails; |
| 248 | + final var orderDetailsMap = orderDetailBatchUpdateDto.getDetails().stream().collect(Collectors.toMap(OrderDbDTO.OrderDetailUpdateDto::getId, Function.identity())); | ||
| 245 | final var modifications = orderDetailBatchUpdateDto.getDetails().stream().map(d -> { | 249 | final var modifications = orderDetailBatchUpdateDto.getDetails().stream().map(d -> { |
| 246 | var mealDetail = MealDetail.newBuilder().build(); | 250 | var mealDetail = MealDetail.newBuilder().build(); |
| 247 | Integer menuDetailId = 0; | 251 | Integer menuDetailId = 0; |
| ... | @@ -280,9 +284,11 @@ public class OrderServiceRpcClient { | ... | @@ -280,9 +284,11 @@ public class OrderServiceRpcClient { |
| 280 | .build(); | 284 | .build(); |
| 281 | } | 285 | } |
| 282 | } | 286 | } |
| 283 | - | ||
| 284 | ServeStatusEnum serveStatus = ServeStatusEnum.UNKNOWN_SERVE_STATUS; | 287 | ServeStatusEnum serveStatus = ServeStatusEnum.UNKNOWN_SERVE_STATUS; |
| 285 | if (d.getShouldUpdateServeStatus()) { | 288 | if (d.getShouldUpdateServeStatus()) { |
| 289 | + if (d.getServeStatus() == ServeStatusEnum.SERVE_REJECT) { | ||
| 290 | + idsOfNoReject.add(d.getId()); | ||
| 291 | + } | ||
| 286 | serveStatus = d.getServeStatus(); | 292 | serveStatus = d.getServeStatus(); |
| 287 | } | 293 | } |
| 288 | Integer count = 0; | 294 | Integer count = 0; |
| ... | @@ -319,7 +325,8 @@ public class OrderServiceRpcClient { | ... | @@ -319,7 +325,8 @@ public class OrderServiceRpcClient { |
| 319 | .build(); | 325 | .build(); |
| 320 | final var totalIds = new ArrayList<>(idsOfNeedUpdateMenuDetails); | 326 | final var totalIds = new ArrayList<>(idsOfNeedUpdateMenuDetails); |
| 321 | totalIds.addAll(idsOfAddCount); | 327 | totalIds.addAll(idsOfAddCount); |
| 322 | - if (!idsOfNeedUpdateMenuDetails.isEmpty() || !idsOfAddCount.isEmpty()) { | 328 | + totalIds.addAll(idsOfNoReject); |
| 329 | + if (!totalIds.isEmpty()) { | ||
| 323 | final var orgionalResponseList = getClientCustomerOrderDetailsByIds(totalIds); | 330 | final var orgionalResponseList = getClientCustomerOrderDetailsByIds(totalIds); |
| 324 | originalOrderDetails = orgionalResponseList.stream().map(d -> OrderDetailDto.builder() | 331 | originalOrderDetails = orgionalResponseList.stream().map(d -> OrderDetailDto.builder() |
| 325 | .id(d.getId()) | 332 | .id(d.getId()) |
| ... | @@ -357,7 +364,7 @@ public class OrderServiceRpcClient { | ... | @@ -357,7 +364,7 @@ public class OrderServiceRpcClient { |
| 357 | } | 364 | } |
| 358 | final var res = orderServiceRpcBlockingStub.batchUpdateClientCustomerOrderDetails(request); | 365 | final var res = orderServiceRpcBlockingStub.batchUpdateClientCustomerOrderDetails(request); |
| 359 | if (res.getIsUpdated()) { | 366 | if (res.getIsUpdated()) { |
| 360 | - if (!idsOfNeedUpdateMenuDetails.isEmpty() || !idsOfAddCount.isEmpty()) { | 367 | + if (!totalIds.isEmpty()) { |
| 361 | final var newResponseList = getClientCustomerOrderDetailsByIds(totalIds); | 368 | final var newResponseList = getClientCustomerOrderDetailsByIds(totalIds); |
| 362 | newOrderDetails = newResponseList.stream().map(d -> | 369 | newOrderDetails = newResponseList.stream().map(d -> |
| 363 | OrderDetailDto.builder() | 370 | OrderDetailDto.builder() |
| ... | @@ -392,15 +399,21 @@ public class OrderServiceRpcClient { | ... | @@ -392,15 +399,21 @@ public class OrderServiceRpcClient { |
| 392 | .updateSource(d.getUpdateSource().getNumber()) | 399 | .updateSource(d.getUpdateSource().getNumber()) |
| 393 | .updatedAt(DateUtil.formatDate(d.getUpdatedAt())) | 400 | .updatedAt(DateUtil.formatDate(d.getUpdatedAt())) |
| 394 | .updatedBy(d.getUpdatedBy()) | 401 | .updatedBy(d.getUpdatedBy()) |
| 395 | - .build()).collect(Collectors.toList()); | 402 | + .build()).toList(); |
| 396 | // 替换菜品的操作记录 | 403 | // 替换菜品的操作记录 |
| 397 | List<SingleOperationDto> operations = new ArrayList<>(); | 404 | List<SingleOperationDto> operations = new ArrayList<>(); |
| 398 | for (OrderDetailDto originalDetail : originalOrderDetails) { | 405 | for (OrderDetailDto originalDetail : originalOrderDetails) { |
| 406 | + if (!totalIds.contains(originalDetail.getId())) { | ||
| 407 | + continue; | ||
| 408 | + } | ||
| 409 | + final var orderDetailUpdateDto = orderDetailsMap.get(originalDetail.getId()); | ||
| 399 | OrderOperationType orderOperationType = OrderOperationType.UNKNOWN_OPERATION_TYPE; | 410 | OrderOperationType orderOperationType = OrderOperationType.UNKNOWN_OPERATION_TYPE; |
| 400 | if (idsOfNeedUpdateMenuDetails.contains(originalDetail.getId())) { | 411 | if (idsOfNeedUpdateMenuDetails.contains(originalDetail.getId())) { |
| 401 | orderOperationType = OrderOperationType.REPLACE_DISHES; | 412 | orderOperationType = OrderOperationType.REPLACE_DISHES; |
| 402 | } else if (idsOfAddCount.contains(originalDetail.getId())) { | 413 | } else if (idsOfAddCount.contains(originalDetail.getId())) { |
| 403 | orderOperationType = OrderOperationType.ADD_DISHES; | 414 | orderOperationType = OrderOperationType.ADD_DISHES; |
| 415 | + } else if (idsOfNoReject.contains(originalDetail.getId())) { | ||
| 416 | + orderOperationType = OrderOperationType.NOT_SERVE; | ||
| 404 | } | 417 | } |
| 405 | String originalDetailStr; | 418 | String originalDetailStr; |
| 406 | String newDetailStr = ""; | 419 | String newDetailStr = ""; |
| ... | @@ -413,6 +426,7 @@ public class OrderServiceRpcClient { | ... | @@ -413,6 +426,7 @@ public class OrderServiceRpcClient { |
| 413 | .count(newDetail.get().getCount()) | 426 | .count(newDetail.get().getCount()) |
| 414 | .adjustSkuRemark(newDetail.get().getAdjustSkuRemark()) | 427 | .adjustSkuRemark(newDetail.get().getAdjustSkuRemark()) |
| 415 | .serveStatus(newDetail.get().getServeStatus().name()) | 428 | .serveStatus(newDetail.get().getServeStatus().name()) |
| 429 | + .price(orderDetailUpdateDto.getPrice() == null ? newDetail.get().getPrice() : orderDetailUpdateDto.getPrice()) | ||
| 416 | .build(); | 430 | .build(); |
| 417 | newDetailStr = JsonUtil.writeAsJson(List.of(newOrderDetailOperation)); | 431 | newDetailStr = JsonUtil.writeAsJson(List.of(newOrderDetailOperation)); |
| 418 | } | 432 | } |
| ... | @@ -423,6 +437,7 @@ public class OrderServiceRpcClient { | ... | @@ -423,6 +437,7 @@ public class OrderServiceRpcClient { |
| 423 | .count(originalDetail.getCount()) | 437 | .count(originalDetail.getCount()) |
| 424 | .adjustSkuRemark(originalDetail.getAdjustSkuRemark()) | 438 | .adjustSkuRemark(originalDetail.getAdjustSkuRemark()) |
| 425 | .serveStatus(originalDetail.getServeStatus().name()) | 439 | .serveStatus(originalDetail.getServeStatus().name()) |
| 440 | + .price(originalDetail.getPrice()) | ||
| 426 | .build(); | 441 | .build(); |
| 427 | originalDetailStr = JsonUtil.writeAsJson(List.of(originalOrderDetailOperation)); | 442 | originalDetailStr = JsonUtil.writeAsJson(List.of(originalOrderDetailOperation)); |
| 428 | final var operation = SingleOperationDto.builder() | 443 | final var operation = SingleOperationDto.builder() |
| ... | @@ -471,7 +486,6 @@ public class OrderServiceRpcClient { | ... | @@ -471,7 +486,6 @@ public class OrderServiceRpcClient { |
| 471 | .setCreationSource(batchOperationDto.getCreationSource()) | 486 | .setCreationSource(batchOperationDto.getCreationSource()) |
| 472 | .build(); | 487 | .build(); |
| 473 | return orderServiceRpcBlockingStub.batchCreateOrderOperationRecords(request); | 488 | return orderServiceRpcBlockingStub.batchCreateOrderOperationRecords(request); |
| 474 | - | ||
| 475 | } | 489 | } |
| 476 | 490 | ||
| 477 | public QueryClientCustomerOrdersByPaginationRpcResponse queryClientCustomerOrdersByPagination(QueryOrderByPaginationDto queryOrderDto) { | 491 | public QueryClientCustomerOrdersByPaginationRpcResponse queryClientCustomerOrdersByPagination(QueryOrderByPaginationDto queryOrderDto) { |
| ... | @@ -489,6 +503,14 @@ public class OrderServiceRpcClient { | ... | @@ -489,6 +503,14 @@ public class OrderServiceRpcClient { |
| 489 | return orderServiceRpcBlockingStub.queryClientCustomerOrdersByPagination(request); | 503 | return orderServiceRpcBlockingStub.queryClientCustomerOrdersByPagination(request); |
| 490 | } | 504 | } |
| 491 | 505 | ||
| 506 | + public GetOrderOperationRecordsByOrderIdsResponse getOrderOperationRecordsByOrderIds(int enterpriseId, List<Integer> orderIds) { | ||
| 507 | + final var request = GetOrderOperationRecordsByOrderIdsRequest.newBuilder() | ||
| 508 | + .setEnterpriseId(enterpriseId) | ||
| 509 | + .addAllOrderIds(orderIds) | ||
| 510 | + .build(); | ||
| 511 | + return orderServiceRpcBlockingStub.getOrderOperationRecordsByOrderIds(request); | ||
| 512 | + } | ||
| 513 | + | ||
| 492 | public QueryClientCustomerOrdersByConditionRpcResponse queryClientCustomerOrdersByCondition(OrderDbDTO.QueryOrderDto queryOrderDto) { | 514 | public QueryClientCustomerOrdersByConditionRpcResponse queryClientCustomerOrdersByCondition(OrderDbDTO.QueryOrderDto queryOrderDto) { |
| 493 | final var request = QueryClientCustomerOrdersByConditionRpcRequest.newBuilder() | 515 | final var request = QueryClientCustomerOrdersByConditionRpcRequest.newBuilder() |
| 494 | .setShouldFilterStatus(true) | 516 | .setShouldFilterStatus(true) | ... | ... |
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
| ... | @@ -2,6 +2,7 @@ package com.infoloop.tianting.utils; | ... | @@ -2,6 +2,7 @@ package com.infoloop.tianting.utils; |
| 2 | 2 | ||
| 3 | import com.fasterxml.jackson.annotation.JsonInclude; | 3 | import com.fasterxml.jackson.annotation.JsonInclude; |
| 4 | import com.fasterxml.jackson.core.JsonProcessingException; | 4 | import com.fasterxml.jackson.core.JsonProcessingException; |
| 5 | +import com.fasterxml.jackson.core.type.TypeReference; | ||
| 5 | import com.fasterxml.jackson.databind.DeserializationFeature; | 6 | import com.fasterxml.jackson.databind.DeserializationFeature; |
| 6 | import com.fasterxml.jackson.databind.JsonNode; | 7 | import com.fasterxml.jackson.databind.JsonNode; |
| 7 | import com.fasterxml.jackson.databind.ObjectMapper; | 8 | import com.fasterxml.jackson.databind.ObjectMapper; |
| ... | @@ -41,6 +42,14 @@ public class JsonUtil { | ... | @@ -41,6 +42,14 @@ public class JsonUtil { |
| 41 | } | 42 | } |
| 42 | } | 43 | } |
| 43 | 44 | ||
| 45 | + public static <T> T readJsonAs(final String json, final TypeReference<T> typeRef) { | ||
| 46 | + try { | ||
| 47 | + return OBJECT_MAPPER.readValue(json, typeRef); | ||
| 48 | + } catch (IOException e) { | ||
| 49 | + throw new RuntimeException(e); | ||
| 50 | + } | ||
| 51 | + } | ||
| 52 | + | ||
| 44 | public static <T> T convertValue(final Object object, final Class<T> clazz) { | 53 | public static <T> T convertValue(final Object object, final Class<T> clazz) { |
| 45 | return OBJECT_MAPPER.convertValue(object, clazz); | 54 | return OBJECT_MAPPER.convertValue(object, clazz); |
| 46 | } | 55 | } | ... | ... |
| ... | @@ -32,6 +32,7 @@ service ClientCustomerOrderServiceRpc { | ... | @@ -32,6 +32,7 @@ service ClientCustomerOrderServiceRpc { |
| 32 | 32 | ||
| 33 | // 操作记录 | 33 | // 操作记录 |
| 34 | rpc GetOrderOperationRecordsByOrderId (GetOrderOperationRecordsByOrderIdRequest) returns (GetOrderOperationRecordsByOrderIdResponse) {} | 34 | rpc GetOrderOperationRecordsByOrderId (GetOrderOperationRecordsByOrderIdRequest) returns (GetOrderOperationRecordsByOrderIdResponse) {} |
| 35 | + rpc GetOrderOperationRecordsByOrderIds (GetOrderOperationRecordsByOrderIdsRequest) returns (GetOrderOperationRecordsByOrderIdsResponse) {} | ||
| 35 | rpc BatchCreateOrderOperationRecords (BatchCreateOrderOperationRecordsRequest) returns (BatchCreateOrderOperationRecordsResponse) {} | 36 | rpc BatchCreateOrderOperationRecords (BatchCreateOrderOperationRecordsRequest) returns (BatchCreateOrderOperationRecordsResponse) {} |
| 36 | 37 | ||
| 37 | 38 | ||
| ... | @@ -624,6 +625,15 @@ message GetOrderOperationRecordsByOrderIdResponse { | ... | @@ -624,6 +625,15 @@ message GetOrderOperationRecordsByOrderIdResponse { |
| 624 | repeated OrderOperationRecord responses = 1; | 625 | repeated OrderOperationRecord responses = 1; |
| 625 | } | 626 | } |
| 626 | 627 | ||
| 628 | +message GetOrderOperationRecordsByOrderIdsRequest { | ||
| 629 | + int32 enterpriseId = 1; | ||
| 630 | + repeated int32 orderIds = 2; | ||
| 631 | +} | ||
| 632 | + | ||
| 633 | +message GetOrderOperationRecordsByOrderIdsResponse { | ||
| 634 | + repeated OrderOperationRecord responses = 1; | ||
| 635 | +} | ||
| 636 | + | ||
| 627 | message OrderOperationRecordCreation { | 637 | message OrderOperationRecordCreation { |
| 628 | int32 orderId = 1; | 638 | int32 orderId = 1; |
| 629 | OrderOperationType type = 2; | 639 | OrderOperationType type = 2; | ... | ... |
-
Please register or login to post a comment