diff --git a/AutoSprout-watering/src/main/java/com/ruoyi/device/iot/domain/LogEntry.java b/AutoSprout-watering/src/main/java/com/ruoyi/device/iot/domain/LogEntry.java index 8d4a6ca..9d489bd 100644 --- a/AutoSprout-watering/src/main/java/com/ruoyi/device/iot/domain/LogEntry.java +++ b/AutoSprout-watering/src/main/java/com/ruoyi/device/iot/domain/LogEntry.java @@ -22,6 +22,14 @@ public class LogEntry { @JsonProperty("ds_id") private String dsId; - private String value; + private WateringMode value; + @Data + public class WateringMode { + private int mode;//模式: 1 土壤浇水 2定时浇水 3远程下发浇水 4手动浇水 + + private int qd;//浇水强度 + + private int time;//浇水时长:秒 + } } diff --git a/AutoSprout-watering/src/main/java/com/ruoyi/device/iot/receive/ReceiveController.java b/AutoSprout-watering/src/main/java/com/ruoyi/device/iot/receive/ReceiveController.java index 76bad7c..b07e462 100644 --- a/AutoSprout-watering/src/main/java/com/ruoyi/device/iot/receive/ReceiveController.java +++ b/AutoSprout-watering/src/main/java/com/ruoyi/device/iot/receive/ReceiveController.java @@ -1,5 +1,6 @@ package com.ruoyi.device.iot.receive; +import cn.hutool.core.util.ObjectUtil; import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSONObject; import com.ruoyi.common.constant.IotConstants; @@ -70,14 +71,17 @@ public class ReceiveController { log.info("receive方法-获取到消息体: msg---" +msg); LogEntry logEntry = JSONObject.parseObject(msg, LogEntry.class); log.info("logEntry转换后的对象: logEntry---【{}】" , JSON.toJSONString(logEntry)); - if(IotConstants.ONENET_LOG.equals(logEntry.getDsId()) && !logEntry.getValue().equals("0")){ + if(IotConstants.ONENET_LOG.equals(logEntry.getDsId()) && ObjectUtil.isNotNull(logEntry.getValue())){ /**如果是日志信息则加入到浇花记录中*/ AsDevice device = asDeviceMapper.selectAsDeviceByMac(logEntry.getDevName()); + LogEntry.WateringMode value = logEntry.getValue(); /** 4.保存浇水记录 保存 as_watering_record表*/ AsWateringRecord record = AsWateringRecord.builder() .deviceId(device.getDeviceId()) + .startMode(value.getMode()+"") .waterTime(new Date(logEntry.getAt())) - .sprayingTime("0".equals(logEntry.getValue())?0:Integer.parseInt(logEntry.getValue())) + .waterIntensity(value.getQd()) + .sprayingTime(value.getTime()) .build(); int insert = wateringRecordMapper.insertAsWateringRecord(record); if(insert>0){ diff --git a/AutoSprout-watering/src/main/java/com/ruoyi/device/service/impl/AsDeviceServiceImpl.java b/AutoSprout-watering/src/main/java/com/ruoyi/device/service/impl/AsDeviceServiceImpl.java index 0ac37c9..5c7c14b 100644 --- a/AutoSprout-watering/src/main/java/com/ruoyi/device/service/impl/AsDeviceServiceImpl.java +++ b/AutoSprout-watering/src/main/java/com/ruoyi/device/service/impl/AsDeviceServiceImpl.java @@ -126,7 +126,7 @@ public class AsDeviceServiceImpl extends ServiceImpl i /** * 根据mac号查询设备信息 * - * @param mac 设备列表主键 + * @param asDevice 设备对象 * @return 设备信息 */ @Override