zhuyifan

feat(order): add support for partial order refund and not serve status

......@@ -60,4 +60,5 @@ public class PayController {
public String cancel(@Valid @RequestBody PayDTO.PayRefundRequestDto payRefundRequestDto) {
return payServiceClient.orderPayRefund(payRefundRequestDto);
}
}
\ No newline at end of file
......
......@@ -9,6 +9,8 @@ import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
@Data
@ApiModel(description = "支付DTO")
public class PayDTO {
......@@ -31,6 +33,7 @@ public class PayDTO {
@AllArgsConstructor
public static class PayRefundRequestDto {
private Integer orderId;
private List<Integer> orderDetailIds;
private String hospitalCode;
}
......
......@@ -240,6 +240,7 @@ public class OrderServiceRpcClient {
final var operator = operatorServiceRpcClient.getCOperatorById(operatorLoginInfo.getId());
final var idsOfNeedUpdateMenuDetails = new ArrayList<Integer>();
final var idsOfAddCount = new ArrayList<Integer>();
final var idsOfNoReject = new ArrayList<Integer>();
List<OrderDetailDto> originalOrderDetails = new ArrayList<>();
List<OrderDetailDto> newOrderDetails;
final var modifications = orderDetailBatchUpdateDto.getDetails().stream().map(d -> {
......@@ -280,9 +281,11 @@ public class OrderServiceRpcClient {
.build();
}
}
ServeStatusEnum serveStatus = ServeStatusEnum.UNKNOWN_SERVE_STATUS;
if (d.getShouldUpdateServeStatus()) {
if (d.getServeStatus() == ServeStatusEnum.SERVE_REJECT) {
idsOfNoReject.add(d.getId());
}
serveStatus = d.getServeStatus();
}
Integer count = 0;
......@@ -319,7 +322,8 @@ public class OrderServiceRpcClient {
.build();
final var totalIds = new ArrayList<>(idsOfNeedUpdateMenuDetails);
totalIds.addAll(idsOfAddCount);
if (!idsOfNeedUpdateMenuDetails.isEmpty() || !idsOfAddCount.isEmpty()) {
totalIds.addAll(idsOfNoReject);
if (!totalIds.isEmpty()) {
final var orgionalResponseList = getClientCustomerOrderDetailsByIds(totalIds);
originalOrderDetails = orgionalResponseList.stream().map(d -> OrderDetailDto.builder()
.id(d.getId())
......@@ -357,7 +361,7 @@ public class OrderServiceRpcClient {
}
final var res = orderServiceRpcBlockingStub.batchUpdateClientCustomerOrderDetails(request);
if (res.getIsUpdated()) {
if (!idsOfNeedUpdateMenuDetails.isEmpty() || !idsOfAddCount.isEmpty()) {
if (!totalIds.isEmpty()) {
final var newResponseList = getClientCustomerOrderDetailsByIds(totalIds);
newOrderDetails = newResponseList.stream().map(d ->
OrderDetailDto.builder()
......@@ -396,7 +400,7 @@ public class OrderServiceRpcClient {
// 替换菜品的操作记录
List<SingleOperationDto> operations = new ArrayList<>();
for (OrderDetailDto originalDetail : originalOrderDetails) {
if (!idsOfNeedUpdateMenuDetails.contains(originalDetail.getId()) && !idsOfAddCount.contains(originalDetail.getId())) {
if (!totalIds.contains(originalDetail.getId())) {
continue;
}
OrderOperationType orderOperationType = OrderOperationType.UNKNOWN_OPERATION_TYPE;
......@@ -404,6 +408,8 @@ public class OrderServiceRpcClient {
orderOperationType = OrderOperationType.REPLACE_DISHES;
} else if (idsOfAddCount.contains(originalDetail.getId())) {
orderOperationType = OrderOperationType.ADD_DISHES;
} else if (idsOfNoReject.contains(originalDetail.getId())) {
orderOperationType = OrderOperationType.NOT_SERVE;
}
String originalDetailStr;
String newDetailStr = "";
......
......@@ -38,6 +38,7 @@ import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
......@@ -346,6 +347,11 @@ public class PayServiceClient {
log.info("Order {} pay is beyond cancel time.", orderId);
throw ClientEndExceptions.BusinessException.build(ErrorCodeEnum.ORDER_PAY_REFUND_FAILED);
}
BigDecimal detailPrice = BigDecimal.ZERO;
if (CollectionUtils.isNotEmpty(payRefundRequestDto.getOrderDetailIds())) {
final var orderDetails = orderServiceRpcClient.getClientCustomerOrderDetailsByIds(payRefundRequestDto.getOrderDetailIds());
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);
}
String appId = businessConfig.getPayClientId();
......@@ -355,9 +361,9 @@ public class PayServiceClient {
.minusHours(8)
.format(DateUtil.YMDHMS);
BigDecimal price =
new BigDecimal(orderById.getPayPrice())
.divide(new BigDecimal(100), 2, RoundingMode.HALF_UP).negate();
BigDecimal price = detailPrice.compareTo(BigDecimal.ZERO) == 0 ?
new BigDecimal(orderById.getPayPrice()).divide(new BigDecimal(100), 2, RoundingMode.HALF_UP).negate()
: detailPrice.negate();
String payContentStr =
orderById.getId()
......