|
|
@@ -15,9 +15,7 @@ import io.renren.modules.qyh.service.ServiceCityService;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@RequiredArgsConstructor
|
|
|
@@ -57,8 +55,17 @@ public class ServiceCityServiceImpl extends ServiceImpl<ServiceCityMapper, Servi
|
|
|
//按首字母分组
|
|
|
Map<String, List<ServiceCityEntity>> map = list.stream().collect(Collectors.groupingBy(ServiceCityEntity::getLetter));
|
|
|
//分组后按首字母排序
|
|
|
- map.entrySet().stream().sorted(Map.Entry.comparingByKey());
|
|
|
- for (Map.Entry<String, List<ServiceCityEntity>> entry : map.entrySet()) {
|
|
|
+ Map<String, List<ServiceCityEntity>> sortedMap = map.entrySet().stream()
|
|
|
+ .sorted(Map.Entry.comparingByKey())
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ Map.Entry::getKey,
|
|
|
+ entry -> entry.getValue().stream()
|
|
|
+ .sorted(Comparator.comparingInt(ServiceCityEntity::getSort))
|
|
|
+ .collect(Collectors.toList()),
|
|
|
+ (e1, e2) -> e1,
|
|
|
+ LinkedHashMap::new
|
|
|
+ ));
|
|
|
+ for (Map.Entry<String, List<ServiceCityEntity>> entry : sortedMap.entrySet()) {
|
|
|
Map<String, Object> map1 = new HashMap<>();
|
|
|
map1.put("letter", entry.getKey());
|
|
|
map1.put("city", entry.getValue());
|