sqls="SELECT count("+field+") FROM \"tdl_policy\".\""+device+"\" WHERE \"tdl\"='"+devList.get(i)+"' and time>="+startTime+" and time <="+resultCircuitVo.getEndTime()*1000000l;
}else{
sqls="SELECT count("+field+") FROM \"tdl_policy\".\""+device+"\" WHERE \"tdl\"='"+devList.get(i)+"' and time>="+startTime+" and time <="+System.currentTimeMillis()*1000000l;
sql="SELECT "+field+" FROM \"tdl_policy\".\""+device+"\" where \"data_type\" = 'data' AND \"tdl\"='"+devList.get(i)+"' and time >="+startTime+" and time<="+resultCircuitVo.getEndTime()*1000000l+" ORDER BY time ";
}else{
sql="SELECT "+field+" FROM \"tdl_policy\".\""+device+"\" where \"data_type\" = 'data' AND \"tdl\"='"+devList.get(i)+"' and time >="+startTime+" ORDER BY time";
// if (resultCircuitVo.getEndTime() != null && resultCircuitVo.getEndTime() != 0) {
// sql = "SELECT "+field+" FROM \"tdl_policy\".\"" + device + "\" where \"tdl\"='" + devList.get(i) + "' and time >=" + startTime + " and time<=" + resultCircuitVo.getEndTime() * 1000000l + " ORDER BY time ";
// } else {
// sql = "SELECT "+field+" FROM \"tdl_policy\".\"" + device + "\" where \"tdl\"='" + devList.get(i) + "' and time >=" + startTime + " ORDER BY time";
sql=sql+"Select "+field+" From \"tdl_policy\".\""+device+"\" where \"tdl\"='"+tdl+"' AND \"topic\" = 'Data' AND \"data_type\" = 'data' AND \"topic\" = 'Data' AND \"event\" = 'Regular measurement' AND \"data_id\" = '2' and time >= "+startTime+" and time <= "+maxTime+" order by time limit 1;";
startTime=maxTime;
}
sql=sql+"Select "+field+" From \"tdl_policy\".\""+device+"\" where \"tdl\"='"+tdl+"' AND \"topic\" = 'Data' AND \"data_type\" = 'data' AND \"topic\" = 'Data' AND \"event\" = 'Regular measurement' AND \"data_id\" = '2' and time >="+startTime+" and time <= "+endTime+" order by time desc limit 1;";
sqls="SELECT count("+list.get(j)+") FROM \"tdl_policy\".\""+device+"\" WHERE \"tdl\"='"+devList.get(i)+"' and time>="+startTime+" and time <="+resultCircuitVo.getEndTime()*1000000l;
}else{
sqls="SELECT count("+list.get(j)+") FROM \"tdl_policy\".\""+device+"\" WHERE \"tdl\"='"+devList.get(i)+"' and time>="+startTime+" and time <="+System.currentTimeMillis()*1000000l;
// sql = "SELECT "+list.get(j)+" FROM \"tdl_policy\".\""+device+"\" where \"tdl\"='"+devList.get(i)+"' and time >="+startTime + " and time<="+resultCircuitVo.getEndTime() *1000000l+" ORDER BY time ";
sqls="SELECT count("+list.get(j)+") FROM \"tdl_policy\".\""+device+"\" WHERE \"tdl\"='"+devList.get(i)+"' and time>="+startTime+" and time <="+resultCircuitVo.getEndTime()*1000000l;
}else{
sqls="SELECT count("+list.get(j)+") FROM \"tdl_policy\".\""+device+"\" WHERE \"tdl\"='"+devList.get(i)+"' and time>="+startTime+" and time <="+System.currentTimeMillis()*1000000l;
sql="SELECT "+list.get(j)+" FROM \"tdl_policy\".\""+device+"\" where \"tdl\"='"+devList.get(i)+"' and time >="+startTime+" and time<="+resultCircuitVo.getEndTime()*1000000l+" ORDER BY time ";
}else{
sql="SELECT "+list.get(j)+" FROM \"tdl_policy\".\""+device+"\" where \"tdl\"='"+devList.get(i)+"' and time >="+startTime+" ORDER BY time";
// sql = "SELECT "+list.get(j)+" FROM \"tdl_policy\".\""+device+"\" where \"tdl\"='"+devList.get(i)+"' and time >="+startTime + " and time<="+resultCircuitVo.getEndTime() *1000000l+" ORDER BY time ";
sql="SELECT "+list.get(j)+" FROM \"tdl_policy\".\""+device+"\" where \"tdl\"='"+devList.get(i)+"' and time >="+startTime+" and time<="+resultCircuitVo.getEndTime()*1000000l+" ORDER BY time ";
}else{
sql="SELECT "+list.get(j)+" FROM \"tdl_policy\".\""+device+"\" where \"tdl\"='"+devList.get(i)+"' and time >="+startTime+" ORDER BY time";
sql=sql+String.format("Select %s From \"tdl_policy\".\"%s\" where \"tdl\"='%s' and time >= %d and time <= %d order by time limit 1;",field,device,tdl,startTime,maxTime);
SELECT warehouseNo,warehouseName,c.country,c.city,addressDetail,(SELECT COUNT(DISTINCT gatewaySN) from tdl_gateway_log WHERE warehouseNo=w.warehouseNo and ISNULL(endTime)) gatewayCounts,
SELECT img,warehouseNo,warehouseName,c.country,c.city,addressDetail,(SELECT COUNT(DISTINCT gatewaySN) from tdl_gateway_log WHERE warehouseNo=w.warehouseNo and ISNULL(endTime)) gatewayCounts,
(SELECT COUNT(TDLSN) from tdl_gateway_log WHERE warehouseNo=w.warehouseNo and ISNULL(endTime)) tdlCounts,property,type,hardwareLevel,areaPlanIndoor
from warehouse w INNER JOIN city c ON w.city_id=c.id