mirror of
https://gitee.com/beecue/fastbee.git
synced 2025-12-18 17:05:55 +08:00
设备解绑功能完善
This commit is contained in:
@@ -187,7 +187,7 @@ public class DeviceController extends BaseController
|
||||
@DeleteMapping("/{deviceIds}")
|
||||
@ApiOperation("批量删除设备")
|
||||
public AjaxResult remove(@PathVariable Long[] deviceIds) throws SchedulerException {
|
||||
return toAjax(deviceService.deleteDeviceByDeviceIds(deviceIds));
|
||||
return toAjax(deviceService.deleteDeviceByDeviceId(deviceIds[0]));
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermi('iot:device:edit')")
|
||||
|
||||
@@ -83,10 +83,10 @@ public interface DeviceLogMapper
|
||||
/**
|
||||
* 根据设备Ids批量删除设备日志
|
||||
*
|
||||
* @param deviceIds 需要删除的数据设备Ids
|
||||
* @param deviceId 需要删除的数据设备Id
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteDeviceLogByDeviceIds(Long[] deviceIds);
|
||||
public int deleteDeviceLogByDeviceId(Long deviceId);
|
||||
|
||||
|
||||
// List<DeviceLog> selectLogList(Long deviceId,String serialNumber,Long isMonitor,Long logType, Date beginDate, Date endDate);
|
||||
|
||||
@@ -180,7 +180,7 @@ public interface DeviceMapper
|
||||
* @param deviceIds
|
||||
* @return
|
||||
*/
|
||||
public int deleteDeviceGroupByDeviceIds(Long[] deviceIds);
|
||||
public int deleteDeviceGroupByDeviceId(UserIdAndDeviceIdModel userIdAndDeviceIdModel);
|
||||
|
||||
/**
|
||||
* 重置设备状态
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.ruoyi.iot.mapper;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.iot.domain.DeviceUser;
|
||||
import com.ruoyi.iot.model.UserIdAndDeviceIdModel;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@@ -49,10 +50,10 @@ public interface DeviceUserMapper
|
||||
/**
|
||||
* 删除设备用户
|
||||
*
|
||||
* @param deviceId 设备用户主键
|
||||
* @param UserIdAndDeviceIdModel 用户ID和设备ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteDeviceUserByDeviceId(Long deviceId);
|
||||
public int deleteDeviceUserByDeviceId(UserIdAndDeviceIdModel userIdAndDeviceIdModel);
|
||||
|
||||
/**
|
||||
* 批量删除设备用户
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.ruoyi.iot.model;
|
||||
|
||||
/**
|
||||
* 用户ID和设备ID模型
|
||||
*
|
||||
* @author kerwincui
|
||||
* @date 2021-12-16
|
||||
*/
|
||||
public class UserIdAndDeviceIdModel
|
||||
{
|
||||
private Long userId;
|
||||
|
||||
private Long deviceId;
|
||||
|
||||
public UserIdAndDeviceIdModel(Long userId,Long deviceId){
|
||||
this.userId=userId;
|
||||
this.deviceId=deviceId;
|
||||
}
|
||||
|
||||
public Long getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setUserId(Long userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public Long getDeviceId() {
|
||||
return deviceId;
|
||||
}
|
||||
|
||||
public void setDeviceId(Long deviceId) {
|
||||
this.deviceId = deviceId;
|
||||
}
|
||||
}
|
||||
@@ -70,10 +70,10 @@ public interface IDeviceLogService
|
||||
public int deleteDeviceLogByLogId(Long logId);
|
||||
|
||||
/**
|
||||
* 根据设备IDs批量删除设备日志
|
||||
* 根据设备ID批量删除设备日志
|
||||
*
|
||||
* @param deviceIds 需要删除的设备日志IDs
|
||||
* @param deviceId 需要删除的设备日志ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteDeviceLogByDeviceIds(Long[] deviceIds);
|
||||
public int deleteDeviceLogByDeviceId(Long deviceId);
|
||||
}
|
||||
|
||||
@@ -155,20 +155,13 @@ public interface IDeviceService
|
||||
public int reportDevice(Device device);
|
||||
|
||||
/**
|
||||
* 批量删除设备
|
||||
* 删除设备
|
||||
*
|
||||
* @param deviceIds 需要删除的设备主键集合
|
||||
* @param deviceId 需要删除的设备主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteDeviceByDeviceIds(Long[] deviceIds) throws SchedulerException;
|
||||
public int deleteDeviceByDeviceId(Long deviceId) throws SchedulerException;
|
||||
|
||||
/**
|
||||
* 删除设备信息
|
||||
*
|
||||
* @param deviceId 设备主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteDeviceByDeviceId(Long deviceId);
|
||||
|
||||
/**
|
||||
* 生成设备唯一编号
|
||||
|
||||
@@ -102,13 +102,13 @@ public class DeviceLogServiceImpl implements IDeviceLogService
|
||||
/**
|
||||
* 根据设备Ids批量删除设备日志
|
||||
*
|
||||
* @param deviceIds 需要删除数据的设备Ids
|
||||
* @param deviceId 需要删除数据的设备Ids
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteDeviceLogByDeviceIds(Long[] deviceIds)
|
||||
public int deleteDeviceLogByDeviceId(Long deviceId)
|
||||
{
|
||||
return deviceLogMapper.deleteDeviceLogByDeviceIds(deviceIds);
|
||||
return deviceLogMapper.deleteDeviceLogByDeviceId(deviceId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -796,34 +796,44 @@ public class DeviceServiceImpl implements IDeviceService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除设备
|
||||
* @param deviceIds 需要删除的设备主键
|
||||
* 删除设备
|
||||
* @param deviceId 需要删除的设备主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public int deleteDeviceByDeviceIds(Long[] deviceIds) throws SchedulerException {
|
||||
// 删除设备分组
|
||||
deviceMapper.deleteDeviceGroupByDeviceIds(deviceIds);
|
||||
// TODO 删除设备日志 td里面删除
|
||||
deviceLogMapper.deleteDeviceLogByDeviceIds(deviceIds);
|
||||
// TODO 删除设备告警记录
|
||||
public int deleteDeviceByDeviceId(Long deviceId) throws SchedulerException {
|
||||
SysUser user=getLoginUser().getUser();
|
||||
// 是否为普通用户,普通用户如果不是设备所有者,只能删除设备用户和用户自己的设备关联分组信息
|
||||
boolean isGeneralUser=false;
|
||||
List<SysRole> roles=user.getRoles();
|
||||
for(int i=0;i<roles.size();i++){
|
||||
if (roles.get(i).getRoleKey().equals("general")){
|
||||
isGeneralUser=true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 删除定时任务
|
||||
deviceJobService.deleteJobByDeviceIds(deviceIds);
|
||||
// 删除设备用户
|
||||
deviceUserMapper.deleteDeviceUserByDeviceIds(deviceIds);
|
||||
// 删除设备
|
||||
return deviceMapper.deleteDeviceByDeviceIds(deviceIds);
|
||||
}
|
||||
Device device=deviceMapper.selectDeviceByDeviceId(deviceId);
|
||||
if(isGeneralUser && device.getUserId().longValue()!=user.getUserId()){
|
||||
// 删除用户的设备用户信息。 普通用户,且不是设备所有者。
|
||||
deviceUserMapper.deleteDeviceUserByDeviceId(new UserIdAndDeviceIdModel(user.getUserId(),deviceId));
|
||||
// 删除用户的设备分组
|
||||
deviceMapper.deleteDeviceGroupByDeviceId(new UserIdAndDeviceIdModel(user.getUserId(),deviceId));
|
||||
}else{
|
||||
// 删除设备用户。 租户、管理员和设备所有者
|
||||
deviceUserMapper.deleteDeviceUserByDeviceId(new UserIdAndDeviceIdModel(null,deviceId));
|
||||
// 删除设备分组。
|
||||
deviceMapper.deleteDeviceGroupByDeviceId(new UserIdAndDeviceIdModel(null,deviceId));
|
||||
// 删除定时任务
|
||||
deviceJobService.deleteJobByDeviceIds(new Long[]{deviceId});
|
||||
// 批量删除设备日志
|
||||
logService.deleteDeviceLogByDeviceId(deviceId);
|
||||
// TODO 删除设备告警记录
|
||||
|
||||
/**
|
||||
* 删除设备信息
|
||||
* @param deviceId 设备主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteDeviceByDeviceId(Long deviceId) {
|
||||
return deviceMapper.deleteDeviceByDeviceId(deviceId);
|
||||
// 删除设备
|
||||
deviceMapper.deleteDeviceByDeviceIds(new Long[]{deviceId});
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.ruoyi.common.core.domain.entity.SysUser;
|
||||
import com.ruoyi.common.utils.DateUtils;
|
||||
import com.ruoyi.iot.domain.DeviceUser;
|
||||
import com.ruoyi.iot.mapper.DeviceUserMapper;
|
||||
import com.ruoyi.iot.model.UserIdAndDeviceIdModel;
|
||||
import com.ruoyi.iot.service.IDeviceUserService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.dao.DuplicateKeyException;
|
||||
@@ -103,7 +104,7 @@ public class DeviceUserServiceImpl implements IDeviceUserService
|
||||
@Override
|
||||
public int deleteDeviceUserByDeviceId(Long deviceId)
|
||||
{
|
||||
return deviceUserMapper.deleteDeviceUserByDeviceId(deviceId);
|
||||
return deviceUserMapper.deleteDeviceUserByDeviceId(new UserIdAndDeviceIdModel(null,deviceId));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -33,7 +33,9 @@ public interface TDDeviceLogDAO {
|
||||
|
||||
int delete(String dbName, DeviceLog deviceLog);
|
||||
|
||||
// List<DeviceLog> selectLogListByPage(String dbName, Integer pageSize, Integer pageNum, String deviceNum, Date beginDate, Date endDate);
|
||||
int deleteDeviceLogByDeviceId(String dbName,Long deviceId);
|
||||
|
||||
// List<DeviceLog> selectLogListByPage(String dbName, Integer pageSize, Integer pageNum, String deviceNum, Date beginDate, Date endDate);
|
||||
|
||||
List<DeviceLog> selectLogList(String dbName, Long deviceId, String serialNumber, Long isMonitor, Long logType, Date beginDate, Date endDate);
|
||||
|
||||
|
||||
@@ -18,8 +18,12 @@ import java.util.List;
|
||||
*/
|
||||
public interface ILogService {
|
||||
|
||||
/** 保存设备日志 **/
|
||||
int saveDeviceLog(DeviceLog deviceLog);
|
||||
|
||||
/** 根据设备ID删除设备日志 **/
|
||||
int deleteDeviceLogByDeviceId(Long deviceId);
|
||||
|
||||
/** 设备属性、功能、事件总数 **/
|
||||
DeviceStatistic selectCategoryLogCount();
|
||||
|
||||
|
||||
@@ -22,11 +22,24 @@ public class MySqlLogServiceImpl implements ILogService {
|
||||
this.deviceLogMapper=_deviceLogMapper;
|
||||
}
|
||||
|
||||
/***
|
||||
* 新增设备日志
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int saveDeviceLog(DeviceLog deviceLog) {
|
||||
return deviceLogMapper.insertDeviceLog(deviceLog);
|
||||
}
|
||||
|
||||
/***
|
||||
* 根据设备ID删除设备日志
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int deleteDeviceLogByDeviceId(Long deviceId) {
|
||||
return deviceLogMapper.deleteDeviceLogByDeviceId(deviceId);
|
||||
}
|
||||
|
||||
/***
|
||||
* 设备属性、功能、事件和监测数据总数
|
||||
* @return
|
||||
|
||||
@@ -36,6 +36,10 @@ public class TdengineLogServiceImpl implements ILogService {
|
||||
this.dbName=_tDengineConfig.getDbName();
|
||||
}
|
||||
|
||||
/***
|
||||
* 新增设备日志
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int saveDeviceLog(DeviceLog deviceLog) {
|
||||
long logId = snowflakeIdWorker.nextId();
|
||||
@@ -43,17 +47,37 @@ 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(){
|
||||
return tdDeviceLogDAO.selectCategoryLogCount(dbName);
|
||||
}
|
||||
|
||||
/***
|
||||
* 日志列表
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<DeviceLog> selectDeviceLogList(DeviceLog deviceLog) {
|
||||
return tdDeviceLogDAO.selectDeviceLogList(dbName,deviceLog);
|
||||
}
|
||||
|
||||
/***
|
||||
* 监测数据列表
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<MonitorModel> selectMonitorList(DeviceLog deviceLog) {
|
||||
if(deviceLog.getIdentity()!=null){
|
||||
|
||||
Reference in New Issue
Block a user