diff --git a/src/main/java/com/gis3c/spatial/common/FeatureUtilities.java b/src/main/java/com/gis3c/spatial/common/FeatureUtilities.java index 901e652..8df4f4a 100644 --- a/src/main/java/com/gis3c/spatial/common/FeatureUtilities.java +++ b/src/main/java/com/gis3c/spatial/common/FeatureUtilities.java @@ -1,6 +1,7 @@ package com.gis3c.spatial.common; -import com.gis3c.spatial.entity.feature.BaseFeature; + +import com.gis3c.spatial.entity.BaseFeature; import org.geotools.data.DataUtilities; import org.geotools.data.simple.SimpleFeatureCollection; import org.geotools.geojson.feature.FeatureJSON; diff --git a/src/main/java/com/gis3c/spatial/dao/RegionDao.java b/src/main/java/com/gis3c/spatial/dao/RegionDao.java index 8ccb990..0ba4139 100644 --- a/src/main/java/com/gis3c/spatial/dao/RegionDao.java +++ b/src/main/java/com/gis3c/spatial/dao/RegionDao.java @@ -1,5 +1,6 @@ package com.gis3c.spatial.dao; +import com.gis3c.common.persistence.annotation.C3SpatialDao; import com.gis3c.spatial.entity.Region; import java.util.List; @@ -8,10 +9,11 @@ import java.util.Map; /** * Created by hukekuan on 2018/3/9. */ +@C3SpatialDao public interface RegionDao { - public Region findRegionByCode(String reginType, String reginCode); - public String findRgionCenterByCode(String reginType, String reginCode); - public List findAroundRegions(String reginType, String reginCode); - public List findRegionsByParentCode(String parentCode); - public List> findRegionCentersByParentCode(String parentCode); + public Region findRegionByCode(String reginTable, String reginCode); + public String findRgionCenterByCode(String reginTable, String reginCode); + public List findAroundRegions(String reginTable, String reginCode); + public List findRegionsByParentCode(String reginTable, String parentCode); + public List> findRegionCentersByParentCode(String reginTable, String parentCode); } diff --git a/src/main/java/com/gis3c/spatial/entity/RegionType.java b/src/main/java/com/gis3c/spatial/entity/RegionType.java new file mode 100644 index 0000000..74395de --- /dev/null +++ b/src/main/java/com/gis3c/spatial/entity/RegionType.java @@ -0,0 +1,38 @@ +package com.gis3c.spatial.entity; + +/** + * Created by hukekuan on 2018/3/9. + */ +public enum RegionType { + PROVINCE("geoprovince"), CITY("geocity"), COUNTRY("geocountry"), TOWN("geotown"); + + private String name; + + private RegionType(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public RegionType ChildType() { + RegionType childType = null; + switch (this) { + case PROVINCE: + childType = RegionType.CITY; + break; + case CITY: + childType = RegionType.COUNTRY; + break; + case COUNTRY: + childType = RegionType.TOWN; + break; + } + return childType; + } +} diff --git a/src/main/java/com/gis3c/spatial/service/RegionService.java b/src/main/java/com/gis3c/spatial/service/RegionService.java index 4b96dd5..fa31928 100644 --- a/src/main/java/com/gis3c/spatial/service/RegionService.java +++ b/src/main/java/com/gis3c/spatial/service/RegionService.java @@ -11,26 +11,23 @@ import java.util.Map; public interface RegionService { /** * 获取区域实体 - * @param reginType * @param reginCode */ - public Region findRegionByCode(String reginType, String reginCode); + public Region findRegionByCode(String reginCode); /** * 获取区域中心点 - * @param reginType * @param reginCode * @return 中心点wkt字符串 */ - public String findRgionCenterByCode(String reginType, String reginCode); + public String findRgionCenterByCode(String reginCode); /** * 获取区域周边区域 - * @param reginType * @param reginCode * @return */ - public List findAroundRegions(String reginType, String reginCode); + public List findAroundRegions(String reginCode); /** * 获取区域内部的所有子区域 diff --git a/src/main/java/com/gis3c/spatial/service/impl/RegionServiceImpl.java b/src/main/java/com/gis3c/spatial/service/impl/RegionServiceImpl.java index 96e1428..937373b 100644 --- a/src/main/java/com/gis3c/spatial/service/impl/RegionServiceImpl.java +++ b/src/main/java/com/gis3c/spatial/service/impl/RegionServiceImpl.java @@ -1,7 +1,11 @@ package com.gis3c.spatial.service.impl; +import com.gis3c.spatial.dao.RegionDao; import com.gis3c.spatial.entity.Region; +import com.gis3c.spatial.entity.RegionType; import com.gis3c.spatial.service.RegionService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; import java.util.List; import java.util.Map; @@ -9,29 +13,101 @@ import java.util.Map; /** * Created by hukekuan on 2018/3/9. */ +@Service public class RegionServiceImpl implements RegionService { + @Autowired + private RegionDao regionDao; + @Override - public Region findRegionByCode(String reginType, String reginCode) { - return null; + public Region findRegionByCode(String reginCode) { + return regionDao.findRegionByCode( + regionTableByCode(reginCode).getName(), + reginCode + ); } @Override - public String findRgionCenterByCode(String reginType, String reginCode) { - return null; + public String findRgionCenterByCode(String reginCode) { + return regionDao.findRgionCenterByCode( + regionTableByCode(reginCode).getName(), + reginCode + ); } @Override - public List findAroundRegions(String reginType, String reginCode) { - return null; + public List findAroundRegions(String reginCode) { + return regionDao.findAroundRegions( + regionTableByCode(reginCode).getName(), + reginCode + ); } @Override public List findRegionsByParentCode(String parentCode) { - return null; + RegionType parentType = regionTableByCode(parentCode); + RegionType regionType = parentType.ChildType(); + if (regionType == null) { + throw new IllegalArgumentException("新政区编号输入错误"); + } + + return regionDao.findRegionsByParentCode( + regionType.getName(), + getlikeCode(parentCode) + ); } @Override public List> findRegionCentersByParentCode(String parentCode) { - return null; + RegionType parentType = regionTableByCode(parentCode); + RegionType regionType = parentType.ChildType(); + if (regionType == null) { + throw new IllegalArgumentException("新政区编号输入错误"); + } + + return regionDao.findRegionCentersByParentCode( + regionType.getName(), + getlikeCode(parentCode) + ); + } + + /** + * 根据行政区编号信息获取对应的新政区类型 + * + * @param regionCode + * @return + */ + private RegionType regionTableByCode(String regionCode) { + if (regionCode == null || (regionCode.length() != 6 && regionCode.length() != 12)) { + throw new IllegalArgumentException("行政区编号格式错误"); + } + RegionType regionTable = null; + int codeLength = regionCode.length(); + String checkedCode = regionCode.substring(codeLength - 3, codeLength); + if ("000".equals(checkedCode)) { + regionTable = codeLength == 6 ? RegionType.PROVINCE : RegionType.TOWN; + } else if (checkedCode.endsWith("00")) { + regionTable = RegionType.CITY; + } else { + regionTable = RegionType.COUNTRY; + } + return regionTable; + } + + /** + * 获取用于查询子行政区的行政区编号 + * + * @param regionCode + * @return + */ + private String getlikeCode(String regionCode) { + String liekCode = null; + if (regionCode.endsWith("0000")) { + liekCode = regionCode.substring(0, 2); + } else if (regionCode.endsWith("00")) { + liekCode = regionCode.substring(0, 4); + } else { + liekCode = regionCode; + } + return liekCode; } } diff --git a/src/test/java/com/gis3c/spatial/App.java b/src/test/java/com/gis3c/spatial/App.java index f1c8a34..50451c8 100644 --- a/src/test/java/com/gis3c/spatial/App.java +++ b/src/test/java/com/gis3c/spatial/App.java @@ -6,6 +6,7 @@ import com.gis3c.ol.entity.Map; import com.gis3c.ol.service.LayerService; import com.gis3c.ol.service.MapService; import com.gis3c.ol.service.SourceService; +import com.gis3c.spatial.entity.RegionType; import com.gis3c.spatial.service.TestService; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; @@ -25,15 +26,19 @@ public class App { public static void main(String[] args) throws IllegalAccessException, IOException { ApplicationContext context = ApplicationInit(); - SourceService sourceService = context.getBean(SourceService.class); - LayerService layerService = context.getBean(LayerService.class); - MapService mapService = context.getBean(MapService.class); - TestService testService = context.getBean(TestService.class); - - +// SourceService sourceService = context.getBean(SourceService.class); +// LayerService layerService = context.getBean(LayerService.class); +// MapService mapService = context.getBean(MapService.class); +// TestService testService = context.getBean(TestService.class); + String code = "370300"; + System.out.println(code.substring(0,4)); +// RegionType r1 = RegionType.CITY; +// RegionType r2 = RegionType.CITY; +// +// System.out.println(r1.ChildType().getName()); diff --git a/src/test/java/com/gis3c/spatial/entity/Test.java b/src/test/java/com/gis3c/spatial/entity/Test.java index 2f5cea9..9e0dcb7 100644 --- a/src/test/java/com/gis3c/spatial/entity/Test.java +++ b/src/test/java/com/gis3c/spatial/entity/Test.java @@ -1,7 +1,5 @@ package com.gis3c.spatial.entity; -import com.gis3c.spatial.entity.feature.BaseFeature; - /** * Created by hukekuan on 2018/1/16. */ diff --git a/src/test/resources/mappings/spatial/RegionDao.xml b/src/test/resources/mappings/spatial/RegionDao.xml new file mode 100644 index 0000000..612c87e --- /dev/null +++ b/src/test/resources/mappings/spatial/RegionDao.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/mappings/spatial/TestDao.xml b/src/test/resources/mappings/spatial/TestDao.xml deleted file mode 100644 index fd2a918..0000000 --- a/src/test/resources/mappings/spatial/TestDao.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/src/test/resources/resources.properties b/src/test/resources/resources.properties index b1c1c10..ba0eafd 100644 --- a/src/test/resources/resources.properties +++ b/src/test/resources/resources.properties @@ -5,6 +5,6 @@ sys.username=gis sys.password=gis spatial.driverClassName=org.postgresql.Driver -spatial.url=jdbc:postgresql:postgis +spatial.url=jdbc:postgresql://172.16.6.13:5432/gisdb spatial.username=postgres spatial.password=postgres \ No newline at end of file