diff --git a/pom.xml b/pom.xml index bb8e5f3..42723e4 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.c3gis c3gis - 1.0.2 + 1.0.3 diff --git a/src/main/java/com/gis3c/common/bean/BeanUtil.java b/src/main/java/com/gis3c/common/bean/BeanUtil.java new file mode 100644 index 0000000..7c9bfa7 --- /dev/null +++ b/src/main/java/com/gis3c/common/bean/BeanUtil.java @@ -0,0 +1,30 @@ +package com.gis3c.common.bean; + +import java.lang.reflect.Field; +import java.util.HashMap; +import java.util.Map; + +/** + * Created by hukekuan on 2018/1/29. + */ +public class BeanUtil { + public static Map Bean2Map(Object instance,Class cls) throws IllegalAccessException { + Map result = new HashMap<>(); + Field[] fields = cls.getDeclaredFields(); + Object value; + Map mapValue; + for(Field field:fields){ + field.setAccessible(true); + value = field.get(instance); + if(value instanceof HashMap){ + mapValue = (HashMap) value; + for(Map.Entry entry:mapValue.entrySet()){ + result.put(entry.getKey(),entry.getValue()); + } + }else{ + result.put(field.getName(),value); + } + } + return result; + } +} diff --git a/src/main/java/com/gis3c/common/exception/BusinessException.java b/src/main/java/com/gis3c/common/exception/BusinessException.java new file mode 100644 index 0000000..745ec9a --- /dev/null +++ b/src/main/java/com/gis3c/common/exception/BusinessException.java @@ -0,0 +1,24 @@ +package com.gis3c.common.exception; + +/** + * Created by hukekuan on 2018/1/29. + */ +public class BusinessException extends RuntimeException { + private static final long serialVersionUID = 1L; + + public BusinessException(){ + super(); + } + + public BusinessException(String message) { + super(message); + } + + public BusinessException(Throwable cause) { + super(cause); + } + + public BusinessException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/src/main/java/com/gis3c/common/exception/DataException.java b/src/main/java/com/gis3c/common/exception/DataException.java new file mode 100644 index 0000000..7ec077e --- /dev/null +++ b/src/main/java/com/gis3c/common/exception/DataException.java @@ -0,0 +1,25 @@ +package com.gis3c.common.exception; + +/** + * Created by hukekuan on 2018/1/29. + */ +public class DataException extends RuntimeException { + private static final long serialVersionUID = 1L; + + public DataException(String message, Throwable cause, + boolean enableSuppression, boolean writableStackTrace){ + super(message,cause,enableSuppression,writableStackTrace); + } + + public DataException(String message,Throwable cause){ + super(message,cause); + } + + public DataException(String message){ + super(message); + } + + public DataException(Throwable cause){ + super(cause); + } +} diff --git a/src/main/java/com/gis3c/common/exception/ViewException.java b/src/main/java/com/gis3c/common/exception/ViewException.java new file mode 100644 index 0000000..2595ea4 --- /dev/null +++ b/src/main/java/com/gis3c/common/exception/ViewException.java @@ -0,0 +1,25 @@ +package com.gis3c.common.exception; + +/** + * Created by hukekuan on 2018/1/29. + */ +public class ViewException extends RuntimeException { + private static final long serialVersionUID = 1L; + + public ViewException(String message, Throwable cause, + boolean enableSuppression, boolean writableStackTrace){ + super(message,cause,enableSuppression,writableStackTrace); + } + + public ViewException(String message,Throwable cause){ + super(message,cause); + } + + public ViewException(String message){ + super(message); + } + + public ViewException(Throwable cause){ + super(cause); + } +} diff --git a/src/main/java/com/gis3c/ol/service/LayerService.java b/src/main/java/com/gis3c/ol/service/LayerService.java index a56cb09..a3f41eb 100644 --- a/src/main/java/com/gis3c/ol/service/LayerService.java +++ b/src/main/java/com/gis3c/ol/service/LayerService.java @@ -10,7 +10,7 @@ import java.util.List; */ public interface LayerService { public List findAllList(); - public List findLayersByPage(Integer pageSize,Integer currentPage); + public List> findLayersByPage(Integer pageSize,Integer currentPage); public Layer findeLayerById(String layerId); public Layer findeLayerByName(String layerName); diff --git a/src/main/java/com/gis3c/ol/service/MapService.java b/src/main/java/com/gis3c/ol/service/MapService.java index 6685d77..7862483 100644 --- a/src/main/java/com/gis3c/ol/service/MapService.java +++ b/src/main/java/com/gis3c/ol/service/MapService.java @@ -9,7 +9,7 @@ import java.util.List; */ public interface MapService { public List findAllList(); - public List findMapsByPage(Integer pageSize,Integer currentPage); + public List> findMapsByPage(Integer pageSize,Integer currentPage); public Map findMapById(String mapId); public Map findMapByName(String mapName); diff --git a/src/main/java/com/gis3c/ol/service/SourceService.java b/src/main/java/com/gis3c/ol/service/SourceService.java index 6cb36d5..bd1feab 100644 --- a/src/main/java/com/gis3c/ol/service/SourceService.java +++ b/src/main/java/com/gis3c/ol/service/SourceService.java @@ -8,7 +8,7 @@ import java.util.List; */ public interface SourceService { public List findAllList(); - public List findSourcesByPage(Integer pageSize,Integer currentPage); + public List> findSourcesByPage(Integer pageSize,Integer currentPage); public Source findSourceById(String sourceId); public Source findSourceByName(String sourceName); public Integer insertSource(Source source); diff --git a/src/main/java/com/gis3c/ol/service/impl/LayerServiceImpl.java b/src/main/java/com/gis3c/ol/service/impl/LayerServiceImpl.java index 47d670f..8310e5e 100644 --- a/src/main/java/com/gis3c/ol/service/impl/LayerServiceImpl.java +++ b/src/main/java/com/gis3c/ol/service/impl/LayerServiceImpl.java @@ -1,11 +1,15 @@ package com.gis3c.ol.service.impl; +import com.gis3c.common.bean.BeanUtil; +import com.gis3c.common.exception.BusinessException; import com.gis3c.ol.dao.LayerDao; import com.gis3c.ol.entity.Layer; +import com.gis3c.ol.entity.Source; import com.gis3c.ol.service.LayerService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.ArrayList; import java.util.List; import java.util.UUID; @@ -23,8 +27,17 @@ public class LayerServiceImpl implements LayerService { } @Override - public List findLayersByPage(Integer pageSize, Integer currentPage) { - return layerDao.findLayersByPage(pageSize,(currentPage -1)*pageSize); + public List> findLayersByPage(Integer pageSize, Integer currentPage) { + List> result = new ArrayList<>(); + List queryList = layerDao.findLayersByPage(pageSize,(currentPage -1)*pageSize); + queryList.forEach(layer -> { + try { + result.add(BeanUtil.Bean2Map(layer, Layer.class)); + } catch (IllegalAccessException e) { + throw new BusinessException(e); + } + }); + return result; } @Override diff --git a/src/main/java/com/gis3c/ol/service/impl/MapServiceImpl.java b/src/main/java/com/gis3c/ol/service/impl/MapServiceImpl.java index ea428bc..61b661e 100644 --- a/src/main/java/com/gis3c/ol/service/impl/MapServiceImpl.java +++ b/src/main/java/com/gis3c/ol/service/impl/MapServiceImpl.java @@ -1,11 +1,15 @@ package com.gis3c.ol.service.impl; +import com.gis3c.common.bean.BeanUtil; +import com.gis3c.common.exception.BusinessException; import com.gis3c.ol.dao.MapDao; import com.gis3c.ol.entity.Map; import com.gis3c.ol.service.MapService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.UUID; @@ -23,8 +27,17 @@ public class MapServiceImpl implements MapService { } @Override - public List findMapsByPage(Integer pageSize,Integer currentPage) { - return mapDao.findMapsByPage(pageSize,(currentPage -1)*pageSize); + public List> findMapsByPage(Integer pageSize,Integer currentPage) { + List> result = new ArrayList<>(); + List queryList = mapDao.findMapsByPage(pageSize,(currentPage -1)*pageSize); + queryList.forEach(map -> { + try { + result.add(BeanUtil.Bean2Map(map, Map.class)); + } catch (IllegalAccessException e) { + throw new BusinessException(e); + } + }); + return result; } @Override diff --git a/src/main/java/com/gis3c/ol/service/impl/SourceServiceImpl.java b/src/main/java/com/gis3c/ol/service/impl/SourceServiceImpl.java index fbb2c6b..9cdaa24 100644 --- a/src/main/java/com/gis3c/ol/service/impl/SourceServiceImpl.java +++ b/src/main/java/com/gis3c/ol/service/impl/SourceServiceImpl.java @@ -1,11 +1,15 @@ package com.gis3c.ol.service.impl; +import com.gis3c.common.bean.BeanUtil; +import com.gis3c.common.exception.BusinessException; import com.gis3c.ol.dao.SourceDao; +import com.gis3c.ol.entity.Map; import com.gis3c.ol.entity.Source; import com.gis3c.ol.service.SourceService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.ArrayList; import java.util.List; import java.util.UUID; @@ -23,8 +27,17 @@ public class SourceServiceImpl implements SourceService { } @Override - public List findSourcesByPage(Integer pageSize, Integer currentPage) { - return sourceDao.findSourcesByPage(pageSize,(currentPage -1)*pageSize); + public List> findSourcesByPage(Integer pageSize, Integer currentPage) { + List> result = new ArrayList<>(); + List queryList = sourceDao.findSourcesByPage(pageSize,(currentPage -1)*pageSize); + queryList.forEach(source -> { + try { + result.add(BeanUtil.Bean2Map(source, Source.class)); + } catch (IllegalAccessException e) { + throw new BusinessException(e); + } + }); + return result; } @Override diff --git a/src/test/java/com/gis3c/spatial/App.java b/src/test/java/com/gis3c/spatial/App.java index 5028ff6..869b43d 100644 --- a/src/test/java/com/gis3c/spatial/App.java +++ b/src/test/java/com/gis3c/spatial/App.java @@ -1,6 +1,8 @@ package com.gis3c.spatial; +import com.gis3c.common.bean.BeanUtil; import com.gis3c.ol.entity.Layer; +import com.gis3c.ol.entity.Map; import com.gis3c.ol.entity.Source; import com.gis3c.ol.service.LayerService; import com.gis3c.ol.service.MapService; @@ -61,8 +63,10 @@ public class App { // System.out.println(FeatureUtilities.JavaBeans2Json(result)); // //地图接口 -// Map map = mapService.findMapById("fc813a1f-6a31-4202-9419-8d125ba203c9"); -// System.out.println(map.getLayers()[0][1]); +// Map map = mapService.findMapById("83c734de-c010-4153-bf68-d291d715ac55"); + System.out.println(mapService.findMapsByPage(5,1)); + + // Map map = new Map(); // map.setMapId(UUID.randomUUID().toString()); @@ -86,16 +90,16 @@ public class App { // System.out.println("插入成功"); //图层接口 - Layer layer = new Layer(); - layer.setLayerName("streetmap"); - layer.setAliasName("超图行政区图"); - layer.setSource("d7cb5f6f-ee31-4a6e-b8fd-72603a066c2b"); - layer.setType("ol.layer.Tile"); - java.util.Map options = new HashMap<>(); - options.put("projection","EPSG:4326"); - layer.setOptions(options); - layerService.insertLayer(layer); - System.out.println("插入成功"); +// Layer layer = new Layer(); +// layer.setLayerName("streetmap"); +// layer.setAliasName("超图行政区图"); +// layer.setSource("d7cb5f6f-ee31-4a6e-b8fd-72603a066c2b"); +// layer.setType("ol.layer.Tile"); +// java.util.Map options = new HashMap<>(); +// options.put("projection","EPSG:4326"); +// layer.setOptions(options); +// layerService.insertLayer(layer); +// System.out.println("插入成功"); //资源接口