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 = 10 * 60 * 1 * 1000; @Resource private TableDataMapper tableDataMapper; /** * 定时删除临时的数据库,删除10分钟之前的 */ @Scheduled(fixedDelay = TIME_INTERVAL) public void AnalyseDBDropStatus() { String TEMPORARY = "temporary"; long tenMinutesInMillis = 10 * 60 * 1000; // 10分钟的毫秒数 Long timeMillis = System.currentTimeMillis() - tenMinutesInMillis; String tenMinutesTableName = TEMPORARY + "_" + timeMillis; List 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); } } } } }