fix:修复打车行程没有更新地点计算字段的问题

This commit is contained in:
lulz1 2024-07-05 15:02:43 +08:00
parent e8c277926e
commit ae404ff1fd
3 changed files with 47 additions and 5 deletions

View File

@ -9,12 +9,14 @@ import com.chint.domain.aggregates.order.OrderDetail;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import org.springframework.data.annotation.Id; import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Transient;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; 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 @Data
public class LegRes { public class LegRes {
@Id @Id
@ -51,7 +53,7 @@ public class LegRes {
private Integer legApprovalStatus; private Integer legApprovalStatus;
private String legApprovalStatusName; private String legApprovalStatusName;
private String currencyType; private String currencyType;
private String locationNameList;
private List<LocationRes> otherLocationList; private List<LocationRes> otherLocationList;
private List<OrderDetail> orderDetails; //这个属性不做持久化保存 根据下单事件进行获取 private List<OrderDetail> orderDetails; //这个属性不做持久化保存 根据下单事件进行获取
@ -84,8 +86,10 @@ public class LegRes {
if (leg.getCurrencyType() != null) { if (leg.getCurrencyType() != null) {
legRes.setCurrencyType(leg.getCurrencyType().getCode()); legRes.setCurrencyType(leg.getCurrencyType().getCode());
} }
legRes.setOriginLocation(LocationRes.copyFrom(leg.getOriginLocation())); Location originLocation = leg.getOriginLocation();
legRes.setDestinationLocation(LocationRes.copyFrom(leg.getDestinationLocation())); Location destinationLocation = leg.getDestinationLocation();
legRes.setOriginLocation(LocationRes.copyFrom(originLocation));
legRes.setDestinationLocation(LocationRes.copyFrom(destinationLocation));
if (legRes.getSupplierList() == null) { if (legRes.getSupplierList() == null) {
legRes.setSupplierList(new ArrayList<>()); legRes.setSupplierList(new ArrayList<>());
@ -94,6 +98,27 @@ public class LegRes {
if (legRes.getSupplierNameList() == null) { if (legRes.getSupplierNameList() == null) {
legRes.setSupplierNameList(new ArrayList<>()); legRes.setSupplierNameList(new ArrayList<>());
} }
StringBuilder sb = new StringBuilder();
if (leg.getLegType().equals(LEG_TYPE_TAXI) || leg.getLegType().equals(LEG_TYPE_OTHER)) {
List<Location> 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; return legRes;
} }
} }

View File

@ -180,7 +180,7 @@ public class LegDomainService {
List<Long> locationIdsAsLong = getLocationIdsAsLong(legExtensionField); List<Long> locationIdsAsLong = getLocationIdsAsLong(legExtensionField);
List<Location> locationList = legExtensionField.getLocationList(); List<Location> locationList = legExtensionField.getLocationList();
if (locationList == null || locationList.size() != locationIdsAsLong.size() || if (locationList == null || locationList.size() != locationIdsAsLong.size() ||
checkIfSameLocationList(locationList, locationIdsAsLong)) { !checkIfSameLocationList(locationList, locationIdsAsLong)) {
List<Location> byNameList = locationRepository.findByNameList(locationIdsAsLong); List<Location> byNameList = locationRepository.findByNameList(locationIdsAsLong);
legExtensionField.setLocationList(byNameList); legExtensionField.setLocationList(byNameList);
updated = true; updated = true;

View File

@ -1506,4 +1506,21 @@ class RouteApplicationTests {
e.printStackTrace(); 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]);
}
}
} }