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 cn.net.cpzslibs.prot.Prot02Logout;
import cn.net.cpzslibs.prot.Prot20ProductDesc;
import cn.net.cpzslibs.prot.SocketCreate;
import cn.net.cpzslibs.prot.bean.req.Prot10001LoginBean;
import cn.net.cpzslibs.prot.bean.req.Prot10016ProductBean;
import cn.net.cpzslibs.prot.bean.req.Prot10046LabelBean;
import cn.net.cpzslibs.prot.bean.req.Prot10077ReqBean;
import cn.net.cpzslibs.prot.bean.req.Prot10078ReqBean;

public class CheckNewPortTest {
	static String labelId = "1000051981787595";

	public static void main(String[] args) {
		String ip = "218.245.0.109";// 218.245.0.109 192.168.0.46
		int port = 8898;// 8002
		SocketCreate create = new SocketCreate(ip, port, "18518626753");// 小米note：865982026661184
																		// 红米：863985026541738
																		// 魅族：868746024641440
		// 18010193187
		// 崔哥手机：864367021078967 三星：353765071931886
		try {
			// Prot10001Login login = new Prot10001Login();
			// login.dealCpzsCheck(create,getTLoginBean());
			// create.createLoginCpzsCheck(login,getTestLoginBean());
			// 获取产品列表
			// --------------------10016协议-------获取产品列表-------------------------------------------------------------------

			// Prot10001Login login = new Prot10001Login();
			// create.createLoginCpzsCheck(login,getTestLoginBean())
			/*
			 * create.createLoginCpzsCheck(358000091); Prot10016ProductList
			 * product = new Prot10016ProductList();
			 * product.dealProductList(create, getTestProductBean()); //
			 * System.err.println(" productResult:" +
			 * product.getProductResult().toString());
			 * System.err.println(product.getProductResult().getResult() +
			 * "----" +product.getProductResult().getTotalCount() +"--size:"+
			 * product.getProductResult().getProducts().size());
			 */
			// 获取标签
			// --------------------10046协议-------获取标签详情-------------------------------------------------------------------
			// [currPackCount=0, products=[Port10016ProductResultInfo
			// [id=100001, name=香菇, nid=1234567890], Port10016ProductResultInfo
			// [id=100005, name=劲仔小鱼测试test, nid=1234567890123],
			// Port10016ProductResultInfo [id=100006, name=渔乐天天（酱汁糖醋鱼）, nid=],
			// Port10016ProductResultInfo [id=100008, name=麻酱鸡蛋, nid=108],
			// Port10016ProductResultInfo [id=100009, name=柴鸡蛋, nid=109],
			// Port10016ProductResultInfo [id=100010, name=核桃, nid=110],
			// Port10016ProductResultInfo [id=100011, name=蘑菇宴, nid=111],
			// Port10016ProductResultInfo [id=100012, name=香油, nid=112],
			// Port10016ProductResultInfo [id=100013, name=精选杂粮,
			// nid=1234567890123], Port10016ProductResultInfo [id=100014,
			// name=好德斋大礼包, nid=], Port10016ProductResultInfo [id=100015,
			// name=未审核产品, nid=], Port10016ProductResultInfo [id=100016,
			// name=未审核产品1, nid=]], totalCount=12, errcode=0, errmsg=null,
			// result=0]
			/*
			 * create.createLoginCpzsCheck(358000091); Prot10016ProductList
			 * product = new Prot10016ProductList();
			 * product.dealProductList(create, getTestProductBean());
			 * System.err.println(" productResult:" +
			 * product.getProductResult().toString());
			 * create.createLoginCpzsCheck(358000091); Prot10046Label label =
			 * new Prot10046Label(); label.dealLabelList(create,
			 * getTestLabelBean()); System.err.println("  label:" +
			 * label.getLabelResult().toString());
			 */
			// 获取窜货信息
			// --------------------1101协议-------获取窜货信息-------------------------------------------------------------------
			// Prot10001Login login = new Prot10001Login();
			// create.createLoginCpzsCheck(login,getTestLoginBean());

			/*create.createLoginCpzsCheck(358000087);// 358000018 // 18310342005
			// if(login.getLoginResult().getResult() != 1) {}
			System.err.println("获取窜货信息");
			Prot11DownConflictInfo conflictInfo = new Prot11DownConflictInfo(); // //
			// conflictInfo.dealDownConflictInfo(create, 1);
			// conflictInfo.dealConflictInfoByPage(create, 20, 1); //
			// conflictInfo.dealAllConflictInfo(create, 10000);
			conflictInfo.dealNewConflictInfoByPage(create, 20, 1);
			System.out.println(conflictInfo.getJsonData() + "---" + conflictInfo.getiRecErrcode());*/

			// System.out.println("--loginResult--" + login.getLoginResult());
			// --------------------01协议登录-------获取图片-------------------------------------------------------------------
			/*
			 * String labelId = "1000020993216988";//1000020993149225
			 * 1000020993216988 create.createLoginCpzs(Long.parseLong(labelId));
			 * Prot01Login login = new Prot01Login("0");
			 * login.dealCpzsLogin(create, Long.parseLong(labelId));
			 * Prot03GetImage prot03GetImage = new Prot03GetImage();
			 * //{"list":[{"companyUrl":"","img":
			 * "M00/00/1B/wKgBA1ackYSAWwuoAAByyeUUU9M672.jpg","name":""}],"url":
			 * "http://218.245.0.109:8088/"}
			 * prot03GetImage.dealProductSummaryImage(create);//最终使用图片
			 * System.err.println("prot03:"+prot03GetImage.getJsonData());
			 */
			// --------------------20协议-------获取产品详细信息-------------------------------------------------------------------

			String labelId = "1000010025854727";// 1000051981787595经销商labelID
//			// 1000020993216988 // 1000051980158581 // 1000032357366199 //1000808408259225
////			labelId = getLabelId(labelId);
////			 System.err.println( " 补齐labelID后四位 " + labelId);
			create.createLoginCpzs(Long.parseLong(labelId));
			Prot20ProductDesc prot20ProductDesc = new Prot20ProductDesc();
			prot20ProductDesc.dealProdInfoSwitch(create);
			System.err.println("   jsonData:" + prot20ProductDesc.getJsonData());

			// --------------------1305协议-------获取消费次数-------------------------------------------------------------------
			// String labelId = "1000032357366199";//1000020993149225
			// 1000020993216988
//			String l = "100002099345";//1000020993424930
////			String l = "123456789102";
//			l = getLabelId(l);
//			System.out.println("查询的label：" + l);
//			create.createLoginCpzs(Long.parseLong(l)); 
//			if (create.isResult()) {
//				Prot13QueryCount prot13QueryCount = new Prot13QueryCount();
//				prot13QueryCount.dealCheckConsInfo1305(create); 
//			} else {
//				System.err.println("-getiErrCode-" + create.getiErrCode());
//			}
			
//			int queryCount = prot13QueryCount.getiConsCount();
//			prot13QueryCount.getiRecErrcode(); 
//			[imTerminalType=2000, iFirstQueryTime=20170505102710, iConsCount=2, iFirstConsArea=1010200, iFirstConsTime=20170505102718]
//					  queryCount:2
//			System.out.println("  queryCount:" + queryCount +"   " + prot13QueryCount.getiRecErrcode() +"--");
			 
			// --------------------06协议-------获取销售地址-------------------------------------------------------------------
			/*
			 * String labelId = "1000032357373652";//1000020993149225
			 * 1000020993216988 create.createLoginCpzs(Long.parseLong(labelId));
			 * Prot06GetAreaCode prot06GetAreaCode = new Prot06GetAreaCode();
			 * prot06GetAreaCode.dealGetAreaCode(create);//1010000
			 * System.err.println("   06areaCode" +prot06GetAreaCode.isSuccess()
			 * +"   " +create.getiErrCode()+"   "+
			 * prot06GetAreaCode.getiAread());
			 */
			// [{"code":"5546","companyTel":"010-84369265","companyUrl":"http://www.baidu.com","companyname":"天津清泰故乡文化传播有限公司（测试）","description":"又名冬菇、香蕈、北菇、厚菇、薄菇、花菇、椎茸，是一种食用真菌。干鲜香菇在中国菜中广泛使用。烹饪时需将干香菇先行泡水发制。素三鲜中，香菇往往作为其中的一鲜出现。在斋食中，香菇亦为重要原料之一。由于营养丰富，香气沁脾，味道鲜美，素有“菇中之王”、“蘑菇皇后”、“蔬菜之冠”的美称。不但位列草菇、平菇之上，而且素有“植物皇后”之誉，为“山珍”之一。\r\n香菇是具有降血压、降血脂、降胆固醇：香菇中含有嘌呤、胆碱、酪氨酸、氧化酶以及某些核酸物质，能起到降血压、降胆固醇、降血脂的作用，又可预防动脉硬化、肝硬化等疾病。\r\n香菇还对糖尿病、肺结核、传染性肝炎、神经炎等起治疗作用，又可用于消化不良、便秘等。香菇营养成分一览。","id":"100001","name":"香菇","origin":"北京市朝阳区","producer":"农产品经销商","product_date":"","query_des":"清远农产品测试公司生产的香菇。","url":"http://www.sou360.com/"}]
			/*
			 * Prot20ProductDesc prot20ProductDesc = new Prot20ProductDesc();
			 * prot20ProductDesc.dealProdInfo(create); System.out.println(
			 * "    prot20ProductDesc:" + prot20ProductDesc.getJsonData());
			 * //{"gx":[{"name":"净含量","value":"100g"},{"name":"品种","value":"香菇"}
			 * ],"bz":[{"name":"工艺流程","value":"test"},{"name":"培育方式","value":
			 * "有机栽培"}],"yl":[{"name":"零售价","value":"100"}]} Prot21ProductInfo
			 * pInfo = new Prot21ProductInfo(); pInfo.dealProductInfo(create);
			 * System.err.println("   pInfo:" + pInfo.getJsonData());
			 */
			// -------------09协议-----地域查询 查询上级信息----
			// 查询下级信息-----------------------------------------------------
			// Prot10001Login login = new Prot10001Login();
			// create.createLoginCpzsCheck(login,getTestLoginBean());
			/*
			 * create.createLoginCpzsCheck(358000020); String labelId =
			 * "9000033099339520";//1000020993178852 1000020993216988
			 * 1000020993135543 Prot09UpDown prot09UpDown = new Prot09UpDown();
			 * prot09UpDown.deal9UpDown(create,Long.parseLong(labelId), (short)
			 * 1); List<Long> list9 = prot09UpDown.getList9();
			 * System.err.println("list9" + prot09UpDown.isSuccess() +"   "+
			 * list9.toString() +"   errorCode:" +
			 * prot09UpDown.getiRecErrcode());
			 * 
			 * //有值时返回 [1000020993193312, 1000020993209285, 1000020993216988,
			 * 1000020993224512] //无值时返回 >9<iRecResult:1 ; iRecErrcode:-35
			 * String labelId = "9000033099339520";//1000020993178852
			 * 1000020993216988 Prot09UpDown prot09UpDown = new Prot09UpDown();
			 * prot09UpDown.deal9UpDown(create,Long.parseLong(labelId), (short)
			 * 2); List<Long> list9down = prot09UpDown.getList9();
			 * System.err.println("list9down" + prot09UpDown.isSuccess() +"   "+
			 * list9down.toString());
			 */
			// -----------------------------提交窜货信息---------------------------------------------------------
			/*
			 * String labelId = "1000020993424930";//1000020993149225
			 * 1000020993216988 create.createLoginCpzs(Long.parseLong(labelId));
			 * Prot10UpdateConflict pConflict = new Prot10UpdateConflict();
			 */
			// pConflict.dealUpdateCnflictCpzsCheck(create, 1020500, 1030000);

			// ------------------------10077-----提交窜货信息---------------------------------------------------------

			// String labelId = "1000051981787595";// 1000020993149225
			/*
			 * create.createLoginCpzs(Long.parseLong(labelId)); if
			 * (create.isResult()) { Prot10077SubmitFleeingInfo
			 * submitFleeingInfo = new Prot10077SubmitFleeingInfo();
			 * submitFleeingInfo.submitFleeingInfo(create,
			 * getProt10077ReqBean(create)); System.err.println(" resBean: " +
			 * submitFleeingInfo.getProt10077ResBean().toString()); }
			 */
			// ------------------------10078-----提交使用稽查的情况---------------------------------------------------------

			// String labelId = "1000051981787595";// 1000020993149225
			/*
			 * create.createLoginCpzs(Long.parseLong(labelId));
			 * /*create.createLoginCpzs(Long.parseLong(labelId)); if
			 * (create.isResult()) { Prot10078CheckUsed submitCheck = new
			 * Prot10078CheckUsed(); submitCheck.submitCheckUsedInfo(create,
			 * getCheckUsedBean()); }
			 */
			// create.createJustCreateSocket();
			// Prot10078CheckUsed submitCheck = new Prot10078CheckUsed();
			// submitCheck.submitCheckUsedInfo(create, getCheckUsedBean());

			// pConflict.dealUpdateCnflictCpzsCheck(create, 1020500, 1030000);

		} catch (BindException e) {
			System.err.println("BindException:" + e.getLocalizedMessage());
			e.printStackTrace();
		} catch (ConnectException e) {
			System.err.println("ConnectException:" + e.getLocalizedMessage());
			e.printStackTrace();
		} catch (SocketTimeoutException e) {
			System.err.println("SocketTimeoutException:" + e.getLocalizedMessage());
			e.printStackTrace();
		} catch (UnknownHostException e) {
			System.err.println("UnknownHostException:" + e.getLocalizedMessage());
			e.printStackTrace();
		} catch (IOException e) {
			System.err.println("IOException:" + e.getLocalizedMessage());
			e.printStackTrace();
		} finally {
			new Prot02Logout().dealLogout(create);
		}
		// {"errcode":65494,"errmsg":"","result":1}
		// {"companyID":"358000020","productID":"0","workMode":0}
		// {"currPackCount":0,"products":[{"id":"100001","name":"香菇","nid":"1234567890"},{"id":"100005","name":"劲仔小鱼测试test","nid":"1234567890123"},{"id":"100006","name":"渔乐天天（酱汁糖醋鱼）","nid":""},{"id":"100008","name":"麻酱鸡蛋","nid":"108"},{"id":"100009","name":"柴鸡蛋","nid":"109"},{"id":"100010","name":"核桃","nid":"110"},{"id":"100011","name":"蘑菇宴","nid":"111"},{"id":"100012","name":"香油","nid":"112"},{"id":"100013","name":"精选杂粮","nid":"1234567890123"},{"id":"100014","name":"好德斋大礼包","nid":""}],"totalCount":"10"}
		// {"errcode":65519,"errmsg":"","result":1}
		// {"chuku_cnt":"64","jihuo_cnt":"40275","label_cnt":"157","name":"天津清泰故乡文化传播有限公司（测试）","ruku_cnt":"25","saoma_cnt":"0","yanzheng_cnt":"0"}
	}

	private static Prot10078ReqBean getCheckUsedBean() {
		Prot10078ReqBean reqBean = new Prot10078ReqBean();
		reqBean.setCompany_id("358000087");
		reqBean.setDevice_id("868746024641440");
		reqBean.setLabel_id(labelId);
		reqBean.setSale_area("");
		return reqBean;
	}

	private static Prot10077ReqBean getProt10077ReqBean(SocketCreate create) {
		Prot10077ReqBean reqBean = new Prot10077ReqBean();
		reqBean.setLabel_id(labelId);
		reqBean.setCompany_id(String.valueOf(create.getiCompanyId()));
		// reqBean.setCompany_id(company_id);
		reqBean.setProduct_id(String.valueOf(create.getiProductId()));
		reqBean.setSale_area("北京市·朝阳区");
		reqBean.setCollision_area("北京市·朝阳区");
		reqBean.setCollision_type(1);
		reqBean.setInspector_id(create.getsInspectorId());

		return reqBean;
	}

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

	private static Prot10001LoginBean getTLoginBean() {
		Prot10001LoginBean bean = new Prot10001LoginBean();
		return null;
	}

	private static Prot10046LabelBean getTestLabelBean() {
		Prot10046LabelBean labelBean = new Prot10046LabelBean();
		// labelBean.setProduct_id("100001");
		return labelBean;
	}

	private static Prot10001LoginBean getTestLoginBean() {
		Prot10001LoginBean bean = new Prot10001LoginBean();
		bean.setCompanyID("358000020");// 358000020
		bean.setMobile("18010193187");
		bean.setMobile_pwd("0000");
		bean.setUserType(1);
		return bean;
	}

	private static Prot10001LoginBean getTestCustomLoginBean() {
		Prot10001LoginBean bean = new Prot10001LoginBean();
		bean.setLabelID("1000020993861121");
		bean.setUserType(0);
		return bean;
	}

	private static Prot10016ProductBean getTestProductBean() {
		Prot10016ProductBean bean = new Prot10016ProductBean();
		bean.setCompany_id("358000052");// 358000020 //
		// bean.setDevice_id(device_id);
		bean.setMode(2);
		// bean.setAll_wine(isAll_wine);
		return bean;
	}
}
