create table airline(
code varchar(3) not null primary key,
name varchar(20) not null,
discount float(2,2) not null
);
create table airport(
code varchar(4) not null primary key,
name varchar(20) not null,
city varchar(20) not null,
country varchar(20) not null,
connTime int(3) not null /* minute */
);
create table airplane(
name varchar(20) not null primary key,
type varchar(10) not null
);
create table seat(
id int(3) not null primary key auto_increment,
relativeID int(3) not null, /* 飞机上作为的相对编号 */
row int(3) not null,
num int(3) not null,
type varchar(12) not null, /* windowSeat middleSeat aisleSeat*/
flightID int(10) not null, /* Table:airplane Item:id */
passport varchar(20) /* passenger passport */
);
create table flight(
id int(10) not null primary key,
airlineCode varchar(3) not null,
number int(6) not null,
depatureDate Date not null,
depatureTime time not null,
arrivalDate Date not null,
arrivalTime time not null,
fare float(6,2) not null,
depatureAirport varchar(4) not null, /* Table:airport Item:code */
arrivalAirport varchar(4) not null, /* Table:airport Item:code */
airplaneName varchar(20) not null, /* Table:airplane Item:name */
airplaneType varchar(10) not null /* Table:airplane Item:type */
);
use AIRLINE_2;
create table airline(
code varchar(3) not null primary key,
name varchar(20) not null,
discount float(2,2) not null
);
create table airport(
code varchar(4) not null primary key,
name varchar(20) not null,
city varchar(20) not null,
country varchar(20) not null,
connTime int(3) not null /* minute */
);
create table airplane(
name varchar(20) not null primary key,
type varchar(10) not null
);
create table seat(
id int(3) not null primary key auto_increment,
relativeID int(3) not null, /* 飞机上作为的相对编号 */
row int(3) not null,
num int(3) not null,
type varchar(12) not null, /* windowSeat middleSeat aisleSeat*/
flightID int(10) not null, /* Table:airplane Item:id */
passport varchar(20) /* passenger passport */
);
create table flight(
id int(10) not null primary key,
airlineCode varchar(3) not null,
number int(6) not null,
depatureDate Date not null,
depatureTime time not null,
arrivalDate Date not null,
arrivalTime time not null,
fare float(6,2) not null,
depatureAirport varchar(4) not null, /* Table:airport Item:code */
arrivalAirport varchar(4) not null, /* Table:airport Item:code */
airplaneName varchar(20) not null, /* Table:airplane Item:name */
airplaneType varchar(10) not null /* Table:airplane Item:type */
);
use AIRLINE_3;
create table airline(
code varchar(3) not null primary key,
name varchar(20) not null,
discount float(2,2) not null
);
create table airport(
code varchar(4) not null primary key,
name varchar(20) not null,
city varchar(20) not null,
country varchar(20) not null,
connTime int(3) not null /* minute */
);
create table airplane(
name varchar(20) not null primary key,
type varchar(10) not null
);
create table seat(
id int(3) not null primary key auto_increment,
relativeID int(3) not null, /* 飞机上作为的相对编号 */
row int(3) not null,
num int(3) not null,
type varchar(12) not null, /* windowSeat middleSeat aisleSeat*/
flightID int(10) not null, /* Table:airplane Item:id */
passport varchar(20) /* passenger passport */
);
create table flight(
id int(10) not null primary key,
airlineCode varchar(3) not null,
number int(6) not null,
depatureDate Date not null,
depatureTime time not null,
arrivalDate Date not null,
arrivalTime time not null,
fare float(6,2) not null,
depatureAirport varchar(4) not null, /* Table:airport Item:code */
arrivalAirport varchar(4) not null, /* Table:airport Item:code */
airplaneName varchar(20) not null, /* Table:airplane Item:name */
airplaneType varchar(10) not null /* Table:airplane Item:type */
);
/* create table of database ABS*/
use ABS;
create table airline(
code varchar(3) not null primary key,
name varchar(20) not null,
discount float(2,2) not null
);
create table flightInfo(
id int(10) not null primary key auto_increment,
airlineCode varchar(3) not null, /* Table:airline Item:code */
flightID int(10) not null, /* Database:Airline Table:flight Item: */
number int(6) not null, /* Database:Airline Table:flight Item:number */
depatureDate Date not null, /* Database:Airline Table:flight Item:depatureDate */
depatureTime time not null, /* Database:Airline Table:flight Item:depatureTime */
arrivalDate Date not null, /* Database:Airline Table:flight Item:arrivalDate */
arrivalTime time not null, /* Database:Airline Table:flight Item:arrivalTime */
fare float(6,2) not null, /* Database:Airline Table:flight Item:fare */
depatureAirport varchar(4) not null, /* Database:Airline Table:flight Item:depatureAirport */
arrivalAirport varchar(4) not null, /* Database:Airline Table:flight Item:arrivalAirport */
airlineName varchar(20) not null, /* Table:airline Item:name */
airplaneName varchar(20) not null, /* Database:Airline Table:airplane Item:name */
airplaneType varchar(10) not null, /* 大:240 中:160 小:80 */
depatureAirportName varchar(20) not null,
arrivalAirportName varchar(20) not null,
depatureAirportCity varchar(20) not null,
arrivalAirportCity varchar(20) not null,
airplaneEmptySeats int(3) not null /* Database:Airline Table:airplane Item:conunt of empty seats */
);
create table airport(
code varchar(4) not null primary key,
name varchar(20) not null,
city varchar(20) not null,
country varchar(20) not null,
connTime int(3) not null /* minute */
);
create table passenger(
passport varchar(20) not null, /* no primary key for test */
name varchar(20) not null
);
create table trip(
id int(10) not null primary key,
flightInfoID int(10) not null, /* Database:Airline Table:flight Item: */
fare float(6,2) not null, /* fare不同于 flightInfo中的 fare */
passport varchar(20) not null, /* Table:passenger Item:passport */
seatID int(3) not null /* Database:Airline Table:seat Item:relativeID */
);
create table orders(
id int(10) not null, /* id 相同的为同一个订单 */
tripID int(10) not null, /* Table:tirp Item:id */
createDate date not null,
createTime time not null,
totalFare float(6,2) not null,
contactName varchar(20) not null,
contactPhone varchar(20) not null
);
=====================================================================
=====================================================================
package com.abs.action;
import java.sql.Date;
import java.sql.Time;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.*;
import com.abs.db.DBName;
import com.abs.factory.DaoFactory;
import com.abs.model.*;
public class SearchAction {
public static List searchFlightDirectly(String departureCity, String arrivalCity, String departureDateString) throws Exception {
List list = null;
Date departureDate = null;
if (checkDate(departureDateString)) { // 测试Date格式是否合格
departureDate = Date.valueOf(departureDateString);
}
list = DaoFactory.getFlightInfoDaoInstance(DBName.ABS).findByAirport(departureCity, arrivalCity, departureDate);
return list;
}
public static List<List> searchFlightTransfer(String departureCity, String arrivalCity, String departureDateString) throws Exception {
List<List> list = new ArrayList<List>();
Date departureDate = null;
if (checkDate(departureDateString)) { // 测试Date格式是否合格
departureDate = Date.valueOf(departureDateString);
}
List departureList = DaoFactory.getFlightInfoDaoInstance(DBName.ABS).findByDepatureAirport(departureCity, departureDate);
for (FlightInfo depatureFlight : departureList) {
Airport transferAirport = DaoFactory.getAirportDaoInstance(DBName.ABS).findByCode(depatureFlight.getArrivalAirport());
if(null != transferAirport){
int connTime = transferAirport.getConnTime();
Time depatureTime = new Time(depatureFlight.getArrivalTime().getTime() + connTime * 60 * 1000);
String transferCity = depatureFlight.getArrivalAirportCity();
List arrivalList = DaoFactory.getFlightInfoDaoInstance(DBName.ABS).findByTransferArrivalAirport(transferCity, arrivalCity, departureDate, depatureTime);
for (FlightInfo arrivalFlight : arrivalList) {
List item = new ArrayList();
if(depatureFlight.getAirlineCode().equals(arrivalFlight.getAirlineCode())){
double discount = DaoFactory.getAirlineDaoInstance(DBName.ABS).findByCode(depatureFlight.getAirlineCode()).getDiscount();
arrivalFlight.setFare(arrivalFlight.getFare() * discount);
}
item.add(depatureFlight);
item.add(arrivalFlight);
list.add(item);
}
}else {
System.err.println(depatureFlight.getArrivalAirportCity() + depatureFlight.getArrivalAirport() + “:没有找到机场信息”);
}
}
return list;
}
public static boolean checkDate(String date) {
String regex= “^((\d{2}(([02468][048])|([13579][26]))[\-\/\s]?((((0?[13578])|(1[02]))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]?((0?[1-9])|([1-2][0-9])))))|(\d{2}(([02468][1235679])|([13579][01345789]))[\-\/\s]?((((0?[13578])|(1[02]))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))”;
return Pattern.compile(regex).matcher(date).matches();
}
}
package com.abs.action;
import java.sql.Date;
import java.sql.Time;
import java.util.List;
import com.abs.db.DBName;
import com.abs.factory.DaoFactory;
import com.abs.model.Flight;
import com.abs.model.FlightInfo;
import com.abs.model.Orders;
import com.abs.model.Passenger;
import com.abs.model.Seat;
import com.abs.model.Trip;
public class OrderAction {
public static Orders createOrder(List flightInfos, List passengers, String[] seatTypeList, String contactName, String contactPhone) throws Exception {
// 生成订单编号
Orders.addIdCounter();
Orders order = null;
double total = 0;
for (FlightInfo flightInfo : flightInfos) {
total += flightInfo.getFare();
}
total = total * passengers.size(); // 计算总费用
for (Passenger passenger : passengers) {
DaoFactory.getPassengerDaoInstance(DBName.ABS).add(passenger);
}
for (FlightInfo flightInfo : flightInfos) {
for (Passenger passenger : passengers) {
Trip trip = new Trip();
trip.setId(Trip.getIdCounter());
trip.setFlightInfoID(flightInfo.getId());
trip.setFare(flightInfo.getFare());
trip.setPassport(passenger.getPassport());
trip.setSeatID(OrderAction.orderSeat(flightInfo, passenger, seatTypeList[passengers.indexOf(passenger)])); // 分配座位
flightInfo.setAirplaneEmptySeats(flightInfo.getAirplaneEmptySeats() - 1); // 空闲座位数 - 1
DaoFactory.getFlightInfoDaoInstance(DBName.ABS).addPassenger(flightInfo.getId()); // 空闲座位数 - 1
DaoFactory.getTripDaoInstance(DBName.ABS).add(trip);
Orders orders = new Orders();
orders.setId(Orders.getIdCounter()); // 同一个订单号,代表为同一个订单
orders.setTripID(trip.getId()); // 每个Orders item 与一个 Trip 一一对应
java.util.Date date = new java.util.Date();
orders.setCreateDate(new Date(date.getTime()));
orders.setCreateTime(new Time(date.getTime()));
orders.setTotalFare(total);
orders.setContactName(contactName);
orders.setContactPhone(contactPhone);
DaoFactory.getOrdersDaoInstance(DBName.ABS).add(orders);
order = orders; // 返回一个 Orders item用于显示
}
}
return order;
}
public static int orderSeat(FlightInfo flightInfo, Passenger passenger, String seatType) throws Exception {
int seatID = -1;
String airlineCode = flightInfo.getAirlineCode();
Flight flight = null;
// airline_1 MU(东方航空), airline_2 CZ(南方航空), airline_3 CA(中国国航)
if(airlineCode.equals(“MU”)){ // airline_1 MU(东方航空)
flight = DaoFactory.getFlightDaoInstance(DBName.AIRLINE_1).findByID(flightInfo.getFlightID());
List emptySeats = DaoFactory.getSeatDaoInstance(DBName.AIRLINE_1).findEmptySeatByFlightID(flight.getId());
if (emptySeats.size() > 0) {
Seat seat = null;
for (Seat emptySeat : emptySeats) {
if(emptySeat.getType() == seatType){
seat = emptySeat;
break;
}
}
if(seat == null){
seat = emptySeats.get(0);
}
seat.setPassport(passenger.getPassport());
DaoFactory.getSeatDaoInstance(DBName.AIRLINE_1).modify(seat);
seatID = seat.getRelativeID();
}
}else if (airlineCode.equals(“CZ”)) { // airline_2 CZ(南方航空)
flight = DaoFactory.getFlightDaoInstance(DBName.AIRLINE_2).findByID(flightInfo.getFlightID());
List emptySeats = DaoFactory.getSeatDaoInstance(DBName.AIRLINE_2).findEmptySeatByFlightID(flight.getId());
if (emptySeats.size() > 0) {
Seat seat = null;
for (Seat emptySeat : emptySeats) {
if(emptySeat.getType() == seatType){
seat = emptySeat;
}
}
if(seat == null){
seat = emptySeats.get(0);
}
seat.setPassport(passenger.getPassport());
DaoFactory.getSeatDaoInstance(DBName.AIRLINE_2).modify(seat);
seatID = seat.getRelativeID();
}
}else { // airline_3 CA(中国国航)
flight = DaoFactory.getFlightDaoInstance(DBName.AIRLINE_3).findByID(flightInfo.getFlightID());
List emptySeats = DaoFactory.getSeatDaoInstance(DBName.AIRLINE_3).findEmptySeatByFlightID(flight.getId());
if (emptySeats.size() > 0) {
Seat seat = null;
for (Seat emptySeat : emptySeats) {
if(emptySeat.getType() == seatType){
seat = emptySeat;
}
}
if(seat == null){
seat = emptySeats.get(0);
}
seat.setPassport(passenger.getPassport());
DaoFactory.getSeatDaoInstance(DBName.AIRLINE_3).modify(seat);
seatID = seat.getRelativeID();
}
}
return seatID;
}
}
package com.abs.dao.impl;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import com.abs.dao.AirlineDao;
import com.abs.db.DBConnection;
import com.abs.db.DBName;
import com.abs.model.Airline;
public class AirlineDaoImpl implements AirlineDao {
private Connection conn = null;
private PreparedStatement pstmt = null;
public AirlineDaoImpl(Connection conn) {
// TODO Auto-generated constructor stub
this.conn = conn;
}
@Override
public boolean add(Airline airline) throws Exception {
// TODO Auto-generated method stub
String sql = “insert into airline(code, name, discount) values(?,?,?)”;
this.pstmt = this.conn.prepareStatement(sql);
this.pstmt.setString(1, airline.getCode());
this.pstmt.setString(2, airline.getName());
this.pstmt.setDouble(3, airline.getDiscount());
int update = this.pstmt.executeUpdate();
this.pstmt.close();
if(update > 0){
return true;
}else{
return false;
}
}
@Override
public Airline findByCode(String code) throws Exception {
// TODO Auto-generated method stub
String sql = “select * from airline where code=?”;
this.pstmt = this.conn.prepareStatement(sql);
this.pstmt.setString(1, code);
ResultSet resultSet = this.pstmt.executeQuery();
Airline airline = null;
if(resultSet.next()){
airline = new Airline();
airline.setCode(resultSet.getString(1));
airline.setName(resultSet.getString(2));
airline.setDiscount(resultSet.getDouble(3));
}
this.pstmt.close();
return airline;
}
@Override
public List findAll() throws Exception {
// TODO Auto-generated method stub
String sql = “select * from airline”;
this.pstmt = this.conn.prepareStatement(sql);
ResultSet resultSet = this.pstmt.executeQuery();
List list = new ArrayList<>();
Airline airline = null;
while(resultSet.next()){
airline = new Airline();
airline.setCode(resultSet.getString(1));
airline.setName(resultSet.getString(2));
airline.setDiscount(resultSet.getDouble(3));
list.add(airline);
}
this.pstmt.close();
return list;
}
public static void main(String args[]) throws Exception {
Airline airline = new Airline();
airline.setCode(“MU”);
airline.setName(“东方航空”);
airline.setDiscount(0.9);
new AirlineDaoImpl(new DBConnection().getConnection(DBName.AIRLINE_1)).add(airline);
}
}
package com.abs.dao.impl;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.sql.*;
import java.util.List;
import com.abs.dao.FlightDao;
import com.abs.db.DBName;
import com.abs.factory.DaoFactory;
import com.abs.model.Flight;
public class FlightDaoImpl implements FlightDao {
private Connection conn = null;
private PreparedStatement pstmt = null;
public FlightDaoImpl(Connection conn) {
// TODO Auto-generated constructor stub
this.conn = conn;
}
@Override
public boolean add(Flight flight) throws Exception {
// TODO Auto-generated method stub
String sql = "insert into flight(id, airlineCode, number, depatureDate, depatureTime, arrivalDate, arrivalTime, fare, "
- “depatureAirport, arrivalAirport, airplaneName, airplaneType) values(?,?,?,?,?,?,?,?,?,?,?,?)”;
this.pstmt = this.conn.prepareStatement(sql);
this.pstmt.setInt(1, flight.getId());
this.pstmt.setString(2, flight.getAirlineCode());
this.pstmt.setInt(3, flight.getNumber());
this.pstmt.setDate(4, flight.getDepatureDate());
this.pstmt.setTime(5, flight.getDepatureTime());
this.pstmt.setDate(6, flight.getArrivalDate());
this.pstmt.setTime(7, flight.getArrivalTime());
this.pstmt.setDouble(8, flight.getFare());
this.pstmt.setString(9, flight.getDepatureAirport());
this.pstmt.setString(10, flight.getArrivalAirport());
this.pstmt.setString(11, flight.getAirplaneName());
this.pstmt.setString(12, flight.getAirplaneType());
int update = this.pstmt.executeUpdate();
this.pstmt.close();
if(update > 0){
return true;
}else {
return false;
}
}
@Override
public Flight findByID(int id) throws Exception {
// TODO Auto-generated method stub
String sql = “select * from flight where id=?”;
this.pstmt = this.conn.prepareStatement(sql);
this.pstmt.setInt(1, id);
ResultSet resultSet = this.pstmt.executeQuery();
Flight flight = null;
if(resultSet.next()){
flight = new Flight();
flight.setId(resultSet.getInt(1));
flight.setAirlineCode(resultSet.getString(2));
flight.setNumber(resultSet.getInt(3));
flight.setDepatureDate(resultSet.getDate(4));
flight.setDepatureTime(resultSet.getTime(5));
flight.setArrivalDate(resultSet.getDate(6));
flight.setArrivalTime(resultSet.getTime(7));
flight.setFare(resultSet.getDouble(8));
flight.setDepatureAirport(resultSet.getString(9));
flight.setArrivalAirport(resultSet.getString(10));
flight.setAirplaneName(resultSet.getString(11));
flight.setAirplaneType(resultSet.getString(12));
}
this.pstmt.close();
return flight;
}
@Override
public List findAll() throws Exception {
// TODO Auto-generated method stub
String sql = “select * from flight”;
this.pstmt = this.conn.prepareStatement(sql);
ResultSet resultSet = this.pstmt.executeQuery();
List list = new ArrayList<>();
Flight flight = null;
while(resultSet.next()){
flight = new Flight();
flight.setId(resultSet.getInt(1));
flight.setAirlineCode(resultSet.getString(2));
flight.setNumber(resultSet.getInt(3));
flight.setDepatureDate(resultSet.getDate(4));
flight.setDepatureTime(resultSet.getTime(5));
flight.setArrivalDate(resultSet.getDate(6));
flight.setArrivalTime(resultSet.getTime(7));
flight.setFare(resultSet.getDouble(8));
flight.setDepatureAirport(resultSet.getString(9));
flight.setArrivalAirport(resultSet.getString(10));
flight.setAirplaneName(resultSet.getString(11));
flight.setAirplaneType(resultSet.getString(12));
}
this.pstmt.close();
return list;
}
public static void main(String agrs[]) throws Exception {
Flight flight = new Flight();
flight.setNumber(123);
flight.setDepatureDate(new Date(new java.util.Date().getTime()));
flight.setDepatureTime(new Time(new java.util.Date().getTime()));
flight.setArrivalDate(new Date(new java.util.Date().getTime()));
flight.setArrivalTime(new Time(new java.util.Date().getTime()));
flight.setFare(599.0);
flight.setDepatureAirport(“ecb”);
flight.setArrivalAirport(“abc”);
flight.setAirplaneName(“空客A320”);
flight.setAirplaneType(“中”);
DaoFactory.getFlightDaoInstance(DBName.AIRLINE_1).add(flight);
}
}
package com.abs.dao.impl;
import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Time;
import java.util.ArrayList;
import java.util.List;
import com.abs.dao.FlightInfoDao;
import com.abs.db.DBName;
import com.abs.factory.DaoFactory;
import com.abs.model.FlightInfo;
public class FlightInfoDaoImpl implements FlightInfoDao {
private Connection conn = null;
private PreparedStatement pstmt = null;
public FlightInfoDaoImpl(Connection conn) {
// TODO Auto-generated constructor stub
this.conn = conn;
}
@Override
public boolean add(FlightInfo flightInfo) throws Exception {
// TODO Auto-generated method stub
String sql = "insert into flightInfo(airlineCode, flightID, number, "
-
“depatureDate, depatureTime, arrivalDate, arrivalTime,”
-
“fare, depatureAirport, arrivalAirport, airlineName, airplaneName,”
-
"airplaneType, depatureAirportName, arrivalAirportName, depatureAirportCity, arrivalAirportCity, airplaneEmptySeats) "
-
“values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)”;
this.pstmt = this.conn.prepareStatement(sql);
this.pstmt.setString(1, flightInfo.getAirlineCode());
this.pstmt.setInt(2, flightInfo.getFlightID());
this.pstmt.setInt(3, flightInfo.getNumber());
this.pstmt.setDate(4, flightInfo.getDepatureDate());
this.pstmt.setTime(5, flightInfo.getDepatureTime());
this.pstmt.setDate(6, flightInfo.getArrivalDate());
this.pstmt.setTime(7, flightInfo.getArrivalTime());
this.pstmt.setDouble(8, flightInfo.getFare());
this.pstmt.setString(9, flightInfo.getDepatureAirport());
this.pstmt.setString(10, flightInfo.getArrivalAirport());
this.pstmt.setString(11, flightInfo.getAirlineName());
this.pstmt.setString(12, flightInfo.getAirplaneName());
this.pstmt.setString(13, flightInfo.getAirplaneType());
this.pstmt.setString(14, flightInfo.getDepatureAirportName());
this.pstmt.setString(15, flightInfo.getArrivalAirportName());
this.pstmt.setString(16, flightInfo.getDepatureAirportCity());
this.pstmt.setString(17, flightInfo.getArrivalAirportCity());
this.pstmt.setInt(18, flightInfo.getAirplaneEmptySeats());
int update = this.pstmt.executeUpdate();
this.pstmt.close();
if(update > 0){
return true;
}else {
return false;
}
}
@Override
public FlightInfo findByID(int id) throws Exception {
// TODO Auto-generated method stub
String sql = “select * from flightInfo where id=?”;
this.pstmt = this.conn.prepareStatement(sql);
this.pstmt.setInt(1, id);
ResultSet resultSet = this.pstmt.executeQuery();
FlightInfo flightInfo = null;
if(resultSet.next()){
flightInfo = new FlightInfo();
flightInfo.setId(resultSet.getInt(1));
flightInfo.setAirlineCode(resultSet.getString(2));
flightInfo.setFlightID(resultSet.getInt(3));
flightInfo.setNumber(resultSet.getInt(4));
flightInfo.setDepatureDate(resultSet.getDate(5));
flightInfo.setDepatureTime(resultSet.getTime(6));
flightInfo.setArrivalDate(resultSet.getDate(7));
flightInfo.setArrivalTime(resultSet.getTime(8));
flightInfo.setFare(resultSet.getDouble(9));
flightInfo.setDepatureAirport(resultSet.getString(10));
flightInfo.setArrivalAirport(resultSet.getString(11));
flightInfo.setAirlineName(resultSet.getString(12));
flightInfo.setAirplaneName(resultSet.getString(13));
flightInfo.setAirplaneType(resultSet.getString(14));
flightInfo.setDepatureAirportName(resultSet.getString(15));
flightInfo.setArrivalAirportName(resultSet.getString(16));
flightInfo.setDepatureAirportCity(resultSet.getString(17));
flightInfo.setArrivalAirportCity(resultSet.getString(18));
flightInfo.setAirplaneEmptySeats(resultSet.getInt(19));
}
this.pstmt.close();
return flightInfo;
}
@Override
public List findByAirport(String depatureAirportCity, String arrivalAirportCity, Date depatureDate) throws Exception {
// TODO Auto-generated method stub
String sql = “select * from flightInfo where depatureAirportCity=? and arrivalAirportCity=? and depatureDate=?”;
this.pstmt = this.conn.prepareStatement(sql);
this.pstmt.setString(1, depatureAirportCity);
this.pstmt.setString(2, arrivalAirportCity);
this.pstmt.setDate(3, depatureDate);
ResultSet resultSet = this.pstmt.executeQuery();
List list = new ArrayList<>();
FlightInfo flightInfo = null;
while(resultSet.next()){
flightInfo = new FlightInfo();
flightInfo.setId(resultSet.getInt(1));
flightInfo.setAirlineCode(resultSet.getString(2));
flightInfo.setFlightID(resultSet.getInt(3));
flightInfo.setNumber(resultSet.getInt(4));
flightInfo.setDepatureDate(resultSet.getDate(5));
flightInfo.setDepatureTime(resultSet.getTime(6));
flightInfo.setArrivalDate(resultSet.getDate(7));
flightInfo.setArrivalTime(resultSet.getTime(8));
flightInfo.setFare(resultSet.getDouble(9));
flightInfo.setDepatureAirport(resultSet.getString(10));
flightInfo.setArrivalAirport(resultSet.getString(11));
flightInfo.setAirlineName(resultSet.getString(12));
flightInfo.setAirplaneName(resultSet.getString(13));
flightInfo.setAirplaneType(resultSet.getString(14));
flightInfo.setDepatureAirportName(resultSet.getString(15));
flightInfo.setArrivalAirportName(resultSet.getString(16));
flightInfo.setDepatureAirportCity(resultSet.getString(17));
flightInfo.setArrivalAirportCity(resultSet.getString(18));
flightInfo.setAirplaneEmptySeats(resultSet.getInt(19));
list.add(flightInfo);
}
this.pstmt.close();
return list;
}
@Override
public List findByDepatureAirport(String depatureAirportCity, Date depatureDate) throws Exception {
// TODO Auto-generated method stub
String sql = “select * from flightInfo where depatureAirportCity=? and depatureDate=?”;
this.pstmt = this.conn.prepareStatement(sql);
this.pstmt.setString(1, depatureAirportCity);
this.pstmt.setDate(2, depatureDate);
ResultSet resultSet = this.pstmt.executeQuery();
List list = new ArrayList<>();
FlightInfo flightInfo = null;
while(resultSet.next()){
flightInfo = new FlightInfo();
flightInfo.setId(resultSet.getInt(1));
flightInfo.setAirlineCode(resultSet.getString(2));
flightInfo.setFlightID(resultSet.getInt(3));
flightInfo.setNumber(resultSet.getInt(4));
flightInfo.setDepatureDate(resultSet.getDate(5));
flightInfo.setDepatureTime(resultSet.getTime(6));
flightInfo.setArrivalDate(resultSet.getDate(7));
flightInfo.setArrivalTime(resultSet.getTime(8));
flightInfo.setFare(resultSet.getDouble(9));
flightInfo.setDepatureAirport(resultSet.getString(10));
flightInfo.setArrivalAirport(resultSet.getString(11));
flightInfo.setAirlineName(resultSet.getString(12));
flightInfo.setAirplaneName(resultSet.getString(13));
flightInfo.setAirplaneType(resultSet.getString(14));
flightInfo.setDepatureAirportName(resultSet.getString(15));
flightInfo.setArrivalAirportName(resultSet.getString(16));
flightInfo.setDepatureAirportCity(resultSet.getString(17));
flightInfo.setArrivalAirportCity(resultSet.getString(18));
flightInfo.setAirplaneEmptySeats(resultSet.getInt(19));
list.add(flightInfo);
}
this.pstmt.close();
return list;
}
@Override
public List findByTransferArrivalAirport(String depatureAirportCity, String arrivalAirportCity, Date depatureDate, Time depatureTime) throws Exception {
// TODO Auto-generated method stub
String sql = “select * from flightInfo where depatureAirportCity=? and arrivalAirportCity=? and depatureDate>=? and depatureTime>=?”;
this.pstmt = this.conn.prepareStatement(sql);
this.pstmt.setString(1, depatureAirportCity);
this.pstmt.setString(2, arrivalAirportCity);
this.pstmt.setDate(3, depatureDate);
this.pstmt.setTime(4, depatureTime);
ResultSet resultSet = this.pstmt.executeQuery();
List list = new ArrayList<>();
FlightInfo flightInfo = null;
while(resultSet.next()){
flightInfo = new FlightInfo();
flightInfo.setId(resultSet.getInt(1));
flightInfo.setAirlineCode(resultSet.getString(2));
flightInfo.setFlightID(resultSet.getInt(3));
flightInfo.setNumber(resultSet.getInt(4));
flightInfo.setDepatureDate(resultSet.getDate(5));
flightInfo.setDepatureTime(resultSet.getTime(6));
flightInfo.setArrivalDate(resultSet.getDate(7));
flightInfo.setArrivalTime(resultSet.getTime(8));
flightInfo.setFare(resultSet.getDouble(9));
flightInfo.setDepatureAirport(resultSet.getString(10));
flightInfo.setArrivalAirport(resultSet.getString(11));
flightInfo.setAirlineName(resultSet.getString(12));
flightInfo.setAirplaneName(resultSet.getString(13));
flightInfo.setAirplaneType(resultSet.getString(14));
flightInfo.setDepatureAirportName(resultSet.getString(15));
flightInfo.setArrivalAirportName(resultSet.getString(16));
flightInfo.setDepatureAirportCity(resultSet.getString(17));
flightInfo.setArrivalAirportCity(resultSet.getString(18));
flightInfo.setAirplaneEmptySeats(resultSet.getInt(19));
list.add(flightInfo);
}
this.pstmt.close();
return list;
}
@Override
public int addPassenger(int id) throws Exception {
// TODO Auto-generated method stub
String sql = “select airplaneEmptySeats from flightInfo where id=?”;
this.pstmt = this.conn.prepareStatement(sql);
this.pstmt.setInt(1, id);
ResultSet resultSet = this.pstmt.executeQuery();
int emptySeats = 0;
if(resultSet.next()){
emptySeats = resultSet.getInt(1);
}
emptySeats–;
sql = “update flightInfo set airplaneEmptySeats=? where id=?”;
this.pstmt = this.conn.prepareStatement(sql);
this.pstmt.setInt(1, emptySeats);
this.pstmt.setInt(2, id);
this.pstmt.executeUpdate();
this.pstmt.close();
return emptySeats;
}
}
package com.abs.servlet;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.abs.db.DBName;
import com.abs.factory.DaoFactory;
import com.abs.model.FlightInfo;
public class BookingServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding(“utf-8”);
String[] fIDList = request.getParameterValues(“flightInfoID”);
List flightInfoList = new ArrayList();
try {
for (String idString : fIDList) {
FlightInfo flightInfo = DaoFactory.getFlightInfoDaoInstance(DBName.ABS).findByID(Integer.parseInt(idString));
if(null != flightInfo){
flightInfoList.add(flightInfo);
}
}
// discount of same airline
if(flightInfoList.size() == 2){
FlightInfo f1 = flightInfoList.get(0);
FlightInfo f2 = flightInfoList.get(1);
if(f1.getAirlineCode().equals(f2.getAirlineCode())){
double discount = DaoFactory.getAirlineDaoInstance(DBName.ABS).findByCode(f1.getAirlineCode()).getDiscount();
f2.setFare(f2.getFare() * discount);
}
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
request.setAttribute(“flightInfoList”, flightInfoList);
request.getRequestDispatcher(“/booking.jsp”).forward(request,response);
}
}
package com.abs.servlet;
import java.io.IOException;
import java.sql.Date;
import java.sql.Time;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.abs.action.SearchAction;
import com.abs.model.FlightInfo;
public class SearchServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding(“utf-8”);
String departureCity = request.getParameter(“departureCity”);
String arrivalCity = request.getParameter(“arrivalCity”);
String departureDate = request.getParameter(“departureDate”);
//String returnDate = request.getParameter(“returnDate”);
request.setAttribute(“currentDepartureCity”, departureCity);
request.setAttribute(“currentArrivalCity”, arrivalCity);
request.setAttribute(“currentDepartureDate”, departureDate);
//request.setAttribute(“currentReturnDate”, returnDate);
List list = null;
List<List> transferList = null;
// directly flight
try {
list = SearchAction.searchFlightDirectly(departureCity, arrivalCity, departureDate);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(list.size() > 0){
Collections.sort(list,new Comparator(){
@Override
public int compare(FlightInfo o1, FlightInfo o2) {
// TODO Auto-generated method stub
return o1.getDepatureTime().compareTo(o2.getDepatureTime());
}});
request.setAttribute(“list”, list);
}else {
// transfer flight
try {
transferList = SearchAction.searchFlightTransfer(departureCity, arrivalCity, departureDate);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(transferList.size() > 0){
Collections.sort(transferList,new Comparator<List>(){
@Override
public int compare(List o1, List o2) {
// TODO Auto-generated method stub
return o1.get(0).getDepatureTime().compareTo(o2.get(0).getDepatureTime());
}});
request.setAttribute(“transferList”, transferList);
}else{
// 显示没有结果
request.setAttribute(“noResult”, “noResult”);
}
// ******* test only ******** transfer path
for (List list2 : transferList) {
for (FlightInfo flightInfo : list2) {
System.out.println(flightInfo.getDepatureAirportCity() + " " + flightInfo.getArrivalAirportCity());
}
System.out.println(“***********************”);
}
}
request.getRequestDispatcher(“/resultList.jsp”).forward(request,response);
}
}
package com.abs.service;
import java.util.List;
import com.abs.dao.AirlineDao;
import com.abs.dao.impl.AirlineDaoImpl;
import com.abs.db.DBConnection;
import com.abs.db.DBName;
import com.abs.model.Airline;
public class AirlineService implements AirlineDao {
private DBConnection dbconn = null;
private AirlineDao AirlineDao = null;
private AirlineDao ABSDao = null;
public AirlineService(DBName dbName) throws Exception {
// TODO Auto-generated constructor stub
this.dbconn = new DBConnection();
this.AirlineDao = new AirlineDaoImpl(dbconn.getConnection(dbName));
this.ABSDao = new AirlineDaoImpl(dbconn.getConnection(DBName.ABS));
}
@Override
public boolean add(Airline airline) throws Exception {
// TODO Auto-generated method stub
boolean airlineFlag = false;
boolean ABSFlag = false;
try {
airlineFlag = this.AirlineDao.add(airline);
ABSFlag = this.ABSDao.add(airline);
} catch (Exception e) {
// TODO: handle exception
throw e;
}finally {
this.dbconn.closeAll();
}
return (airlineFlag && ABSFlag);
}
@Override
public Airline findByCode(String code) throws Exception {
// TODO Auto-generated method stub
Airline airline = null;
try {
airline = this.ABSDao.findByCode(code);
} catch (Exception e) {
// TODO: handle exception
throw e;
}finally {
this.dbconn.closeAll();
}
return airline;
}
@Override
public List findAll() throws Exception {
// TODO Auto-generated method stub
List list = null;
try {
list = this.ABSDao.findAll();
} catch (Exception e) {
// TODO: handle exception
throw e;
}finally {
this.dbconn.closeAll();
}
return list;
}
}
package com.abs.service;
import java.sql.Date;
import java.sql.Time;
import java.util.List;
import com.abs.dao.FlightInfoDao;
import com.abs.dao.impl.FlightInfoDaoImpl;
import com.abs.db.DBConnection;
import com.abs.db.DBName;
import com.abs.model.FlightInfo;
public class FlightInfoService implements FlightInfoDao {
private DBConnection dbconn = null;
private FlightInfoDao dao = null;
public FlightInfoService(DBName dbName) throws Exception {
// TODO Auto-generated constructor stub
this.dbconn = new DBConnection();
this.dao = new FlightInfoDaoImpl(dbconn.getConnection(dbName));
}
@Override
public boolean add(FlightInfo flightInfo) throws Exception {
// TODO Auto-generated method stub
boolean flag = false;
try {
flag = this.dao.add(flightInfo);
} catch (Exception e) {
// TODO: handle exception
throw e;
}finally {
this.dbconn.closeAll();
}
return flag;
}
@Override
public FlightInfo findByID(int id) throws Exception {
// TODO Auto-generated method stub
FlightInfo flightInfo = null;
try {
flightInfo = this.dao.findByID(id);
} catch (Exception e) {
// TODO: handle exception
throw e;
}finally {
this.dbconn.closeAll();
}
return flightInfo;
}
@Override
public List findByAirport(String depatureAirportCity, String arrivalAirportCity, Date depatureDate) throws Exception {
// TODO Auto-generated method stub
List list = null;
try {
list = this.dao.findByAirport(depatureAirportCity, arrivalAirportCity, depatureDate);
} catch (Exception e) {
// TODO: handle exception
throw e;
}finally {
this.dbconn.closeAll();
}
return list;
}
@Override
public List findByDepatureAirport(String depatureAirportCity, Date depatureDate) throws Exception {
// TODO Auto-generated method stub
List list = null;
try {
list = this.dao.findByDepatureAirport(depatureAirportCity, depatureDate);
} catch (Exception e) {
// TODO: handle exception
throw e;
}finally {
this.dbconn.closeAll();
}
return list;
}
@Override
public List findByTransferArrivalAirport(String depatureAirportCity, String arrivalAirportCity, Date depatureDate, Time depatureTime) throws Exception {
// TODO Auto-generated method stub
List list = null;
try {
list = this.dao.findByTransferArrivalAirport(depatureAirportCity, arrivalAirportCity, depatureDate,depatureTime);
} catch (Exception e) {
// TODO: handle exception
throw e;
}finally {
this.dbconn.closeAll();
}
return list;
}
@Override
public int addPassenger(int id) throws Exception {
// TODO Auto-generated method stub
int emptySeats = -1;
try {
emptySeats = this.dao.addPassenger(id);
} catch (Exception e) {
// TODO: handle exception
throw e;
}finally {
this.dbconn.closeAll();
}
return emptySeats;
}
}
<%@ page language=“java” contentType=“text/html; charset=UTF-8”
pageEncoding=“UTF-8”%>
<%@ taglib prefix=“c” uri=“http://java.sun.com/jsp/jstl/core”%>
<%@ taglib prefix=“fn” uri=“http://java.sun.com/jsp/jstl/functions”%>
<%@ taglib prefix=“fmt” uri=“http://java.sun.com/jsp/jstl/fmt” %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+“😕/”+request.getServerName()+“:”+request.getServerPort()+path+“/”;
%>
乘客
1
姓 名:
护 照:
座位偏好:
默认
靠窗
中间
靠过道
删除

<c:forEach items=“${flightInfoList}” var=“flightInfo”>
¥
<fmt:formatNumber type=“number” groupingUsed=“false” value=“${flightInfo.fare}” />
</c:forEach>
+ 添加乘客
联系人
姓 名:
手机号:
<c:forEach items=“${flightInfoList}” var=“flightInfo”>
</c:forEach>
<c:set var=“totalFare” value=“0”/>
<c:forEach items=“${flightInfoList}” var=“flightInfo”>
<fmt:formatDate value=“${flightInfo.depatureDate}” type=“both” pattern=“MM-dd”/>
${flightInfo.depatureAirportCity}

${flightInfo.arrivalAirportCity}
${flightInfo.airlineName} f l i g h t I n f o . a i r l i n e C o d e {flightInfo.airlineCode} flightInfo.airlineCode{flightInfo.number}
${flightInfo.airplaneName}
<fmt:formatDate value=“${flightInfo.depatureTime}” type=“both” pattern=“HH:mm”/>

<fmt:formatDate value=“${flightInfo.arrivalTime}” type=“both” pattern=“HH:mm”/>
${flightInfo.depatureAirportName}

${flightInfo.arrivalAirportName}
</c:forEach>
<c:forEach items=“${flightInfoList}” var=“flightInfo”>
机票
最后
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数初中级Android工程师,想要提升技能,往往是自己摸索成长,自己不成体系的自学效果低效漫长且无助。
因此收集整理了一份《2024年Web前端开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点!不论你是刚入门Android开发的新手,还是希望在技术上不断提升的资深开发者,这些资料都将为你打开新的学习之门!
如果你觉得这些内容对你有帮助,需要这份全套学习资料的朋友可以戳我获取!!
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!
">
姓 名:
手机号:
<c:forEach items=“${flightInfoList}” var=“flightInfo”>
</c:forEach>
<c:set var=“totalFare” value=“0”/>
<c:forEach items=“${flightInfoList}” var=“flightInfo”>
<fmt:formatDate value=“${flightInfo.depatureDate}” type=“both” pattern=“MM-dd”/>
${flightInfo.depatureAirportCity}

${flightInfo.arrivalAirportCity}
${flightInfo.airlineName} f l i g h t I n f o . a i r l i n e C o d e {flightInfo.airlineCode} flightInfo.airlineCode{flightInfo.number}
${flightInfo.airplaneName}
<fmt:formatDate value=“${flightInfo.depatureTime}” type=“both” pattern=“HH:mm”/>

<fmt:formatDate value=“${flightInfo.arrivalTime}” type=“both” pattern=“HH:mm”/>
${flightInfo.depatureAirportName}

${flightInfo.arrivalAirportName}
</c:forEach>
<c:forEach items=“${flightInfoList}” var=“flightInfo”>
机票
最后
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数初中级Android工程师,想要提升技能,往往是自己摸索成长,自己不成体系的自学效果低效漫长且无助。
因此收集整理了一份《2024年Web前端开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
[外链图片转存中…(img-pkOZgIHG-1715531518039)]
[外链图片转存中…(img-NjsWHXCG-1715531518039)]
[外链图片转存中…(img-YudJ7gni-1715531518039)]
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点!不论你是刚入门Android开发的新手,还是希望在技术上不断提升的资深开发者,这些资料都将为你打开新的学习之门!
如果你觉得这些内容对你有帮助,需要这份全套学习资料的朋友可以戳我获取!!
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!