From 4435339e7ba345ca5a1d6ff990645394d8e6b0ba Mon Sep 17 00:00:00 2001 From: LokerL Date: Thu, 24 Oct 2024 10:17:28 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9E=20fix:=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E4=BC=A0=E6=84=9F=E5=99=A8=E6=95=B0=E6=8D=AE=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=EF=BC=8C=E8=B0=83=E6=95=B4=E6=8A=A5=E5=91=8A=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E4=B8=BA=E5=AD=97=E7=AC=A6=E4=B8=B2=E5=B9=B6?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=95=B0=E6=8D=AE=E6=8F=92=E5=85=A5=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../project/outside/domain/SensorData.java | 6 +-- .../service/impl/OutSideServiceImpl.java | 42 +++++++++---------- .../mybatis/outside/OutSideMapper.xml | 2 +- 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/RuoYi-Vue-Oracle/src/main/java/com/ruoyi/project/outside/domain/SensorData.java b/RuoYi-Vue-Oracle/src/main/java/com/ruoyi/project/outside/domain/SensorData.java index 9825355..f45adc2 100644 --- a/RuoYi-Vue-Oracle/src/main/java/com/ruoyi/project/outside/domain/SensorData.java +++ b/RuoYi-Vue-Oracle/src/main/java/com/ruoyi/project/outside/domain/SensorData.java @@ -9,7 +9,7 @@ public class SensorData { * 上报时间 */ @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") - private Date reportTime; + private String reportTime; /** * 设备编码 */ @@ -97,11 +97,11 @@ public class SensorData { return zl; } - public Date getReportTime() { + public String getReportTime() { return reportTime; } - public void setReportTime(Date reportTime) { + public void setReportTime(String reportTime) { this.reportTime = reportTime; } diff --git a/RuoYi-Vue-Oracle/src/main/java/com/ruoyi/project/outside/service/impl/OutSideServiceImpl.java b/RuoYi-Vue-Oracle/src/main/java/com/ruoyi/project/outside/service/impl/OutSideServiceImpl.java index 1fbd021..bf46665 100644 --- a/RuoYi-Vue-Oracle/src/main/java/com/ruoyi/project/outside/service/impl/OutSideServiceImpl.java +++ b/RuoYi-Vue-Oracle/src/main/java/com/ruoyi/project/outside/service/impl/OutSideServiceImpl.java @@ -29,27 +29,27 @@ public class OutSideServiceImpl implements OutSideService { String jsonData = data.substring(16); ObjectMapper objectMapper = new ObjectMapper(); JsonNode rootNode = objectMapper.readTree(jsonData); - JsonNode sensorNode = rootNode.get("sensorDatas").get(0); // 获取第一个 sensorData - sensorData.setSn(sn); - sensorData.setFlag(sensorNode.get("flag").asText()); - sensorData.setDs(sensorNode.get("gas_value").asText()); - sensorData.setJcjd(sensorNode.get("gas_dec").asInt()); - // 将 gas_status 转换为中文状态描述 - int gasStatus = sensorNode.get("gas_status").asInt(); - String statusDescription = getStatusDescription(gasStatus); // 调用转换方法 - sensorData.setZt(statusDescription); - // sensorData.setZl(sensorNode.get("gas_type").asText()); 写死了 都是VOCS - sensorData.setZl("VOCS"); - // 将 gas_unit 转换为对应单位 - int gasUnit = sensorNode.get("gas_unit").asInt(); - String unitDescription = getUnitDescription(gasUnit); // 调用转换方法 - sensorData.setDw(unitDescription); // 将中文单位设置到 dw 字段 - sensorData.setDbz(sensorNode.get("alarml").asText()); - sensorData.setGbz(sensorNode.get("alarmh").asText()); - sensorData.setLc(sensorNode.get("gas_range").asText()); - sensorData.setJcjd(sensorNode.get("gas_dec").asInt());//检测精度 - sensorData.setReportTime(DateUtils.getNowDate()); - outSideMapper.insertDevice(sensorData); + for (JsonNode sensorNode : rootNode.get("sensorDatas")) { + sensorData.setSn(sn); + sensorData.setFlag(sensorNode.get("flag").asText()); + sensorData.setDs(sensorNode.get("gas_value").asText()); + sensorData.setJcjd(sensorNode.get("gas_dec").asInt()); + // 将 gas_status 转换为中文状态描述 + int gasStatus = sensorNode.get("gas_status").asInt(); + String statusDescription = getStatusDescription(gasStatus); // 调用转换方法 + sensorData.setZt(statusDescription); + sensorData.setZl(sensorNode.get("gas_type").asText()); + // 将 gas_unit 转换为对应单位 + int gasUnit = sensorNode.get("gas_unit").asInt(); + String unitDescription = getUnitDescription(gasUnit); // 调用转换方法 + sensorData.setDw(unitDescription); // 将中文单位设置到 dw 字段 + sensorData.setDbz(sensorNode.get("alarml").asText()); + sensorData.setGbz(sensorNode.get("alarmh").asText()); + sensorData.setLc(sensorNode.get("gas_range").asText()); + sensorData.setJcjd(sensorNode.get("gas_dec").asInt());//检测精度 + sensorData.setReportTime(DateUtils.getTime()); + outSideMapper.insertDevice(sensorData); + } return 1; }catch (Exception e) { System.out.println(e); diff --git a/RuoYi-Vue-Oracle/src/main/resources/mybatis/outside/OutSideMapper.xml b/RuoYi-Vue-Oracle/src/main/resources/mybatis/outside/OutSideMapper.xml index 77d872f..c3c5ab4 100644 --- a/RuoYi-Vue-Oracle/src/main/resources/mybatis/outside/OutSideMapper.xml +++ b/RuoYi-Vue-Oracle/src/main/resources/mybatis/outside/OutSideMapper.xml @@ -25,7 +25,7 @@ LC ) VALUES ( #{sn, jdbcType=NVARCHAR}, - #{reportTime, jdbcType=DATE}, + TO_DATE(#{reportTime}, 'yyyy-mm-dd hh24:mi:ss'), #{ds, jdbcType=NVARCHAR}, #{gbz, jdbcType=NVARCHAR}, #{dbz, jdbcType=NVARCHAR},