Search in sources :

Example 1 with TrainQueryInfo

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

the class HttpClientService method submitOrderRequest.

public void submitOrderRequest(SingleTrainOrderVO singleTrainOrderVO) {
    String title = "[登录用户:" + singleTrainOrderVO.getLoginUser() + "] ";
    HttpClient httpClient = buildHttpClient();
    TrainQueryInfo trainQueryInfo = singleTrainOrderVO.getTrainQueryInfo();
    try {
        // 提交预定的车次 一共25个参数
        List<NameValuePair> parameters = new ArrayList<NameValuePair>();
        parameters.add(new BasicNameValuePair(ORDER_ARRIVE_TIME, trainQueryInfo.getEndTime()));
        parameters.add(new BasicNameValuePair(ORDER_FROM_STATION_NAME, trainQueryInfo.getFromStation()));
        parameters.add(new BasicNameValuePair(ORDER_FROM_STATION_NO, trainQueryInfo.getFormStationNo()));
        parameters.add(new BasicNameValuePair(ORDER_FROM_STATION_TELECODE, trainQueryInfo.getFromStationCode()));
        parameters.add(new BasicNameValuePair(ORDER_FROM_STATION_TELECODE_NAME, trainQueryInfo.getFromStationName()));
        parameters.add(new BasicNameValuePair(ORDER_INCLUDE_STUDENT, "00"));
        parameters.add(new BasicNameValuePair(ORDER_LISHI, trainQueryInfo.getTakeTime()));
        parameters.add(new BasicNameValuePair(ORDER_LOCATIONCODE, trainQueryInfo.getLocationCode()));
        parameters.add(new BasicNameValuePair(ORDER_MMSTR, trainQueryInfo.getMmStr()));
        parameters.add(new BasicNameValuePair(ORDER_ROUND_START_TIME_STR, "00:00--24:00"));
        parameters.add(new BasicNameValuePair(ORDER_ROUND_TRAIN_DATE, singleTrainOrderVO.getTrainDate()));
        parameters.add(new BasicNameValuePair(ORDER_SEATTYPE_NUM, ""));
        parameters.add(new BasicNameValuePair(ORDER_SINGLE_ROUND_TYPE, trainQueryInfo.getSingle_round_type()));
        parameters.add(new BasicNameValuePair(ORDER_START_TIME_STR, "00:00--24:00"));
        parameters.add(new BasicNameValuePair(ORDER_STATION_TRAIN_CODE, trainQueryInfo.getTrainNo()));
        parameters.add(new BasicNameValuePair(ORDER_TO_STATION_NAME, trainQueryInfo.getToStation()));
        parameters.add(new BasicNameValuePair(ORDER_TO_STATION_NO, trainQueryInfo.getToStationNo()));
        parameters.add(new BasicNameValuePair(ORDER_TO_STATION_TELECODE, trainQueryInfo.getToStationCode()));
        parameters.add(new BasicNameValuePair(ORDER_TO_STATION_TELECODE_NAME, trainQueryInfo.getToStationName()));
        parameters.add(new BasicNameValuePair(ORDER_TRAIN_CLASS_ARR, "QB#D#Z#T#K#QT#"));
        parameters.add(new BasicNameValuePair(ORDER_TRAIN_DATE, singleTrainOrderVO.getTrainDate()));
        parameters.add(new BasicNameValuePair(ORDER_TRAIN_PASS_TYPE, "QB"));
        parameters.add(new BasicNameValuePair(ORDER_TRAIN_START_TIME, trainQueryInfo.getStartTime()));
        parameters.add(new BasicNameValuePair(ORDER_TRAINNO4, trainQueryInfo.getTrainno4()));
        parameters.add(new BasicNameValuePair(ORDER_YPINFODETAIL, trainQueryInfo.getYpInfoDetail()));
        TicketMainFrame.appendMessage(title + "提交订票请求, 车次:" + singleTrainOrderVO.getTrainNo() + ",席别:" + singleTrainOrderVO.getSeatType());
        HttpResponse response = postHttpRequest(httpClient, POST_URL_SUBMUTORDERREQUEST, parameters, singleTrainOrderVO.getCookieData());
        int statusCode = response.getStatusLine().getStatusCode();
        // 返回码 301 或 302 转发到location的新地址
        if (statusCode == HttpStatus.SC_MOVED_PERMANENTLY || statusCode == HttpStatus.SC_MOVED_TEMPORARILY) {
            Header locationHeader = response.getFirstHeader("location");
            String redirectUrl = locationHeader.getValue();
            TicketMainFrame.appendMessage(title + "订票请求响应代码:" + statusCode + ", 转向获取订票凭证数据");
            logger.debug("Response StatusCode: " + statusCode, "Redirect to URL: " + redirectUrl);
            HttpClient httpClient2 = buildHttpClient();
            String responseBody = postHttpRequestAsString(httpClient2, redirectUrl, null, singleTrainOrderVO.getCookieData());
            httpClient2.getConnectionManager().shutdown();
            String leftTicketStr = TicketUtil.getCredential(responseBody);
            if (StringUtils.isBlank(leftTicketStr)) {
                throw new IllegalArgumentException(title + "未取到有效的leftTicketStr数据");
            } else {
                TicketMainFrame.appendMessage(title + "成功获取到leftTicketStr凭证数据:" + leftTicketStr);
            }
            singleTrainOrderVO.setSubmitOrderRequestLeftTicketStr(leftTicketStr);
            String token = TicketUtil.getToken(responseBody);
            if (StringUtils.isBlank(leftTicketStr)) {
                throw new IllegalArgumentException(title + "未取到有效的token数据");
            } else {
                TicketMainFrame.appendMessage(title + "成功获取到Token凭证数据:" + token);
            }
            singleTrainOrderVO.setSubmitOrderRequestToken(token);
        }
    } finally {
        httpClient.getConnectionManager().shutdown();
    }
}
Also used : BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair) Header(org.apache.http.Header) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ArrayList(java.util.ArrayList) HttpResponse(org.apache.http.HttpResponse) TrainQueryInfo(lab.ticket.model.TrainQueryInfo)

Example 2 with TrainQueryInfo

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

the class HttpClientService method confirmSingleForQueueOrder.

public String confirmSingleForQueueOrder(TicketData ticketData, SingleTrainOrderVO singleTrainOrderVO, String randCode, boolean justCheck) {
    String title = "[登录用户:" + singleTrainOrderVO.getLoginUser() + "] ";
    HttpClient httpClient = buildHttpClient();
    TrainQueryInfo trainQueryInfo = singleTrainOrderVO.getTrainQueryInfo();
    try {
        String url = null;
        if (justCheck) {
            url = POST_URL_CHECKORDERINFO + randCode;
        } else {
            url = POST_URL_CONFIRMSINGLEFORQUEUE;
        }
        List<PassengerData> validPassengerDatas = ticketData.getValidPassengerDatas();
        List<NameValuePair> parameters = new ArrayList<NameValuePair>();
        for (int i = 0; i < validPassengerDatas.size(); i++) {
            parameters.add(new BasicNameValuePair("checkbox" + i, Integer.toString(i)));
        }
        parameters.add(new BasicNameValuePair("checkbox9", "Y"));
        parameters.add(new BasicNameValuePair("checkbox9", "Y"));
        parameters.add(new BasicNameValuePair("checkbox9", "Y"));
        parameters.add(new BasicNameValuePair("checkbox9", "Y"));
        parameters.add(new BasicNameValuePair("checkbox9", "Y"));
        parameters.add(new BasicNameValuePair(SUBMIT_LEFTTICKETSTR, singleTrainOrderVO.getSubmitOrderRequestLeftTicketStr()));
        for (int i = 0; i < validPassengerDatas.size(); i++) {
            parameters.add(new BasicNameValuePair(SUBMIT_OLDPASSENGERS, validPassengerDatas.get(i).getShortText()));
        }
        for (int i = 0; i < (5 - validPassengerDatas.size()); i++) {
            parameters.add(new BasicNameValuePair(SUBMIT_OLDPASSENGERS, ""));
        }
        parameters.add(new BasicNameValuePair(SUBMIT_BED_LEVEL_ORDER_NUM, "000000000000000000000000000000"));
        parameters.add(new BasicNameValuePair(SUBMIT_CANCEL_FLAG, "1"));
        parameters.add(new BasicNameValuePair(SUBMIT_END_TIME, trainQueryInfo.getEndTime()));
        parameters.add(new BasicNameValuePair(SUBMIT_FROM_STATION_NAME, trainQueryInfo.getFromStation()));
        parameters.add(new BasicNameValuePair(SUBMIT_FROM_STATION_TELECODE, trainQueryInfo.getFromStationCode()));
        parameters.add(new BasicNameValuePair(SUBMIT_ID_MODE, "Y"));
        parameters.add(new BasicNameValuePair(SUBMIT_RESERVE_FLAG, "A"));
        parameters.add(new BasicNameValuePair(SUBMIT_TO_SEAT_TYPE_CODE, ""));
        parameters.add(new BasicNameValuePair(SUBMIT_START_TIME, trainQueryInfo.getStartTime()));
        parameters.add(new BasicNameValuePair(SUBMIT_STATION_TRAIN_CODE, trainQueryInfo.getTrainNo()));
        parameters.add(new BasicNameValuePair(SUBMIT_TICKET_TYPE_ORDER_NUM, ""));
        parameters.add(new BasicNameValuePair(SUBMIT_TO_STATION_NAME, trainQueryInfo.getToStation()));
        parameters.add(new BasicNameValuePair(SUBMIT_TO_STATION_TELECODE, trainQueryInfo.getToStationCode()));
        parameters.add(new BasicNameValuePair(QUERY_TRAIN_DATE, singleTrainOrderVO.getTrainDate()));
        parameters.add(new BasicNameValuePair(QUERY_TRAIN_NO, trainQueryInfo.getTrainno4()));
        parameters.add(new BasicNameValuePair(SUBMIT_TOKEN, singleTrainOrderVO.getSubmitOrderRequestToken()));
        for (int i = 0; i < validPassengerDatas.size(); i++) {
            parameters.add(new BasicNameValuePair(SUBMIT_PASSENGERTICKETS, validPassengerDatas.get(i).getLongText(singleTrainOrderVO.getSeatType())));
            parameters.add(new BasicNameValuePair("passenger_" + (i + 1) + "_cardno", validPassengerDatas.get(i).getCardNo()));
            parameters.add(new BasicNameValuePair("passenger_" + (i + 1) + "_cardtype", validPassengerDatas.get(i).getCardType().getValue()));
            parameters.add(new BasicNameValuePair("passenger_" + (i + 1) + "_mobileno", validPassengerDatas.get(i).getMobile()));
            parameters.add(new BasicNameValuePair("passenger_" + (i + 1) + "_name", validPassengerDatas.get(i).getName()));
            parameters.add(new BasicNameValuePair("passenger_" + (i + 1) + "_seat", singleTrainOrderVO.getSeatType().getValue()));
            parameters.add(new BasicNameValuePair("passenger_" + (i + 1) + "_ticket", validPassengerDatas.get(i).getTicketType().getValue()));
        }
        parameters.add(new BasicNameValuePair(SUBMIT_RANDCODE, randCode));
        // 检查订单
        if (justCheck) {
            parameters.add(new BasicNameValuePair(SUBMIT_TFLAG, "dc"));
        }
        parameters.add(new BasicNameValuePair(SUBMIT_TEXTFIELD, "中文或拼音首字母"));
        TicketMainFrame.appendMessage(title + "提交订单, 车次:" + singleTrainOrderVO.getTrainNo() + ",席别:" + singleTrainOrderVO.getSeatType() + ",日期:" + singleTrainOrderVO.getTrainDate());
        String responseBody = postHttpRequestAsString(httpClient, url, parameters, singleTrainOrderVO.getCookieData());
        return responseBody;
    } finally {
        httpClient.getConnectionManager().shutdown();
    }
}
Also used : BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ArrayList(java.util.ArrayList) TrainQueryInfo(lab.ticket.model.TrainQueryInfo) PassengerData(lab.ticket.model.PassengerData)

Example 3 with TrainQueryInfo

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

the class HttpClientService method getQueueCount.

public String getQueueCount(TicketData ticketData, SingleTrainOrderVO singleTrainOrderVO) {
    String title = "[登录用户:" + singleTrainOrderVO.getLoginUser() + "] ";
    HttpClient httpClient = buildHttpClient();
    TrainQueryInfo trainQueryInfo = singleTrainOrderVO.getTrainQueryInfo();
    try {
        List<NameValuePair> parameters = new ArrayList<NameValuePair>();
        parameters.add(new BasicNameValuePair(GETQUEUECOUNT_FROM, ticketData.getTrainFromCode()));
        parameters.add(new BasicNameValuePair(GETQUEUECOUNT_SEAT, singleTrainOrderVO.getSeatType().getValue()));
        parameters.add(new BasicNameValuePair(GETQUEUECOUNT_STATION, trainQueryInfo.getTrainNo()));
        parameters.add(new BasicNameValuePair(GETQUEUECOUNT_TICKET, singleTrainOrderVO.getSubmitOrderRequestLeftTicketStr()));
        parameters.add(new BasicNameValuePair(GETQUEUECOUNT_TO, ticketData.getTrainToCode()));
        parameters.add(new BasicNameValuePair(GETQUEUECOUNT_TRAIN_DATE, singleTrainOrderVO.getTrainDate()));
        parameters.add(new BasicNameValuePair(GETQUEUECOUNT_TRAIN_NO, trainQueryInfo.getTrainno4()));
        TicketMainFrame.appendMessage(title + "下单余票数查询请求, 车次:" + singleTrainOrderVO.getTrainNo() + ",席别:" + singleTrainOrderVO.getSeatType());
        String response = getHttpRequestAsString(httpClient, GET_URL_GETQUEUECOUNT, parameters, singleTrainOrderVO.getCookieData());
        return response;
    } finally {
        httpClient.getConnectionManager().shutdown();
    }
}
Also used : BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ArrayList(java.util.ArrayList) TrainQueryInfo(lab.ticket.model.TrainQueryInfo)

Example 4 with TrainQueryInfo

use of lab.ticket.model.TrainQueryInfo 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 5 with TrainQueryInfo

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

TrainQueryInfo (lab.ticket.model.TrainQueryInfo)5 ArrayList (java.util.ArrayList)4 NameValuePair (org.apache.http.NameValuePair)3 HttpClient (org.apache.http.client.HttpClient)3 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)3 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)3 HashMap (java.util.HashMap)1 Map (java.util.Map)1 PassengerData (lab.ticket.model.PassengerData)1 SingleTrainOrderVO (lab.ticket.model.SingleTrainOrderVO)1 TrainData (lab.ticket.model.TrainData)1 SeatType (lab.ticket.model.UserData.SeatType)1 RandomCodeDialog (lab.ticket.view.RandomCodeDialog)1 Header (org.apache.http.Header)1 HttpResponse (org.apache.http.HttpResponse)1