添加监控实时状态获取定时任务
This commit is contained in:
parent
2b9a21c063
commit
3a642833c4
@ -189,4 +189,6 @@ public class DeviceInfoController extends BaseController {
|
||||
.eq(DeviceInformationMonitor::getProjectId,projectId);
|
||||
return success(deviceInformationMonitorMapper.selectList(queryWrapper));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -63,7 +63,6 @@ public class DeviceRealtimedataSeedlingGrowthController {
|
||||
if (videoPlayMap.containsKey("playUrl")) {
|
||||
Object playUrl = videoPlayMap.get("playUrl");
|
||||
monitor.setPlayUrl(playUrl.toString());
|
||||
|
||||
}
|
||||
if( videoPlayMap.containsKey("accessToken")){
|
||||
Object accessToken = videoPlayMap.get("accessToken");
|
||||
@ -76,4 +75,16 @@ public class DeviceRealtimedataSeedlingGrowthController {
|
||||
monitor.setStatus((Long) status);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新设备状态测试接口
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
@GetMapping("/status")
|
||||
public AjaxResult getMonitorDeviceRealtimeStatusData() throws Exception {
|
||||
return AjaxResult.success(yingshiyunService.getMonitorDeviceRealtimeStatusData());
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -4,6 +4,7 @@ import cn.hutool.core.util.StrUtil;
|
||||
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.query.LambdaQueryChainWrapper;
|
||||
@ -13,6 +14,7 @@ import com.fastbee.deviceData.domain.NgYingshiCloudIntegrationInfo;
|
||||
import com.fastbee.deviceData.mapper.NgYingshiCloudIntegrationInfoMapper;
|
||||
import com.fastbee.deviceInfo.domain.DeviceInformationMonitor;
|
||||
import com.fastbee.deviceInfo.mapper.DeviceInformationMonitorMapper;
|
||||
import com.fastbee.deviceInfo.service.IDeviceInformationMonitorService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -23,6 +25,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
@Service
|
||||
@ -34,6 +37,82 @@ public class YingshiyunService {
|
||||
private DeviceInformationMonitorMapper deviceInformationMonitorMapper;
|
||||
@Autowired
|
||||
private NgYingshiCloudIntegrationInfoMapper ngYingshiCloudIntegrationInfoMapper;
|
||||
@Autowired
|
||||
private DeviceInformationMonitorMapper monitorMapper;
|
||||
@Autowired
|
||||
private NgYingshiCloudIntegrationInfoMapper yingshiCloudIntegrationInfoMapper;
|
||||
@Autowired
|
||||
private IDeviceInformationMonitorService deviceInformationMonitorService;
|
||||
|
||||
/**
|
||||
* 获取监控设备实时状态并更新
|
||||
*/
|
||||
public String getMonitorDeviceRealtimeStatusData() throws Exception{
|
||||
try{
|
||||
//获取所有监控设备编码列表
|
||||
List<DeviceInformationMonitor> monitorList=new LambdaQueryChainWrapper<>(monitorMapper)
|
||||
.select(DeviceInformationMonitor::getDeviceEncoding,DeviceInformationMonitor::getStatus,DeviceInformationMonitor::getId,DeviceInformationMonitor::getProjectId)
|
||||
.list();
|
||||
System.err.println("monitorLIST:"+monitorList);
|
||||
//获取所有萤石云对接信息列表
|
||||
List<NgYingshiCloudIntegrationInfo> integrationInfoList=new LambdaQueryChainWrapper<>(yingshiCloudIntegrationInfoMapper)
|
||||
.select(NgYingshiCloudIntegrationInfo::getAppkey,NgYingshiCloudIntegrationInfo::getAppsecret,NgYingshiCloudIntegrationInfo::getProjectid)
|
||||
.list();
|
||||
System.err.println("integrationInfoList:"+integrationInfoList);
|
||||
//根据projectId进行分组
|
||||
Map<Long, List<DeviceInformationMonitor>> collect = monitorList.stream().collect(Collectors.groupingBy(DeviceInformationMonitor::getProjectId));
|
||||
System.err.println("collect:"+collect);
|
||||
if(integrationInfoList.size()==0)
|
||||
{
|
||||
System.err.println("设备信息不存在");
|
||||
}
|
||||
//k为projectId,v为projectId下的设备列表
|
||||
collect.forEach((k,v)->{
|
||||
System.err.println("k:"+k);
|
||||
System.err.println("v:"+v);
|
||||
//获取萤石云对接信息
|
||||
List<NgYingshiCloudIntegrationInfo> list = new LambdaQueryChainWrapper<>(yingshiCloudIntegrationInfoMapper)
|
||||
.select(NgYingshiCloudIntegrationInfo::getAppkey, NgYingshiCloudIntegrationInfo::getAppsecret)
|
||||
.eq(NgYingshiCloudIntegrationInfo::getProjectid, k)
|
||||
.list();
|
||||
NgYingshiCloudIntegrationInfo yingshiCloudIntegrationInfo;
|
||||
if(!list.isEmpty())
|
||||
{
|
||||
yingshiCloudIntegrationInfo=list.get(0);
|
||||
//获取accessToken
|
||||
String accessToken=getAuth(yingshiCloudIntegrationInfo.getAppkey(),yingshiCloudIntegrationInfo.getAppsecret());
|
||||
//获取设备信息列表
|
||||
int page=0;
|
||||
JSONObject deviceInfoList = getInfoList(accessToken);
|
||||
JSONArray data= deviceInfoList.getJSONArray("data");
|
||||
System.err.println("data:"+data);
|
||||
data.forEach(d->{
|
||||
|
||||
JSONObject object = JSONUtil.parseObj(d.toString());
|
||||
String deviceSerial=object.getStr("deviceSerial");//设备编码
|
||||
Long status=object.getLong("status");//设备状态
|
||||
for(DeviceInformationMonitor device:v)
|
||||
{
|
||||
if(device.getDeviceEncoding().equals(deviceSerial))
|
||||
{
|
||||
device.setStatus(status);//设置status,0=离线,1=在线
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
//批量更新设备状态数据
|
||||
boolean flag=deviceInformationMonitorService.updateBatchById(v);
|
||||
if(!flag)
|
||||
{
|
||||
System.err.println("监控设备状态更新失败");
|
||||
}
|
||||
});
|
||||
}catch (Exception e){
|
||||
System.err.println("获取监控设备实时状态失败"+e.getMessage());
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
//获取鉴权
|
||||
public String getAuth(String appKey,String appSecret){
|
||||
@ -210,6 +289,26 @@ public class YingshiyunService {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设备信息列表,包括在线状态和是否加密
|
||||
* @param accessToken
|
||||
* @return
|
||||
*/
|
||||
public JSONObject getInfoList(String accessToken)
|
||||
{
|
||||
String INFO_URL="https://open.ys7.com/api/lapp/device/list";//获取单个设备信息接口地址
|
||||
String infoBody=StrUtil.format("accessToken={}",accessToken);
|
||||
HttpResponse infoResponse=HttpRequest.post(INFO_URL)
|
||||
.body(infoBody).execute();
|
||||
if(!JSONUtil.parseObj(infoResponse.body()).get("code").toString().equals("200"))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
JSONObject response=JSONUtil.parseObj(infoResponse.body());
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1,7 +1,11 @@
|
||||
package com.fastbee.deviceInfo.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.fastbee.deviceInfo.domain.DeviceInformationMonitor;
|
||||
import com.fastbee.deviceInfo.mapper.DeviceInformationMonitorMapper;
|
||||
|
||||
/**
|
||||
* 监控站设备基础信息Service接口
|
||||
@ -9,12 +13,11 @@ import com.fastbee.deviceInfo.domain.DeviceInformationMonitor;
|
||||
* @author kerwincui
|
||||
* @date 2024-11-18
|
||||
*/
|
||||
public interface IDeviceInformationMonitorService
|
||||
public interface IDeviceInformationMonitorService extends IService<DeviceInformationMonitor>
|
||||
{
|
||||
/**
|
||||
* 查询监控站设备基础信息
|
||||
*
|
||||
* @param id 监控站设备基础信息主键
|
||||
*
|
||||
* @return 监控站设备基础信息
|
||||
*/
|
||||
public DeviceInformationMonitor selectDeviceInformationMonitorById(String deviceEncoding);
|
||||
|
@ -1,6 +1,8 @@
|
||||
package com.fastbee.deviceInfo.service.impl;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.fastbee.common.utils.DateUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -15,15 +17,14 @@ import com.fastbee.deviceInfo.service.IDeviceInformationMonitorService;
|
||||
* @date 2024-11-18
|
||||
*/
|
||||
@Service
|
||||
public class DeviceInformationMonitorServiceImpl implements IDeviceInformationMonitorService
|
||||
public class DeviceInformationMonitorServiceImpl extends ServiceImpl<DeviceInformationMonitorMapper,DeviceInformationMonitor> implements IDeviceInformationMonitorService
|
||||
{
|
||||
@Autowired
|
||||
private DeviceInformationMonitorMapper deviceInformationMonitorMapper;
|
||||
|
||||
/**
|
||||
* 查询监控站设备基础信息
|
||||
*
|
||||
* @param id 监控站设备基础信息主键
|
||||
*
|
||||
* @return 监控站设备基础信息
|
||||
*/
|
||||
@Override
|
||||
|
@ -1,5 +1,8 @@
|
||||
package com.fastbee.iot.timer;
|
||||
|
||||
import cn.hutool.json.JSONArray;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
|
||||
import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper;
|
||||
import com.fastbee.deviceData.api.devlink.service.ZhanLianMetDataService;
|
||||
@ -8,6 +11,7 @@ import com.fastbee.deviceData.api.devlink.service.ZhanLianMoistureDataService;
|
||||
import com.fastbee.deviceData.api.devlink.service.ZhanLianPhotovoltaicDataService;
|
||||
import com.fastbee.deviceData.api.renke.service.RenkeTargetpestsDeviceDataService;
|
||||
import com.fastbee.deviceData.api.renke.service.RenkeWormDeviceDataService;
|
||||
import com.fastbee.deviceData.api.yingshiyun.service.YingshiyunService;
|
||||
import com.fastbee.deviceData.domain.*;
|
||||
|
||||
import com.fastbee.deviceData.mapper.*;
|
||||
@ -15,14 +19,13 @@ import com.fastbee.deviceData.service.IDeviceRealtimedataWormsService;
|
||||
import com.fastbee.deviceData.service.impl.DeviceRealtimedataMeteorologyServiceImpl;
|
||||
import com.fastbee.deviceData.service.impl.DeviceRealtimedataMoistureServiceImpl;
|
||||
import com.fastbee.deviceData.service.impl.DeviceRealtimedataWormsServiceImpl;
|
||||
import com.fastbee.deviceInfo.domain.DeviceInformationMeteorology;
|
||||
import com.fastbee.deviceInfo.domain.DeviceInformationMoisture;
|
||||
import com.fastbee.deviceInfo.domain.DeviceInformationTargetpests;
|
||||
import com.fastbee.deviceInfo.domain.DeviceInformationWorms;
|
||||
import com.fastbee.deviceInfo.domain.*;
|
||||
import com.fastbee.deviceInfo.mapper.*;
|
||||
import com.fastbee.deviceInfo.service.IDeviceInformationMonitorService;
|
||||
import com.fastbee.iot.mapper.DeviceMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.connection.stream.Consumer;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@ -98,6 +101,15 @@ public class DeviceDateTask {
|
||||
@Autowired
|
||||
private DeviceInformationTargetpestsMapper targetpestsMapper;
|
||||
|
||||
@Autowired
|
||||
private YingshiyunService yingshiyunService;
|
||||
|
||||
@Autowired
|
||||
private NgYingshiCloudIntegrationInfoMapper yingshiCloudIntegrationInfoMapper;
|
||||
|
||||
@Autowired
|
||||
private IDeviceInformationMonitorService deviceInformationMonitorService;
|
||||
|
||||
|
||||
|
||||
|
||||
@ -252,5 +264,80 @@ public class DeviceDateTask {
|
||||
System.out.println("插入数据失败!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取监控设备实时状态并更新
|
||||
*/
|
||||
public void getMonitorDeviceRealtimeStatusData() throws Exception{
|
||||
try{
|
||||
//获取所有监控设备编码列表
|
||||
List<DeviceInformationMonitor> monitorList=new LambdaQueryChainWrapper<>(monitorMapper)
|
||||
.select(DeviceInformationMonitor::getDeviceEncoding,DeviceInformationMonitor::getStatus,DeviceInformationMonitor::getId,DeviceInformationMonitor::getProjectId)
|
||||
.list();
|
||||
// log.info("monitorLIST:"+monitorList);
|
||||
//根据projectId对监控设备列表进行分组
|
||||
Map<Long, List<DeviceInformationMonitor>> collect = monitorList.stream().collect(Collectors.groupingBy(DeviceInformationMonitor::getProjectId));
|
||||
// System.err.println("collect:"+collect);
|
||||
//获取所有萤石云对接信息列表
|
||||
List<NgYingshiCloudIntegrationInfo> integrationInfoList=new LambdaQueryChainWrapper<>(yingshiCloudIntegrationInfoMapper)
|
||||
.select(NgYingshiCloudIntegrationInfo::getAppkey,NgYingshiCloudIntegrationInfo::getAppsecret,NgYingshiCloudIntegrationInfo::getProjectid)
|
||||
.list();
|
||||
// System.err.println("integrationInfoList:"+integrationInfoList);
|
||||
|
||||
if(integrationInfoList.size()==0)
|
||||
{
|
||||
// System.err.println("设备信息不存在");
|
||||
log.warn("设备信息不存在");
|
||||
}
|
||||
//k为projectId,v为projectId下的设备列表
|
||||
collect.forEach((k,v)->{
|
||||
/*log.info("k:"+k);
|
||||
log.info("v:"+v);*/
|
||||
//获取萤石云对接信息
|
||||
List<NgYingshiCloudIntegrationInfo> list = new LambdaQueryChainWrapper<>(yingshiCloudIntegrationInfoMapper)
|
||||
.select(NgYingshiCloudIntegrationInfo::getAppkey, NgYingshiCloudIntegrationInfo::getAppsecret)
|
||||
.eq(NgYingshiCloudIntegrationInfo::getProjectid, k)
|
||||
.list();
|
||||
NgYingshiCloudIntegrationInfo yingshiCloudIntegrationInfo;
|
||||
if(!list.isEmpty())
|
||||
{
|
||||
yingshiCloudIntegrationInfo=list.get(0);
|
||||
//获取accessToken
|
||||
String accessToken=yingshiyunService.getAuth(yingshiCloudIntegrationInfo.getAppkey(),yingshiCloudIntegrationInfo.getAppsecret());
|
||||
//获取设备信息列表
|
||||
JSONObject deviceInfoList = yingshiyunService.getInfoList(accessToken);
|
||||
log.info(k+"的监控设备json:"+deviceInfoList);
|
||||
if(deviceInfoList.isEmpty())
|
||||
{
|
||||
log.warn(k+"的监控设备json为空");
|
||||
}
|
||||
JSONArray data= deviceInfoList.getJSONArray("data");
|
||||
log.info(k+"的监控设备信息:"+data);
|
||||
data.forEach(d->{
|
||||
JSONObject object = JSONUtil.parseObj(d.toString());
|
||||
String deviceSerial=object.getStr("deviceSerial");//设备编码
|
||||
Long status=object.getLong("status");//设备状态
|
||||
for(DeviceInformationMonitor device:v)
|
||||
{
|
||||
if(device.getDeviceEncoding().equals(deviceSerial))
|
||||
{
|
||||
device.setStatus(status);//设置status,0=离线,1=在线
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
//批量更新设备状态数据
|
||||
boolean flag=deviceInformationMonitorService.updateBatchById(v);
|
||||
if(!flag)
|
||||
{
|
||||
log.warn("监控设备状态更新失败");
|
||||
}
|
||||
});
|
||||
}catch (Exception e){
|
||||
log.warn("获取监控设备实时状态失败",e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user