fix(接口测试): 修复定时清理不生效的缺陷

--bug=1039529 --user=王孝刚 【项目管理】项目与权限-接口测试报告保留时间设置3小时,场景报告超过3小时的未删除
https://www.tapd.cn/55049933/s/1499849
This commit is contained in:
wxg0103 2024-04-17 15:49:12 +08:00 committed by Craftsman
parent 5714a1275a
commit ff30c8e2ad
1 changed files with 5 additions and 4 deletions

View File

@ -3,7 +3,6 @@ package io.metersphere.sdk.util;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import java.time.Instant; import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.ZoneId; import java.time.ZoneId;
@ -50,8 +49,8 @@ public class ShareUtil {
} }
public static long getCleanDate(String expr) { public static long getCleanDate(String expr) {
LocalDate date = null; LocalDateTime date = null;
LocalDate localDate = LocalDate.now(); LocalDateTime localDate = LocalDateTime.now();
long timeMills = 0; long timeMills = 0;
if (StringUtils.isNotBlank(expr)) { if (StringUtils.isNotBlank(expr)) {
try { try {
@ -63,6 +62,8 @@ public class ShareUtil {
date = localDate.minusMonths(quantity); date = localDate.minusMonths(quantity);
} else if (StringUtils.equals(unit, UNIT_YEAR)) { } else if (StringUtils.equals(unit, UNIT_YEAR)) {
date = localDate.minusYears(quantity); date = localDate.minusYears(quantity);
} else if (StringUtils.equals(unit, UNIT_HOUR)) {
date = localDate.minusHours(quantity);
} else { } else {
LogUtils.error("clean up expr parse error. expr : " + expr); LogUtils.error("clean up expr parse error. expr : " + expr);
} }
@ -72,7 +73,7 @@ public class ShareUtil {
} }
} }
if (date != null) { if (date != null) {
timeMills = date.atStartOfDay(ZoneId.systemDefault()).toInstant().toEpochMilli(); timeMills = date.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
} }
return timeMills; return timeMills;
} }