mirror of
https://gitee.com/beecue/fastbee.git
synced 2025-12-18 00:45:55 +08:00
设备日志改进
This commit is contained in:
@@ -47,9 +47,13 @@ public class DeviceLog extends BaseEntity
|
||||
private String identity;
|
||||
|
||||
/** 是否监测数据(1=是,0=否) */
|
||||
@Excel(name = "是否监测数据", readConverterExp = "1==是,0=否")
|
||||
@Excel(name = "是否监测数据", readConverterExp = "1=是,0=否")
|
||||
private Integer isMonitor;
|
||||
|
||||
/** 模式 */
|
||||
@Excel(name = "模式", readConverterExp = "1=影子模式,2=在线模式,3=其他")
|
||||
private Integer mode;
|
||||
|
||||
/** 用户ID */
|
||||
@Excel(name = "用户ID")
|
||||
private Long userId;
|
||||
@@ -66,6 +70,14 @@ public class DeviceLog extends BaseEntity
|
||||
@Excel(name = "租户名称")
|
||||
private String tenantName;
|
||||
|
||||
public Integer getMode() {
|
||||
return mode;
|
||||
}
|
||||
|
||||
public void setMode(Integer mode) {
|
||||
this.mode = mode;
|
||||
}
|
||||
|
||||
public Long getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.ruoyi.iot.mqtt;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.ruoyi.common.utils.DateUtils;
|
||||
import com.ruoyi.iot.domain.Device;
|
||||
import com.ruoyi.iot.domain.DeviceLog;
|
||||
import com.ruoyi.iot.model.NtpModel;
|
||||
@@ -203,6 +204,9 @@ public class EmqxService {
|
||||
deviceLog.setUserName(device.getUserName());
|
||||
deviceLog.setTenantId(device.getTenantId());
|
||||
deviceLog.setTenantName(device.getTenantName());
|
||||
deviceLog.setCreateTime(DateUtils.getNowDate());
|
||||
// 1=影子模式,2=在线模式,3=其他
|
||||
deviceLog.setMode(2);
|
||||
logService.saveDeviceLog(deviceLog);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -71,7 +71,6 @@ public class DeviceLogServiceImpl implements IDeviceLogService
|
||||
@Override
|
||||
public int insertDeviceLog(DeviceLog deviceLog)
|
||||
{
|
||||
deviceLog.setCreateTime(DateUtils.getNowDate());
|
||||
return logService.saveDeviceLog(deviceLog);
|
||||
}
|
||||
|
||||
|
||||
@@ -235,14 +235,17 @@ public class DeviceServiceImpl implements IDeviceService {
|
||||
deviceLog.setLogValue(input.getThingsModelValueRemarkItem().get(i).getValue());
|
||||
deviceLog.setRemark(input.getThingsModelValueRemarkItem().get(i).getRemark());
|
||||
deviceLog.setIdentity(input.getThingsModelValueRemarkItem().get(i).getId());
|
||||
deviceLog.setCreateTime(DateUtils.getNowDate());
|
||||
deviceLog.setIsMonitor(valueList.get(k).getIsMonitor());
|
||||
deviceLog.setLogType(type);
|
||||
deviceLog.setUserId(deviceThings.getUserId());
|
||||
deviceLog.setUserName(deviceThings.getUserName());
|
||||
deviceLog.setTenantId(deviceThings.getTenantId());
|
||||
deviceLog.setTenantName(deviceThings.getTenantName());
|
||||
deviceLog.setCreateTime(DateUtils.getNowDate());
|
||||
// 1=影子模式,2=在线模式,3=其他
|
||||
deviceLog.setMode(isShadow?1:2);
|
||||
logService.saveDeviceLog(deviceLog);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -709,7 +712,7 @@ public class DeviceServiceImpl implements IDeviceService {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param device 设备
|
||||
* @param device 设备状态和定位更新
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
@@ -738,6 +741,9 @@ public class DeviceServiceImpl implements IDeviceService {
|
||||
deviceLog.setUserName(device.getUserName());
|
||||
deviceLog.setTenantId(device.getTenantId());
|
||||
deviceLog.setTenantName(device.getTenantName());
|
||||
deviceLog.setCreateTime(DateUtils.getNowDate());
|
||||
// 1=影子模式,2=在线模式,3=其他
|
||||
deviceLog.setMode(3);
|
||||
if(device.getStatus()==3){
|
||||
deviceLog.setLogValue("1");
|
||||
deviceLog.setRemark("设备上线");
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.ruoyi.iot.tdengine.service.impl;
|
||||
|
||||
import com.ruoyi.common.utils.DateUtils;
|
||||
import com.ruoyi.iot.domain.Device;
|
||||
import com.ruoyi.iot.domain.DeviceLog;
|
||||
import com.ruoyi.iot.model.DeviceStatistic;
|
||||
|
||||
@@ -19,6 +19,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<result property="identity" column="identity" />
|
||||
<result property="createBy" column="create_by" />
|
||||
<result property="isMonitor" column="is_monitor" />
|
||||
<result property="mode" column="mode" />
|
||||
<result property="createTime" column="create_time" />
|
||||
<result property="userId" column="user_id" />
|
||||
<result property="userName" column="user_name" />
|
||||
@@ -28,7 +29,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectDeviceLogVo">
|
||||
select log_id, log_type, log_value, device_id, device_name,serial_number, identity, create_by, is_monitor, user_id, user_name, tenant_id, tenant_name, create_time, remark from iot_device_log
|
||||
select log_id, log_type, log_value, device_id, device_name,serial_number, identity, create_by, is_monitor,mode, user_id, user_name, tenant_id, tenant_name, create_time, remark from iot_device_log
|
||||
</sql>
|
||||
|
||||
<select id="selectMonitorList" parameterType="com.ruoyi.iot.domain.DeviceLog" resultMap="MonitorResult">
|
||||
@@ -92,7 +93,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="tenantId != null and tenantId != 0"> and tenant_id = #{tenantId}</if>
|
||||
</where>
|
||||
) as monitorCount
|
||||
from iot_device_log
|
||||
limit 1
|
||||
</select>
|
||||
|
||||
@@ -107,6 +107,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="identity != null">identity,</if>
|
||||
<if test="createBy != null">create_by,</if>
|
||||
<if test="isMonitor != null">is_monitor,</if>
|
||||
<if test="mode != null">mode,</if>
|
||||
<if test="createTime != null">create_time,</if>
|
||||
<if test="remark != null">remark,</if>
|
||||
<if test="userId != null">user_id,</if>
|
||||
@@ -123,6 +124,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="identity != null">#{identity},</if>
|
||||
<if test="createBy != null">#{createBy},</if>
|
||||
<if test="isMonitor != null">#{isMonitor},</if>
|
||||
<if test="mode != null">#{mode},</if>
|
||||
<if test="createTime != null">#{createTime},</if>
|
||||
<if test="remark != null">#{remark},</if>
|
||||
<if test="userId != null">#{userId},</if>
|
||||
@@ -143,6 +145,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="identity != null">identity = #{identity},</if>
|
||||
<if test="createBy != null">create_by = #{createBy},</if>
|
||||
<if test="isMonitor != null">is_monitor = #{isMonitor},</if>
|
||||
<if test="mode != null">mode = #{mode},</if>
|
||||
<if test="createTime != null">create_time = #{createTime},</if>
|
||||
<if test="remark != null">remark = #{remark},</if>
|
||||
<if test="userId != null">user_id = #{userId},</if>
|
||||
|
||||
@@ -225,36 +225,42 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
</select>
|
||||
|
||||
<select id="selectDeviceProductAlertCount" parameterType="com.ruoyi.iot.domain.Device" resultType="com.ruoyi.iot.model.DeviceStatistic">
|
||||
SELECT count(device_id) as deviceCount,
|
||||
(
|
||||
<!--普通用户查询设备中的产品数量-->
|
||||
<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 count(distinct d.device_id,d.user_id)
|
||||
from iot_device d
|
||||
inner join iot_device_user u on u.device_id = d.device_id
|
||||
<where>
|
||||
<if test="userId != null and userId != 0"> and u.user_id = #{userId}</if>
|
||||
<if test="tenantId != null and tenantId != 0"> and d.tenant_id = #{tenantId}</if>
|
||||
</where>
|
||||
) as deviceCount,
|
||||
|
||||
(
|
||||
<!--普通用户查询设备中的产品数量-->
|
||||
<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
|
||||
</select>
|
||||
|
||||
<select id="selectProductAuthenticate" parameterType="com.ruoyi.iot.model.AuthenticateInputModel" resultMap="DeviceAuthenticateResult">
|
||||
|
||||
Reference in New Issue
Block a user