mirror of
https://gitee.com/beecue/fastbee.git
synced 2025-12-18 00:45:55 +08:00
多租户的测试调整
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package com.ruoyi.iot.mapper;
|
||||
|
||||
import com.ruoyi.iot.domain.Device;
|
||||
import com.ruoyi.iot.domain.DeviceLog;
|
||||
import com.ruoyi.iot.model.DeviceStatistic;
|
||||
import com.ruoyi.iot.model.MonitorModel;
|
||||
@@ -30,7 +31,7 @@ public interface DeviceLogMapper
|
||||
*
|
||||
* @return 设备日志
|
||||
*/
|
||||
public DeviceStatistic selectCategoryLogCount();
|
||||
public DeviceStatistic selectCategoryLogCount(Device device);
|
||||
|
||||
/**
|
||||
* 查询设备日志列表
|
||||
|
||||
@@ -30,7 +30,7 @@ public interface DeviceMapper
|
||||
*
|
||||
* @return 设备
|
||||
*/
|
||||
public DeviceStatistic selectDeviceProductAlertCount();
|
||||
public DeviceStatistic selectDeviceProductAlertCount(Device device);
|
||||
|
||||
/**
|
||||
* 根据设备编号查询设备
|
||||
|
||||
@@ -12,79 +12,79 @@ import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
public class DeviceStatistic
|
||||
{
|
||||
/** 设备数量 **/
|
||||
private Long deviceCount;
|
||||
private int deviceCount;
|
||||
|
||||
/** 产品数量 **/
|
||||
private Long productCount;
|
||||
private int productCount;
|
||||
|
||||
/** 告警 **/
|
||||
private Long alertCount;
|
||||
private int alertCount;
|
||||
|
||||
/** 属性上报 **/
|
||||
private Long propertyCount;
|
||||
private int propertyCount;
|
||||
|
||||
/** 功能上报 **/
|
||||
private Long functionCount;
|
||||
private int functionCount;
|
||||
|
||||
/** 事件上报 **/
|
||||
private Long eventCount;
|
||||
private int eventCount;
|
||||
|
||||
/** 监测数据上报 **/
|
||||
private Long monitorCount;
|
||||
private int monitorCount;
|
||||
|
||||
public Long getMonitorCount() {
|
||||
public int getMonitorCount() {
|
||||
return monitorCount;
|
||||
}
|
||||
|
||||
public void setMonitorCount(Long monitorCount) {
|
||||
public void setMonitorCount(int monitorCount) {
|
||||
this.monitorCount = monitorCount;
|
||||
}
|
||||
|
||||
public Long getDeviceCount() {
|
||||
public int getDeviceCount() {
|
||||
return deviceCount;
|
||||
}
|
||||
|
||||
public void setDeviceCount(Long deviceCount) {
|
||||
public void setDeviceCount(int deviceCount) {
|
||||
this.deviceCount = deviceCount;
|
||||
}
|
||||
|
||||
public Long getProductCount() {
|
||||
public int getProductCount() {
|
||||
return productCount;
|
||||
}
|
||||
|
||||
public void setProductCount(Long productCount) {
|
||||
public void setProductCount(int productCount) {
|
||||
this.productCount = productCount;
|
||||
}
|
||||
|
||||
public Long getAlertCount() {
|
||||
public int getAlertCount() {
|
||||
return alertCount;
|
||||
}
|
||||
|
||||
public void setAlertCount(Long alertCount) {
|
||||
public void setAlertCount(int alertCount) {
|
||||
this.alertCount = alertCount;
|
||||
}
|
||||
|
||||
public Long getPropertyCount() {
|
||||
public int getPropertyCount() {
|
||||
return propertyCount;
|
||||
}
|
||||
|
||||
public void setPropertyCount(Long propertyCount) {
|
||||
public void setPropertyCount(int propertyCount) {
|
||||
this.propertyCount = propertyCount;
|
||||
}
|
||||
|
||||
public Long getFunctionCount() {
|
||||
public int getFunctionCount() {
|
||||
return functionCount;
|
||||
}
|
||||
|
||||
public void setFunctionCount(Long functionCount) {
|
||||
public void setFunctionCount(int functionCount) {
|
||||
this.functionCount = functionCount;
|
||||
}
|
||||
|
||||
public Long getEventCount() {
|
||||
public int getEventCount() {
|
||||
return eventCount;
|
||||
}
|
||||
|
||||
public void setEventCount(Long eventCount) {
|
||||
public void setEventCount(int eventCount) {
|
||||
this.eventCount = eventCount;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,10 +98,29 @@ public class DeviceServiceImpl implements IDeviceService {
|
||||
*/
|
||||
@Override
|
||||
public DeviceStatistic selectDeviceStatistic() {
|
||||
Device device=new Device();
|
||||
SysUser user = getLoginUser().getUser();
|
||||
List<SysRole> roles=user.getRoles();
|
||||
for(int i=0;i<roles.size();i++){
|
||||
if(roles.get(i).getRoleKey().equals("tenant")){
|
||||
// 租户查看产品下所有设备
|
||||
device.setTenantId(user.getUserId());
|
||||
}else if (roles.get(i).getRoleKey().equals("general")){
|
||||
// 用户查看自己设备
|
||||
device.setUserId(user.getUserId());
|
||||
}
|
||||
}
|
||||
// 获取设备、产品和告警数量
|
||||
DeviceStatistic statistic=deviceMapper.selectDeviceProductAlertCount();
|
||||
DeviceStatistic statistic=deviceMapper.selectDeviceProductAlertCount(device);
|
||||
if(statistic==null){
|
||||
statistic=new DeviceStatistic();
|
||||
return statistic;
|
||||
}
|
||||
// 获取属性、功能和事件
|
||||
DeviceStatistic thingsCount=logService.selectCategoryLogCount();
|
||||
DeviceStatistic thingsCount=logService.selectCategoryLogCount(device);
|
||||
if(thingsCount==null){
|
||||
return statistic;
|
||||
}
|
||||
// 组合属性、功能、事件和监测数据
|
||||
statistic.setPropertyCount(thingsCount.getPropertyCount());
|
||||
statistic.setFunctionCount(thingsCount.getFunctionCount());
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.ruoyi.iot.tdengine.dao;
|
||||
|
||||
import com.ruoyi.iot.domain.Device;
|
||||
import com.ruoyi.iot.domain.DeviceLog;
|
||||
import com.ruoyi.iot.model.DeviceStatistic;
|
||||
import com.ruoyi.iot.model.MonitorModel;
|
||||
@@ -27,7 +28,7 @@ public interface TDDeviceLogDAO {
|
||||
|
||||
int save(@Param("database") String database,@Param("device") DeviceLog deviceLog);
|
||||
|
||||
DeviceStatistic selectCategoryLogCount(@Param("database") String database);
|
||||
DeviceStatistic selectCategoryLogCount(@Param("database") String database, Device device);
|
||||
|
||||
List<DeviceLog> selectSTable(String database,DeviceLog deviceLog);
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.ruoyi.iot.tdengine.service;
|
||||
|
||||
import com.ruoyi.iot.domain.Device;
|
||||
import com.ruoyi.iot.domain.DeviceLog;
|
||||
|
||||
import com.ruoyi.iot.model.DeviceStatistic;
|
||||
@@ -25,7 +26,7 @@ public interface ILogService {
|
||||
int deleteDeviceLogByDeviceId(Long deviceId);
|
||||
|
||||
/** 设备属性、功能、事件总数 **/
|
||||
DeviceStatistic selectCategoryLogCount();
|
||||
DeviceStatistic selectCategoryLogCount(Device device);
|
||||
|
||||
/** 查询物模型日志列表 **/
|
||||
List<DeviceLog> selectDeviceLogList(DeviceLog deviceLog);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.ruoyi.iot.tdengine.service.impl;
|
||||
|
||||
import com.ruoyi.iot.domain.Device;
|
||||
import com.ruoyi.iot.domain.DeviceLog;
|
||||
import com.ruoyi.iot.model.DeviceStatistic;
|
||||
import com.ruoyi.iot.tdengine.service.ILogService;
|
||||
@@ -45,8 +46,8 @@ public class MySqlLogServiceImpl implements ILogService {
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public DeviceStatistic selectCategoryLogCount(){
|
||||
return deviceLogMapper.selectCategoryLogCount();
|
||||
public DeviceStatistic selectCategoryLogCount(Device device){
|
||||
return deviceLogMapper.selectCategoryLogCount(device);
|
||||
}
|
||||
|
||||
/***
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.ruoyi.iot.tdengine.service.impl;
|
||||
|
||||
import com.ruoyi.iot.domain.Device;
|
||||
import com.ruoyi.iot.domain.DeviceLog;
|
||||
import com.ruoyi.iot.model.DeviceStatistic;
|
||||
import com.ruoyi.iot.tdengine.service.ILogService;
|
||||
@@ -61,8 +62,8 @@ public class TdengineLogServiceImpl implements ILogService {
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public DeviceStatistic selectCategoryLogCount(){
|
||||
return tdDeviceLogDAO.selectCategoryLogCount(dbName);
|
||||
public DeviceStatistic selectCategoryLogCount(Device device){
|
||||
return tdDeviceLogDAO.selectCategoryLogCount(dbName,device);
|
||||
}
|
||||
|
||||
/***
|
||||
|
||||
@@ -54,12 +54,40 @@ 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 id="selectCategoryLogCount" parameterType="com.ruoyi.iot.domain.Device" 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
|
||||
(select count(log_id)
|
||||
from iot_device_log
|
||||
<where>
|
||||
<if test="1==1"> and log_type=1</if>
|
||||
<if test="userId != null and userId != 0"> and user_id = #{userId}</if>
|
||||
<if test="tenantId != null and tenantId != 0"> and tenant_id = #{tenantId}</if>
|
||||
</where>
|
||||
) as propertyCount,
|
||||
(select count(log_id)
|
||||
from iot_device_log
|
||||
<where>
|
||||
<if test="1==1"> and log_type=2</if>
|
||||
<if test="userId != null and userId != 0"> and user_id = #{userId}</if>
|
||||
<if test="tenantId != null and tenantId != 0"> and tenant_id = #{tenantId}</if>
|
||||
</where>
|
||||
) as functionCount,
|
||||
(select count(log_id)
|
||||
from iot_device_log
|
||||
<where>
|
||||
<if test="1==1"> and log_type=3</if>
|
||||
<if test="userId != null and userId != 0"> and user_id = #{userId}</if>
|
||||
<if test="tenantId != null and tenantId != 0"> and tenant_id = #{tenantId}</if>
|
||||
</where>
|
||||
) as eventCount,
|
||||
(select count(log_id)
|
||||
from iot_device_log
|
||||
<where>
|
||||
<if test="1==1"> and log_type=1 and is_monitor=1</if>
|
||||
<if test="userId != null and userId != 0"> and user_id = #{userId}</if>
|
||||
<if test="tenantId != null and tenantId != 0"> and tenant_id = #{tenantId}</if>
|
||||
</where>
|
||||
) as monitorCount
|
||||
from iot_device_log
|
||||
limit 1
|
||||
</select>
|
||||
|
||||
@@ -214,11 +214,37 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
where device_id = #{deviceId}
|
||||
</select>
|
||||
|
||||
<select id="selectDeviceProductAlertCount" resultType="com.ruoyi.iot.model.DeviceStatistic">
|
||||
<select id="selectDeviceProductAlertCount" parameterType="com.ruoyi.iot.domain.Device" 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
|
||||
(
|
||||
<!--普通用户查询设备中的产品数量-->
|
||||
<if test="userId != null and userId != 0">
|
||||
select count(product_id)
|
||||
from iot_device
|
||||
where user_id = #{userId}
|
||||
group by product_id
|
||||
</if>
|
||||
<!--管理员和租户直接查询产品的数量-->
|
||||
<if test="userId == null || userId == 0">
|
||||
select count(product_id)
|
||||
from iot_product
|
||||
<where>
|
||||
<if test="tenantId != null and tenantId != 0"> and tenant_id = #{tenantId} </if>
|
||||
</where>
|
||||
</if>
|
||||
) as productCount,
|
||||
(select count(alert_log_id)
|
||||
from iot_alert_log
|
||||
<where>
|
||||
<if test="userId != null and userId != 0"> and user_id = #{userId}</if>
|
||||
<if test="tenantId != null and tenantId != 0"> and tenant_id = #{tenantId}</if>
|
||||
</where>
|
||||
) as alertCount
|
||||
from iot_device
|
||||
<where>
|
||||
<if test="userId != null and userId != 0"> and user_id = #{userId}</if>
|
||||
<if test="tenantId != null and tenantId != 0"> and tenant_id = #{tenantId}</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="selectProductAuthenticate" parameterType="com.ruoyi.iot.model.AuthenticateInputModel" resultMap="DeviceAuthenticateResult">
|
||||
|
||||
@@ -78,10 +78,38 @@
|
||||
|
||||
<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
|
||||
(select count(log_id)
|
||||
from iot_device_log
|
||||
<where>
|
||||
<if test="1==1"> and log_type=1</if>
|
||||
<if test="userId != null and userId != 0"> and user_id = #{userId}</if>
|
||||
<if test="tenantId != null and tenantId != 0"> and tenant_id = #{tenantId}</if>
|
||||
</where>
|
||||
) as propertyCount,
|
||||
(select count(log_id)
|
||||
from iot_device_log
|
||||
<where>
|
||||
<if test="1==1"> and log_type=2</if>
|
||||
<if test="userId != null and userId != 0"> and user_id = #{userId}</if>
|
||||
<if test="tenantId != null and tenantId != 0"> and tenant_id = #{tenantId}</if>
|
||||
</where>
|
||||
) as functionCount,
|
||||
(select count(log_id)
|
||||
from iot_device_log
|
||||
<where>
|
||||
<if test="1==1"> and log_type=3</if>
|
||||
<if test="userId != null and userId != 0"> and user_id = #{userId}</if>
|
||||
<if test="tenantId != null and tenantId != 0"> and tenant_id = #{tenantId}</if>
|
||||
</where>
|
||||
) as eventCount,
|
||||
(select count(log_id)
|
||||
from iot_device_log
|
||||
<where>
|
||||
<if test="1==1"> and log_type=1 and is_monitor=1</if>
|
||||
<if test="userId != null and userId != 0"> and user_id = #{userId}</if>
|
||||
<if test="tenantId != null and tenantId != 0"> and tenant_id = #{tenantId}</if>
|
||||
</where>
|
||||
) as monitorCount
|
||||
from ${database}.device_log
|
||||
limit 1
|
||||
</select>
|
||||
|
||||
Reference in New Issue
Block a user