查询时间戳提前3小时

This commit is contained in:
李正@用友 2025-05-22 12:24:11 +08:00
parent ab3ed04215
commit ab7ec1a0ff
1 changed files with 9 additions and 5 deletions

View File

@ -14,10 +14,7 @@ import javax.ws.rs.Consumes;
import javax.ws.rs.POST; import javax.ws.rs.POST;
import javax.ws.rs.Path; import javax.ws.rs.Path;
import javax.ws.rs.Produces; import javax.ws.rs.Produces;
import java.util.Date; import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
// import java.util.StringJoiner; // 不再需要 // import java.util.StringJoiner; // 不再需要
@ -37,8 +34,15 @@ public class QuerySync extends AbstractNCCRestResource {
if (tsObj instanceof String) { if (tsObj instanceof String) {
String ts = (String) tsObj; String ts = (String) tsObj;
UFDate ufdate = new UFDate(ts);
Date date = ufdate.toDate();
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.HOUR_OF_DAY, -3); // 减去 3 小时
//提前三小时防止ts与现实时间差别
UFDate adjustedUfDate = new UFDate(calendar.getTimeInMillis());
if (!ts.contains(",")) { // 单个时间戳 if (!ts.contains(",")) { // 单个时间戳
tsCondition = "ts >= '" + ts + "' AND ts <= '" + new UFDate(new Date()) + "'"; tsCondition = "ts >= '" + adjustedUfDate + "' AND ts <= '" + new UFDate(new Date()) + "'";
} }
} }