feat(order): add support for partial order refund and not serve status
Showing
4 changed files
with
23 additions
and
7 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 | ... | ... |
| ... | @@ -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 | ... | ... |
| ... | @@ -240,6 +240,7 @@ public class OrderServiceRpcClient { | ... | @@ -240,6 +240,7 @@ public class OrderServiceRpcClient { |
| 240 | final var operator = operatorServiceRpcClient.getCOperatorById(operatorLoginInfo.getId()); | 240 | final var operator = operatorServiceRpcClient.getCOperatorById(operatorLoginInfo.getId()); |
| 241 | final var idsOfNeedUpdateMenuDetails = new ArrayList<Integer>(); | 241 | final var idsOfNeedUpdateMenuDetails = new ArrayList<Integer>(); |
| 242 | final var idsOfAddCount = new ArrayList<Integer>(); | 242 | final var idsOfAddCount = new ArrayList<Integer>(); |
| 243 | + final var idsOfNoReject = new ArrayList<Integer>(); | ||
| 243 | List<OrderDetailDto> originalOrderDetails = new ArrayList<>(); | 244 | List<OrderDetailDto> originalOrderDetails = new ArrayList<>(); |
| 244 | List<OrderDetailDto> newOrderDetails; | 245 | List<OrderDetailDto> newOrderDetails; |
| 245 | final var modifications = orderDetailBatchUpdateDto.getDetails().stream().map(d -> { | 246 | final var modifications = orderDetailBatchUpdateDto.getDetails().stream().map(d -> { |
| ... | @@ -280,9 +281,11 @@ public class OrderServiceRpcClient { | ... | @@ -280,9 +281,11 @@ public class OrderServiceRpcClient { |
| 280 | .build(); | 281 | .build(); |
| 281 | } | 282 | } |
| 282 | } | 283 | } |
| 283 | - | ||
| 284 | ServeStatusEnum serveStatus = ServeStatusEnum.UNKNOWN_SERVE_STATUS; | 284 | ServeStatusEnum serveStatus = ServeStatusEnum.UNKNOWN_SERVE_STATUS; |
| 285 | if (d.getShouldUpdateServeStatus()) { | 285 | if (d.getShouldUpdateServeStatus()) { |
| 286 | + if (d.getServeStatus() == ServeStatusEnum.SERVE_REJECT) { | ||
| 287 | + idsOfNoReject.add(d.getId()); | ||
| 288 | + } | ||
| 286 | serveStatus = d.getServeStatus(); | 289 | serveStatus = d.getServeStatus(); |
| 287 | } | 290 | } |
| 288 | Integer count = 0; | 291 | Integer count = 0; |
| ... | @@ -319,7 +322,8 @@ public class OrderServiceRpcClient { | ... | @@ -319,7 +322,8 @@ public class OrderServiceRpcClient { |
| 319 | .build(); | 322 | .build(); |
| 320 | final var totalIds = new ArrayList<>(idsOfNeedUpdateMenuDetails); | 323 | final var totalIds = new ArrayList<>(idsOfNeedUpdateMenuDetails); |
| 321 | totalIds.addAll(idsOfAddCount); | 324 | totalIds.addAll(idsOfAddCount); |
| 322 | - if (!idsOfNeedUpdateMenuDetails.isEmpty() || !idsOfAddCount.isEmpty()) { | 325 | + totalIds.addAll(idsOfNoReject); |
| 326 | + if (!totalIds.isEmpty()) { | ||
| 323 | final var orgionalResponseList = getClientCustomerOrderDetailsByIds(totalIds); | 327 | final var orgionalResponseList = getClientCustomerOrderDetailsByIds(totalIds); |
| 324 | originalOrderDetails = orgionalResponseList.stream().map(d -> OrderDetailDto.builder() | 328 | originalOrderDetails = orgionalResponseList.stream().map(d -> OrderDetailDto.builder() |
| 325 | .id(d.getId()) | 329 | .id(d.getId()) |
| ... | @@ -357,7 +361,7 @@ public class OrderServiceRpcClient { | ... | @@ -357,7 +361,7 @@ public class OrderServiceRpcClient { |
| 357 | } | 361 | } |
| 358 | final var res = orderServiceRpcBlockingStub.batchUpdateClientCustomerOrderDetails(request); | 362 | final var res = orderServiceRpcBlockingStub.batchUpdateClientCustomerOrderDetails(request); |
| 359 | if (res.getIsUpdated()) { | 363 | if (res.getIsUpdated()) { |
| 360 | - if (!idsOfNeedUpdateMenuDetails.isEmpty() || !idsOfAddCount.isEmpty()) { | 364 | + if (!totalIds.isEmpty()) { |
| 361 | final var newResponseList = getClientCustomerOrderDetailsByIds(totalIds); | 365 | final var newResponseList = getClientCustomerOrderDetailsByIds(totalIds); |
| 362 | newOrderDetails = newResponseList.stream().map(d -> | 366 | newOrderDetails = newResponseList.stream().map(d -> |
| 363 | OrderDetailDto.builder() | 367 | OrderDetailDto.builder() |
| ... | @@ -396,7 +400,7 @@ public class OrderServiceRpcClient { | ... | @@ -396,7 +400,7 @@ public class OrderServiceRpcClient { |
| 396 | // 替换菜品的操作记录 | 400 | // 替换菜品的操作记录 |
| 397 | List<SingleOperationDto> operations = new ArrayList<>(); | 401 | List<SingleOperationDto> operations = new ArrayList<>(); |
| 398 | for (OrderDetailDto originalDetail : originalOrderDetails) { | 402 | for (OrderDetailDto originalDetail : originalOrderDetails) { |
| 399 | - if (!idsOfNeedUpdateMenuDetails.contains(originalDetail.getId()) && !idsOfAddCount.contains(originalDetail.getId())) { | 403 | + if (!totalIds.contains(originalDetail.getId())) { |
| 400 | continue; | 404 | continue; |
| 401 | } | 405 | } |
| 402 | OrderOperationType orderOperationType = OrderOperationType.UNKNOWN_OPERATION_TYPE; | 406 | OrderOperationType orderOperationType = OrderOperationType.UNKNOWN_OPERATION_TYPE; |
| ... | @@ -404,6 +408,8 @@ public class OrderServiceRpcClient { | ... | @@ -404,6 +408,8 @@ public class OrderServiceRpcClient { |
| 404 | orderOperationType = OrderOperationType.REPLACE_DISHES; | 408 | orderOperationType = OrderOperationType.REPLACE_DISHES; |
| 405 | } else if (idsOfAddCount.contains(originalDetail.getId())) { | 409 | } else if (idsOfAddCount.contains(originalDetail.getId())) { |
| 406 | orderOperationType = OrderOperationType.ADD_DISHES; | 410 | orderOperationType = OrderOperationType.ADD_DISHES; |
| 411 | + } else if (idsOfNoReject.contains(originalDetail.getId())) { | ||
| 412 | + orderOperationType = OrderOperationType.NOT_SERVE; | ||
| 407 | } | 413 | } |
| 408 | String originalDetailStr; | 414 | String originalDetailStr; |
| 409 | String newDetailStr = ""; | 415 | String newDetailStr = ""; | ... | ... |
| ... | @@ -38,6 +38,7 @@ import lombok.RequiredArgsConstructor; | ... | @@ -38,6 +38,7 @@ import lombok.RequiredArgsConstructor; |
| 38 | import lombok.extern.slf4j.Slf4j; | 38 | import lombok.extern.slf4j.Slf4j; |
| 39 | import org.apache.commons.codec.binary.Base64; | 39 | import org.apache.commons.codec.binary.Base64; |
| 40 | import org.apache.commons.codec.digest.DigestUtils; | 40 | import org.apache.commons.codec.digest.DigestUtils; |
| 41 | +import org.apache.commons.collections4.CollectionUtils; | ||
| 41 | import org.springframework.beans.factory.annotation.Autowired; | 42 | import org.springframework.beans.factory.annotation.Autowired; |
| 42 | import org.springframework.http.HttpEntity; | 43 | import org.springframework.http.HttpEntity; |
| 43 | import org.springframework.http.HttpHeaders; | 44 | import org.springframework.http.HttpHeaders; |
| ... | @@ -346,6 +347,11 @@ public class PayServiceClient { | ... | @@ -346,6 +347,11 @@ public class PayServiceClient { |
| 346 | log.info("Order {} pay is beyond cancel time.", orderId); | 347 | log.info("Order {} pay is beyond cancel time.", orderId); |
| 347 | throw ClientEndExceptions.BusinessException.build(ErrorCodeEnum.ORDER_PAY_REFUND_FAILED); | 348 | throw ClientEndExceptions.BusinessException.build(ErrorCodeEnum.ORDER_PAY_REFUND_FAILED); |
| 348 | } | 349 | } |
| 350 | + BigDecimal detailPrice = BigDecimal.ZERO; | ||
| 351 | + if (CollectionUtils.isNotEmpty(payRefundRequestDto.getOrderDetailIds())) { | ||
| 352 | + final var orderDetails = orderServiceRpcClient.getClientCustomerOrderDetailsByIds(payRefundRequestDto.getOrderDetailIds()); | ||
| 353 | + detailPrice = orderDetails.stream().filter(e -> e.getPrice() > 0).map(e -> new BigDecimal(e.getPrice()).divide(new BigDecimal(100), 2, RoundingMode.HALF_UP)).reduce(BigDecimal.ZERO, BigDecimal::add); | ||
| 354 | + } | ||
| 349 | 355 | ||
| 350 | String appId = businessConfig.getPayClientId(); | 356 | String appId = businessConfig.getPayClientId(); |
| 351 | 357 | ||
| ... | @@ -355,9 +361,9 @@ public class PayServiceClient { | ... | @@ -355,9 +361,9 @@ public class PayServiceClient { |
| 355 | .minusHours(8) | 361 | .minusHours(8) |
| 356 | .format(DateUtil.YMDHMS); | 362 | .format(DateUtil.YMDHMS); |
| 357 | 363 | ||
| 358 | - BigDecimal price = | 364 | + BigDecimal price = detailPrice.compareTo(BigDecimal.ZERO) == 0 ? |
| 359 | - new BigDecimal(orderById.getPayPrice()) | 365 | + new BigDecimal(orderById.getPayPrice()).divide(new BigDecimal(100), 2, RoundingMode.HALF_UP).negate() |
| 360 | - .divide(new BigDecimal(100), 2, RoundingMode.HALF_UP).negate(); | 366 | + : detailPrice.negate(); |
| 361 | 367 | ||
| 362 | String payContentStr = | 368 | String payContentStr = |
| 363 | orderById.getId() | 369 | orderById.getId() | ... | ... |
-
Please register or login to post a comment