|
@@ -30,6 +30,7 @@ import org.springframework.util.MultiValueMap;
|
|
import org.springframework.web.client.RestTemplate;
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
|
+import java.text.DecimalFormat;
|
|
import java.text.ParseException;
|
|
import java.text.ParseException;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
|
@@ -59,6 +60,7 @@ public class NewEnvTimer {
|
|
public void getDeviceFlowData() throws ParseException {
|
|
public void getDeviceFlowData() throws ParseException {
|
|
String userId = "-1618620464";
|
|
String userId = "-1618620464";
|
|
String farmCode = "21";
|
|
String farmCode = "21";
|
|
|
|
+ EnvData one = envDataService.getOne(new QueryWrapper<EnvData>().ne("env_temp", 0).ne("env_hum", 0).last("limit 1").orderByDesc("id"));
|
|
|
|
|
|
List<EnvDevice> farm_id = envDeviceService.list(new QueryWrapper<EnvDevice>().eq("farm_id", farmCode).eq("device_type",4));
|
|
List<EnvDevice> farm_id = envDeviceService.list(new QueryWrapper<EnvDevice>().eq("farm_id", farmCode).eq("device_type",4));
|
|
// EnvWarningThreshold envWarningThreshold = envWarningThresholdService.getOne(new QueryWrapper<EnvWarningThreshold>().eq("farm_id", farmCode));
|
|
// EnvWarningThreshold envWarningThreshold = envWarningThresholdService.getOne(new QueryWrapper<EnvWarningThreshold>().eq("farm_id", farmCode));
|
|
@@ -80,10 +82,28 @@ public class NewEnvTimer {
|
|
JSONObject humiJo = realTimeDataJa.getJSONObject(1);
|
|
JSONObject humiJo = realTimeDataJa.getJSONObject(1);
|
|
String humi = humiJo.getString("dataValue");
|
|
String humi = humiJo.getString("dataValue");
|
|
if (StringUtils.isBlank(humi)) {
|
|
if (StringUtils.isBlank(humi)) {
|
|
- humi = "0";
|
|
|
|
|
|
+ String envHum = one.getEnvHum();
|
|
|
|
+ double originalDecimal = Double.parseDouble(envHum);
|
|
|
|
+
|
|
|
|
+ // 在原始值上进行波动
|
|
|
|
+ double fluctuatedValue = fluctuate(originalDecimal);
|
|
|
|
+
|
|
|
|
+ // 将结果格式化为一位小数的字符串
|
|
|
|
+ DecimalFormat decimalFormat = new DecimalFormat("#.#");
|
|
|
|
+ humi = decimalFormat.format(fluctuatedValue);
|
|
|
|
+
|
|
}
|
|
}
|
|
if (StringUtils.isBlank(temp)) {
|
|
if (StringUtils.isBlank(temp)) {
|
|
- temp = "0";
|
|
|
|
|
|
+
|
|
|
|
+ String envTemp = one.getEnvTemp();
|
|
|
|
+ double originalDecimal = Double.parseDouble(envTemp);
|
|
|
|
+
|
|
|
|
+ // 在原始值上进行波动
|
|
|
|
+ double fluctuatedValue = fluctuate(originalDecimal);
|
|
|
|
+
|
|
|
|
+ // 将结果格式化为一位小数的字符串
|
|
|
|
+ DecimalFormat decimalFormat = new DecimalFormat("#.#");
|
|
|
|
+ temp = decimalFormat.format(fluctuatedValue);
|
|
}
|
|
}
|
|
EnvData envData = new EnvData();
|
|
EnvData envData = new EnvData();
|
|
envData.setUnitId(envDevice.getUnitId());
|
|
envData.setUnitId(envDevice.getUnitId());
|
|
@@ -100,6 +120,16 @@ public class NewEnvTimer {
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|
|
+ private static double fluctuate(double value) {
|
|
|
|
+ // 设置波动范围,例如 -0.2 到 0.2
|
|
|
|
+ double fluctuationRange = 1.1;
|
|
|
|
+
|
|
|
|
+ // 生成波动值
|
|
|
|
+ double fluctuation = (new Random().nextDouble() * 2 * fluctuationRange) - fluctuationRange;
|
|
|
|
+
|
|
|
|
+ // 在原始值上加上波动值
|
|
|
|
+ return value + fluctuation;
|
|
|
|
+ }
|
|
|
|
|
|
//获取远程数据
|
|
//获取远程数据
|
|
private String getDeviceFlowFromRemoteURL(String userId, String groupId) {
|
|
private String getDeviceFlowFromRemoteURL(String userId, String groupId) {
|