Commit ab9504a5 authored by Carit Zhu's avatar Carit Zhu 🎱

查询最新一条数据时增加endTime条件

parent 10bba9f4
Pipeline #1871 passed with stage
in 0 seconds
......@@ -177,8 +177,6 @@ public class WarehouseController {
return warehouseService.getAllByTerm(warehouseTermVo);
}
//获取仓库以及设备数据
@ApiOperation(value = "获取仓库以及设备数据",notes = "获取仓库以及设备数据,传值说明:" +
" warehouseName:仓库名," +
......@@ -207,6 +205,7 @@ public class WarehouseController {
if(StringUtils.isEmpty(warehouseTermVo.getCountry())){
warehouseTermVo.setCountry(null);
}
long endTime = System.currentTimeMillis();
List<SimpleWarehouseVo> simpleWarehouseVos = warehouseService.getByWarehouse(warehouseTermVo);
for( int i = 0,length= simpleWarehouseVos.size();i<length;i++ ){
//判断是否已经绑定设备
......@@ -221,15 +220,19 @@ public class WarehouseController {
simpleWarehouseVos.get(i).setHumidity("~");
continue;
}
String sql = "";
for(int j = 0,len=list.size();j<len;j++){
if( StringUtils.isEmpty(list.get(j).getTdl())){
String sql = "";
for (DeviceVo deviceVo : list) {
if (StringUtils.isEmpty(deviceVo.getTdl())) {
simpleWarehouseVos.get(i).setTemp("~");
simpleWarehouseVos.get(i).setHumidity("~");
continue;
}
String tdl = list.get(j).getTdl().replace(",","\' or \"tdl\" = \'");
sql = "SELECT \"T\",\"h\" FROM \"tdl_policy\".\""+list.get(j).getDevice()+"\" where \"tdl\" = \'"+ tdl +"\' and time >="+ list.get(j).getStartTime() +" GROUP BY \"tdl\" order by time desc limit 1";
String tdl = deviceVo.getTdl().replace(",", "\' or \"tdl\" = \'");
sql = "SELECT \"T\",\"h\" FROM \"tdl_policy\".\"" + deviceVo.getDevice()
+ "\" WHERE \"tdl\" = '" + tdl
+ "' AND time >= " + deviceVo.getStartTime()
+ " AND time <= " + (endTime * 1000000L)
+ " GROUP BY \"tdl\" ORDER BY time DESC LIMIT 1";
}
if(StringUtils.isEmpty(sql)){
simpleWarehouseVos.get(i).setTemp("~");
......@@ -337,8 +340,12 @@ public class WarehouseController {
gatewayOnLineVo.setState(6);
}
//根据网关线路编号获取时间
Long startTime = tdlLogService.getTimeByWarehouseNo(warehouseNo,list.get(a).getSN());
String sql ="SELECT \"battery\" FROM \"tdl_policy\".\""+list.get(a).getDevice() +"\" where time >"+startTime*1000000l+" ORDER BY time DESC LIMIT 1";
Long startTime = tdlLogService.getTimeByWarehouseNo(warehouseNo, list.get(a).getSN());
long endTime = System.currentTimeMillis();
String sql = "SELECT \"battery\" FROM \"tdl_policy\".\"" + list.get(a).getDevice()
+ "\" WHERE time >= " + (startTime * 1000000L)
+ " AND time <= " + (endTime * 1000000L)
+ " ORDER BY time DESC LIMIT 1";
QueryResult queryResult = influxDBTemplate.query(new Query(sql, database));
if (queryResult.getResults().get(0).getSeries() != null) {
if(Double.valueOf(queryResult.getResults().get(0).getSeries().get(0).getValues().get(0).get(1).toString())>0){
......@@ -355,7 +362,11 @@ public class WarehouseController {
for (TDLDeviceVo tdlDeviceVo : tdlDeviceVos) {
TDLDeviceDetailVo tdlDeviceDetailVo = new TDLDeviceDetailVo();
tdlDeviceDetailVo.setGatewaySN(list.get(a).getSN());
String sqls ="SELECT \"b\", \"T\", \"h\" FROM \"tdl_policy\".\""+list.get(a).getDevice() +"\" WHERE (\"tdl\" = '"+tdlDeviceVo.getTDLSN()+"') and time>="+startTime*1000000L+" ORDER BY time DESC LIMIT 1";
String sqls = "SELECT \"b\", \"T\", \"h\" FROM \"tdl_policy\".\"" + list.get(a).getDevice()
+ "\" WHERE (\"tdl\" = '" + tdlDeviceVo.getTDLSN()
+ "') AND time >= " + (startTime * 1000000L)
+ " AND time <= " + (endTime * 1000000L)
+ " ORDER BY time DESC LIMIT 1";
QueryResult queryResults = influxDBTemplate.query(new Query(sqls, database));
if (queryResults.getResults().get(0).getSeries() != null) {
tdlDeviceDetailVo.setTime(parseTime(queryResults.getResults().get(0).getSeries().get(0).getValues().get(0).get(0).toString()));
......@@ -1008,7 +1019,7 @@ public class WarehouseController {
}
List<WarehouseGatewayDateVo> warehouseGatewayDateVoList=new ArrayList<>();
List<GatewayOnLineVo> gatewayOnLineVos=gatewayService.getByWarehouseNo(warehouseVo.getWarehouseNo());
Long endTime = System.currentTimeMillis() + 2 * 24 * 3600 * 1000L;
long endTime = System.currentTimeMillis() + 2 * 24 * 3600 * 1000L;
for (int a=0;a<gatewayOnLineVos.size();a++){
if(gatewayOnLineVos.get(a) == null){
continue;
......@@ -1018,11 +1029,16 @@ public class WarehouseController {
warehouseGatewayDateVo.setType(gatewayOnLineVos.get(a).getType());
warehouseGatewayDateVo.setName(gatewayOnLineVos.get(a).getName());
String device = gatewayOnLineVos.get(a).getType() + "_" + gatewayOnLineVos.get(a).getgSN();
String sql ="SELECT \"battery\" FROM \"tdl_policy\".\""+device +"\" where time >="+ gatewayOnLineVos.get(a).getStartTime()*1000000l+" ORDER BY time DESC LIMIT 1";
String sql = "SELECT \"battery\" FROM \"tdl_policy\".\"" + device
+ "\" where time >= "+ gatewayOnLineVos.get(a).getStartTime() * 1000000L
+ " AND time <=" + (endTime * 1000000L)
+ " ORDER BY time DESC LIMIT 1";
QueryResult queryResult = influxDBTemplate.query(new Query(sql, database));
if (queryResult.getResults().get(0).getSeries() != null) {
if(Double.valueOf(queryResult.getResults().get(0).getSeries().get(0).getValues().get(0).get(1).toString())>0){
warehouseGatewayDateVo.setBattery(queryResult.getResults().get(0).getSeries().get(0).getValues().get(0).get(1)==null ? "NA" :queryResult.getResults().get(0).getSeries().get(0).getValues().get(0).get(1).toString());
warehouseGatewayDateVo.setBattery(
queryResult.getResults().get(0).getSeries().get(0).getValues().get(0).get(1)==null ?
"NA" :queryResult.getResults().get(0).getSeries().get(0).getValues().get(0).get(1).toString());
}else{
warehouseGatewayDateVo.setBattery("NA");
}
......@@ -1050,7 +1066,11 @@ public class WarehouseController {
String rawTDLSN = tdlDeviceVo.getTDLSN().replace("TDL-","").trim();
warehouseDataVo.setTDLSN(rawTDLSN);
warehouseDataVo.setTDLName(tdlDeviceVo.getTDLName());
String sqls ="SELECT \"tdl\",\"b\",\"T\",\"h\" FROM \"tdl_policy\".\""+device+"\" WHERE \"tdl\" = '"+tdlDeviceVo.getTDLSN()+"' AND time >="+ gatewayOnLineVos.get(a).getStartTime()*1000000l+" and time <="+ endTime*1000000l+" ORDER BY time desc limit 1 ";
String sqls = "SELECT \"tdl\",\"b\",\"T\",\"h\" FROM \"tdl_policy\".\"" + device
+ "\" WHERE \"tdl\" = '" + tdlDeviceVo.getTDLSN()
+ "' AND time >= " + (gatewayOnLineVos.get(a).getStartTime() * 1000000L)
+ " AND time <=" + (endTime * 1000000L)
+ " ORDER BY time DESC LIMIT 1";
QueryResult queryResults = influxDBTemplate.query(new Query(sqls, database));
ResultAlarmVo resultAlarmVo=alarmService.getAlarmByWarehouseNo(warehouseVo.getWarehouseNo(),gatewayOnLineVos.get(a).getgSN(),rawTDLSN);
if (queryResults.getResults().get(0).getSeries() != null) {
......@@ -1064,7 +1084,11 @@ public class WarehouseController {
warehouseDataVo.setTemperature("NA");
warehouseDataVo.setHumidity("NA");
}
String sql3 ="SELECT \"tdl\",\"T\",\"h\" FROM \"tdl_policy\".\""+device+"\" WHERE \"tdl\" = '"+tdlDeviceVo.getTDLSN()+"' AND time >="+ gatewayOnLineVos.get(a).getStartTime()*1000000l+" and time <="+ endTime*1000000l+" ORDER BY time ";
String sql3 = "SELECT \"tdl\",\"T\",\"h\" FROM \"tdl_policy\".\"" + device
+ "\" WHERE \"tdl\" = '" + tdlDeviceVo.getTDLSN()
+ "' AND time >= " + (gatewayOnLineVos.get(a).getStartTime() * 1000000L)
+ " AND time <= " + (endTime * 1000000L)
+ " ORDER BY time ";
QueryResult queryResult3 = influxDBTemplate.query(new Query(sql3, database));
if(queryResult3.getResults().get(0).getSeries() != null){
......@@ -1079,8 +1103,6 @@ public class WarehouseController {
return warehouseGatewayDateVoList;
}
//货物仓库某一tdl的温湿度
@ApiOperation(value="货物仓库某一tdl的温湿度",notes = "货物仓库某一tdl的温湿度,传值:" +
" warehouseNo:仓库编号," +
......@@ -1149,7 +1171,9 @@ public class WarehouseController {
List<GraphicDataVo> graphicDataList = new ArrayList<>();
List<TdlDataVo.HistoryDataVo> historyDataList = new ArrayList<>();
//获取TDL数据
String sql = "SELECT \"T\",\"h\" FROM \"tdl_policy\".\""+deviceMessageVo.getType()+"_"+deviceMessageVo.getSN()+"\" where \"tdl\" = \'TDL-"+searchTdlVo.getTDLSN()+"\' order by time ";
String sql = "SELECT \"T\",\"h\" FROM \"tdl_policy\".\"" + deviceMessageVo.getType() + "_" + deviceMessageVo.getSN()
+ "\" WHERE \"tdl\" = 'TDL-"+searchTdlVo.getTDLSN()
+ "' ORDER BY time ";
QueryResult queryResult = influxDBTemplate.query(new Query(sql,database));
if(queryResult.getResults().get(0).getSeries()== null){
tdlDataVo.setGraphicDataList(graphicDataList);
......@@ -1225,7 +1249,7 @@ public class WarehouseController {
}
List<WarehouseGatewayDateVo> warehouseGatewayDateVoList=new ArrayList<>();
List<GatewayOnLineVo> gatewayOnLineVos=gatewayService.getByWarehouseNo(downloadForWarehouseVo.getWarehouseNo());
Long endTime = System.currentTimeMillis() +2*24*3600*1000l;
long endTime = System.currentTimeMillis() + 2 * 24 * 3600 * 1000L;
for (int a=0;a<gatewayOnLineVos.size();a++){
if(gatewayOnLineVos.get(a) == null){
continue;
......@@ -1234,7 +1258,10 @@ public class WarehouseController {
warehouseGatewayDateVo.setgSN(gatewayOnLineVos.get(a).getgSN());
warehouseGatewayDateVo.setType(gatewayOnLineVos.get(a).getType());
String device = gatewayOnLineVos.get(a).getType() + "_" + gatewayOnLineVos.get(a).getgSN();
String sql ="SELECT \"battery\" FROM \"tdl_policy\".\""+device +"\" where time >="+ gatewayOnLineVos.get(a).getStartTime()*1000000l+" ORDER BY time DESC LIMIT 1";
String sql = "SELECT \"battery\" FROM \"tdl_policy\".\"" + device
+ "\" where time >=" + (gatewayOnLineVos.get(a).getStartTime() * 1000000L)
+ " AND time <= " + (endTime * 1000000L)
+ " ORDER BY time DESC LIMIT 1";
QueryResult queryResult = influxDBTemplate.query(new Query(sql, database));
if (queryResult.getResults().get(0).getSeries() != null) {
if(Double.valueOf(queryResult.getResults().get(0).getSeries().get(0).getValues().get(0).get(1).toString())>0){
......@@ -1262,7 +1289,11 @@ public class WarehouseController {
List<WarehouseTDLDetailVo> warehouseTDLDetailVos=new ArrayList<>();
WarehouseDataVo warehouseDataVo=new WarehouseDataVo();
warehouseDataVo.setTDLSN(tdls.get(b).replace("TDL-","").trim());
String sqls ="SELECT \"tdl\",\"b\",\"T\",\"h\" FROM \"tdl_policy\".\""+device+"\" WHERE \"tdl\" = '"+tdls.get(b)+"' AND time >="+ downloadForWarehouseVo.getStartTime()*1000000l+" and time <="+ downloadForWarehouseVo.getStopTime()*1000000l+" ORDER BY time desc limit 1 ";
String sqls = "SELECT \"tdl\",\"b\",\"T\",\"h\" FROM \"tdl_policy\".\"" + device
+ "\" WHERE \"tdl\" = '" + tdls.get(b)
+ "' AND time >= " + downloadForWarehouseVo.getStartTime() * 1000000L
+ " AND time <= "+ downloadForWarehouseVo.getStopTime() * 1000000L
+ " ORDER BY time DESC LIMIT 1";
QueryResult queryResults = influxDBTemplate.query(new Query(sqls, database));
ResultAlarmVo resultAlarmVo=alarmService.getAlarmByWarehouseNo(downloadForWarehouseVo.getWarehouseNo(),gatewayOnLineVos.get(a).getgSN(),tdls.get(b).replace("TDL-","").trim());
if (queryResults.getResults().get(0).getSeries() != null) {
......@@ -1277,7 +1308,11 @@ public class WarehouseController {
warehouseDataVo.setTemperature("NA");
warehouseDataVo.setHumidity("NA");
}
String sql3 ="SELECT \"tdl\",\"T\",\"h\" FROM \"tdl_policy\".\""+device+"\" WHERE \"tdl\" = '"+tdls.get(b)+"' AND time >="+ downloadForWarehouseVo.getStartTime()*1000000l+" and time <="+ downloadForWarehouseVo.getStopTime()*1000000l+" ORDER BY time ";
String sql3 = "SELECT \"tdl\",\"T\",\"h\" FROM \"tdl_policy\".\"" + device
+ "\" WHERE \"tdl\" = '" + tdls.get(b)
+ "' AND time >= " + downloadForWarehouseVo.getStartTime() * 1000000L
+ " AND time <= " + downloadForWarehouseVo.getStopTime() * 1000000L
+ " ORDER BY time ";
QueryResult queryResult3 = influxDBTemplate.query(new Query(sql3, database));
if(queryResult3.getResults().get(0).getSeries() != null){
warehouseTDLDetailVos = getWarehouseData(queryResult3,downloadForWarehouseVo.getOffset()==null ? "+8" : downloadForWarehouseVo.getOffset(),resultAlarmVo,warehouseDataVo);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment