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.Prot10052TransInfo;
import cn.net.cpzslibs.prot.SocketCreate;
import cn.net.cpzslibs.prot.bean.req.Prot10001LoginBean;
import cn.net.cpzslibs.prot.bean.req.Prot10003ReqBean;
import cn.net.cpzslibs.prot.bean.req.Prot10006ReqBean;
import cn.net.cpzslibs.prot.bean.req.Prot10009ReqBean;
import cn.net.cpzslibs.prot.bean.req.Prot10013ReqBean;
import cn.net.cpzslibs.prot.bean.req.Prot10020ReqBean;
import cn.net.cpzslibs.prot.bean.req.Prot10020ReqBean16;
import cn.net.cpzslibs.prot.bean.req.Prot10021ReqBean16;
import cn.net.cpzslibs.prot.bean.req.Prot10052ReqBean;
import cn.net.cpzslibs.prot.bean.res.Prot10052ResBean;

public class CheckNewYthPT {
//	static String labelid = "1002183441951137";//2000041000000000105462   1002183441951137  1002183451943842
	static String labelid = "1004213805232020";//汽车   1002185617251070  1000051989353205   
	static String inspectorID = "355066063970208";//小米note：865982026661184   红米：863985026541738 魅族：868746024641440
	//崔哥手机：864367021078967    三星：353765071931886 龙哥手机：866697020552135 联想：866622020589697
	public static void main(String[] args) {
		String ip = "218.245.0.108";//218.245.0.109    192.168.0.46  www.gjcpzlzs.com
		int port = 8002;
		//补齐追溯码后四位
//		System.err.println(" 补齐labelID后四位 " + getLabelId("100002099342"));
		
		
		SocketCreate create = new SocketCreate(ip, port,inspectorID);
//		Prot10001Login login = new Prot10001Login();
		try {
			//{"companyID":"458000221","productID":"100007","workMode":9}
//			create.createLoginCpzsCheck(login, getLoginT());
//			create.createLoginCpzsCheck(358000000);
			//--------------------------------------获取标签货运信息10052--------------16位码------------------------------------------------------------
			//{"batch_number":"1608091SFA","station_dec":"","station_name":"楚雄西","trans_id":"11","trans_time":"2016-08-09 05:54:00"}
//			labelid = getLabelId(labelid);
//			System.err.println(" labelid:" + labelid);
			create.createLoginCpzs(Long.parseLong(labelid));
			if (create.isResult()) {
				Prot10052TransInfo transInfo = new Prot10052TransInfo();
				transInfo.dealTransInfo(create,getTransBean());
				Prot10052ResBean resBean = transInfo.getTransInfo();
				System.err.println("-结果-" + resBean);
				
			}
			
			/*create.createLoginCpzs(Long.parseLong(labelid));
			Prot06GetAreaCode prot06GetAreaCode = new Prot06GetAreaCode();
			prot06GetAreaCode.dealGetAreaCode(create);//1010000
			System.err.println("   06areaCode" +prot06GetAreaCode.isSuccess() +"   " +create.getiErrCode()+"   "+ prot06GetAreaCode.getiAread());*/
			
			/*create.createLoginCpzs(Long.parseLong(labelid));
			Prot10006ReqSalesArea salesArea = new Prot10006ReqSalesArea();
			salesArea.dealProductSalesArea(create, get10006Req());
			System.err.println("-saleArea--" + salesArea.getSalesAreaResult());*/
			//--------------------------------------获取产品的详细信息10020--------------16位码------------------------------------------------------------
			/*create.createLoginCpzs(Long.parseLong(labelid));
			System.out.println(create.isResult() + "-----" + create.getiProductId() +"   " + create.getiErrCode());
			if (create.isResult()) {
				Prot10020ProductDesc16 pDesc16 = new Prot10020ProductDesc16();
				pDesc16.dealProductInfo(create, getP20ReqBean16(create.getiCompanyId(), create.getiProductId(), labelid));
				System.err.println("结果:"+pDesc16.getProductInfoResult());
			}*/
			//--------------------------------------获取产品的详细信息10020--------------------------------------------------------------------------
			//{"companyName":"烟草追溯模式测试公司","companyTel":"","companyUrl":"https://www.so.com/?src=so.com","consumeCode":"3036","description":"esse是韩国产的一种女式香烟，它的中文名为 爱喜 。这个烟是韩国烟草人参公社出品，它的全称为 ESSE Menthol，也叫 爱易，爱喜。它有粉色普通型、蓝色特醇型和绿色薄荷型，是极有女人缘的韩国烟，薄荷味入口清凉，比较经典的凉烟。test","name":"ESSE-test","origin":"222test","producer":"222test","productId":"100007","productUrl":"http://www.sou360.com/","query_des":"烟草追溯模式测试公司生产的ESSE 测试修改","tobaccoType":2}
//			1000 0209 9321 6988
			/*create.createLoginCpzs(Long.parseLong(labelid));
			Prot10020ProductDesc productDesc = new Prot10020ProductDesc();
			productDesc.dealProductInfo(create, getP20ReaBean());
			System.err.println("  ProductInfoResult:" + productDesc.getProductInfoResult());*/
			
			//--------------------------------------获取产品的图片---------------16位码和22位码通用-----------------------------------------------------------
			//{"list":[{"companyUrl":"","img":"M00/07/D4/wKgBBVdqKQeAOBOfAAAmXfs7dgc061.jpg","name":""}],"url":"http://218.245.0.109:8088/"}
			/*create.createLoginCpzs(Long.parseLong(labelid));
			Prot10003ReqImage reqImage = new Prot10003ReqImage();
			reqImage.dealProductImage(create, getReqImage());
			System.err.println("  ImageResult:" + reqImage.getImageResult());*/
			//--------------------------------------获取产品信息10021---------------16位码和22位码通用-----------------------------------------------------------
			//{"gx":[{"name":"含氮量","value":"》46.4%"},{"name":"净含量","value":"40kg"},{"name":"粒径","value":"（0.85~2.80）mm"},{"name":"化学成分","value":"N-P2O5-K2O 30-10-0"}],"bz":[{"name":"作用","value":"果菜、叶菜、块茎类作物、果树"},{"name":"浇灌用量","value":"3-6kg/亩次稀释350-100倍"},{"name":"过期","value":"生长旺盛期7-10天一次"},{"name":"撒施","value":"20-4-kg/每亩 追施2-3次"},{"name":"埋施","value":"20-60kg/每亩 追施1-2次"},{"name":"产品特点","value":"水溶性速度快、残渣少、黯淡+硝酸 、速效+长效、不含缩二脲、不烧根、不烧苗"}],"yl":[{"name":"执行标准,生产许可证","value":"GB 15063-2009,（滇）XK13-001-00013"},{"name":"肥料登记证","value":"云农肥（2008）准字0092号"},{"name":"公司网址","value":"http://www.yyth.com.cn"},{"name":"生产地址","value":"云南省曲靖市宣威市板桥街道云天化股份云峰分公司"},{"name":"服务热线","value":"400-7390111"},{"name":"免费电话","value":"800-8897766（座机拨打）"},{"name":"生产日期","value":"2016-03-03"}]}
//			create.createLoginCpzs(Long.parseLong(labelid));
//			if (create.isResult()) {
//				Prot10021ProductInfo info = new Prot10021ProductInfo();
//				info.dealProductInfo(create, get10021Bean16(create.getiCompanyId(), create.getiProductId()));
//				System.err.println("结果：" + info.getProductInfoResult());
//				
//				info.getProductInfoResult().getBz();
//			}
			
			
			//--------------------------------------获取产品的销售地址--------------------------------------------------------------------------
			/*Prot10006ReqSalesArea reqSalesArea = new Prot10006ReqSalesArea();
			reqSalesArea.dealProductSalesArea(create, get10006Req());
			System.err.println(" SalesAreaResult:" + reqSalesArea.getSalesAreaResult());*/
			
			//--------------------------------------获取产品的查询次数--------------------------------------------------------------------------
			//{"cons_count":1,"first_cons_area":0,"first_cons_time":"0","first_query_time":"20160622144939","play_id":0,"play_url":""}
			//{"cons_count":1,"first_cons_area":0,"first_cons_time":"0","first_query_time":"20160622144939","play_id":0,"play_url":""}
			/*Prot10013QueryCount queryCount = new Prot10013QueryCount();
			queryCount.dealQueryCount(create, get10013Req());
			System.err.println("   QueryCountResult:" + queryCount.getQueryCountResult());*/
			//--------------------10001------------------新版带密码的登录--------------------------------------------------------------------------
			/*create.createJustCreateSocket();
			Prot10001Login login = new Prot10001Login();
			login.dealCpzsCheck(create, getLoginT());*/
			//修改密码
			/*if (login.getLoginResult() != null) {
				if (login.getLoginResult().getResult() == 0) {
					login.dealCpzsCheck(create, getModifyPwdT());
				}
			}*/
			
			
			//--------------------------------------查询上下级标签--------------------------------------------------------------------------
			/*create.createLoginCpzsCheck(458000221);
			Prot10009SupSubLabel subLabel = new Prot10009SupSubLabel();
			subLabel.dealReqSupSub(create, getSupBean());*/
			/*if (create.isResult()) {
				Prot10009SupSubLabel subLabel = new Prot10009SupSubLabel();
				subLabel.dealReqSupSub(create, getSupBean());
				
			}*/
			
		} 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();
		} finally {
			new Prot02Logout().dealLogout(create);
		}
				
	}
	
	private static String getLabelId(String id){
		String labelId = LableUtil.getCheckNum(id);
		return labelId;
	}
	private static Prot10052ReqBean getTransBean() {
		Prot10052ReqBean b = new Prot10052ReqBean();
		b.setLabel(labelid);
		return b;
	}

	private static Prot10021ReqBean16 get10021Bean16(int companyId, long productId) {
		Prot10021ReqBean16 bean16 = new Prot10021ReqBean16();
		bean16.setCompany_id(String.valueOf(companyId));
		bean16.setProduct_id(String.valueOf(productId));
//		bean16.setProduct_id("100001");
//		bean16.setCompanyId(companyId);
		return bean16;
	}


	private static Prot10020ReqBean16 getP20ReqBean16(int companyId, long productId, String labelID) {
		Prot10020ReqBean16 req = new Prot10020ReqBean16();
		req.setCompanyId(String.valueOf(companyId));
		req.setLabelID(labelID);
		req.setProductId(String.valueOf(productId));
		return req;
	}

	private static Prot10009ReqBean getSupBean() {
		// TODO Auto-generated method stub
		Prot10009ReqBean reqBean = new Prot10009ReqBean();
		reqBean.setPackageId(labelid);
		reqBean.setType(1);//1-取父标签，2-取子标签
		reqBean.setUniqOfProduct(1);//同老协议902，汽配模式有效，同一产品返回一个标签，1-是 0-返回所有产品的所有标签
		return reqBean;
	}

	private static Prot10013ReqBean get10013Req() {
		// TODO Auto-generated method stub
		Prot10013ReqBean reqBean = new Prot10013ReqBean();
		reqBean.setLabel_id(labelid);
		reqBean.setApp_type(2);
//		reqBean.setCons_area(0);
//		reqBean.setCons_check_code(0);
//		reqBean.setLabel_type(1);
		reqBean.setTerminal_type(2000);
		return reqBean;
	}

	private static Prot10006ReqBean get10006Req() {
		// TODO Auto-generated method stub
		Prot10006ReqBean reqBean = new Prot10006ReqBean();
		reqBean.setLabel(labelid);
		return reqBean;
	}

	private static Prot10003ReqBean getReqImage() {
		// TODO Auto-generated method stub
		Prot10003ReqBean reqBean = new Prot10003ReqBean();
		reqBean.setLabel_id(labelid);
		reqBean.setImage_type(2);//1- 企业介绍,2- 产品介绍,3- 产品概述,4- 广告概述,5- 红酒城图片
		return reqBean;
	}

	private static Prot10020ReqBean getP20ReaBean() {
		// TODO Auto-generated method stub
		Prot10020ReqBean reqBean = new Prot10020ReqBean();
		reqBean.setCompany_id("358000000");
//		reqBean.setProduct_id("100007");
		reqBean.setLabel_id(labelid);//200004100000000010546
		return reqBean;
	}
//{"errcode":65459,"errmsg":"","result":1}密码错误  65534
	private static Prot10001LoginBean getLoginT() {
		Prot10001LoginBean bean = new Prot10001LoginBean();
		bean.setUserType(1);
//		bean.setCompanyID("358000091");
//		bean.setInspectorID(inspectorID);
//		bean.setInspector_pwd(MD5.GetMD5Code("0000"));
		bean.setCompanyID("358000020");
		bean.setMobile("18310342005");
		bean.setMobile_pwd(MD5.GetMD5Code("1111"));
		return bean;
	}
	private static Prot10001LoginBean getModifyPwdT() {
		Prot10001LoginBean bean = new Prot10001LoginBean();
		bean.setUserType(4);
		bean.setCompanyID("358000020");
		bean.setInspectorID(inspectorID);
//		bean.setDeviceID(inspectorID);
		bean.setInspector_pwd(MD5.GetMD5Code("0000"));
		return bean;
	}

}
