1. 调整
This commit is contained in:
parent
b7a1c8172e
commit
e9544c8518
|
@ -73,7 +73,9 @@ public class IotConstants {
|
|||
|
||||
/**----------------------------启动模式end----------------------------*/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* ONENET日志
|
||||
*/
|
||||
public static final String ONENET_LOG = "LOG";
|
||||
|
||||
}
|
||||
|
|
|
@ -48,80 +48,80 @@ public class IotLogTask {
|
|||
|
||||
@SneakyThrows
|
||||
public void getDeviceLog() {
|
||||
logger.info("定时任务--获取浇花器日志");
|
||||
/**1.获取到所有的设备列表*/
|
||||
List<AsDevice> asDevices = asDeviceMapper.selectAsDeviceList(null);
|
||||
for (AsDevice device : asDevices) {
|
||||
/**1.请求url获取到浇花器日志*/
|
||||
String param = "device_name=" + device.getMac() + "&product_id=" + productId;
|
||||
String sendUrl = iotUrl+ IotConstants.ADDS_HISTORY_DATAPOINTS + "?"+param;
|
||||
|
||||
String token = Token.getToken();
|
||||
logger.info("IOT获取到Authorization:【{}】",token);
|
||||
String result = HttpUtils.sendGetWithToken(sendUrl, null, token);
|
||||
|
||||
logger.info("IOT返回的结果【{}】",result);
|
||||
/**2.处理返回的参数*/
|
||||
DataPointRes dataPointRes = JSONObject.parseObject(result, DataPointRes.class);
|
||||
Data data = dataPointRes.getData();
|
||||
List<Datastream> datastreams = data.getDatastreams();
|
||||
|
||||
for (Datastream datastream: datastreams) {
|
||||
if(datastream.getId().equals("jj")){
|
||||
List<Datapoint> datapoints = datastream.getDatapoints();
|
||||
for (Object obj:datapoints) {
|
||||
// String s = JSON.toJSONString(obj);
|
||||
// Datapoint datapoint = JSONObject.parseObject(s, Datapoint.class);
|
||||
// DatapointValue value = datapoint.getValue();
|
||||
// DatapointValue.Ds ds = value.getDs();//定时
|
||||
// boolean kaiguan3 = ds.getKaiguan();//定时开关
|
||||
// int js_sec1 = ds.getJs_sec();//喷洒时间
|
||||
// int start_hour = ds.getStart_hour();//启动小时
|
||||
// int start_min = ds.getStart_min();//启动分钟
|
||||
// logger.info("定时任务--获取浇花器日志");
|
||||
// /**1.获取到所有的设备列表*/
|
||||
// List<AsDevice> asDevices = asDeviceMapper.selectAsDeviceList(null);
|
||||
// for (AsDevice device : asDevices) {
|
||||
// /**1.请求url获取到浇花器日志*/
|
||||
// String param = "device_name=" + device.getMac() + "&product_id=" + productId;
|
||||
// String sendUrl = iotUrl+ IotConstants.ADDS_HISTORY_DATAPOINTS + "?"+param;
|
||||
//
|
||||
// DatapointValue.Mc mc = value.getMc();//脉冲模式
|
||||
// int jg_sec = mc.getJg_sec();//间隔时间
|
||||
// int js_sec = mc.getJs_sec();//启动时间
|
||||
// boolean kaiguan2 = mc.getKaiguan();//开关
|
||||
// String token = Token.getToken();
|
||||
// logger.info("IOT获取到Authorization:【{}】",token);
|
||||
// String result = HttpUtils.sendGetWithToken(sendUrl, null, token);
|
||||
//
|
||||
// logger.info("IOT返回的结果【{}】",result);
|
||||
// /**2.处理返回的参数*/
|
||||
// DataPointRes dataPointRes = JSONObject.parseObject(result, DataPointRes.class);
|
||||
// Data data = dataPointRes.getData();
|
||||
// List<Datastream> datastreams = data.getDatastreams();
|
||||
//
|
||||
// for (Datastream datastream: datastreams) {
|
||||
// if(datastream.getId().equals("LOG")){
|
||||
// List<Datapoint> datapoints = datastream.getDatapoints();
|
||||
// for (Object obj:datapoints) {
|
||||
//// String s = JSON.toJSONString(obj);
|
||||
//// Datapoint datapoint = JSONObject.parseObject(s, Datapoint.class);
|
||||
//// DatapointValue value = datapoint.getValue();
|
||||
//// DatapointValue.Ds ds = value.getDs();//定时
|
||||
//// boolean kaiguan3 = ds.getKaiguan();//定时开关
|
||||
//// int js_sec1 = ds.getJs_sec();//喷洒时间
|
||||
//// int start_hour = ds.getStart_hour();//启动小时
|
||||
//// int start_min = ds.getStart_min();//启动分钟
|
||||
////
|
||||
//// DatapointValue.Mc mc = value.getMc();//脉冲模式
|
||||
//// int jg_sec = mc.getJg_sec();//间隔时间
|
||||
//// int js_sec = mc.getJs_sec();//启动时间
|
||||
//// boolean kaiguan2 = mc.getKaiguan();//开关
|
||||
////
|
||||
////
|
||||
//// DatapointValue.Set set = value.getSet();//设置
|
||||
//// boolean kaiguan1 = set.getKaiguan();//开关
|
||||
//// int xp_min = set.getXp_min();//息屏分钟
|
||||
////
|
||||
//// DatapointValue.Tr tr = value.getTr();//土壤
|
||||
//// int end_sd = tr.getEnd_sd();//结束湿度
|
||||
//// boolean kaiguan = tr.getKaiguan();//开关
|
||||
//// int start_sd = tr.getStart_sd();//启动湿度
|
||||
////
|
||||
//// int turan_show = value.getTuran_show();//土壤当前湿度
|
||||
//// int jiaoshui_qiangdu = value.getJiaoshui_qiangdu();//浇水强度
|
||||
////
|
||||
//// String s ="{\"water_time\":\"2023-12-06\",\"start_mode\":\"1\",\"spraying_time\":60,\"mc\":{\"jg_sec\":10,\"js_sec\":5,\"kaiguan\":false},\"jiaoshui_qiangdu\":3,\"start_moisture\":10,\"end_moisture\":10}\n";
|
||||
//// WateringLog wateringLog = JSONObject.parseObject(s, WateringLog.class);
|
||||
////
|
||||
//// /**3.将DatapointValue对象转成*/
|
||||
//// AsWateringRecord build = AsWateringRecord.builder()
|
||||
//// .deviceId(device.getDeviceId())
|
||||
//// .waterTime(DateUtils.dateTime(DateUtils.YYYY_MM_DD, wateringLog.getWater_time()))
|
||||
//// .startMode(wateringLog.getStart_mode())
|
||||
//// .sprayingTime(Integer.parseInt(wateringLog.getSpraying_time()))
|
||||
//// .pulseMode(wateringLog.getMc().getKaiguan() + "")
|
||||
//// .pulseModeParam(wateringLog.getMc().toString())
|
||||
//// .waterIntensity(wateringLog.getJiaoshui_qiangdu())
|
||||
//// .startMoisture(wateringLog.getStart_moisture())
|
||||
//// .endMoisture(wateringLog.getEnd_moisture())
|
||||
//// .userName(device.getUserName())
|
||||
//// .build();
|
||||
//// build.setCreateTime(DateUtils.getNowDate());
|
||||
//// int i = asWateringRecordMapper.insertAsWateringRecord(build);
|
||||
// /**3.根据最新时间保存数据*/
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
// DatapointValue.Set set = value.getSet();//设置
|
||||
// boolean kaiguan1 = set.getKaiguan();//开关
|
||||
// int xp_min = set.getXp_min();//息屏分钟
|
||||
//
|
||||
// DatapointValue.Tr tr = value.getTr();//土壤
|
||||
// int end_sd = tr.getEnd_sd();//结束湿度
|
||||
// boolean kaiguan = tr.getKaiguan();//开关
|
||||
// int start_sd = tr.getStart_sd();//启动湿度
|
||||
//
|
||||
// int turan_show = value.getTuran_show();//土壤当前湿度
|
||||
// int jiaoshui_qiangdu = value.getJiaoshui_qiangdu();//浇水强度
|
||||
|
||||
String s ="{\"water_time\":\"2023-12-06\",\"start_mode\":\"1\",\"spraying_time\":60,\"mc\":{\"jg_sec\":10,\"js_sec\":5,\"kaiguan\":false},\"jiaoshui_qiangdu\":3,\"start_moisture\":10,\"end_moisture\":10}\n";
|
||||
WateringLog wateringLog = JSONObject.parseObject(s, WateringLog.class);
|
||||
|
||||
/**3.将DatapointValue对象转成*/
|
||||
AsWateringRecord build = AsWateringRecord.builder()
|
||||
.deviceId(device.getDeviceId())
|
||||
.waterTime(DateUtils.dateTime(DateUtils.YYYY_MM_DD, wateringLog.getWater_time()))
|
||||
.startMode(wateringLog.getStart_mode())
|
||||
.sprayingTime(Integer.parseInt(wateringLog.getSpraying_time()))
|
||||
.pulseMode(wateringLog.getMc().getKaiguan() + "")
|
||||
.pulseModeParam(wateringLog.getMc().toString())
|
||||
.waterIntensity(wateringLog.getJiaoshui_qiangdu())
|
||||
.startMoisture(wateringLog.getStart_moisture())
|
||||
.endMoisture(wateringLog.getEnd_moisture())
|
||||
.userName(device.getUserName())
|
||||
.build();
|
||||
build.setCreateTime(DateUtils.getNowDate());
|
||||
int i = asWateringRecordMapper.insertAsWateringRecord(build);
|
||||
/**3.根据最新时间保存数据*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
// }
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,11 +7,10 @@ import lombok.Builder;
|
|||
import lombok.Data;
|
||||
import com.ruoyi.common.annotation.Excel;
|
||||
import com.ruoyi.common.core.domain.BaseEntity;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
/**
|
||||
* 浇水记录对象 as_watering_record
|
||||
*
|
||||
*
|
||||
* @author ruoyi
|
||||
* @date 2023-11-21
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
package com.ruoyi.device.iot.domain;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* onenet接收到的浇花器日志对象
|
||||
* */
|
||||
@Data
|
||||
public class LogEntry {
|
||||
|
||||
//mac号
|
||||
@JsonProperty("dev_name")
|
||||
private String devName;
|
||||
|
||||
private long at;
|
||||
|
||||
private String pid;
|
||||
|
||||
private int type;
|
||||
|
||||
@JsonProperty("ds_id")
|
||||
private String dsId;
|
||||
|
||||
private String value;
|
||||
|
||||
}
|
|
@ -1,14 +1,23 @@
|
|||
package com.ruoyi.device.iot.receive;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.ruoyi.common.constant.IotConstants;
|
||||
import com.ruoyi.device.domain.AsDevice;
|
||||
import com.ruoyi.device.domain.AsWateringRecord;
|
||||
import com.ruoyi.device.iot.domain.BodyObj;
|
||||
import com.ruoyi.device.iot.domain.LogEntry;
|
||||
import com.ruoyi.device.iot.util.Util;
|
||||
import com.ruoyi.device.mapper.AsDeviceMapper;
|
||||
import com.ruoyi.device.mapper.AsWateringRecordMapper;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 接收硬件参数
|
||||
|
@ -24,6 +33,12 @@ public class ReceiveController {
|
|||
@Value(value = "${watering.token}")
|
||||
private String token;
|
||||
|
||||
@Resource
|
||||
private AsWateringRecordMapper wateringRecordMapper;
|
||||
|
||||
@Resource
|
||||
private AsDeviceMapper asDeviceMapper;
|
||||
|
||||
/**
|
||||
* 功能描述:第三方平台数据接收。<p>
|
||||
* <ul>注:
|
||||
|
@ -50,11 +65,25 @@ public class ReceiveController {
|
|||
boolean dataRight = Util.checkSignature(obj, token);
|
||||
if (dataRight){
|
||||
log.info("receive方法验证签名正确: content" + JSON.toJSONString(obj));
|
||||
Object msg = obj.getMsg();
|
||||
/**TODO 接收到msg 更新设备参数*/
|
||||
// msg.
|
||||
log.info("receive方法-获取到消息体: msg---" + JSON.toJSONString(msg));
|
||||
|
||||
String msg = (String)obj.getMsg();
|
||||
/**接收到msg 更新浇水记录*/
|
||||
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")){
|
||||
/**如果是日志信息则加入到浇花记录中*/
|
||||
AsDevice device = asDeviceMapper.selectAsDeviceByMac(logEntry.getDevName());
|
||||
/** 4.保存浇水记录 保存 as_watering_record表*/
|
||||
AsWateringRecord record = AsWateringRecord.builder()
|
||||
.deviceId(device.getDeviceId())
|
||||
.waterTime(new Date(logEntry.getAt()))
|
||||
.sprayingTime("0".equals(logEntry.getValue())?0:Integer.parseInt(logEntry.getValue()))
|
||||
.build();
|
||||
int insert = wateringRecordMapper.insertAsWateringRecord(record);
|
||||
if(insert>0){
|
||||
log.info("保存浇水记录成功---【{}】",JSON.toJSON(record));
|
||||
}
|
||||
}
|
||||
}else {
|
||||
log.info("receive方法验证签名错误: signature error");
|
||||
}
|
||||
|
@ -63,28 +92,6 @@ public class ReceiveController {
|
|||
log.info("receive方法参数为空: body empty error");
|
||||
}
|
||||
/*************明文模式 end****************/
|
||||
|
||||
|
||||
/********************************************************
|
||||
* 解析数据推送请求,加密模式
|
||||
*
|
||||
* 如果是加密模式使用以下代码
|
||||
********************************************************/
|
||||
/*************加密模式 start****************/
|
||||
// Util.BodyObj obj1 = Util.resolveBody(body, true);
|
||||
// logger.info("data receive: body Object--- " +obj1);
|
||||
// if (obj1 != null){
|
||||
// boolean dataRight1 = Util.checkSignature(obj1, token);
|
||||
// if (dataRight1){
|
||||
// String msg = Util.decryptMsg(obj1, aeskey);
|
||||
// logger.info("data receive: content" + msg);
|
||||
// }else {
|
||||
// logger.info("data receive: signature error " );
|
||||
// }
|
||||
// }else {
|
||||
// logger.info("data receive: body empty error" );
|
||||
// }
|
||||
/*************加密模式 end****************/
|
||||
return "ok";
|
||||
}
|
||||
|
||||
|
@ -104,8 +111,10 @@ public class ReceiveController {
|
|||
|
||||
log.info("check方法接收到参数:: msg:{} nonce{} signature:{}",msg,nonce,signature);
|
||||
if (Util.checkToken(msg,nonce,signature,token)){
|
||||
log.info("校验成功",msg,nonce,signature);
|
||||
return msg;
|
||||
}else {
|
||||
log.info("校验失败",msg,nonce,signature);
|
||||
return "error";
|
||||
}
|
||||
|
||||
|
|
|
@ -413,18 +413,18 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
|
|||
}
|
||||
logger.info("IOT请求调用结果:【{}】",result);
|
||||
|
||||
/** 4.保存浇水记录 保存 as_watering_record表*/
|
||||
AsWateringRecord record = AsWateringRecord.builder()
|
||||
.deviceId(device.getDeviceId())
|
||||
.waterTime(DateUtils.getNowDate())
|
||||
.startMode(IotConstants.START_MODE_MANUAL)
|
||||
.pulseMode(device.getPulseMode())
|
||||
.pulseModeParam(device.getPulseModeParam())
|
||||
// .sprayingTime(device.getPulseModeParam()) //喷洒时间
|
||||
// .userName(getUsername())
|
||||
.build();
|
||||
int insert = wateringRecordMapper.insertAsWateringRecord(record);
|
||||
return AjaxResult.success(insert);
|
||||
// /** 4.保存浇水记录 保存 as_watering_record表*/
|
||||
// AsWateringRecord record = AsWateringRecord.builder()
|
||||
// .deviceId(device.getDeviceId())
|
||||
// .waterTime(DateUtils.getNowDate())
|
||||
// .startMode(IotConstants.START_MODE_MANUAL)
|
||||
// .pulseMode(device.getPulseMode())
|
||||
// .pulseModeParam(device.getPulseModeParam())
|
||||
//// .sprayingTime(device.getPulseModeParam()) //喷洒时间
|
||||
//// .userName(getUsername())
|
||||
// .build();
|
||||
// int insert = wateringRecordMapper.insertAsWateringRecord(record);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -50,7 +50,10 @@ public class AsWateringRecordServiceImpl extends ServiceImpl<AsWateringRecordMap
|
|||
{
|
||||
List<AsWateringRecord> asWateringRecords = asWateringRecordMapper.selectAsWateringRecordList(asWateringRecord);
|
||||
for (AsWateringRecord record :asWateringRecords) {
|
||||
record.setStartMode(DictUtils.getDictLabel("as_start_mode", record.getStartMode()));
|
||||
String startMode = record.getStartMode();
|
||||
if(StringUtils.isNotEmpty(startMode)){
|
||||
record.setStartMode(DictUtils.getDictLabel("as_start_mode", startMode));
|
||||
}
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
if("1".equals(record.getPulseMode())){//脉冲模式
|
||||
stringBuilder.append("脉冲模式浇水");
|
||||
|
|
Loading…
Reference in New Issue
Block a user