|
|
@ -2,6 +2,7 @@ package org.dromara.sample.manage.service.impl; |
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.ListUtil; |
|
|
import cn.hutool.core.collection.ListUtil; |
|
|
import cn.hutool.core.lang.Dict; |
|
|
import cn.hutool.core.lang.Dict; |
|
|
|
|
|
import cn.hutool.core.stream.StreamUtil; |
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
@ -142,6 +143,9 @@ public class DeviceProServiceImpl implements IDeviceProService { |
|
|
deviceProUserMapper.insert(different); |
|
|
deviceProUserMapper.insert(different); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//更新设备组redis缓存
|
|
|
|
|
|
Boolean flag = updateDeviceProCache(); |
|
|
|
|
|
|
|
|
return true; |
|
|
return true; |
|
|
} catch (ServiceException e) { |
|
|
} catch (ServiceException e) { |
|
|
log.error(e.getMessage(),e); |
|
|
log.error(e.getMessage(),e); |
|
|
@ -149,6 +153,53 @@ public class DeviceProServiceImpl implements IDeviceProService { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private Boolean updateDeviceProCache() { |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
// -------------------------------------- redis缓存 ---------------------------------------------------
|
|
|
|
|
|
//更新redis缓存
|
|
|
|
|
|
//1、如何存储redis 人员 项目组id device_pro:userId -> List<Long> proIdList
|
|
|
|
|
|
// device_pro:
|
|
|
|
|
|
//查询所有的用户-设备组信息
|
|
|
|
|
|
List<DeviceProUserEntity> proUserList = deviceProUserMapper.selectList(new LambdaQueryWrapper<>()); |
|
|
|
|
|
|
|
|
|
|
|
//分组
|
|
|
|
|
|
Map<Long, List<Integer>> proUserMap = proUserList.stream() |
|
|
|
|
|
.collect(Collectors.groupingBy( |
|
|
|
|
|
DeviceProUserEntity::getUserId, // 按 userId 分组
|
|
|
|
|
|
Collectors.mapping(DeviceProUserEntity::getDeviceProId, Collectors.toList()) // 收集每个 userId 对应的 DeviceProId 列表
|
|
|
|
|
|
)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//更新redis设备组信息
|
|
|
|
|
|
proUserMap.keySet().forEach(userId -> { |
|
|
|
|
|
//获取最新的用户设备组信息
|
|
|
|
|
|
List<Integer> currentProId = proUserMap.get(userId); |
|
|
|
|
|
|
|
|
|
|
|
List<Object> cacheList = RedisUtils.getCacheList("device_pro:" + userId); |
|
|
|
|
|
|
|
|
|
|
|
log.info("设备组缓存:{}",cacheList); |
|
|
|
|
|
|
|
|
|
|
|
//删除这个用户的设备组信息
|
|
|
|
|
|
if (RedisUtils.hasKey("device_pro:" + userId)){ |
|
|
|
|
|
RedisUtils.deleteObject("device_pro:" + userId); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//更新设备组信息
|
|
|
|
|
|
RedisUtils.setCacheList("device_pro:" + userId, currentProId); |
|
|
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
// -------------------------------------- redis缓存 ---------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
log.error(e.getMessage(),e); |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 绑定设备的项目组 |
|
|
* 绑定设备的项目组 |
|
|
* @param dict |
|
|
* @param dict |
|
|
@ -265,7 +316,13 @@ public class DeviceProServiceImpl implements IDeviceProService { |
|
|
LambdaQueryWrapper<DeviceProUserEntity> wrapper = new LambdaQueryWrapper<>(); |
|
|
LambdaQueryWrapper<DeviceProUserEntity> wrapper = new LambdaQueryWrapper<>(); |
|
|
wrapper.eq(DeviceProUserEntity::getDeviceProId,proId); |
|
|
wrapper.eq(DeviceProUserEntity::getDeviceProId,proId); |
|
|
wrapper.eq(DeviceProUserEntity::getId,proUserId); |
|
|
wrapper.eq(DeviceProUserEntity::getId,proUserId); |
|
|
return deviceProUserMapper.delete(wrapper) > 0; |
|
|
|
|
|
|
|
|
int flag = deviceProUserMapper.delete(wrapper); |
|
|
|
|
|
|
|
|
|
|
|
//更新缓存
|
|
|
|
|
|
updateDeviceProCache(); |
|
|
|
|
|
|
|
|
|
|
|
return flag > 0; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
|