设备统计接口

This commit is contained in:
kerwincui
2022-06-06 17:45:36 +08:00
parent 1aa94d3e50
commit 653eee4e76
12 changed files with 182 additions and 7 deletions

View File

@@ -107,6 +107,17 @@ public class DeviceController extends BaseController
return AjaxResult.success(deviceService.selectDeviceByDeviceId(deviceId));
}
/**
* 获取设备统计信息
*/
@PreAuthorize("@ss.hasPermi('iot:device:query')")
@GetMapping(value = "/statistic")
@ApiOperation("获取设备统计信息")
public AjaxResult getDeviceStatistic()
{
return AjaxResult.success(deviceService.selectDeviceStatistic());
}
/**
* 获取设备详细信息
*/

View File

@@ -1,6 +1,7 @@
package com.ruoyi.iot.mapper;
import com.ruoyi.iot.domain.DeviceLog;
import com.ruoyi.iot.model.DeviceStatistic;
import com.ruoyi.iot.model.MonitorModel;
import org.springframework.stereotype.Repository;
@@ -24,6 +25,13 @@ public interface DeviceLogMapper
*/
public DeviceLog selectDeviceLogByLogId(Long logId);
/**
* 查询日志分类总数
*
* @return 设备日志
*/
public DeviceStatistic selectCategoryLogCount();
/**
* 查询设备日志列表
*

View File

@@ -1,10 +1,7 @@
package com.ruoyi.iot.mapper;
import com.ruoyi.iot.domain.Device;
import com.ruoyi.iot.model.AuthenticateInputModel;
import com.ruoyi.iot.model.DeviceAllShortOutput;
import com.ruoyi.iot.model.ProductAuthenticateModel;
import com.ruoyi.iot.model.DeviceShortOutput;
import com.ruoyi.iot.model.*;
import com.ruoyi.iot.model.ThingsModels.ThingsModelValuesInput;
import com.ruoyi.iot.model.ThingsModels.ThingsModelValuesOutput;
import org.springframework.stereotype.Repository;
@@ -28,6 +25,13 @@ public interface DeviceMapper
*/
public Device selectDeviceByDeviceId(Long deviceId);
/**
* 查询设备和产品总数
*
* @return 设备
*/
public DeviceStatistic selectDeviceProductAlertCount();
/**
* 根据设备编号查询设备
*

View File

@@ -0,0 +1,90 @@
package com.ruoyi.iot.model;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
/**
* id和name
*
* @author kerwincui
* @date 2021-12-16
*/
public class DeviceStatistic
{
/** 设备数量 **/
private Long deviceCount;
/** 产品数量 **/
private Long productCount;
/** 告警 **/
private Long alertCount;
/** 属性上报 **/
private Long propertyCount;
/** 功能上报 **/
private Long functionCount;
/** 事件上报 **/
private Long eventCount;
/** 监测数据上报 **/
private Long monitorCount;
public Long getMonitorCount() {
return monitorCount;
}
public void setMonitorCount(Long monitorCount) {
this.monitorCount = monitorCount;
}
public Long getDeviceCount() {
return deviceCount;
}
public void setDeviceCount(Long deviceCount) {
this.deviceCount = deviceCount;
}
public Long getProductCount() {
return productCount;
}
public void setProductCount(Long productCount) {
this.productCount = productCount;
}
public Long getAlertCount() {
return alertCount;
}
public void setAlertCount(Long alertCount) {
this.alertCount = alertCount;
}
public Long getPropertyCount() {
return propertyCount;
}
public void setPropertyCount(Long propertyCount) {
this.propertyCount = propertyCount;
}
public Long getFunctionCount() {
return functionCount;
}
public void setFunctionCount(Long functionCount) {
this.functionCount = functionCount;
}
public Long getEventCount() {
return eventCount;
}
public void setEventCount(Long eventCount) {
this.eventCount = eventCount;
}
}

View File

@@ -24,6 +24,13 @@ public interface IDeviceService
*/
public Device selectDeviceByDeviceId(Long deviceId);
/**
* 查询设备统计信息
*
* @return 设备
*/
public DeviceStatistic selectDeviceStatistic();
/**
* 根据设备编号查询设备
*

View File

@@ -47,7 +47,6 @@ public class DeviceLogServiceImpl implements IDeviceLogService
@Override
public List<DeviceLog> selectDeviceLogList(DeviceLog deviceLog)
{
// deviceLogMapper.selectDeviceLogList(deviceLog);
return logService.selectDeviceLogList(deviceLog);
}
@@ -60,7 +59,6 @@ public class DeviceLogServiceImpl implements IDeviceLogService
@Override
public List<MonitorModel> selectMonitorList(DeviceLog deviceLog)
{
// return deviceLogMapper.selectMonitorList(deviceLog);
return logService.selectMonitorList(deviceLog);
}
@@ -74,7 +72,6 @@ public class DeviceLogServiceImpl implements IDeviceLogService
public int insertDeviceLog(DeviceLog deviceLog)
{
deviceLog.setCreateTime(DateUtils.getNowDate());
// return deviceLogMapper.insertDeviceLog(deviceLog);
return logService.saveDeviceLog(deviceLog);
}

View File

@@ -89,6 +89,25 @@ public class DeviceServiceImpl implements IDeviceService {
return deviceMapper.selectDeviceByDeviceId(deviceId);
}
/**
* 查询设备统计信息
*
* @return 设备
*/
@Override
public DeviceStatistic selectDeviceStatistic() {
// 获取设备、产品和告警数量
DeviceStatistic statistic=deviceMapper.selectDeviceProductAlertCount();
// 获取属性、功能和事件
DeviceStatistic thingsCount=logService.selectCategoryLogCount();
// 组合属性、功能、事件和监测数据
statistic.setPropertyCount(thingsCount.getPropertyCount());
statistic.setFunctionCount(thingsCount.getFunctionCount());
statistic.setEventCount(thingsCount.getEventCount());
statistic.setMonitorCount(thingsCount.getMonitorCount());
return statistic;
}
/**
* 根据设备编号查询设备
*

View File

@@ -2,6 +2,7 @@ package com.ruoyi.iot.tdengine.service;
import com.ruoyi.iot.domain.DeviceLog;
import com.ruoyi.iot.model.DeviceStatistic;
import com.ruoyi.iot.model.MonitorModel;
import org.springframework.stereotype.Service;
@@ -19,7 +20,12 @@ public interface ILogService {
int saveDeviceLog(DeviceLog deviceLog);
/** 设备属性、功能、事件总数 **/
DeviceStatistic selectCategoryLogCount();
/** 查询物模型日志列表 **/
List<DeviceLog> selectDeviceLogList(DeviceLog deviceLog);
/** 查询监测数据列表 **/
List<MonitorModel> selectMonitorList(DeviceLog deviceLog);
}

View File

@@ -1,6 +1,7 @@
package com.ruoyi.iot.tdengine.service.impl;
import com.ruoyi.iot.domain.DeviceLog;
import com.ruoyi.iot.model.DeviceStatistic;
import com.ruoyi.iot.tdengine.service.ILogService;
import com.ruoyi.iot.mapper.DeviceLogMapper;
import com.ruoyi.iot.model.MonitorModel;
@@ -20,11 +21,18 @@ public class MySqlLogServiceImpl implements ILogService {
public MySqlLogServiceImpl(DeviceLogMapper _deviceLogMapper){
this.deviceLogMapper=_deviceLogMapper;
}
@Override
public int saveDeviceLog(DeviceLog deviceLog) {
return deviceLogMapper.insertDeviceLog(deviceLog);
}
/** 设备属性、功能、事件和监测数据总数 **/
@Override
public DeviceStatistic selectCategoryLogCount(){
return deviceLogMapper.selectCategoryLogCount();
}
@Override
public List<DeviceLog> selectDeviceLogList(DeviceLog deviceLog) {
return deviceLogMapper.selectDeviceLogList(deviceLog);

View File

@@ -1,6 +1,7 @@
package com.ruoyi.iot.tdengine.service.impl;
import com.ruoyi.iot.domain.DeviceLog;
import com.ruoyi.iot.model.DeviceStatistic;
import com.ruoyi.iot.tdengine.service.ILogService;
import com.ruoyi.iot.model.MonitorModel;
import com.ruoyi.iot.tdengine.config.TDengineConfig;
@@ -42,6 +43,13 @@ public class TdengineLogServiceImpl implements ILogService {
return tdDeviceLogDAO.save(dbName,deviceLog);
}
/** 设备属性、功能、事件和监测数据总数 **/
@Override
public DeviceStatistic selectCategoryLogCount(){
// return tdDeviceLogDAO.save(dbName,new DeviceLog());
return null;
}
@Override
public List<DeviceLog> selectDeviceLogList(DeviceLog deviceLog) {
return tdDeviceLogDAO.selectDeviceLogList(dbName,deviceLog);

View File

@@ -54,6 +54,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where log_id = #{logId}
</select>
<select id="selectCategoryLogCount" parameterType="Long" resultType="com.ruoyi.iot.model.DeviceStatistic">
SELECT
(select count(log_id) from iot_device_log where log_type=1) as propertyCount,
(select count(log_id) from iot_device_log where log_type=2) as functionCount,
(select count(log_id) from iot_device_log where log_type=3) as eventCount,
(select count(log_id) from iot_device_log where log_type=1 and is_monitor=1) as monitorCount
from iot_device_log
limit 1
</select>
<insert id="insertDeviceLog" parameterType="com.ruoyi.iot.domain.DeviceLog" useGeneratedKeys="true" keyProperty="logId">
insert into iot_device_log
<trim prefix="(" suffix=")" suffixOverrides=",">

View File

@@ -192,6 +192,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where device_id = #{deviceId}
</select>
<select id="selectDeviceProductAlertCount" resultType="com.ruoyi.iot.model.DeviceStatistic">
SELECT count(device_id) as deviceCount,
(select count(product_id) from iot_product) as productCount,
(select count(alert_log_id) from iot_alert_log) as alertCount
from iot_device
</select>
<select id="selectProductAuthenticate" parameterType="com.ruoyi.iot.model.AuthenticateInputModel" resultMap="DeviceAuthenticateResult">
SELECT p.mqtt_password,p.mqtt_account, p.mqtt_secret,p.is_authorize,p.product_id,p.product_name,p.vertificate_method,p.STATUS as product_status,d.device_id,d.device_name,d.STATUS,d.serial_number
FROM iot_product p