AnalyseDBSchedule.java 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package com.onemap.analyse.task;
  2. import com.onemap.analyse.mapper.vector.TableDataMapper;
  3. import com.onemap.common.core.utils.DateUtils;
  4. import com.onemap.common.core.utils.StringUtils;
  5. import lombok.extern.slf4j.Slf4j;
  6. import org.bouncycastle.util.Strings;
  7. import org.springframework.scheduling.annotation.Scheduled;
  8. import org.springframework.stereotype.Component;
  9. import javax.annotation.Resource;
  10. import java.util.List;
  11. /**
  12. * 定时删除空间计算生成的临时表
  13. */
  14. @Component
  15. @Slf4j
  16. public class AnalyseDBSchedule {
  17. //间隔时间 单位ms
  18. public static final long TIME_INTERVAL = 10 * 60 * 1 * 1000;
  19. @Resource
  20. private TableDataMapper tableDataMapper;
  21. /**
  22. * 定时删除临时的数据库,删除10分钟之前的
  23. */
  24. @Scheduled(fixedDelay = TIME_INTERVAL)
  25. public void AnalyseDBDropStatus() {
  26. String TEMPORARY = "temporary";
  27. long tenMinutesInMillis = 10 * 60 * 1000; // 10分钟的毫秒数
  28. Long timeMillis = System.currentTimeMillis() - tenMinutesInMillis;
  29. String tenMinutesTableName = TEMPORARY + "_" + timeMillis;
  30. List<String> tableList = tableDataMapper.getVectorTableS();
  31. log.info("data :" + timeMillis);
  32. log.info("data1 :" + DateUtils.dateTimeNow());
  33. for (String tableName : tableList) {
  34. if (tableName.indexOf(TEMPORARY) == 0) {
  35. if (tableName.compareTo(tenMinutesTableName) < 0) {
  36. tableDataMapper.dropVectorTable(tableName);
  37. }
  38. }
  39. }
  40. }
  41. }