public class GetCmdsHistoryApi extends AbstractAPI{

    private final Logger logger = LoggerFactory.getLogger(this.getClass());
    private HttpGetMethod HttpMethod;
    /***
     * 设备id
     **/
//    private String devId;
//    /***
//     * master-key
//     **/
//    private String key;
//    /***
//     * 指定开始时间,必选
//     **/
//    private String start;
//    /***
//     * 指定结束时间,可选
//     **/
//    private String end;
//    /***
//     * 时间间隔，可选，默认不传，单位秒，最大一周（duration和end只能选一个）
//     **/
//    private Integer duration;
//    /***
//     * 命令条数，默认10，最大6000
//     **/
//    private Integer limit;
//    /***
//     * 命令条数，默认10，最大6000
//     **/
//    private String cursor;
//
//    /***
//     * 值为DESC|ASC时间排序方式，DESC:降序，ASC升序，默认降序
//     **/
//    private String sort;
//


    /**
     * 根据响应状态查询，可选
     * 1：命令已创建| Command Created
     * 2：命令已发往设备| Command Sent
     * 3：命令发往设备失败| Send Command Failed
     * 4：设备正常响应| Command Response Received
     * 5：命令执行超时| Command Response Timeout
     * 6：设备响应消息过长 | Command Response Too Large
     */
//    private Integer status;

    /**
     * 查询历史命令分页列表请求构造方法
     * @param devId
     * @param key
     * @param start
     * @param end
     * @param duration
     * @param limit
     * @param cursor
     * @param sort
     * @param status
     */
    public GetCmdsHistoryApi(String devId, String key, String start, String end, Integer duration, Integer limit, String cursor, String sort, Integer status) {
//        this.devId = devId;
//        this.key = key;
//        this.start = start;
//        this.end = end;
//        this.duration = duration;
//        this.limit = limit;
//        this.cursor = cursor;
//        this.sort = sort;
//        this.status = status;

        this.method = Method.GET;
        Map<String, Object> headmap = new HashMap<String, Object>();
        Map<String, Object> urlmap = new HashMap<String, Object>();
        this.HttpMethod = new HttpGetMethod(method);
        Asserts.notBlank(devId,"devId");
        this.url = Config.getString("test.url") + "/cmds/history/"+devId;
        Asserts.notBlank(key,"api-key");
        headmap.put("api-key", key);
        if(start!=null){
            urlmap.put("start",start);
        }
        if(end!=null){
            urlmap.put("end",end);
        }
        if(duration!=null){
            urlmap.put("duration",duration);
        }
        if(limit!=null){
            urlmap.put("limit",limit);
        }
        if(cursor!=null){
            urlmap.put("cursor",cursor);
        }
        if(cursor!=null){
            urlmap.put("cursor",cursor);
        }
        if(sort!=null){
            urlmap.put("sort",sort);
        }
        if(status!=null){
            urlmap.put("status",status);
        }
        this.HttpMethod.setHeader(headmap);
        this.HttpMethod.setcompleteUrl(this.url,urlmap);
    }

    public BasicResponse<CmdsList> executeApi() {
        BasicResponse response;
//        mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
        try {
            HttpResponse httpResponse = HttpMethod.execute();
            InputStream instreams = httpResponse.getEntity().getContent();
            String str = IOUtils.toString(instreams, "UTF-8");
            response = mapper.readValue(str, BasicResponse.class);
            response.setJson(str);
            Object newData = mapper.readValue(mapper.writeValueAsString(response.getDataInternal()), CmdsList.class);
            response.setData(newData);
            return response;
        } catch (Exception e) {
            logger.error("error: {}", e.getMessage());
            throw new OnenetApiException(e.getMessage());
        } finally {
            try {
                HttpMethod.httpClient.close();
            } catch (Exception e) {
                logger.error("http close error: {}", e.getMessage());
                throw new OnenetApiException(e.getMessage());
            }
        }
    }
} public class CmdsList {
	@JsonProperty("cursor")
	private String cursor;
	@JsonProperty("count")
	private Integer count;

	@JsonProperty("items")
	private List<CmdsItem> items;

	public static class CmdsItem{
		@JsonProperty("cmd_uuid")
		private String cmdUuid;
		@JsonProperty("dev_id")
		private Integer devId;
		@JsonProperty("expire_time")
		private String expireTime;
		@JsonProperty("status")
		private Integer status;
		@JsonProperty("send_time")
		private String sendTime;
		@JsonProperty("confirm_time")
		private String confirmTime;
		@JsonProperty("confirm_body")
		private String confirm_body;
		@JsonProperty("body")
		private String body;

		public String getCmdUuid() {
			return cmdUuid;
		}

		public void setCmdUuid(String cmdUuid) {
			this.cmdUuid = cmdUuid;
		}

		public Integer getDevId() {
			return devId;
		}

		public void setDevId(Integer devId) {
			this.devId = devId;
		}

		public String getExpireTime() {
			return expireTime;
		}

		public void setExpireTime(String expireTime) {
			this.expireTime = expireTime;
		}

		public Integer getStatus() {
			return status;
		}

		public void setStatus(Integer status) {
			this.status = status;
		}

		public String getSendTime() {
			return sendTime;
		}

		public void setSendTime(String sendTime) {
			this.sendTime = sendTime;
		}

		public String getConfirmTime() {
			return confirmTime;
		}

		public void setConfirmTime(String confirmTime) {
			this.confirmTime = confirmTime;
		}

		public String getConfirm_body() {
			return confirm_body;
		}

		public void setConfirm_body(String confirm_body) {
			this.confirm_body = confirm_body;
		}

		public String getBody() {
			return body;
		}

		public void setBody(String body) {
			this.body = body;
		}
	}

	public String getCursor() {
		return cursor;
	}

	public void setCursor(String cursor) {
		this.cursor = cursor;
	}

	public Integer getCount() {
		return count;
	}

	public void setCount(Integer count) {
		this.count = count;
	}

	public List<CmdsItem> getItems() {
		return items;
	}

	public void setItems(List<CmdsItem> items) {
		this.items = items;
	}
} public class OrderConstant {
    /***
     * 正序
     **/
    public static final String ORDER_ASC = "ASC";
    /***
     * 正序
     **/
    public static final String ORDER_DESC = "DESC";
    /***
     * 不指定顺序，默认顺序
     **/
    public static final String ORDER_NONE = null;
} public class AddBindataApi extends AbstractAPI{
	private final Logger logger = LoggerFactory.getLogger(this.getClass());
	private  String devId;
	private  String datastreamId;
	private  String filename;
	private  String filepath;
	private HttpPostMethod HttpMethod;
	/**
	 * @param devId:数据所属设备（必选）,String
	 * @param datastreamId:该数据所属已经存在的数据流（必选）,String
	 * @param key:masterkey 或者 该设备的设备key
	 * @param filename:文件名,String
	 * @param filepath：路径,String
	 */
	public AddBindataApi(String devId, String datastreamId,String key, String filename,String filepath) {
		this.devId = devId;
		this.datastreamId = datastreamId;
		this.key=key;
		this.filename=filename;
		this.filepath=filepath;
		this.method=Method.POST;

        Map<String, Object> headmap = new HashMap<String, Object>();
        HttpMethod=  new HttpPostMethod(method);
        headmap.put("api-key", key);
        HttpMethod.setHeader(headmap);
        this.url=Config.getString("test.url")+"/bindata";
        Map<String, Object> urlmap = new HashMap<String, Object>();
        if(devId!=null){
            urlmap.put("device_id", devId);
        }
        if(datastreamId!=null){
            urlmap.put("datastream_id", datastreamId);
        }
        Map<String, String> fileMap=new HashMap<String, String>();
        fileMap.put(filename, filepath);
        ((HttpPostMethod)HttpMethod).setEntity(null,fileMap);
        HttpMethod.setcompleteUrl(url,urlmap);
	}

	public BasicResponse<NewBindataResponse> executeApi(){
		BasicResponse response=null;
		try {
			HttpResponse httpResponse=HttpMethod.execute();
			response = mapper.readValue(httpResponse.getEntity().getContent(),BasicResponse.class);
			response.setJson(mapper.writeValueAsString(response));
			Object newData = mapper.readValue(mapper.writeValueAsString(response.getDataInternal()), NewBindataResponse.class);
			response.setData(newData);
			return response;
			
		} catch (Exception e) {
			logger.error("json error {}", e.getMessage());
			throw new OnenetApiException(e.getMessage());
		}finally {
			try {
				HttpMethod.httpClient.close();
			} catch (Exception e) {
				logger.error("http close error: {}", e.getMessage());
				throw new OnenetApiException(e.getMessage());
			}
		}
		
	}
	
} public class GetBindataApi extends AbstractAPI{
	private final Logger logger = LoggerFactory.getLogger(this.getClass());
	private HttpGetMethod HttpMethod;
	private  String index;
	/**
	 * @param index:二进制数据索引号,String
	 * @param key:masterkey 或者 该设备的设备key
	 */
	public GetBindataApi(String index,String key) {
		this.index = index;
		this.key=key;
		this.method= Method.GET;
		this.HttpMethod=new HttpGetMethod(method);
        Map<String, Object> headmap = new HashMap<String, Object>();
        headmap.put("api-key", key);
        HttpMethod.setHeader(headmap);
        this.url = Config.getString("test.url") + "/bindata" + "/" + index;
        HttpMethod.setcompleteUrl(url,null);
	}

	public String executeApi() {
		String response=null;
         try {
        	 HttpResponse httpResponse=HttpMethod.execute();
			response = EntityUtils.toString(httpResponse.getEntity());
			return response;
		} catch (Exception e) {
			logger.error("error: {}" , e.getMessage());
			throw new OnenetApiException(e.getMessage());
		}finally {
			try {
				HttpMethod.httpClient.close();
			} catch (Exception e) {
				logger.error("http close error: {}", e.getMessage());
				throw new OnenetApiException(e.getMessage());
			}
		}
		
	}
} public class QueryCmdsRespApi extends AbstractAPI {
	private final Logger logger = LoggerFactory.getLogger(this.getClass());
	private HttpGetMethod HttpMethod;
	private String cmdUuid;

	/**
	 * @param cmdUuid:命令id,String
	 * @param key:masterkey或者设备apikey
	 */
	public QueryCmdsRespApi(String cmdUuid, String key) {
		this.cmdUuid = cmdUuid;
		this.key = key;
		this.method = Method.GET;
		this.HttpMethod = new HttpGetMethod(method);

		Map<String, Object> headmap = new HashMap<String, Object>();
		headmap.put("api-key", key);
		HttpMethod.setHeader(headmap);
		this.url = Config.getString("test.url") + "/cmds/" + cmdUuid + "/resp";
		HttpMethod.setcompleteUrl(url, null);
	}

	public String executeApi() {
		String resp = null;
		try {
			HttpResponse httpResponse = HttpMethod.execute();
			resp = EntityUtils.toString(httpResponse.getEntity());
			return resp;
		} catch (Exception e) {
			logger.error("json error {}", e.getMessage());
			throw new OnenetApiException(e.getMessage());
		} finally {
			try {
				HttpMethod.httpClient.close();
			} catch (Exception e) {
				logger.error("http close error: {}", e.getMessage());
				throw new OnenetApiException(e.getMessage());
			}
		}
		
	}
} public class QueryCmdsStatus extends AbstractAPI {
	private final Logger logger = LoggerFactory.getLogger(this.getClass());
	private HttpGetMethod HttpMethod;
	private  String cmdUuid;
	
	
	/**
	 * @param cmdUuid:命令id,String
	 * @param key:masterkey或者设备apikey
	 */
	public QueryCmdsStatus(String cmdUuid,String key) {
		this.cmdUuid = cmdUuid;
		this.key=key;
		this.method= Method.GET;
		this.HttpMethod=new HttpGetMethod(method);

        Map<String, Object> headmap = new HashMap<String, Object>();
        headmap.put("api-key", key);
        HttpMethod.setHeader(headmap);
        this.url = Config.getString("test.url") + "/cmds/" + cmdUuid;
        HttpMethod.setcompleteUrl(url,null);
	}


	public BasicResponse<CmdsResponse> executeApi() {
		BasicResponse response=null;
		try {
			HttpResponse httpResponse=HttpMethod.execute();
			response = mapper.readValue(httpResponse.getEntity().getContent(), BasicResponse.class);
			response.setJson(mapper.writeValueAsString(response));
			Object newData = mapper.readValue(mapper.writeValueAsString(response.getDataInternal()), CmdsResponse.class);
			response.setData(newData);
			return response;
		} catch (Exception e) {
			logger.error("json error {}", e.getMessage());
			throw new OnenetApiException(e.getMessage());
		}finally {
			try {
				HttpMethod.httpClient.close();
			} catch (Exception e) {
				logger.error("http close error: {}", e.getMessage());
				throw new OnenetApiException(e.getMessage());
			}
		}
		
	}

} public class SendCmdsApi  extends AbstractAPI {
	private final Logger logger = LoggerFactory.getLogger(this.getClass());
	private String devId;
	private Integer qos;
	private Integer timeOut;
	private Integer type;
	private Object contents;//用户自定义数据
	private HttpPostMethod HttpMethod;
	/**
	 * @param devId：接收该数据的设备ID（必选），String
	 * @param qos:是否需要响应，默认为0,Integer
	 * 0：不需要响应，即最多发送一次，不关心设备是否响应；
	 * 1：需要响应，如果设备收到命令后没有响应，则会在下一次设备登陆时若命令在有效期内(有效期定义参见timeout参数）则会继续发送。
	 * 对响应时间无限制，多次响应以最后一次为准。
	 * 本参数仅当type=0时有效；
	 * @param timeOut:命令有效时间，默认0,Integer
	 * 0：在线命令，若设备在线,下发给设备，若设备离线，直接丢弃；
	 *  >0： 离线命令，若设备在线，下发给设备，若设备离线，在当前时间加timeout时间内为有效期，有效期内，若设备上线，则下发给设备。单位：秒，有效围：0~2678400。
	 *  本参数仅当type=0时有效；
	 * @param type://默认0。0：发送CMD_REQ包，1：发送PUSH_DATA包
	 * @param contents:用户自定义数据：json、string、二进制数据（小于64K）
	 * @param key:masterkey或者设备apikey
	 */
	public SendCmdsApi(String devId, Integer qos, Integer timeOut, Integer type, Object contents,String key) {
		this.devId = devId;
		this.qos = qos;
		this.timeOut = timeOut;
		this.type = type;
		this.contents=contents;
		this.key = key;
		this.method = Method.POST;

        Map<String, Object> headmap = new HashMap<String, Object>();
        Map<String, Object> urlmap = new HashMap<String, Object>();
        HttpMethod=  new HttpPostMethod(method);
        headmap.put("api-key", key);
        HttpMethod.setHeader(headmap);
        this.url=Config.getString("test.url")+"/cmds";
        if(devId!=null){
            urlmap.put("device_id", devId);
        }
        if(qos!=null){
            urlmap.put("qos", qos);
        }
        if(timeOut!=null){
            urlmap.put("timeout", timeOut);
        }
        if(type!=null){
            urlmap.put("type", type);
        }
        //body参数处理
        if(contents instanceof byte[]){
        	((HttpPostMethod)HttpMethod).setEntity((byte[])contents);
        }
        if(contents instanceof String){
            ((HttpPostMethod)HttpMethod).setEntity((String)contents);
        }
        HttpMethod.setcompleteUrl(url,urlmap);
	}

	public BasicResponse<NewCmdsResponse> executeApi(){
		BasicResponse response=null;
		try {
			HttpResponse httpResponse=HttpMethod.execute();
			response = mapper.readValue(httpResponse.getEntity().getContent(),BasicResponse.class);
			response.setJson(mapper.writeValueAsString(response));
			Object newData = mapper.readValue(mapper.writeValueAsString(response.getDataInternal()), NewCmdsResponse.class);
			response.setData(newData);
			return response;

		} catch (Exception e) {
			logger.error("json error {}", e.getMessage());
			throw new OnenetApiException(e.getMessage());
		}finally {
			try {
				HttpMethod.httpClient.close();
			} catch (Exception e) {
				logger.error("http close error: {}", e.getMessage());
				throw new OnenetApiException(e.getMessage());
			}
		}
		
	}
} public class AddDatapointsApi extends AbstractAPI{
	private Map<String,List<Datapoints>> map;
	private String data;
	private Integer type;
	private  String devId;
	private HttpPostMethod HttpMethod;
	private final Logger logger = LoggerFactory.getLogger(this.getClass());
	/**
	 * @param map :数据点内容,Map<String,List<Datapoints>>
	 * @param data:提供简写方式上传数据,String
	 * 示例：
	 * type=4
	 * data="{\"temperature\":{\"2015-03-22T22:31:12\":22.5}}";
	 * type=5
	 * data=",;temperature,2015-03-22T22:31:12,22.5;pm2.5,89";
	 * @param type:上传数据类型（可选，默认为完整JSON型，见HTTP内容示例）
	 * @param devId:设备ID,String
	 * @param key:masterkey 或者 设备apikey
	 */
	public AddDatapointsApi(Map<String,List<Datapoints>> map, String data, Integer type, String devId,String key) {
		super();
		this.map = map;
		this.data = data;
		this.type = type;
		this.devId = devId;
		this.key=key;
		this.method=Method.POST;

        Map<String, Object> headmap = new HashMap<String, Object>();
        HttpMethod=  new HttpPostMethod(method);
        headmap.put("api-key", key);
        HttpMethod.setHeader(headmap);
        this.url=Config.getString("test.url")+"/devices/"+devId+"/datapoints";
        Map<String, Object> urlmap = new HashMap<String, Object>();
        if(type!=null){
            urlmap.put("type", type);
        }
        // body参数
        String json=null;
        try {
            if(map!=null){
                json = mapper.writeValueAsString(map);
            }
            else{
                json=data;//支持其他类型
            }
        } catch (Exception e) {
            logger.error("json error", e.getMessage());
            throw new OnenetApiException(e.getMessage());
        }
        ((HttpPostMethod)HttpMethod).setEntity(json);
        HttpMethod.setcompleteUrl(url,urlmap);
	}

	public BasicResponse<Void> executeApi() {
		BasicResponse response = null;
		try {
			HttpResponse httpResponse = HttpMethod.execute();
			response = mapper.readValue(httpResponse.getEntity().getContent(), BasicResponse.class);
			response.setJson(mapper.writeValueAsString(response));
			return response;
		} catch (Exception e) {
			logger.error("json error {}", e.getMessage());
			throw new OnenetApiException(e.getMessage());
		}finally {
			try {
				HttpMethod.httpClient.close();
			} catch (Exception e) {
				logger.error("http close error: {}", e.getMessage());
				throw new OnenetApiException(e.getMessage());
			}
		}
		
	}
} public class GetDatapointsListApi extends AbstractAPI{
	private HttpGetMethod HttpMethod;
	private String datastreamIds;
	private String start;
	private String end;
	private String devId;
	private Integer duration;
	private Integer limit;
	private String cursor;
	private Integer interval;
	private String metd;
	private Integer first;
	private String sort;
	private final Logger logger = LoggerFactory.getLogger(this.getClass());
	/**
	 * 数据点查询
	 * @param datastreamIds:查询的数据流，多个数据流之间用逗号分隔（可选）,String
	 * @param start:提取数据点的开始时间（可选）,String
	 * @param end:提取数据点的结束时间（可选）,String
	 * @param devId:设备ID,String
	 * @param duration:查询时间区间（可选，单位为秒）,Integer
	 *  start+duration：按时间顺序返回从start开始一段时间内的数据点
	 *  end+duration：按时间倒序返回从end回溯一段时间内的数据点
	 * @param limit:限定本次请求最多返回的数据点数，0<n<=6000（可选，默认1440）,Integer
	 * @param cursor:指定本次请求继续从cursor位置开始提取数据（可选）,String
	 * @param interval:通过采样方式返回数据点，interval值指定采样的时间间隔（可选）,Integer，参数已废弃
	 * @param metd:指定在返回数据点时，同时返回统计结果，可能的值为（可选）,String
	 * @param first:返回结果中最值的时间点。1-最早时间，0-最近时间，默认为1（可选）,Integer
	 * @param sort:值为DESC|ASC时间排序方式，DESC:倒序，ASC升序，默认升序,String
	 * @param key:masterkey 或者 设备apikey
	 */
	public GetDatapointsListApi(String datastreamIds, String start, String end, String devId, Integer duration,
			Integer limit, String cursor, @Deprecated Integer interval, String metd, Integer first, String sort,String key) {
		super();
		this.datastreamIds = datastreamIds;
		this.start = start;
		this.end = end;
		this.devId = devId;
		this.duration = duration;
		this.limit = limit;
		this.cursor = cursor;
		this.interval = interval;
		this.metd = metd;
		this.first = first;
		this.sort = sort;
		this.key=key;
		this.method= Method.GET;
		this.HttpMethod = new HttpGetMethod(method);

        Map<String, Object> headmap = new HashMap<String, Object>();
        Map<String, Object> urlmap = new HashMap<String, Object>();
        headmap.put("api-key", key);
        HttpMethod.setHeader(headmap);
        this.url = Config.getString("test.url") + "/devices/" + devId + "/datapoints";
        // url参数
        if (datastreamIds != null) {
            urlmap.put("datastream_id", datastreamIds);
        }
        if (start != null) {
            urlmap.put("start", start);
        }
        if (end != null) {
            urlmap.put("end", end);
        }
        if (duration != null) {
            urlmap.put("duration", duration);
        }
        if (limit != null) {
            urlmap.put("limit", limit);
        }
        if (cursor != null) {
            urlmap.put("cursor", cursor);
        }
        if (interval != null) {
            urlmap.put("interval", interval);
        }
        if (metd != null) {
            urlmap.put("method", metd);
        }
        if (first != null) {
            urlmap.put("first", first);
        }
        if (sort != null) {
            urlmap.put("sort", sort);
        }
        HttpMethod.setcompleteUrl(url, urlmap);
	}

	public BasicResponse<DatapointsList> executeApi() {
		BasicResponse response;
//        mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
		try {
			HttpResponse httpResponse = HttpMethod.execute();
			response = mapper.readValue(httpResponse.getEntity().getContent(), BasicResponse.class);
			response.setJson(mapper.writeValueAsString(response));
			Object newData = mapper.readValue(mapper.writeValueAsString(response.getDataInternal()),DatapointsList.class);
			response.setData(newData);

		} catch (Exception e) {
			e.printStackTrace();
			logger.error("error: {}", e.getMessage());
			throw new OnenetApiException(e.getMessage());
		}
		return response;

	}
} public class AddDatastreamsApi extends AbstractAPI{
	private final Logger logger = LoggerFactory.getLogger(this.getClass());
	private  String id;
	private  String devId;
	private  List<String> tags;
	private  String unit;
	private  String unitSymbol;
	private  String cmd;
	private  Integer interval;
	private  String formula;	
	private HttpPostMethod HttpMethod;
	/**
	 * 数据流新增
	 * @param id：数据流名称 ，String
	 * @param devId:设备ID,String
	 * @param tags:数据流标签（可选，可以为一个或多个）,List<Stirng>
	 * @param unit:单位（可选）,String
	 * @param unitSymbol:单位符号（可选）,String
	 * @param cmd:MODBUS设备填写，周期下发命令，16进制字节字符串
	 * @param interval:MODBUS设备填写，采集间隔，秒,Integer
	 * @param formula:MODBUS设备填写，寄存器计算公式（可选）,String
	 * @param key:masterkey 或者 设备apikey
	 */
	public AddDatastreamsApi(String id, String devId, List<String> tags, String unit, String unitSymbol, String cmd,
			Integer interval, String formula, String key) {
		super();
		this.id = id;
		this.devId = devId;
		this.tags = tags;
		this.unit = unit;
		this.unitSymbol = unitSymbol;
		this.cmd = cmd;
		this.interval = interval;
		this.formula = formula;
		this.key=key;
		this.method=Method.POST;
        Map<String, Object> headmap = new HashMap<String, Object>();
        HttpMethod=  new HttpPostMethod(method);
        headmap.put("api-key", key);
        HttpMethod.setHeader(headmap);
        this.url=Config.getString("test.url")+"/devices/"+devId+"/datastreams";
        // body参数
        Map<String, Object> bodymap = new HashMap<String, Object>();
        if(this.id!=null){
            bodymap.put("id", id);
        }
        if(this.tags!=null){
            bodymap.put("tags", tags);
        }
        if(this.unit!=null){
            bodymap.put("unit", unit);
        }
        if(this.unitSymbol!=null){
            bodymap.put("unit_symbol", unitSymbol);
        }
        if(this.cmd!=null){
            bodymap.put("cmd", cmd);
        }
        if(this.interval!=null){
            bodymap.put("interval", interval);
        }
        if(this.formula!=null){
            bodymap.put("formula", formula);
        }
        String json=null;
        ObjectMapper remapper = new ObjectMapper();
        try {
            json = remapper.writeValueAsString(bodymap);
        } catch (Exception e) {
            logger.error("json error {}", e.getMessage());
            throw new OnenetApiException(e.getMessage());
        }
        ((HttpPostMethod)HttpMethod).setEntity(json);
        HttpMethod.setcompleteUrl(url,null);
	}



	public BasicResponse<NewdatastramsResponse> executeApi(){
		BasicResponse response=null;
		try {
			HttpResponse httpResponse=HttpMethod.execute();
			response = mapper.readValue(httpResponse.getEntity().getContent(),BasicResponse.class);
			response.setJson(mapper.writeValueAsString(response));
			Object newData = mapper.readValue(mapper.writeValueAsString(response.getDataInternal()), NewdatastramsResponse.class);
			response.setData(newData);
			return response;
			
		} catch (Exception e) {
			System.out.println(e.getMessage());
			logger.error("json error {}", e.getMessage());
			throw new OnenetApiException(e.getMessage());
		}finally {
			try {
				HttpMethod.httpClient.close();
			} catch (Exception e) {
				logger.error("http close error: {}", e.getMessage());
				throw new OnenetApiException(e.getMessage());
			}
		}
	}
} public class DeleteDatastreamsApi extends AbstractAPI{
	private final Logger logger = LoggerFactory.getLogger(this.getClass());
	private String devId;
	private HttpDeleteMethod HttpMethod;
	private String datastreamId;
	/**
	 * @param devId
	 * @param datastreamId
	 * @param key
	 */
	public DeleteDatastreamsApi(String devId, String datastreamId,String key) {
		this.devId = devId;
		this.datastreamId = datastreamId;
		this.key=key;
		this.method = Method.DELETE;
        Map<String, Object> headmap = new HashMap<String, Object>();
        HttpMethod = new HttpDeleteMethod(method);
        headmap.put("api-key", key);
        HttpMethod.setHeader(headmap);
        this.url = Config.getString("test.url") + "/devices/" + devId+"/datastreams/"+datastreamId;
        HttpMethod.setcompleteUrl(url,null);
	}


	public BasicResponse<Void> executeApi() {
		BasicResponse response = null;
		try {
			HttpResponse httpResponse = HttpMethod.execute();
			response = mapper.readValue(httpResponse.getEntity().getContent(), BasicResponse.class);
			response.setJson(mapper.writeValueAsString(response));
			return response;
		} catch (Exception e) {
			logger.error("json error {}", e.getMessage());
			throw new OnenetApiException(e.getMessage());
		}finally {
			try {
				HttpMethod.httpClient.close();
			} catch (Exception e) {
				logger.error("http close error: {}", e.getMessage());
				throw new OnenetApiException(e.getMessage());
			}
		}
	}
} public class FindDatastreamListApi extends AbstractAPI {
	private HttpGetMethod HttpMethod;
	private String datastreamids;
	private String devId;
	private final Logger logger = LoggerFactory.getLogger(this.getClass());
	/**
	 * 查询多个数据流
	 * @param datastreamids:数据流名称 ,String
	 * @param devId:设备ID,String
	 * @param key:masterkey 或者 设备apikey
	 */
	public FindDatastreamListApi(String datastreamids, String devId, String key) {
		this.datastreamids = datastreamids;
		this.devId = devId;
		this.key = key;
		this.method = Method.GET;
		this.HttpMethod = new HttpGetMethod(method);
        Map<String, Object> headmap = new HashMap<String, Object>();
        Map<String, Object> urlmap = new HashMap<String, Object>();
        headmap.put("api-key", key);
        HttpMethod.setHeader(headmap);
        this.url = Config.getString("test.url") + "/devices/" + devId + "/datastreams";
        // url参数
        if (datastreamids != null) {
            urlmap.put("datastream_ids", datastreamids);
        }
        HttpMethod.setcompleteUrl(url, urlmap);
	}



	public BasicResponse<List<DatastreamsResponse>> executeApi() {
		BasicResponse response;
		/*ObjectMapper mapper = new ObjectMapper();
        mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));*/
		try {
			HttpResponse httpResponse = HttpMethod.execute();
			response = mapper.readValue(httpResponse.getEntity().getContent(), BasicResponse.class);
			response.setJson(mapper.writeValueAsString(response));
			Object newData = mapper.readValue(mapper.writeValueAsString(response.getDataInternal()),  new TypeReference<List<DatastreamsResponse>>(){});
			response.setData(newData);
			return response;
		} catch (Exception e) {
			logger.error("error: {}" , e.getMessage());
			throw new OnenetApiException(e.getMessage());
		}finally {
			try {
				HttpMethod.httpClient.close();
			} catch (Exception e) {
				logger.error("http close error: {}", e.getMessage());
				throw new OnenetApiException(e.getMessage());
			}
		}
		

	}
} public class GetDatastreamApi extends AbstractAPI{
	private final Logger logger = LoggerFactory.getLogger(this.getClass());
	private HttpGetMethod HttpMethod;
	private String datastreamId;
	private String devId;
	/**
	 * 查询单个数据流
	 * @param devId
	 * @param datastreamId
	 * @param key
	 */
	public GetDatastreamApi( String devId,String datastreamId,String key) {
		this.datastreamId = datastreamId;
		this.devId = devId;
		this.key = key;
		this.method = Method.GET;
        this.HttpMethod=new HttpGetMethod(method);
        Map<String, Object> headmap = new HashMap<String, Object>();
        headmap.put("api-key", key);
        HttpMethod.setHeader(headmap);
        this.url = Config.getString("test.url") + "/devices/"+ devId+"/datastreams/"+datastreamId;
        HttpMethod.setcompleteUrl(url,null);
		
	}

	public BasicResponse<DatastreamsResponse> executeApi() {
		BasicResponse response;
//		ObjectMapper mapper = new ObjectMapper();
//                mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
		try {
			HttpResponse httpResponse=HttpMethod.execute();
			response = mapper.readValue(httpResponse.getEntity().getContent(), BasicResponse.class);
			response.setJson(mapper.writeValueAsString(response));
			Object newData = mapper.readValue(mapper.writeValueAsString(response.getDataInternal()), DatastreamsResponse.class);
			response.setData(newData);
			return response;
		} catch (Exception e) {
			logger.error("json error {}", e.getMessage());
			throw new OnenetApiException(e.getMessage());
		}
		finally {
			try {
				HttpMethod.httpClient.close();
			} catch (Exception e) {
				logger.error("http close error: {}", e.getMessage());
				throw new OnenetApiException(e.getMessage());
			}
		}
		
	}
} public class ModifyDatastramsApi extends AbstractAPI {
	private final Logger logger = LoggerFactory.getLogger(this.getClass());
	private String uuid;
	private String devId;
	private List<String> tags;
	private String unit;
	private String unitSymbol;
	private String cmd;
	private Integer interval;
	private String formula;
	private HttpPutMethod HttpMethod;

	/**
	 * 数据流更新
	 * @param uuid:数据流名称 ,String
	 * @param devId:设备ID,String
	 * @param tags:数据流标签（可选，可以为一个或多个）
	 * @param unit:单位（可选）,String
	 * @param unitSymbol:单位符号（可选）,String
	 * @param cmd:MODBUS设备填写，周期下发命令，16进制字节字符串
	 * @param interval:MODBUS设备填写，采集间隔，秒,Integer
	 * @param formula:MODBUS设备填写，寄存器计算公式（可选）,String
	 * @param key:masterkey 或者 设备apikey
	 */
	public ModifyDatastramsApi(String uuid, String devId, List<String> tags, String unit, String unitSymbol, String cmd,
			Integer interval, String formula, String key) {
		super();
		this.uuid = uuid;
		this.devId = devId;
		this.tags = tags;
		this.unit = unit;
		this.unitSymbol = unitSymbol;
		this.cmd = cmd;
		this.interval = interval;
		this.formula = formula;
		this.key = key;
		this.method = Method.PUT;

        Map<String, Object> headmap = new HashMap<String, Object>();
        HttpMethod = new HttpPutMethod(method);
        headmap.put("api-key", key);
        HttpMethod.setHeader(headmap);
        this.url = Config.getString("test.url") + "/devices/" + devId + "/datastreams/" + uuid;
        // body参数
        Map<String, Object> bodymap = new HashMap<String, Object>();
        if (this.tags != null) {
            bodymap.put("tags", tags);
        }
        if (this.unit != null) {
            bodymap.put("unit", unit);
        }
        if (this.unitSymbol != null) {
            bodymap.put("unit_symbol", unitSymbol);
        }
        if (this.cmd != null) {
            bodymap.put("cmd", cmd);
        }
        if (this.interval != null) {
            bodymap.put("interval", interval);
        }
        if (this.formula != null) {
            bodymap.put("formula", formula);
        }
        String json = null;
        ObjectMapper remapper = new ObjectMapper();
        try {
            json = remapper.writeValueAsString(bodymap);
        } catch (Exception e) {
            logger.error("json error {}", e.getMessage());
            throw new OnenetApiException(e.getMessage());
        }
        ((HttpPutMethod) HttpMethod).setEntity(json);
        HttpMethod.setcompleteUrl(url, null);
	}


	public BasicResponse<Void> executeApi() {
		BasicResponse response = null;
		try {
			HttpResponse httpResponse = HttpMethod.execute();
			response = mapper.readValue(httpResponse.getEntity().getContent(), BasicResponse.class);
			response.setJson(mapper.writeValueAsString(response));
			return response;
		} catch (Exception e) {
			logger.error("json error {}", e.getMessage());
			throw new OnenetApiException(e.getMessage());
		}
		finally {
			try {
				HttpMethod.httpClient.close();
			} catch (Exception e) {
				logger.error("http close error: {}", e.getMessage());
				throw new OnenetApiException(e.getMessage());
			}
		}
		
	}
} public class AddDtuParser extends AbstractAPI {
	private final Logger logger = LoggerFactory.getLogger(this.getClass());
	private String name;
	private String filepath;
	private HttpPostMethod HttpMethod;
	
	/**
	 * TCP透传新增
	 * @param name ： 名字,String
	 * @param filepath:路径，String
	 * @param key :必须为masterkey
	 */
	public AddDtuParser(String name, String filepath, String key) {
		super();
		this.name = name;
		this.filepath = filepath;
		this.key = key;
		this.method = Method.POST;
		Map<String, Object> headmap = new HashMap<String, Object>();
		HttpMethod = new HttpPostMethod(method);
		headmap.put("api-key", key);
		HttpMethod.setHeader(headmap);
		this.url = Config.getString("test.url") + "/dtu/parser";
		Map<String, String> fileMap = new HashMap<String, String>();
		fileMap.put("parser", filepath);
		Map<String, String> stringMap = new HashMap<String, String>();
		stringMap.put("name", name);
		((HttpPostMethod) HttpMethod).setEntity(stringMap, fileMap);
		HttpMethod.setcompleteUrl(url, null);
	}
	public BasicResponse<NewParserResponse> executeApi(){
		ObjectMapper mapper = new ObjectMapper();
		BasicResponse response=null;
		try {
			HttpResponse httpResponse=HttpMethod.execute();
			response = mapper.readValue(httpResponse.getEntity().getContent(),BasicResponse.class);
			response.setJson(mapper.writeValueAsString(response));
			Object newData = mapper.readValue(mapper.writeValueAsString(response.getDataInternal()), NewParserResponse.class);
			response.setData(newData);
			return response;
			
		} catch (Exception e) {
			logger.error("json error {}", e.getMessage());
			throw new OnenetApiException(e.getMessage());
		}finally {
			try {
				HttpMethod.httpClient.close();
			} catch (Exception e) {
				logger.error("http close error: {}", e.getMessage());
				throw new OnenetApiException(e.getMessage());
			}
		}
		
	}
} public class DeleteDtuParser extends AbstractAPI {
	private final Logger logger = LoggerFactory.getLogger(this.getClass());
	private Integer id;
	private HttpDeleteMethod HttpMethod;

	/**
	 * TCP透传parser删除
	 * @param id:parser_id,Integer
	 * @param key:masterkey 或者 设备key
	 */
	public DeleteDtuParser(Integer id, String key) {
		this.id = id;
		this.key = key;
		this.method = Method.DELETE;
		Map<String, Object> headmap = new HashMap<String, Object>();
		HttpMethod = new HttpDeleteMethod(method);
		headmap.put("api-key", key);
		HttpMethod.setHeader(headmap);
		if (id == null) {
			throw new OnenetApiException("parser id is required ");
		}
		this.url = Config.getString("test.url") + "/dtu/parser/" +id;
		HttpMethod.setcompleteUrl(url, null);
	}
	public BasicResponse<Void> executeApi() {
		BasicResponse response = null;
		try {
			HttpResponse httpResponse = HttpMethod.execute();
			response = mapper.readValue(httpResponse.getEntity().getContent(), BasicResponse.class);
			response.setJson(mapper.writeValueAsString(response));
			return response;
		} catch (Exception e) {
			logger.error("json error {}", e.getMessage());
			throw new OnenetApiException(e.getMessage());
		}finally {
			try {
				HttpMethod.httpClient.close();
			} catch (Exception e) {
				logger.error("http close error: {}", e.getMessage());
				throw new OnenetApiException(e.getMessage());
			}
		}
	
	}
} public class FindDtuParserList extends AbstractAPI {
	private final Logger logger = LoggerFactory.getLogger(this.getClass());
	private String name; // 精确匹配名字（可选）
	private HttpGetMethod HttpMethod;
	/**
	 * TCP透传查询
	 * @param name： 名字,精确匹配名字（可选）,String
	 * @param key:masterkey 或者 该设备的设备apikey
	 */
	public FindDtuParserList(String name, String key) {
		this.name = name;
		this.method = Method.GET;
		this.key = key;
		Map<String, Object> headmap = new HashMap<String, Object>();
		Map<String, Object> urlmap = new HashMap<String, Object>();
		HttpMethod = new HttpGetMethod(method);
		this.url = Config.getString("test.url") + "/dtu/parser";
		if (name != null) {
			urlmap.put("name", name);
		}
		headmap.put("api-key", key);
		HttpMethod.setHeader(headmap);
		HttpMethod.setcompleteUrl(url, urlmap);
	}

	public BasicResponse<DtuParserList> executeApi() {
		BasicResponse response;
		mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd"));
		try {
			HttpResponse httpResponse = HttpMethod.execute();
            InputStream instreams = httpResponse.getEntity().getContent();
            String str = IOUtils.toString(instreams, "UTF-8");
            response = mapper.readValue(str, BasicResponse.class);
			response.setJson(str);
			Object newData = mapper.readValue(mapper.writeValueAsString(response.getDataInternal()), DtuParserList.class);
			response.setData(newData);
			return response;
		} catch (Exception e) {
			logger.error("error: {}" , e.getMessage());
			throw new OnenetApiException(e.getMessage());
		}finally {
			try {
				HttpMethod.httpClient.close();
			} catch (Exception e) {
				logger.error("http close error: {}", e.getMessage());
				throw new OnenetApiException(e.getMessage());
			}
		}
		

	}
} public class ModifyDtuParser extends AbstractAPI {
	private final Logger logger = LoggerFactory.getLogger(this.getClass());
	private String name;
	private String filepath;
	private HttpPutMethod HttpMethod;
	private Integer id;

   /**
    * TCP透传更新
    * @param id :parserId ,Integer
    * @param name:名字, String
    * @param filepath:路径，String
    * @param key:masterkey 或者 设备apikey
    */
	public ModifyDtuParser(Integer id, String name, String filepath, String key) {
		this.name = name;
		this.filepath = filepath;
		this.key = key;
		this.method = Method.PUT;
		Map<String, Object> headmap = new HashMap<String, Object>();
		HttpMethod = new HttpPutMethod(method);
		headmap.put("api-key", key);
		HttpMethod.setHeader(headmap);
		if (id == null) {
			throw new OnenetApiException("parser id is required ");
		}
		this.url = Config.getString("test.url") + "/dtu/parser/" + id;
		Map<String, String> fileMap = new HashMap<String, String>();
		fileMap.put("parser", filepath);
		Map<String, String> stringMap = new HashMap<String, String>();
		stringMap.put("name", name);
		((HttpPutMethod) HttpMethod).setEntity(stringMap, fileMap);
		HttpMethod.setcompleteUrl(url, null);
	}

	public BasicResponse executeApi() {
		BasicResponse response = null;
		try {
			HttpResponse httpResponse = HttpMethod.execute();
			response = mapper.readValue(httpResponse.getEntity().getContent(), BasicResponse.class);
			response.setJson(mapper.writeValueAsString(response));
			return response;
		} catch (Exception e) {
			logger.error("json error {}", e.getMessage());
			throw new OnenetApiException(e.getMessage());
		} finally {
			try {
				HttpMethod.httpClient.close();
			} catch (Exception e) {
				logger.error("http close error: {}", e.getMessage());
				throw new OnenetApiException(e.getMessage());
			}
		}

	}

} public class AddKeyApi extends AbstractAPI{
	private final Logger logger = LoggerFactory.getLogger(this.getClass());
	private String title;
	private List<Permissions>permissions;
	private HttpPostMethod HttpMethod;
	/**
	 * @param title:名称（可选）,String
	 * @param permissions,List<Permissions>permissions
	 * @param key:masterkey 或者 该设备的设备key
	 */
	public AddKeyApi(String title, List<Permissions> permissions,String key) {
		this.title = title;
		this.permissions = permissions;
		this.key=key;
		this.method = Method.POST;
        Map<String, Object> headmap = new HashMap<String, Object>();
        HttpMethod=  new HttpPostMethod(method);
        headmap.put("api-key", key);
        HttpMethod.setHeader(headmap);
        this.url=Config.getString("test.url")+"/keys";
        Map<String, Object> bodymap = new HashMap<String, Object>();
        if (title != null) {
            bodymap.put("title", title);
        }
        if(permissions!=null){
            bodymap.put("permissions", permissions);
        }
        String json=null;
        ObjectMapper remapper = new ObjectMapper();
        try {
            json = remapper.writeValueAsString(bodymap);
        } catch (Exception e) {
            logger.error("json error {}", e.getMessage());
            throw new OnenetApiException(e.getMessage());
        }
        ((HttpPostMethod)HttpMethod).setEntity(json);
        HttpMethod.setcompleteUrl(url,null);
	}

	public BasicResponse<NewKeyResponse> executeApi(){
		BasicResponse response=null;
		try {
			HttpResponse httpResponse=HttpMethod.execute();
			response = mapper.readValue(httpResponse.getEntity().getContent(),BasicResponse.class);
			response.setJson(mapper.writeValueAsString(response));
			Object newData = mapper.readValue(mapper.writeValueAsString(response.getDataInternal()), NewKeyResponse.class);
			response.setData(newData);
			return response;
		} catch (Exception e) {
		e.printStackTrace();
			logger.error("json error {}", e.getMessage());
			throw new OnenetApiException(e.getMessage());
		}
		finally {
			try {
				HttpMethod.httpClient.close();
			} catch (Exception e) {
				logger.error("http close error: {}", e.getMessage());
				throw new OnenetApiException(e.getMessage());
			}
		}
	}
} public class DeleteKeyApi extends AbstractAPI{
	private final Logger logger = LoggerFactory.getLogger(this.getClass());
	private String keyStr;
	private HttpDeleteMethod HttpMethod;
	
	/**
	 * @param keyStr：需要删除的apikey,String
	 * @param key：masterkey(注：只能为master-key)
	 */
	public DeleteKeyApi(String keyStr, String key) {
		this.keyStr = keyStr;
		this.key = key;
		this.method = Method.DELETE;
        Map<String, Object> headmap = new HashMap<String, Object>();
        HttpMethod = new HttpDeleteMethod(method);
        headmap.put("api-key", key);
        HttpMethod.setHeader(headmap);
        this.url = Config.getString("test.url") + "/keys" + "/" + keyStr;
        HttpMethod.setcompleteUrl(url,null);
	}


	public BasicResponse<Void> executeApi() {
		BasicResponse response = null;
		try {
			HttpResponse httpResponse = HttpMethod.execute();
			response = mapper.readValue(httpResponse.getEntity().getContent(), BasicResponse.class);
			response.setJson(mapper.writeValueAsString(response));
			return response;
		} catch (Exception e) {
			logger.error("json error {}", e.getMessage());
			throw new OnenetApiException(e.getMessage());
		}
		finally {
			try {
				HttpMethod.httpClient.close();
			} catch (Exception e) {
				logger.error("http close error: {}", e.getMessage());
				throw new OnenetApiException(e.getMessage());
			}
		}
		
	}
} public class FindKeyList extends AbstractAPI{
	private String apikey;
	private Integer page;
	private Integer perpage;
	private HttpGetMethod HttpMethod;
	private String devId;
	private String title;
	private final Logger logger = LoggerFactory.getLogger(this.getClass());
	/**
	 * @param title：根据名称查询，可选，字符串（左匹配
	 * @param apikey：需要查找的apikey,String
	 * @param page:指定页码，最大页数为10000（可选）,Integer
	 * @param perpage:指定每页输出设备个数，默认30，最多100（可选）,Integer
	 * @param devId：可选,只查看与该设备相关的非master-key,String
	 * @param key：masterkey(注：只能为master-key)
	 */
	public FindKeyList(String title,String apikey, Integer page, Integer perpage, String devId,String key) {
		this.apikey = apikey;
		this.page = page;
		this.perpage = perpage;
		this.devId = devId;
		this.method = Method.GET;
		this.key = key;
		this.title = title;
        Map<String, Object> headmap = new HashMap<String, Object>();
        Map<String, Object> urlmap = new HashMap<String, Object>();
        HttpMethod = new HttpGetMethod(method);
        this.url = Config.getString("test.url") + "/keys";
        // url参数
		if (apikey != null) {
			urlmap.put("key", apikey);
		}
		if (StringUtils.isNotBlank(title)) {
			urlmap.put("title", title);
		}
        if (page != null) {
            urlmap.put("page", page);
        }
        if (perpage != null) {
            urlmap.put("per_page", perpage);
        }
        if (devId != null) {
            urlmap.put("device_id", devId);
        }
        headmap.put("api-key", key);
        HttpMethod.setHeader(headmap);
        HttpMethod.setcompleteUrl(url,urlmap);
	}


	public BasicResponse<KeyList> executeApi() {
		BasicResponse response;
//        mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
		try {
			HttpResponse httpResponse = HttpMethod.execute();
			response = mapper.readValue(httpResponse.getEntity().getContent(), BasicResponse.class);
			response.setJson(mapper.writeValueAsString(response));
			Object newData = mapper.readValue(mapper.writeValueAsString(response.getDataInternal()), KeyList.class);
			response.setData(newData);
			return response;
		} catch (Exception e) {
			logger.error("error: {}" , e.getMessage());
			throw new OnenetApiException(e.getMessage());
		}finally {
			try {
				HttpMethod.httpClient.close();
			} catch (Exception e) {
				logger.error("http close error: {}", e.getMessage());
				throw new OnenetApiException(e.getMessage());
			}
		}
	}
} public class ModifyKeyApi extends AbstractAPI{
	private final Logger logger = LoggerFactory.getLogger(this.getClass());
	private String title;
	private String apikey;
	private List<Permissions>permissions;
	private HttpPutMethod HttpMethod;
	/**
	 * @param title:名称（可选）,String
	 * @param apikey:需要修改的apikey,String
	 * @param permissions：apikey权限,List<Permissions>permissions
	 * @param key：masterkey(注：只能为master-key)
	 */
	public ModifyKeyApi(String title, String apikey, List<Permissions> permissions,String key) {
		this.title = title;
		this.apikey = apikey;
		this.permissions = permissions;
		this.key=key;
		this.method = Method.PUT;

        Map<String, Object> headmap = new HashMap<String, Object>();
        HttpMethod=  new HttpPutMethod(method);
        headmap.put("api-key", key);
        HttpMethod.setHeader(headmap);
        this.url=Config.getString("test.url")+"/keys/"+apikey;
        Map<String, Object> bodymap = new HashMap<String, Object>();
        if (title != null) {
            bodymap.put("title", title);
        }
        if(permissions!=null){
            bodymap.put("permissions", permissions);
        }
        String json=null;
        try {
            json = mapper.writeValueAsString(bodymap);
        } catch (Exception e) {
            logger.error("json error {}", e.getMessage());
            throw new OnenetApiException(e.getMessage());
        }
        ((HttpPutMethod)HttpMethod).setEntity(json);
        HttpMethod.setcompleteUrl(url,null);
	}


	public BasicResponse<Void> executeApi(){
		ObjectMapper mapper = new ObjectMapper();
		BasicResponse response=null;	
		try {
			HttpResponse httpResponse=HttpMethod.execute();
			response = mapper.readValue(httpResponse.getEntity().getContent(),BasicResponse.class);
			response.setJson(mapper.writeValueAsString(response));
			return response;
		} catch (Exception e) {
			logger.error("json error {}", e.getMessage());
			throw new OnenetApiException(e.getMessage());
		}finally {
			try {
				HttpMethod.httpClient.close();
			} catch (Exception e) {
				logger.error("http close error: {}", e.getMessage());
				throw new OnenetApiException(e.getMessage());
			}
		}
		
	}
} public class CreateMqttTopicApi extends AbstractAPI {
	private final Logger logger = LoggerFactory.getLogger(this.getClass());
	private HttpPostMethod HttpMethod;
	private String name;
	/**
	 * @param name:设备订阅的主题（必选）,String
	 * @param key：masterkey
	 */
	public CreateMqttTopicApi(String name,String key) {
		this.name = name;
		this.key = key;
		this.method = Method.POST;

        Map<String, Object> headmap = new HashMap<String, Object>();
        HttpMethod=  new HttpPostMethod(method);
        headmap.put("api-key", key);
        HttpMethod.setHeader(headmap);
        this.url=Config.getString("test.url")+"/mqtt"+"/topic";
        Map<String, Object> bodymap = new HashMap<String, Object>();
        if(name!=null){
            bodymap.put("name", name);
        }
        String json=null;
        ObjectMapper remapper = new ObjectMapper();
        try {
            json = remapper.writeValueAsString(bodymap);
        } catch (Exception e) {
            logger.error("json error {}", e.getMessage());
            throw new OnenetApiException(e.getMessage());
        }
        ((HttpPostMethod)HttpMethod).setEntity(json);
        HttpMethod.setcompleteUrl(url,null);
	}
	
	

	public BasicResponse<Void> executeApi() {
		BasicResponse response = null;
		try {
			HttpResponse httpResponse = HttpMethod.execute();
			response = mapper.readValue(httpResponse.getEntity().getContent(), BasicResponse.class);
			response.setJson(mapper.writeValueAsString(response));
			return response;
		} catch (Exception e) {
			logger.error("json error {}", e.getMessage());
			throw new OnenetApiException(e.getMessage());
		}
		finally {
			try {
				HttpMethod.httpClient.close();
			} catch (Exception e) {
				logger.error("http close error: {}", e.getMessage());
				throw new OnenetApiException(e.getMessage());
			}
		}
	}
} public class DeleteUserTopic extends AbstractAPI{
	private final Logger logger = LoggerFactory.getLogger(this.getClass());
	private String name;
	private HttpDeleteMethod HttpMethod;
	/**
	 * 删除产品的Topic
	 * @param name：topic名（必选）
	 * @param key：masterkey
	 */
	public DeleteUserTopic(String name,String key) {
		this.name = name;
		this.key = key;
		this.method = Method.DELETE;
        Map<String, Object> headmap = new HashMap<String, Object>();
        Map<String, Object> urlmap = new HashMap<String, Object>();
        if(name!=null){
            urlmap.put("name", name);
        }
        HttpMethod = new HttpDeleteMethod(method);
        headmap.put("api-key", key);
        HttpMethod.setHeader(headmap);
        this.url = Config.getString("test.url") + "/mqtt" + "/topic" ;
        HttpMethod.setcompleteUrl(url,urlmap);

	}

	public BasicResponse<Void> executeApi() {
		BasicResponse response = null;
		try {
			HttpResponse httpResponse = HttpMethod.execute();
			response = mapper.readValue(httpResponse.getEntity().getContent(), BasicResponse.class);
			response.setJson(mapper.writeValueAsString(response));
			return response;
		} catch (Exception e) {
			logger.error("json error {}", e.getMessage());
			throw new OnenetApiException(e.getMessage());
		}finally {
			try {
				HttpMethod.httpClient.close();
			} catch (Exception e) {
				logger.error("http close error: {}", e.getMessage());
				throw new OnenetApiException(e.getMessage());
			}
		}
	
	}
} public class FindTopicDevices  extends AbstractAPI{
	private Integer page;
	private Integer perPage;
	private String topic;
	private HttpGetMethod HttpMethod;
	private final Logger logger = LoggerFactory.getLogger(this.getClass());
	
	/**
	 * @param page
	 * @param perPage
	 * @param topic
	 * @param key
	 */
	public FindTopicDevices(Integer page, Integer perPage, String topic,String key) {
		this.page = page;
		this.perPage = perPage;
		this.topic = topic;
		this.method = Method.GET;
		this.key = key;

        Map<String, Object> headmap = new HashMap<String, Object>();
        Map<String, Object> urlmap = new HashMap<String, Object>();
        HttpMethod = new HttpGetMethod(method);
        this.url = Config.getString("test.url") +"/mqtt"+"/topic_device";
        if (topic != null) {
            urlmap.put("topic", topic);
        }
        if (perPage != null) {
            urlmap.put("per_page", perPage);
        }
        if (page != null) {
            urlmap.put("page", page);
        }
        headmap.put("api-key", key);
        HttpMethod.setHeader(headmap);
        HttpMethod.setcompleteUrl(url,urlmap);
	}

	public BasicResponse<TopicDeviceList> executeApi(){
		BasicResponse response=null;
		try {
			HttpResponse httpResponse=HttpMethod.execute();
			response = mapper.readValue(httpResponse.getEntity().getContent(),BasicResponse.class);
			response.setJson(mapper.writeValueAsString(response));
			Object newData = mapper.readValue(mapper.writeValueAsString(response.getDataInternal()), TopicDeviceList.class);
			response.setData(newData);
			return response;
			
		} catch (Exception e) {
			logger.error("json error {}", e.getMessage());
			throw new OnenetApiException(e.getMessage());
		}
		finally {
			try {
				HttpMethod.httpClient.close();
			} catch (Exception e) {
				logger.error("http close error: {}", e.getMessage());
				throw new OnenetApiException(e.getMessage());
			}
		}
		
	}
} public class GetDevicesTopicsApi extends AbstractAPI{
	private String devId;
	private HttpGetMethod HttpMethod;
	private final Logger logger = LoggerFactory.getLogger(this.getClass());
	
	/**
	 * 查询设备订阅的Topic列表
	 * @param devId：设备ID（必选）,String
	 * @param key：masterkey
	 */
	public GetDevicesTopicsApi(String devId,String key) {
		this.devId = devId;
		this.key=key;
		this.method = Method.GET;

        Map<String, Object> headmap = new HashMap<String, Object>();
        HttpMethod = new HttpGetMethod(method);
        this.url = Config.getString("test.url") +"/mqtt"+"/device_topic/"+devId;
        headmap.put("api-key", key);
        HttpMethod.setHeader(headmap);
        HttpMethod.setcompleteUrl(url,null);
	}


	public BasicResponse<List<String>> executeApi() {
		BasicResponse response = null;
		try {
			HttpResponse httpResponse = HttpMethod.execute();
			response = mapper.readValue(httpResponse.getEntity().getContent(), BasicResponse.class);
			response.setJson(mapper.writeValueAsString(response));
			Object newData = mapper.readValue(mapper.writeValueAsString(response.getDataInternal()), new TypeReference<List<String>>(){});
			response.setData(newData);
			return response;
		} catch (Exception e) {
			logger.error("error: {}" , e.getMessage());
			throw new OnenetApiException(e.getMessage());
		}finally {
			try {
				HttpMethod.httpClient.close();
			} catch (Exception e) {
				logger.error("http close error: {}", e.getMessage());
				throw new OnenetApiException(e.getMessage());
			}
		}
		

	}
} public class GetUserTopics  extends AbstractAPI{
	private HttpGetMethod HttpMethod;
	private final Logger logger = LoggerFactory.getLogger(this.getClass());
	
	/**
	 * 查询产品Topic
	 * @param key：masterkey
	 */
	public GetUserTopics(String key) {
		this.key=key;
		this.method = Method.GET;
        Map<String, Object> headmap = new HashMap<String, Object>();
        HttpMethod = new HttpGetMethod(method);
        this.url = Config.getString("test.url") +"/mqtt"+"/topic";
        headmap.put("api-key", key);
        HttpMethod.setHeader(headmap);
        HttpMethod.setcompleteUrl(url,null);
	}

	public BasicResponse<List<String>> executeApi() {
		BasicResponse response = null;	
		try {
			HttpResponse httpResponse = HttpMethod.execute();
			response = mapper.readValue(httpResponse.getEntity().getContent(), BasicResponse.class);
			response.setJson(mapper.writeValueAsString(response));
			Object newData = mapper.readValue(mapper.writeValueAsString(response.getDataInternal()), new TypeReference<List<String>>(){});
			response.setData(newData);
			return response;
		} catch (Exception e) {
			logger.error("json error {}", e.getMessage());
			throw new OnenetApiException(e.getMessage());
		}
		finally {
			try {
				HttpMethod.httpClient.close();
			} catch (Exception e) {
				logger.error("http close error: {}", e.getMessage());
				throw new OnenetApiException(e.getMessage());
			}
		}
	}
} public class SendMqttApi extends AbstractAPI {
	private final Logger logger = LoggerFactory.getLogger(this.getClass());
	private String topic;
	private Object contents;// 用户自定义数据
	private HttpPostMethod HttpMethod;

	/**
	 * @param topic：设备订阅的主题（必选）,String
	 * @param contents:用户自定义数据：json、string、二进制数据（小于64K）
	 * @param key：masterkey
	 */
	public SendMqttApi(String topic, Object contents,String key) {
		this.topic = topic;
		this.contents = contents;
		this.key = key;
		this.method = Method.POST;
        Map<String, Object> headmap = new HashMap<String, Object>();
        Map<String, Object> urlmap = new HashMap<String, Object>();
        HttpMethod = new HttpPostMethod(method);
        headmap.put("api-key", key);
        HttpMethod.setHeader(headmap);
        this.url = Config.getString("test.url") + "/mqtt";
        if (topic != null) {
            urlmap.put("topic", topic);
        }
        // body参数处理
        if (contents instanceof byte[]) {
            try {
                String s = new String((byte[]) contents, "UTF-8");
                ((HttpPostMethod) HttpMethod).setEntity(s);
            } catch (UnsupportedEncodingException e) {
                logger.error("bytes[]  error {}", e.getMessage());
                throw new OnenetApiException(e.getMessage());
            }
        }
        if (contents instanceof String) {
            ((HttpPostMethod) HttpMethod).setEntity((String) contents);
        }
        HttpMethod.setcompleteUrl(url,urlmap);
	}

	public BasicResponse<Void> executeApi() {
		BasicResponse response = null;
		try {
			HttpResponse httpResponse = HttpMethod.execute();
			response = mapper.readValue(httpResponse.getEntity().getContent(), BasicResponse.class);
			response.setJson(mapper.writeValueAsString(response));
			return response;
		} catch (Exception e) {
			logger.error("json error {}", e.getMessage());
			throw new OnenetApiException(e.getMessage());
		}
		finally {
			try {
				HttpMethod.httpClient.close();
			} catch (Exception e) {
				logger.error("http close error: {}", e.getMessage());
				throw new OnenetApiException(e.getMessage());
			}
		}
	}
} public class AddTriggersApi extends AbstractAPI{
	private final Logger logger = LoggerFactory.getLogger(this.getClass());
	private String title;
	private String dsid;
	private List<String> devids;
	private List<String>dsuuids;
	private String desturl;
	private String type;
	private Integer threshold;
	private HttpPostMethod HttpMethod;
	
	
	/**
	 * @param title
	 * @param dsid
	 * @param devids
	 * @param dsuuids
	 * @param desturl
	 * @param type
	 * @param threshold
	 * @param key
	 */
	public AddTriggersApi(String title, String dsid, List<String> devids, List<String> dsuuids, String desturl,
			String type, Integer threshold,String key) {
		super();
		this.title = title;
		this.dsid = dsid;
		this.devids = devids;
		this.dsuuids = dsuuids;
		this.desturl = desturl;
		this.type = type;
		this.threshold = threshold;
		this.key=key;
		this.method = Method.POST;
        Map<String, Object> headmap = new HashMap<String, Object>();
        HttpMethod=  new HttpPostMethod(method);
        headmap.put("api-key", key);
        HttpMethod.setHeader(headmap);
        this.url=Config.getString("test.url")+"/triggers";
        // body参数
        Map<String, Object> bodymap = new HashMap<String, Object>();
        if (title != null) {
            bodymap.put("title", title);
        }
        if (dsid != null) {
            bodymap.put("ds_id", dsid);
        }
        if (devids != null) {
            bodymap.put("dev_ids", devids);
        }
        if (dsuuids != null) {
            bodymap.put("ds_uuids", dsuuids);
        }
        if (desturl != null) {
            bodymap.put("url", desturl);
        }
        if (type != null) {
            bodymap.put("type", type);
        }
        if (threshold != null) {
            bodymap.put("threshold", threshold);
        }
        String json=null;
        ObjectMapper remapper = new ObjectMapper();
        try {
            json = remapper.writeValueAsString(bodymap);
        } catch (Exception e) {
            logger.error("json error {}", e.getMessage());
            throw new OnenetApiException(e.getMessage());
        }
        ((HttpPostMethod)HttpMethod).setEntity(json);
        HttpMethod.setcompleteUrl(url,null);
	}



	public BasicResponse<NewTriggersResponse> executeApi(){
		BasicResponse response=null;
		try {
			HttpResponse httpResponse=HttpMethod.execute();
			response = mapper.readValue(httpResponse.getEntity().getContent(),BasicResponse.class);
			response.setJson(mapper.writeValueAsString(response));
			Object newData = mapper.readValue(mapper.writeValueAsString(response.getDataInternal()), NewTriggersResponse.class);
			response.setData(newData);
			return response;
		} catch (Exception e) {
			logger.error("json error {}", e.getMessage());
			throw new OnenetApiException(e.getMessage());
		}
		finally {
			try {
				HttpMethod.httpClient.close();
			} catch (Exception e) {
				logger.error("http close error: {}", e.getMessage());
				throw new OnenetApiException(e.getMessage());
			}
		}
	}
} public class DeleteTriggersApi extends AbstractAPI {
	private final Logger logger = LoggerFactory.getLogger(this.getClass());
	private String tirggerId;
	private HttpDeleteMethod HttpMethod;
	
	/**
	 * @param tirggerId
	 * @param key
	 */
	public DeleteTriggersApi(String tirggerId,String key) {
		this.tirggerId = tirggerId;
		this.key=key;
		this.method = Method.DELETE;
        Map<String, Object> headmap = new HashMap<String, Object>();
        HttpMethod = new HttpDeleteMethod(method);
        headmap.put("api-key", key);
        HttpMethod.setHeader(headmap);
        this.url = Config.getString("test.url") + "/triggers" + "/" + tirggerId;
        HttpMethod.setcompleteUrl(url,null);
	}


	public BasicResponse<Void> executeApi() {
		BasicResponse response = null;
		try {
			HttpResponse httpResponse = HttpMethod.execute();
			response = mapper.readValue(httpResponse.getEntity().getContent(), BasicResponse.class);
			response.setJson(mapper.writeValueAsString(response));
			return response;
		} catch (Exception e) {
			logger.error("json error {}", e.getMessage());
			throw new OnenetApiException(e.getMessage());
		}
		finally {
			try {
				HttpMethod.httpClient.close();
			} catch (Exception e) {
				logger.error("http close error: {}", e.getMessage());
				throw new OnenetApiException(e.getMessage());
			}
		}
	}
} public class FindTriggersListApi extends AbstractAPI{
	private String title;
	private Integer page;
	private Integer perpage;
	private HttpGetMethod HttpMethod;
	private final Logger logger = LoggerFactory.getLogger(this.getClass());
	/**
	 * @param title:名称（可选）,String
	 * @param page:指定页码，最大页数为10000（可选）,Integer
	 * @param perpage:指定每页输出设备个数，默认30，最多100（可选）,Integer
	 * @param key:masterkey 或者 设备apikey
	 */
	public FindTriggersListApi(String title, Integer page, Integer perpage, String key) {
		this.title = title;
		this.page = page;
		this.perpage = perpage;
		this.method = Method.GET;
		this.key = key;
        Map<String, Object> headmap = new HashMap<String, Object>();
        Map<String, Object> urlmap = new HashMap<String, Object>();
        HttpMethod = new HttpGetMethod(method);
        headmap.put("api-key", key);
        HttpMethod.setHeader(headmap);
        this.url = Config.getString("test.url") + "/triggers";
        // url参数
        if (title != null) {
            urlmap.put("title", title);
        }
        if (page != null) {
            urlmap.put("page", page);
        }
        if (perpage != null) {
            urlmap.put("per_page", perpage);
        }
        headmap.put("api-key", key);
        HttpMethod.setHeader(headmap);
        HttpMethod.setcompleteUrl(url,urlmap);
	}

	public BasicResponse<TriggersList> executeApi() {
		BasicResponse response;
//        mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
		try {
			HttpResponse httpResponse = HttpMethod.execute();
			response = mapper.readValue(httpResponse.getEntity().getContent(), BasicResponse.class);
			response.setJson(mapper.writeValueAsString(response));
			Object newData = mapper.readValue(mapper.writeValueAsString(response.getDataInternal()), TriggersList.class);
			response.setData(newData);
			return response;
		} catch (Exception e) {
			logger.error("json error {}", e.getMessage());
			throw new OnenetApiException(e.getMessage());
		}
		finally {
			try {
				HttpMethod.httpClient.close();
			} catch (Exception e) {
				logger.error("http close error: {}", e.getMessage());
				throw new OnenetApiException(e.getMessage());
			}
		}
	}
} public class GetTriggersApi extends AbstractAPI {
	private final Logger logger = LoggerFactory.getLogger(this.getClass());
	private HttpGetMethod HttpMethod;
	private String tirggerId;
	
	/**
	 * 查询单个触发器
	 * @param tirggerId:触发器ID,String
	 * @param key:masterkey 或者 设备apikey
	 */
	public GetTriggersApi(String tirggerId,String key) {
		this.tirggerId = tirggerId;
		this.key=key;
		this.method = Method.GET;
		this.HttpMethod=new HttpGetMethod(method);
        Map<String, Object> headmap = new HashMap<String, Object>();
        headmap.put("api-key", key);
        HttpMethod.setHeader(headmap);
        this.url = Config.getString("test.url") + "/triggers" + "/" + tirggerId;
        HttpMethod.setcompleteUrl(url,null);
	}

	public BasicResponse<TriggersResponse> executeApi() {
		BasicResponse response;
//		ObjectMapper mapper = new ObjectMapper();
//        mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
		try {
			HttpResponse httpResponse=HttpMethod.execute();
			response = mapper.readValue(httpResponse.getEntity().getContent(), BasicResponse.class);
			response.setJson(mapper.writeValueAsString(response));
			Object newData = mapper.readValue(mapper.writeValueAsString(response.getDataInternal()), TriggersResponse.class);
			response.setData(newData);
			return response;
		} catch (Exception e) {
			logger.error("json error {}", e.getMessage());
			throw new OnenetApiException(e.getMessage());
		}
		finally {
			try {
				HttpMethod.httpClient.close();
			} catch (Exception e) {
				logger.error("http close error: {}", e.getMessage());
				throw new OnenetApiException(e.getMessage());
			}
		}
	}
} public class ModifyTriggersApi extends AbstractAPI {
	private final Logger logger = LoggerFactory.getLogger(this.getClass());
	private String tirggerId;
	private String title;
	private String dsid;
	private List<String> devids;
	private List<String>dsuuids;
	private String desturl;
	private String type;
	private Integer threshold;
	private HttpPutMethod HttpMethod;

	/**
	 * 触发器更新
	 * @param tirggerId:触发器ID,String
	 * @param title:设备名（可选）,String
	 * @param dsid 数据流名称（id）（可选）,String
	 * @param devids:设备ID（可选）,List<String>
	 * @param dsuuids:数据流uuid（可选）,List<String>
	 * @param desturl:url,String
	 * @param type:触发类型，String
	 * @param threshold:阙值，根据type不同，见以下说明,Integer
	 * @param key:masterkey 或者 设备apikey
	 */
	public ModifyTriggersApi(String tirggerId, String title, String dsid, List<String> devids, List<String> dsuuids,
			String desturl, String type, Integer threshold,String key) {
		super();
		this.tirggerId = tirggerId;
		this.title = title;
		this.dsid = dsid;
		this.devids = devids;
		this.dsuuids = dsuuids;
		this.desturl = desturl;
		this.type = type;
		this.threshold = threshold;
		this.key = key;
		this.method = Method.PUT;
        Map<String, Object> headmap = new HashMap<String, Object>();
        HttpMethod=  new HttpPutMethod(method);
        headmap.put("api-key", key);
        HttpMethod.setHeader(headmap);
        this.url=Config.getString("test.url")+"/triggers/"+tirggerId;
        // body参数
        Map<String, Object> bodymap = new HashMap<String, Object>();
        if (title != null) {
            bodymap.put("title", title);
        }
        if (dsid != null) {
            bodymap.put("ds_id", dsid);
        }
        if (devids != null) {
            bodymap.put("dev_ids", devids);
        }
        if (dsuuids != null) {
            bodymap.put("ds_uuids", dsuuids);
        }
        if (desturl != null) {
            bodymap.put("url", desturl);
        }
        if (type != null) {
            bodymap.put("type", type);
        }
        if (threshold != null) {
            bodymap.put("threshold", threshold);
        }
        String json=null;
        try {
            json = mapper.writeValueAsString(bodymap);
        } catch (Exception e) {

            logger.error("json error {}", e.getMessage());
            throw new OnenetApiException(e.getMessage());
        }
        ((HttpPutMethod)HttpMethod).setEntity(json);
        HttpMethod.setcompleteUrl(url,null);
	}

	public BasicResponse<Void> executeApi() {
		ObjectMapper mapper = new ObjectMapper();
		BasicResponse response = null;
		try {
			HttpResponse httpResponse = HttpMethod.execute();
			response = mapper.readValue(httpResponse.getEntity().getContent(), BasicResponse.class);
			response.setJson(mapper.writeValueAsString(response));
			return response;
		} catch (Exception e) {
			logger.error("json error {}", e.getMessage());
			throw new OnenetApiException(e.getMessage());
		}
		finally {
			try {
				HttpMethod.httpClient.close();
			} catch (Exception e) {
				logger.error("http close error: {}", e.getMessage());
				throw new OnenetApiException(e.getMessage());
			}
		}
	}
} public class Data{
	private String at;
	private Object  value;
	public Data(String at, Object value) {
		super();
		this.at = at;
		this.value = value;
	}
	public String getAt() {
		return at;
	}
	public void setAt(String at) {
		this.at = at;
	}
	public Object getValue() {
		return value;
	}
	public void setValue(Object value) {
		this.value = value;
	}
	
} public class Datapoints {
	//必须
	public String id;
	public List<Data>datapoints;
	public List<Data> getDatapoints() {
		return datapoints;
	}

	public void setDatapoints(List<Data> datapoints) {
		this.datapoints = datapoints;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public Datapoints(String id, List<Data> datapoints) {
		super();
		this.id = id;
		this.datapoints = datapoints;
	}





	
	
} public class Devices {

	public String dev_id;

	public Devices(String dev_id) {
		this.dev_id = dev_id;
	}

} public class Location {
	private  double ele;
	private  double lat;//纬度
	private  double lon;//经度
	private  boolean eleSet;

	public Location(double ele, double lat, double lon, boolean eleSet) {
		this.ele = ele;
		this.lat = lat;
		this.lon = lon;
		this.eleSet = eleSet;
	}

	public Map<String,Double> toMap() {
		Map<String,Double> result = new HashMap<String,Double>();
		if (eleSet) {
			result.put("ele", ele);
		}
		result.put("lon", lon);
		result.put("lat", lat);
		result.put("ele", ele);
		return result;
	}

	public Location(double lon,double lat, double ele) {
		this.ele = ele;
		this.lat = lat;
		this.lon = lon;
	}



	public double getEle() {
		return ele;
	}

	public double getLat() {
		return lat;
	}

	public double getLon() {
		return lon;
	}
} public class Permissions {
	private List<Devices>resources;
	 private List<String>access_methods;

	public Permissions(List<Devices> resources, List<String> access_methods) {
		this.resources = resources;
		this.access_methods = access_methods;
	}
	public List<Devices> getResources() {
		return resources;
	}
	public void setResources(List<Devices> resources) {
		this.resources = resources;
	}
	public List<String> getAccess_methods() {
		return access_methods;
	}
	public void setAccess_methods(List<String> access_methods) {
		this.access_methods = access_methods;
	}
} public class BasicResponse<T> {
	public int errno;
	public String error;
    @JsonProperty("data")
    public Object dataInternal;
    public T data;
    @JsonIgnore
    public String json;

	public String getJson() {
		return json;
	}

	public void setJson(String json) {
		this.json = json;
	}

	public int getErrno() {
        return errno;
    }

    public void setErrno(int errno) {
        this.errno = errno;
    }

    public String getError() {
        return error;
    }

    public void setError(String error) {
        this.error = error;
    }

    @JsonGetter("data")
    public Object getDataInternal() {
        return dataInternal;
    }
    @JsonSetter("data")
    public void setDataInternal(Object dataInternal) {
        this.dataInternal = dataInternal;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
} public class NewBindataResponse {
	 @JsonProperty(value="index")
	 public String index;

	public String getIndex() {
		return index;
	}

	public void setIndex(String index) {
		this.index = index;
	}
} public class CmdsResponse {
	@JsonProperty("status")
	private Integer status;
	@JsonProperty("desc")
	private String desc;
	public Integer getStatus() {
		return status;
	}
	public void setStatus(Integer status) {
		this.status = status;
	}
	public String getDesc() {
		return desc;
	}
	public void setDesc(String desc) {
		this.desc = desc;
	}
	
} public class NewCmdsResponse {
	@JsonProperty(value = "cmd_uuid")
	public String cmduuid;

	public String getCmduuid() {
		return cmduuid;
	}

	public void setCmduuid(String cmduuid) {
		this.cmduuid = cmduuid;
	}

} public class DatapointsList {
	@JsonProperty("count")
	private String count;
	@JsonProperty("cursor")
	private String cursor;
	
	public String getCursor() {
		return cursor;
	}
	public void setCursor(String cursor) {
		this.cursor = cursor;
	}
	public String getCount() {
		return count;
	}
	public void setCount(String count) {
		this.count = count;
	}

	public ArrayList<DatastreamsItem> getDevices() {
		return devices;
	}




	public void setDevices(ArrayList<DatastreamsItem> devices) {
		this.devices = devices;
	}




	@JsonProperty("datastreams")
	private ArrayList<DatastreamsItem> devices;
	
	
	
	@JsonCreator
	public DatapointsList(@JsonProperty("count")String count, @JsonProperty("datastreams")ArrayList<DatastreamsItem> devices) {
		super();
		this.count = count;
		this.devices = devices;
	}




	public static  class DatastreamsItem{
		@JsonProperty("id")
		public String id;
		public String getId() {
			return id;
		}



		public void setId(String id) {
			this.id = id;
		}



		public List<DatapointsItem> getDatapoints() {
			return datapoints;
		}



		public void setDatapoints(List<DatapointsItem> datapoints) {
			this.datapoints = datapoints;
		}



		@JsonProperty("datapoints")
		public List<DatapointsItem>datapoints;
		
		
		@JsonCreator
		public DatastreamsItem(@JsonProperty("id")String id, @JsonProperty("datapoints")List<DatapointsItem> datapoints) {
			super();
			this.id = id;
			this.datapoints = datapoints;
		}



		public static class DatapointsItem{
			@JsonProperty("at")
			private String at;
			public String getAt() {
				return at;
			}

			public void setAt(String at) {
				this.at = at;
			}

			public Object getValue() {
				return value;
			}

			public void setValue(Object value) {
				this.value = value;
			}

			@JsonProperty("value")
			private Object  value;
		
			@JsonCreator
			public DatapointsItem(@JsonProperty("at")String at, @JsonProperty("value")Object value) {
				super();
				this.at = at;
				this.value = value;
			}
			
		}
	}
		
} public class DatastreamsResponse {
	@JsonProperty("id")
	private  String id;
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	@JsonProperty("create_time")
	private  Date createTime;
	@JsonProperty("tags")
	private List<String> tags;
	@JsonProperty("unit")
	private String unit;
	@JsonProperty("unit_symbol")
	private  String unitSymbol;
	@JsonProperty("current_value")
	private Object currentValue;
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	@JsonProperty("update_at")
	private Date updateAt;
	@JsonProperty("formula")
	private String formula;
	@JsonProperty("interval")
	private int interval;
	@JsonProperty("cmd")
	private String cmd;
	@JsonProperty("uuid")
	private String uuid;
	@JsonCreator
	public DatastreamsResponse(@JsonProperty("id")String id, @JsonProperty("create_time")Date createTime, @JsonProperty("tags")List<String> tags, @JsonProperty("unit")String unit, @JsonProperty("unit_symbol")String unitSymbol,
			@JsonProperty("current_value") Object currentValue,@JsonProperty("update_at")Date updateAt,@JsonProperty("formula")String formula,@JsonProperty("interval")int interval,@JsonProperty("cmd")String cmd,@JsonProperty("uuid")String uuid) {
		super();
		this.id = id;
		this.createTime = createTime;
		this.tags = tags;
		this.unit = unit;
		this.unitSymbol = unitSymbol;
		this.currentValue = currentValue;
		this.updateAt = updateAt;
		this.formula=formula;
		this.interval=interval;
		this.cmd=cmd;
		this.uuid=uuid;
	}
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public Date getCreateTime() {
		return createTime;
	}
	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}
	public List<String> getTags() {
		return tags;
	}
	public void setTags(List<String> tags) {
		this.tags = tags;
	}
	public String getUnit() {
		return unit;
	}
	public void setUnit(String unit) {
		this.unit = unit;
	}
	public String getUnitSymbol() {
		return unitSymbol;
	}
	public void setUnitSymbol(String unitSymbol) {
		this.unitSymbol = unitSymbol;
	}
	public Object getCurrentValue() {
		return currentValue;
	}
	public void setCurrentValue(Object currentValue) {
		this.currentValue = currentValue;
	}
	public Date getUpdateAt() {
		return updateAt;
	}
	public String getFormula() {
		return formula;
	}
	public void setFormula(String formula) {
		this.formula = formula;
	}
	public int getInterval() {
		return interval;
	}
	public void setInterval(int interval) {
		this.interval = interval;
	}
	public String getCmd() {
		return cmd;
	}
	public void setCmd(String cmd) {
		this.cmd = cmd;
	}
	public String getUuid() {
		return uuid;
	}
	public void setUuid(String uuid) {
		this.uuid = uuid;
	}
	public void setUpdateAt(Date updateAt) {
		this.updateAt = updateAt;
	}
	/*public static  class CurrentValue{
		@JsonProperty("index")
		private String index;

	
		public String getIndex() {
			return index;
		}


		public void setIndex(String index) {
			this.index = index;
		}


		@JsonCreator
		public CurrentValue(@JsonProperty("index")String index) {
			super();
			this.index = index;
		}
	}*/
	
} public class NewdatastramsResponse {
	@JsonProperty(value = "ds_uuid")
	public String id;

	public String getid() {
		return id;
	}

	public void setid(String id) {
		this.id = id;
	}
} public class DtuParserList {
	@JsonProperty("parsers")
	private ArrayList<ParsersItem> parsers;
	
	public static  class ParsersItem {
		@JsonProperty("id")
		private Integer id;
		@JsonProperty("name")
		private String name;
		@JsonProperty("fileName")
		private String fileName;
		@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd")
		@JsonProperty("time")
		private Date time;
		
		@JsonCreator
		public ParsersItem(@JsonProperty("id")Integer id, @JsonProperty("name")String name, @JsonProperty("fileName")String fileName
				,@JsonProperty("time")Date time){
			this.id = id;
			this.name = name;
			this.fileName = fileName;
			this.time = time;
		}

		public Integer getId() {
			return id;
		}

		public void setId(Integer id) {
			this.id = id;
		}

		public String getName() {
			return name;
		}

		public void setName(String name) {
			this.name = name;
		}

		public String getFileName() {
			return fileName;
		}

		public void setFileName(String fileName) {
			this.fileName = fileName;
		}

		public Date getTime() {
			return time;
		}

		public void setTime(Date time) {
			this.time = time;
		}
	}

	public ArrayList<ParsersItem> getParsers() {
		return parsers;
	}

	public void setParsers(ArrayList<ParsersItem> parsers) {
		this.parsers = parsers;
	}
} public class NewParserResponse {
	@JsonProperty(value = "id")
	public String id;

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

} public class KeyList {
	@JsonProperty("total_count")
	public int totalcount;
	@JsonProperty("per_page")
	public int perpage;
	@JsonProperty("page")
	public int page;
	@JsonProperty("keys")
	public ArrayList<KeysItem> keys;
	
	
	@JsonCreator
	public KeyList(@JsonProperty("total_count")int totalcount,@JsonProperty("per_page") int perpage, @JsonProperty("page")int page, @JsonProperty("keys")ArrayList<KeysItem> keys) {
		this.totalcount = totalcount;
		this.perpage = perpage;
		this.page = page;
		this.keys = keys;
	}



	public static class KeysItem{
		@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
		@JsonProperty("create_time")
		public Date createTime;
		@JsonProperty("title")
		public String title;
		@JsonProperty("key")
		public String key;
		@JsonProperty("permissions")
		public ArrayList<PermissionsItem> permissions;
		
		public Date getCreateTime() {
			return createTime;
		}


		public void setCreateTime(Date createTime) {
			this.createTime = createTime;
		}


		public String getTitle() {
			return title;
		}


		public void setTitle(String title) {
			this.title = title;
		}


		public String getKey() {
			return key;
		}


		public void setKey(String key) {
			this.key = key;
		}


		public ArrayList<PermissionsItem> getPermissions() {
			return permissions;
		}


		public void setPermissions(ArrayList<PermissionsItem> permissions) {
			this.permissions = permissions;
		}


		@JsonCreator
		public KeysItem( @JsonProperty("create_time")Date createTime, @JsonProperty("title")String title,@JsonProperty("key") String key,@JsonProperty("permissions") ArrayList<PermissionsItem> permissions) {
			this.createTime = createTime;
			this.title = title;
			this.key = key;
			this.permissions = permissions;
		}


		public static class PermissionsItem{
			@JsonProperty("resources")
			public List<DevicesItem>resources;
			public List<DevicesItem> getResources() {
				return resources;
			}


			public void setResources(List<DevicesItem> resources) {
				this.resources = resources;
			}


			public ArrayList<String> getAccessMethods() {
				return accessMethods;
			}


			public void setAccessMethods(ArrayList<String> accessMethods) {
				this.accessMethods = accessMethods;
			}


			@JsonProperty("access_methods")
			public ArrayList<String> accessMethods;
			@JsonCreator
			public PermissionsItem(@JsonProperty("permissions")List<DevicesItem> resources,@JsonProperty("access_methods")ArrayList<String> accessMethods) {
				this.resources = resources;
				this.accessMethods=accessMethods;
			}


			public static class DevicesItem{
				@JsonProperty("dev_id")
				public String devid;

				@JsonCreator
				public DevicesItem(@JsonProperty("dev_id")String devid) {
					this.devid = devid;
				}
				
				
			}
		}
	}



	public int getTotalcount() {
		return totalcount;
	}



	public void setTotalcount(int totalcount) {
		this.totalcount = totalcount;
	}



	public int getPerpage() {
		return perpage;
	}



	public void setPerpage(int perpage) {
		this.perpage = perpage;
	}



	public int getPage() {
		return page;
	}



	public void setPage(int page) {
		this.page = page;
	}



	public ArrayList<KeysItem> getKeys() {
		return keys;
	}



	public void setKeys(ArrayList<KeysItem> keys) {
		this.keys = keys;
	}
} public class NewKeyResponse {
    @JsonProperty(value="key")
    public String key;

	public String getKey() {
		return key;
	}

	public void setKey(String key) {
		this.key = key;
	}


} public class TopicDeviceList {
	@JsonProperty("total_count")
	private int totalcount;
	@JsonProperty("per_page")
	private int perpage;
	@JsonProperty("page")
	private int page;
	@JsonProperty("devices")
	private ArrayList<String> devices;
	 
	@JsonCreator
	public TopicDeviceList(@JsonProperty("total_count")int totalcount,@JsonProperty("per_page") int perpage, @JsonProperty("page")int page,	@JsonProperty("devices") ArrayList<String> devices) {
		this.totalcount = totalcount;
		this.perpage = perpage;
		this.page = page;
		this.devices = devices;
	}
	
} public class NewTriggersResponse {
	 @JsonProperty(value="trigger_id")
	    public String Tirggerid;

	    public String getTirggerid() {
	        return Tirggerid;
	    }

	    public void setTirggerid(String Tirggerid) {
	        this.Tirggerid = Tirggerid;
	    }
} public class TriggersList {
	@JsonProperty("total_count")
	private int totalcount;
	@JsonProperty("per_page")
	private int perpage;
	@JsonProperty("page")
	private int page;
	@JsonProperty("triggers")
	private List<TriggersItem>list;
	@JsonCreator
	public TriggersList(@JsonProperty("total_count")int totalcount,@JsonProperty("per_page") int perpage, @JsonProperty("page")int page, @JsonProperty("triggers")List<TriggersItem> list) {
		this.totalcount = totalcount;
		this.perpage = perpage;
		this.page = page;
		this.list = list;
	}
	public static  class TriggersItem{
		@JsonProperty("id")
		private String id;
		@JsonProperty("title")
		private String title;
		@JsonProperty("ds_uuids")
		private List<String> dsuuids;
		@JsonProperty("url")
		private String url;
		@JsonProperty("type")
		private String type;
		@JsonProperty("threshold")
		private int threshold;
		@JsonProperty("invalid")
		private boolean invalid;
		@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
		@JsonProperty("create_time")
		private Date createtime;
		@JsonProperty("target_type")
		private Date targettype;

		@JsonProperty("dev_ids")
		private List<String> devIds;
		@JsonProperty("ds_id")
		private String dsId;

		public String getId() {
			return id;
		}

		public void setId(String id) {
			this.id = id;
		}

		public String getTitle() {
			return title;
		}

		public void setTitle(String title) {
			this.title = title;
		}

		public List<String> getDsuuids() {
			return dsuuids;
		}

		public void setDsuuids(List<String> dsuuids) {
			this.dsuuids = dsuuids;
		}

		public String getUrl() {
			return url;
		}

		public void setUrl(String url) {
			this.url = url;
		}

		public String getType() {
			return type;
		}

		public void setType(String type) {
			this.type = type;
		}

		public int getThreshold() {
			return threshold;
		}

		public void setThreshold(int threshold) {
			this.threshold = threshold;
		}

		public boolean isInvalid() {
			return invalid;
		}

		public void setInvalid(boolean invalid) {
			this.invalid = invalid;
		}

		public Date getCreatetime() {
			return createtime;
		}

		public void setCreatetime(Date createtime) {
			this.createtime = createtime;
		}

		public Date getTargettype() {
			return targettype;
		}

		public void setTargettype(Date targettype) {
			this.targettype = targettype;
		}

		public List<String> getDevIds() {
			return devIds;
		}

		public void setDevIds(List<String> devIds) {
			this.devIds = devIds;
		}

		public String getDsId() {
			return dsId;
		}

		public void setDsId(String dsId) {
			this.dsId = dsId;
		}
	}
} public class TriggersResponse {
	@JsonProperty("id")
	private String id;
	@JsonProperty("title")
	private String title;
	@JsonProperty("ds_uuids")
	private List<String> dsuuids;
	@JsonProperty("url")
	private String url;
	@JsonProperty("type")
	private String type;
	@JsonProperty("threshold")
	private int threshold;
	@JsonProperty("invalid")
	private boolean invalid;
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	@JsonProperty("create_time")
	private Date createtime;
	@JsonProperty("target_type")
	private Date targettype;
	@JsonProperty("dev_ids")
	private List<String> devIds;
	@JsonProperty("dev_details")
	private List<TriggerDeviceDetailItem> devDetails;
	@JsonProperty("ds_id")
	private String dsId;
	
	
	public List<String> getDevIds() {
		return devIds;
	}
	public void setDevIds(List<String> devIds) {
		this.devIds = devIds;
	}
	public Date getTargettype() {
		return targettype;
	}
	public void setTargettype(Date targettype) {
		this.targettype = targettype;
	}
	public Date getCreatetime() {
		return createtime;
	}
	public void setCreatetime(Date createtime) {
		this.createtime = createtime;
	}
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public List<String> getDsuuids() {
		return dsuuids;
	}
	public void setDsuuids(List<String> dsuuids) {
		this.dsuuids = dsuuids;
	}
	public String getUrl() {
		return url;
	}
	public void setUrl(String url) {
		this.url = url;
	}
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	public int getThreshold() {
		return threshold;
	}
	public void setThreshold(int threshold) {
		this.threshold = threshold;
	}
	public boolean isInvalid() {
		return invalid;
	}
	public void setInvalid(boolean invalid) {
		this.invalid = invalid;
	}

	public List<TriggerDeviceDetailItem> getDevDetails() {
		return devDetails;
	}

	public void setDevDetails(List<TriggerDeviceDetailItem> devDetails) {
		this.devDetails = devDetails;
	}

	public String getDsId() {
		return dsId;
	}

	public void setDsId(String dsId) {
		this.dsId = dsId;
	}
}
import java.io.IOException;
import java.util.*;
import cmcc.iot.onenet.javasdk.api.cmds.GetCmdsHistoryApi;
import cmcc.iot.onenet.javasdk.api.device.*;
import cmcc.iot.onenet.javasdk.response.cmds.CmdsList;
import cmcc.iot.onenet.javasdk.response.device.*;
import cmcc.iot.onenet.javasdk.utils.OrderConstant;
import org.json.JSONObject;
import org.junit.Test;
import cmcc.iot.onenet.javasdk.api.bindata.AddBindataApi;
import cmcc.iot.onenet.javasdk.api.bindata.GetBindataApi;
import cmcc.iot.onenet.javasdk.api.cmds.QueryCmdsRespApi;
import cmcc.iot.onenet.javasdk.api.cmds.QueryCmdsStatus;
import cmcc.iot.onenet.javasdk.api.cmds.SendCmdsApi;
import cmcc.iot.onenet.javasdk.api.datapoints.AddDatapointsApi;
import cmcc.iot.onenet.javasdk.api.datapoints.GetDatapointsListApi;
import cmcc.iot.onenet.javasdk.api.datastreams.AddDatastreamsApi;
import cmcc.iot.onenet.javasdk.api.datastreams.DeleteDatastreamsApi;
import cmcc.iot.onenet.javasdk.api.datastreams.FindDatastreamListApi;
import cmcc.iot.onenet.javasdk.api.datastreams.GetDatastreamApi;
import cmcc.iot.onenet.javasdk.api.datastreams.ModifyDatastramsApi;
import cmcc.iot.onenet.javasdk.api.dtu.AddDtuParser;
import cmcc.iot.onenet.javasdk.api.dtu.DeleteDtuParser;
import cmcc.iot.onenet.javasdk.api.dtu.FindDtuParserList;
import cmcc.iot.onenet.javasdk.api.dtu.ModifyDtuParser;
import cmcc.iot.onenet.javasdk.api.key.AddKeyApi;
import cmcc.iot.onenet.javasdk.api.key.DeleteKeyApi;
import cmcc.iot.onenet.javasdk.api.key.FindKeyList;
import cmcc.iot.onenet.javasdk.api.key.ModifyKeyApi;
import cmcc.iot.onenet.javasdk.api.mqtt.CreateMqttTopicApi;
import cmcc.iot.onenet.javasdk.api.mqtt.DeleteUserTopic;
import cmcc.iot.onenet.javasdk.api.mqtt.FindTopicDevices;
import cmcc.iot.onenet.javasdk.api.mqtt.GetDevicesTopicsApi;
import cmcc.iot.onenet.javasdk.api.mqtt.GetUserTopics;
import cmcc.iot.onenet.javasdk.api.mqtt.SendMqttApi;
import cmcc.iot.onenet.javasdk.api.triggers.AddTriggersApi;
import cmcc.iot.onenet.javasdk.api.triggers.DeleteTriggersApi;
import cmcc.iot.onenet.javasdk.api.triggers.FindTriggersListApi;
import cmcc.iot.onenet.javasdk.api.triggers.GetTriggersApi;
import cmcc.iot.onenet.javasdk.api.triggers.ModifyTriggersApi;
import cmcc.iot.onenet.javasdk.model.Data;
import cmcc.iot.onenet.javasdk.model.Datapoints;
import cmcc.iot.onenet.javasdk.model.Devices;
import cmcc.iot.onenet.javasdk.model.Location;
import cmcc.iot.onenet.javasdk.model.Permissions;
import cmcc.iot.onenet.javasdk.response.BasicResponse;
import cmcc.iot.onenet.javasdk.response.bindata.NewBindataResponse;
import cmcc.iot.onenet.javasdk.response.cmds.CmdsResponse;
import cmcc.iot.onenet.javasdk.response.cmds.NewCmdsResponse;
import cmcc.iot.onenet.javasdk.response.datapoints.DatapointsList;
import cmcc.iot.onenet.javasdk.response.datastreams.DatastreamsResponse;
import cmcc.iot.onenet.javasdk.response.datastreams.NewdatastramsResponse;
import cmcc.iot.onenet.javasdk.response.dtu.DtuParserList;
import cmcc.iot.onenet.javasdk.response.dtu.NewParserResponse;
import cmcc.iot.onenet.javasdk.response.key.KeyList;
import cmcc.iot.onenet.javasdk.response.key.NewKeyResponse;
import cmcc.iot.onenet.javasdk.response.mqtt.TopicDeviceList;
import cmcc.iot.onenet.javasdk.response.triggers.NewTriggersResponse;
import cmcc.iot.onenet.javasdk.response.triggers.TriggersList;
import cmcc.iot.onenet.javasdk.response.triggers.TriggersResponse;
		 * @param unit:单位（可选）,String
		 * @param unitSymbol:单位符号（可选）,String
		 * @param cmd:MODBUS设备填写，周期下发命令，16进制字节字符串
		 * @param interval:MODBUS设备填写，采集间隔，秒,Integer，参数已
		 * @param formula:MODBUS设备填写，寄存器计算公式（可选）,String
		 * @param key:masterkey 或者 设备apikey
		 */
		AddDatastreamsApi api = new AddDatastreamsApi(id, devId, tags, unit, unitsymbol, cmd, interval, formula, key);
		BasicResponse<NewdatastramsResponse> response = api.executeApi();
		System.out.println("errno:"+response.errno+" error:"+response.error);
		System.out.println(response.getData().id);
	}

	@Test
	public void testModifyDatastreamsApi() {
		String dsid = "temperature2";
		String key = "9ylHzkz25nre41i=SuJR=F=k5kU=";
		String devId = "1674527";
		List<String> tags = new ArrayList<String>();
		tags.add("china");
		tags.add("mobile");
		String unit = "celsius";
		String unitsymbol = "C";
		String cmd = "0003000000184411";
		int interval = 80;
		String formula = "(A0+A1)*A2";
		/**
		 * 数据流更新
		 * @param dsid:数据流名称 ,String
		 * @param devId:设备ID,String
		 * @param tags:数据流标签（可选，可以为一个或多个）
		 * @param unit:单位（可选）,String
		 * @param unitSymbol:单位符号（可选）,String
		 * @param cmd:MODBUS设备填写，周期下发命令，16进制字节字符串
		 * @param interval:MODBUS设备填写，采集间隔，秒,Integer
		 * @param formula:MODBUS设备填写，寄存器计算公式（可选）,String
		 * @param key:masterkey 或者 设备apikey
		 */
		ModifyDatastramsApi api = new ModifyDatastramsApi(dsid, devId, tags, unit, unitsymbol, cmd, interval, formula,
				key);
		BasicResponse<Void> response = api.executeApi();
		System.out.println("errno:"+response.errno+" error:"+response.error);

	}

	@Test
	public void testGetDatastream() {
		String devId = "212141";
		String id = "datastream_idxx";
		String key = "m4EubNp9WCeAxjFu4lVw=kn2idE=";
		/**
		 * 查询单个数据流
		 * @param devid:设备ID,String
		 * @param datastreamid:数据流名称 ,String
		 * @param key:masterkey 或者 设备apikey
		 */
		GetDatastreamApi api = new GetDatastreamApi(devId, id, key);
		BasicResponse<DatastreamsResponse> response = api.executeApi();
		System.out.println("errno:"+response.errno+" error:"+response.error);
		System.out.println(response.getData().getId());
	}

	@Test
	public void testFindDatastreamsListApi() {
		String datastreamids = "datastream_idxx,datastream_idxy";
		String devid = "212141";
		String key = "m4EubNp9WCeAxjFu4lVw=kn2idE=";
		/**
		 * 查询多个数据流
		 * @param datastreamids:数据流名称 ,String
		 * @param devid:设备ID,String
		 * @param key:masterkey 或者 设备apikey
		 */
		FindDatastreamListApi api = new FindDatastreamListApi(datastreamids, devid, key);
		BasicResponse<List<DatastreamsResponse>> response = api.executeApi();
		System.out.println("errno:"+response.errno+" error:"+response.error);
		System.out.println(response.getJson());
	}

	@Test
	public void testRemoveDatastreamApi() {
		String dsid = "temperature2";
		String key = "9ylHzkz25nre41i=SuJR=F=k5kU=";
		String devId = "1674527";
		/**
		 * 数据流删除
		 * @param devid:设备ID,String
		 * @param datastreamid:数据流名称 ,String
		 * @param key:masterkey 或者 设备apikey
		 */
		DeleteDatastreamsApi api = new DeleteDatastreamsApi(devId, dsid, key);
		BasicResponse<Void> response = api.executeApi();
		System.out.println("errno:"+response.errno+" error:"+response.error);
	}
	
	@Test
	public void testAddDatapointsApi() {
		String devid = "212141";
		String key = "m4EubNp9WCeAxjFu4lVw=kn2idE=";
		List<Datapoints> list = new ArrayList<Datapoints>();
		List<Data> dl = new ArrayList<Data>();
		dl.add(new Data("2013-04-22T00:35:43", 11));
		dl.add(new Data("2013-04-22T00:36:43", 12));
		list.add(new Datapoints("datastream_idxx", dl));
		list.add(new Datapoints("datastream_idxy", dl));
		Map<String, List<Datapoints>> map = new HashMap<String, List<Datapoints>>();
		map.put("datastreams", list);
		/**
		 * 数据点新增
		 * @param map :数据点内容,Map<String,List<Datapoints>>
		 * @param data:提供简写方式上传数据,String
		 * 示例：
		 * type=4
		 * data="{\"temperature\":{\"2015-03-22T22:31:12\":22.5}}";
		 * type=5
		 * data=",;temperature,2015-03-22T22:31:12,22.5;pm2.5,89";
		 * @param type:上传数据类型（可选，默认为完整JSON型，见HTTP内容示例）
		 * @param devId:设备ID,String
		 * @param key:masterkey 或者 设备apikey
		 */
		AddDatapointsApi api = new AddDatapointsApi(map, null, null, devid, key);