1. 浇水记录

This commit is contained in:
邱贞招 2024-04-27 09:50:01 +08:00
parent 81ad0e724f
commit 1dc4d9fb1d
3 changed files with 16 additions and 4 deletions

View File

@ -22,6 +22,14 @@ public class LogEntry {
@JsonProperty("ds_id") @JsonProperty("ds_id")
private String dsId; 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;//浇水时长
}
} }

View File

@ -1,5 +1,6 @@
package com.ruoyi.device.iot.receive; package com.ruoyi.device.iot.receive;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject; import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.constant.IotConstants; import com.ruoyi.common.constant.IotConstants;
@ -70,14 +71,17 @@ public class ReceiveController {
log.info("receive方法-获取到消息体: msg---" +msg); log.info("receive方法-获取到消息体: msg---" +msg);
LogEntry logEntry = JSONObject.parseObject(msg, LogEntry.class); LogEntry logEntry = JSONObject.parseObject(msg, LogEntry.class);
log.info("logEntry转换后的对象: logEntry---【{}】" , JSON.toJSONString(logEntry)); 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()); AsDevice device = asDeviceMapper.selectAsDeviceByMac(logEntry.getDevName());
LogEntry.WateringMode value = logEntry.getValue();
/** 4.保存浇水记录 保存 as_watering_record表*/ /** 4.保存浇水记录 保存 as_watering_record表*/
AsWateringRecord record = AsWateringRecord.builder() AsWateringRecord record = AsWateringRecord.builder()
.deviceId(device.getDeviceId()) .deviceId(device.getDeviceId())
.startMode(value.getMode()+"")
.waterTime(new Date(logEntry.getAt())) .waterTime(new Date(logEntry.getAt()))
.sprayingTime("0".equals(logEntry.getValue())?0:Integer.parseInt(logEntry.getValue())) .waterIntensity(value.getQd())
.sprayingTime(value.getTime())
.build(); .build();
int insert = wateringRecordMapper.insertAsWateringRecord(record); int insert = wateringRecordMapper.insertAsWateringRecord(record);
if(insert>0){ if(insert>0){

View File

@ -126,7 +126,7 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
/** /**
* 根据mac号查询设备信息 * 根据mac号查询设备信息
* *
* @param mac 设备列表主键 * @param asDevice 设备对象
* @return 设备信息 * @return 设备信息
*/ */
@Override @Override