Browse Source

Merge branch 'dev' of http://114.244.114.158:8802/siwei/sanya-data-management-back into dev

gushoubang 8 months ago
parent
commit
4dfaea0a4a

+ 4 - 0
onemap-modules/onemap-analyse/src/main/java/com/onemap/analyse/mapper/vector/TableDataMapper.java

@@ -37,4 +37,8 @@ public interface TableDataMapper {
     void delByColumns(@Param("tableName") String tableName, @Param("column") String column, @Param("values") List<String> values);
 
     List<String> getTableNames(@Param("schema") String schema, @Param("startWith") String startWith);
+
+    List<String> getVectorTableS();
+
+    int dropVectorTable(@Param("tableName") String tableName);
 }

+ 46 - 0
onemap-modules/onemap-analyse/src/main/java/com/onemap/analyse/task/AnalyseDBSchedule.java

@@ -0,0 +1,46 @@
+package com.onemap.analyse.task;
+
+import com.onemap.analyse.mapper.vector.TableDataMapper;
+import com.onemap.common.core.utils.DateUtils;
+import com.onemap.common.core.utils.StringUtils;
+import lombok.extern.slf4j.Slf4j;
+import org.bouncycastle.util.Strings;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+import java.util.List;
+
+/**
+ * 定时删除空间计算生成的临时表
+ */
+@Component
+@Slf4j
+public class AnalyseDBSchedule {
+    //间隔时间 单位ms
+    public static final long TIME_INTERVAL = 60 * 60 * 1 * 1000;
+
+    @Resource
+    private TableDataMapper tableDataMapper;
+
+    /**
+     * 定时删除临时的数据库,删除10分钟之前的
+     */
+    @Scheduled(fixedDelay = TIME_INTERVAL)
+    public void AnalyseDBDropStatus() {
+        String TEMPORARY = "temporary";
+        long tenMinutesInMillis = 60 * 60 * 1000; // 10分钟的毫秒数
+        Long timeMillis = System.currentTimeMillis() - tenMinutesInMillis;
+        String tenMinutesTableName = TEMPORARY + "_" + timeMillis;
+        List<String> tableList = tableDataMapper.getVectorTableS();
+        log.info("data :" + timeMillis);
+        log.info("data1 :" + DateUtils.dateTimeNow());
+        for (String tableName : tableList) {
+            if (tableName.indexOf(TEMPORARY) == 0) {
+                if (tableName.compareTo(tenMinutesTableName) < 0) {
+                    tableDataMapper.dropVectorTable(tableName);
+                }
+            }
+        }
+    }
+}

+ 11 - 0
onemap-modules/onemap-analyse/src/main/resources/mapper/oracle/vector/TableDateMapper.xml

@@ -197,4 +197,15 @@
         FROM user_tables
         WHERE table_name LIKE #{tableName}
     </select>
+
+    <select id="getVectorTableS" resultType="String">
+        SELECT table_name
+        FROM information_schema.tables
+        WHERE table_schema = 'vector'
+    </select>
+
+    <delete id="dropVectorTable">
+        DROP TABLE "${tableName}"
+    </delete>
+
 </mapper>