diff --git a/src/main/java/com/chint/application/out/LocationController.java b/src/main/java/com/chint/application/out/LocationController.java index ff201d3e..d803ffd6 100644 --- a/src/main/java/com/chint/application/out/LocationController.java +++ b/src/main/java/com/chint/application/out/LocationController.java @@ -18,7 +18,13 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import java.util.AbstractMap; +import java.util.ArrayList; +import java.util.Comparator; import java.util.List; +import java.util.function.BinaryOperator; +import java.util.function.Function; +import java.util.stream.Collectors; import static com.chint.infrastructure.constant.CommonMessageConstant.SUCCESS; import static com.chint.infrastructure.constant.LegConstant.LEG_TYPE_AIRPLANE; @@ -61,7 +67,16 @@ public class LocationController { .toList(); } - if (locations != null && !locations.isEmpty()) { + // + // 在每个分组中,按 locationId 对 Location 进行排序,然后取出每组的第一个元素 + locations = new ArrayList<>(locations.stream() + // 将 Location 对象映射为 locationPath 和 locationPathName 的组合作为 key,Location 对象本身作为 value + .collect(Collectors.toMap(location -> new AbstractMap.SimpleEntry<>(location.getLocationPath(), + location.getLocationPathName()), Function.identity(), + BinaryOperator.minBy(Comparator.comparingLong(Location::getLocationId)))) + .values()); // 将 Stream 转换为 List + + if (!locations.isEmpty()) { locationRes = locations .stream() .map(LocationRes::copyFrom).toList();