新设备flag=1 ;老设备type=5

This commit is contained in:
gongjiale 2024-12-04 10:03:21 +08:00
parent 31b41ca39d
commit 9edb776849
1 changed files with 28 additions and 24 deletions

View File

@ -31,25 +31,27 @@ public class OutSideServiceImpl implements OutSideService {
ObjectMapper objectMapper = new ObjectMapper(); ObjectMapper objectMapper = new ObjectMapper();
JsonNode rootNode = objectMapper.readTree(jsonData); JsonNode rootNode = objectMapper.readTree(jsonData);
for (JsonNode sensorNode : rootNode.get("sensorDatas")) { for (JsonNode sensorNode : rootNode.get("sensorDatas")) {
sensorData.setSn(sn); if (sensorNode.get("flag").asInt()==1) {
sensorData.setFlag(sensorNode.get("flag").asText()); sensorData.setSn(sn);
sensorData.setDs(sensorNode.get("gas_value").asText()); sensorData.setFlag(sensorNode.get("flag").asText());
sensorData.setJcjd(sensorNode.get("gas_dec").asInt()); sensorData.setDs(sensorNode.get("gas_value").asText());
// gas_status 转换为中文状态描述 sensorData.setJcjd(sensorNode.get("gas_dec").asInt());
int gasStatus = sensorNode.get("gas_status").asInt(); // gas_status 转换为中文状态描述
String statusDescription = getStatusDescription(gasStatus); // 调用转换方法 int gasStatus = sensorNode.get("gas_status").asInt();
sensorData.setZt(statusDescription); String statusDescription = getStatusDescription(gasStatus); // 调用转换方法
sensorData.setZl(sensorNode.get("gas_type").asText()); sensorData.setZt(statusDescription);
// gas_unit 转换为对应单位 sensorData.setZl(sensorNode.get("gas_type").asText());
int gasUnit = sensorNode.get("gas_unit").asInt(); // gas_unit 转换为对应单位
String unitDescription = getUnitDescription(gasUnit); // 调用转换方法 int gasUnit = sensorNode.get("gas_unit").asInt();
sensorData.setDw(unitDescription); // 将中文单位设置到 dw 字段 String unitDescription = getUnitDescription(gasUnit); // 调用转换方法
sensorData.setDbz(sensorNode.get("alarml").asText()); sensorData.setDw(unitDescription); // 将中文单位设置到 dw 字段
sensorData.setGbz(sensorNode.get("alarmh").asText()); sensorData.setDbz(sensorNode.get("alarml").asText());
sensorData.setLc(sensorNode.get("gas_range").asText()); sensorData.setGbz(sensorNode.get("alarmh").asText());
sensorData.setJcjd(sensorNode.get("gas_dec").asInt());//检测精度 sensorData.setLc(sensorNode.get("gas_range").asText());
sensorData.setReportTime(DateUtils.getTime()); sensorData.setJcjd(sensorNode.get("gas_dec").asInt());//检测精度
outSideMapper.insertDevice(sensorData); sensorData.setReportTime(DateUtils.getTime());
outSideMapper.insertDevice(sensorData);
}
} }
return 1; return 1;
} catch (Exception e) { } catch (Exception e) {
@ -82,14 +84,16 @@ public class OutSideServiceImpl implements OutSideService {
// 判断是否是数组 // 判断是否是数组
if (rootNode.isArray()) { if (rootNode.isArray()) {
for (JsonNode node : rootNode) { for (JsonNode node : rootNode) {
if (node.get("type").asInt()==5) {
SensorData sd = insertOldData(node); SensorData sd = insertOldData(node);
outSideMapper.insertDevice(sd);
outSideMapper.insertDevice(sd); }
} }
} else {
SensorData sd = insertOldData(rootNode);
outSideMapper.insertDevice(sd);
} }
// else {
// SensorData sd = insertOldData(rootNode);
// outSideMapper.insertDevice(sd);
// }
return 0; return 0;
} }