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.Prot10001Login;
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.Prot10088ReqBean;

public class CheckNewPT {
	static String labelid = "2000041000000000105462";//2000041000000000105462
//	static String inspectorID = "868746024641440";//864367021078967       865982026661184
	static String inspectorID = "";
	//小米note：865982026661184   红米：863985026541738 魅族：868746024641440  
			//崔哥手机：864367021078967    三星：353765071931886
	public static void main(String[] args) {
		String ip = "218.245.0.109";//218.245.0.109    192.168.0.46
		int port = 8898;
		
		SocketCreate create = new SocketCreate(ip, port,inspectorID);
//		Prot10001Login login = new Prot10001Login(); 
		try {
			//--------------------------------------提交稽查用户的扫码记录--------------------------------------------------------------------------
			/*long labelId = Long.parseLong(getLabelId("100002099321"));//100002099321(3580000020)   100002099342(358000021)
			create.createLoginCpzs(labelId);
			if (create.isResult()) {
				Prot10088SubmitScannerLog scannerLog = new Prot10088SubmitScannerLog();
				scannerLog.submitScannerLog(create, getProt10088ReqBean(labelId));
			}*/
			
			
			
//			System.err.println(getLabelId("10025344094"));
			
			//--------------------------------------获取产品的详细信息--------------------------------------------------------------------------
			//{"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}
//			create.createLoginCpzs(labelid);
			/*Prot10020ProductDesc productDesc = new Prot10020ProductDesc();
			productDesc.dealProductInfo(create, getP20ReaBean());
			System.err.println("  ProductInfoResult:" + productDesc.getProductInfoResult());*/
			
			//--------------------------------------获取产品的图片--------------------------------------------------------------------------
			//{"list":[{"companyUrl":"","img":"M00/07/D4/wKgBBVdqKQeAOBOfAAAmXfs7dgc061.jpg","name":""}],"url":"http://218.245.0.109:8088/"}
			/*Prot10003ReqImage reqImage = new Prot10003ReqImage();
			reqImage.dealProductImage(create, getReqImage());
			System.err.println("  ImageResult:" + reqImage.getImageResult());*/
			
			//--------------------------------------获取产品的销售地址--------------------------------------------------------------------------
			/*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":""}
//			create.createLoginCpzsCheck(358000020);
//			create.createJustCreateSocket();
//			create.createLoginCpzsCheck(358000020);
//			Prot10013QueryCount queryCount = new Prot10013QueryCount();
//			queryCount.dealQueryCount(create, get10013Req());
//			System.err.println("   QueryCountResult:" + queryCount.getQueryCountResult());
			
			//--------------------------------------获取窜货信息-------------------------------------------------------------------------
//			create.createLoginCpzsCheck(358000087);
//			Prot11DownConflictInfo conflictInfo = new Prot11DownConflictInfo();
////	        conflictInfo.dealDownConflictInfo(create, pageNo);//按照页数请求，每页12条数据
////	        conflictInfo.dealAllConflictInfo(create,10000);
////	        conflictInfo.dealConflictInfoByPage(create, 20, 1);
//	        conflictInfo.dealNewConflictInfoByPage(create, 20, 1);
//	        String conficationStr = conflictInfo.getJsonData();
//	        System.err.println("-conficationStr--" + conficationStr);
			//--------------------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 Prot10088ReqBean getProt10088ReqBean(long labelId) {
		Prot10088ReqBean reqBean = new Prot10088ReqBean();
		reqBean.setUser_id("868746024641440");
		reqBean.setJwd("116.425747,40.032955");
		reqBean.setArea_id(110105);
		reqBean.setLabel_id(String.valueOf(labelId));//100001002573
		reqBean.setCompany_id("358000021");
		return reqBean;
	}

	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(3);//1- 企业介绍,2- 产品介绍,3- 产品概述,4- 广告概述,5- 红酒城图片
		return reqBean;
	}

	private static Prot10020ReqBean getP20ReaBean() {
		// TODO Auto-generated method stub
		Prot10020ReqBean reqBean = new Prot10020ReqBean();
		reqBean.setCompany_id("458000221");
		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("358000020");
		bean.setInspectorID("15117958565");
		bean.setInspector_pwd(MD5.GetMD5Code("0000"));
//		bean.setMobile("13596161374");
//		bean.setMobile_pwd(MD5.GetMD5Code("0000"));
		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;
	}

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