同步代码

This commit is contained in:
mi9688
2024-11-29 19:11:30 +08:00
parent 9327c600f7
commit 172bd4f89d
28 changed files with 552 additions and 182 deletions

View File

@ -12,7 +12,7 @@ import org.springframework.stereotype.Service;
import java.net.URLEncoder;
/**
* 建大仁科气象设备服务
* 建大杀虫灯设备
*/
@Service
public class RenkeMetDeviceService {
@ -22,7 +22,7 @@ public class RenkeMetDeviceService {
/**
* 获取气象设备全部信息
* 获取杀虫灯设备全部信息
* @param deviceStr 设备地址,支持多个用英文逗号分隔
* @return JSONObject
*/
@ -38,7 +38,7 @@ public class RenkeMetDeviceService {
return JSONUtil.parseObj(respBodyStr);
}
/**
* 根据气象设备地址获取节点信息
* 根据杀虫灯设备地址获取节点信息
*/
public JSONObject getAllInsectEquipmentInformation(String deviceAddr){
@ -54,7 +54,7 @@ public class RenkeMetDeviceService {
return JSONUtil.parseObj(respBodyStr);
}
/**
* 根据气象设备地址获取已启用的节点信息
* 根据杀虫灯设备地址获取已启用的节点信息
*/
public JSONObject listTargetEnabledNode(String deviceAddr){
@ -70,7 +70,7 @@ public class RenkeMetDeviceService {
return JSONUtil.parseObj(respBodyStr);
}
/**
* 根据气象节点编号获取遥调信息
* 根据杀虫灯节点编号获取遥调信息
*/
public JSONObject listTargetEnabledNode(String deviceAddr,String nodeId){
// 请求基础URL
@ -95,7 +95,7 @@ public class RenkeMetDeviceService {
return JSONUtil.parseObj(respBodyStr);
}
/**
* 修改指定气象设备全部节点的可用状态
* 修改指定杀虫灯设备全部节点的可用状态
*/
public JSONObject updateAllOfNodesEnable(String deviceAddr,String enable){
// 请求基础URL
@ -121,7 +121,7 @@ public class RenkeMetDeviceService {
}
/**
* 修改气象设备信息
* 修改杀虫灯设备信息
*/
public JSONObject updateDevice(UpdateDevice updateDevice){
//获取设备实时数据
@ -137,7 +137,7 @@ public class RenkeMetDeviceService {
}
/**
* 更新气象节点信息
* 更新杀虫灯节点信息
*/
public JSONObject updateNodeInfo(UpdateNodeInfo updateNodeInfo){
//获取设备实时数据

View File

@ -0,0 +1,92 @@
package com.fastbee.deviceData.api.renke.service;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper;
import com.fastbee.common.exception.ServiceException;
import com.fastbee.common.utils.DateUtils;
import com.fastbee.deviceData.domain.DeviceRealtimedataWorms;
import com.fastbee.deviceInfo.domain.DeviceInformationTargetpests;
import com.fastbee.deviceInfo.mapper.DeviceInformationTargetpestsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
@Service
public class RenkeTargetpestsDeviceDataService {
@Autowired
private RenKeAuthorizationService authenticationService;
@Autowired
private DeviceInformationTargetpestsMapper targetpestsMapper;
/**
* 获取设备实时数据
* @param deviceAddrs 设备地址,支持多个用英文逗号分隔
*/
public void setData(String deviceAddrs) {
DeviceRealtimedataWorms deviceRealtimedataWorms = new DeviceRealtimedataWorms();
//处理鉴权
String token = authenticationService.getToken();
// String token = "34491732858666778";
//获取设备基础实时数据
HttpResponse response = HttpRequest.get("http://api.farm.0531yun.cn/api/v2.0/entrance/device/getRealTimeData")
.header("token", token)
.form("deviceAddrs", deviceAddrs)
.execute();
String respBodyStr = response.body();
JSONObject respBody = JSONUtil.parseObj(respBodyStr);
// System.err.println(respBodyStr);
if(!respBody.get("code") .toString().equals("1000")){
System.err.println(respBodyStr);
throw new ServiceException("获取设备实时数据失败!");
}
JSONArray realtimeDataList = JSONUtil.parseArray(respBody.get("data"));
realtimeDataList.forEach(json -> {
//设备编码
JSONObject jsonObject = JSONUtil.parseObj(json);
String deviceAddr = jsonObject.getStr("deviceAddr");
String data = jsonObject.getStr("data");
JSONArray jsonArray = JSONUtil.parseArray(data);
jsonArray.forEach(json1 -> {
JSONObject obj = JSONUtil.parseObj(json1);
String nodeName = obj.getStr("nodeName");
if(nodeName.equals("引虫灯状态")){
//引虫灯状态
String temValueStr = obj.getStr("temValueStr");
// System.err.println(deviceAddr+"引虫灯状态:"+temValueStr);
//如果引虫灯设备关闭判定为离线
if(temValueStr.equals("关闭")){
//更新设备状态为离线
new LambdaUpdateChainWrapper<>(targetpestsMapper).eq(DeviceInformationTargetpests::getDeviceEncoding,deviceAddr).set(DeviceInformationTargetpests::getStatus, 0).update();
} else {
new LambdaUpdateChainWrapper<>(targetpestsMapper).eq(DeviceInformationTargetpests::getDeviceEncoding,deviceAddr).set(DeviceInformationTargetpests::getStatus, 1).update();
}
}
});
});
}
public static void main(String[] args) {
RenkeTargetpestsDeviceDataService renkeDeviceDataService = new RenkeTargetpestsDeviceDataService();
renkeDeviceDataService.setData("21094868");
// HttpResponse response1 = HttpRequest.get("http://api.farm.0531yun.cn/api/v2.0/entrance/device/getRealTimeData?deviceAddrs="+"21094868")
// .header("token", "34491732858666778")
// .execute();
// String respBodyStr1 = response1.body();
//
// JSONObject respBody1 = JSONUtil.parseObj(respBodyStr1);
// System.err.println(respBodyStr1);
}
}

View File

@ -7,20 +7,18 @@ import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.fastbee.common.exception.ServiceException;
import com.fastbee.common.utils.DateUtils;
import com.fastbee.common.utils.date.DateTimeCalculationUtils;
import com.fastbee.deviceData.domain.DeviceRealtimedataWorms;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Service
public class RenkeDeviceDataService {
public class RenkeWormDeviceDataService {
@Autowired
private RenKeAuthorizationService authenticationService;
@ -29,8 +27,9 @@ public class RenkeDeviceDataService {
* 获取设备实时数据
* @param deviceAddrs 设备地址支持多个用英文逗号分隔
*/
public DeviceRealtimedataWorms setData(String deviceAddrs) {
DeviceRealtimedataWorms deviceRealtimedataWorms= new DeviceRealtimedataWorms();
public List<DeviceRealtimedataWorms> setData(String deviceAddrs) {
List<DeviceRealtimedataWorms> dataList =new ArrayList<>();
//处理鉴权
String token = authenticationService.getToken();
// String token = new RenKeAuthorizationService().getToken();
@ -48,22 +47,24 @@ public class RenkeDeviceDataService {
throw new ServiceException("获取设备实时数据失败!");
}
JSONArray realtimeDataList = JSONUtil.parseArray(respBody.get("data"));
JSONObject jsonObject = JSONUtil.parseObj(realtimeDataList.get(0));
JSONObject jsonObject1 = JSONUtil.parseObj(jsonObject.get("data"));
//获取实时时间
String realTime = jsonObject1.get("DTime").toString();
//反序列化封装基础数据
deviceRealtimedataWorms = JSONUtil.toBean(jsonObject1, DeviceRealtimedataWorms.class);
//获取虫情设备关键数据
HttpResponse response1 = HttpRequest.get("http://api.farm.0531yun.cn/api/v2.0/worm/deviceData/getWormDataAndWormDataAIBy?deviceAddr="+deviceAddrs)
.header("token", token)
realtimeDataList.forEach(o -> {
DeviceRealtimedataWorms deviceRealtimedataWorms= new DeviceRealtimedataWorms();
JSONObject dataObj = JSONUtil.parseObj(o);
JSONObject jsonObject1 = JSONUtil.parseObj(dataObj .get("data"));
//获取实时时间
String realTime = jsonObject1.get("DTime").toString();
//反序列化封装基础数据
deviceRealtimedataWorms = JSONUtil.toBean(jsonObject1, DeviceRealtimedataWorms.class);
//获取虫情设备关键数据
HttpResponse response1 = HttpRequest.get("http://api.farm.0531yun.cn/api/v2.0/worm/deviceData/getWormDataAndWormDataAIBy?deviceAddr="+deviceAddrs)
.header("token", token)
// .form( "deviceAddr", deviceAddrs)
// //开始时间是5分钟前
// .form("beginTime", DateTimeCalculationUtils.format(DateTimeCalculationUtils.minus(5, ChronoUnit.MINUTES)))
// .form("endTime", DateUtils.getNowDate())
// .form("pages", 1)
// .form("limit", 10)
.execute();
.execute();
// HttpResponse response1 = HttpRequest.get("http://api.farm.0531yun.cn/api/v2.0/worm/deviceData/getWormDataList")
// .header("token", token)
@ -76,20 +77,20 @@ public class RenkeDeviceDataService {
// .execute();
String respBodyStr1 = response1.body();
String respBodyStr1 = response1.body();
JSONObject respBody1 = JSONUtil.parseObj(respBodyStr1);
JSONObject respBody1 = JSONUtil.parseObj(respBodyStr1);
// System.err.println(respBodyStr1);
if(!respBody1.get("code") .toString().equals("1000")) {
throw new RuntimeException("获取设备实时数据失败!");
}
System.err.println(respBody1);
JSONArray jsonArray = JSONUtil.parseArray(respBody1.get("data"));
JSONObject entries = JSONUtil.parseObj(jsonArray.get(0));
if(!respBody1.get("code") .toString().equals("1000")) {
throw new RuntimeException("获取设备实时数据失败!");
}
System.err.println(respBody1);
JSONArray jsonArray = JSONUtil.parseArray(respBody1.get("data"));
JSONObject entries = JSONUtil.parseObj(jsonArray.get(0));
//获取害虫种类以及数量
JSONArray analyseData = JSONUtil.parseArray(entries.get("analyseData"));
//有害虫时保存
//获取害虫种类以及数量
JSONArray analyseData = JSONUtil.parseArray(entries.get("analyseData"));
//有害虫时保存
// if(!analyseData.isEmpty()){
//获取拍照图片
Object imagesUrl = entries .get("imagesUrl");
@ -100,16 +101,22 @@ public class RenkeDeviceDataService {
deviceRealtimedataWorms.setCamera(imagesUrl.toString());
// }
deviceRealtimedataWorms.setSaveTime(DateUtils.getNowDate());
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
Date date = sdf.parse(realTime);
deviceRealtimedataWorms.setRealTime(date);
} catch (ParseException e) {
throw new ServiceException("时间格式转换失败!");
}
System.err.println("虫情设备实时数据:"+deviceRealtimedataWorms);
return deviceRealtimedataWorms;
deviceRealtimedataWorms.setSaveTime(DateUtils.getNowDate());
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
Date date = sdf.parse(realTime);
deviceRealtimedataWorms.setRealTime(date);
} catch (ParseException e) {
throw new ServiceException("时间格式转换失败!");
}
System.err.println("虫情设备实时数据:"+deviceRealtimedataWorms);
dataList.add(deviceRealtimedataWorms);
});
// JSONObject jsonObject = JSONUtil.parseObj(realtimeDataList.get(0));
// JSONObject jsonObject1 = JSONUtil.parseObj(jsonObject.get("data"));
return dataList;
}

View File

@ -3,7 +3,9 @@ package com.fastbee.deviceData.service;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.extension.service.IService;
import com.fastbee.deviceData.domain.DeviceRealtimedataMeteorology;
import com.fastbee.deviceData.domain.DeviceRealtimedataWorms;
import com.fastbee.deviceData.domain.dto.DeviceProperties;
/**
@ -12,7 +14,7 @@ import com.fastbee.deviceData.domain.dto.DeviceProperties;
* @author kerwincui
* @date 2024-11-14
*/
public interface IDeviceRealtimedataMeteorologyService
public interface IDeviceRealtimedataMeteorologyService extends IService<DeviceRealtimedataMeteorology>
{
/**
* 查询气象设备实时数据

View File

@ -1,6 +1,8 @@
package com.fastbee.deviceData.service;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.IService;
import com.fastbee.deviceData.domain.DeviceRealtimedataMoisture;
import com.fastbee.deviceData.domain.dto.DeviceProperties;
@ -10,7 +12,7 @@ import com.fastbee.deviceData.domain.dto.DeviceProperties;
* @author kerwincui
* @date 2024-11-14
*/
public interface IDeviceRealtimedataMoistureService
public interface IDeviceRealtimedataMoistureService extends IService<DeviceRealtimedataMoisture>
{
/**
* 查询墒情实时数据

View File

@ -1,6 +1,8 @@
package com.fastbee.deviceData.service;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.IService;
import com.fastbee.deviceData.domain.DeviceRealtimedataWorms;
import com.fastbee.deviceData.domain.dto.DeviceProperties;
import org.apache.ibatis.annotations.Mapper;
@ -13,7 +15,7 @@ import org.apache.ibatis.annotations.Select;
* @date 2024-11-14
*/
@Mapper
public interface IDeviceRealtimedataWormsService
public interface IDeviceRealtimedataWormsService extends IService<DeviceRealtimedataWorms>
{
/**
* 查询虫情设备实时数据

View File

@ -4,8 +4,11 @@ import java.util.*;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fastbee.common.utils.DateUtils;
import com.fastbee.deviceData.domain.DeviceRealtimedataWorms;
import com.fastbee.deviceData.domain.dto.DeviceProperties;
import com.fastbee.deviceData.mapper.DeviceRealtimedataWormsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.fastbee.deviceData.mapper.DeviceRealtimedataMeteorologyMapper;
@ -19,7 +22,7 @@ import com.fastbee.deviceData.service.IDeviceRealtimedataMeteorologyService;
* @date 2024-11-14
*/
@Service
public class DeviceRealtimedataMeteorologyServiceImpl implements IDeviceRealtimedataMeteorologyService
public class DeviceRealtimedataMeteorologyServiceImpl extends ServiceImpl<DeviceRealtimedataMeteorologyMapper, DeviceRealtimedataMeteorology> implements IDeviceRealtimedataMeteorologyService
{
@Autowired
private DeviceRealtimedataMeteorologyMapper deviceRealtimedataMeteorologyMapper;

View File

@ -3,6 +3,7 @@ package com.fastbee.deviceData.service.impl;
import java.util.*;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fastbee.deviceData.domain.dto.DeviceProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -17,7 +18,7 @@ import com.fastbee.deviceData.service.IDeviceRealtimedataMoistureService;
* @date 2024-11-14
*/
@Service
public class DeviceRealtimedataMoistureServiceImpl implements IDeviceRealtimedataMoistureService
public class DeviceRealtimedataMoistureServiceImpl extends ServiceImpl<DeviceRealtimedataMoistureMapper,DeviceRealtimedataMoisture> implements IDeviceRealtimedataMoistureService
{
@Autowired
private DeviceRealtimedataMoistureMapper deviceRealtimedataMoistureMapper;

View File

@ -6,6 +6,7 @@ import java.util.List;
import java.util.Objects;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fastbee.deviceData.domain.DeviceRealtimedataMoisture;
import com.fastbee.deviceData.domain.dto.DeviceProperties;
import com.fastbee.deviceData.service.IDeviceRealtimedataWormsService;
@ -22,7 +23,7 @@ import com.fastbee.deviceData.domain.DeviceRealtimedataWorms;
* @date 2024-11-07
*/
@Service
public class DeviceRealtimedataWormsServiceImpl implements IDeviceRealtimedataWormsService
public class DeviceRealtimedataWormsServiceImpl extends ServiceImpl<DeviceRealtimedataWormsMapper, DeviceRealtimedataWorms> implements IDeviceRealtimedataWormsService
{
@Autowired
private DeviceRealtimedataWormsMapper deviceRealtimedataWormsMapper;

View File

@ -88,5 +88,9 @@ private static final long serialVersionUID = 1L;
/** 删除标志0代表存在2代表删除 */
private Integer delFlag;
/** 状态1在线0离线 */
@Excel(name = "状态1在线0离线")
@ApiModelProperty("状态1在线0离线")
private Long status;
}

View File

@ -94,4 +94,9 @@ private static final long serialVersionUID = 1L;
/** 删除标志0代表存在2代表删除 */
private Integer delFlag;
/** 状态1在线0离线 */
@Excel(name = "状态1在线0离线")
@ApiModelProperty("状态1在线0离线")
private Long status;
}

View File

@ -108,6 +108,10 @@ public class DeviceInformationMonitor extends BaseEntity
/** 删除标志0代表存在2代表删除 */
private Integer delFlag;
/** 状态1在线0离线 */
@Excel(name = "状态1在线0离线")
@ApiModelProperty("状态1在线0离线")
private Long status;
//------------------------------------------------------------------------------------业务字段---------------

View File

@ -85,4 +85,9 @@ private static final long serialVersionUID = 1L;
@ApiModelProperty("名称")
private String name;
/** 状态1在线0离线 */
@Excel(name = "状态1在线0离线")
@ApiModelProperty("状态1在线0离线")
private Long status;
}

View File

@ -83,5 +83,9 @@ private static final long serialVersionUID = 1L;
/** 删除标志0代表存在2代表删除 */
private Integer delFlag;
/** 状态1在线0离线 */
@Excel(name = "状态1在线0离线")
@ApiModelProperty("状态1在线0离线")
private Long status;
}