|
|
|
|
@ -1,6 +1,7 @@ |
|
|
|
|
|
|
|
|
|
package org.springblade.iot.controller; |
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
|
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; |
|
|
|
|
@ -9,20 +10,26 @@ import io.swagger.annotations.ApiOperation; |
|
|
|
|
import io.swagger.annotations.ApiParam; |
|
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
|
import org.springblade.core.boot.ctrl.BladeController; |
|
|
|
|
import org.springblade.core.cache.utils.CacheUtil; |
|
|
|
|
import org.springblade.core.mp.support.Condition; |
|
|
|
|
import org.springblade.core.mp.support.Query; |
|
|
|
|
import org.springblade.core.secure.utils.AuthUtil; |
|
|
|
|
import org.springblade.core.tool.api.R; |
|
|
|
|
import org.springblade.core.tool.utils.Func; |
|
|
|
|
import org.springblade.iot.entry.Sensor; |
|
|
|
|
import org.springblade.iot.entry.SensorHistory; |
|
|
|
|
import org.springblade.iot.service.ISensorHistoryService; |
|
|
|
|
import org.springblade.iot.service.ISensorService; |
|
|
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
|
|
|
|
|
|
import java.util.Date; |
|
|
|
|
import java.text.DecimalFormat; |
|
|
|
|
import java.text.ParseException; |
|
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
|
|
import static org.springblade.core.cache.constant.CacheConstant.BIZ_CACHE; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 物品申领表 控制器 |
|
|
|
|
* |
|
|
|
|
* @author swj |
|
|
|
|
* @since 2022年8月17日16:35:34 |
|
|
|
|
*/ |
|
|
|
|
@ -34,6 +41,8 @@ public class SensorController extends BladeController { |
|
|
|
|
|
|
|
|
|
private final ISensorService service; |
|
|
|
|
|
|
|
|
|
private final ISensorHistoryService sensorHistoryService; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 分页 |
|
|
|
|
*/ |
|
|
|
|
@ -80,9 +89,500 @@ public class SensorController extends BladeController { |
|
|
|
|
/** |
|
|
|
|
* 根据id获取对应的Sensor |
|
|
|
|
*/ |
|
|
|
|
@GetMapping("/getSensor") |
|
|
|
|
@GetMapping("/getDetail") |
|
|
|
|
public Sensor getReagent(String id) { |
|
|
|
|
Sensor sensor = service.getById(id); |
|
|
|
|
return sensor; |
|
|
|
|
return service.getById(id); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 今日实验室温度变化趋势 |
|
|
|
|
*/ |
|
|
|
|
@GetMapping("/temperature") |
|
|
|
|
public R<Map<String, Object>> temperature(String roomNumber) throws ParseException { |
|
|
|
|
Map<String, Object> map = new HashMap<>(); |
|
|
|
|
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); |
|
|
|
|
SimpleDateFormat df2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
|
|
|
|
String format = df.format(new Date()); |
|
|
|
|
Date parse0 = df2.parse(format + " 00:00:00"); |
|
|
|
|
Date parse2 = df2.parse(format + " 02:00:00"); |
|
|
|
|
Date parse4 = df2.parse(format + " 04:00:00"); |
|
|
|
|
Date parse6 = df2.parse(format + " 06:00:00"); |
|
|
|
|
Date parse8 = df2.parse(format + " 08:00:00"); |
|
|
|
|
Date parse10 = df2.parse(format + " 10:00:00"); |
|
|
|
|
Date parse12 = df2.parse(format + " 12:00:00"); |
|
|
|
|
Date parse14 = df2.parse(format + " 14:00:00"); |
|
|
|
|
Date parse16 = df2.parse(format + " 16:00:00"); |
|
|
|
|
Date parse18 = df2.parse(format + " 18:00:00"); |
|
|
|
|
Date parse20 = df2.parse(format + " 20:00:00"); |
|
|
|
|
Date parse22 = df2.parse(format + " 22:00:00"); |
|
|
|
|
Date parse24 = df2.parse(format + " 23:59:59"); |
|
|
|
|
DecimalFormat decimalFormat = new DecimalFormat("#0.0"); |
|
|
|
|
List<String> time = new ArrayList<>(); |
|
|
|
|
List<String> temperatures = new ArrayList<>(); |
|
|
|
|
List<String> humiditys = new ArrayList<>(); |
|
|
|
|
// 0点到2点的平均温度值
|
|
|
|
|
LambdaQueryWrapper<SensorHistory> wrapper = new LambdaQueryWrapper<>(); |
|
|
|
|
wrapper.eq(SensorHistory::getRoomNumber, roomNumber); |
|
|
|
|
wrapper.eq(SensorHistory::getType, "温度"); |
|
|
|
|
wrapper.between(SensorHistory::getCreateTime, parse0, parse2); |
|
|
|
|
List<SensorHistory> histories2 = sensorHistoryService.list(wrapper); |
|
|
|
|
if (histories2 != null && histories2.size() > 0) { |
|
|
|
|
double temperature = 0; |
|
|
|
|
for (SensorHistory history : histories2) { |
|
|
|
|
temperature += Double.parseDouble(history.getCurrData()); |
|
|
|
|
} |
|
|
|
|
String format1 = decimalFormat.format(temperature / histories2.size()); |
|
|
|
|
temperatures.add(format1); |
|
|
|
|
} else { |
|
|
|
|
temperatures.add("0"); |
|
|
|
|
} |
|
|
|
|
time.add("2a"); |
|
|
|
|
|
|
|
|
|
// 2点到4点的平均温度值
|
|
|
|
|
wrapper.clear(); |
|
|
|
|
wrapper.eq(SensorHistory::getRoomNumber, roomNumber); |
|
|
|
|
wrapper.eq(SensorHistory::getType, "温度"); |
|
|
|
|
wrapper.between(SensorHistory::getCreateTime, parse2, parse4); |
|
|
|
|
List<SensorHistory> histories4 = sensorHistoryService.list(wrapper); |
|
|
|
|
if (histories4 != null && histories4.size() > 0) { |
|
|
|
|
double temperature = 0; |
|
|
|
|
for (SensorHistory history : histories4) { |
|
|
|
|
temperature += Double.parseDouble(history.getCurrData()); |
|
|
|
|
} |
|
|
|
|
String format1 = decimalFormat.format(temperature / histories4.size()); |
|
|
|
|
temperatures.add(format1); |
|
|
|
|
} else { |
|
|
|
|
temperatures.add("0"); |
|
|
|
|
} |
|
|
|
|
time.add("4a"); |
|
|
|
|
|
|
|
|
|
// 4点到6点的平均温度值
|
|
|
|
|
wrapper.clear(); |
|
|
|
|
wrapper.eq(SensorHistory::getRoomNumber, roomNumber); |
|
|
|
|
wrapper.eq(SensorHistory::getType, "温度"); |
|
|
|
|
wrapper.between(SensorHistory::getCreateTime, parse4, parse6); |
|
|
|
|
List<SensorHistory> histories6 = sensorHistoryService.list(wrapper); |
|
|
|
|
if (histories6 != null && histories6.size() > 0) { |
|
|
|
|
double temperature = 0; |
|
|
|
|
for (SensorHistory history : histories6) { |
|
|
|
|
temperature += Double.parseDouble(history.getCurrData()); |
|
|
|
|
} |
|
|
|
|
String format1 = decimalFormat.format(temperature / histories6.size()); |
|
|
|
|
temperatures.add(format1); |
|
|
|
|
} else { |
|
|
|
|
temperatures.add("0"); |
|
|
|
|
} |
|
|
|
|
time.add("6a"); |
|
|
|
|
|
|
|
|
|
// 6点到8点的平均温度值
|
|
|
|
|
wrapper.clear(); |
|
|
|
|
wrapper.eq(SensorHistory::getRoomNumber, roomNumber); |
|
|
|
|
wrapper.eq(SensorHistory::getType, "温度"); |
|
|
|
|
wrapper.between(SensorHistory::getCreateTime, parse6, parse8); |
|
|
|
|
List<SensorHistory> histories8 = sensorHistoryService.list(wrapper); |
|
|
|
|
if (histories8 != null && histories8.size() > 0) { |
|
|
|
|
double temperature = 0; |
|
|
|
|
for (SensorHistory history : histories8) { |
|
|
|
|
temperature += Double.parseDouble(history.getCurrData()); |
|
|
|
|
} |
|
|
|
|
String format1 = decimalFormat.format(temperature / histories8.size()); |
|
|
|
|
temperatures.add(format1); |
|
|
|
|
} else { |
|
|
|
|
temperatures.add("0"); |
|
|
|
|
} |
|
|
|
|
time.add("8a"); |
|
|
|
|
|
|
|
|
|
// 8点到10点的平均温度值
|
|
|
|
|
wrapper.clear(); |
|
|
|
|
wrapper.eq(SensorHistory::getRoomNumber, roomNumber); |
|
|
|
|
wrapper.eq(SensorHistory::getType, "温度"); |
|
|
|
|
wrapper.between(SensorHistory::getCreateTime, parse8, parse10); |
|
|
|
|
List<SensorHistory> histories10 = sensorHistoryService.list(wrapper); |
|
|
|
|
if (histories10 != null && histories10.size() > 0) { |
|
|
|
|
double temperature = 0; |
|
|
|
|
for (SensorHistory history : histories10) { |
|
|
|
|
temperature += Double.parseDouble(history.getCurrData()); |
|
|
|
|
} |
|
|
|
|
String format1 = decimalFormat.format(temperature / histories10.size()); |
|
|
|
|
temperatures.add(format1); |
|
|
|
|
} else { |
|
|
|
|
temperatures.add("0"); |
|
|
|
|
} |
|
|
|
|
time.add("10a"); |
|
|
|
|
|
|
|
|
|
// 10点到12点的平均温度值
|
|
|
|
|
wrapper.clear(); |
|
|
|
|
wrapper.eq(SensorHistory::getRoomNumber, roomNumber); |
|
|
|
|
wrapper.eq(SensorHistory::getType, "温度"); |
|
|
|
|
wrapper.between(SensorHistory::getCreateTime, parse10, parse12); |
|
|
|
|
List<SensorHistory> histories12 = sensorHistoryService.list(wrapper); |
|
|
|
|
if (histories12 != null && histories12.size() > 0) { |
|
|
|
|
double temperature = 0; |
|
|
|
|
for (SensorHistory history : histories12) { |
|
|
|
|
temperature += Double.parseDouble(history.getCurrData()); |
|
|
|
|
} |
|
|
|
|
String format1 = decimalFormat.format(temperature / histories12.size()); |
|
|
|
|
temperatures.add(format1); |
|
|
|
|
} else { |
|
|
|
|
temperatures.add("0"); |
|
|
|
|
} |
|
|
|
|
time.add("12a"); |
|
|
|
|
|
|
|
|
|
// 12点到14点的平均温度值
|
|
|
|
|
wrapper.clear(); |
|
|
|
|
wrapper.eq(SensorHistory::getRoomNumber, roomNumber); |
|
|
|
|
wrapper.eq(SensorHistory::getType, "温度"); |
|
|
|
|
wrapper.between(SensorHistory::getCreateTime, parse12, parse14); |
|
|
|
|
List<SensorHistory> histories14 = sensorHistoryService.list(wrapper); |
|
|
|
|
if (histories14 != null && histories14.size() > 0) { |
|
|
|
|
double temperature = 0; |
|
|
|
|
for (SensorHistory history : histories14) { |
|
|
|
|
temperature += Double.parseDouble(history.getCurrData()); |
|
|
|
|
} |
|
|
|
|
String format1 = decimalFormat.format(temperature / histories14.size()); |
|
|
|
|
temperatures.add(format1); |
|
|
|
|
} else { |
|
|
|
|
temperatures.add("0"); |
|
|
|
|
} |
|
|
|
|
time.add("2p"); |
|
|
|
|
|
|
|
|
|
// 14点到16点的平均温度值
|
|
|
|
|
wrapper.clear(); |
|
|
|
|
wrapper.eq(SensorHistory::getRoomNumber, roomNumber); |
|
|
|
|
wrapper.eq(SensorHistory::getType, "温度"); |
|
|
|
|
wrapper.between(SensorHistory::getCreateTime, parse14, parse16); |
|
|
|
|
List<SensorHistory> histories16 = sensorHistoryService.list(wrapper); |
|
|
|
|
if (histories16 != null && histories16.size() > 0) { |
|
|
|
|
double temperature = 0; |
|
|
|
|
for (SensorHistory history : histories16) { |
|
|
|
|
temperature += Double.parseDouble(history.getCurrData()); |
|
|
|
|
} |
|
|
|
|
String format1 = decimalFormat.format(temperature / histories16.size()); |
|
|
|
|
temperatures.add(format1); |
|
|
|
|
} else { |
|
|
|
|
temperatures.add("0"); |
|
|
|
|
} |
|
|
|
|
time.add("4p"); |
|
|
|
|
|
|
|
|
|
// 16点到18点的平均温度值
|
|
|
|
|
wrapper.clear(); |
|
|
|
|
wrapper.eq(SensorHistory::getRoomNumber, roomNumber); |
|
|
|
|
wrapper.eq(SensorHistory::getType, "温度"); |
|
|
|
|
wrapper.between(SensorHistory::getCreateTime, parse16, parse18); |
|
|
|
|
List<SensorHistory> histories18 = sensorHistoryService.list(wrapper); |
|
|
|
|
if (histories18 != null && histories18.size() > 0) { |
|
|
|
|
double temperature = 0; |
|
|
|
|
for (SensorHistory history : histories18) { |
|
|
|
|
temperature += Double.parseDouble(history.getCurrData()); |
|
|
|
|
} |
|
|
|
|
String format1 = decimalFormat.format(temperature / histories18.size()); |
|
|
|
|
temperatures.add(format1); |
|
|
|
|
} else { |
|
|
|
|
temperatures.add("0"); |
|
|
|
|
} |
|
|
|
|
time.add("6p"); |
|
|
|
|
|
|
|
|
|
// 18点到20点的平均温度值
|
|
|
|
|
wrapper.clear(); |
|
|
|
|
wrapper.eq(SensorHistory::getRoomNumber, roomNumber); |
|
|
|
|
wrapper.eq(SensorHistory::getType, "温度"); |
|
|
|
|
wrapper.between(SensorHistory::getCreateTime, parse18, parse20); |
|
|
|
|
List<SensorHistory> histories20 = sensorHistoryService.list(wrapper); |
|
|
|
|
if (histories20 != null && histories20.size() > 0) { |
|
|
|
|
double temperature = 0; |
|
|
|
|
for (SensorHistory history : histories20) { |
|
|
|
|
temperature += Double.parseDouble(history.getCurrData()); |
|
|
|
|
} |
|
|
|
|
String format1 = decimalFormat.format(temperature / histories20.size()); |
|
|
|
|
temperatures.add(format1); |
|
|
|
|
} else { |
|
|
|
|
temperatures.add("0"); |
|
|
|
|
} |
|
|
|
|
time.add("8p"); |
|
|
|
|
|
|
|
|
|
// 20点到22点的平均温度值
|
|
|
|
|
wrapper.clear(); |
|
|
|
|
wrapper.eq(SensorHistory::getRoomNumber, roomNumber); |
|
|
|
|
wrapper.eq(SensorHistory::getType, "温度"); |
|
|
|
|
wrapper.between(SensorHistory::getCreateTime, parse20, parse22); |
|
|
|
|
List<SensorHistory> histories22 = sensorHistoryService.list(wrapper); |
|
|
|
|
if (histories22 != null && histories22.size() > 0) { |
|
|
|
|
double temperature = 0; |
|
|
|
|
for (SensorHistory history : histories22) { |
|
|
|
|
temperature += Double.parseDouble(history.getCurrData()); |
|
|
|
|
} |
|
|
|
|
String format1 = decimalFormat.format(temperature / histories22.size()); |
|
|
|
|
temperatures.add(format1); |
|
|
|
|
} else { |
|
|
|
|
temperatures.add("0"); |
|
|
|
|
} |
|
|
|
|
time.add("10p"); |
|
|
|
|
|
|
|
|
|
// 22点到24点的平均温度值
|
|
|
|
|
wrapper.clear(); |
|
|
|
|
wrapper.eq(SensorHistory::getRoomNumber, roomNumber); |
|
|
|
|
wrapper.eq(SensorHistory::getType, "温度"); |
|
|
|
|
wrapper.between(SensorHistory::getCreateTime, parse22, parse24); |
|
|
|
|
List<SensorHistory> histories24 = sensorHistoryService.list(wrapper); |
|
|
|
|
if (histories24 != null && histories24.size() > 0) { |
|
|
|
|
double temperature = 0; |
|
|
|
|
for (SensorHistory history : histories24) { |
|
|
|
|
temperature += Double.parseDouble(history.getCurrData()); |
|
|
|
|
} |
|
|
|
|
String format1 = decimalFormat.format(temperature / histories24.size()); |
|
|
|
|
temperatures.add(format1); |
|
|
|
|
} else { |
|
|
|
|
temperatures.add("0"); |
|
|
|
|
} |
|
|
|
|
time.add("12p"); |
|
|
|
|
|
|
|
|
|
// 0点到2点的平均湿度值
|
|
|
|
|
wrapper.clear(); |
|
|
|
|
wrapper.eq(SensorHistory::getRoomNumber, roomNumber); |
|
|
|
|
wrapper.eq(SensorHistory::getType, "湿度"); |
|
|
|
|
wrapper.between(SensorHistory::getCreateTime, parse0, parse2); |
|
|
|
|
List<SensorHistory> histories1 = sensorHistoryService.list(wrapper); |
|
|
|
|
if (histories1 != null && histories1.size() > 0) { |
|
|
|
|
double temperature = 0; |
|
|
|
|
for (SensorHistory history : histories1) { |
|
|
|
|
temperature += Double.parseDouble(history.getCurrData()); |
|
|
|
|
} |
|
|
|
|
String format1 = decimalFormat.format(temperature / histories1.size()); |
|
|
|
|
humiditys.add(format1); |
|
|
|
|
} else { |
|
|
|
|
humiditys.add("0"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 2点到4点的平均湿度值
|
|
|
|
|
wrapper.clear(); |
|
|
|
|
wrapper.eq(SensorHistory::getRoomNumber, roomNumber); |
|
|
|
|
wrapper.eq(SensorHistory::getType, "湿度"); |
|
|
|
|
wrapper.between(SensorHistory::getCreateTime, parse2, parse4); |
|
|
|
|
List<SensorHistory> histories3 = sensorHistoryService.list(wrapper); |
|
|
|
|
if (histories3 != null && histories3.size() > 0) { |
|
|
|
|
double temperature = 0; |
|
|
|
|
for (SensorHistory history : histories3) { |
|
|
|
|
temperature += Double.parseDouble(history.getCurrData()); |
|
|
|
|
} |
|
|
|
|
String format1 = decimalFormat.format(temperature / histories3.size()); |
|
|
|
|
humiditys.add(format1); |
|
|
|
|
} else { |
|
|
|
|
humiditys.add("0"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 4点到6点的平均湿度值
|
|
|
|
|
wrapper.clear(); |
|
|
|
|
wrapper.eq(SensorHistory::getRoomNumber, roomNumber); |
|
|
|
|
wrapper.eq(SensorHistory::getType, "湿度"); |
|
|
|
|
wrapper.between(SensorHistory::getCreateTime, parse4, parse6); |
|
|
|
|
List<SensorHistory> histories5 = sensorHistoryService.list(wrapper); |
|
|
|
|
if (histories5 != null && histories5.size() > 0) { |
|
|
|
|
double temperature = 0; |
|
|
|
|
for (SensorHistory history : histories5) { |
|
|
|
|
temperature += Double.parseDouble(history.getCurrData()); |
|
|
|
|
} |
|
|
|
|
String format1 = decimalFormat.format(temperature / histories5.size()); |
|
|
|
|
humiditys.add(format1); |
|
|
|
|
} else { |
|
|
|
|
humiditys.add("0"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 6点到8点的平均湿度值
|
|
|
|
|
wrapper.clear(); |
|
|
|
|
wrapper.eq(SensorHistory::getRoomNumber, roomNumber); |
|
|
|
|
wrapper.eq(SensorHistory::getType, "湿度"); |
|
|
|
|
wrapper.between(SensorHistory::getCreateTime, parse6, parse8); |
|
|
|
|
List<SensorHistory> histories7 = sensorHistoryService.list(wrapper); |
|
|
|
|
if (histories7 != null && histories7.size() > 0) { |
|
|
|
|
double temperature = 0; |
|
|
|
|
for (SensorHistory history : histories7) { |
|
|
|
|
temperature += Double.parseDouble(history.getCurrData()); |
|
|
|
|
} |
|
|
|
|
String format1 = decimalFormat.format(temperature / histories7.size()); |
|
|
|
|
humiditys.add(format1); |
|
|
|
|
} else { |
|
|
|
|
humiditys.add("0"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 8点到10点的平均湿度值
|
|
|
|
|
wrapper.clear(); |
|
|
|
|
wrapper.eq(SensorHistory::getRoomNumber, roomNumber); |
|
|
|
|
wrapper.eq(SensorHistory::getType, "湿度"); |
|
|
|
|
wrapper.between(SensorHistory::getCreateTime, parse8, parse10); |
|
|
|
|
List<SensorHistory> histories9 = sensorHistoryService.list(wrapper); |
|
|
|
|
if (histories9 != null && histories9.size() > 0) { |
|
|
|
|
double temperature = 0; |
|
|
|
|
for (SensorHistory history : histories9) { |
|
|
|
|
temperature += Double.parseDouble(history.getCurrData()); |
|
|
|
|
} |
|
|
|
|
String format1 = decimalFormat.format(temperature / histories9.size()); |
|
|
|
|
humiditys.add(format1); |
|
|
|
|
} else { |
|
|
|
|
humiditys.add("0"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 10点到12点的平均湿度值
|
|
|
|
|
wrapper.clear(); |
|
|
|
|
wrapper.eq(SensorHistory::getRoomNumber, roomNumber); |
|
|
|
|
wrapper.eq(SensorHistory::getType, "湿度"); |
|
|
|
|
wrapper.between(SensorHistory::getCreateTime, parse10, parse12); |
|
|
|
|
List<SensorHistory> histories11 = sensorHistoryService.list(wrapper); |
|
|
|
|
if (histories11 != null && histories11.size() > 0) { |
|
|
|
|
double temperature = 0; |
|
|
|
|
for (SensorHistory history : histories11) { |
|
|
|
|
temperature += Double.parseDouble(history.getCurrData()); |
|
|
|
|
} |
|
|
|
|
String format1 = decimalFormat.format(temperature / histories11.size()); |
|
|
|
|
humiditys.add(format1); |
|
|
|
|
} else { |
|
|
|
|
humiditys.add("0"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 12点到14点的平均湿度值
|
|
|
|
|
wrapper.clear(); |
|
|
|
|
wrapper.eq(SensorHistory::getRoomNumber, roomNumber); |
|
|
|
|
wrapper.eq(SensorHistory::getType, "湿度"); |
|
|
|
|
wrapper.between(SensorHistory::getCreateTime, parse12, parse14); |
|
|
|
|
List<SensorHistory> histories13 = sensorHistoryService.list(wrapper); |
|
|
|
|
if (histories13 != null && histories13.size() > 0) { |
|
|
|
|
double temperature = 0; |
|
|
|
|
for (SensorHistory history : histories13) { |
|
|
|
|
temperature += Double.parseDouble(history.getCurrData()); |
|
|
|
|
} |
|
|
|
|
String format1 = decimalFormat.format(temperature / histories13.size()); |
|
|
|
|
humiditys.add(format1); |
|
|
|
|
} else { |
|
|
|
|
humiditys.add("0"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 14点到16点的平均湿度值
|
|
|
|
|
wrapper.clear(); |
|
|
|
|
wrapper.eq(SensorHistory::getRoomNumber, roomNumber); |
|
|
|
|
wrapper.eq(SensorHistory::getType, "湿度"); |
|
|
|
|
wrapper.between(SensorHistory::getCreateTime, parse14, parse16); |
|
|
|
|
List<SensorHistory> histories15 = sensorHistoryService.list(wrapper); |
|
|
|
|
if (histories15 != null && histories15.size() > 0) { |
|
|
|
|
double temperature = 0; |
|
|
|
|
for (SensorHistory history : histories15) { |
|
|
|
|
temperature += Double.parseDouble(history.getCurrData()); |
|
|
|
|
} |
|
|
|
|
String format1 = decimalFormat.format(temperature / histories15.size()); |
|
|
|
|
humiditys.add(format1); |
|
|
|
|
} else { |
|
|
|
|
humiditys.add("0"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 16点到18点的平均湿度值
|
|
|
|
|
wrapper.clear(); |
|
|
|
|
wrapper.eq(SensorHistory::getRoomNumber, roomNumber); |
|
|
|
|
wrapper.eq(SensorHistory::getType, "湿度"); |
|
|
|
|
wrapper.between(SensorHistory::getCreateTime, parse16, parse18); |
|
|
|
|
List<SensorHistory> histories17 = sensorHistoryService.list(wrapper); |
|
|
|
|
if (histories17 != null && histories17.size() > 0) { |
|
|
|
|
double temperature = 0; |
|
|
|
|
for (SensorHistory history : histories17) { |
|
|
|
|
temperature += Double.parseDouble(history.getCurrData()); |
|
|
|
|
} |
|
|
|
|
String format1 = decimalFormat.format(temperature / histories17.size()); |
|
|
|
|
humiditys.add(format1); |
|
|
|
|
} else { |
|
|
|
|
humiditys.add("0"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 18点到20点的平均湿度值
|
|
|
|
|
wrapper.clear(); |
|
|
|
|
wrapper.eq(SensorHistory::getRoomNumber, roomNumber); |
|
|
|
|
wrapper.eq(SensorHistory::getType, "湿度"); |
|
|
|
|
wrapper.between(SensorHistory::getCreateTime, parse18, parse20); |
|
|
|
|
List<SensorHistory> histories19 = sensorHistoryService.list(wrapper); |
|
|
|
|
if (histories19 != null && histories19.size() > 0) { |
|
|
|
|
double temperature = 0; |
|
|
|
|
for (SensorHistory history : histories19) { |
|
|
|
|
temperature += Double.parseDouble(history.getCurrData()); |
|
|
|
|
} |
|
|
|
|
String format1 = decimalFormat.format(temperature / histories19.size()); |
|
|
|
|
humiditys.add(format1); |
|
|
|
|
} else { |
|
|
|
|
humiditys.add("0"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 20点到22点的平均湿度值
|
|
|
|
|
wrapper.clear(); |
|
|
|
|
wrapper.eq(SensorHistory::getRoomNumber, roomNumber); |
|
|
|
|
wrapper.eq(SensorHistory::getType, "湿度"); |
|
|
|
|
wrapper.between(SensorHistory::getCreateTime, parse20, parse22); |
|
|
|
|
List<SensorHistory> histories21 = sensorHistoryService.list(wrapper); |
|
|
|
|
if (histories21 != null && histories21.size() > 0) { |
|
|
|
|
double temperature = 0; |
|
|
|
|
for (SensorHistory history : histories21) { |
|
|
|
|
temperature += Double.parseDouble(history.getCurrData()); |
|
|
|
|
} |
|
|
|
|
String format1 = decimalFormat.format(temperature / histories21.size()); |
|
|
|
|
humiditys.add(format1); |
|
|
|
|
} else { |
|
|
|
|
humiditys.add("0"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 22点到24点的平均湿度值
|
|
|
|
|
wrapper.clear(); |
|
|
|
|
wrapper.eq(SensorHistory::getRoomNumber, roomNumber); |
|
|
|
|
wrapper.eq(SensorHistory::getType, "湿度"); |
|
|
|
|
wrapper.between(SensorHistory::getCreateTime, parse22, parse24); |
|
|
|
|
List<SensorHistory> histories23 = sensorHistoryService.list(wrapper); |
|
|
|
|
if (histories23 != null && histories23.size() > 0) { |
|
|
|
|
double temperature = 0; |
|
|
|
|
for (SensorHistory history : histories23) { |
|
|
|
|
temperature += Double.parseDouble(history.getCurrData()); |
|
|
|
|
} |
|
|
|
|
String format1 = decimalFormat.format(temperature / histories23.size()); |
|
|
|
|
humiditys.add(format1); |
|
|
|
|
} else { |
|
|
|
|
humiditys.add("0"); |
|
|
|
|
} |
|
|
|
|
map.put("time", time); |
|
|
|
|
map.put("temperatures", temperatures); |
|
|
|
|
map.put("humiditys", humiditys); |
|
|
|
|
return R.data(map); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 今日实验室湿度变化趋势 |
|
|
|
|
*/ |
|
|
|
|
// @GetMapping("/humidity")
|
|
|
|
|
// public R<Map<String, Object>> humidity(String roomNumber) throws ParseException {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 右上角实验室实时数据 |
|
|
|
|
*/ |
|
|
|
|
@GetMapping("/realTime") |
|
|
|
|
public R<Map<String, Object>> realTime(String roomNumber) { |
|
|
|
|
Map<String, Object> map = new HashMap<>(); |
|
|
|
|
LambdaQueryWrapper<Sensor> wrapper = new LambdaQueryWrapper<>(); |
|
|
|
|
wrapper.eq(Sensor::getRoomNumber, roomNumber); |
|
|
|
|
List<Sensor> sensors = service.list(wrapper); |
|
|
|
|
System.out.println("sensors" + sensors); |
|
|
|
|
if (sensors != null && sensors.size() > 0) { |
|
|
|
|
for (Sensor sensor : sensors) { |
|
|
|
|
System.out.println("sensor.getId()" + sensor.getId()); |
|
|
|
|
String str = (String) CacheUtil.get(BIZ_CACHE, "sensor:id", sensor.getId()); |
|
|
|
|
System.out.println("str:" + str); |
|
|
|
|
Sensor result = JSONObject.parseObject(str, Sensor.class); |
|
|
|
|
System.out.println("result" + result); |
|
|
|
|
System.out.println("result.getType()" + result.getType()); |
|
|
|
|
if ("温度".equals(result.getType())) { |
|
|
|
|
map.put("temperature", result.getCurrData()); |
|
|
|
|
} |
|
|
|
|
if ("湿度".equals(result.getType())) { |
|
|
|
|
map.put("humidity", result.getCurrData()); |
|
|
|
|
} |
|
|
|
|
if ("压差".equals(result.getType())) { |
|
|
|
|
map.put("pressure", result.getCurrData()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return R.data(map); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|