|
|
@ -11,7 +11,10 @@ import com.fasterxml.jackson.databind.JsonNode; |
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.ibatis.executor.BatchResult; |
|
|
|
import org.dromara.common.core.constant.Constants; |
|
|
|
import org.dromara.common.core.exception.ServiceException; |
|
|
|
import org.dromara.common.redis.utils.RedisOpsUtils; |
|
|
|
import org.dromara.common.redis.utils.RedisUtils; |
|
|
|
import org.dromara.common.satoken.utils.LoginHelper; |
|
|
|
import org.dromara.common.sdk.cloudapi.device.*; |
|
|
|
import org.dromara.common.sdk.cloudapi.firmware.*; |
|
|
@ -34,6 +37,7 @@ import org.dromara.common.sdk.mqtt.services.ServicesSubscribe; |
|
|
|
import org.dromara.common.sdk.mqtt.services.TopicServicesResponse; |
|
|
|
import org.dromara.common.sdk.mqtt.state.StateSubscribe; |
|
|
|
import org.dromara.common.sdk.mqtt.status.StatusSubscribe; |
|
|
|
import org.dromara.common.tenant.helper.TenantHelper; |
|
|
|
import org.dromara.common.websocket.dto.BizCodeEnum; |
|
|
|
import org.dromara.sample.common.error.CommonErrorEnum; |
|
|
|
import org.dromara.sample.component.mqtt.model.EventsReceiver; |
|
|
@ -62,10 +66,7 @@ import org.springframework.util.CollectionUtils; |
|
|
|
import org.springframework.util.StringUtils; |
|
|
|
|
|
|
|
import java.time.LocalDateTime; |
|
|
|
import java.util.Collection; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Optional; |
|
|
|
import java.util.*; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
/** |
|
|
@ -107,7 +108,7 @@ public class DeviceProServiceImpl implements IDeviceProService { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public Boolean deleteIds(List<Long> ids) { |
|
|
|
public Boolean deleteIds(List<Integer> ids) { |
|
|
|
|
|
|
|
List<DeviceEntity> deviceEntityList = deviceMapper.selectList(new LambdaQueryWrapper<DeviceEntity>().in(DeviceEntity::getProId, ids)); |
|
|
|
|
|
|
@ -125,14 +126,75 @@ public class DeviceProServiceImpl implements IDeviceProService { |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public Boolean updateDeviceProUser(List<DeviceProUserEntity> userEntity,Long proId) { |
|
|
|
public Boolean updateDeviceProUser(List<DeviceProUserEntity> userEntity,Integer proId) { |
|
|
|
try { |
|
|
|
//获取项目组信息
|
|
|
|
DeviceProEntity deviceProEntity = deviceProMapper.selectOne(new LambdaQueryWrapper<DeviceProEntity>().eq(DeviceProEntity::getId, proId)); |
|
|
|
|
|
|
|
//查询之前项目所属的人员信息
|
|
|
|
List<DeviceProUserEntity> proUserEntityList = deviceProUserMapper.selectList(new LambdaQueryWrapper<DeviceProUserEntity>().eq(DeviceProUserEntity::getDeviceProId, proId)); |
|
|
|
|
|
|
|
List<DeviceProUserEntity> difference = new ArrayList<>(); |
|
|
|
|
|
|
|
// 判断两个集合的差值(基于 userId)
|
|
|
|
difference = proUserEntityList.stream() |
|
|
|
.filter(proUser -> userEntity.stream() |
|
|
|
.noneMatch(user -> user.getUserId().equals(proUser.getUserId()))) |
|
|
|
.toList(); |
|
|
|
|
|
|
|
//--------------------------------------------缓存相关操作----------------------------------------------------------------
|
|
|
|
|
|
|
|
//人员如果解绑了项目删除缓存数据
|
|
|
|
difference.forEach(proUserEntity -> { |
|
|
|
//删除人员项目组信息
|
|
|
|
List<Object> projects = RedisUtils.getCacheList(String.format(Constants.PRO_GROUP, proUserEntity.getUserId())); |
|
|
|
List<DeviceProEntity> projectList = projects.stream() |
|
|
|
.filter(DeviceProEntity.class::isInstance) |
|
|
|
.map(DeviceProEntity.class::cast) |
|
|
|
.toList(); |
|
|
|
|
|
|
|
//删除人员中所拥有的当前的项目组,然后构建新的存入redis
|
|
|
|
List<DeviceProEntity> deviceProEntities = projectList.stream().filter(p -> !p.getId().equals(proId)).toList(); |
|
|
|
//删除
|
|
|
|
RedisUtils.deleteObject(String.format(Constants.PRO_GROUP, proUserEntity.getUserId())); |
|
|
|
//重新插入
|
|
|
|
RedisUtils.setCacheList(String.format(Constants.PRO_GROUP, proUserEntity.getUserId()),deviceProEntities); |
|
|
|
|
|
|
|
|
|
|
|
//删除人员所拥有的设备信息
|
|
|
|
List<Object> cacheList = RedisUtils.getCacheList(String.format(Constants.PRO_DEVICE, proUserEntity.getUserId())); |
|
|
|
List<DeviceEntity> deviceList = cacheList.stream() |
|
|
|
.filter(DeviceEntity.class::isInstance) |
|
|
|
.map(DeviceEntity.class::cast) |
|
|
|
.toList(); |
|
|
|
|
|
|
|
//过滤除了这个删除的项目组之外的设备
|
|
|
|
deviceList = deviceList.stream().filter(p-> !p.getProId().equals(proId)).toList(); |
|
|
|
//删除
|
|
|
|
RedisUtils.deleteObject(String.format(Constants.PRO_DEVICE, proUserEntity.getUserId())); |
|
|
|
|
|
|
|
RedisUtils.setCacheList(String.format(String.format(Constants.PRO_DEVICE, proUserEntity.getUserId())),deviceList); |
|
|
|
}); |
|
|
|
|
|
|
|
//先清除原来的项目组成员
|
|
|
|
deviceProUserMapper.delete(new LambdaQueryWrapper<DeviceProUserEntity>().eq(DeviceProUserEntity::getDeviceProId, proId)); |
|
|
|
|
|
|
|
if (ObjectUtil.isNotEmpty(userEntity)) { |
|
|
|
//添加新的项目组成员
|
|
|
|
deviceProUserMapper.insert(userEntity); |
|
|
|
|
|
|
|
//更新缓存记录
|
|
|
|
userEntity.forEach(proUserEntity -> { |
|
|
|
List<Object> projects = RedisUtils.getCacheList(String.format(Constants.PRO_GROUP, proUserEntity.getUserId())); |
|
|
|
List<DeviceProEntity> projectList = projects.stream() |
|
|
|
.filter(DeviceProEntity.class::isInstance) |
|
|
|
.map(DeviceProEntity.class::cast) |
|
|
|
.toList(); |
|
|
|
|
|
|
|
if (!projectList.stream().anyMatch(p-> p.getId().equals(proUserEntity.getDeviceProId()))){ |
|
|
|
RedisUtils.addCacheList(String.format(String.format(Constants.PRO_GROUP, proUserEntity.getUserId())), deviceProEntity); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
return true; |
|
|
@ -150,18 +212,39 @@ public class DeviceProServiceImpl implements IDeviceProService { |
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public Boolean updateDevice(Dict dict) { |
|
|
|
Long deviceId = dict.getLong("deviceId"); |
|
|
|
Long proId = dict.getLong("proId"); |
|
|
|
Integer deviceId = dict.getInt("deviceId"); |
|
|
|
Integer proId = dict.getInt("proId"); |
|
|
|
|
|
|
|
if (ObjectUtil.hasEmpty(deviceId, proId)) { |
|
|
|
throw new ServiceException("【deviceId】或【proId】参数为空!"); |
|
|
|
} |
|
|
|
|
|
|
|
try { |
|
|
|
LambdaUpdateWrapper<DeviceEntity> wrapper = new LambdaUpdateWrapper<>(); |
|
|
|
wrapper.set(DeviceEntity::getProId, proId); |
|
|
|
wrapper.eq(DeviceEntity::getId, deviceId); |
|
|
|
|
|
|
|
return deviceMapper.update(wrapper) > 0; |
|
|
|
if (deviceMapper.update(wrapper) > 0) { |
|
|
|
DeviceEntity deviceEntity = deviceMapper.selectOne(new LambdaQueryWrapper<DeviceEntity>().eq(DeviceEntity::getId, deviceId)); |
|
|
|
//根据proid获取人员用于存储人员的设备权限
|
|
|
|
List<DeviceProUserEntity> proUserEntityList = deviceProUserMapper.selectList(new LambdaQueryWrapper<DeviceProUserEntity>().eq(DeviceProUserEntity::getDeviceProId, proId)); |
|
|
|
proUserEntityList.forEach(deviceProUserEntity -> { |
|
|
|
List<Object> devices = RedisUtils.getCacheList(String.format(Constants.PRO_DEVICE, deviceProUserEntity.getUserId())); |
|
|
|
List<DeviceEntity> deviceList = devices.stream() |
|
|
|
.filter(DeviceEntity.class::isInstance) |
|
|
|
.map(DeviceEntity.class::cast) |
|
|
|
.toList(); |
|
|
|
|
|
|
|
if (!deviceList.stream().anyMatch(p-> p.getId().equals(deviceEntity.getId()))){ |
|
|
|
RedisUtils.addCacheList(String.format(String.format(Constants.PRO_DEVICE, deviceProUserEntity.getUserId())), deviceEntity); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|