/**
* 前端条件查询航班
* @param param 查询条件
* @param page 分页
*/
@Override
public IPage<FlightDTO> getFlight(FlightQueryParam param, Page<Flight> page) {
return flightPage(param,page).convert(this::toFlightDTO);
}
/**
* @param param 查询条件
* @param page 分页
*/
@Override
public IPage<Flight> flightPage(FlightQueryParam param, Page<Flight> page){
return page(page, Wrappers.lambdaQuery(Flight.class)
.eq(StringUtils.isNotEmpty((CharSequence) param.getFlightDate()),Flight::getFlightDate,param.getFlightDate())
.eq(StringUtils.isNotBlank(param.getFlightNumber()),Flight::getFlightNumber,param.getFlightNumber())
.eq(StringUtils.isNotBlank(param.getStartPlace()),Flight::getStartPlace,param.getStartPlace())
.eq(StringUtils.isNotBlank(param.getEndPlace()),Flight::getEndPlace,param.getEndPlace())
.apply(StringUtils.isNotEmpty((CharSequence) param.getDepartStartTime()),
"date_format(start_time,'%Y-%m-%d')>=date_format('"+ param.getDepartStartTime() + "','%Y-%m-%d')")
.apply(StringUtils.isNotEmpty((CharSequence) param.getDepartEndTime()),
"date_format(start_time,'%Y-%m-%d')>=date_format('"+ param.getDepartEndTime() + "','%Y-%m-%d')")
.apply(StringUtils.isNotEmpty((CharSequence) param.getArrivalStartTime()),
"date_format(start_time,'%Y-%m-%d')>=date_format('"+ param.getArrivalStartTime() + "','%Y-%m-%d')")
.apply(StringUtils.isNotEmpty((CharSequence) param.getArrivalEndTime()),
"date_format(start_time,'%Y-%m-%d')>=date_format('"+ param.getArrivalEndTime() + "','%Y-%m-%d')")
.likeRight(StringUtils.isNotBlank(param.getAircraftType()),Flight::getAircraftType,param.getAircraftType())
.orderByAsc(StringUtils.isNotBlank(param.getTakeoffCycle()),Flight::getTakeoffCycle)
.orderByAsc(StringUtils.isNotBlank(param.getFirstMoney()),Flight::getFirstMoney)
.orderByAsc(StringUtils.isNotBlank(param.getBusinessMoney()),Flight::getBusinessMoney)
.orderByAsc(StringUtils.isNotBlank(param.getEconomicMoney()),Flight::getEconomicMoney)
.orderByAsc(StringUtils.isNotBlank((CharSequence) param.getStartTime()),Flight::getStartTime)
.orderByAsc(StringUtils.isNotBlank((CharSequence) param.getEndTime()),Flight::getEndTime)
.orderByDesc(StringUtils.isNotBlank((CharSequence) param.getStartTime()),Flight::getStartTime)
.orderByDesc(StringUtils.isNotBlank((CharSequence) param.getEndTime()),Flight::getEndTime)
.orderByDesc(StringUtils.isNotBlank(param.getTakeoffCycle()),Flight::getTakeoffCycle)
);
}
/**
* 封装为FlightDTO
* @param flight 航班
* @return FlightDTO FlightDTO
*/
private FlightDTO toFlightDTO(Flight flight){
FlightDTO flightDTO=new FlightDTO();
Airline airline = airlineMapper.selectById(flight.getAirlineId());
List<Airport> airports = flightAirportMapper.selectList(new QueryWrapper<FlightAirport>().eq("flight_id", flight.getId()))
.stream()
.map(this::toAirport)
.collect(Collectors.toList());
//将查询出的对象封装为FlightDTO对象
flightDTO.setFlight(flight);
flightDTO.setAirline(airline);
flightDTO.setAirports(airports);
return flightDTO;
}
/**
* 封装Airport
* @param flightAirport 航班机场
*/
private Airport toAirport(FlightAirport flightAirport){
return airportMapper.selectById(flightAirport.getAirportId());
}
mybatis中的时间范围查询&&集合的遍历
于 2022-05-28 19:09:42 首次发布