我正在开发一个Spring-MVC项目,其中Hibernate和DB作为Postgres,其中有可能将任务分配给属于组的个人。
现在任务有结束时间,并且我有一个调度程序正在运行,每隔30分钟检查一次任务是否还剩48小时才能完成,如果是这样,那么我会发送一封电子邮件。
不幸的是,我不能只检查不到48小时,因为我也检查了不到12小时而不是8小时。
所以,我想为什么不检查剩余时间是否在47-48小时之间。而且我不知道如何检查这种情况。
所以,基本上,从当前时间开始,如果行的时间戳为47-48小时,我想要检索该行。 我知道如何检查更多,然后现在是什么,下面是代码。任何人都可以帮助我如何在47-48小时内检查。非常感谢。
代码:
@Override
public List<GroupNotes> findGroupNotesWithExpiryInFortyEightHours() {
int val = 0;
Session session = this.sessionFactory.getCurrentSession();
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
Query query = session.createQuery("from GroupNotes as gn where gn.zugwisenPersonId!=:val and gn.timeToend>:timestamp");
}
非常感谢。
答案 0 :(得分:3)
这个查询应该完成这项工作(虽然它没有经过测试,我这里没有IDE):
long currentTime = System.currentTimeMillis();
long plus47Hours = currentTime + (47 * 60 * 60 * 1000);
Timestamp plus47HoursTS = new Timestamp(plus47Hours);
long plus48Hours = currentTime + (48 * 60 * 60 * 1000);
Timestamp plus48HoursTS = new Timestamp(plus48Hours);
Query query = session.createQuery("from GroupNotes as gn where gn.zugwisenPersonId!=:val and gn.timeToend > :from and gn.timeToend < :to");
query.setParameter("from", plus47HoursTS);
query.setParameter("to", plus48HoursTS);