Browse Source

增加数据库连接池逻辑和支持sql语句查询

liwh 1 year ago
parent
commit
635be39cae

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

@@ -47,7 +47,7 @@ public interface IECqlService {
 
 
 
-    void cqlAggQuery4Mysql(Map<String, Object> mapParams, String cql, FeatureVisitor visitor);
+    void cqlAggQuery(Map<String, Object> mapParams, String cql, FeatureVisitor visitor);
 
 
 }

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

@@ -9,5 +9,5 @@ import java.util.Map;
 public interface ISqlService {
 
 
-    PageResult sqlQuery4Mysql(Map<String, Object> mapParams, String sql, Object[] bindArgs);
+    PageResult sqlQuery4Jdbc(Map<String, Object> mapParams, String sql, Object[] bindArgs);
 }

+ 78 - 12
cql-service/src/main/java/cn/com/taiji/cql/service/impl/ECqlServiceImpl.java

@@ -16,6 +16,9 @@ import org.geotools.api.filter.identity.FeatureId;
 import org.geotools.api.filter.sort.SortBy;
 import org.geotools.api.filter.sort.SortOrder;
 import org.geotools.data.collection.ListFeatureCollection;
+import org.geotools.data.jdbc.datasource.DBCPDataSourceFactory;
+import org.geotools.data.jdbc.datasource.DataSourceFinder;
+import org.geotools.data.mysql.MySQLDataStoreFactory;
 import org.geotools.data.simple.SimpleFeatureCollection;
 import org.geotools.data.simple.SimpleFeatureIterator;
 import org.geotools.data.store.ContentFeatureSource;
@@ -26,6 +29,7 @@ import org.geotools.filter.text.ecql.ECQL;
 import org.geotools.jdbc.JDBCDataStoreFactory;
 import org.springframework.stereotype.Service;
 
+import javax.sql.DataSource;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -51,6 +55,8 @@ public class ECqlServiceImpl implements IECqlService{
 
         DataStore dataStore = null;
 
+        JDBCDataStoreFactory jDBCDataStoreFactory = null;
+
         String host = dsParams.get(JDBCDataStoreFactory.HOST.key).toString();
 
         String port = dsParams.get(JDBCDataStoreFactory.PORT.key).toString();
@@ -73,6 +79,7 @@ public class ECqlServiceImpl implements IECqlService{
 
 
         try {
+
             if(dataStoreMaps.containsKey(String.valueOf(hashKey))){
 
                 dataStore = dataStoreMaps.get(String.valueOf(hashKey));
@@ -81,11 +88,34 @@ public class ECqlServiceImpl implements IECqlService{
 
             }else{
 
-                dataStore = DataStoreFinder.getDataStore(dsParams);
 
-                dataStoreMaps.put(String.valueOf(hashKey),dataStore);
+                DataSource dataSource = DataSourceFinder.getDataSource(dsParams);
+
+                if(dataSource !=null){
+
+                    if(dsParams.get(DBCPDataSourceFactory.DRIVERCLASS.key).equals("com.mysql.cj.jdbc.Driver")){
+
+                        jDBCDataStoreFactory = new MySQLDataStoreFactory();
+                    }
+
+                    Map<String, Object> dataStoreParams = new HashMap<String, Object>();
+
+                    dataStoreParams.put(JDBCDataStoreFactory.SCHEMA.key, database);
+                    dataStoreParams.put(JDBCDataStoreFactory.DATASOURCE.key,dataSource);
+                    dataStoreParams.put(JDBCDataStoreFactory.BATCH_INSERT_SIZE.key, 1000);
+
+                    dataStore = jDBCDataStoreFactory.createDataStore(dataStoreParams);
+
+                    dataStoreMaps.put(String.valueOf(hashKey),dataStore);
+
+                    log.info("系统新建连接到位于:" + host + "的空间数据库" + database + "成功!");
+
+                }else{
+
+                    log.info("获取"+host+"-"+port+"-"+database+"的数据源连接池失败!");
+                }
+
 
-                log.info("系统新建连接到位于:" + host + "的空间数据库" + database + "成功!");
 
             }
 
@@ -481,17 +511,60 @@ public class ECqlServiceImpl implements IECqlService{
     }
 
     @Override
-    public void cqlAggQuery4Mysql(Map<String, Object> mapParams, String cql, FeatureVisitor visitor) {
+    public void cqlAggQuery(Map<String, Object> mapParams, String cql, FeatureVisitor visitor) {
 
         String host = mapParams.get(JDBCDataStoreFactory.HOST.key).toString();
 
+        String port = mapParams.get(JDBCDataStoreFactory.PORT.key).toString();
+
         String database = mapParams.get(JDBCDataStoreFactory.DATABASE.key).toString();
 
+        int hashKey = HashCodeUtil.hashCode(host+"-"+port+"-"+database);
+
         DataStore dataStore = null;
 
+        JDBCDataStoreFactory jDBCDataStoreFactory = null;
+
         try{
 
-            dataStore = DataStoreFinder.getDataStore(mapParams);
+            if(dataStoreMaps.containsKey(String.valueOf(hashKey))){
+
+                dataStore = dataStoreMaps.get(String.valueOf(hashKey));
+
+                log.info("系统从内存连接到位于:" + host + "的空间数据库" + database + "成功!");
+
+            }else{
+
+
+                DataSource dataSource = DataSourceFinder.getDataSource(mapParams);
+
+                if(dataSource !=null){
+
+                    if(mapParams.get(DBCPDataSourceFactory.DRIVERCLASS.key).equals("com.mysql.cj.jdbc.Driver")){
+
+                        jDBCDataStoreFactory = new MySQLDataStoreFactory();
+                    }
+
+                    Map<String, Object> dataStoreParams = new HashMap<String, Object>();
+
+                    dataStoreParams.put(JDBCDataStoreFactory.SCHEMA.key, database);
+                    dataStoreParams.put(JDBCDataStoreFactory.DATASOURCE.key,dataSource);
+                    dataStoreParams.put(JDBCDataStoreFactory.BATCH_INSERT_SIZE.key, 1000);
+
+                    dataStore = jDBCDataStoreFactory.createDataStore(dataStoreParams);
+
+                    dataStoreMaps.put(String.valueOf(hashKey),dataStore);
+
+                    log.info("系统新建连接到位于:" + host + "的空间数据库" + database + "成功!");
+
+                }else{
+
+                    log.info("获取"+host+"-"+port+"-"+database+"的数据源连接池失败!");
+                }
+
+
+
+            }
 
             if (dataStore != null) {
 
@@ -522,13 +595,6 @@ public class ECqlServiceImpl implements IECqlService{
             e.printStackTrace();
             log.error("系统连接到位于:" + mapParams.get(JDBCDataStoreFactory.HOST.key) + "的空间数据库" + mapParams.get(JDBCDataStoreFactory.DATABASE.key) + "失败!请检查相关参数");
 
-        }finally {
-
-            if(dataStore !=null){
-
-                dataStore.dispose();
-
-            }
         }
     }
 }

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

@@ -19,7 +19,7 @@ import java.util.Map;
 public class SqlServiceImpl implements ISqlService {
 
     @Override
-    public PageResult sqlQuery4Mysql(Map<String, Object> mapParams, String sql, Object[] bindArgs) {
+    public PageResult sqlQuery4Jdbc(Map<String, Object> mapParams, String sql, Object[] bindArgs) {
 
 
         //查询记录总数

+ 76 - 39
tile-service/src/main/java/cn/com/taiji/tile/service/impl/TileServiceImpl.java

@@ -5,11 +5,13 @@ import cn.com.taiji.common.model.LayerGroupDsView;
 import cn.com.taiji.common.model.LayerStyleView;
 import cn.com.taiji.cql.model.GeoRequestParam;
 import cn.com.taiji.cql.service.IECqlService;
+import cn.com.taiji.cql.service.ISqlService;
 import cn.com.taiji.tile.model.POI;
 import cn.com.taiji.tile.service.ITileService;
 import cn.com.taiji.tile.style.ShapeStyle;
 import cn.com.taiji.tile.util.ShapeUtils;
 import lombok.extern.slf4j.Slf4j;
+import org.geotools.data.jdbc.datasource.DBCPDataSourceFactory;
 import org.geotools.jdbc.JDBCDataStoreFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -30,6 +32,9 @@ public class TileServiceImpl implements ITileService {
     @Autowired
     private IECqlService ecqlService;
 
+    @Autowired
+    private ISqlService sqlService;
+
 
     @Override
     public byte[] tileData(GeoRequestParam requestParam, List<LayerGroupDsView> layerGroupDsViewList, Map<String, List<LayerStyleView>> dataMaps) {
@@ -48,42 +53,61 @@ public class TileServiceImpl implements ITileService {
             }
 
 
-            //2根据cql规则获取图层对应的空间地理数据
+            String host = layerGroupDsView.getHost().split(",")[0].split(":")[0];
+            String port = layerGroupDsView.getHost().split(",")[0].split(":")[1];
 
-            long currentTimeMillis = System.currentTimeMillis();
+            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());
 
-            StringBuffer filterCqlStr = new StringBuffer();
 
-            String filterCql = requestParam.getCqlFilter();
+            String layerDataType = layerGroupDsView.getLayerDataType();
+            String layerDataRun = layerGroupDsView.getLayerDataRun();
 
-            if (filterCql != null && !"".equals(filterCql)) {
+            PageResult pageResult = null;
 
-                filterCqlStr.append(filterCql);
-            }
+            StringBuffer filterCqlStr = new StringBuffer();
 
-            String bbox = requestParam.getBbox();
-            if(bbox !=null && !"".equals(bbox)){
+            if (layerDataType != null && !"".equals(layerDataType) && "cql".equals(layerDataType)) {
 
-                StringBuffer sbBbox = new StringBuffer();
-                sbBbox.append("(bbox (");
-                sbBbox.append(layerGroupDsView.getBoxColumn()+",");
-                sbBbox.append(requestParam.getBbox()+"))");
+                //2根据cql规则获取图层对应的空间地理数据
 
-                if(filterCqlStr.length() >0){
+                long currentTimeMillis = System.currentTimeMillis();
 
-                    filterCqlStr.append(" and "+sbBbox.toString());
-                }else{
+                String filterCql = requestParam.getCqlFilter();
 
-                    filterCqlStr.append(sbBbox.toString());
+                if (filterCql != null && !"".equals(filterCql)) {
 
+                    filterCqlStr.append(filterCql);
                 }
 
-            }
+                String bbox = requestParam.getBbox();
+                if(bbox !=null && !"".equals(bbox)){
 
-            String layerDataType = layerGroupDsView.getLayerDataType();
-            String layerDataRun = layerGroupDsView.getLayerDataRun();
+                    StringBuffer sbBbox = new StringBuffer();
+                    sbBbox.append("(bbox (");
+                    sbBbox.append(layerGroupDsView.getBoxColumn()+",");
+                    sbBbox.append(requestParam.getBbox()+"))");
 
-            if (layerDataType != null && !"".equals(layerDataType) && "cql".equals(layerDataType)) {
+                    if(filterCqlStr.length() >0){
+
+                        filterCqlStr.append(" and "+sbBbox.toString());
+                    }else{
+
+                        filterCqlStr.append(sbBbox.toString());
+
+                    }
+
+                }
 
                 if (layerDataRun != null && !"".equals(layerDataRun)) {
 
@@ -98,34 +122,47 @@ public class TileServiceImpl implements ITileService {
 
                 }
 
-            }
+                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");
+
+                }
 
-            System.out.println("查询条件:" + filterCqlStr.toString());
 
-            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(JDBCDataStoreFactory.DATABASE.key, layerGroupDsView.getDataBase());
-            cqlDsParams.put(JDBCDataStoreFactory.DBTYPE.key, layerGroupDsView.getDbType());
-            cqlDsParams.put(JDBCDataStoreFactory.HOST.key, host);
-            cqlDsParams.put(JDBCDataStoreFactory.PORT.key, port);
-            cqlDsParams.put(JDBCDataStoreFactory.USER.key, layerGroupDsView.getUserName());
-            cqlDsParams.put(JDBCDataStoreFactory.PASSWD.key, layerGroupDsView.getUserPassword());
-            cqlDsParams.put("tableName", layerGroupDsView.getTableName());
-            Map<String, Object> mapParams = new HashMap<String, Object>();
-            if (filterCqlStr.length() > 0) {
-                mapParams.put("cql", filterCqlStr.toString());
             }
-            PageResult pageResult = ecqlService.cqlQuery(cqlDsParams, mapParams);
-            if (pageResult.getRecordCount() > 0) {
+
+
+            if (pageResult!=null && pageResult.getRecordCount() > 0 ) {
+
                 List<Map<String, Object>> cqlDataList = (List<Map<String, Object>>) pageResult.getDatas();
                 //3根据空间地理数据生成图层二进制数据
                 ShapeUtils.drawImage(requestParam.getBbox(), convert(cqlDataList,layerGroupDsView.getBoxColumn()), layerStyleViewList,g2);
 
             } else {
 
-                log.info("根据cql规则:" + filterCqlStr.toString() + "和图层代码:" + requestParam.getLayers() + " 没有找到图层对应的数据源的空间地理数据");
+                log.info("根据查询过滤规则条件:" + filterCqlStr.toString() + "和图层代码:" + requestParam.getLayers() + " 没有找到图层对应的数据源的空间地理数据");
             }
 
         }

+ 33 - 23
tile-web/src/main/java/cn/com/taiji/web/service/impl/EnterpriseServiceImpl.java

@@ -44,14 +44,18 @@ public class EnterpriseServiceImpl implements IEnterpriseService {
     public PageResult enterpriseQuery(EnterpriseVo enterpriseVo) {
 
         //数据源
-        Map<String, Object> entDsParams = new HashMap<String, Object>();
-        entDsParams.put(JDBCDataStoreFactory.DATABASE.key, enterpriseConfig.getDsBaseName());
-        entDsParams.put(JDBCDataStoreFactory.DBTYPE.key, enterpriseConfig.getDbType());
 
+        Map<String, Object> entDsParams = new HashMap<String, Object>();
+        entDsParams.put(DBCPDataSourceFactory.DSTYPE.key, "DBCP");
+        entDsParams.put(DBCPDataSourceFactory.DRIVERCLASS.key, "com.mysql.cj.jdbc.Driver");
+        entDsParams.put(DBCPDataSourceFactory.JDBC_URL.key, "jdbc:mysql://"+enterpriseConfig.getDsIp()+":"+enterpriseConfig.getDsPort()+"/"+enterpriseConfig.getDsBaseName()+"?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&zeroDateTimeBehavior=convertToNull&serverTimezone=Asia/Shanghai");
+        entDsParams.put(DBCPDataSourceFactory.USERNAME.key, enterpriseConfig.getDsUserName());
+        entDsParams.put(DBCPDataSourceFactory.PASSWORD.key, enterpriseConfig.getDsPassword());
+        entDsParams.put(DBCPDataSourceFactory.MAXACTIVE.key, Integer.valueOf(10));
+        entDsParams.put(DBCPDataSourceFactory.MAXIDLE.key, Integer.valueOf(1));
         entDsParams.put(JDBCDataStoreFactory.HOST.key, enterpriseConfig.getDsIp());
+        entDsParams.put(JDBCDataStoreFactory.DATABASE.key, enterpriseConfig.getDsBaseName());
         entDsParams.put(JDBCDataStoreFactory.PORT.key, enterpriseConfig.getDsPort());
-        entDsParams.put(JDBCDataStoreFactory.USER.key, enterpriseConfig.getDsUserName());
-        entDsParams.put(JDBCDataStoreFactory.PASSWD.key, enterpriseConfig.getDsPassword());
         entDsParams.put("tableName", enterpriseConfig.getEnterprise());
 
         //组转cql查询条件
@@ -149,15 +153,14 @@ public class EnterpriseServiceImpl implements IEnterpriseService {
         mapParams.put(DBCPDataSourceFactory.USERNAME.key, enterpriseConfig.getDsUserName());
         mapParams.put(DBCPDataSourceFactory.PASSWORD.key, enterpriseConfig.getDsPassword());
         mapParams.put(DBCPDataSourceFactory.MAXACTIVE.key, Integer.valueOf(10));
-        mapParams.put(DBCPDataSourceFactory.MAXIDLE.key, Integer.valueOf(0));
+        mapParams.put(DBCPDataSourceFactory.MAXIDLE.key, Integer.valueOf(1));
         mapParams.put(JDBCDataStoreFactory.HOST.key, enterpriseConfig.getDsIp());
         mapParams.put(JDBCDataStoreFactory.DATABASE.key, enterpriseConfig.getDsBaseName());
 
 
-//        String sql = "SELECT *,(st_distance(point(longitude, latitude), point("+deviceVo.getLon()+","+deviceVo.getLat()+"))*111195) AS distance FROM "+enterpriseConfig.getDevice()+" having distance < "+deviceVo.getRadius()*1000+" order by distance asc";
-          String sql = "SELECT *,(6371 * acos (cos ( radians("+deviceVo.getLat()+") )* cos( radians(latitude) )* cos( radians(longitude) - radians("+deviceVo.getLon()+") )+ sin ( radians("+deviceVo.getLat()+"))* sin( radians(latitude) ))) AS distance FROM "+enterpriseConfig.getDevice()+" having distance <"+deviceVo.getRadius()+" order by distance asc";
+        String sql = "SELECT *,(6371 * acos (cos ( radians("+deviceVo.getLat()+") )* cos( radians(latitude) )* cos( radians(longitude) - radians("+deviceVo.getLon()+") )+ sin ( radians("+deviceVo.getLat()+"))* sin( radians(latitude) ))) AS distance FROM "+enterpriseConfig.getDevice()+" having distance <"+deviceVo.getRadius()+" order by distance asc";
 
-        PageResult pageResult = sqlService.sqlQuery4Mysql(mapParams,sql,null);
+        PageResult pageResult = sqlService.sqlQuery4Jdbc(mapParams,sql,null);
 
         List<DeviceInfo> deviceInfoList = new ArrayList<DeviceInfo>();
 
@@ -190,13 +193,16 @@ public class EnterpriseServiceImpl implements IEnterpriseService {
 
         //数据源
         Map<String, Object> entDsParams = new HashMap<String, Object>();
-        entDsParams.put(JDBCDataStoreFactory.DATABASE.key, enterpriseConfig.getDsBaseName());
-        entDsParams.put(JDBCDataStoreFactory.DBTYPE.key, enterpriseConfig.getDbType());
-
+        entDsParams.put(DBCPDataSourceFactory.DSTYPE.key, "DBCP");
+        entDsParams.put(DBCPDataSourceFactory.DRIVERCLASS.key, "com.mysql.cj.jdbc.Driver");
+        entDsParams.put(DBCPDataSourceFactory.JDBC_URL.key, "jdbc:mysql://"+enterpriseConfig.getDsIp()+":"+enterpriseConfig.getDsPort()+"/"+enterpriseConfig.getDsBaseName()+"?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&zeroDateTimeBehavior=convertToNull&serverTimezone=Asia/Shanghai");
+        entDsParams.put(DBCPDataSourceFactory.USERNAME.key, enterpriseConfig.getDsUserName());
+        entDsParams.put(DBCPDataSourceFactory.PASSWORD.key, enterpriseConfig.getDsPassword());
+        entDsParams.put(DBCPDataSourceFactory.MAXACTIVE.key, Integer.valueOf(10));
+        entDsParams.put(DBCPDataSourceFactory.MAXIDLE.key, Integer.valueOf(1));
         entDsParams.put(JDBCDataStoreFactory.HOST.key, enterpriseConfig.getDsIp());
+        entDsParams.put(JDBCDataStoreFactory.DATABASE.key, enterpriseConfig.getDsBaseName());
         entDsParams.put(JDBCDataStoreFactory.PORT.key, enterpriseConfig.getDsPort());
-        entDsParams.put(JDBCDataStoreFactory.USER.key, enterpriseConfig.getDsUserName());
-        entDsParams.put(JDBCDataStoreFactory.PASSWD.key, enterpriseConfig.getDsPassword());
         entDsParams.put("tableName", enterpriseConfig.getDevice());
 
         //组转cql查询条件
@@ -275,35 +281,39 @@ public class EnterpriseServiceImpl implements IEnterpriseService {
     public Result staticsQuery() {
 
         //数据源
-        Map<String, Object> entDsParams = new HashMap<String, Object>();
-        entDsParams.put(JDBCDataStoreFactory.DATABASE.key, enterpriseConfig.getDsBaseName());
-        entDsParams.put(JDBCDataStoreFactory.DBTYPE.key, enterpriseConfig.getDbType());
 
+        Map<String, Object> entDsParams = new HashMap<String, Object>();
+        entDsParams.put(DBCPDataSourceFactory.DSTYPE.key, "DBCP");
+        entDsParams.put(DBCPDataSourceFactory.DRIVERCLASS.key, "com.mysql.cj.jdbc.Driver");
+        entDsParams.put(DBCPDataSourceFactory.JDBC_URL.key, "jdbc:mysql://"+enterpriseConfig.getDsIp()+":"+enterpriseConfig.getDsPort()+"/"+enterpriseConfig.getDsBaseName()+"?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&zeroDateTimeBehavior=convertToNull&serverTimezone=Asia/Shanghai");
+        entDsParams.put(DBCPDataSourceFactory.USERNAME.key, enterpriseConfig.getDsUserName());
+        entDsParams.put(DBCPDataSourceFactory.PASSWORD.key, enterpriseConfig.getDsPassword());
+        entDsParams.put(DBCPDataSourceFactory.MAXACTIVE.key, Integer.valueOf(10));
+        entDsParams.put(DBCPDataSourceFactory.MAXIDLE.key, Integer.valueOf(1));
         entDsParams.put(JDBCDataStoreFactory.HOST.key, enterpriseConfig.getDsIp());
+        entDsParams.put(JDBCDataStoreFactory.DATABASE.key, enterpriseConfig.getDsBaseName());
         entDsParams.put(JDBCDataStoreFactory.PORT.key, enterpriseConfig.getDsPort());
-        entDsParams.put(JDBCDataStoreFactory.USER.key, enterpriseConfig.getDsUserName());
-        entDsParams.put(JDBCDataStoreFactory.PASSWD.key, enterpriseConfig.getDsPassword());
         entDsParams.put("tableName", enterpriseConfig.getEnterprise());
 
         //计算企业总数
 
         CountVisitor countVisitor = new CountVisitor();
-        ecqlService.cqlAggQuery4Mysql(entDsParams,null,countVisitor);
+        ecqlService.cqlAggQuery(entDsParams,null,countVisitor);
 
         //计算零关税自用进口生产设备数量
         CountVisitor deviceCountVisitor = new CountVisitor();
         String cqlDevice = "(qykx ='零关税自用进口生产设备')";
-        ecqlService.cqlAggQuery4Mysql(entDsParams,cqlDevice,deviceCountVisitor);
+        ecqlService.cqlAggQuery(entDsParams,cqlDevice,deviceCountVisitor);
 
         //计算零关税进口原辅料数量
         CountVisitor materialCountVisitor = new CountVisitor();
         String cqlMaterial = "(qykx ='零关税进口原辅料')";
-        ecqlService.cqlAggQuery4Mysql(entDsParams,cqlMaterial,materialCountVisitor);
+        ecqlService.cqlAggQuery(entDsParams,cqlMaterial,materialCountVisitor);
 
         //计算加工增值免关税数量
         CountVisitor noTaxCountVisitor = new CountVisitor();
         String cqlNoTax = "(qykx ='加工增值免关税')";
-        ecqlService.cqlAggQuery4Mysql(entDsParams,cqlNoTax,noTaxCountVisitor);
+        ecqlService.cqlAggQuery(entDsParams,cqlNoTax,noTaxCountVisitor);
 
         StaticsInfo staticsInfo = new StaticsInfo();
         staticsInfo.setCount(countVisitor.getCount());

+ 49 - 34
tile-web/src/main/java/cn/com/taiji/web/service/impl/GeoDataSourceServiceImpl.java

@@ -44,13 +44,16 @@ public class GeoDataSourceServiceImpl implements IGeoDataSourceService {
         List<LayerGroupDsView> layerGroupDsViewList = new ArrayList<LayerGroupDsView>();
 
         Map<String, Object> dsParams = new HashMap<String, Object>();
-        dsParams.put(JDBCDataStoreFactory.DATABASE.key, geoConfig.getDsBase());
-        dsParams.put(JDBCDataStoreFactory.DBTYPE.key, geoConfig.getDbType());
-
+        dsParams.put(DBCPDataSourceFactory.DSTYPE.key, "DBCP");
+        dsParams.put(DBCPDataSourceFactory.DRIVERCLASS.key, "com.mysql.cj.jdbc.Driver");
+        dsParams.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");
+        dsParams.put(DBCPDataSourceFactory.USERNAME.key, geoConfig.getDsUsername());
+        dsParams.put(DBCPDataSourceFactory.PASSWORD.key, geoConfig.getDsPassword());
+        dsParams.put(DBCPDataSourceFactory.MAXACTIVE.key, Integer.valueOf(10));
+        dsParams.put(DBCPDataSourceFactory.MAXIDLE.key, Integer.valueOf(1));
         dsParams.put(JDBCDataStoreFactory.HOST.key, geoConfig.getDsIp());
+        dsParams.put(JDBCDataStoreFactory.DATABASE.key, geoConfig.getDsBase());
         dsParams.put(JDBCDataStoreFactory.PORT.key, geoConfig.getDsPort());
-        dsParams.put(JDBCDataStoreFactory.USER.key, geoConfig.getDsUsername());
-        dsParams.put(JDBCDataStoreFactory.PASSWD.key, geoConfig.getDsPassword());
         dsParams.put("tableName", "layer_group_ds_view");
 
 
@@ -86,14 +89,18 @@ public class GeoDataSourceServiceImpl implements IGeoDataSourceService {
         if(CollUtil.isEmpty(layerCodeList)){
             return dataMaps;
         }
-        Map<String, Object> dsParams = new HashMap<String, Object>();
-        dsParams.put(JDBCDataStoreFactory.DATABASE.key, geoConfig.getDsBase());
-        dsParams.put(JDBCDataStoreFactory.DBTYPE.key, geoConfig.getDbType());
 
+        Map<String, Object> dsParams = new HashMap<String, Object>();
+        dsParams.put(DBCPDataSourceFactory.DSTYPE.key, "DBCP");
+        dsParams.put(DBCPDataSourceFactory.DRIVERCLASS.key, "com.mysql.cj.jdbc.Driver");
+        dsParams.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");
+        dsParams.put(DBCPDataSourceFactory.USERNAME.key, geoConfig.getDsUsername());
+        dsParams.put(DBCPDataSourceFactory.PASSWORD.key, geoConfig.getDsPassword());
+        dsParams.put(DBCPDataSourceFactory.MAXACTIVE.key, Integer.valueOf(10));
+        dsParams.put(DBCPDataSourceFactory.MAXIDLE.key, Integer.valueOf(1));
         dsParams.put(JDBCDataStoreFactory.HOST.key, geoConfig.getDsIp());
+        dsParams.put(JDBCDataStoreFactory.DATABASE.key, geoConfig.getDsBase());
         dsParams.put(JDBCDataStoreFactory.PORT.key, geoConfig.getDsPort());
-        dsParams.put(JDBCDataStoreFactory.USER.key, geoConfig.getDsUsername());
-        dsParams.put(JDBCDataStoreFactory.PASSWD.key, geoConfig.getDsPassword());
         dsParams.put("tableName", "layer_style_view");
 
 
@@ -163,14 +170,16 @@ public class GeoDataSourceServiceImpl implements IGeoDataSourceService {
     public PageResult geoDsQuery(Map<String, Object> paramMaps) throws Exception {
 
         Map<String, Object> dsParams = new HashMap<String, Object>();
-
-        dsParams.put(JDBCDataStoreFactory.DATABASE.key, geoConfig.getDsBase());
-        dsParams.put(JDBCDataStoreFactory.DBTYPE.key, geoConfig.getDbType());
-
+        dsParams.put(DBCPDataSourceFactory.DSTYPE.key, "DBCP");
+        dsParams.put(DBCPDataSourceFactory.DRIVERCLASS.key, "com.mysql.cj.jdbc.Driver");
+        dsParams.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");
+        dsParams.put(DBCPDataSourceFactory.USERNAME.key, geoConfig.getDsUsername());
+        dsParams.put(DBCPDataSourceFactory.PASSWORD.key, geoConfig.getDsPassword());
+        dsParams.put(DBCPDataSourceFactory.MAXACTIVE.key, Integer.valueOf(10));
+        dsParams.put(DBCPDataSourceFactory.MAXIDLE.key, Integer.valueOf(1));
         dsParams.put(JDBCDataStoreFactory.HOST.key, geoConfig.getDsIp());
+        dsParams.put(JDBCDataStoreFactory.DATABASE.key, geoConfig.getDsBase());
         dsParams.put(JDBCDataStoreFactory.PORT.key, geoConfig.getDsPort());
-        dsParams.put(JDBCDataStoreFactory.USER.key, geoConfig.getDsUsername());
-        dsParams.put(JDBCDataStoreFactory.PASSWD.key, geoConfig.getDsPassword());
         dsParams.put("tableName", "tile_data_source");
 
         return ecqlService.cqlQuery(dsParams,paramMaps);
@@ -180,14 +189,16 @@ public class GeoDataSourceServiceImpl implements IGeoDataSourceService {
     public Result geoDsAddInfo(Map<String, Object> paramMaps) throws Exception {
 
         Map<String, Object> dsParams = new HashMap<String, Object>();
-
-        dsParams.put(JDBCDataStoreFactory.DATABASE.key, geoConfig.getDsBase());
-        dsParams.put(JDBCDataStoreFactory.DBTYPE.key, geoConfig.getDbType());
-
+        dsParams.put(DBCPDataSourceFactory.DSTYPE.key, "DBCP");
+        dsParams.put(DBCPDataSourceFactory.DRIVERCLASS.key, "com.mysql.cj.jdbc.Driver");
+        dsParams.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");
+        dsParams.put(DBCPDataSourceFactory.USERNAME.key, geoConfig.getDsUsername());
+        dsParams.put(DBCPDataSourceFactory.PASSWORD.key, geoConfig.getDsPassword());
+        dsParams.put(DBCPDataSourceFactory.MAXACTIVE.key, Integer.valueOf(10));
+        dsParams.put(DBCPDataSourceFactory.MAXIDLE.key, Integer.valueOf(1));
         dsParams.put(JDBCDataStoreFactory.HOST.key, geoConfig.getDsIp());
+        dsParams.put(JDBCDataStoreFactory.DATABASE.key, geoConfig.getDsBase());
         dsParams.put(JDBCDataStoreFactory.PORT.key, geoConfig.getDsPort());
-        dsParams.put(JDBCDataStoreFactory.USER.key, geoConfig.getDsUsername());
-        dsParams.put(JDBCDataStoreFactory.PASSWD.key, geoConfig.getDsPassword());
         dsParams.put("tableName", "tile_data_source");
 
         DateTime beginTime = DateUtil.parse(DateUtil.formatDateTime(new Date()), DatePattern.NORM_DATETIME_PATTERN);
@@ -201,14 +212,16 @@ public class GeoDataSourceServiceImpl implements IGeoDataSourceService {
     public Result geoDsUpdateInfo(Map<String, Object> paramMaps) throws Exception {
 
         Map<String, Object> dsParams = new HashMap<String, Object>();
-
-        dsParams.put(JDBCDataStoreFactory.DATABASE.key, geoConfig.getDsBase());
-        dsParams.put(JDBCDataStoreFactory.DBTYPE.key, geoConfig.getDbType());
-
+        dsParams.put(DBCPDataSourceFactory.DSTYPE.key, "DBCP");
+        dsParams.put(DBCPDataSourceFactory.DRIVERCLASS.key, "com.mysql.cj.jdbc.Driver");
+        dsParams.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");
+        dsParams.put(DBCPDataSourceFactory.USERNAME.key, geoConfig.getDsUsername());
+        dsParams.put(DBCPDataSourceFactory.PASSWORD.key, geoConfig.getDsPassword());
+        dsParams.put(DBCPDataSourceFactory.MAXACTIVE.key, Integer.valueOf(10));
+        dsParams.put(DBCPDataSourceFactory.MAXIDLE.key, Integer.valueOf(1));
         dsParams.put(JDBCDataStoreFactory.HOST.key, geoConfig.getDsIp());
+        dsParams.put(JDBCDataStoreFactory.DATABASE.key, geoConfig.getDsBase());
         dsParams.put(JDBCDataStoreFactory.PORT.key, geoConfig.getDsPort());
-        dsParams.put(JDBCDataStoreFactory.USER.key, geoConfig.getDsUsername());
-        dsParams.put(JDBCDataStoreFactory.PASSWD.key, geoConfig.getDsPassword());
         dsParams.put("tableName", "tile_data_source");
 
         DateTime updateTime = DateUtil.parse(DateUtil.formatDateTime(new Date()), DatePattern.NORM_DATETIME_PATTERN);
@@ -229,14 +242,16 @@ public class GeoDataSourceServiceImpl implements IGeoDataSourceService {
     public Result geoDsRemoveInfo(Map<String, Object> paramMaps) throws Exception {
 
         Map<String, Object> dsParams = new HashMap<String, Object>();
-
-        dsParams.put(JDBCDataStoreFactory.DATABASE.key, geoConfig.getDsBase());
-        dsParams.put(JDBCDataStoreFactory.DBTYPE.key, geoConfig.getDbType());
-
+        dsParams.put(DBCPDataSourceFactory.DSTYPE.key, "DBCP");
+        dsParams.put(DBCPDataSourceFactory.DRIVERCLASS.key, "com.mysql.cj.jdbc.Driver");
+        dsParams.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");
+        dsParams.put(DBCPDataSourceFactory.USERNAME.key, geoConfig.getDsUsername());
+        dsParams.put(DBCPDataSourceFactory.PASSWORD.key, geoConfig.getDsPassword());
+        dsParams.put(DBCPDataSourceFactory.MAXACTIVE.key, Integer.valueOf(10));
+        dsParams.put(DBCPDataSourceFactory.MAXIDLE.key, Integer.valueOf(1));
         dsParams.put(JDBCDataStoreFactory.HOST.key, geoConfig.getDsIp());
+        dsParams.put(JDBCDataStoreFactory.DATABASE.key, geoConfig.getDsBase());
         dsParams.put(JDBCDataStoreFactory.PORT.key, geoConfig.getDsPort());
-        dsParams.put(JDBCDataStoreFactory.USER.key, geoConfig.getDsUsername());
-        dsParams.put(JDBCDataStoreFactory.PASSWD.key, geoConfig.getDsPassword());
         dsParams.put("tableName", "tile_data_source");
 
         String cql = paramMaps.get("cql").toString();