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.Prot10003ReqImage;
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.Prot10068ReqBean;

public class CheckFireExtinguisherTest {
	// static String labelid = "1002183441951137";//2000041000000000105462
	// 1002183441951137 1002183451943842
	static String labelid = "1000010032223636";// 汽车 1002185617251070
											// 1000051989353205
	static String inspectorID = "868746024641440";// 小米note：865982026661184
													// 红米：863985026541738
													// 魅族：868746024641440
	// 崔哥手机：864367021078967 三星：353765071931886 龙哥手机：866697020552135
	// 联想：866622020589697 云天化正式：355066063970208

	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;
		// 补齐追溯码后四位
		// System.err.println(" 补齐labelID后四位 " + getLabelId("100218900000"));
//		labelid = getLabelId(labelid);// 1000010032307479
//		System.err.println(" 补齐labelID后四位 " + labelid);
		SocketCreate create = new SocketCreate(ip, port, inspectorID);
		int count = 0;
		try {
			// 默认登录账号："081182914";
			// 默认登录密码：MD5.GetMD5Code("0104");
			/*
			 * 后台： http://218.245.0.109:8080/jymf/admin/main?lang=zh_CN admin
			 * 123456
			 */
			// 测试标签：1002185616836936 1002185616847905 1002185616862233
			// 1002185616879213
			// --------------------------------------10001稽查身份登录---------------16位码和22位码通用-----------------------------------------------------------
			/*
			 * create.createJustCreateSocket(); Prot10001Login login = new
			 * Prot10001Login(); login.dealCpzsCheck(create, getLoginT());
			 */
			// System.err.println(" " + login.getLoginResult().toString());
			// System.err.println("md5:"+MD5.GetMD5Code("0104"));
			/*
			 * for (int i = 0; i < 1000; i++) { count++;
			 * create.createJustCreateSocket(); Prot10001Login login = new
			 * Prot10001Login(); login.dealCpzsCheck(create, getLoginT()); }
			 */

			// --------------------------------------获取灭火器产品信息
			// 10068---------------16位码和22位码通用-----------------------------------------------------------
			/*
			 * create.createLoginCpzs(Long.parseLong(labelid)); if
			 * (create.isResult()) { Prot10068FireExtinguisher fire = new
			 * Prot10068FireExtinguisher(); fire.dealFireExtinguisher(create,
			 * getFireReqBean()); System.err.println(" fireRes " +
			 * fire.getFireRes().toString()); }
			 */

			// {"address":"瑞普大夏","check_date":"2016-10-04","check_user":"李扬","check_user_tel":"15726673655","company_name":"哈尔滨消防公司测试","next_check_date":"2017-10-04","num":"50000","product_name":"产品名称","surplus":"9"}

			// --------------------------------------获取产品信息10021---------------16位码和22位码通用-----------------------------------------------------------
			// {"gx":[{"name":"1","value":"11"}],"bz":[{"name":"2","value":"22"}],"yl":[{"name":"3","value":"33"},{"name":"4","value":"44"}]}
			/*
			 * create.createLoginCpzs(Long.parseLong(labelid)); if
			 * (create.isResult()) { Prot10021ProductInfo info = new
			 * Prot10021ProductInfo(); System.out.println(" cID: " +
			 * create.getiCompanyId() +"  pID; " + create.getiProductId());
			 * info.dealProductInfo(create,
			 * get10021Bean16(create.getiCompanyId(), create.getiProductId()));
			 * System.err.println("结果：" + info.getProductInfoResult());
			 * 
			 * info.getProductInfoResult().getBz(); }
			 */

			// --------------------------------------获取产品的图片---------------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());
			 */

			create.createLoginCpzs(Long.parseLong(labelid));
			Prot10003ReqImage reqImage = new Prot10003ReqImage();
			reqImage.dealProductImage(create, getReqProductImage());
			System.err.println("  ImageResult:" + reqImage.getImageResult());

		} 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 {
			System.err.println("count:" + count);
			new Prot02Logout().dealLogout(create);
		}

	}

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

	private static Prot10068ReqBean getFireReqBean() {
		Prot10068ReqBean b = new Prot10068ReqBean();
		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(1);// 1- 企业介绍,2- 产品介绍,3- 产品概述,4- 广告概述,5- 红酒城图片
		return reqBean;
	}
//	{"list":[{"companyUrl":"","img":"M00/0A/6A/wKgBBVihb46AVYl7AACRK0DwaCs585.jpg","name":""},{"companyUrl":"","img":"M00/0A/6A/wKgBBVihb4-AHVCyAAEPR4q5sG0897.jpg","name":""}],"url":"http://218.245.0.109:8088/"}
	private static Prot10003ReqBean getReqProductImage() {
		// TODO Auto-generated method stub
		Prot10003ReqBean reqBean = new Prot10003ReqBean();
		reqBean.setLabel_id(labelid);
		reqBean.setImage_type(2);// 1- 企业介绍,2- 产品介绍,3- 产品概述,4- 广告概述,5- 红酒城图片
//		1- 企业介绍,2- 产品介绍,3- 产品概述,4- 广告概述,5- 红酒城图片,6-红酒城检疫证图片,7-红酒城入馆单图片,8-公司JSON,9-产品JSON,10-质检图片
		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("081182914");
		bean.setInspectorID(inspectorID);
		bean.setInspector_pwd(MD5.GetMD5Code("0104"));
		// bean.setCompanyID("558000002");
		// 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;
	}

}
