虫情、气象接口数据
This commit is contained in:
parent
4cd7499be5
commit
61e3e76116
@ -0,0 +1,80 @@
|
|||||||
|
package com.fastbee.deviceData.api.renke.constant;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.fastbee.common.annotation.Log;
|
||||||
|
import com.fastbee.common.config.RuoYiConfig;
|
||||||
|
import com.fastbee.common.core.controller.BaseController;
|
||||||
|
import com.fastbee.common.core.domain.AjaxResult;
|
||||||
|
import com.fastbee.common.core.page.TableDataInfo;
|
||||||
|
import com.fastbee.common.enums.BusinessType;
|
||||||
|
import com.fastbee.common.exception.ServiceException;
|
||||||
|
import com.fastbee.common.model.bto.DoorAlertBto;
|
||||||
|
import com.fastbee.common.utils.RotateImageUtils;
|
||||||
|
import com.fastbee.common.utils.file.FileUploadUtils;
|
||||||
|
import com.fastbee.common.utils.poi.ExcelUtil;
|
||||||
|
import com.fastbee.deviceData.api.renke.domin.*;
|
||||||
|
import com.fastbee.deviceData.api.renke.service.RenkeMetDeviceService;
|
||||||
|
import com.fastbee.deviceData.api.renke.service.RenkeWormSituationDeviceService;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.math.RoundingMode;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static com.fastbee.common.utils.StringUtils.isEmpty;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设备告警上传Controller
|
||||||
|
*
|
||||||
|
* @author Dunxi Zang
|
||||||
|
* @date 2024-06-19
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/iot/photos")
|
||||||
|
@Api(tags = "安防小板")
|
||||||
|
public class test extends BaseController {
|
||||||
|
@Autowired
|
||||||
|
private RenkeWormSituationDeviceService renkeWormSituationDeviceService;
|
||||||
|
@Autowired
|
||||||
|
private RenkeMetDeviceService renkeMetDeviceService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询设备告警上传列表
|
||||||
|
*/
|
||||||
|
|
||||||
|
@GetMapping("/test")
|
||||||
|
public Object list() {
|
||||||
|
RenkeWormSituationDeviceService service = new RenkeWormSituationDeviceService();
|
||||||
|
String deviceAddr= "1017240042";
|
||||||
|
String groupId = "1";
|
||||||
|
String recordIds = "1";
|
||||||
|
String token = "199491731313034631";
|
||||||
|
String beginTime = "2024-10-30 10:00:00",
|
||||||
|
endTime = "2024-11-12 10:00:00";
|
||||||
|
Integer pages = 1;
|
||||||
|
Integer limit = 1;
|
||||||
|
String nodeId = "1";
|
||||||
|
String enable = "1";
|
||||||
|
return renkeMetDeviceService.getWormDataList(deviceAddr,nodeId,beginTime,endTime,pages,limit,token);
|
||||||
|
}
|
||||||
|
@PostMapping("/testJosn")
|
||||||
|
public Object testJosn(@RequestBody UpdateNodeInfo json) {
|
||||||
|
|
||||||
|
|
||||||
|
String token = "91191731304831841";
|
||||||
|
return renkeMetDeviceService.updateNodeInfo(json,token);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
package com.fastbee.deviceData.api.renke.domin;
|
||||||
|
|
||||||
|
public class GetWormHistoryData {
|
||||||
|
public String deviceAddr;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
package com.fastbee.deviceData.api.renke.domin;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class ModWormAutoMode {
|
||||||
|
public String deviceAddr;
|
||||||
|
public String beginTime;
|
||||||
|
public String endtime;
|
||||||
|
public String beginTime2;
|
||||||
|
public String endtime2;
|
||||||
|
public Integer runHour;
|
||||||
|
public Integer dryingHum;
|
||||||
|
public Integer dryingHumHystersis;
|
||||||
|
public Integer delayAfterRain;
|
||||||
|
public Integer openingTimeOfTrapLamp;
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
package com.fastbee.deviceData.api.renke.domin;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class UpdateDevice {
|
||||||
|
public String deviceAddr;
|
||||||
|
public String deviceName;
|
||||||
|
public Double lng;
|
||||||
|
public Double lat;
|
||||||
|
public String saveDateInterval;
|
||||||
|
public String offlineInterval;
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
package com.fastbee.deviceData.api.renke.domin;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class UpdateNodeInfo {
|
||||||
|
private String deviceAddr;
|
||||||
|
private Integer nodeId;
|
||||||
|
private Integer nodeType;
|
||||||
|
private Integer nodeMold;
|
||||||
|
private Integer digits;
|
||||||
|
private Integer enable;
|
||||||
|
private Number humLowerLimit;
|
||||||
|
private String humName;
|
||||||
|
private Number humOffset;
|
||||||
|
private Number humRatio;
|
||||||
|
private String humUnit;
|
||||||
|
private Number humUpperLimit;
|
||||||
|
private String nodeName;
|
||||||
|
private Integer priority;
|
||||||
|
private Integer switchAlarmType;
|
||||||
|
private String switchOffContent;
|
||||||
|
private String switchOnContent;
|
||||||
|
private Number temLowerLimit;
|
||||||
|
private String temName;
|
||||||
|
private Number temOffset;
|
||||||
|
private Number temRatio;
|
||||||
|
private String temUnit;
|
||||||
|
private Number temUpperLimit;
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
package com.fastbee.deviceData.api.renke.domin;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class WormMode {
|
||||||
|
public String deviceAddr;
|
||||||
|
public String mode;
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
package com.fastbee.deviceData.api.renke.domin;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class WormOper {
|
||||||
|
public String deviceAddr;
|
||||||
|
public String module;
|
||||||
|
public String opt;
|
||||||
|
}
|
@ -42,31 +42,6 @@ public class RenkeDeviceDataService {
|
|||||||
System.err.println("设备实时数据:"+realtimeDataList);
|
System.err.println("设备实时数据:"+realtimeDataList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//获取token
|
//获取token
|
||||||
private String getAuth(){
|
private String getAuth(){
|
||||||
//判断token是否过期
|
//判断token是否过期
|
||||||
|
@ -1,10 +1,258 @@
|
|||||||
package com.fastbee.deviceData.api.renke.service;
|
package com.fastbee.deviceData.api.renke.service;
|
||||||
|
|
||||||
|
import cn.hutool.http.HttpRequest;
|
||||||
|
import cn.hutool.http.HttpResponse;
|
||||||
|
import cn.hutool.json.JSONObject;
|
||||||
|
import cn.hutool.json.JSONUtil;
|
||||||
|
import com.fastbee.deviceData.api.renke.domin.UpdateDevice;
|
||||||
|
import com.fastbee.deviceData.api.renke.domin.UpdateNodeInfo;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.net.URLEncoder;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 建大仁科气象设备服务
|
* 建大仁科气象设备服务
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class RenkeMetDeviceService {
|
public class RenkeMetDeviceService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取气象设备全部信息
|
||||||
|
* @param deviceStr
|
||||||
|
* @param token
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public JSONObject getDeviceAllInfo(String deviceStr,String token){
|
||||||
|
|
||||||
|
HttpResponse response = HttpRequest.get("http://api.farm.0531yun.cn/api/v2.0/met/device/getDeviceAllInfo?deviceStr="+deviceStr)
|
||||||
|
.header("token", token)
|
||||||
|
.execute();
|
||||||
|
String respBodyStr = response.body();
|
||||||
|
if(StringUtils.isBlank(respBodyStr)) {
|
||||||
|
throw new RuntimeException("获取设备实时数据失败!");
|
||||||
|
}
|
||||||
|
JSONObject jsonObject = JSONUtil.parseObj(respBodyStr);
|
||||||
|
return jsonObject;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 根据气象设备地址获取节点信息
|
||||||
|
* @param deviceAddr
|
||||||
|
* @param token
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public JSONObject getAllInsectEquipmentInformation(String deviceAddr,String token){
|
||||||
|
|
||||||
|
//获取设备实时数据
|
||||||
|
//请求参数
|
||||||
|
HttpResponse response = HttpRequest.get("http://api.farm.0531yun.cn/api/v2.0/met/device/listTargetNodeInfo?deviceAddr="+deviceAddr)
|
||||||
|
.header("token", token)
|
||||||
|
.execute();
|
||||||
|
String respBodyStr = response.body();
|
||||||
|
if(StringUtils.isBlank(respBodyStr)) {
|
||||||
|
throw new RuntimeException("获取设备实时数据失败!");
|
||||||
|
}
|
||||||
|
JSONObject jsonObject = JSONUtil.parseObj(respBodyStr);
|
||||||
|
return jsonObject;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 根据气象设备地址获取已启用的节点信息
|
||||||
|
* @param deviceAddr
|
||||||
|
* @param token
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public JSONObject listTargetEnabledNode(String deviceAddr,String token){
|
||||||
|
|
||||||
|
//获取设备实时数据
|
||||||
|
//请求参数
|
||||||
|
HttpResponse response = HttpRequest.get("http://api.farm.0531yun.cn/api/v2.0/met/device/listTargetEnabledNode?deviceAddr="+deviceAddr)
|
||||||
|
.header("token", token)
|
||||||
|
.execute();
|
||||||
|
String respBodyStr = response.body();
|
||||||
|
if(StringUtils.isBlank(respBodyStr)) {
|
||||||
|
throw new RuntimeException("获取设备实时数据失败!");
|
||||||
|
}
|
||||||
|
JSONObject jsonObject = JSONUtil.parseObj(respBodyStr);
|
||||||
|
return jsonObject;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 根据气象节点编号获取遥调信息
|
||||||
|
* @param deviceAddr
|
||||||
|
* @param token
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public JSONObject listTargetEnabledNode(String deviceAddr,String nodeId,String token){
|
||||||
|
// 请求基础URL
|
||||||
|
String baseUrl = "http://api.farm.0531yun.cn/api/v2.0/met/device/listTargetEnabledNode";
|
||||||
|
|
||||||
|
StringBuilder queryParams = new StringBuilder();
|
||||||
|
if (deviceAddr != null && !deviceAddr.isEmpty()) {
|
||||||
|
queryParams.append("deviceAddr=").append(URLEncoder.encode(deviceAddr));
|
||||||
|
}
|
||||||
|
if (nodeId != null && !nodeId.isEmpty()) {
|
||||||
|
if (queryParams.length() > 0) queryParams.append("&");
|
||||||
|
queryParams.append("nodeId=").append(URLEncoder.encode(nodeId));
|
||||||
|
}
|
||||||
|
String fullUrl = baseUrl + "?" + queryParams.toString();
|
||||||
|
HttpResponse response = HttpRequest.get(fullUrl)
|
||||||
|
.header("token", token)
|
||||||
|
.execute();
|
||||||
|
String respBodyStr = response.body();
|
||||||
|
if(StringUtils.isBlank(respBodyStr)) {
|
||||||
|
throw new RuntimeException("获取虫情设备历史记录失败!");
|
||||||
|
}
|
||||||
|
JSONObject jsonObject = JSONUtil.parseObj(respBodyStr);
|
||||||
|
return jsonObject;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 修改指定气象设备全部节点的可用状态
|
||||||
|
* @param deviceAddr
|
||||||
|
* @param token
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public JSONObject updateAllOfNodesEnable(String deviceAddr,String enable,String token){
|
||||||
|
// 请求基础URL
|
||||||
|
String baseUrl = "http://api.farm.0531yun.cn/api/v2.0/met/device/updateAllOfNodesEnable";
|
||||||
|
|
||||||
|
StringBuilder queryParams = new StringBuilder();
|
||||||
|
if (deviceAddr != null && !deviceAddr.isEmpty()) {
|
||||||
|
queryParams.append("deviceAddr=").append(URLEncoder.encode(deviceAddr));
|
||||||
|
}
|
||||||
|
if (enable != null && !enable.isEmpty()) {
|
||||||
|
if (queryParams.length() > 0) queryParams.append("&");
|
||||||
|
queryParams.append("enable=").append(URLEncoder.encode(enable));
|
||||||
|
}
|
||||||
|
String fullUrl = baseUrl + "?" + queryParams.toString();
|
||||||
|
HttpResponse response = HttpRequest.get(fullUrl)
|
||||||
|
.header("token", token)
|
||||||
|
.execute();
|
||||||
|
String respBodyStr = response.body();
|
||||||
|
if(StringUtils.isBlank(respBodyStr)) {
|
||||||
|
throw new RuntimeException("获取虫情设备历史记录失败!");
|
||||||
|
}
|
||||||
|
JSONObject jsonObject = JSONUtil.parseObj(respBodyStr);
|
||||||
|
return jsonObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改气象设备信息
|
||||||
|
* @param updateDevice
|
||||||
|
* @param token
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public JSONObject updateDevice(UpdateDevice updateDevice, String token){
|
||||||
|
//获取设备实时数据
|
||||||
|
//请求参数
|
||||||
|
Map<String,Object> reqBody =getObjectProperties(updateDevice);
|
||||||
|
HttpResponse response = HttpRequest.post("http://api.farm.0531yun.cn/api/v2.0/met/device/updateDevice")
|
||||||
|
.header("token", token).body(JSONUtil.toJsonStr(reqBody))
|
||||||
|
.execute();
|
||||||
|
String respBodyStr = response.body();
|
||||||
|
if(StringUtils.isBlank(respBodyStr)) {
|
||||||
|
throw new RuntimeException("修改气象设备信息失败!");
|
||||||
|
}
|
||||||
|
JSONObject jsonObject = JSONUtil.parseObj(respBodyStr);
|
||||||
|
return jsonObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新气象节点信息
|
||||||
|
* @param updateNodeInfo
|
||||||
|
* @param token
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public JSONObject updateNodeInfo(UpdateNodeInfo updateNodeInfo, String token){
|
||||||
|
//获取设备实时数据
|
||||||
|
//请求参数
|
||||||
|
Map<String,Object> reqBody =getObjectProperties(updateNodeInfo);
|
||||||
|
HttpResponse response = HttpRequest.post("http://api.farm.0531yun.cn/api/v2.0/met/device/updateNodeInfo")
|
||||||
|
.header("token", token).body(JSONUtil.toJsonStr(reqBody))
|
||||||
|
.execute();
|
||||||
|
String respBodyStr = response.body();
|
||||||
|
if(StringUtils.isBlank(respBodyStr)) {
|
||||||
|
throw new RuntimeException("修改气象设备信息失败!");
|
||||||
|
}
|
||||||
|
JSONObject jsonObject = JSONUtil.parseObj(respBodyStr);
|
||||||
|
return jsonObject;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 根据条件获取历史数据
|
||||||
|
* @param token
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public JSONObject getWormDataList(String deviceAddr,String nodeId,String beginTime,String endTime,Integer pages,Integer limit,String token){
|
||||||
|
// 请求基础URL
|
||||||
|
String baseUrl = "http://api.farm.0531yun.cn/api/v2.0/met/history/getHistoryDataList";
|
||||||
|
|
||||||
|
StringBuilder queryParams = new StringBuilder();
|
||||||
|
if (deviceAddr != null && !deviceAddr.isEmpty()) {
|
||||||
|
queryParams.append("deviceAddr=").append(URLEncoder.encode(deviceAddr));
|
||||||
|
}
|
||||||
|
if (beginTime != null && !beginTime.isEmpty()) {
|
||||||
|
if (queryParams.length() > 0) queryParams.append("&");
|
||||||
|
queryParams.append("beginTime=").append(URLEncoder.encode(beginTime));
|
||||||
|
}
|
||||||
|
if (endTime != null && !endTime.isEmpty()) {
|
||||||
|
if (queryParams.length() > 0) queryParams.append("&");
|
||||||
|
queryParams.append("endTime=").append(URLEncoder.encode(endTime));
|
||||||
|
}
|
||||||
|
if (pages != null) {
|
||||||
|
if (queryParams.length() > 0) queryParams.append("&");
|
||||||
|
queryParams.append("pages=").append(pages);
|
||||||
|
}
|
||||||
|
if (limit != null) {
|
||||||
|
if (queryParams.length() > 0) queryParams.append("&");
|
||||||
|
queryParams.append("limit=").append(limit);
|
||||||
|
}
|
||||||
|
String fullUrl = baseUrl + "?" + queryParams.toString();
|
||||||
|
HttpResponse response = HttpRequest.get(fullUrl)
|
||||||
|
.header("token", token)
|
||||||
|
.execute();
|
||||||
|
String respBodyStr = response.body();
|
||||||
|
if(StringUtils.isBlank(respBodyStr)) {
|
||||||
|
throw new RuntimeException("获取虫情设备历史记录失败!");
|
||||||
|
}
|
||||||
|
JSONObject jsonObject = JSONUtil.parseObj(respBodyStr);
|
||||||
|
return jsonObject;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 通过反射获取对象的所有属性和值,并存储到Map中
|
||||||
|
*
|
||||||
|
* @param obj 目标对象
|
||||||
|
* @return 包含属性和值的Map
|
||||||
|
*/
|
||||||
|
public static Map<String, Object> getObjectProperties(Object obj) {
|
||||||
|
Map<String, Object> propertiesMap = new HashMap<>();
|
||||||
|
|
||||||
|
// 获取对象的类类型
|
||||||
|
Class<?> clazz = obj.getClass();
|
||||||
|
|
||||||
|
// 获取类的所有字段(包括私有字段)
|
||||||
|
Field[] fields = clazz.getDeclaredFields();
|
||||||
|
|
||||||
|
// 遍历字段
|
||||||
|
for (Field field : fields) {
|
||||||
|
// 设置字段为可访问(即使它是私有的)
|
||||||
|
field.setAccessible(true);
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 获取字段的名称
|
||||||
|
String fieldName = field.getName();
|
||||||
|
|
||||||
|
// 获取字段的值(从目标对象中)
|
||||||
|
Object fieldValue = field.get(obj);
|
||||||
|
|
||||||
|
// 将字段名称和值存入Map中
|
||||||
|
propertiesMap.put(fieldName, fieldValue);
|
||||||
|
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
// 理论上不应该发生,因为我们已经设置了setAccessible(true)
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return propertiesMap;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,19 @@
|
|||||||
package com.fastbee.deviceData.api.renke.service;
|
package com.fastbee.deviceData.api.renke.service;
|
||||||
|
|
||||||
|
import cn.hutool.http.HttpRequest;
|
||||||
|
import cn.hutool.http.HttpResponse;
|
||||||
|
import cn.hutool.json.JSONObject;
|
||||||
|
import cn.hutool.json.JSONUtil;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.net.URLEncoder;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import com.fastbee.deviceData.api.renke.domin.ModWormAutoMode;
|
||||||
|
import com.fastbee.deviceData.api.renke.domin.UpdateDevice;
|
||||||
|
import com.fastbee.deviceData.api.renke.domin.WormMode;
|
||||||
|
import com.fastbee.deviceData.api.renke.domin.WormOper;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -8,5 +22,376 @@ import org.springframework.stereotype.Service;
|
|||||||
@Service
|
@Service
|
||||||
public class RenkeWormSituationDeviceService {
|
public class RenkeWormSituationDeviceService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量获取设备详情
|
||||||
|
* @param deviceAddr
|
||||||
|
* @param token
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public JSONObject getAllInsectEquipmentInformation(String deviceAddr,String token){
|
||||||
|
|
||||||
|
//获取设备实时数据
|
||||||
|
//请求参数
|
||||||
|
HttpResponse response = HttpRequest.get("http://api.farm.0531yun.cn/api/v2.0/worm/device/getBtchDeviceDO?deviceAddr="+deviceAddr)
|
||||||
|
.header("token", token)
|
||||||
|
.execute();
|
||||||
|
String respBodyStr = response.body();
|
||||||
|
if(StringUtils.isBlank(respBodyStr)) {
|
||||||
|
throw new RuntimeException("获取设备实时数据失败!");
|
||||||
|
}
|
||||||
|
JSONObject jsonObject = JSONUtil.parseObj(respBodyStr);
|
||||||
|
return jsonObject;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 修改虫情设备信息
|
||||||
|
* @param updateDevice
|
||||||
|
* @param token
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public JSONObject updateDevice(UpdateDevice updateDevice, String token){
|
||||||
|
//获取设备实时数据
|
||||||
|
//请求参数
|
||||||
|
Map<String,Object> reqBody =getObjectProperties(updateDevice);
|
||||||
|
HttpResponse response = HttpRequest.post("http://api.farm.0531yun.cn/api/v2.0/worm/device/updateDevice")
|
||||||
|
.header("token", token).body(JSONUtil.toJsonStr(reqBody))
|
||||||
|
.execute();
|
||||||
|
String respBodyStr = response.body();
|
||||||
|
if(StringUtils.isBlank(respBodyStr)) {
|
||||||
|
throw new RuntimeException("修改设备自动模式时间失败!");
|
||||||
|
}
|
||||||
|
JSONObject jsonObject = JSONUtil.parseObj(respBodyStr);
|
||||||
|
return jsonObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取设备自动模式时间
|
||||||
|
* @param deviceAddr
|
||||||
|
* @param token
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public JSONObject getWormAutoMode(String deviceAddr,String token){
|
||||||
|
HttpResponse response = HttpRequest.get("http://api.farm.0531yun.cn/api/v2.0/worm/device/getWormAutoMode?deviceAddr="+deviceAddr)
|
||||||
|
.header("token", token)
|
||||||
|
.execute();
|
||||||
|
String respBodyStr = response.body();
|
||||||
|
if(StringUtils.isBlank(respBodyStr)) {
|
||||||
|
throw new RuntimeException("获取设备实时数据失败!");
|
||||||
|
}
|
||||||
|
JSONObject jsonObject = JSONUtil.parseObj(respBodyStr);
|
||||||
|
return jsonObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改设备自动模式时间
|
||||||
|
* @param modWormAutoMode
|
||||||
|
* @param token
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public JSONObject updateWormAutoMode(ModWormAutoMode modWormAutoMode,String token){
|
||||||
|
//获取设备实时数据
|
||||||
|
//请求参数
|
||||||
|
Map<String,Object> reqBody =getObjectProperties(modWormAutoMode);
|
||||||
|
HttpResponse response = HttpRequest.post("http://api.farm.0531yun.cn/api/v2.0/worm/device/modWormAutoMode")
|
||||||
|
.header("token", token).body(JSONUtil.toJsonStr(reqBody))
|
||||||
|
.execute();
|
||||||
|
String respBodyStr = response.body();
|
||||||
|
if(StringUtils.isBlank(respBodyStr)) {
|
||||||
|
throw new RuntimeException("修改设备自动模式时间失败!");
|
||||||
|
}
|
||||||
|
JSONObject jsonObject = JSONUtil.parseObj(respBodyStr);
|
||||||
|
return jsonObject;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 手自动模式切换
|
||||||
|
* @param wormMode
|
||||||
|
* @param token
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public JSONObject updateWormMode(WormMode wormMode, String token){
|
||||||
|
//获取设备实时数据
|
||||||
|
//请求参数
|
||||||
|
Map<String,Object> reqBody =getObjectProperties(wormMode);
|
||||||
|
HttpResponse response = HttpRequest.post("http://api.farm.0531yun.cn/api/v2.0/worm/device/modWormAutoMode")
|
||||||
|
.header("token", token).body(JSONUtil.toJsonStr(reqBody))
|
||||||
|
.execute();
|
||||||
|
String respBodyStr = response.body();
|
||||||
|
if(StringUtils.isBlank(respBodyStr)) {
|
||||||
|
throw new RuntimeException("虫情设备下发命令失败!");
|
||||||
|
}
|
||||||
|
JSONObject jsonObject = JSONUtil.parseObj(respBodyStr);
|
||||||
|
return jsonObject;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 虫情设备下发命令
|
||||||
|
* @param wormOper
|
||||||
|
* @param token
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public JSONObject updateWormOper(WormOper wormOper, String token){
|
||||||
|
//获取设备实时数据
|
||||||
|
//请求参数
|
||||||
|
Map<String,Object> reqBody =getObjectProperties(wormOper);
|
||||||
|
HttpResponse response = HttpRequest.post("http://api.farm.0531yun.cn/api/v2.0/worm/device/deviceOper/wormOper")
|
||||||
|
.header("token", token).body(JSONUtil.toJsonStr(reqBody))
|
||||||
|
.execute();
|
||||||
|
String respBodyStr = response.body();
|
||||||
|
if(StringUtils.isBlank(respBodyStr)) {
|
||||||
|
throw new RuntimeException("获取设备实时数据失败!");
|
||||||
|
}
|
||||||
|
JSONObject jsonObject = JSONUtil.parseObj(respBodyStr);
|
||||||
|
return jsonObject;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 虫情设备历史记录
|
||||||
|
* @param token
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public JSONObject getWormHistoryData(String deviceAddr,String beginTime,String endTime,Integer pages,Integer limit,String token){
|
||||||
|
// 请求基础URL
|
||||||
|
String baseUrl = "http://api.farm.0531yun.cn/api/v2.0/worm/deviceData/getWormHistoryData";
|
||||||
|
|
||||||
|
StringBuilder queryParams = new StringBuilder();
|
||||||
|
if (deviceAddr != null && !deviceAddr.isEmpty()) {
|
||||||
|
queryParams.append("deviceAddr=").append(URLEncoder.encode(deviceAddr));
|
||||||
|
}
|
||||||
|
if (beginTime != null && !beginTime.isEmpty()) {
|
||||||
|
if (queryParams.length() > 0) queryParams.append("&");
|
||||||
|
queryParams.append("beginTime=").append(URLEncoder.encode(beginTime));
|
||||||
|
}
|
||||||
|
if (endTime != null && !endTime.isEmpty()) {
|
||||||
|
if (queryParams.length() > 0) queryParams.append("&");
|
||||||
|
queryParams.append("endTime=").append(URLEncoder.encode(endTime));
|
||||||
|
}
|
||||||
|
if (pages != null) {
|
||||||
|
if (queryParams.length() > 0) queryParams.append("&");
|
||||||
|
queryParams.append("pages=").append(pages);
|
||||||
|
}
|
||||||
|
if (limit != null) {
|
||||||
|
if (queryParams.length() > 0) queryParams.append("&");
|
||||||
|
queryParams.append("limit=").append(limit);
|
||||||
|
}
|
||||||
|
String fullUrl = baseUrl + "?" + queryParams.toString();
|
||||||
|
HttpResponse response = HttpRequest.get(fullUrl)
|
||||||
|
.header("token", token)
|
||||||
|
.execute();
|
||||||
|
String respBodyStr = response.body();
|
||||||
|
if(StringUtils.isBlank(respBodyStr)) {
|
||||||
|
throw new RuntimeException("获取虫情设备历史记录失败!");
|
||||||
|
}
|
||||||
|
JSONObject jsonObject = JSONUtil.parseObj(respBodyStr);
|
||||||
|
return jsonObject;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 虫情区域统计
|
||||||
|
* @param token
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public JSONObject getWormStatisticsByGroup(String groupId,String beginTime,String endTime,String token){
|
||||||
|
// 请求基础URL
|
||||||
|
String baseUrl = "http://api.farm.0531yun.cn/api/v2.0/worm/deviceData/getWormStatisticsByGroup";
|
||||||
|
|
||||||
|
StringBuilder queryParams = new StringBuilder();
|
||||||
|
if (groupId != null && !groupId.isEmpty()) {
|
||||||
|
queryParams.append("deviceAddr=").append(URLEncoder.encode(groupId));
|
||||||
|
}
|
||||||
|
if (beginTime != null && !beginTime.isEmpty()) {
|
||||||
|
if (queryParams.length() > 0) queryParams.append("&");
|
||||||
|
queryParams.append("beginTime=").append(URLEncoder.encode(beginTime));
|
||||||
|
}
|
||||||
|
if (endTime != null && !endTime.isEmpty()) {
|
||||||
|
if (queryParams.length() > 0) queryParams.append("&");
|
||||||
|
queryParams.append("endTime=").append(URLEncoder.encode(endTime));
|
||||||
|
}
|
||||||
|
|
||||||
|
String fullUrl = baseUrl + "?" + queryParams.toString();
|
||||||
|
HttpResponse response = HttpRequest.get(fullUrl)
|
||||||
|
.header("token", token)
|
||||||
|
.execute();
|
||||||
|
String respBodyStr = response.body();
|
||||||
|
if(StringUtils.isBlank(respBodyStr)) {
|
||||||
|
throw new RuntimeException("获取虫情区域统计失败!");
|
||||||
|
}
|
||||||
|
JSONObject jsonObject = JSONUtil.parseObj(respBodyStr);
|
||||||
|
return jsonObject;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 虫情设备分析报表
|
||||||
|
* @param token
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public JSONObject getWormDataList(String deviceAddr,String beginTime,String endTime,Integer pages,Integer limit,String token){
|
||||||
|
// 请求基础URL
|
||||||
|
String baseUrl = "http://api.farm.0531yun.cn/api/v2.0/worm/deviceData/getWormDataList";
|
||||||
|
|
||||||
|
StringBuilder queryParams = new StringBuilder();
|
||||||
|
if (deviceAddr != null && !deviceAddr.isEmpty()) {
|
||||||
|
queryParams.append("deviceAddr=").append(URLEncoder.encode(deviceAddr));
|
||||||
|
}
|
||||||
|
if (beginTime != null && !beginTime.isEmpty()) {
|
||||||
|
if (queryParams.length() > 0) queryParams.append("&");
|
||||||
|
queryParams.append("beginTime=").append(URLEncoder.encode(beginTime));
|
||||||
|
}
|
||||||
|
if (endTime != null && !endTime.isEmpty()) {
|
||||||
|
if (queryParams.length() > 0) queryParams.append("&");
|
||||||
|
queryParams.append("endTime=").append(URLEncoder.encode(endTime));
|
||||||
|
}
|
||||||
|
if (pages != null) {
|
||||||
|
if (queryParams.length() > 0) queryParams.append("&");
|
||||||
|
queryParams.append("pages=").append(pages);
|
||||||
|
}
|
||||||
|
if (limit != null) {
|
||||||
|
if (queryParams.length() > 0) queryParams.append("&");
|
||||||
|
queryParams.append("limit=").append(limit);
|
||||||
|
}
|
||||||
|
String fullUrl = baseUrl + "?" + queryParams.toString();
|
||||||
|
HttpResponse response = HttpRequest.get(fullUrl)
|
||||||
|
.header("token", token)
|
||||||
|
.execute();
|
||||||
|
String respBodyStr = response.body();
|
||||||
|
if(StringUtils.isBlank(respBodyStr)) {
|
||||||
|
throw new RuntimeException("获取虫情设备历史记录失败!");
|
||||||
|
}
|
||||||
|
JSONObject jsonObject = JSONUtil.parseObj(respBodyStr);
|
||||||
|
return jsonObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 虫情设备分析报表记录(最新一条记录)
|
||||||
|
* @param deviceAddr
|
||||||
|
* @param token
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public JSONObject getWormDataAndWormDataAIBy(String deviceAddr,String token){
|
||||||
|
|
||||||
|
//获取设备实时数据
|
||||||
|
//请求参数
|
||||||
|
HttpResponse response = HttpRequest.get("http://api.farm.0531yun.cn/api/v2.0/worm/deviceData/getWormDataAndWormDataAIBy?deviceAddr="+deviceAddr)
|
||||||
|
.header("token", token)
|
||||||
|
.execute();
|
||||||
|
String respBodyStr = response.body();
|
||||||
|
if(StringUtils.isBlank(respBodyStr)) {
|
||||||
|
throw new RuntimeException("获取虫情设备分析报表记录(最新一条记录)失败!");
|
||||||
|
}
|
||||||
|
JSONObject jsonObject = JSONUtil.parseObj(respBodyStr);
|
||||||
|
return jsonObject;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 害虫自动识别
|
||||||
|
* @param recordId
|
||||||
|
* @param token
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public JSONObject analysistWorm(String recordId,String token){
|
||||||
|
|
||||||
|
//获取设备实时数据
|
||||||
|
//请求参数
|
||||||
|
HttpResponse response = HttpRequest.get("http://api.farm.0531yun.cn/api/v2.0/worm/deviceData/analysistWorm?recordId="+recordId)
|
||||||
|
.header("token", token)
|
||||||
|
.execute();
|
||||||
|
String respBodyStr = response.body();
|
||||||
|
if(StringUtils.isBlank(respBodyStr)) {
|
||||||
|
throw new RuntimeException("获取虫情设备分析报表记录(最新一条记录)失败!");
|
||||||
|
}
|
||||||
|
JSONObject jsonObject = JSONUtil.parseObj(respBodyStr);
|
||||||
|
return jsonObject;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 根据ID获取虫情设备分析报表记录
|
||||||
|
* @param token
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public JSONObject getDeviceAnalysisReportRecordAccordingIdList(String deviceAddr,String recordIds,String token){
|
||||||
|
// 请求基础URL
|
||||||
|
String baseUrl = "http://api.farm.0531yun.cn/api/v2.0/worm/deviceData/getDeviceAnalysisReportRecordAccordingIdList";
|
||||||
|
|
||||||
|
StringBuilder queryParams = new StringBuilder();
|
||||||
|
if (deviceAddr != null && !deviceAddr.isEmpty()) {
|
||||||
|
queryParams.append("deviceAddr=").append(URLEncoder.encode(deviceAddr));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (recordIds != null) {
|
||||||
|
if (queryParams.length() > 0) queryParams.append("&");
|
||||||
|
queryParams.append("recordIds=").append(recordIds);
|
||||||
|
}
|
||||||
|
String fullUrl = baseUrl + "?" + queryParams.toString();
|
||||||
|
HttpResponse response = HttpRequest.get(fullUrl)
|
||||||
|
.header("token", token)
|
||||||
|
.execute();
|
||||||
|
String respBodyStr = response.body();
|
||||||
|
if(StringUtils.isBlank(respBodyStr)) {
|
||||||
|
throw new RuntimeException("获取虫情设备历史记录失败!");
|
||||||
|
}
|
||||||
|
JSONObject jsonObject = JSONUtil.parseObj(respBodyStr);
|
||||||
|
return jsonObject;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 虫情设备操作记录
|
||||||
|
* @param token
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public JSONObject getWormOperationLog(String deviceAddr,String beginTime,String endTime,String token){
|
||||||
|
// 请求基础URL
|
||||||
|
String baseUrl = "http://api.farm.0531yun.cn/api/v2.0/worm/deviceData/getWormOperationLog";
|
||||||
|
|
||||||
|
StringBuilder queryParams = new StringBuilder();
|
||||||
|
if (deviceAddr != null && !deviceAddr.isEmpty()) {
|
||||||
|
queryParams.append("deviceAddr=").append(URLEncoder.encode(deviceAddr));
|
||||||
|
}
|
||||||
|
if (beginTime != null && !beginTime.isEmpty()) {
|
||||||
|
if (queryParams.length() > 0) queryParams.append("&");
|
||||||
|
queryParams.append("beginTime=").append(URLEncoder.encode(beginTime));
|
||||||
|
}
|
||||||
|
if (endTime != null && !endTime.isEmpty()) {
|
||||||
|
if (queryParams.length() > 0) queryParams.append("&");
|
||||||
|
queryParams.append("endTime=").append(URLEncoder.encode(endTime));
|
||||||
|
}
|
||||||
|
String fullUrl = baseUrl + "?" + queryParams.toString();
|
||||||
|
HttpResponse response = HttpRequest.get(fullUrl)
|
||||||
|
.header("token", token)
|
||||||
|
.execute();
|
||||||
|
String respBodyStr = response.body();
|
||||||
|
if(StringUtils.isBlank(respBodyStr)) {
|
||||||
|
throw new RuntimeException("获取虫情设备历史记录失败!");
|
||||||
|
}
|
||||||
|
JSONObject jsonObject = JSONUtil.parseObj(respBodyStr);
|
||||||
|
return jsonObject;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 通过反射获取对象的所有属性和值,并存储到Map中
|
||||||
|
*
|
||||||
|
* @param obj 目标对象
|
||||||
|
* @return 包含属性和值的Map
|
||||||
|
*/
|
||||||
|
public static Map<String, Object> getObjectProperties(Object obj) {
|
||||||
|
Map<String, Object> propertiesMap = new HashMap<>();
|
||||||
|
|
||||||
|
// 获取对象的类类型
|
||||||
|
Class<?> clazz = obj.getClass();
|
||||||
|
|
||||||
|
// 获取类的所有字段(包括私有字段)
|
||||||
|
Field[] fields = clazz.getDeclaredFields();
|
||||||
|
|
||||||
|
// 遍历字段
|
||||||
|
for (Field field : fields) {
|
||||||
|
// 设置字段为可访问(即使它是私有的)
|
||||||
|
field.setAccessible(true);
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 获取字段的名称
|
||||||
|
String fieldName = field.getName();
|
||||||
|
|
||||||
|
// 获取字段的值(从目标对象中)
|
||||||
|
Object fieldValue = field.get(obj);
|
||||||
|
|
||||||
|
// 将字段名称和值存入Map中
|
||||||
|
propertiesMap.put(fieldName, fieldValue);
|
||||||
|
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
// 理论上不应该发生,因为我们已经设置了setAccessible(true)
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return propertiesMap;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -110,7 +110,5 @@ public class DeviceDateTask {
|
|||||||
System.err.println("请求获取到token:"+tokenObject.get("token").toString());
|
System.err.println("请求获取到token:"+tokenObject.get("token").toString());
|
||||||
return stringRedisTemplate.opsForValue().get("rkckth:user:token").toString();
|
return stringRedisTemplate.opsForValue().get("rkckth:user:token").toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user