Search in sources :

Example 1 with SeatType

use of lab.ticket.model.UserData.SeatType 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 SeatType

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

the class TicketUtil method parserQueryInfo.

/**
	 * 查询返回字符对象化
	 * 
	 * @param response
	 * @return List<TrainQueryInfo>
	 */
public static List<TrainQueryInfo> parserQueryInfo(String response) {
    List<TrainQueryInfo> tqis = new ArrayList<TrainQueryInfo>();
    response = response.replaceAll("&nbsp;", "");
    logger.info("Response String is " + response);
    // Session 过期
    if ("-10".equals(response)) {
        logger.info("Session is timeout!");
        return tqis;
    }
    String[] number = response.split("\\\\n");
    for (int i = 0; i < number.length; i++) {
        String info = number[i];
        if (StringUtils.isNotBlank(info)) {
            String[] ticketInfo = info.split(",");
            TrainQueryInfo trainQueryInfo = new TrainQueryInfo();
            trainQueryInfo.setTrainCode(ticketInfo[0]);
            trainQueryInfo.setTrainNo(ticketInfo[1].substring(ticketInfo[1].lastIndexOf("\'>") + 2, ticketInfo[1].lastIndexOf("</span>")));
            String startstation = isStartOrEndStation(ticketInfo[2]);
            trainQueryInfo.setFromStation(startstation.substring(0, startstation.lastIndexOf("<br>")));
            trainQueryInfo.setFromStationName(convertStation(trainQueryInfo.getFromStation()));
            trainQueryInfo.setFromStationCode(TicketUtil.getCityCode(startstation.substring(0, startstation.lastIndexOf("<br>"))));
            trainQueryInfo.setStartTime(startstation.substring(startstation.lastIndexOf("<br>") + 4, startstation.length()));
            String endstation = isStartOrEndStation(ticketInfo[3]);
            trainQueryInfo.setToStation(endstation.substring(0, endstation.lastIndexOf("<br>")));
            trainQueryInfo.setToStationName(convertStation(trainQueryInfo.getToStation()));
            trainQueryInfo.setToStationCode(TicketUtil.getCityCode(endstation.substring(0, endstation.lastIndexOf("<br>"))));
            trainQueryInfo.setEndTime(endstation.substring(endstation.lastIndexOf("<br>") + 4, endstation.length()));
            trainQueryInfo.setTakeTime(ticketInfo[4]);
            Map<SeatType, String> seatDatas = trainQueryInfo.getSeatDatas();
            seatDatas.put(SeatType.BUSS_SEAT, isExistTicket(ticketInfo[5]));
            seatDatas.put(SeatType.BEST_SEAT, isExistTicket(ticketInfo[6]));
            seatDatas.put(SeatType.ONE_SEAT, isExistTicket(ticketInfo[7]));
            seatDatas.put(SeatType.TWO_SEAT, isExistTicket(ticketInfo[8]));
            seatDatas.put(SeatType.VAG_SLEEPER, isExistTicket(ticketInfo[9]));
            seatDatas.put(SeatType.SOFT_SLEEPER, isExistTicket(ticketInfo[10]));
            seatDatas.put(SeatType.HARD_SLEEPER, isExistTicket(ticketInfo[11]));
            seatDatas.put(SeatType.SOFT_SEAT, isExistTicket(ticketInfo[12]));
            seatDatas.put(SeatType.HARD_SEAT, isExistTicket(ticketInfo[13]));
            seatDatas.put(SeatType.NONE_SEAT, isExistTicket(ticketInfo[14]));
            seatDatas.put(SeatType.OTH_SEAT, isExistTicket(ticketInfo[15]));
            String infos = ticketInfo[16];
            String[] trainInfo = getMMString(infos);
            if (trainInfo.length > 0) {
                trainQueryInfo.setMmStr(trainInfo[12]);
                trainQueryInfo.setTrainno4(trainInfo[3]);
                trainQueryInfo.setYpInfoDetail(trainInfo[11]);
                trainQueryInfo.setFormStationNo(trainInfo[9]);
                trainQueryInfo.setToStationNo(trainInfo[10]);
                trainQueryInfo.setLocationCode(trainInfo[13]);
            }
            // --:没有该席别;*:未到开始时间;有:有并且数量充足;数字:有但数量有限:无:已售完
            boolean validForPurchase = false;
            for (Map.Entry<SeatType, String> me : seatDatas.entrySet()) {
                String value = me.getValue();
                if (value.equals("--") || value.equals("无") || value.equals("*")) {
                    continue;
                }
                validForPurchase = true;
                break;
            }
            trainQueryInfo.setValidForPurchase(validForPurchase);
            tqis.add(trainQueryInfo);
        }
    }
    return tqis;
}
Also used : ArrayList(java.util.ArrayList) SeatType(lab.ticket.model.UserData.SeatType) TrainQueryInfo(lab.ticket.model.TrainQueryInfo) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

SeatType (lab.ticket.model.UserData.SeatType)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TrainData (lab.ticket.model.TrainData)1 TrainQueryInfo (lab.ticket.model.TrainQueryInfo)1 UserData (lab.ticket.model.UserData)1