获取日期范围内的记录

时间:2019-05-29 16:36:00

标签: java spring-boot jpa spring-data-jpa

这是我的模特

public class FlightSchedule {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column(name = "takeoff_date")
    private LocalDateTime takeoffDate;

    @ManyToOne
    @JsonIgnoreProperties("airportTakeoff")
    private Airports airportTakeoff;

    @ManyToOne
    @JsonIgnoreProperties("airportArrival")
    private Airports airportArrival;

}

这是我的存储库:

public List<FlightSchedule> findByAirportTakeoff_idAndAirportArrival_idAndTakeoffDateGreaterThanEqualAndTakeoffDateLessThan(
        String airportTakeoff, String airportArrival, LocalDateTime arrivalDate, LocalDateTime arrivalDate2);

这是我的服务:

LocalDateTime takeoffLocalDate =
            Instant.ofEpochMilli(takeoffDate).atZone(ZoneId.systemDefault()).toLocalDateTime();
    LocalDateTime takeoffLocalDate2 =
            Instant.ofEpochMilli(takeoffDate).atZone(ZoneId.systemDefault()).toLocalDateTime().plusDays(1);


    return flightScheduleRepository.findByAirportTakeoff_idAndAirportArrival_idAndTakeoffDateGreaterThanEqualAndTakeoffDateLessThan(
            airportTakeoff, airportArrival, takeoffLocalDate, takeoffLocalDate2)
            .stream().map(flightScheduleMapper::toDto)
            .collect(Collectors.toCollection(LinkedList::new));

这些是我的记录:

1   2019-05-28 17:00:00 TGU   MAD

6   2019-05-28 23:00:00 TGU   MAD

但是,当通过以下方式发出请求时:

/flight-schedules/optional/1558994400000/TGU/MAD

1558994400000 = 28 May 2019

我应该同时获得两个功能。我已通知我每天21:00小时后仍无法搭乘航班。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

LocalDateTime.of(2019,5,28,0,0,0).toInstant(ZoneOffset.UTC).toEpochMilli();

这给了我一个1559001600000的长值,这与你的毫秒不同。因此,问题可能出在您的毫秒值上,与UTC时区相差3个小时。