| 
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -40,6 +40,7 @@ import com.epmet.entity.AreaCodeEntity; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.redis.AreaCodeRedis; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.service.AreaCodeChildService; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.service.AreaCodeService; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import lombok.extern.slf4j.Slf4j; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import org.apache.commons.lang3.StringUtils; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import org.springframework.beans.factory.annotation.Autowired; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import org.springframework.stereotype.Service; | 
				
			
			
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
				 | 
				
					@ -55,6 +56,7 @@ import java.util.stream.Collectors; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					 * @author generator generator@elink-cn.com | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					 * @since v1.0.0 2021-01-07 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					 */ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					@Slf4j | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					@Service | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					public class AreaCodeServiceImpl extends BaseServiceImpl<AreaCodeDao, AreaCodeEntity> implements AreaCodeService { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -568,6 +570,10 @@ public class AreaCodeServiceImpl extends BaseServiceImpl<AreaCodeDao, AreaCodeEn | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					     **/ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    @Override | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    public String addStreetCommAreaCode(AddAreaCodeDictFormDTO formDTO) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        String originalParentCode = formDTO.getParentAreaCode().replaceAll("_UD", ""); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        if (originalParentCode.length() < NumConstant.SIX) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            throw new RenException("目前只允许添加街道或社区"); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        if (StringUtils.isNotBlank(formDTO.getCode())) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            AreaCodeChildDTO areaCodeChildDTO = childDao.selectByCode(formDTO.getCode().trim()); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            if (null == areaCodeChildDTO) { | 
				
			
			
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
				 | 
				
					@ -579,8 +585,11 @@ public class AreaCodeServiceImpl extends BaseServiceImpl<AreaCodeDao, AreaCodeEn | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        AreaCodeChildDTO parent = childDao.selectByCode(formDTO.getParentAreaCode().trim()); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        if (null == parent) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            AreaCodeDTO areaCodeDTOP = baseDao.selectByCountyCode(formDTO.getParentAreaCode().trim()); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            if (null == areaCodeDTOP) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                throw new RenException("parentAreaCode不存在"); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        //同一级不允许重名
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        List<AreaCodeChildDTO> list = childDao.selectByPCodeAndName(formDTO.getParentAreaCode().trim(), formDTO.getName().trim()); | 
				
			
			
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
				 | 
				
					@ -590,8 +599,12 @@ public class AreaCodeServiceImpl extends BaseServiceImpl<AreaCodeDao, AreaCodeEn | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        AreaCodeChildDTO areaCodeChildDTO = new AreaCodeChildDTO(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        areaCodeChildDTO.setName(formDTO.getName().trim()); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        areaCodeChildDTO.setPCode(formDTO.getParentAreaCode().trim()); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        //4:街道;5:社区或村委会
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        areaCodeChildDTO.setLevel(formDTO.getParentAreaCode().length() == NumConstant.SIX ? NumConstant.FOUR : NumConstant.FIVE); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        if (formDTO.getParentAreaCode().length() == NumConstant.SIX) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            //如果是增加街道
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            areaCodeChildDTO.setLevel(NumConstant.FOUR); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        } else { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            areaCodeChildDTO.setLevel(null != parent && null != parent.getLevel() ? parent.getLevel() + 1 : null); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        //获取子级中最大的编码
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        AreaCodeChildDTO maxChildDto = childDao.selectMaxChild(formDTO.getParentAreaCode().trim()); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        if (null == maxChildDto) { | 
				
			
			
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
				 | 
				
					@ -599,13 +612,28 @@ public class AreaCodeServiceImpl extends BaseServiceImpl<AreaCodeDao, AreaCodeEn | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            areaCodeChildDTO.setCode(formDTO.getParentAreaCode().concat("001_UD")); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        } else { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            //去掉_UD +1赋值;370124001225_UD  锦源社区
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            String[] codeArr = maxChildDto.getCode().split(StrConstant.UNDER_LINE); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            /*String[] codeArr = maxChildDto.getCode().split(StrConstant.UNDER_LINE); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            long code = Long.parseLong(codeArr[NumConstant.ZERO]) + NumConstant.ONE; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            areaCodeChildDTO.setCode(String.valueOf(code).concat("_UD")); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            areaCodeChildDTO.setCode(String.valueOf(code).concat("_UD"));*/ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            String subStr = maxChildDto.getCode().replaceAll(formDTO.getParentAreaCode(), ""); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            String[] codeArr = subStr.split(StrConstant.UNDER_LINE); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            long num = Long.parseLong(codeArr[NumConstant.ZERO]) + NumConstant.ONE; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            String numStr = String.valueOf(num); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            String temp = ""; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            if (numStr.length() == 2) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                temp = "0".concat(numStr); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            } else if (numStr.length() == 1) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                temp = "00".concat(numStr); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            } else { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                temp = numStr; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            areaCodeChildDTO.setCode(formDTO.getParentAreaCode().concat(temp).concat("_UD")); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            /*log.info("最大="+maxChildDto.getCode()+";去初父级("+formDTO.getParentAreaCode()+"):"+subStr); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            log.info("数字位+1="+num); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            log.info("temp="+temp);*/ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        //保存到area_code_child表
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        areaCodeChildService.save(areaCodeChildDTO); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        return areaCodeChildDTO.getCode(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					} |