🐞 fix: 修改传感器数据模型,调整报告时间类型为字符串并更新数据插入逻辑

This commit is contained in:
LokerL 2024-10-24 10:17:28 +08:00
parent be99d7e3e0
commit 4435339e7b
3 changed files with 25 additions and 25 deletions

View File

@ -9,7 +9,7 @@ public class SensorData {
* 上报时间 * 上报时间
*/ */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date reportTime; private String reportTime;
/** /**
* 设备编码 * 设备编码
*/ */
@ -97,11 +97,11 @@ public class SensorData {
return zl; return zl;
} }
public Date getReportTime() { public String getReportTime() {
return reportTime; return reportTime;
} }
public void setReportTime(Date reportTime) { public void setReportTime(String reportTime) {
this.reportTime = reportTime; this.reportTime = reportTime;
} }

View File

@ -29,27 +29,27 @@ public class OutSideServiceImpl implements OutSideService {
String jsonData = data.substring(16); String jsonData = data.substring(16);
ObjectMapper objectMapper = new ObjectMapper(); ObjectMapper objectMapper = new ObjectMapper();
JsonNode rootNode = objectMapper.readTree(jsonData); JsonNode rootNode = objectMapper.readTree(jsonData);
JsonNode sensorNode = rootNode.get("sensorDatas").get(0); // 获取第一个 sensorData for (JsonNode sensorNode : rootNode.get("sensorDatas")) {
sensorData.setSn(sn); sensorData.setSn(sn);
sensorData.setFlag(sensorNode.get("flag").asText()); sensorData.setFlag(sensorNode.get("flag").asText());
sensorData.setDs(sensorNode.get("gas_value").asText()); sensorData.setDs(sensorNode.get("gas_value").asText());
sensorData.setJcjd(sensorNode.get("gas_dec").asInt()); sensorData.setJcjd(sensorNode.get("gas_dec").asInt());
// gas_status 转换为中文状态描述 // gas_status 转换为中文状态描述
int gasStatus = sensorNode.get("gas_status").asInt(); int gasStatus = sensorNode.get("gas_status").asInt();
String statusDescription = getStatusDescription(gasStatus); // 调用转换方法 String statusDescription = getStatusDescription(gasStatus); // 调用转换方法
sensorData.setZt(statusDescription); sensorData.setZt(statusDescription);
// sensorData.setZl(sensorNode.get("gas_type").asText()); 写死了 都是VOCS sensorData.setZl(sensorNode.get("gas_type").asText());
sensorData.setZl("VOCS"); // gas_unit 转换为对应单位
// gas_unit 转换为对应单位 int gasUnit = sensorNode.get("gas_unit").asInt();
int gasUnit = sensorNode.get("gas_unit").asInt(); String unitDescription = getUnitDescription(gasUnit); // 调用转换方法
String unitDescription = getUnitDescription(gasUnit); // 调用转换方法 sensorData.setDw(unitDescription); // 将中文单位设置到 dw 字段
sensorData.setDw(unitDescription); // 将中文单位设置到 dw 字段 sensorData.setDbz(sensorNode.get("alarml").asText());
sensorData.setDbz(sensorNode.get("alarml").asText()); sensorData.setGbz(sensorNode.get("alarmh").asText());
sensorData.setGbz(sensorNode.get("alarmh").asText()); sensorData.setLc(sensorNode.get("gas_range").asText());
sensorData.setLc(sensorNode.get("gas_range").asText()); sensorData.setJcjd(sensorNode.get("gas_dec").asInt());//检测精度
sensorData.setJcjd(sensorNode.get("gas_dec").asInt());//检测精度 sensorData.setReportTime(DateUtils.getTime());
sensorData.setReportTime(DateUtils.getNowDate()); outSideMapper.insertDevice(sensorData);
outSideMapper.insertDevice(sensorData); }
return 1; return 1;
}catch (Exception e) { }catch (Exception e) {
System.out.println(e); System.out.println(e);

View File

@ -25,7 +25,7 @@
LC LC
) VALUES ( ) VALUES (
#{sn, jdbcType=NVARCHAR}, #{sn, jdbcType=NVARCHAR},
#{reportTime, jdbcType=DATE}, TO_DATE(#{reportTime}, 'yyyy-mm-dd hh24:mi:ss'),
#{ds, jdbcType=NVARCHAR}, #{ds, jdbcType=NVARCHAR},
#{gbz, jdbcType=NVARCHAR}, #{gbz, jdbcType=NVARCHAR},
#{dbz, jdbcType=NVARCHAR}, #{dbz, jdbcType=NVARCHAR},