设备在线率统计等
This commit is contained in:
@ -1,19 +1,28 @@
|
||||
package com.fastbee.data.controller.aaScreenAgricultural;
|
||||
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLForeignKeyImpl;
|
||||
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
|
||||
import com.fastbee.common.core.controller.BaseController;
|
||||
import com.fastbee.common.core.domain.AjaxResult;
|
||||
import com.fastbee.common.holder.ProjectHolder;
|
||||
import com.fastbee.deviceData.api.devlink.service.ZhanLianBaseService;
|
||||
import com.fastbee.deviceData.domain.dto.DeviceProperties;
|
||||
import com.fastbee.deviceInfo.manager.DeviceInformationManager;
|
||||
import com.fastbee.iot.domain.AlertLog;
|
||||
import com.fastbee.iot.domain.Device;
|
||||
import com.fastbee.iot.mapper.AlertLogMapper;
|
||||
import com.fastbee.iot.mapper.DeviceMapper;
|
||||
import com.fastbee.iot.model.DeviceShortOutput;
|
||||
import com.fastbee.iot.service.IDeviceService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@ -32,6 +41,9 @@ public class DeviceAlarmController extends BaseController {
|
||||
@Autowired
|
||||
private DeviceInformationManager deviceInformationManager;
|
||||
|
||||
@Autowired
|
||||
private DeviceMapper deviceMapper;
|
||||
|
||||
/**
|
||||
* 获取设备告警数量
|
||||
*/
|
||||
@ -49,9 +61,23 @@ public class DeviceAlarmController extends BaseController {
|
||||
.eq(false,AlertLog::getUserId,"")
|
||||
.count();
|
||||
|
||||
//统计设备离线数量
|
||||
List<Device> deviceList = new LambdaQueryChainWrapper<>(deviceMapper)
|
||||
.select(Device::getDeviceId,Device::getDeviceName,Device::getProductId,Device::getProductName,Device::getStatus,Device::getTenantId)
|
||||
.eq(Device::getTenantId, ProjectHolder.getProjectInfo().getProjectAdminId())
|
||||
.list();
|
||||
//循环统计状态值为4离线设备数量
|
||||
int count1 = 0;
|
||||
for (Device device : deviceList) {
|
||||
if(device.getStatus()==4){
|
||||
count1++;
|
||||
}
|
||||
}
|
||||
|
||||
Map<String,Object> resp =new HashMap<>();
|
||||
resp.put("alarmTotal",count);
|
||||
resp.put("securityLevel",getSecurityLevel(count));
|
||||
resp.put("alarmTotal",count);//告警总数
|
||||
resp.put("securityLevel",getSecurityLevel(count));//安全等级
|
||||
resp.put("offlineDeviceTotal",count1);//离线设备总数
|
||||
return AjaxResult.success(resp);
|
||||
}
|
||||
|
||||
@ -69,20 +95,120 @@ public class DeviceAlarmController extends BaseController {
|
||||
* 统计设备在线率
|
||||
*/
|
||||
@GetMapping("/onlineRate")
|
||||
public AjaxResult getDeviceOnlineRate() {
|
||||
HashMap<String, Object> body = new HashMap<>();
|
||||
body.put("method","get");
|
||||
body.put("path","api/v1/product/device/list");
|
||||
JSONObject data = zhanLianBaseService.baseRequest(body);
|
||||
public AjaxResult getDeviceOnlineRate(Device device) {
|
||||
|
||||
//仁科设备
|
||||
List<Device> deviceList = new LambdaQueryChainWrapper<>(deviceMapper)
|
||||
.select(Device::getDeviceId,Device::getDeviceName,Device::getProductId,Device::getProductName,Device::getStatus,Device::getTenantId)
|
||||
.eq(Device::getTenantId,device.getTenantId())
|
||||
.list();
|
||||
// deviceList.forEach(System.err::println);
|
||||
int meteorologyDeviceCount = 0;//气象设备总量
|
||||
int meteorologyDeviceOnLineCount = 0;//气象设备在线量
|
||||
double meteorologyDeviceOnlineRate = 0.0; //气象设备在线率
|
||||
|
||||
int moistureDeviceCount = 0;//墒情设备总量
|
||||
int moistureDeviceOnLineCount = 0;//墒情设备在线量
|
||||
double moistureDeviceOnlineRate = 0.0; //墒情设备在线率
|
||||
|
||||
int wormDeviceCount = 0;//虫情设备总量
|
||||
int wormDeviceOnLineCount = 0;//虫情设备在线量
|
||||
double wormDeviceOnlineRate = 0.0; //虫情设备在线率
|
||||
|
||||
int miaoQingDeviceCount = 0;//苗情设备总量
|
||||
int miaoQingDeviceOnLineCount = 0;//苗情设备在线量
|
||||
double miaoQingDeviceOnlineRate = 0.0; //苗情设备在线率
|
||||
|
||||
int insecticidalLampDeviceCount = 0;//杀虫灯设备总量
|
||||
int insecticidalLampDeviceOnLineCount = 0;//杀虫灯设备在线量
|
||||
double insecticidalLampDeviceOnlineRate = 0.0; //杀虫灯设备在线率
|
||||
|
||||
int monitorDeviceCount = 0;//监控设备总量
|
||||
int monitorDeviceOnLineCount = 0;//监控设备在线量
|
||||
double monitorDeviceOnlineRate = 0.0; //监控设备在线率
|
||||
|
||||
return AjaxResult.success();
|
||||
for (Device d:deviceList) {
|
||||
if (d.getProductName().equals("气象设备") || d.getProductId() == 144) {
|
||||
meteorologyDeviceCount++;
|
||||
if (d.getStatus() == 3) {
|
||||
meteorologyDeviceOnLineCount++;
|
||||
}
|
||||
} else if (d.getProductName().equals("墒情设备") || d.getProductId() == 142) {
|
||||
moistureDeviceCount++;
|
||||
if (d.getStatus() == 3) {
|
||||
moistureDeviceOnLineCount++;
|
||||
}
|
||||
} else if (d.getProductName().equals("太阳能供电设备") || d.getProductId() == 138) {
|
||||
miaoQingDeviceCount++;
|
||||
if (d.getStatus() == 3) {
|
||||
miaoQingDeviceOnLineCount++;
|
||||
}
|
||||
} else if (d.getProductName().equals("杀虫灯设备") || d.getProductId() == 145) {
|
||||
insecticidalLampDeviceCount++;
|
||||
if (d.getStatus() == 3) {
|
||||
insecticidalLampDeviceOnLineCount++;
|
||||
}
|
||||
} else if (d.getProductName().equals("虫情设备") || d.getProductId() == 143) {
|
||||
wormDeviceCount++;
|
||||
if (d.getStatus() == 3) {
|
||||
wormDeviceOnLineCount++;
|
||||
}
|
||||
|
||||
} else if ( d.getProductName().equals("萤石云视频")||d.getProductId()==141) {
|
||||
monitorDeviceCount++;
|
||||
if(d.getStatus()==3){
|
||||
monitorDeviceOnLineCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
//打印累加后结果
|
||||
System.out.println("气象设备总量:"+meteorologyDeviceCount);
|
||||
System.out.println("气象设备在线量:"+meteorologyDeviceOnLineCount);
|
||||
System.out.println("气象设备在线率:"+meteorologyDeviceOnlineRate);
|
||||
System.out.println("-------------------------------------------");
|
||||
System.out.println("墒情设备总量:"+moistureDeviceCount);
|
||||
System.out.println("墒情设备在线量:"+moistureDeviceOnLineCount);
|
||||
System.out.println("墒情设备在线率:"+moistureDeviceOnlineRate);
|
||||
System.out.println("-------------------------------------------");
|
||||
System.out.println("虫情设备总量:"+wormDeviceCount);
|
||||
System.out.println("虫情设备在线量:"+wormDeviceOnLineCount);
|
||||
System.out.println("虫情设备在线率:"+wormDeviceOnlineRate);
|
||||
System.out.println("-------------------------------------------");
|
||||
System.out.println("苗情设备总量:"+miaoQingDeviceCount);
|
||||
System.out.println("苗情设备在线量:"+miaoQingDeviceOnLineCount);
|
||||
System.out.println("苗情设备在线率:"+miaoQingDeviceOnlineRate);
|
||||
System.out.println("-------------------------------------------");
|
||||
System.out.println("杀虫灯设备总量:"+insecticidalLampDeviceCount);
|
||||
System.out.println("杀虫灯设备在线量:"+insecticidalLampDeviceOnLineCount);
|
||||
System.out.println("杀虫灯设备在线率:"+insecticidalLampDeviceOnlineRate);
|
||||
System.out.println("-------------------------------------------");
|
||||
System.out.println("监控设备总量:"+monitorDeviceCount);
|
||||
System.out.println("监控设备在线量:"+monitorDeviceOnLineCount);
|
||||
System.out.println("监控设备在线率:"+monitorDeviceOnlineRate);
|
||||
System.out.println("-------------------------------------------");
|
||||
//计算在线率
|
||||
//气象设备在线率
|
||||
meteorologyDeviceOnlineRate = meteorologyDeviceCount==0?0.0:((double) meteorologyDeviceOnLineCount / meteorologyDeviceCount)*100;
|
||||
//墒情设备在线率
|
||||
moistureDeviceOnlineRate = moistureDeviceCount==0?0.0:((double) moistureDeviceOnLineCount / moistureDeviceCount)*100;
|
||||
//虫情设备在线率
|
||||
wormDeviceOnlineRate = wormDeviceCount==0?0.0:((double) wormDeviceOnLineCount / wormDeviceCount)*100;
|
||||
//苗情设备在线率
|
||||
miaoQingDeviceOnlineRate = miaoQingDeviceCount==0?0.0:((double) miaoQingDeviceOnLineCount / miaoQingDeviceCount)*100;
|
||||
//杀虫灯设备在线率
|
||||
insecticidalLampDeviceOnlineRate = insecticidalLampDeviceCount==0?0.0:((double) insecticidalLampDeviceOnLineCount / insecticidalLampDeviceCount)*100;
|
||||
//监控设备在线率
|
||||
monitorDeviceOnlineRate = monitorDeviceCount==0?0.0:((double) monitorDeviceOnLineCount / monitorDeviceCount)*100;
|
||||
|
||||
//封装结果
|
||||
List<DeviceProperties> restList=new ArrayList<>();
|
||||
restList.add(DeviceProperties.builder().name("气象监测").value(String.valueOf(meteorologyDeviceOnlineRate)).unit("%").build());
|
||||
restList.add(DeviceProperties.builder().name("墒情监测").value(String.valueOf(moistureDeviceOnlineRate)).unit("%").build());
|
||||
restList.add(DeviceProperties.builder().name("虫情监测").value(String.valueOf(wormDeviceOnlineRate)).unit("%").build());
|
||||
restList.add(DeviceProperties.builder().name("苗情监测").value(String.valueOf(miaoQingDeviceOnlineRate)).unit("%").build());
|
||||
restList.add(DeviceProperties.builder().name("杀虫灯").value(String.valueOf(insecticidalLampDeviceOnlineRate)).unit("%").build());
|
||||
restList.add(DeviceProperties.builder().name("监控").value(String.valueOf(monitorDeviceOnlineRate)).unit("%").build());
|
||||
|
||||
return AjaxResult.success(restList);
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user