|
@@ -3,11 +3,18 @@ package cn.hnthyy.thmz.service.impl.his;
|
|
|
import cn.hnthyy.thmz.entity.his.mz.CodeNameEntity;
|
|
|
import cn.hnthyy.thmz.mapper.his.mz.RegionMapper;
|
|
|
import cn.hnthyy.thmz.service.his.RegionService;
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
@Service
|
|
|
+@Slf4j
|
|
|
public class RegionServiceImpl implements RegionService {
|
|
|
@SuppressWarnings("all")
|
|
|
@Autowired
|
|
@@ -36,4 +43,93 @@ public class RegionServiceImpl implements RegionService {
|
|
|
public List<CodeNameEntity> queryAll() {
|
|
|
return regionMapper.selectAll();
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param result
|
|
|
+ * @description: 根据中文地址 获取 省市区县编码 参数 province city district
|
|
|
+ * @author: lihong
|
|
|
+ * @date: 2025/2/12 15:46
|
|
|
+ * @param: result
|
|
|
+ * @return: java.util.Map<java.lang.String, java.lang.Object>
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> getAddressCodes(Map<String, String> result) {
|
|
|
+ Map<String, Object> codeMap = new HashMap<>();
|
|
|
+ String province = result.get("province");
|
|
|
+ String city = result.get("city");
|
|
|
+ String district = result.get("district");
|
|
|
+ try {
|
|
|
+ if(StrUtil.isBlank(province)){
|
|
|
+ putByCity(codeMap,city,district);
|
|
|
+ }else {
|
|
|
+ CodeNameEntity codeNameEntity = regionMapper.selectByName(province, null);
|
|
|
+ if(codeNameEntity != null){
|
|
|
+ codeMap.put("provinceCode",codeNameEntity.getCode());
|
|
|
+ if(StrUtil.isBlank(city)){
|
|
|
+ putByDistrict(codeMap, district, codeNameEntity);
|
|
|
+ }else {
|
|
|
+ CodeNameEntity tempCity = regionMapper.selectByName(city, codeNameEntity.getCode());
|
|
|
+ if(tempCity != null){
|
|
|
+ codeMap.put("cityCode",tempCity.getCode());
|
|
|
+ if(StrUtil.isNotBlank(district)){
|
|
|
+ CodeNameEntity districtEntity = regionMapper.selectByName(district, tempCity.getCode());
|
|
|
+ codeMap.put("districtCode",districtEntity.getCode());
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ if(StrUtil.isBlank(district)){
|
|
|
+ List<CodeNameEntity> districtEntity = regionMapper.getByName(city);
|
|
|
+ if(CollUtil.isNotEmpty(districtEntity)){
|
|
|
+ codeMap.put("cityCode",districtEntity.get(0).getParentCode());
|
|
|
+ codeMap.put("districtCode",districtEntity.get(0).getCode());
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ putByDistrict(codeMap, district, codeNameEntity);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ putByCity(codeMap, city, district);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ log.error("根据中文地址获取省市区县编码报错{}",e);
|
|
|
+ }
|
|
|
+ return codeMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void putByDistrict(Map<String, Object> codeMap, String district, CodeNameEntity codeNameEntity) {
|
|
|
+ if(StrUtil.isNotBlank(district)){
|
|
|
+ List<CodeNameEntity> nameEntities = regionMapper.getByName(district);
|
|
|
+ if(CollUtil.isNotEmpty(nameEntities)){
|
|
|
+ if(nameEntities.size() == 1){
|
|
|
+ codeMap.put("cityCode", nameEntities.get(0).getParentCode());
|
|
|
+ codeMap.put("districtCode", nameEntities.get(0).getCode());
|
|
|
+ }else {
|
|
|
+ for(CodeNameEntity entity : nameEntities){
|
|
|
+ CodeNameEntity parentEntity = regionMapper.selectByCode(entity.getParentCode());
|
|
|
+ if(parentEntity.getParentCode().equals(codeNameEntity.getCode())){
|
|
|
+ codeMap.put("cityCode", entity.getParentCode());
|
|
|
+ codeMap.put("districtCode", entity.getCode());
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void putByCity(Map<String, Object> codeMap, String city, String district) {
|
|
|
+ if(StrUtil.isNotBlank(city)){
|
|
|
+ List<CodeNameEntity> cityEntityList = regionMapper.getByName(city);
|
|
|
+ if(CollUtil.isNotEmpty(cityEntityList)){
|
|
|
+ codeMap.put("provinceCode",cityEntityList.get(0).getParentCode());
|
|
|
+ codeMap.put("cityCode",cityEntityList.get(0).getCode());
|
|
|
+ if(StrUtil.isNotBlank(district)){
|
|
|
+ CodeNameEntity districtEntity = regionMapper.selectByName(district, cityEntityList.get(0).getCode());
|
|
|
+ codeMap.put("districtCode",districtEntity.getCode());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|