Browse Source

[feat]

1、修改设备权限存储redis逻辑①
pull/2/head
杨威 2 months ago
parent
commit
d01e5c7237
  1. 45
      dk-modules/sample/src/main/java/org/dromara/sample/manage/service/impl/DeviceProServiceImpl.java

45
dk-modules/sample/src/main/java/org/dromara/sample/manage/service/impl/DeviceProServiceImpl.java

@ -88,6 +88,8 @@ public class DeviceProServiceImpl implements IDeviceProService {
@Autowired
private IDeviceProUserMapper deviceProUserMapper;
private final ObjectMapper objectMapper = new ObjectMapper();
@Override
public PaginationData<DeviceProEntity> listDeviceProEntityMap(Page page, DeviceProDTO deviceProDTO) {
Page<DeviceProEntity> pagination = deviceProMapper.listDeviceProEntityMap(page, deviceProDTO);
@ -148,13 +150,13 @@ public class DeviceProServiceImpl implements IDeviceProService {
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)
List<Map> projectList = projects.stream()
.filter(Map.class::isInstance)
.map(Map.class::cast)
.toList();
//删除人员中所拥有的当前的项目组,然后构建新的存入redis
List<DeviceProEntity> deviceProEntities = projectList.stream().filter(p -> !p.getId().equals(proId)).toList();
List<Map> deviceProEntities = projectList.stream().filter(p -> !Integer.valueOf(p.get("id") + "").equals(proId)).toList();
//删除
RedisUtils.deleteObject(String.format(Constants.PRO_GROUP, proUserEntity.getUserId()));
//重新插入
@ -163,19 +165,21 @@ public class DeviceProServiceImpl implements IDeviceProService {
//删除人员所拥有的设备信息
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)
List<Map> deviceList = cacheList.stream()
.filter(Map.class::isInstance)
.map(Map.class::cast)
.toList();
//过滤除了这个删除的项目组之外的设备
deviceList = deviceList.stream().filter(p-> !p.getProId().equals(proId)).toList();
deviceList = deviceList.stream().filter(p-> !Integer.valueOf(p.get("proId") + "").equals(proId)).toList();
//删除
RedisUtils.deleteObject(String.format(Constants.PRO_DEVICE, proUserEntity.getUserId()));
RedisUtils.setCacheList(String.format(String.format(Constants.PRO_DEVICE, proUserEntity.getUserId())),deviceList);
RedisUtils.setCacheList(String.format(Constants.PRO_DEVICE, proUserEntity.getUserId()),deviceList);
});
//--------------------------------------------缓存相关操作----------------------------------------------------------------
//先清除原来的项目组成员
deviceProUserMapper.delete(new LambdaQueryWrapper<DeviceProUserEntity>().eq(DeviceProUserEntity::getDeviceProId, proId));
@ -186,13 +190,14 @@ public class DeviceProServiceImpl implements IDeviceProService {
//更新缓存记录
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)
List<Map> projectList = projects.stream()
.filter(Map.class::isInstance)
.map(Map.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);
if (!projectList.stream().anyMatch(p-> Integer.valueOf(p.get("id") + "").equals(proUserEntity.getDeviceProId()))){
Map proMap = objectMapper.convertValue(deviceProEntity, Map.class);
RedisUtils.addCacheList(String.format(String.format(Constants.PRO_GROUP, proUserEntity.getUserId())), proMap);
}
});
}
@ -230,13 +235,15 @@ public class DeviceProServiceImpl implements IDeviceProService {
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)
List<Map> deviceList = devices.stream()
.filter(Map.class::isInstance)
.map(Map.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);
if (!deviceList.stream().anyMatch(p-> Integer.valueOf(p.get("id") + "").equals(deviceEntity.getId()))){
Map deviceMap = objectMapper.convertValue(deviceEntity, Map.class);
RedisUtils.addCacheList(String.format(String.format(Constants.PRO_DEVICE, deviceProUserEntity.getUserId())), deviceMap);
}
});
}

Loading…
Cancel
Save