2023-11-20 11:03:11 +08:00
|
|
|
package com.ruoyi.quartz.task;
|
|
|
|
|
2023-11-25 11:54:32 +08:00
|
|
|
import com.alibaba.fastjson2.JSON;
|
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
|
import com.ruoyi.common.constant.IotConstants;
|
|
|
|
import com.ruoyi.common.utils.http.HttpUtils;
|
|
|
|
import com.ruoyi.common.utils.onenet.Token;
|
|
|
|
import com.ruoyi.device.domain.AsWateringRecord;
|
|
|
|
import com.ruoyi.device.mapper.AsWateringRecordMapper;
|
|
|
|
import com.ruoyi.quartz.domain.Data;
|
|
|
|
import com.ruoyi.quartz.domain.DataPointRes;
|
|
|
|
import com.ruoyi.quartz.domain.Datastream;
|
|
|
|
import lombok.SneakyThrows;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
2023-11-20 11:03:11 +08:00
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
2023-11-25 11:54:32 +08:00
|
|
|
import javax.annotation.Resource;
|
|
|
|
import java.util.List;
|
|
|
|
|
2023-11-20 11:03:11 +08:00
|
|
|
/**
|
|
|
|
* 定时获取浇花器日志
|
|
|
|
*
|
|
|
|
* @author qiuzhenzhao
|
|
|
|
*/
|
|
|
|
@Component("logTask")
|
|
|
|
public class IotLogTask {
|
|
|
|
|
2023-11-25 11:54:32 +08:00
|
|
|
private static final Logger logger = LoggerFactory.getLogger(IotLogTask.class);
|
|
|
|
|
|
|
|
@Value(value = "${watering.iotUrl}")
|
|
|
|
private String iotUrl;
|
|
|
|
|
|
|
|
@Value(value = "${watering.productId}")
|
|
|
|
private String productId;
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
private AsWateringRecordMapper asWateringRecordMapper;
|
|
|
|
|
|
|
|
|
|
|
|
@SneakyThrows
|
|
|
|
public void getDeviceLog() {
|
|
|
|
logger.info("定时任务--获取浇花器日志");
|
|
|
|
/**1.请求url获取到浇花器日志*/
|
|
|
|
// String deviceName = asDevice.getMac();//mac地址就是产品名称
|
|
|
|
String param = "device_name=" + "4827E2945C54" + "&product_id=" + productId;
|
|
|
|
String sendUrl = iotUrl+ IotConstants.ADDS_HISTORY_DATAPOINTS + "?"+param;
|
|
|
|
|
|
|
|
String token = Token.getToken();
|
|
|
|
logger.info("IOT获取到Authorization:【{}】",token);
|
|
|
|
String result = HttpUtils.sendPostWithToken(sendUrl, "command", token);
|
|
|
|
|
|
|
|
/**2.处理返回的参数*/
|
|
|
|
// JSONObject paramsObj = JSON.parseObject(result);
|
|
|
|
DataPointRes dataPointRes = JSONObject.parseObject(result, DataPointRes.class);
|
|
|
|
Data data = dataPointRes.getData();
|
|
|
|
List<Datastream> datastreams = data.getDatastreams();
|
|
|
|
// String code = paramsObj.getString("code");
|
|
|
|
// String msg = paramsObj.getString("msg");
|
2023-11-21 16:35:16 +08:00
|
|
|
|
2023-11-25 11:54:32 +08:00
|
|
|
/**3.将DatapointValue对象转成*/
|
|
|
|
asWateringRecordMapper.insertAsWateringRecord(AsWateringRecord.builder()
|
|
|
|
.userName("")
|
|
|
|
.deviceId(1L)
|
|
|
|
// .waterTime()
|
2023-11-21 16:35:16 +08:00
|
|
|
|
2023-11-25 11:54:32 +08:00
|
|
|
.build());
|
2023-11-21 16:35:16 +08:00
|
|
|
|
2023-11-25 11:54:32 +08:00
|
|
|
/**3.根据最新时间保存数据*/
|
2023-11-20 11:03:11 +08:00
|
|
|
}
|
|
|
|
}
|