liyatao hai 7 meses
pai
achega
5f919d1284

+ 5 - 0
onemap-modules/onemap-overlap/pom.xml

@@ -170,6 +170,11 @@
             <artifactId>sqlite-jdbc</artifactId>
             <version>3.47.1.0</version>
         </dependency>
+<!--        <dependency>-->
+<!--            <groupId>org.geotools.jdbc</groupId>-->
+<!--            <artifactId>gt-jdbc-spatialite</artifactId>-->
+<!--            <version>20.4</version>-->
+<!--        </dependency>-->
     </dependencies>
 
     <repositories>

+ 28 - 6
onemap-modules/onemap-overlap/src/main/java/com/onemap/overlap/service/impl/SQLiteImp.java

@@ -11,6 +11,14 @@ import java.sql.*;
 
 import com.onemap.overlap.service.impl.SQLiteHelper;
 
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import org.sqlite.SQLiteConfig;
+
 @Service
 public class SQLiteImp implements SQLiteService {
     @Value("${spatialite.filepath}")
@@ -23,14 +31,18 @@ public class SQLiteImp implements SQLiteService {
         try {
             // 加载SQLite驱动程序
             Class.forName("org.sqlite.JDBC");
-            // 创建数据库连接
-            //connection = DriverManager.getConnection(String.format("jdbc:sqlite:%s",filepath));
-            SQLiteHelper sqliteHelper = new SQLiteHelper(filepath);
-            connection = sqliteHelper.getConnection(filepath);
+            SQLiteConfig config = new SQLiteConfig();
+            config.enableLoadExtension(true);//扩展
+            connection = config.createConnection("jdbc:sqlite:" + filepath);
             // 创建Statement对象
             statement = connection.createStatement();
-
-            //查询
+            statement.execute("SELECT load_extension('mod_spatialite')");//启动sqlite空间扩展,启动前需要把mod_spatialite驱动拷贝至C:\Windows\System32
+            String sqlDelete = "delete from 当前检查图斑;";
+            Boolean reultDelete = statement.execute(sqlDelete);
+            String sqlInsert = "insert into 当前检查图斑 (id,图斑编号,HLX,HLB,合法性判断,合法性说明,面积,geom) SELECT id,JCBH, HLX, HLB, '' as 合法性判断, '' as 合法性说明,  '' as 面积, geom FROM wuchuan4525";
+            Boolean reultInsert = statement.execute(sqlInsert);
+            String sqlUpdate = "update 当前检查图斑 set 合法性判断 =  null , 合法性说明 = null ;";
+            Boolean reultUpdate = statement.execute(sqlUpdate);
             String querySQL = "select 图层名,合法方式,有效性 from 管控信息表";
             //ResultSet resultSet = sqliteHelper.executeQuery(querySQL,new RowMapper<String>(){});
             ResultSet resultSet = statement.executeQuery(querySQL);
@@ -38,6 +50,16 @@ public class SQLiteImp implements SQLiteService {
                 String layerName = resultSet.getString("图层名");
                 String type = resultSet.getString("合法方式");
                 String isValid = resultSet.getString("有效性");
+                if(isValid.equals("有效")){
+                    if(type.equals("外部")){
+                        String update = String.format("update 当前检查图斑 as c set 合法性说明 = case when 合法性说明 is null then '' else 合法性说明 || ';' end || '疑似%s内建设',面积 = case when 面积 is null then '' else 面积 end || ST_Area(ST_Intersection(c.geom,d.geom)) || ';' from %s d, idx_当前检查图斑_geom a, %s b where (a.xmax >= b.xmin  and a.xmin <= b.xmax and a.ymax >= b.ymin and a.ymin <= b.ymax) and (a.rowid = c.rowid  and b.rowid = d.rowid) and intersects(c.geom, d.geom) and st_intersection(c.geom,d.geom)  is not null;",layerName ,layerName,"idx_"+layerName+"_geom");
+                        Boolean resultUpdateOverlap = statement.execute(update);
+                    }
+                    if(type.equals("内部")){
+                        String update = String.format("update 当前检查图斑 as c set 合法性说明 = case when 合法性说明 is null then '' else 合法性说明 || ';' end || '符合%s用地',面积 = case when 面积 is null then '' else 面积  end || ST_Area(ST_Intersection(c.geom,d.geom))|| ';' from %s d, idx_当前检查图斑_geom a, %s b where (a.xmax >= b.xmin  and a.xmin <= b.xmax and a.ymax >= b.ymin and a.ymin <= b.ymax) and (a.rowid = c.rowid  and b.rowid = d.rowid) and intersects(c.geom, d.geom) and st_within(c.geom, d.geom);",layerName ,layerName,"idx_"+layerName+"_geom");
+                        Boolean resultUpdateOverlap = statement.execute(update);
+                    }
+                }
             }
 
         } catch (ClassNotFoundException e) {