From ae404ff1fd6a05effd0113e805220fcc47944935 Mon Sep 17 00:00:00 2001 From: lulz1 Date: Fri, 5 Jul 2024 15:02:43 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8D=E6=89=93=E8=BD=A6?= =?UTF-8?q?=E8=A1=8C=E7=A8=8B=E6=B2=A1=E6=9C=89=E6=9B=B4=E6=96=B0=E5=9C=B0?= =?UTF-8?q?=E7=82=B9=E8=AE=A1=E7=AE=97=E5=AD=97=E6=AE=B5=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/dtos/response/LegRes.java | 33 ++++++++++++++++--- .../domain/service/LegDomainService.java | 2 +- .../java/com/chint/RouteApplicationTests.java | 17 ++++++++++ 3 files changed, 47 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/chint/application/dtos/response/LegRes.java b/src/main/java/com/chint/application/dtos/response/LegRes.java index f35172fb..5895a117 100644 --- a/src/main/java/com/chint/application/dtos/response/LegRes.java +++ b/src/main/java/com/chint/application/dtos/response/LegRes.java @@ -9,12 +9,14 @@ import com.chint.domain.aggregates.order.OrderDetail; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import org.springframework.data.annotation.Id; -import org.springframework.data.annotation.Transient; import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.List; +import static com.chint.infrastructure.constant.LegConstant.LEG_TYPE_OTHER; +import static com.chint.infrastructure.constant.LegConstant.LEG_TYPE_TAXI; + @Data public class LegRes { @Id @@ -51,7 +53,7 @@ public class LegRes { private Integer legApprovalStatus; private String legApprovalStatusName; private String currencyType; - + private String locationNameList; private List otherLocationList; private List orderDetails; //这个属性不做持久化保存 ,根据下单事件进行获取 @@ -84,8 +86,10 @@ public class LegRes { if (leg.getCurrencyType() != null) { legRes.setCurrencyType(leg.getCurrencyType().getCode()); } - legRes.setOriginLocation(LocationRes.copyFrom(leg.getOriginLocation())); - legRes.setDestinationLocation(LocationRes.copyFrom(leg.getDestinationLocation())); + Location originLocation = leg.getOriginLocation(); + Location destinationLocation = leg.getDestinationLocation(); + legRes.setOriginLocation(LocationRes.copyFrom(originLocation)); + legRes.setDestinationLocation(LocationRes.copyFrom(destinationLocation)); if (legRes.getSupplierList() == null) { legRes.setSupplierList(new ArrayList<>()); @@ -94,6 +98,27 @@ public class LegRes { if (legRes.getSupplierNameList() == null) { legRes.setSupplierNameList(new ArrayList<>()); } + + StringBuilder sb = new StringBuilder(); + if (leg.getLegType().equals(LEG_TYPE_TAXI) || leg.getLegType().equals(LEG_TYPE_OTHER)) { + List locationList = leg.getLegExtensionField().getLocationList(); + if (locationList != null && !locationList.isEmpty()) { + for (Location location : locationList) { + sb.append(location.getLocationName()); + sb.append(","); + } + // Remove the last comma + if (!sb.isEmpty()) { + sb.setLength(sb.length() - 1); + } + legRes.setLocationNameList(sb.toString()); + } + } else { + sb.append(originLocation.getLocationName()); + sb.append(","); + sb.append(destinationLocation.getLocationName()); + } + legRes.setLocationNameList(sb.toString()); return legRes; } } diff --git a/src/main/java/com/chint/domain/service/LegDomainService.java b/src/main/java/com/chint/domain/service/LegDomainService.java index 9d61f058..d3e88569 100644 --- a/src/main/java/com/chint/domain/service/LegDomainService.java +++ b/src/main/java/com/chint/domain/service/LegDomainService.java @@ -180,7 +180,7 @@ public class LegDomainService { List locationIdsAsLong = getLocationIdsAsLong(legExtensionField); List locationList = legExtensionField.getLocationList(); if (locationList == null || locationList.size() != locationIdsAsLong.size() || - checkIfSameLocationList(locationList, locationIdsAsLong)) { + !checkIfSameLocationList(locationList, locationIdsAsLong)) { List byNameList = locationRepository.findByNameList(locationIdsAsLong); legExtensionField.setLocationList(byNameList); updated = true; diff --git a/src/test/java/com/chint/RouteApplicationTests.java b/src/test/java/com/chint/RouteApplicationTests.java index 4a3a56e2..471e8ece 100644 --- a/src/test/java/com/chint/RouteApplicationTests.java +++ b/src/test/java/com/chint/RouteApplicationTests.java @@ -1506,4 +1506,21 @@ class RouteApplicationTests { e.printStackTrace(); } } + + @Test + void spiltTest() { + String[] parts = "2024-07-05 00:00:00|2024-07-19 00:00:00|null|null|200.00|53".split("\\|"); + if (parts.length >= 5) { + System.out.println(parts[0]); + System.out.println(parts[1]); + System.out.println(parts[2]); + System.out.println(parts[3]); + System.out.println(parts[4]); + } else { + throw new IllegalArgumentException("Invalid legString format."); + } + if (parts.length >= 6 && parts[5] != null && !parts[5].isEmpty() && !"null".equals(parts[5])) { + System.out.println(parts[5]); + } + } }