|
@@ -16,10 +16,16 @@ import com.ylx.massage.domain.dto.CoordinateDTO;
|
|
|
import com.ylx.massage.domain.vo.*;
|
|
import com.ylx.massage.domain.vo.*;
|
|
|
import com.ylx.massage.mapper.AreaMapper;
|
|
import com.ylx.massage.mapper.AreaMapper;
|
|
|
import com.ylx.massage.service.AreaService;
|
|
import com.ylx.massage.service.AreaService;
|
|
|
|
|
+import com.ylx.userhome.area.constants.CityCodeTypeEnum;
|
|
|
|
|
+import com.ylx.userhome.area.domain.vo.CityVo;
|
|
|
|
|
+import com.ylx.userhome.area.util.CityChineseUtil;
|
|
|
|
|
+import org.apache.commons.lang3.ObjectUtils;
|
|
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
|
|
+import java.util.Arrays;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
@@ -38,6 +44,10 @@ public class AreaServiceImpl extends ServiceImpl<AreaMapper, Area> implements Ar
|
|
|
private static final String ERROR_MSG_CITY_NOT_FOUND = "城市数据不存在";
|
|
private static final String ERROR_MSG_CITY_NOT_FOUND = "城市数据不存在";
|
|
|
private static final int MAX_QUERY_RESULTS = 1;
|
|
private static final int MAX_QUERY_RESULTS = 1;
|
|
|
|
|
|
|
|
|
|
+ private static final List<String> PROVINCE_CODE_LIST = Arrays.asList("110100", "120100", "310100", "500100");
|
|
|
|
|
+
|
|
|
|
|
+ private final static String CITY_TYPE = "市辖区";
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 一次性查询所有区域,内存构建树形结构
|
|
* 一次性查询所有区域,内存构建树形结构
|
|
|
*/
|
|
*/
|
|
@@ -155,4 +165,73 @@ public class AreaServiceImpl extends ServiceImpl<AreaMapper, Area> implements Ar
|
|
|
|
|
|
|
|
return new CityInfoVo(area.getName(), area.getCode());
|
|
return new CityInfoVo(area.getName(), area.getCode());
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 用户首页地区查询
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public List<CityVo> getHomeList() {
|
|
|
|
|
+ LambdaQueryWrapper<Area> citySql = new LambdaQueryWrapper<>();
|
|
|
|
|
+ citySql.eq(Area::getLevel, 2);
|
|
|
|
|
+ List<Area> homeListDB = list(citySql);
|
|
|
|
|
+ homeListDB.stream()
|
|
|
|
|
+ .forEach(city -> {
|
|
|
|
|
+ if (PROVINCE_CODE_LIST.contains(city.getCode())) {
|
|
|
|
|
+ String cityName = CityCodeTypeEnum.getCityCodeType(city.getCode());
|
|
|
|
|
+ city.setName(cityName);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ List<CityVo> cityList = cityConvert(homeListDB);
|
|
|
|
|
+ cityList = cityList.stream()
|
|
|
|
|
+ .filter(cityDTO -> ObjectUtils.isNotEmpty(cityDTO.getCityList()) && !cityDTO.getCityList().isEmpty())
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+ return cityList;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public List<CityVo> getCityName(String name) {
|
|
|
|
|
+ LambdaQueryWrapper<Area> citySql = new LambdaQueryWrapper<>();
|
|
|
|
|
+ citySql.like(Area::getName, name);
|
|
|
|
|
+ List<Area> homeList = list(citySql);
|
|
|
|
|
+ List<CityVo> cityList = cityConvert(homeList);
|
|
|
|
|
+ cityList = cityList.stream()
|
|
|
|
|
+ .filter(cityVO -> ObjectUtils.isNotEmpty(cityVO.getCityList()) && !cityVO.getCityList().isEmpty())
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+ return cityList;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private List<CityVo> cityConvert(List<Area> homeListDB) {
|
|
|
|
|
+ List<Area> homeList = homeListDB.stream()
|
|
|
|
|
+ .filter(city -> !CITY_TYPE.equals(city.getName()))
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+ Map<String, Area> cityMap = homeList.stream().collect(Collectors.toMap(Area::getName, Area -> Area, (existing, replacement) -> existing));
|
|
|
|
|
+// }
|
|
|
|
|
+ //获取所有城市名称
|
|
|
|
|
+ List<String> cityList = cityMap.keySet().stream().collect(Collectors.toList());
|
|
|
|
|
+
|
|
|
|
|
+ List<CityVo> cityVoList = new ArrayList<>();
|
|
|
|
|
+ try {
|
|
|
|
|
+ //按照首字母进行城市分组
|
|
|
|
|
+ Map<String, List<String>> pinyingMap = CityChineseUtil.getCodeGroup(cityList);
|
|
|
|
|
+ //将分组对象转化成前端所需格式类型
|
|
|
|
|
+ pinyingMap.forEach((pinying, mapCityList) -> {
|
|
|
|
|
+ CityVo cityVo = new CityVo();
|
|
|
|
|
+ cityVo.setLetter(pinying);
|
|
|
|
|
+ List<CityVo.City> cityNewList = new ArrayList<>();
|
|
|
|
|
+ mapCityList.stream()
|
|
|
|
|
+ .forEach(city -> {
|
|
|
|
|
+ CityVo.City cityNew = new CityVo.City();
|
|
|
|
|
+ BeanUtils.copyProperties(cityMap.get(city), cityNew);
|
|
|
|
|
+ cityNewList.add(cityNew);
|
|
|
|
|
+ });
|
|
|
|
|
+ cityVo.setCityList(cityNewList);
|
|
|
|
|
+ cityVoList.add(cityVo);
|
|
|
|
|
+ });
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("首页城市列表拼音转换接口报错!");
|
|
|
|
|
+ throw new RuntimeException(e);
|
|
|
|
|
+ }
|
|
|
|
|
+ return cityVoList;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|