diff --git a/springboot/wumei-iot/src/main/java/com/ruoyi/iot/mapper/DeviceLogMapper.java b/springboot/wumei-iot/src/main/java/com/ruoyi/iot/mapper/DeviceLogMapper.java index 6b72e720..06a44482 100644 --- a/springboot/wumei-iot/src/main/java/com/ruoyi/iot/mapper/DeviceLogMapper.java +++ b/springboot/wumei-iot/src/main/java/com/ruoyi/iot/mapper/DeviceLogMapper.java @@ -84,11 +84,10 @@ public interface DeviceLogMapper /** * 根据设备Ids批量删除设备日志 * - * @param deviceId 需要删除的数据设备Id + * @param deviceNumber 需要删除的数据设备Id * @return 结果 */ - public int deleteDeviceLogByDeviceId(Long deviceId); + public int deleteDeviceLogByDeviceNumber(String deviceNumber); -// List selectLogList(Long deviceId,String serialNumber,Long isMonitor,Long logType, Date beginDate, Date endDate); } diff --git a/springboot/wumei-iot/src/main/java/com/ruoyi/iot/model/DeviceStatistic.java b/springboot/wumei-iot/src/main/java/com/ruoyi/iot/model/DeviceStatistic.java index c957babb..943f000a 100644 --- a/springboot/wumei-iot/src/main/java/com/ruoyi/iot/model/DeviceStatistic.java +++ b/springboot/wumei-iot/src/main/java/com/ruoyi/iot/model/DeviceStatistic.java @@ -18,25 +18,25 @@ public class DeviceStatistic private int productCount; /** 告警 **/ - private int alertCount; + private long alertCount; /** 属性上报 **/ - private int propertyCount; + private long propertyCount; /** 功能上报 **/ - private int functionCount; + private long functionCount; /** 事件上报 **/ - private int eventCount; + private long eventCount; /** 监测数据上报 **/ - private int monitorCount; + private long monitorCount; - public int getMonitorCount() { + public long getMonitorCount() { return monitorCount; } - public void setMonitorCount(int monitorCount) { + public void setMonitorCount(long monitorCount) { this.monitorCount = monitorCount; } @@ -56,35 +56,35 @@ public class DeviceStatistic this.productCount = productCount; } - public int getAlertCount() { + public long getAlertCount() { return alertCount; } - public void setAlertCount(int alertCount) { + public void setAlertCount(long alertCount) { this.alertCount = alertCount; } - public int getPropertyCount() { + public long getPropertyCount() { return propertyCount; } - public void setPropertyCount(int propertyCount) { + public void setPropertyCount(long propertyCount) { this.propertyCount = propertyCount; } - public int getFunctionCount() { + public long getFunctionCount() { return functionCount; } - public void setFunctionCount(int functionCount) { + public void setFunctionCount(long functionCount) { this.functionCount = functionCount; } - public int getEventCount() { + public long getEventCount() { return eventCount; } - public void setEventCount(int eventCount) { + public void setEventCount(long eventCount) { this.eventCount = eventCount; } } diff --git a/springboot/wumei-iot/src/main/java/com/ruoyi/iot/service/IDeviceLogService.java b/springboot/wumei-iot/src/main/java/com/ruoyi/iot/service/IDeviceLogService.java index 6e126f5c..237e2a21 100644 --- a/springboot/wumei-iot/src/main/java/com/ruoyi/iot/service/IDeviceLogService.java +++ b/springboot/wumei-iot/src/main/java/com/ruoyi/iot/service/IDeviceLogService.java @@ -70,10 +70,10 @@ public interface IDeviceLogService public int deleteDeviceLogByLogId(Long logId); /** - * 根据设备ID批量删除设备日志 + * 根据设备编号批量删除设备日志 * - * @param deviceId 需要删除的设备日志ID + * @param deviceNumber 需要删除的设备日志ID * @return 结果 */ - public int deleteDeviceLogByDeviceId(Long deviceId); + public int deleteDeviceLogByDeviceNumber(String deviceNumber); } diff --git a/springboot/wumei-iot/src/main/java/com/ruoyi/iot/service/impl/DeviceLogServiceImpl.java b/springboot/wumei-iot/src/main/java/com/ruoyi/iot/service/impl/DeviceLogServiceImpl.java index ec0eeac3..5b3dc5a3 100644 --- a/springboot/wumei-iot/src/main/java/com/ruoyi/iot/service/impl/DeviceLogServiceImpl.java +++ b/springboot/wumei-iot/src/main/java/com/ruoyi/iot/service/impl/DeviceLogServiceImpl.java @@ -101,13 +101,13 @@ public class DeviceLogServiceImpl implements IDeviceLogService /** * 根据设备Ids批量删除设备日志 * - * @param deviceId 需要删除数据的设备Ids + * @param deviceNumber 需要删除数据的设备Ids * @return 结果 */ @Override - public int deleteDeviceLogByDeviceId(Long deviceId) + public int deleteDeviceLogByDeviceNumber(String deviceNumber) { - return deviceLogMapper.deleteDeviceLogByDeviceId(deviceId); + return deviceLogMapper.deleteDeviceLogByDeviceNumber(deviceNumber); } /** diff --git a/springboot/wumei-iot/src/main/java/com/ruoyi/iot/service/impl/DeviceServiceImpl.java b/springboot/wumei-iot/src/main/java/com/ruoyi/iot/service/impl/DeviceServiceImpl.java index 06d2196d..2bd7e6b0 100644 --- a/springboot/wumei-iot/src/main/java/com/ruoyi/iot/service/impl/DeviceServiceImpl.java +++ b/springboot/wumei-iot/src/main/java/com/ruoyi/iot/service/impl/DeviceServiceImpl.java @@ -234,7 +234,7 @@ 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.setIsMonitor(valueList.get(k).getIsMonitor()); + deviceLog.setIsMonitor(valueList.get(k).getIsMonitor()==null ? 0:valueList.get(k).getIsMonitor()); deviceLog.setLogType(type); deviceLog.setUserId(deviceThings.getUserId()); deviceLog.setUserName(deviceThings.getUserName()); @@ -244,7 +244,6 @@ public class DeviceServiceImpl implements IDeviceService { // 1=影子模式,2=在线模式,3=其他 deviceLog.setMode(isShadow?1:2); logService.saveDeviceLog(deviceLog); - break; } } @@ -885,7 +884,7 @@ public class DeviceServiceImpl implements IDeviceService { // 删除定时任务 deviceJobService.deleteJobByDeviceIds(new Long[]{deviceId}); // 批量删除设备日志 - logService.deleteDeviceLogByDeviceId(deviceId); + logService.deleteDeviceLogByDeviceNumber(device.getSerialNumber()); // TODO 删除设备告警记录 // 删除设备 diff --git a/springboot/wumei-iot/src/main/java/com/ruoyi/iot/tdengine/dao/TDDeviceLogDAO.java b/springboot/wumei-iot/src/main/java/com/ruoyi/iot/tdengine/dao/TDDeviceLogDAO.java index d00d0082..585e164c 100644 --- a/springboot/wumei-iot/src/main/java/com/ruoyi/iot/tdengine/dao/TDDeviceLogDAO.java +++ b/springboot/wumei-iot/src/main/java/com/ruoyi/iot/tdengine/dao/TDDeviceLogDAO.java @@ -19,28 +19,55 @@ import java.util.List; @Repository public interface TDDeviceLogDAO { - + /*** + * 创建数据库 + */ int createDB( String database); + /*** + * 创建超级表 + */ int createSTable(String database); - int createTable(String database,String deviceId); + /*** + * 新增设备日志 + */ int save(@Param("database") String database,@Param("device") DeviceLog deviceLog); - DeviceStatistic selectCategoryLogCount(@Param("database") String database, Device device); + /*** + * 设备属性数据总数 + */ + Long selectPropertyLogCount(@Param("database") String database,@Param("device") Device device); - List selectSTable(String database,DeviceLog deviceLog); + /*** + * 设备功能数据总数 + */ + Long selectFunctionLogCount(@Param("database") String database,@Param("device") Device device); - int delete(String dbName, DeviceLog deviceLog); + /*** + * 设备事件数据总数 + */ + Long selectEventLogCount(@Param("database") String database,@Param("device") Device device); - int deleteDeviceLogByDeviceId(String dbName,Long deviceId); - - // List selectLogListByPage(String dbName, Integer pageSize, Integer pageNum, String deviceNum, Date beginDate, Date endDate); - - List selectLogList(String dbName, Long deviceId, String serialNumber, Long isMonitor, Long logType, Date beginDate, Date endDate); + /*** + * 设备监测数据总数 + */ + Long selectMonitorLogCount(@Param("database") String database,@Param("device") Device device); + /*** + * 监测数据列表 + */ List selectMonitorList(@Param("database") String database, @Param("device") DeviceLog deviceLog); + /*** + * 日志列表 + */ List selectDeviceLogList(@Param("database") String database,@Param("device") DeviceLog deviceLog); + + /*** + * 根据设备ID删除设备日志 + */ + int deleteDeviceLogByDeviceNumber(@Param("database")String dbName,@Param("serialNumber") String serialNumber); + } diff --git a/springboot/wumei-iot/src/main/java/com/ruoyi/iot/tdengine/init/ApplicationStarted.java b/springboot/wumei-iot/src/main/java/com/ruoyi/iot/tdengine/init/ApplicationStarted.java index 59cce2f3..3e4691b0 100644 --- a/springboot/wumei-iot/src/main/java/com/ruoyi/iot/tdengine/init/ApplicationStarted.java +++ b/springboot/wumei-iot/src/main/java/com/ruoyi/iot/tdengine/init/ApplicationStarted.java @@ -70,10 +70,9 @@ public class ApplicationStarted implements ApplicationRunner { createDatabase(); //创建数据库表 deviceLogMapper.createSTable(dbName); - System.out.println("完成超级表的创建"); LOGGER.info("完成超级表的创建"); } catch (Exception e) { - LOGGER.info("错误",e.getMessage()); + LOGGER.error("错误",e.getMessage()); e.printStackTrace(); } diff --git a/springboot/wumei-iot/src/main/java/com/ruoyi/iot/tdengine/service/ILogService.java b/springboot/wumei-iot/src/main/java/com/ruoyi/iot/tdengine/service/ILogService.java index 065b7210..0155ae9a 100644 --- a/springboot/wumei-iot/src/main/java/com/ruoyi/iot/tdengine/service/ILogService.java +++ b/springboot/wumei-iot/src/main/java/com/ruoyi/iot/tdengine/service/ILogService.java @@ -22,8 +22,8 @@ public interface ILogService { /** 保存设备日志 **/ int saveDeviceLog(DeviceLog deviceLog); - /** 根据设备ID删除设备日志 **/ - int deleteDeviceLogByDeviceId(Long deviceId); + /** 根据设备编号删除设备日志 **/ + int deleteDeviceLogByDeviceNumber(String deviceNumber); /** 设备属性、功能、事件总数 **/ DeviceStatistic selectCategoryLogCount(Device device); diff --git a/springboot/wumei-iot/src/main/java/com/ruoyi/iot/tdengine/service/impl/MySqlLogServiceImpl.java b/springboot/wumei-iot/src/main/java/com/ruoyi/iot/tdengine/service/impl/MySqlLogServiceImpl.java index 9d50b20a..2417e13b 100644 --- a/springboot/wumei-iot/src/main/java/com/ruoyi/iot/tdengine/service/impl/MySqlLogServiceImpl.java +++ b/springboot/wumei-iot/src/main/java/com/ruoyi/iot/tdengine/service/impl/MySqlLogServiceImpl.java @@ -38,8 +38,8 @@ public class MySqlLogServiceImpl implements ILogService { * @return */ @Override - public int deleteDeviceLogByDeviceId(Long deviceId) { - return deviceLogMapper.deleteDeviceLogByDeviceId(deviceId); + public int deleteDeviceLogByDeviceNumber(String deviceNumber) { + return deviceLogMapper.deleteDeviceLogByDeviceNumber(deviceNumber); } /*** diff --git a/springboot/wumei-iot/src/main/java/com/ruoyi/iot/tdengine/service/impl/TdengineLogServiceImpl.java b/springboot/wumei-iot/src/main/java/com/ruoyi/iot/tdengine/service/impl/TdengineLogServiceImpl.java index 4f30be32..3b248d0a 100644 --- a/springboot/wumei-iot/src/main/java/com/ruoyi/iot/tdengine/service/impl/TdengineLogServiceImpl.java +++ b/springboot/wumei-iot/src/main/java/com/ruoyi/iot/tdengine/service/impl/TdengineLogServiceImpl.java @@ -48,22 +48,22 @@ public class TdengineLogServiceImpl implements ILogService { return tdDeviceLogDAO.save(dbName,deviceLog); } - /*** - * 根据设备ID删除设备日志 - * @return - */ - @Override - public int deleteDeviceLogByDeviceId(Long deviceId) { - return tdDeviceLogDAO.deleteDeviceLogByDeviceId(dbName,deviceId); - } - /*** * 设备属性、功能、事件和监测数据总数 * @return */ @Override public DeviceStatistic selectCategoryLogCount(Device device){ - return tdDeviceLogDAO.selectCategoryLogCount(dbName,device); + DeviceStatistic statistic=new DeviceStatistic(); + Long property=tdDeviceLogDAO.selectPropertyLogCount(dbName,device); + Long function=tdDeviceLogDAO.selectFunctionLogCount(dbName,device); + Long event=tdDeviceLogDAO.selectEventLogCount(dbName,device); + Long monitor=tdDeviceLogDAO.selectMonitorLogCount(dbName,device); + statistic.setPropertyCount(property==null?0:property); + statistic.setFunctionCount(function==null?0:function); + statistic.setEventCount(event==null?0:event); + statistic.setMonitorCount(monitor==null?0:monitor); + return statistic; } /*** @@ -86,4 +86,13 @@ public class TdengineLogServiceImpl implements ILogService { } return tdDeviceLogDAO.selectMonitorList(dbName,deviceLog); } + + /*** + * 根据设备ID删除设备日志 + * @return + */ + @Override + public int deleteDeviceLogByDeviceNumber(String deviceNumber) { + return tdDeviceLogDAO.deleteDeviceLogByDeviceNumber(dbName,deviceNumber); + } } diff --git a/springboot/wumei-iot/src/main/resources/mapper/iot/DeviceLogMapper.xml b/springboot/wumei-iot/src/main/resources/mapper/iot/DeviceLogMapper.xml index b988f7d1..8622d2ef 100644 --- a/springboot/wumei-iot/src/main/resources/mapper/iot/DeviceLogMapper.xml +++ b/springboot/wumei-iot/src/main/resources/mapper/iot/DeviceLogMapper.xml @@ -167,7 +167,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - - delete from iot_device_log where device_id = #{deviceId} + + delete from iot_device_log where serial_number = #{deviceNumber} \ No newline at end of file diff --git a/springboot/wumei-iot/src/main/resources/mapper/tdengine/TDDeviceLogMapper.xml b/springboot/wumei-iot/src/main/resources/mapper/tdengine/TDDeviceLogMapper.xml index 02252b6a..50aa1186 100644 --- a/springboot/wumei-iot/src/main/resources/mapper/tdengine/TDDeviceLogMapper.xml +++ b/springboot/wumei-iot/src/main/resources/mapper/tdengine/TDDeviceLogMapper.xml @@ -4,36 +4,26 @@ "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> - - - - - - - - - - - - - - - + - + - + + + + + @@ -43,124 +33,93 @@ create STABLE if not exists ${database}.device_log - ( - ts timestamp, - log_id BIGINT, - log_type TINYINT, - `identity` BINARY(100), + (ts timestamp, `log_value` BINARY(100), is_monitor TINYINT, - create_by BINARY(100), - create_time timestamp, - remark BINARY(500) + log_type TINYINT, + `identity` BINARY(100), + mode TINYINT, + remark BINARY(500)) - ) TAGS( device_id BIGINT, - device_name BINARY(100), - serial_number BINARY(50)); + serial_number BINARY(50), + user_id BIGINT, + tenant_Id BIGINT, + user_name BINARY(100), + tenant_name BINARY(100), + device_name BINARY(100)); - - create TABLE if not exists ${database}.${tableName} - USING ${database}.device_${deviceId} TAGS(log_type,is_monitor,create_by,create_time,remark) - (ts2 timestamp, - log_type BINARY(100) - ); - - - - - - - INSERT INTO ${database}.device_${device.serialNumber} USING device_log - TAGS (#{device.deviceId},#{device.deviceName},#{device.serialNumber}) - VALUES (now, #{device.logId}, #{device.logType},#{device.identity},#{device.logValue},#{device.isMonitor},#{device.createBy},now,#{device.remark} ); + INSERT INTO ${database}.${device.serialNumber} USING device_log + TAGS (#{device.deviceId}, + #{device.serialNumber}, + #{device.userId}, + #{device.tenantId}, + #{device.userName}, + #{device.tenantName}, + #{device.deviceName}) + VALUES (now, + #{device.logValue}, + #{device.isMonitor}, + #{device.logType}, + #{device.identity}, + #{device.mode}, + #{device.remark}); - - delete from ${database}.device_${device.serialNumber} - - log_id = #{logId} - device_id = #{deviceId} - serial_number = #{serialNumber} - + + DROP TABLE IF EXISTS ${database}.${serialNumber}; - - delete from ${database}.device_${device.serialNumber} + - - + select count(mode) as functionCount + from ${database}.device_log - and device_id = #{deviceId} - and serial_number = #{serialNumber} - and is_monitor = #{isMonitor} - and log_type = #{logType} - - and create_time <= #{beginDate} - and create_time >= #{endDate} - + and log_type=2 + and user_id = #{device.userId} + and tenant_id = #{device.tenantId} + + + + + + select * from ${database}.device_log - is_monitor !=1 + is_monitor!=1 and device_id = #{device.deviceId} and log_type = #{device.logType} and identity like #{device.identity}