package cn.net.cpzslibs.prot.handset;

import com.google.gson.Gson;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.SocketTimeoutException;
import java.util.HashMap;
import java.util.Map;

import cn.net.cpzslibs.prot.ProtBase;
import cn.net.cpzslibs.prot.SocketCreate;

/**
 * 提交车辆信息
 * 
 * @author zwj
 * 
 * @date 2015-12-29 下午3:08:49
 */
public class Prot35CarSubmitInfo extends ProtBase {
	private final short iTaskCode35 = 35;

	public void dealProt(SocketCreate socketCreate, String car_no, String engine_no, String vin, String label_id)
			throws IOException {
		Gson gson = new Gson();
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("car_no", car_no);
		map.put("engine_no", engine_no);
		map.put("vin", vin);
		map.put("company_id", socketCreate.getiCompanyId());
		map.put("label_id", label_id);
		String sJson = gson.toJson(map);
		sendProt(socketCreate.getDos(), iTaskCode35, sJson);
		recProt(socketCreate.getDis(), iTaskCode35);
	}

	private void recProt(DataInputStream dis, short iTaskCode) throws IOException {
		recHeader(dis);
		recFFFF(dis, iTaskCode);
	}
	private void sendProt(DataOutputStream dos, short iTaskCode, String sJson) throws SocketTimeoutException,
			IOException {
		errLog(iTaskCode, sJson);
		byte[] sendJsons = string2bytes(sJson);
		short iBodySize = countBodySize(sendJsons);
		sendHeader(dos, iTaskCode, iBodySize);
		dos.write(sendJsons);
		sendCheckCode(dos);
	}
}
