package cn.net.test;

import java.io.IOException;
import java.net.BindException;
import java.net.ConnectException;
import java.net.SocketTimeoutException;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;

import cn.net.cpzslibs.prot.Prot02Logout;
import cn.net.cpzslibs.prot.SocketCreate;
import cn.net.cpzslibs.prot.bean.req.Prot10051InvoiceBean;
import cn.net.cpzslibs.prot.bean.req.Prot10051ReqBean;
import cn.net.cpzslibs.prot.handset.Prot10051SubmitInvoice;

public class HandsetYunTh {
	public static void main(String[] args) {
		
		String ip = "218.245.0.109";// 218.245.0.109 192.168.0.46
		int port = 8890;//8899
		SocketCreate create = new SocketCreate(ip, port, "1000022");
		try {
			System.out.println("开始请求数据");
			create.createLoginCpzsHandset(1000022L);//1000022
			//{"ac":[{"id":"6","line":"741","region":"白云区,乌当区,云岩区","region_id":"1260105,1260104,1260103","station_dec":"741","station_name":"741","trans_mode":1},{"id":"7","line":"852","region":"游仙区,镇远县","region_id":"1270402,1260505","station_dec":"852","station_name":"852","trans_mode":1},{"id":"9","line":"015240","region":"云岩区","region_id":"1260102","station_dec":"","station_name":"曲靖火车站","trans_mode":1},{"id":"11","line":"","region":"南明区","region_id":"1260101","station_dec":"","station_name":"唐山北站","trans_mode":1},{"id":"12","line":"","region":"","region_id":"","station_dec":"111111111","station_name":"11111111","trans_mode":1},{"id":"14","line":"","region":"","region_id":"","station_dec":"","station_name":"33333333333333","trans_mode":1},{"id":"15","line":"","region":"","region_id":"","station_dec":"","station_name":"44444444","trans_mode":1},{"id":"16","line":"","region":"","region_id":"","station_dec":"","station_name":"55555555555","trans_mode":1},{"id":"17","line":"","region":"","region_id":"","station_dec":"","station_name":"66666666666","trans_mode":1},{"id":"18","line":"","region":"","region_id":"","station_dec":"","station_name":"7777777","trans_mode":1},{"id":"19","line":"100001","region":"南明区","region_id":"1260101","station_dec":"火车1","station_name":"火车1","trans_mode":1},{"id":"20","line":"100002","region":"云岩区","region_id":"1260102","station_dec":"火车2","station_name":"火车1","trans_mode":1},{"id":"21","line":"200001","region":"白云区","region_id":"1260105","station_dec":"汽车1","station_name":"汽车1","trans_mode":2}],"index":0,"num_per":500,"total":13}
//			System.err.println("0----" + create.isResult());
			System.err.println("----" + create.getiErrCode() +"   " + create.getErrMsg());
		//---------------10050-------------------获取车站列表------------------------------------------------------------------
			/*Prot10050ReqStationManager sm = new Prot10050ReqStationManager();
			sm.dealStationList(create);
			System.err.println(" station: " + sm.getStations().toString());*/
		//---------------10061-------------------检测PackageID------------------------------------------------------------------
//			Prot10061CheckPackageID cPackageID = new Prot10061CheckPackageID();
//			//1000000003486968 //packageID为空
//			//1000000003543989
//			cPackageID.dealCheckPackageId(create, new Prot10061ReqBean("100001003781400"));
//			System.err.println("  resBean:" + cPackageID.getRes().toString());
			
			//---------------10051-------------------获取车站列表------------------------------------------------------------------
			Prot10051SubmitInvoice submitInvoice = new Prot10051SubmitInvoice();
			submitInvoice.submitInvoice(create, getT51TrainReqBean());
//			submitInvoice.submitInvoice(create, getT51ReqBean());

		} catch (BindException e) {
			e.printStackTrace();
		} catch (ConnectException e) {
			e.printStackTrace();
		} catch (SocketTimeoutException e) {
			e.printStackTrace();
		} catch (UnknownHostException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
			System.err.println("IOException:" + e.getLocalizedMessage());
		} finally {
			new Prot02Logout().dealLogout(create);
		}

	
//		Gson gson = new Gson();
//		System.err.println("  testJsonData: " + gson.toJson(getT51ReqBean()));
		
	
	}
	private static Prot10051ReqBean getT51TrainReqBean() {

		Prot10051ReqBean reqBean = new Prot10051ReqBean();
		reqBean.setType(1);
		Prot10051InvoiceBean invoiceBean = new Prot10051InvoiceBean();
		invoiceBean.setCarriage_no("P1234567");
		invoiceBean.setOrder_no("1234567");
		invoiceBean.setStarting_station(1);
		invoiceBean.setTerminal_station(17);
		invoiceBean.setTimestamp("2016-08-08 10:10:10");
		invoiceBean.setOpt(-1);
		invoiceBean.setVid(getVidTrueTData());
		invoiceBean.setLabel_id(getLabelTrueTData());
		reqBean.setOrder(invoiceBean);
		return reqBean;
	
	}
	private static List<String> getLabelTrueTData() {
		List<String> label = new ArrayList<>();
		label.add("1002151303552344");
		return label;
	}
	private static List<String> getVidTrueTData() {
		List<String> via = new ArrayList<>();
		via.add("1002151303158180");
		return via;
	}
	private static Prot10051ReqBean getT51ReqBean() {
		Prot10051ReqBean reqBean = new Prot10051ReqBean();
		reqBean.setType(2);
		Prot10051InvoiceBean invoiceBean = new Prot10051InvoiceBean();
		invoiceBean.setTruck_no("京A10001");
		invoiceBean.setDriver_name("echoTest");
		invoiceBean.setDriver_phone("15009287021");
		invoiceBean.setOrder_no("1234567");
		invoiceBean.setStarting_station(0);
		invoiceBean.setTerminal_station(17);
		invoiceBean.setTimestamp("2016-08-08 10:10:10");
		invoiceBean.setVid(getVidTData());
		invoiceBean.setLabel_id(getLabelTData());
		reqBean.setOrder(invoiceBean);
		return reqBean;
	}

	private static List<String> getLabelTData() {
		List<String> labelID = new ArrayList<>();
		for (int i = 0; i < 20; i++) {
			labelID.add("200011234567" + i);
		}
		return labelID;
	}

	private static List<String> getVidTData() {
		List<String> vid = new ArrayList<>();
		for (int i = 0; i < 10; i++) {
			vid.add("100011234567" + i);
		}
		return vid;
	}

}
