Browse Source

重构cql代码

liwh 1 year ago
parent
commit
bc77fb0f99
24 changed files with 601 additions and 269 deletions
  1. 17 77
      cql-service/pom.xml
  2. 0 13
      cql-service/src/main/java/cn/com/taiji/cql/CqlServiceApplication.java
  3. 1 1
      cql-service/src/main/java/cn/com/taiji/cql/service/IECqlService.java
  4. 0 15
      cql-service/src/main/java/cn/com/taiji/cql/service/IGeoDataSourceService.java
  5. 0 9
      cql-service/src/main/java/cn/com/taiji/cql/service/ITileService.java
  6. 46 2
      cql-service/src/main/java/cn/com/taiji/cql/service/impl/ECqlServiceImpl.java
  7. 0 37
      cql-service/src/main/java/cn/com/taiji/cql/service/impl/GeoDataSourceServiceImpl.java
  8. 0 94
      cql-service/src/main/java/cn/com/taiji/cql/service/impl/TileServiceImpl.java
  9. 107 0
      cql-service/src/main/java/cn/com/taiji/cql/test/EcqlData.java
  10. 1 2
      cql-service/src/main/java/cn/com/taiji/cql/test/EcqlTest.java
  11. 7 1
      pom.xml
  12. 7 8
      tile-service/pom.xml
  13. 11 0
      tile-service/src/main/java/cn/com/taiji/tile/service/ITileService.java
  14. 69 0
      tile-service/src/main/java/cn/com/taiji/tile/service/impl/TileServiceImpl.java
  15. 61 3
      tile-service/src/main/java/cn/com/taiji/tile/util/TileUtils.java
  16. 120 0
      tile-web/pom.xml
  17. 13 0
      tile-web/src/main/java/cn/com/taiji/web/TileWebApplication.java
  18. 1 1
      cql-service/src/main/java/cn/com/taiji/cql/config/GeoConfig.java
  19. 44 6
      cql-service/src/main/java/cn/com/taiji/cql/controller/TileEcqlController.java
  20. 16 0
      tile-web/src/main/java/cn/com/taiji/web/service/IGeoDataSourceService.java
  21. 80 0
      tile-web/src/main/java/cn/com/taiji/web/service/impl/GeoDataSourceServiceImpl.java
  22. 0 0
      tile-web/src/main/resources/application-test.properties
  23. 0 0
      tile-web/src/main/resources/application.yml
  24. 0 0
      tile-web/src/main/resources/logback.xml

+ 17 - 77
cql-service/pom.xml

@@ -10,35 +10,31 @@
     <modelVersion>4.0.0</modelVersion>
 
     <artifactId>cql-service</artifactId>
+    <packaging>jar</packaging>
 
     <dependencies>
 
         <dependency>
-            <groupId>cn.com.taiji</groupId>
-            <artifactId>tile-service</artifactId>
-            <version>1.0</version>
-        </dependency>
-
-
-
-        <dependency>
             <groupId>cn.hutool</groupId>
             <artifactId>hutool-all</artifactId>
             <version>5.7.19</version>
         </dependency>
+
         <dependency>
-            <groupId>org.springframework.boot</groupId>
-            <artifactId>spring-boot-starter-actuator</artifactId>
+            <groupId>com.alibaba</groupId>
+            <artifactId>fastjson</artifactId>
+            <version>1.2.60</version>
         </dependency>
+
         <dependency>
-            <groupId>org.springframework.boot</groupId>
-            <artifactId>spring-boot-starter-web</artifactId>
+            <groupId>org.projectlombok</groupId>
+            <artifactId>lombok</artifactId>
         </dependency>
 
-
         <dependency>
             <groupId>org.geotools</groupId>
             <artifactId>gt-main</artifactId>
+            <version>${geotools.version}</version>
         </dependency>
 
         <dependency>
@@ -94,72 +90,16 @@
             <version>${geotools.version}</version>
         </dependency>
 
-
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-actuator</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-web</artifactId>
+        </dependency>
 
     </dependencies>
 
-    <build>
-        <finalName>${project.artifactId}</finalName>
-        <plugins>
-            <plugin>
-                <groupId>org.springframework.boot</groupId>
-                <artifactId>spring-boot-maven-plugin</artifactId>
-                <!--将scope 为 system的本地jar包也加入到打包jar中-->
-                <configuration>
-                    <includeSystemScope>true</includeSystemScope>
-                </configuration>
-                <executions>
-                    <execution>
-                        <goals>
-                            <goal>repackage</goal>
-                        </goals>
-                    </execution>
-                </executions>
-            </plugin>
-        </plugins>
-    </build>
-
-    <repositories>
-        <repository>
-            <id>locationtech-releases</id>
-            <url>https://repo.eclipse.org/content/groups/releases</url>
-            <snapshots>
-                <enabled>false</enabled>
-            </snapshots>
-        </repository>
-        <repository>
-            <id>locationtech-snapshots</id>
-            <url>https://repo.eclipse.org/content/groups/snapshots</url>
-            <releases>
-                <enabled>false</enabled>
-            </releases>
-            <snapshots>
-                <enabled>true</enabled>
-            </snapshots>
-        </repository>
-        <!-- geotools -->
-        <repository>
-            <id>osgeo</id>
-            <url>https://repo.osgeo.org/repository/release</url>
-            <snapshots>
-                <enabled>false</enabled>
-            </snapshots>
-        </repository>
-        <repository>
-            <id>osgeo-snapshots</id>
-            <url>https://repo.osgeo.org/repository/snapshot</url>
-            <releases>
-                <enabled>false</enabled>
-            </releases>
-            <snapshots>
-                <enabled>true</enabled>
-            </snapshots>
-        </repository>
-        <repository>
-            <id>conjars.org</id>
-            <url>http://conjars.org/repo</url>
-        </repository>
-    </repositories>
-
 
 </project>

+ 0 - 13
cql-service/src/main/java/cn/com/taiji/cql/CqlServiceApplication.java

@@ -1,13 +0,0 @@
-package cn.com.taiji.cql;
-
-import org.springframework.boot.SpringApplication;
-import org.springframework.boot.autoconfigure.SpringBootApplication;
-
-@SpringBootApplication
-public class CqlServiceApplication {
-
-    public static void main(String[] args) {
-
-        SpringApplication.run(CqlServiceApplication.class, args);
-    }
-}

+ 1 - 1
cql-service/src/main/java/cn/com/taiji/cql/service/IECqlService.java

@@ -7,5 +7,5 @@ import java.util.Map;
 public interface IECqlService {
 
 
-    List<Map<String,Object>> cqlQuery(Map<String, Object> mapParams,String cql);
+    List<Map<String,Object>> cqlQuery(Map<String, Object> mapParams,String cql,Map<String,Object> sortMaps);
 }

+ 0 - 15
cql-service/src/main/java/cn/com/taiji/cql/service/IGeoDataSourceService.java

@@ -1,15 +0,0 @@
-package cn.com.taiji.cql.service;
-
-import cn.com.taiji.cql.model.GeoDataSource;
-import org.geotools.api.data.DataStore;
-
-import javax.sql.DataSource;
-
-public interface IGeoDataSourceService {
-
-    /**
-     * 基于geotools创建mysql数据源
-     * @return
-     */
-    DataSource createGeoDataSource() throws Exception;
-}

+ 0 - 9
cql-service/src/main/java/cn/com/taiji/cql/service/ITileService.java

@@ -1,9 +0,0 @@
-package cn.com.taiji.cql.service;
-
-import cn.com.taiji.cql.model.GeoRequestParam;
-
-public interface ITileService {
-
-
-    byte[] tileData(GeoRequestParam requestParam);
-}

+ 46 - 2
cql-service/src/main/java/cn/com/taiji/cql/service/impl/ECqlServiceImpl.java

@@ -3,13 +3,19 @@ import cn.com.taiji.cql.service.IECqlService;
 import lombok.extern.slf4j.Slf4j;
 import org.geotools.api.data.DataStore;
 import org.geotools.api.data.DataStoreFinder;
+import org.geotools.api.data.Query;
 import org.geotools.api.data.SimpleFeatureSource;
 import org.geotools.api.feature.simple.SimpleFeature;
 import org.geotools.api.feature.simple.SimpleFeatureType;
 import org.geotools.api.feature.type.AttributeDescriptor;
 import org.geotools.api.filter.Filter;
+import org.geotools.api.filter.FilterFactory;
+import org.geotools.api.filter.sort.SortBy;
+import org.geotools.api.filter.sort.SortOrder;
 import org.geotools.data.simple.SimpleFeatureCollection;
 import org.geotools.data.simple.SimpleFeatureIterator;
+import org.geotools.filter.FilterFactoryImpl;
+import org.geotools.filter.SortByImpl;
 import org.geotools.filter.text.ecql.ECQL;
 import org.geotools.jdbc.JDBCDataStoreFactory;
 import org.springframework.stereotype.Service;
@@ -30,7 +36,7 @@ public class ECqlServiceImpl implements IECqlService{
      * @return
      */
     @Override
-    public List<Map<String, Object>> cqlQuery(Map<String, Object> mapParams, String cql) {
+    public List<Map<String, Object>> cqlQuery(Map<String, Object> mapParams, String cql,Map<String,Object> sortMaps) {
 
         List<Map<String, Object>> dataList = new ArrayList<Map<String, Object>>();
 
@@ -52,9 +58,47 @@ public class ECqlServiceImpl implements IECqlService{
                 //根据表名获取source
                 SimpleFeatureSource fSource=dataStore.getFeatureSource(mapParams.get("tableName").toString());
 
+
+                FilterFactoryImpl filterFactory = new FilterFactoryImpl();
+
                 Filter filter = ECQL.toFilter(cql);
 
-                SimpleFeatureCollection fCollection =fSource.getFeatures(filter);
+                Query query = new Query();
+                query.setFilter(filter);
+
+
+
+                if(sortMaps.keySet().size() >0){
+
+                    List<SortByImpl> sortByList = new ArrayList<SortByImpl>();
+
+                    for (String sortKey : sortMaps.keySet()) {
+
+                        String sortValue = sortMaps.get(sortKey).toString();
+
+                        if("asc".equals(sortValue.toLowerCase())){
+
+                            SortByImpl sb = new SortByImpl(filterFactory.property(sortKey),SortOrder.ASCENDING);
+
+                            sortByList.add(sb);
+                        }else{
+
+                            SortByImpl sb = new SortByImpl(filterFactory.property(sortKey),SortOrder.DESCENDING);
+
+                            sortByList.add(sb);
+
+                        }
+
+
+                    }
+
+                    query.setSortBy(sortByList.toArray(new SortBy[sortByList.size()]));
+
+                }
+
+
+
+                SimpleFeatureCollection fCollection =fSource.getFeatures(query);
 
                 if(fCollection !=null){
 

+ 0 - 37
cql-service/src/main/java/cn/com/taiji/cql/service/impl/GeoDataSourceServiceImpl.java

@@ -1,37 +0,0 @@
-package cn.com.taiji.cql.service.impl;
-
-import cn.com.taiji.cql.config.GeoConfig;
-import cn.com.taiji.cql.service.IGeoDataSourceService;
-import lombok.extern.slf4j.Slf4j;
-import org.geotools.data.jdbc.datasource.DBCPDataSourceFactory;
-import org.geotools.data.jdbc.datasource.DataSourceFinder;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-import javax.sql.DataSource;
-import java.util.HashMap;
-import java.util.Map;
-
-@Slf4j
-@Service
-public class GeoDataSourceServiceImpl implements IGeoDataSourceService {
-
-    @Autowired
-    private GeoConfig geoConfig;
-
-    @Override
-    public DataSource createGeoDataSource() throws Exception{
-
-
-        //构建mysql数据库连接数据源--DataSource
-        Map<String, Object> mapParams = new HashMap<String, Object>();
-        mapParams.put(DBCPDataSourceFactory.DSTYPE.key, "DBCP");
-        mapParams.put(DBCPDataSourceFactory.DRIVERCLASS.key, "com.mysql.cj.jdbc.Driver");
-        mapParams.put(DBCPDataSourceFactory.JDBC_URL.key, "jdbc:mysql://"+geoConfig.getDsIp()+":"+geoConfig.getDsPort()+"/"+geoConfig.getDsBase()+"?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&zeroDateTimeBehavior=convertToNull&serverTimezone=Asia/Shanghai");
-        mapParams.put(DBCPDataSourceFactory.USERNAME.key, geoConfig.getDsUsername());
-        mapParams.put(DBCPDataSourceFactory.PASSWORD.key, geoConfig.getDsPassword());
-        mapParams.put(DBCPDataSourceFactory.MAXACTIVE.key, Integer.valueOf(10));
-        mapParams.put(DBCPDataSourceFactory.MAXIDLE.key, Integer.valueOf(0));
-
-        return DataSourceFinder.getDataSource(mapParams);
-    }
-}

+ 0 - 94
cql-service/src/main/java/cn/com/taiji/cql/service/impl/TileServiceImpl.java

@@ -1,94 +0,0 @@
-package cn.com.taiji.cql.service.impl;
-import cn.com.taiji.cql.config.GeoConfig;
-import cn.com.taiji.cql.model.GeoDataSource;
-import cn.com.taiji.cql.model.GeoRequestParam;
-import cn.com.taiji.cql.service.IECqlService;
-import cn.com.taiji.cql.service.ITileService;
-import cn.com.taiji.tile.util.TileUtils;
-import com.alibaba.fastjson.JSONObject;
-import lombok.extern.slf4j.Slf4j;
-import org.geotools.jdbc.JDBCDataStoreFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-@Slf4j
-@Service
-public class TileServiceImpl implements ITileService {
-
-    @Autowired
-    private IECqlService ecqlService;
-
-    @Autowired
-    private GeoConfig geoConfig;
-
-
-    @Override
-    public byte[] tileData(GeoRequestParam requestParam) {
-
-        //1先根据图层代码获取对应的数据源
-        Map<String, Object> mapParams = new HashMap<String, Object>();
-        mapParams.put(JDBCDataStoreFactory.DATABASE.key, geoConfig.getDsBase());
-        mapParams.put(JDBCDataStoreFactory.DBTYPE.key, geoConfig.getDbType());
-
-        mapParams.put(JDBCDataStoreFactory.HOST.key, geoConfig.getDsIp());
-        mapParams.put(JDBCDataStoreFactory.PORT.key, geoConfig.getDsPort());
-        mapParams.put(JDBCDataStoreFactory.USER.key, geoConfig.getDsUsername());
-        mapParams.put(JDBCDataStoreFactory.PASSWD.key, geoConfig.getDsPassword());
-        mapParams.put("tableName", "geo_data_source");
-
-        String layerCodeCql = "layer_code='"+requestParam.getLayers()+"'";
-        List<Map<String, Object>> dataSourceList = ecqlService.cqlQuery(mapParams,layerCodeCql);
-
-        if(dataSourceList.size() >0){
-
-
-            //2根据cql规则获取图层对应的空间地理数据
-
-            GeoDataSource gds = JSONObject.parseObject(JSONObject.toJSONString(dataSourceList.get(0)), GeoDataSource.class);
-
-
-            StringBuffer sbBbox = new StringBuffer();
-            sbBbox.append("(bbox (");
-            sbBbox.append(gds.getBboxColumn()+",");
-            sbBbox.append(requestParam.getBbox()+"))");
-
-
-            String filterCql = requestParam.getCqlFilter()+" and "+sbBbox.toString();
-
-            Map<String, Object> cqlDsParams = new HashMap<String, Object>();
-            cqlDsParams.put(JDBCDataStoreFactory.DATABASE.key, gds.getDataBase());
-            cqlDsParams.put(JDBCDataStoreFactory.DBTYPE.key, gds.getDbType());
-
-            cqlDsParams.put(JDBCDataStoreFactory.HOST.key, gds.getHost());
-            cqlDsParams.put(JDBCDataStoreFactory.PORT.key, gds.getPort());
-            cqlDsParams.put(JDBCDataStoreFactory.USER.key, gds.getUserName());
-            cqlDsParams.put(JDBCDataStoreFactory.PASSWD.key, gds.getUserPassword());
-            cqlDsParams.put("tableName", gds.getTableName());
-
-            List<Map<String, Object>> cqlDataList = ecqlService.cqlQuery(cqlDsParams,filterCql);
-
-            if(cqlDataList.size() >0){
-                //3根据空间地理数据生成图层二进制数据
-                System.out.println("返回的数据:"+cqlDataList.toString());
-                return TileUtils.getTile(cqlDataList, requestParam.getBbox());
-
-            }else{
-
-                log.info("根据cql规则:"+sbBbox.toString()+"和图层代码:" + requestParam.getLayers() + " 没有找到图层对应的数据源的空间地理数据");
-            }
-
-
-        }else{
-
-            log.info("根据图层代码:" + requestParam.getLayers() + "获取图层对应的数据源为空或者为null");
-        }
-
-        return new byte[0];
-    }
-
-
-}

File diff suppressed because it is too large
+ 107 - 0
cql-service/src/main/java/cn/com/taiji/cql/test/EcqlData.java


File diff suppressed because it is too large
+ 1 - 2
cql-service/src/main/java/cn/com/taiji/cql/test/EcqlTest.java


+ 7 - 1
pom.xml

@@ -7,16 +7,21 @@
     <groupId>cn.com.taiji</groupId>
     <artifactId>ecql-service</artifactId>
     <version>1.0</version>
+    <packaging>pom</packaging>
+
     <modules>
         <module>cql-service</module>
         <module>tile-service</module>
+        <module>tile-web</module>
     </modules>
-    <packaging>pom</packaging>
 
     <properties>
         <spring-boot-dependencies.version>2.5.5</spring-boot-dependencies.version>
         <geotools.version>30.0</geotools.version>
         <lombok.version>1.18.28</lombok.version>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+        <maven.compiler.source>11</maven.compiler.source>
+        <maven.compiler.target>11</maven.compiler.target>
     </properties>
 
     <dependencyManagement>
@@ -54,6 +59,7 @@
                 <plugin>
                     <groupId>org.springframework.boot</groupId>
                     <artifactId>spring-boot-maven-plugin</artifactId>
+                    <version>${spring-boot-dependencies.version}</version>
                 </plugin>
             </plugins>
         </pluginManagement>

+ 7 - 8
tile-service/pom.xml

@@ -10,12 +10,7 @@
     </parent>
 
     <artifactId>tile-service</artifactId>
-
-    <properties>
-        <maven.compiler.source>8</maven.compiler.source>
-        <maven.compiler.target>8</maven.compiler.target>
-        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
-    </properties>
+    <packaging>jar</packaging>
 
     <dependencies>
         <dependency>
@@ -82,10 +77,14 @@
             <version>1.7.30</version>
         </dependency>
 
-
-    </dependencies>
+        <dependency>
+            <groupId>cn.com.taiji</groupId>
+            <artifactId>cql-service</artifactId>
+            <version>1.0</version>
+        </dependency>
 
 
+    </dependencies>
 
 
 </project>

+ 11 - 0
tile-service/src/main/java/cn/com/taiji/tile/service/ITileService.java

@@ -0,0 +1,11 @@
+package cn.com.taiji.tile.service;
+
+
+import cn.com.taiji.cql.model.GeoDataSource;
+import cn.com.taiji.cql.model.GeoRequestParam;
+
+public interface ITileService {
+
+
+    byte[] tileData(GeoRequestParam requestParam, GeoDataSource geoDs);
+}

+ 69 - 0
tile-service/src/main/java/cn/com/taiji/tile/service/impl/TileServiceImpl.java

@@ -0,0 +1,69 @@
+package cn.com.taiji.tile.service.impl;
+import cn.com.taiji.cql.model.GeoDataSource;
+import cn.com.taiji.cql.model.GeoRequestParam;
+import cn.com.taiji.cql.service.IECqlService;
+import cn.com.taiji.tile.service.ITileService;
+import cn.com.taiji.tile.util.TileUtils;
+import com.alibaba.fastjson.JSONObject;
+import lombok.extern.slf4j.Slf4j;
+import org.geotools.jdbc.JDBCDataStoreFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@Slf4j
+@Service
+public class TileServiceImpl implements ITileService {
+
+    @Autowired
+    private IECqlService ecqlService;
+
+
+    @Override
+    public byte[] tileData(GeoRequestParam requestParam,GeoDataSource geoDs) {
+
+        //2根据cql规则获取图层对应的空间地理数据
+
+
+        StringBuffer sbBbox = new StringBuffer();
+        sbBbox.append("(bbox (");
+        sbBbox.append(geoDs.getBboxColumn()+",");
+        sbBbox.append(requestParam.getBbox()+"))");
+
+
+//        String filterCql = requestParam.getCqlFilter()+" and "+sbBbox.toString();
+        String filterCql = requestParam.getCqlFilter();
+
+        Map<String, Object> cqlDsParams = new HashMap<String, Object>();
+        cqlDsParams.put(JDBCDataStoreFactory.DATABASE.key, geoDs.getDataBase());
+        cqlDsParams.put(JDBCDataStoreFactory.DBTYPE.key, geoDs.getDbType());
+
+        cqlDsParams.put(JDBCDataStoreFactory.HOST.key, geoDs.getHost());
+        cqlDsParams.put(JDBCDataStoreFactory.PORT.key, geoDs.getPort());
+        cqlDsParams.put(JDBCDataStoreFactory.USER.key, geoDs.getUserName());
+        cqlDsParams.put(JDBCDataStoreFactory.PASSWD.key, geoDs.getUserPassword());
+        cqlDsParams.put("tableName", geoDs.getTableName());
+
+        Map<String, Object> sortParams = new HashMap<String, Object>();
+        sortParams.put("sort","asc");
+
+        List<Map<String, Object>> cqlDataList = ecqlService.cqlQuery(cqlDsParams,filterCql,sortParams);
+
+        if(cqlDataList.size() >0){
+            //3根据空间地理数据生成图层二进制数据
+            System.out.println("返回的数据:"+cqlDataList.toString());
+            return TileUtils.getTile2lwh(cqlDataList, requestParam.getBbox(),geoDs);
+
+        }else{
+
+            log.info("根据cql规则:"+sbBbox.toString()+"和图层代码:" + requestParam.getLayers() + " 没有找到图层对应的数据源的空间地理数据");
+        }
+
+        return new byte[0];
+    }
+
+
+}

File diff suppressed because it is too large
+ 61 - 3
tile-service/src/main/java/cn/com/taiji/tile/util/TileUtils.java


+ 120 - 0
tile-web/pom.xml

@@ -0,0 +1,120 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <artifactId>ecql-service</artifactId>
+        <groupId>cn.com.taiji</groupId>
+        <version>1.0</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>tile-web</artifactId>
+
+    <dependencies>
+
+        <dependency>
+            <groupId>cn.com.taiji</groupId>
+            <artifactId>tile-service</artifactId>
+            <version>1.0</version>
+        </dependency>
+
+        <dependency>
+            <groupId>cn.com.taiji</groupId>
+            <artifactId>cql-service</artifactId>
+            <version>1.0</version>
+        </dependency>
+
+        <dependency>
+            <groupId>cn.hutool</groupId>
+            <artifactId>hutool-all</artifactId>
+            <version>5.7.19</version>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-actuator</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-web</artifactId>
+        </dependency>
+
+
+        <dependency>
+            <groupId>org.geotools</groupId>
+            <artifactId>gt-main</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.geotools</groupId>
+            <artifactId>gt-cql</artifactId>
+            <version>${geotools.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.geotools</groupId>
+            <artifactId>gt-elasticsearch</artifactId>
+            <version>${geotools.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.geotools</groupId>
+            <artifactId>gt-xml</artifactId>
+            <version>${geotools.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.geotools</groupId>
+            <artifactId>gt-coverage</artifactId>
+            <version>${geotools.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.geotools</groupId>
+            <artifactId>gt-process</artifactId>
+            <version>${geotools.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.geotools</groupId>
+            <artifactId>gt-process-feature</artifactId>
+            <version>${geotools.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.geotools</groupId>
+            <artifactId>gt-jdbc</artifactId>
+            <version>${geotools.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.geotools.jdbc</groupId>
+            <artifactId>gt-jdbc-mysql</artifactId>
+            <version>${geotools.version}</version>
+        </dependency>
+
+
+
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-maven-plugin</artifactId>
+                <!--将scope 为 system的本地jar包也加入到打包jar中-->
+                <configuration>
+                    <includeSystemScope>true</includeSystemScope>
+                </configuration>
+                <executions>
+                    <execution>
+                        <goals>
+                            <goal>repackage</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+
+
+</project>

+ 13 - 0
tile-web/src/main/java/cn/com/taiji/web/TileWebApplication.java

@@ -0,0 +1,13 @@
+package cn.com.taiji.web;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication(scanBasePackages = {"cn.com.taiji"})
+public class TileWebApplication {
+
+    public static void main(String[] args) {
+
+        SpringApplication.run(TileWebApplication.class, args);
+    }
+}

+ 1 - 1
cql-service/src/main/java/cn/com/taiji/cql/config/GeoConfig.java

@@ -1,4 +1,4 @@
-package cn.com.taiji.cql.config;
+package cn.com.taiji.web.config;
 
 import lombok.Data;
 import org.springframework.beans.factory.annotation.Value;

+ 44 - 6
cql-service/src/main/java/cn/com/taiji/cql/controller/TileEcqlController.java

@@ -1,12 +1,17 @@
-package cn.com.taiji.cql.controller;
+package cn.com.taiji.web.controller;
 
 
+
+import cn.com.taiji.cql.model.GeoDataSource;
 import cn.com.taiji.cql.model.GeoRequestParam;
-import cn.com.taiji.cql.service.ITileService;
+import cn.com.taiji.tile.service.ITileService;
+import cn.com.taiji.web.service.IGeoDataSourceService;
 import com.alibaba.fastjson.JSONObject;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.*;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RestController;
 
 import javax.servlet.ServletOutputStream;
 import javax.servlet.http.HttpServletRequest;
@@ -23,11 +28,14 @@ import java.util.Map;
  */
 @Slf4j
 @RestController
-public class TileEcqlController {
+public class TileWebController {
 
     @Autowired
     private ITileService tileService;
 
+    @Autowired
+    private IGeoDataSourceService geoDataSourceService;
+
 
     @RequestMapping(value = {"/queryTile"}, method = {RequestMethod.GET, RequestMethod.POST})
     public void queryTile(HttpServletRequest request, HttpServletResponse response) {
@@ -35,9 +43,39 @@ public class TileEcqlController {
 
         GeoRequestParam geoRequestParam = JSONObject.parseObject(JSONObject.toJSONString(getParameterMap(request)), GeoRequestParam.class);
 
-        byte[] ret = tileService.tileData(geoRequestParam);
+        if(geoRequestParam.getLayers() !=null && !"".equals(geoRequestParam.getLayers())){
+
+            try{
+
+                GeoDataSource geoDs = geoDataSourceService.layerCodeGeoDataSource(geoRequestParam.getLayers());
+
+                if(geoDs !=null){
+
+                    byte[] ret = tileService.tileData(geoRequestParam,geoDs);
+
+                    responseWrite(response, "image/png", ret);
+
+
+                }else{
+
+                    log.info("根据图层代码:" + geoRequestParam.getLayers() + "获取图层对应的数据源为空或者为null");
+                }
+
+            }catch (Exception exception){
+
+                exception.printStackTrace();
+
+                log.error("根据图层代码:" + geoRequestParam.getLayers() +"获取数据源信息失败!"+exception);
+            }
+
+
+
+        }else{
+
+            log.info("图层代码layers参数为空!");
+        }
+
 
-        responseWrite(response, "image/png", ret);
     }
 
     private void responseWrite(HttpServletResponse response, String contentType, byte[] data) {

+ 16 - 0
tile-web/src/main/java/cn/com/taiji/web/service/IGeoDataSourceService.java

@@ -0,0 +1,16 @@
+package cn.com.taiji.web.service;
+
+import cn.com.taiji.cql.model.GeoDataSource;
+
+import javax.sql.DataSource;
+
+public interface IGeoDataSourceService {
+
+    /**
+     * 获取图层代码对应的数据源信息
+     * @return
+     */
+    GeoDataSource layerCodeGeoDataSource(String layerCode) throws Exception;
+
+    DataSource defaultDataSource() throws Exception;
+}

+ 80 - 0
tile-web/src/main/java/cn/com/taiji/web/service/impl/GeoDataSourceServiceImpl.java

@@ -0,0 +1,80 @@
+package cn.com.taiji.web.service.impl;
+
+import cn.com.taiji.cql.model.GeoDataSource;
+import cn.com.taiji.cql.service.IECqlService;
+import cn.com.taiji.web.config.GeoConfig;
+import cn.com.taiji.web.service.IGeoDataSourceService;
+import com.alibaba.fastjson.JSONObject;
+import lombok.extern.slf4j.Slf4j;
+import org.geotools.data.jdbc.datasource.DBCPDataSourceFactory;
+import org.geotools.data.jdbc.datasource.DataSourceFinder;
+import org.geotools.jdbc.JDBCDataStoreFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import javax.sql.DataSource;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@Slf4j
+@Service
+public class GeoDataSourceServiceImpl implements IGeoDataSourceService {
+
+    @Autowired
+    private GeoConfig geoConfig;
+
+    @Autowired
+    private IECqlService ecqlService;
+
+    @Override
+    public GeoDataSource layerCodeGeoDataSource(String layerCode) throws Exception{
+
+
+        //1先根据图层代码获取对应的数据源
+        Map<String, Object> mapParams = new HashMap<String, Object>();
+        mapParams.put(JDBCDataStoreFactory.DATABASE.key, geoConfig.getDsBase());
+        mapParams.put(JDBCDataStoreFactory.DBTYPE.key, geoConfig.getDbType());
+
+        mapParams.put(JDBCDataStoreFactory.HOST.key, geoConfig.getDsIp());
+        mapParams.put(JDBCDataStoreFactory.PORT.key, geoConfig.getDsPort());
+        mapParams.put(JDBCDataStoreFactory.USER.key, geoConfig.getDsUsername());
+        mapParams.put(JDBCDataStoreFactory.PASSWD.key, geoConfig.getDsPassword());
+        mapParams.put("tableName", "geo_data_source");
+
+        String layerCodeCql = "layer_code='"+layerCode+"'";
+
+        Map<String, Object> sortParams = new HashMap<String, Object>();
+
+        List<Map<String, Object>> dataSourceList = ecqlService.cqlQuery(mapParams,layerCodeCql,sortParams);
+
+        if(dataSourceList.size() >0){
+
+            GeoDataSource gds = JSONObject.parseObject(JSONObject.toJSONString(dataSourceList.get(0)), GeoDataSource.class);
+
+            return gds;
+
+        }
+
+        return null;
+
+
+
+    }
+
+    public DataSource defaultDataSource() throws Exception{
+
+        //构建mysql数据库连接数据源--DataSource
+        Map<String, Object> mapParams = new HashMap<String, Object>();
+        mapParams.put(DBCPDataSourceFactory.DSTYPE.key, "DBCP");
+        mapParams.put(DBCPDataSourceFactory.DRIVERCLASS.key, "com.mysql.cj.jdbc.Driver");
+        mapParams.put(DBCPDataSourceFactory.JDBC_URL.key, "jdbc:mysql://"+geoConfig.getDsIp()+":"+geoConfig.getDsPort()+"/"+geoConfig.getDsBase()+"?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&zeroDateTimeBehavior=convertToNull&serverTimezone=Asia/Shanghai");
+        mapParams.put(DBCPDataSourceFactory.USERNAME.key, geoConfig.getDsUsername());
+        mapParams.put(DBCPDataSourceFactory.PASSWORD.key, geoConfig.getDsPassword());
+        mapParams.put(DBCPDataSourceFactory.MAXACTIVE.key, Integer.valueOf(10));
+        mapParams.put(DBCPDataSourceFactory.MAXIDLE.key, Integer.valueOf(0));
+
+        return DataSourceFinder.getDataSource(mapParams);
+
+    }
+}

cql-service/src/main/resources/application-test.properties → tile-web/src/main/resources/application-test.properties


cql-service/src/main/resources/application.yml → tile-web/src/main/resources/application.yml


cql-service/src/main/resources/logback.xml → tile-web/src/main/resources/logback.xml