设备在线率统计等
This commit is contained in:
parent
6e9249aa49
commit
eda321d9d8
@ -1,19 +1,28 @@
|
|||||||
package com.fastbee.data.controller.aaScreenAgricultural;
|
package com.fastbee.data.controller.aaScreenAgricultural;
|
||||||
|
|
||||||
import cn.hutool.json.JSONObject;
|
import cn.hutool.json.JSONObject;
|
||||||
|
import com.alibaba.druid.sql.ast.statement.SQLForeignKeyImpl;
|
||||||
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
|
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
|
||||||
import com.fastbee.common.core.controller.BaseController;
|
import com.fastbee.common.core.controller.BaseController;
|
||||||
import com.fastbee.common.core.domain.AjaxResult;
|
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.api.devlink.service.ZhanLianBaseService;
|
||||||
|
import com.fastbee.deviceData.domain.dto.DeviceProperties;
|
||||||
import com.fastbee.deviceInfo.manager.DeviceInformationManager;
|
import com.fastbee.deviceInfo.manager.DeviceInformationManager;
|
||||||
import com.fastbee.iot.domain.AlertLog;
|
import com.fastbee.iot.domain.AlertLog;
|
||||||
|
import com.fastbee.iot.domain.Device;
|
||||||
import com.fastbee.iot.mapper.AlertLogMapper;
|
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.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -32,6 +41,9 @@ public class DeviceAlarmController extends BaseController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private DeviceInformationManager deviceInformationManager;
|
private DeviceInformationManager deviceInformationManager;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private DeviceMapper deviceMapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取设备告警数量
|
* 获取设备告警数量
|
||||||
*/
|
*/
|
||||||
@ -49,9 +61,23 @@ public class DeviceAlarmController extends BaseController {
|
|||||||
.eq(false,AlertLog::getUserId,"")
|
.eq(false,AlertLog::getUserId,"")
|
||||||
.count();
|
.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<>();
|
Map<String,Object> resp =new HashMap<>();
|
||||||
resp.put("alarmTotal",count);
|
resp.put("alarmTotal",count);//告警总数
|
||||||
resp.put("securityLevel",getSecurityLevel(count));
|
resp.put("securityLevel",getSecurityLevel(count));//安全等级
|
||||||
|
resp.put("offlineDeviceTotal",count1);//离线设备总数
|
||||||
return AjaxResult.success(resp);
|
return AjaxResult.success(resp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,20 +95,120 @@ public class DeviceAlarmController extends BaseController {
|
|||||||
* 统计设备在线率
|
* 统计设备在线率
|
||||||
*/
|
*/
|
||||||
@GetMapping("/onlineRate")
|
@GetMapping("/onlineRate")
|
||||||
public AjaxResult getDeviceOnlineRate() {
|
public AjaxResult getDeviceOnlineRate(Device device) {
|
||||||
HashMap<String, Object> body = new HashMap<>();
|
|
||||||
body.put("method","get");
|
|
||||||
body.put("path","api/v1/product/device/list");
|
|
||||||
JSONObject data = zhanLianBaseService.baseRequest(body);
|
|
||||||
|
|
||||||
//仁科设备
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -19,6 +19,8 @@ public class ZhanLianBaseService {
|
|||||||
private ZhanLianAuthorizationService authorizationService;
|
private ZhanLianAuthorizationService authorizationService;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 基本请求
|
* 基本请求
|
||||||
* @param body 请求负载
|
* @param body 请求负载
|
||||||
|
@ -5,6 +5,7 @@ import com.fasterxml.jackson.annotation.JsonFormat;
|
|||||||
import com.fastbee.common.annotation.Excel;
|
import com.fastbee.common.annotation.Excel;
|
||||||
import com.fastbee.iot.model.ThingsModelItem.*;
|
import com.fastbee.iot.model.ThingsModelItem.*;
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
@ -18,6 +19,7 @@ import java.util.List;
|
|||||||
* @author kerwincui
|
* @author kerwincui
|
||||||
* @date 2021-12-16
|
* @date 2021-12-16
|
||||||
*/
|
*/
|
||||||
|
@Data
|
||||||
public class DeviceShortOutput implements Serializable {
|
public class DeviceShortOutput implements Serializable {
|
||||||
public DeviceShortOutput(){
|
public DeviceShortOutput(){
|
||||||
this.stringList=new ArrayList<>();
|
this.stringList=new ArrayList<>();
|
||||||
|
@ -65,7 +65,7 @@ public class QxtrTask {
|
|||||||
* 定时任务 更新设备在线状态
|
* 定时任务 更新设备在线状态
|
||||||
*/
|
*/
|
||||||
public void updateDeviceStatus() throws Exception {
|
public void updateDeviceStatus() throws Exception {
|
||||||
// log.info("定时任务,更新设备在线状态");
|
log.info("定时任务,更新设备在线状态");
|
||||||
Device device = new Device();
|
Device device = new Device();
|
||||||
ArrayList<Map<String, Object>> resultList = new ArrayList<>();
|
ArrayList<Map<String, Object>> resultList = new ArrayList<>();
|
||||||
device.setProductId(136L);
|
device.setProductId(136L);
|
||||||
|
@ -39,6 +39,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
<result property="tel" column="tel" />
|
<result property="tel" column="tel" />
|
||||||
<result property="caretaker" column="caretaker" />
|
<result property="caretaker" column="caretaker" />
|
||||||
<result property="managementUnit" column="management_unit" />
|
<result property="managementUnit" column="management_unit" />
|
||||||
|
<result property="deviceBrand" column="device_brand" />
|
||||||
|
<result property="deviceModel" column="device_model" />
|
||||||
</resultMap>
|
</resultMap>
|
||||||
|
|
||||||
<resultMap type="com.fastbee.iot.model.DeviceShortOutput" id="DeviceShortResult">
|
<resultMap type="com.fastbee.iot.model.DeviceShortOutput" id="DeviceShortResult">
|
||||||
@ -370,7 +372,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
d.serial_number, d.management_unit, d.caretaker, d.tel,
|
d.serial_number, d.management_unit, d.caretaker, d.tel,
|
||||||
d.firmware_version, d.status, d.rssi,d.is_shadow,d.is_simulate ,d.location_way,d.things_model_value,
|
d.firmware_version, d.status, d.rssi,d.is_shadow,d.is_simulate ,d.location_way,d.things_model_value,
|
||||||
d.network_address, d.network_ip, d.longitude, d.latitude, d.active_time, d.create_time, d.update_time,
|
d.network_address, d.network_ip, d.longitude, d.latitude, d.active_time, d.create_time, d.update_time,
|
||||||
d.img_url,d.summary,d.remark,d.dev_params,p.guid from iot_device d
|
d.img_url,d.summary,d.remark,d.dev_params,p.guid,d.device_brand,d.device_model from iot_device d
|
||||||
left join iot_product p on p.product_id=d.product_id
|
left join iot_product p on p.product_id=d.product_id
|
||||||
where device_id = #{deviceId}
|
where device_id = #{deviceId}
|
||||||
</select>
|
</select>
|
||||||
@ -537,6 +539,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
<if test="managementUnit != null">management_unit,</if>
|
<if test="managementUnit != null">management_unit,</if>
|
||||||
<if test="caretaker != null">caretaker,</if>
|
<if test="caretaker != null">caretaker,</if>
|
||||||
<if test="tel != null">tel,</if>
|
<if test="tel != null">tel,</if>
|
||||||
|
<if test="deviceBrand != null">device_brand,</if>
|
||||||
|
<if test="deviceModel != null">device_model,</if>
|
||||||
</trim>
|
</trim>
|
||||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||||
<if test="deviceName != null and deviceName != ''">#{deviceName},</if>
|
<if test="deviceName != null and deviceName != ''">#{deviceName},</if>
|
||||||
@ -571,6 +575,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
<if test="managementUnit != null">#{managementUnit},</if>
|
<if test="managementUnit != null">#{managementUnit},</if>
|
||||||
<if test="caretaker != null">#{caretaker},</if>
|
<if test="caretaker != null">#{caretaker},</if>
|
||||||
<if test="tel != null">#{tel},</if>
|
<if test="tel != null">#{tel},</if>
|
||||||
|
<if test="deviceBrand != null">#{deviceBrand},</if>
|
||||||
|
<if test="deviceModel != null">#{deviceModel},</if>
|
||||||
</trim>
|
</trim>
|
||||||
</insert>
|
</insert>
|
||||||
|
|
||||||
@ -630,6 +636,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
<if test="managementUnit != null">management_unit = #{managementUnit},</if>
|
<if test="managementUnit != null">management_unit = #{managementUnit},</if>
|
||||||
<if test="caretaker != null">caretaker = #{caretaker},</if>
|
<if test="caretaker != null">caretaker = #{caretaker},</if>
|
||||||
<if test="tel != null">tel = #{tel},</if>
|
<if test="tel != null">tel = #{tel},</if>
|
||||||
|
<if test="deviceBrand != null">#{deviceBrand},</if>
|
||||||
|
<if test="deviceModel != null">#{deviceModel},</if>
|
||||||
</trim>
|
</trim>
|
||||||
where device_id = #{deviceId}
|
where device_id = #{deviceId}
|
||||||
</update>
|
</update>
|
||||||
@ -694,6 +702,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
<if test="managementUnit != null">management_unit = #{managementUnit},</if>
|
<if test="managementUnit != null">management_unit = #{managementUnit},</if>
|
||||||
<if test="caretaker != null">caretaker = #{caretaker},</if>
|
<if test="caretaker != null">caretaker = #{caretaker},</if>
|
||||||
<if test="tel != null">tel = #{tel},</if>
|
<if test="tel != null">tel = #{tel},</if>
|
||||||
|
<if test="deviceBrand != null">#{deviceBrand},</if>
|
||||||
|
<if test="deviceModel != null">#{deviceModel},</if>
|
||||||
</trim>
|
</trim>
|
||||||
where serial_number = #{serialNumber}
|
where serial_number = #{serialNumber}
|
||||||
</update>
|
</update>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user