|
@@ -13,6 +13,7 @@ import cn.com.taiji.tile.style.ShapeStyle;
|
|
|
import cn.com.taiji.tile.util.ShapeUtils;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.geotools.data.jdbc.datasource.DBCPDataSourceFactory;
|
|
|
import org.geotools.jdbc.JDBCDataStoreFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -45,99 +46,14 @@ public class TileServiceImpl implements ITileService {
|
|
|
public byte[] tileData(GeoRequestParam requestParam, List<LayerGroupDsView> layerGroupDsViewList, Map<String, List<LayerStyleView>> dataMaps) {
|
|
|
ConcurrentHashMap<String, BufferedImage> biMap = new ConcurrentHashMap<>();
|
|
|
layerGroupDsViewList.parallelStream().forEach(layerGroupDsView -> {
|
|
|
- long l = System.currentTimeMillis();
|
|
|
- //获取图层代码对应的样式
|
|
|
- List<LayerStyleView> layerStyleViewList = new ArrayList<LayerStyleView>();
|
|
|
- if (dataMaps.containsKey(layerGroupDsView.getLayerCode())) {
|
|
|
- layerStyleViewList = dataMaps.get(layerGroupDsView.getLayerCode());
|
|
|
- }
|
|
|
- String host = layerGroupDsView.getHost().split(",")[0].split(":")[0];
|
|
|
- String port = layerGroupDsView.getHost().split(",")[0].split(":")[1];
|
|
|
-
|
|
|
- Map<String, Object> cqlDsParams = new HashMap<String, Object>();
|
|
|
- cqlDsParams.put(DBCPDataSourceFactory.DSTYPE.key, "DBCP");
|
|
|
- cqlDsParams.put(DBCPDataSourceFactory.DRIVERCLASS.key, "com.mysql.cj.jdbc.Driver");
|
|
|
- cqlDsParams.put(DBCPDataSourceFactory.JDBC_URL.key, "jdbc:mysql://" + host + ":" + port + "/" + layerGroupDsView.getDataBase() + "?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&zeroDateTimeBehavior=convertToNull&serverTimezone=Asia/Shanghai");
|
|
|
- cqlDsParams.put(DBCPDataSourceFactory.USERNAME.key, layerGroupDsView.getUserName());
|
|
|
- cqlDsParams.put(DBCPDataSourceFactory.PASSWORD.key, layerGroupDsView.getUserPassword());
|
|
|
- cqlDsParams.put(DBCPDataSourceFactory.MAXACTIVE.key, Integer.valueOf(10));
|
|
|
- cqlDsParams.put(DBCPDataSourceFactory.MAXIDLE.key, Integer.valueOf(1));
|
|
|
- cqlDsParams.put(JDBCDataStoreFactory.HOST.key, host);
|
|
|
- cqlDsParams.put(JDBCDataStoreFactory.DATABASE.key, layerGroupDsView.getDataBase());
|
|
|
- cqlDsParams.put(JDBCDataStoreFactory.PORT.key, port);
|
|
|
- cqlDsParams.put("tableName", layerGroupDsView.getTableName());
|
|
|
-
|
|
|
-
|
|
|
- String layerDataType = layerGroupDsView.getLayerDataType();
|
|
|
- String layerDataRun = layerGroupDsView.getLayerDataRun();
|
|
|
-
|
|
|
- PageResult pageResult = null;
|
|
|
-
|
|
|
- StringBuffer filterCqlStr = new StringBuffer();
|
|
|
-
|
|
|
- if (layerDataType != null && !"".equals(layerDataType) && "cql".equals(layerDataType)) {
|
|
|
-
|
|
|
- //2根据cql规则获取图层对应的空间地理数据
|
|
|
-
|
|
|
- long currentTimeMillis = System.currentTimeMillis();
|
|
|
-
|
|
|
- String filterCql = requestParam.getCqlFilter();
|
|
|
-
|
|
|
- if (filterCql != null && !"".equals(filterCql)) {
|
|
|
-
|
|
|
- filterCqlStr.append(filterCql);
|
|
|
- }
|
|
|
-
|
|
|
- String bbox = requestParam.getBbox();
|
|
|
- if (bbox != null && !"".equals(bbox)) {
|
|
|
-
|
|
|
- StringBuffer sbBbox = new StringBuffer();
|
|
|
- sbBbox.append("(bbox (");
|
|
|
- sbBbox.append("location,");
|
|
|
- sbBbox.append(requestParam.getBbox() + "))");
|
|
|
-
|
|
|
- if (filterCqlStr.length() > 0) {
|
|
|
-
|
|
|
- filterCqlStr.append(" and " + sbBbox.toString());
|
|
|
- } else {
|
|
|
-
|
|
|
- filterCqlStr.append(sbBbox.toString());
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- if (layerDataRun != null && !"".equals(layerDataRun)) {
|
|
|
- if (filterCqlStr.length() > 0) {
|
|
|
- filterCqlStr.append(" and " + layerDataRun);
|
|
|
- } else {
|
|
|
- filterCqlStr.append(layerDataRun);
|
|
|
- }
|
|
|
- }
|
|
|
- System.out.println("查询条件:" + filterCqlStr.toString());
|
|
|
- Map<String, Object> mapParams = new HashMap<String, Object>();
|
|
|
- if (filterCqlStr.length() > 0) {
|
|
|
- mapParams.put("cql", filterCqlStr.toString());
|
|
|
- }
|
|
|
- pageResult = ecqlService.cqlQuery(cqlDsParams, mapParams);
|
|
|
- } else if (layerDataType != null && !"".equals(layerDataType) && "sql".equals(layerDataType)) {
|
|
|
- if (layerDataRun != null && !"".equals(layerDataRun)) {
|
|
|
- //安照sql语句的占位符?的顺序来设置sql语句的动态参数
|
|
|
- Object[] bindArgs = new Object[0];
|
|
|
- pageResult = sqlService.sqlQuery4Jdbc(cqlDsParams, layerDataRun, bindArgs);
|
|
|
- } else {
|
|
|
- log.info("执行图层数据类型:" + layerDataType + "和图层代码:" + requestParam.getLayers() + " 的执行内容为空或者为null");
|
|
|
- }
|
|
|
- }
|
|
|
- if (pageResult != null && pageResult.getRecordCount() > 0) {
|
|
|
- List<Map<String, Object>> cqlDataList = (List<Map<String, Object>>) pageResult.getDatas();
|
|
|
+ Result result = getResult(requestParam, dataMaps, layerGroupDsView);
|
|
|
+ if (result.pageResult != null && result.pageResult.getRecordCount() > 0) {
|
|
|
+ List<Map<String, Object>> cqlDataList = (List<Map<String, Object>>) result.pageResult.getDatas();
|
|
|
//3根据空间地理数据生成图层二进制数据
|
|
|
- long l1 = System.currentTimeMillis();
|
|
|
- System.out.println("查询耗时:" + (l1 - l));
|
|
|
- BufferedImage bufferedImage = ShapeUtils.drawImage(requestParam.getBbox(), cqlDataList, layerGroupDsView.getBoxColumn(), layerStyleViewList);
|
|
|
+ BufferedImage bufferedImage = ShapeUtils.drawImage(requestParam.getBbox(), cqlDataList, layerGroupDsView.getBoxColumn(), result.layerStyleViewList);
|
|
|
biMap.put(layerGroupDsView.getLayerCode(),bufferedImage);
|
|
|
- System.out.println("瓦片生成:" + (System.currentTimeMillis() - l1) + "数据大小:" + cqlDataList.size());
|
|
|
} else {
|
|
|
- log.info("根据查询过滤规则条件:" + filterCqlStr.toString() + "和图层代码:" + requestParam.getLayers() + " 没有找到图层对应的数据源的空间地理数据");
|
|
|
+// log.info("根据查询过滤规则条件:" + filterCqlStr.toString() + "和图层代码:" + requestParam.getLayers() + " 没有找到图层对应的数据源的空间地理数据");
|
|
|
}
|
|
|
});
|
|
|
BufferedImage image = new BufferedImage(requestParam.getWidth(), requestParam.getHeight(), BufferedImage.TYPE_INT_ARGB);
|
|
@@ -152,6 +68,81 @@ public class TileServiceImpl implements ITileService {
|
|
|
return buffer.toByteArray();
|
|
|
}
|
|
|
|
|
|
+ private Result getResult(GeoRequestParam requestParam, Map<String, List<LayerStyleView>> dataMaps, LayerGroupDsView layerGroupDsView) {
|
|
|
+ //获取图层代码对应的样式
|
|
|
+ List<LayerStyleView> layerStyleViewList = new ArrayList<>();
|
|
|
+ if (dataMaps.containsKey(layerGroupDsView.getLayerCode())) {
|
|
|
+ layerStyleViewList = dataMaps.get(layerGroupDsView.getLayerCode());
|
|
|
+ }
|
|
|
+ String host = layerGroupDsView.getHost().split(",")[0].split(":")[0];
|
|
|
+ String port = layerGroupDsView.getHost().split(",")[0].split(":")[1];
|
|
|
+
|
|
|
+ Map<String, Object> cqlDsParams = new HashMap<>();
|
|
|
+ cqlDsParams.put(DBCPDataSourceFactory.DSTYPE.key, "DBCP");
|
|
|
+ cqlDsParams.put(DBCPDataSourceFactory.DRIVERCLASS.key, "com.mysql.cj.jdbc.Driver");
|
|
|
+ cqlDsParams.put(DBCPDataSourceFactory.JDBC_URL.key, "jdbc:mysql://" + host + ":" + port + "/" + layerGroupDsView.getDataBase() + "?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&zeroDateTimeBehavior=convertToNull&serverTimezone=Asia/Shanghai");
|
|
|
+ cqlDsParams.put(DBCPDataSourceFactory.USERNAME.key, layerGroupDsView.getUserName());
|
|
|
+ cqlDsParams.put(DBCPDataSourceFactory.PASSWORD.key, layerGroupDsView.getUserPassword());
|
|
|
+ cqlDsParams.put(DBCPDataSourceFactory.MAXACTIVE.key, Integer.valueOf(10));
|
|
|
+ cqlDsParams.put(DBCPDataSourceFactory.MAXIDLE.key, Integer.valueOf(1));
|
|
|
+ cqlDsParams.put(JDBCDataStoreFactory.HOST.key, host);
|
|
|
+ cqlDsParams.put(JDBCDataStoreFactory.DATABASE.key, layerGroupDsView.getDataBase());
|
|
|
+ cqlDsParams.put(JDBCDataStoreFactory.PORT.key, port);
|
|
|
+ cqlDsParams.put("tableName", layerGroupDsView.getTableName());
|
|
|
+ String layerDataType = layerGroupDsView.getLayerDataType();
|
|
|
+ String layerDataRun = layerGroupDsView.getLayerDataRun();
|
|
|
+ PageResult pageResult = null;
|
|
|
+ StringBuilder filterCqlStr = new StringBuilder();
|
|
|
+ if (StringUtils.equals(layerDataType,"cql")) {
|
|
|
+ //2根据cql规则获取图层对应的空间地理数据
|
|
|
+ String filterCql = requestParam.getCqlFilter();
|
|
|
+ if (StringUtils.isNotBlank(filterCql)) {
|
|
|
+ filterCqlStr.append(filterCql);
|
|
|
+ }
|
|
|
+ String bbox = requestParam.getBbox();
|
|
|
+ if (StringUtils.isNotBlank(bbox)) {
|
|
|
+ StringBuilder sbBbox = new StringBuilder();
|
|
|
+ sbBbox.append("(bbox (");
|
|
|
+ sbBbox.append("location,");
|
|
|
+ sbBbox.append(requestParam.getBbox()).append("))");
|
|
|
+ if (filterCqlStr.length() > 0) {
|
|
|
+
|
|
|
+ filterCqlStr.append(" and " + sbBbox.toString());
|
|
|
+ } else {
|
|
|
+
|
|
|
+ filterCqlStr.append(sbBbox.toString());
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ if (layerDataRun != null && !"".equals(layerDataRun)) {
|
|
|
+ if (filterCqlStr.length() > 0) {
|
|
|
+ filterCqlStr.append(" and " + layerDataRun);
|
|
|
+ } else {
|
|
|
+ filterCqlStr.append(layerDataRun);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ System.out.println("查询条件:" + filterCqlStr.toString());
|
|
|
+ Map<String, Object> mapParams = new HashMap<String, Object>();
|
|
|
+ if (filterCqlStr.length() > 0) {
|
|
|
+ mapParams.put("cql", filterCqlStr.toString());
|
|
|
+ }
|
|
|
+ pageResult = ecqlService.cqlQuery(cqlDsParams, mapParams);
|
|
|
+ } else if (layerDataType != null && !"".equals(layerDataType) && "sql".equals(layerDataType)) {
|
|
|
+ if (layerDataRun != null && !"".equals(layerDataRun)) {
|
|
|
+ //安照sql语句的占位符?的顺序来设置sql语句的动态参数
|
|
|
+ Object[] bindArgs = new Object[0];
|
|
|
+ pageResult = sqlService.sqlQuery4Jdbc(cqlDsParams, layerDataRun, bindArgs);
|
|
|
+ } else {
|
|
|
+ log.info("执行图层数据类型:" + layerDataType + "和图层代码:" + requestParam.getLayers() + " 的执行内容为空或者为null");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Result result = new Result(layerStyleViewList, pageResult);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
public static List<POI> convert(List<Map<String, Object>> maps,String column) {
|
|
|
List<POI> pois = new ArrayList<>();
|
|
|
for (Map<String, Object> map : maps) {
|
|
@@ -163,109 +154,20 @@ public class TileServiceImpl implements ITileService {
|
|
|
return pois;
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public List<?> queryElements(String bbox, Integer type, String layerName) {
|
|
|
- return null;
|
|
|
- }
|
|
|
|
|
|
@Override
|
|
|
public FeatureInfo getFeatureInfo(GeoRequestParam requestParam, List<LayerGroupDsView> layerGroupDsViewList, Map<String, List<LayerStyleView>> dataMaps) {
|
|
|
FeatureInfo featureInfo = new FeatureInfo();
|
|
|
List<Map<String, Object>> features = new CopyOnWriteArrayList<>();
|
|
|
layerGroupDsViewList.parallelStream().forEach(layerGroupDsView -> {
|
|
|
- long l = System.currentTimeMillis();
|
|
|
- //获取图层代码对应的样式
|
|
|
- List<LayerStyleView> layerStyleViewList = new ArrayList<LayerStyleView>();
|
|
|
- if (dataMaps.containsKey(layerGroupDsView.getLayerCode())) {
|
|
|
- layerStyleViewList = dataMaps.get(layerGroupDsView.getLayerCode());
|
|
|
- }
|
|
|
- String host = layerGroupDsView.getHost().split(",")[0].split(":")[0];
|
|
|
- String port = layerGroupDsView.getHost().split(",")[0].split(":")[1];
|
|
|
-
|
|
|
- Map<String, Object> cqlDsParams = new HashMap<String, Object>();
|
|
|
- cqlDsParams.put(DBCPDataSourceFactory.DSTYPE.key, "DBCP");
|
|
|
- cqlDsParams.put(DBCPDataSourceFactory.DRIVERCLASS.key, "com.mysql.cj.jdbc.Driver");
|
|
|
- cqlDsParams.put(DBCPDataSourceFactory.JDBC_URL.key, "jdbc:mysql://" + host + ":" + port + "/" + layerGroupDsView.getDataBase() + "?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&zeroDateTimeBehavior=convertToNull&serverTimezone=Asia/Shanghai");
|
|
|
- cqlDsParams.put(DBCPDataSourceFactory.USERNAME.key, layerGroupDsView.getUserName());
|
|
|
- cqlDsParams.put(DBCPDataSourceFactory.PASSWORD.key, layerGroupDsView.getUserPassword());
|
|
|
- cqlDsParams.put(DBCPDataSourceFactory.MAXACTIVE.key, Integer.valueOf(10));
|
|
|
- cqlDsParams.put(DBCPDataSourceFactory.MAXIDLE.key, Integer.valueOf(1));
|
|
|
- cqlDsParams.put(JDBCDataStoreFactory.HOST.key, host);
|
|
|
- cqlDsParams.put(JDBCDataStoreFactory.DATABASE.key, layerGroupDsView.getDataBase());
|
|
|
- cqlDsParams.put(JDBCDataStoreFactory.PORT.key, port);
|
|
|
- cqlDsParams.put("tableName", layerGroupDsView.getTableName());
|
|
|
-
|
|
|
-
|
|
|
- String layerDataType = layerGroupDsView.getLayerDataType();
|
|
|
- String layerDataRun = layerGroupDsView.getLayerDataRun();
|
|
|
-
|
|
|
- PageResult pageResult = null;
|
|
|
-
|
|
|
- StringBuffer filterCqlStr = new StringBuffer();
|
|
|
-
|
|
|
- if (layerDataType != null && !"".equals(layerDataType) && "cql".equals(layerDataType)) {
|
|
|
-
|
|
|
- //2根据cql规则获取图层对应的空间地理数据
|
|
|
-
|
|
|
- long currentTimeMillis = System.currentTimeMillis();
|
|
|
-
|
|
|
- String filterCql = requestParam.getCqlFilter();
|
|
|
-
|
|
|
- if (filterCql != null && !"".equals(filterCql)) {
|
|
|
-
|
|
|
- filterCqlStr.append(filterCql);
|
|
|
- }
|
|
|
-
|
|
|
- String bbox = requestParam.getBbox();
|
|
|
- if (bbox != null && !"".equals(bbox)) {
|
|
|
-
|
|
|
- StringBuffer sbBbox = new StringBuffer();
|
|
|
- sbBbox.append("(bbox (");
|
|
|
- sbBbox.append("location,");
|
|
|
- sbBbox.append(requestParam.getBbox() + "))");
|
|
|
-
|
|
|
- if (filterCqlStr.length() > 0) {
|
|
|
-
|
|
|
- filterCqlStr.append(" and " + sbBbox.toString());
|
|
|
- } else {
|
|
|
-
|
|
|
- filterCqlStr.append(sbBbox.toString());
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- if (layerDataRun != null && !"".equals(layerDataRun)) {
|
|
|
- if (filterCqlStr.length() > 0) {
|
|
|
- filterCqlStr.append(" and " + layerDataRun);
|
|
|
- } else {
|
|
|
- filterCqlStr.append(layerDataRun);
|
|
|
- }
|
|
|
- }
|
|
|
- System.out.println("查询条件:" + filterCqlStr.toString());
|
|
|
- Map<String, Object> mapParams = new HashMap<String, Object>();
|
|
|
- if (filterCqlStr.length() > 0) {
|
|
|
- mapParams.put("cql", filterCqlStr.toString());
|
|
|
- }
|
|
|
- pageResult = ecqlService.cqlQuery(cqlDsParams, mapParams);
|
|
|
- } else if (layerDataType != null && !"".equals(layerDataType) && "sql".equals(layerDataType)) {
|
|
|
- if (layerDataRun != null && !"".equals(layerDataRun)) {
|
|
|
- //安照sql语句的占位符?的顺序来设置sql语句的动态参数
|
|
|
- Object[] bindArgs = new Object[0];
|
|
|
- pageResult = sqlService.sqlQuery4Jdbc(cqlDsParams, layerDataRun, bindArgs);
|
|
|
- } else {
|
|
|
- log.info("执行图层数据类型:" + layerDataType + "和图层代码:" + requestParam.getLayers() + " 的执行内容为空或者为null");
|
|
|
- }
|
|
|
- }
|
|
|
- if (pageResult != null && pageResult.getRecordCount() > 0) {
|
|
|
- List<Map<String, Object>> cqlDataList = (List<Map<String, Object>>) pageResult.getDatas();
|
|
|
+ Result result = getResult(requestParam, dataMaps, layerGroupDsView);
|
|
|
+ if (result.pageResult != null && result.pageResult.getRecordCount() > 0) {
|
|
|
+ List<Map<String, Object>> cqlDataList = (List<Map<String, Object>>) result.pageResult.getDatas();
|
|
|
//3根据空间地理数据生成图层二进制数据
|
|
|
- long l1 = System.currentTimeMillis();
|
|
|
- System.out.println("查询耗时:" + (l1 - l));
|
|
|
- List<Map<String, Object>> maps = ShapeUtils.detectClick(requestParam.getBbox(), cqlDataList, layerGroupDsView.getBoxColumn(), layerStyleViewList, requestParam.getX(), requestParam.getY());
|
|
|
+ List<Map<String, Object>> maps = ShapeUtils.detectClick(requestParam.getBbox(), cqlDataList, layerGroupDsView.getBoxColumn(), result.layerStyleViewList, requestParam.getX(), requestParam.getY());
|
|
|
features.addAll(maps);
|
|
|
- System.out.println("瓦片生成:" + (System.currentTimeMillis() - l1) + "数据大小:" + cqlDataList.size());
|
|
|
} else {
|
|
|
- log.info("根据查询过滤规则条件:" + filterCqlStr.toString() + "和图层代码:" + requestParam.getLayers() + " 没有找到图层对应的数据源的空间地理数据");
|
|
|
+// log.info("根据查询过滤规则条件:" + filterCqlStr.toString() + "和图层代码:" + requestParam.getLayers() + " 没有找到图层对应的数据源的空间地理数据");
|
|
|
}
|
|
|
});
|
|
|
featureInfo.setFeatures(features);
|
|
@@ -274,6 +176,12 @@ public class TileServiceImpl implements ITileService {
|
|
|
return featureInfo;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<?> queryElements(String bbox, Integer type, String layerName) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
public static double[] parseBbox(String bboxString) {
|
|
|
String[] bboxValuesStr = bboxString.split(",");
|
|
|
if (bboxValuesStr.length != 4) {
|
|
@@ -292,4 +200,13 @@ public class TileServiceImpl implements ITileService {
|
|
|
return bboxValues;
|
|
|
}
|
|
|
|
|
|
+ private static class Result {
|
|
|
+ public final List<LayerStyleView> layerStyleViewList;
|
|
|
+ public final PageResult pageResult;
|
|
|
+
|
|
|
+ public Result(List<LayerStyleView> layerStyleViewList, PageResult pageResult) {
|
|
|
+ this.layerStyleViewList = layerStyleViewList;
|
|
|
+ this.pageResult = pageResult;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|