Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HuangHong #108

Merged
merged 6 commits into from
May 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public void backButtonClick() {

/**
* The code for other pages to open AdminLogin.fxml
*
* @param stage
* @throws IOException
*/
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/com/app/flight/controller/HelpController.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,14 @@ public void backButton(ActionEvent actionEvent) {
inputNumberController.next.setDisable(inputNumberController.number.getText().length() <= 0);
});
if (inputNumberController.type.equals("id")) {
inputNumberController.annotation.setText("--> Please input your ID number:");
inputNumberController.annotation.setText("--> Please input your ID number and surname:");
inputNumberController.numLabel.setText("ID Number:");
inputNumberController.nameLabel.setText("Surname:");
} else if (inputNumberController.type.equals("booking")) {
inputNumberController.annotation.setText("--> Please input your booking number:");
inputNumberController.nameClean.setVisible(false);
inputNumberController.nameClean.setVisible(false);
inputNumberController.surName.setVisible(false);
}
}
case "PaymentController" -> {
Expand Down
40 changes: 27 additions & 13 deletions src/main/java/com/app/flight/controller/InputNumberController.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,46 +33,55 @@ public class InputNumberController {
public Button help;
public Button back;

public Button numClean;
public Button nameClean;
public Label nameLabel;
public Label numLabel;
public TextField surName;

public Label attention;

protected String type;
GetPassenger getPassenger = new GetPassengerImpl();

public void submit(ActionEvent actionEvent) {
p = getPassengerInfo(type, number.getText());
p = getPassengerInfo(type, number.getText(), surName.getText());
System.out.println(p);
Platform.runLater(() -> {
Stage stage = (Stage) clean.getScene().getWindow();
try {
FXMLLoader fxmlLoader;
if (p != null) {
fxmlLoader = new InfoConfirmController().getLoader();
} else {
fxmlLoader = new ComingSoonController().getLoader();
}
stage.setScene(new Scene(fxmlLoader.load(), 1200, 800));
if (p != null) {
stage.setScene(new Scene(fxmlLoader.load(), 1200, 800));
InfoConfirmController i = fxmlLoader.getController();
i.showNum(p);
i.pRetrieve = p;
} else {
number.setText("");
surName.setText("");
next.setDisable(true);
}

} catch (IOException e) {
e.printStackTrace();
}
});
}

protected Passenger getPassengerInfo(String type, String text) {
protected Passenger getPassengerInfo(String type, String id, String name) {
Passenger passenger;
if (type.equals("id") && (Validator.idValidator(text) || text.equals("123456"))) {
passenger = getPassenger.lookupPassengerById(text);
} else if (type.equals("booking") && Validator.reservationIdValidator(text)) {
passenger = getPassenger.lookupPassengerByBookingNumber(text);
if (type.equals("id") && (Validator.idValidator(id) || id.equals("123456"))) {
passenger = getPassenger.lookupPassengerById(id);
if (passenger == null) {
attention.setText("Passenger not found.");
} else if (!passenger.getLastName().equals(name)) {
attention.setText("Surname doesn't match the ID number.");
passenger = null;
}
} else if (type.equals("booking") && Validator.reservationIdValidator(id)) {
passenger = getPassenger.lookupPassengerByBookingNumber(id);
} else {
//TODO:页面提示输入错误
attention.setText("Invalid number.");
passenger = null;
}
return passenger;
Expand All @@ -95,6 +104,11 @@ public void clean(ActionEvent actionEvent) {
next.setDisable(true);
}

public void nameClean(ActionEvent actionEvent) {
surName.setText("");
next.setDisable(true);
}

public FXMLLoader getLoader() {
return new FXMLLoader(Main.class.getResource("fxml/InputNumber.fxml"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.app.flight.entity.Passenger;
import com.app.flight.service.GetPassenger;
import com.app.flight.service.impl.GetPassengerImpl;
import com.app.flight.util.Validator;
import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
Expand All @@ -16,6 +15,8 @@

import java.io.IOException;

import static cn.hutool.core.util.IdcardUtil.isValidCard;


/**
* @author LianJunhong
Expand All @@ -31,7 +32,7 @@ public FXMLLoader getLoader() {
}

public void checkIdNumber(String idNumber, Stage stage) {
if (Validator.idValidator(idNumber) || idNumber.equals("123456")) {
if (isValidCard(idNumber) || idNumber.equals("123456")) {
GetPassenger getPassenger = new GetPassengerImpl();
Passenger passenger = getPassenger.lookupPassengerById(idNumber);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,20 @@ public void nextClick(ActionEvent actionEvent) {
inputNumberController.type = (String) method.getSelectedToggle().getUserData();
inputNumberController.next.setDisable(true);
inputNumberController.number.textProperty().addListener(changeListener -> {
inputNumberController.next.setDisable(inputNumberController.number.getText().length() <= 0);
inputNumberController.next.setDisable((inputNumberController.number.getText().length() <= 0) || (inputNumberController.surName.getText().length() <= 0));
});
inputNumberController.surName.textProperty().addListener(changeListener -> {
inputNumberController.next.setDisable((inputNumberController.number.getText().length() <= 0) || (inputNumberController.surName.getText().length() <= 0));
});
if (inputNumberController.type.equals("id")) {
inputNumberController.annotation.setText("--> Please input your Surname and ID number:");
inputNumberController.annotation.setText("--> Please input your ID number and surname:");
inputNumberController.numLabel.setText("ID Number:");
inputNumberController.nameLabel.setText("Surname:");

} else if (inputNumberController.type.equals("booking")) {
inputNumberController.annotation.setText("--> Please input your booking number:");
inputNumberController.numClean.setVisible(false);
inputNumberController.numClean.setVisible(false);
inputNumberController.nameClean.setVisible(false);
inputNumberController.nameClean.setVisible(false);
inputNumberController.surName.setVisible(false);
}
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,18 @@
*/
public class SelectSeatController {

private final int firstClassLimit = Seat.FIRST_CLASS.getRow();
private final int businessClassLimit = Seat.BUSINESS_CLASS.getRow();
@FXML
public ChoiceBox<String> seat;

@FXML
public Button help;

@FXML
public Button next;

@FXML
public GridPane gridPane;

public Button choiceButton;
private final int firstClassLimit = Seat.FIRST_CLASS.getRow();

public int choiceRow;
private final int businessClassLimit = Seat.BUSINESS_CLASS.getRow();

public String choiceColumn;

public double choicePrice;
Expand Down
128 changes: 14 additions & 114 deletions src/main/java/com/app/flight/util/Validator.java
Original file line number Diff line number Diff line change
@@ -1,133 +1,29 @@
package com.app.flight.util;

import java.text.SimpleDateFormat;
import cn.hutool.core.util.IdcardUtil;

import java.time.LocalDateTime;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
* @author JiaBoran
* @version 1.0
* @date 2022.5.5
*/
public class Validator {
final static Map<Integer, String> zoneNum = new HashMap<Integer, String>();
final static int[] PARITY_BIT = {'1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'};
final static int[] POWER_LIST = {7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2};

static {
zoneNum.put(11, "北京");
zoneNum.put(12, "天津");
zoneNum.put(13, "河北");
zoneNum.put(14, "山西");
zoneNum.put(15, "内蒙古");
zoneNum.put(21, "辽宁");
zoneNum.put(22, "吉林");
zoneNum.put(23, "黑龙江");
zoneNum.put(31, "上海");
zoneNum.put(32, "江苏");
zoneNum.put(33, "浙江");
zoneNum.put(34, "安徽");
zoneNum.put(35, "福建");
zoneNum.put(36, "江西");
zoneNum.put(37, "山东");
zoneNum.put(41, "河南");
zoneNum.put(42, "湖北");
zoneNum.put(43, "湖南");
zoneNum.put(44, "广东");
zoneNum.put(45, "广西");
zoneNum.put(46, "海南");
zoneNum.put(50, "重庆");
zoneNum.put(51, "四川");
zoneNum.put(52, "贵州");
zoneNum.put(53, "云南");
zoneNum.put(54, "西藏");
zoneNum.put(61, "陕西");
zoneNum.put(62, "甘肃");
zoneNum.put(63, "青海");
zoneNum.put(64, "宁夏");
zoneNum.put(65, "新疆");
zoneNum.put(71, "台湾");
zoneNum.put(81, "香港");
zoneNum.put(82, "澳门");
zoneNum.put(91, "外国");
}

/**
* Validate passengerId
* Validate bankId 19 digits
*
* @param id passengerId
* @return whether valid or not, null and "" are both false
* @param id bankId
* @return valid or not
*/
public static boolean idValidator(String id) {
if (id == null || (id.length() != 15 && id.length() != 18))
return false;
final char[] cs = id.toUpperCase().toCharArray();
//check bit
int power = 0;
for (int i = 0; i < cs.length; i++) {
if (i == cs.length - 1 && cs[i] == 'X')
break;//The last digit can be X or x
if (cs[i] < '0' || cs[i] > '9')
return false;
if (i < cs.length - 1) {
power += (cs[i] - '0') * POWER_LIST[i];
public static boolean bankIdValidator(String id) {
if (id.length() == 19) {
if (isDigit(id)) {
return true;
}
}

//check zoneNum
if (!zoneNum.containsKey(Integer.valueOf(id.substring(0, 2)))) {
return false;
}

//check year
String year = null;
year = id.length() == 15 ? getIdCardCalendar(id) : id.substring(6, 10);


final int iYear = Integer.parseInt(year);
if (iYear < 1900 || iYear > Calendar.getInstance().get(Calendar.YEAR))
return false;//pass year before 1900 and after this year

//check month
String month = id.length() == 15 ? id.substring(8, 10) : id.substring(10, 12);
final int iMonth = Integer.parseInt(month);
if (iMonth < 1 || iMonth > 12) {
return false;
}

//check day
String day = id.length() == 15 ? id.substring(10, 12) : id.substring(12, 14);
final int iDay = Integer.parseInt(day);
if (iDay < 1 || iDay > 31)
return false;

//check PARITY_BIT
if (id.length() == 15)
return true;
return cs[cs.length - 1] == PARITY_BIT[power % 11];
}

/**
* @param id passengerId
* @return year
*/
private static String getIdCardCalendar(String id) {
//Get birth year,month, day
String birthday = id.substring(6, 12);
SimpleDateFormat ft = new SimpleDateFormat("yyMMdd");
Date birthdate = null;
try {
birthdate = ft.parse(birthday);
} catch (java.text.ParseException e) {
e.printStackTrace();
}
Calendar cday = Calendar.getInstance();
assert birthdate != null;
cday.setTime(birthdate);
return String.valueOf(cday.get(Calendar.YEAR));
return false;
}

/**
Expand Down Expand Up @@ -217,4 +113,8 @@ public static boolean visaIdValidator(String visaId) {
//TODO:验证银行卡号,自己编写规则
return true;
}

public static boolean idValidator(String id) {
return IdcardUtil.isValidCard(id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,4 @@ passenger,flight,seatNo,food
123456,MH1234,3A,VEGETARIAN
123456,MH8633,3E,HALAL
123456,MH8633,2F,VEGETARIAN
123456,MH8633,4F,VEGETARIAN
30 changes: 15 additions & 15 deletions src/main/resources/com/app/flight/data/csv/Passenger.csv
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
passengerId ,firstName,lastName,age,telephone
123456 ,Test ,Jun ,22 ,13104368848
220802200005217774,Test ,Lian ,18 ,13104367774
220802200005217748,Test ,Hong ,99 ,13104362222
220802200005217891,Test ,Jun ,22 ,13104368848
510903199912239122,Sing ,Tong ,18 ,13177777777
510902200208035220,Ling ,Er ,20 ,15134235235
62562319801230993X,Li ,Sing ,42 ,15134235235
510103199810019323,Ding ,Zen ,25 ,15892039444
110103200410019323,Gu ,Eileen ,25 ,15892039444
309003199912259334,Jia ,Ran ,38 ,15892039444
309003200001039233,Nai ,Lin ,42 ,13980188599
203993199708190934,Lei ,Sui ,26 ,15880234599
203993199810240934,Nana ,Mi ,22 ,15980234395
403912199804045593,He ,Student ,23 ,18309038855
passengerId,firstName,lastName,age,telephone
123456,Test,Jun,22,13104368848
220802200005217774,Test,Lian,18,13104367774
220802200005217748,Test,Hong,99,13104362222
220802200005217891,Test,Jun,22,13104368848
510903199912239122,Sing,Tong,18,13177777777
510902200208035220,Ling,Er,20,15134235235
62562319801230993X,Li,Sing,42,15134235235
510103199810019323,Ding,Zen,25,15892039444
110103200410019323,Gu,Eileen,25,15892039444
309003199912259334,Jia,Ran,38,15892039444
309003200001039233,Nai,Lin,42,13980188599
203993199708190934,Lei,Sui,26,15880234599
203993199810240934,Nana,Mi,22,15980234395
403912199804045593,He,Student,23,18309038855
Loading