package cn.net.test;

import com.jymf.common.LableUtil;

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.Prot10087GetCarNumber;
import cn.net.cpzslibs.prot.handset.bean.req.Prot10079ReqBean;
import cn.net.cpzslibs.prot.handset.bean.req.Prot20002ReqBatchBean;
import cn.net.cpzslibs.prot.handset.bean.req.Prot20002ReqBean;
import cn.net.cpzslibs.prot.handset.bean.req.Prot20003ReqBean;
import cn.net.cpzslibs.prot.handset.bean.req.Prot20005ReqBean;
import cn.net.cpzslibs.prot.handset.bean.req.Prot20016ReqBean;
import cn.net.cpzslibs.prot.handset.bean.req.Prot20017ReqBean;
import cn.net.cpzslibs.prot.handset.bean.req.Prot20025ReqBean;
import cn.net.cpzslibs.prot.handset.bean.req.Prot20026ReqBean;
import cn.net.cpzslibs.prot.handset.bean.req.SheepWarehouseBean;

public class SheepLaeder {
	private static long deviceId = 358000052L;// 1000000000118 358000020L
											// 1000022L  458000427L

	public static void main(String[] args) {
		String ip = "218.245.0.109";// 218.245.0.109 192.168.0.46
									// www.gjcpzlzs.com
		int port = 8898;
		SocketCreate create = new SocketCreate(ip, port, "");
		try {
			// -----------------羊毛出库------------------羊毛-------20026--------------------------------------------------
			//{"list":[{"error_code":10004,"id":10},{"error_code":10004,"id":11}],"result":2}
			/*create.createLoginCpzsHandset(deviceId);
			if (create.isResult()) {
				Prot20026SheepWarehouse submitWarehouse = new Prot20026SheepWarehouse();
				submitWarehouse.submitWarehouseInfo(create, getSheepWarehouseBean());
				System.err.println("请求结果：" + submitWarehouse.getResBean().toString());
			}*/
			// ---------- ---------------------------------------
			create.createLoginCpzsHandset(deviceId);
			if (create.isResult()) {
				Prot10087GetCarNumber p87 = new Prot10087GetCarNumber();
				p87.getCatNumList(create);
				System.err.println("请求结果：" + p87.getResBean().toString());
				
			}
			// -----------------查询标签信息------------------羊毛-------20022--------------------------------------------------
			//{"dealer_id":"1","first_consume_time":"2014-08-08 09:44:56","iResult":0,"label_id":"1000021066414976","package_id":"","pop_time":"2017-06-14 14:46:39","produce_time":"2017-07-06 14:44:59","product_name":"","remark":"111"}
//			String labelId="100002108843";//1000021066414976(正常标签)
//			labelId = getLabelId(labelId);
//			create.createLoginCpzsHandset(deviceId);
//			if (create.isResult()) {
//				Prot20022SearchLabelInfo searchLabelInfo = new Prot20022SearchLabelInfo();
//				searchLabelInfo.searchLabelInfo(create,new SingleLabelIdBean(labelId));
//				System.err.println("请求结果：" + searchLabelInfo.getResBean().toString());
//			}
			// -----------------出返库操作------------------羊毛-------20021--------------------------------------------------
//			create.createLoginCpzsHandset(deviceId);
//			if (create.isResult()) {
//				
//			}
			// -----------------上传手持机参数------------------云天化-------20025--------------------------------------------------

//			create.createLoginCpzsHandset(deviceId);
//			if (create.isResult()) {
//				Prot20025SubmitHandsetParameter submitHandsetParameter = new Prot20025SubmitHandsetParameter();
//				submitHandsetParameter.submitHandsetParameter(create, getSubmitHandsetBean());
//			}
			// -----------------请求用户信息------------------云天化-------20020--------------------------------------------------

//			create.createLoginCpzsHandset(deviceId);
//			if (create.isResult()) {
//				Prot20020ReqUserInfo reqUserInfo = new Prot20020ReqUserInfo();
//				reqUserInfo.dealUserInfoList(create);
//				System.err.println("--" + reqUserInfo.getUserInfo().toString());
//			}

			// -----------------通用版检测标签状态------------------通用版-------20017--------------------------------------------------
			// create.createLoginCpzsHandset(deviceId);
			// if (create.isResult()) {
			// Prot20017CheckLabelStatus checkLabelStatus = new
			// Prot20017CheckLabelStatus();
			// checkLabelStatus.checkLabel(create, get20017ReqBean());
			// System.err.println("解析后：" + checkLabelStatus.getResBean());
			// }
			// //
			// -----------------上传天安的发货列表------------------云天化-------20016--------------------------------------------------

			// create.createLoginCpzsHandset(deviceId);
			// if (create.isResult()) {
			// Prot20016SubmitTAInvoice submitTAInvoice = new
			// Prot20016SubmitTAInvoice();
			// submitTAInvoice.submitInvoice(create, getTaInvoiceBean());
			// }

			// -----------------下载天安的收货人信息------------------云天化-------20014--------------------------------------------------

			// create.createLoginCpzsHandset(deviceId);
			// if (create.isResult()) {
			// Prot20014ReqTAConsignee consignee = new
			// Prot20014ReqTAConsignee();
			// consignee.dealConsigneeList(create);
			// System.err.println("获取到收货人信息：" +
			// consignee.getConsignees().toString());
			// }

			// -----------------获取天安收货地址信息------------------云天化-------20015--------------------------------------------------

			// create.createLoginCpzsHandset(deviceId);
			// if (create.isResult()) {
			// Prot20015ReqTAddress reqTAddress = new Prot20015ReqTAddress();
			// reqTAddress.dealAddressList(create);
			// System.err.println("获取到地址列表：" +
			// reqTAddress.getAddress().toString());
			// }
			// ---------------获取云天化版带图片的--------------------产品列表-------20006--------------------------------------------------

			// create.createLoginCpzsHandset(deviceId);
			// System.err.println(" isResult:" + create.isResult());
			// if (create.isResult()) {
			// Prot20006Product p = new Prot20006Product();
			// p.reqProductList(create, new
			// Prot20001ReqBean(String.valueOf(deviceId)));
			// System.err.println(" " + (p.getResBean().getList() != null));
			// }

			// -----------------------------------云天化激活-------20007--------------------------------------------------

			// create.createLoginCpzsHandset(deviceId);
			// System.err.println(" isResult:" + create.isResult());
			// if (create.isResult()) {
			// Prot20007Activate activate = new Prot20007Activate();
			// activate.submitActivateInfo(create,
			// getYthSingleActivateBean());// 单标激活
			// }

			// -----------------提交发货信息---------------云天化-------20010--------------------------------------------------

			// create.createLoginCpzsHandset(deviceId);
			// if (create.isResult()) {
			// Prot20010SubmitInvoice submitInvoice = new
			// Prot20010SubmitInvoice(); //
			//// submitInvoice.submitInvoice(create, getT51ReqBean());
			// submitInvoice.submitInvoice(create, getT51TrainReqBean());
			// System.err.println("--" +
			// submitInvoice.getResponse().toString());
			// }

			// -------------------检测packageID----------------云天化-------20009--------------------------------------------------

			// create.createLoginCpzsHandset(deviceId);
			// if (create.isResult()) {
			// Prot20009CheckPackageId packageId = new
			// Prot20009CheckPackageId();
			// packageId.dealCheckPackageId(create, new
			// Prot10061ReqBean("1002185670224854"));
			// System.err.println("--" + packageId.getRes().toString());
			// }

			// -----------------请求地址列表------------------云天化-------20011--------------------------------------------------

			// create.createLoginCpzsHandset(deviceId);
			// if (create.isResult()) {
			// Prot20011ReqStationManager reqStationManager = new
			// Prot20011ReqStationManager();
			// reqStationManager.dealStationList(create);
			// System.err.println("--" +
			// reqStationManager.getStations().toString());
			// }

			// -----------------请求火车地址列表------------------云天化-------20012--------------------------------------------------

			// create.createLoginCpzsHandset(deviceId);
			// if (create.isResult()) {
			// Prot20012ReqTrainStation reqStationManager = new
			// Prot20012ReqTrainStation();
			// reqStationManager.dealStationList(create);
			// System.err.println("--" +
			// reqStationManager.getStations().toString());
			// }

			// -----------------请求客户信息------------------云天化-------20013--------------------------------------------------

			// create.createLoginCpzsHandset(deviceId);
			// if (create.isResult()) {
			// Prot20013ReqConsignee req = new Prot20013ReqConsignee();
			// req.dealConsigneeList(create);
			// System.err.println("--" + req.getConsignees().toString());
			// }

			// -----------------------------------1-出库 2-入库 3-销售 4-返库 5-采集 6-运输
			// 7-贮藏-------2000--------------------------------------------------

			// create.createLoginCpzsHandset(deviceId);
			// if (create.isResult()) {
			// Prot20005LabelOption p = new Prot20005LabelOption();
			// System.err.println("上传：" + getLabelOptionReqBean());
			// p.submitLabelOptionInfo(create, getLabelOptionReqBean());
			// }

			// -----------------------------------打包-------20003--------------------------------------------------

			// create.createLoginCpzsHandset(deviceId);
			// if (create.isResult()) {
			// Prot20003Pack p = new Prot20003Pack();
			// p.submitPackInfo(create, getProt20003ReqBean());
			// }

			// -----------------------------------拆包-------20004--------------------------------------------------

			// create.createLoginCpzsHandset(deviceId);
			// if (create.isResult()) {
			// Prot20004Unpack p = new Prot20004Unpack();
			// p.submitUnpackInfo(create, new
			// Prot20004ReqBean("1002185670211234"));
			// System.err.println(getLabelId("100001002679") + " " +
			// (p.getResBean().toString()));
			// long label = 100218567021L;// 100218567021L;
			// for (int i = 0; i < 20; i++) {
			// label++;
			// p.submitUnpackInfo(create, new
			// Prot20004ReqBean(getLabelId(String.valueOf(label))));
			// System.err.println("i:" + i + " " + (p.getResBean().toString()));
			// }
			// }

			// -----------------------------------获取产品列表-------20001--------------------------------------------------

			// create.createLoginCpzsHandset(deviceId);
			// System.err.println(" isResult:" + create.isResult());
			// if (create.isResult()) {
			// Prot20001Product p = new Prot20001Product();
			// p.reqProductList(create, new
			// Prot20001ReqBean(String.valueOf(deviceId)));
			// System.err.println("" + (p.getResBean().getList() != null));
			// }

			// -----------------------------------获取云天化版带图片的产品列表-------10080--------------------------------------------------

			// create.createLoginCpzsHandset(deviceId);
			// System.err.println(" isResult:" + create.isResult());
			// if (create.isResult()) {
			// Prot10080Product p = new Prot10080Product();
			// p.reqProductList(create, new
			// Prot20001ReqBean(String.valueOf(deviceId)));
			// System.err.println(" " + (p.getResBean().getList() != null));
			// }

			// -----------------------------------云天化激活-------10080--------------------------------------------------

			// create.createLoginCpzsHandset(deviceId);
			// System.err.println(" isResult:" + create.isResult());
			// if (create.isResult()) {
			// Prot10079Activate activate = new Prot10079Activate();
			// activate.submitActivateInfo(create,
			// getYthSingleActivateBean());// 单标激活
			// activate.submitActivateInfo(create, getBatchActivateBean());//
			// 批量激活
			// }

			// -----------------------------------激活---------------------------------------------------------

			// create.createLoginCpzsHandset(deviceId);
			// System.err.println(" isResult:" + create.isResult());
			// if (create.isResult()) {
			// Prot20002Activate activate = new Prot20002Activate();
			// activate.submitActivateInfo(create, getSingleActivateBean());//
			// 单标激活
			// // activate.submitActivateInfo(create,getBatchActivateBean());//
			// // 批量激活
			// }

		} catch (BindException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ConnectException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SocketTimeoutException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (UnknownHostException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			new Prot02Logout().dealLogout(create);
		}
	}

	private static Prot20026ReqBean getSheepWarehouseBean() {
		Prot20026ReqBean reqBean = new Prot20026ReqBean();
		reqBean.setArea_id(100000);
		reqBean.setCreate_time("2017-06-15 14:52:00");
		reqBean.setDealer_id(1);
		reqBean.setOpt(1);
		reqBean.setRemark("Echo Test 2");
		reqBean.setList(getSheepWarehouseList());
		return reqBean;
	}

	private static List<SheepWarehouseBean> getSheepWarehouseList() {
		List<SheepWarehouseBean> list = new ArrayList<>();
		
//		long startLabel = 100002106642L;
//		for (int i = 0; i < 10; i++) {
//			SheepWarehouseBean sBean1 = new SheepWarehouseBean();
//			sBean1.setActive_id(i+1);
//			sBean1.setActual_num(100);
//			sBean1.setProduct_id("100003");//1.31 GB/2.66 GB  1.31 GB、2.66 GB
//			sBean1.setStart(getLabelId(String.valueOf(startLabel+1)));
//			startLabel = startLabel + 100;
//			sBean1.setEnd(getLabelId(String.valueOf(startLabel)));//7143
//			list.add(sBean1);
//			
//		}
		SheepWarehouseBean sBean1 = new SheepWarehouseBean();
		sBean1.setActive_id(10);
		sBean1.setActual_num(100);
		sBean1.setProduct_id("100002");
		sBean1.setStart(getLabelId("100002106643"));
		sBean1.setEnd(getLabelId("100002107143"));//7143    100001207143
		list.add(sBean1);
//		
		
		SheepWarehouseBean sBean = new SheepWarehouseBean();
		sBean.setActive_id(11);
		sBean.setActual_num(10);
		sBean.setProduct_id("100002");
		sBean.setStart(getLabelId("100002108843"));
		sBean.setEnd(getLabelId("100002109943"));//7143    100002207143
		list.add(sBean);
		
		
		
		
		return list;
	}

	private static Prot20025ReqBean getSubmitHandsetBean() {
		// TODO Auto-generated method stub
		Prot20025ReqBean reqBean = new Prot20025ReqBean();
		String json = "{\"androidReleaseVersion\":\"5.2\",\"appInfos\":[\"Site Pyo\",\"物流终端\",\"入库工具\",\"计步器\",\"花粉儿\",\"搜狗输入法\",\"美团\",\"安兔兔评测\",\"扫一扫\",\"豌豆荚连接服务\",\"大众点评\",\"查询\",\"EchoRecyclerview\",\"图片浏览\",\"Multiple Images Selector\",\"ChinaTrace\",\"微信\",\"记事本\",\"AndroidTest02\",\"应用宝\",\"手机百度\",\"Material Everywhere\",\"高德定位SDK示例\",\"91VPN\",\"鲁大师手机助手\",\"中国追溯\",\"echoIonic\",\"宠托邦\",\"APKPure\",\"RecyclerViewDemo\",\"智能扫描小工具\",\"画板\",\"手持机\",\"GenSignature\",\"灭火器\",\"Barcode Scanner\",\"Video List\",\"Dome\",\"QQ\",\"平安口袋银行\",\"网易新闻\",\"稽查\",\"我查查\",\"Cropper Sample\",\"GalleryFinal\",\"PhotoView Sample\",\"豌豆荚\",\"喜马拉雅FM\",\"百度地图\",\"Google Maps API Demos\",\"AliImageEngine\",\"TO-DO-MVP\",\"cnodejs\",\"AlxImageLoader\",\"HuJiang\",\"AMaps3D Demos\",\"谷歌服务\",\"视频解码器\",\"360手机助手\",\"HeadZoomScrollView\",\"noder\",\"AlxYoutubePlayer\",\"翻译\",\"RecyclerViewLoadMore\",\"ijkmediademo\",\"TestActionBar\",\"DisplayingBitmaps\",\"AndroidSystemUiTraining\",\"手机京东\",\"换机助手\",\"农产品\",\"ImageListViewRefresh\",\"BuzzerBeater\",\"QR_CodeScan\",\"携程旅行\",\"echoMap\",\"微博\",\"AndroidSwipeLayout\",\"NetworkConnection\",\"鲁大师\",\"EchoImageLoader\",\"PowerRecyclerView\",\"ShareSDK第三方平台登录示例\",\"MultiWindowSDKExample\",\"支付宝\",\"SwipeToLoadLayout Demo\"],\"brand\":\"Meizu\",\"cpuName\":\"AArch64 Processor rev 2 (aarch64)\",\"imei\":\"868746024641440\",\"mac\":\"38:bc:1a:3f:b3:75\",\"memoryAvailableCapacity\":1445359616,\"memoryAvailableCapacityDes\":\"1.35 GB\",\"memoryTotalCapacity\":2860711936,\"memoryTotalCapacityDes\":\"2.66 GB\",\"sdcardAvailableCapacity\":2933022720,\"sdcardAvailableCapacityDes\":\"2.73 GB\",\"sdcardTotalCapacity\":12553089024,\"sdcardTotalCapacityDes\":\"11.69 GB\",\"serial\":\"85GABMCJWH6D\",\"sysAvailableCapacity\":80429056,\"sysAvailableCapacityDes\":\"76.70 MB\",\"sysTotalCapacity\":1560133632,\"sysTotalCapacityDes\":\"1.45 GB\",\"wifiIp\":\"10.0.2.12\"}";
		reqBean.setImei("868746024641440");//868746024641440
		reqBean.setHandset_parameter(json);
		return reqBean;
	}

	private static Prot20017ReqBean get20017ReqBean() {
		// 100001002781
		Prot20017ReqBean reqBean = new Prot20017ReqBean();
		List<String> labels = new ArrayList<>();
		long startLabel = 100001002781L;// 100218567021L;
		for (int i = 0; i < 20; i++) {
			startLabel++;
			labels.add(getLabelId(String.valueOf(startLabel)));
		}
		// labels.add(getLabelId(String.valueOf(startLabel)));
		// labels.add(getLabelId(String.valueOf(startLabel+20)));
		labels.add("1234567894125456");

		reqBean.setLabels(labels);
		reqBean.setOpt(3);// 1-出库 2-入库 3-销售 4-返库 6-打包 8-激活

		return reqBean;
	}

	private static Prot20016ReqBean getTaInvoiceBean() {
		Prot20016ReqBean reqBean = new Prot20016ReqBean();
		reqBean.setTruck_number("京A050995");
		reqBean.setAccount("13552648105");
		reqBean.setRegion_id(1010000);
		reqBean.setAddress("红军营南路、瑞普大厦C座1");
		reqBean.setTeam("一班");
		reqBean.setConsignee("奉节县华维农业技术咨询有限公司1");
		reqBean.setUpload_time("2017-05-25 10:10:10");
		// reqBean.setLabel_id(getLabelTrueTData());
		reqBean.setLabel_id(getSingleLabel());
		return reqBean;
	}

	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(0);
		invoiceBean.setTerminal_station(17);
		invoiceBean.setCustomer_id(1);
		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<>();
		System.out.println(getLabelId("100218567022"));
		label.add(getLabelId("100218567022"));
		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;
	}

	private static Prot20005ReqBean getLabelOptionReqBean() {
		Prot20005ReqBean reqBean = new Prot20005ReqBean();
		reqBean.setLabels(getSingleLabel());
		reqBean.setOpt(3);// 1-出库 2-入库 3-销售 4-返库 5-采集 6-运输 7-贮藏
		reqBean.setOpt_description("测试销售1");
		reqBean.setSales_area(1042900);
		return reqBean;
	}

	private static Prot20003ReqBean getProt20003ReqBean() {
		Prot20003ReqBean pBean = new Prot20003ReqBean();
		pBean.setPackage_id(getLabelId("100218567021"));
		pBean.setSingle(getSingleLabel());
		System.err.println(" 上传的数据：" + pBean.toString());
		return pBean;
	}

	private static Prot10079ReqBean getYthSingleActivateBean() {
		Prot10079ReqBean reqBean = new Prot10079ReqBean();
		reqBean.setProduct_id("100001");
		reqBean.setProduce_date("2017-3-2");
		// reqBean.setProducer("生产者");
		reqBean.setProduce_batch("1234567");
		reqBean.setType(1);
		reqBean.setGroup_number("");
		reqBean.setFactory_code("358000000_6");
		reqBean.setSingle(getSingleLabel());
		return reqBean;
	}

	private static Prot20002ReqBean getBatchActivateBean() {
		Prot20002ReqBean reqBean = new Prot20002ReqBean();
		reqBean.setProduct_id("100001");
		reqBean.setProduce_date("2017-3-2");
		reqBean.setProducer("生产者");
		reqBean.setProduce_batch("1234567");
		reqBean.setType(2);
		reqBean.setBatcher(new Prot20002ReqBatchBean(getLabelId(String.valueOf(100218567022L)),
				getLabelId(String.valueOf(100218617022L))));
		return reqBean;
	}

	private static Prot20002ReqBean getSingleActivateBean() {
		Prot20002ReqBean reqBean = new Prot20002ReqBean();
		reqBean.setProduct_id("100001");
		reqBean.setProduce_date("2017-3-2");
		reqBean.setProducer("生产者");
		reqBean.setProduce_batch("1234567");
		reqBean.setType(0);
		reqBean.setSingle(getSingleLabel());
		return reqBean;
	}

	private static List<String> getSingleLabel() {
		List<String> list = new ArrayList<>();
		long startLabel = 100218567021L;// 100218567021L;
		for (int i = 0; i < 2000; i++) {
			startLabel++;
			if (i == 1999) {
				System.out.println(i + "当前label: " + getLabelId(String.valueOf(startLabel)));
			}
			list.add(getLabelId(String.valueOf(startLabel)));
		}
		return list;
	}

	private static String getLabelId(String id) {
		String labelId = LableUtil.getCheckNum(id);
		return labelId;
	}

}
