Search in sources :

Example 1 with TrainData

use of lab.ticket.model.TrainData in project 12306-hunter by xautlx.

the class UserPanel method bindUItoModel.

public UserData bindUItoModel() {
    logger.debug("Binding UI data for user: {}", textLoginUser.getText());
    UserData userData = new UserData();
    userData.setLoginUser(textLoginUser.getText());
    if ("登录成功".equals(lblLoginCodeImg.getText())) {
        userData.setLoginSuccess(true);
    } else {
        userData.setLoginSuccess(false);
    }
    userData.setCookieData(cookieData);
    List<TrainData> trainDatas = userData.getTrainDatas();
    if (StringUtils.isNotBlank(textTrainNo1.getText())) {
        trainDatas.add(new TrainData(textTrainNo1.getText(), (SeatType) comboSeatType1.getSelectedItem()));
    }
    if (StringUtils.isNotBlank(textTrainNo2.getText())) {
        trainDatas.add(new TrainData(textTrainNo2.getText(), (SeatType) comboSeatType2.getSelectedItem()));
    }
    if (StringUtils.isNotBlank(textTrainNo3.getText())) {
        trainDatas.add(new TrainData(textTrainNo3.getText(), (SeatType) comboSeatType3.getSelectedItem()));
    }
    if (StringUtils.isNotBlank(textTrainNo4.getText())) {
        trainDatas.add(new TrainData(textTrainNo4.getText(), (SeatType) comboSeatType4.getSelectedItem()));
    }
    if (StringUtils.isNotBlank(textTrainNo5.getText())) {
        trainDatas.add(new TrainData(textTrainNo5.getText(), (SeatType) comboSeatType5.getSelectedItem()));
    }
    return userData;
}
Also used : TrainData(lab.ticket.model.TrainData) UserData(lab.ticket.model.UserData) SeatType(lab.ticket.model.UserData.SeatType)

Example 2 with TrainData

use of lab.ticket.model.TrainData in project 12306-hunter by xautlx.

the class TicketUserThread method run.

@Override
public void run() {
    String title = "[线程: " + this.getId() + ", 登录用户:" + userData.getLoginUser() + "] ";
    TicketMainFrame.appendMessage(title + "刷票日期顺序列表:");
    List<String> trainDates = ticketData.getTrainDateList();
    for (String trainDate : trainDates) {
        TicketMainFrame.appendMessage(title + " - " + trainDate);
    }
    while (!success) {
        try {
            if (terminalSign) {
                TicketMainFrame.appendMessage(title + "终止退出");
                return;
            }
            TicketMainFrame.appendMessage(title + "第 " + (++count) + " 次刷票");
            SingleTrainOrderVO singleTrainOrderVO = null;
            for (String trainDate : trainDates) {
                TicketMainFrame.appendMessage(title + "查询【" + trainDate + "】车票信息响应:");
                List<TrainQueryInfo> trainQueryInfos = httpClientService.queryTrain(ticketData, userData, trainDate);
                for (TrainQueryInfo trainQueryInfo : trainQueryInfos) {
                    if (!trainQueryInfo.isValidForPurchase()) {
                        TicketMainFrame.appendMessage(title + " - :( 当前不可购买或无票车次:" + trainDate + trainQueryInfo);
                    } else {
                        TicketMainFrame.appendMessage(title + " - :) 可购买车次:" + trainDate + trainQueryInfo);
                    }
                }
                // 从查询到车次数据按照优先级找到最匹配的车次和座位类型
                // --:没有该席别;*:未到开始时间;有:有并且数量充足;数字:有但数量有限:无:已售完
                List<TrainData> trainDatas = userData.getTrainDatas();
                for (TrainData trainData : trainDatas) {
                    for (TrainQueryInfo trainQueryInfo : trainQueryInfos) {
                        if (!trainQueryInfo.isValidForPurchase()) {
                            continue;
                        }
                        if (trainQueryInfo.getTrainNo().equals(trainData.getTrainNo())) {
                            String seatTypeValue = trainQueryInfo.getSeatDatas().get(trainData.getSeatType());
                            if (seatTypeValue.equals("无")) {
                                continue;
                            }
                            TicketMainFrame.appendMessage(title + ":) 预定车次有票:" + trainData.getTrainNo() + ",席别:" + trainData.getSeatType() + ",日期:" + trainDate + ",车票:" + seatTypeValue);
                            singleTrainOrderVO = new SingleTrainOrderVO();
                            singleTrainOrderVO.setTrainQueryInfo(trainQueryInfo);
                            singleTrainOrderVO.setLoginUser(userData.getLoginUser());
                            singleTrainOrderVO.setCookieData(userData.getCookieData());
                            singleTrainOrderVO.setSeatType(trainData.getSeatType());
                            singleTrainOrderVO.setTrainDate(trainDate);
                            singleTrainOrderVO.setTrainNo(trainData.getTrainNo());
                            break;
                        }
                    }
                    if (singleTrainOrderVO != null) {
                        break;
                    }
                    TicketMainFrame.appendMessage(title + ":( 预定车次无票:" + trainData.getTrainNo() + ",席别:" + trainData.getSeatType() + ",日期:" + trainDate);
                }
                if (singleTrainOrderVO != null) {
                    break;
                }
            }
            if (singleTrainOrderVO == null) {
                TicketMainFrame.appendMessage(title + "郁闷:所有指定日期车次目前均无法购票或无票。暂停 " + SLEEP_SECONDS + " 秒继续尝试刷票...");
                Thread.sleep(Float.valueOf(SLEEP_SECONDS * 1000).intValue());
            } else {
                TicketMainFrame.appendMessage(title + "暂停 " + SLEEP_SECONDS + " 秒后继续...");
                Thread.sleep(Float.valueOf(SLEEP_SECONDS * 1000).intValue());
                httpClientService.submitOrderRequest(singleTrainOrderVO);
                String responseBody = null;
                do {
                    synchronized (this) {
                        new RandomCodeDialog(singleTrainOrderVO, this);
                        this.wait();
                    }
                    if (StringUtils.isBlank(this.submitCode)) {
                        TicketMainFrame.appendMessage(title + "已取消本次下单验证码输入");
                        break;
                    }
                    responseBody = httpClientService.confirmSingleForQueueOrder(ticketData, singleTrainOrderVO, this.submitCode, true);
                    if (responseBody.contains("验证码")) {
                        TicketMainFrame.appendMessage(title + "下单验证码错误,请重新输入");
                    }
                } while (responseBody.contains("验证码"));
                //如果errMsg不为Y则表示访问错误,继续下一次循环
                if (responseBody == null || responseBody.indexOf("\"errMsg\":\"Y\"") == -1) {
                    continue;
                }
                //下单确认前的余票数量检查请求
                TicketMainFrame.appendMessage(title + "暂停 " + SLEEP_SECONDS + " 秒后继续...");
                Thread.sleep(Float.valueOf(SLEEP_SECONDS * 1000).intValue());
                responseBody = httpClientService.getQueueCount(ticketData, singleTrainOrderVO);
                //此处可考虑添加检查判断逻辑:只有最新返回有余票才继续后续提交订单
                // 提交订单
                TicketMainFrame.appendMessage(title + "暂停 " + SLEEP_SECONDS + " 秒后继续...");
                Thread.sleep(Float.valueOf(SLEEP_SECONDS * 1000).intValue());
                responseBody = httpClientService.confirmSingleForQueueOrder(ticketData, singleTrainOrderVO, this.submitCode, false);
                if (responseBody.indexOf("\"errMsg\":\"Y\"") > -1) {
                    String msg = title + "貌似已成功下单,赶快用浏览器登录此账号访问“未完成订单”中查看确认及进行后续付款操作";
                    JOptionPane.showMessageDialog(ticketMainFrame, msg);
                    TicketMainFrame.appendMessage(msg);
                    TicketMainFrame.appendMessage(title + "已终止当前用户刷票线程,其他用户刷票线程继续运行");
                    success = true;
                    break;
                }
            }
        } catch (InterruptedException e) {
            TicketMainFrame.appendMessage(title + "异常:" + e.getMessage());
            logger.error("Error at thread " + this.getId() + " for user " + userData.getLoginUser(), e);
        }
    }
}
Also used : TrainData(lab.ticket.model.TrainData) RandomCodeDialog(lab.ticket.view.RandomCodeDialog) SingleTrainOrderVO(lab.ticket.model.SingleTrainOrderVO) TrainQueryInfo(lab.ticket.model.TrainQueryInfo)

Example 3 with TrainData

use of lab.ticket.model.TrainData in project 12306-hunter by xautlx.

the class UserPanel method bindModeltoUI.

public void bindModeltoUI(UserData userData, boolean passwdFocus) {
    logger.debug("Binding Model data for user: {}", userData.getLoginUser());
    textLoginUser.setText(userData.getLoginUser());
    List<TrainData> trainDatas = userData.getTrainDatas();
    if (trainDatas.size() > 0) {
        TrainData trainData = trainDatas.get(0);
        textTrainNo1.setText(trainData.getTrainNo());
        comboSeatType1.setSelectedItem(trainData.getSeatType());
    }
    if (trainDatas.size() > 1) {
        TrainData trainData = trainDatas.get(1);
        textTrainNo2.setText(trainData.getTrainNo());
        comboSeatType2.setSelectedItem(trainData.getSeatType());
    }
    if (trainDatas.size() > 2) {
        TrainData trainData = trainDatas.get(2);
        textTrainNo3.setText(trainData.getTrainNo());
        comboSeatType3.setSelectedItem(trainData.getSeatType());
    }
    if (trainDatas.size() > 3) {
        TrainData trainData = trainDatas.get(3);
        textTrainNo4.setText(trainData.getTrainNo());
        comboSeatType4.setSelectedItem(trainData.getSeatType());
    }
    if (trainDatas.size() > 4) {
        TrainData trainData = trainDatas.get(4);
        textTrainNo5.setText(trainData.getTrainNo());
        comboSeatType5.setSelectedItem(trainData.getSeatType());
    }
    if (passwdFocus) {
        textLoginPasswd.grabFocus();
    }
}
Also used : TrainData(lab.ticket.model.TrainData)

Aggregations

TrainData (lab.ticket.model.TrainData)3 SingleTrainOrderVO (lab.ticket.model.SingleTrainOrderVO)1 TrainQueryInfo (lab.ticket.model.TrainQueryInfo)1 UserData (lab.ticket.model.UserData)1 SeatType (lab.ticket.model.UserData.SeatType)1 RandomCodeDialog (lab.ticket.view.RandomCodeDialog)1