|
|
@ -59,6 +59,7 @@ import org.dromara.sample.manage.model.receiver.BasicDeviceProperty; |
|
|
|
import org.dromara.sample.manage.service.*; |
|
|
|
import org.dromara.sample.websocket.service.IWebSocketMessageService; |
|
|
|
import org.dromara.system.api.model.LoginUser; |
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
@ -88,7 +89,6 @@ public class DeviceProServiceImpl implements IDeviceProService { |
|
|
|
@Autowired |
|
|
|
private IDeviceProUserMapper deviceProUserMapper; |
|
|
|
|
|
|
|
// private final ObjectMapper objectMapper = new ObjectMapper();
|
|
|
|
|
|
|
|
@Override |
|
|
|
public PaginationData<DeviceProEntity> listDeviceProEntityMap(Page page, DeviceProDTO deviceProDTO) { |
|
|
@ -100,10 +100,13 @@ public class DeviceProServiceImpl implements IDeviceProService { |
|
|
|
@Override |
|
|
|
public Boolean updateDevicePro(DeviceProEntity deviceProEntity) { |
|
|
|
if(ObjectUtil.isNotEmpty(deviceProEntity.getId())){ |
|
|
|
DeviceProEntity devicePro = deviceProMapper.selectById(deviceProEntity.getId()); |
|
|
|
BeanUtils.copyProperties(deviceProEntity, devicePro); |
|
|
|
|
|
|
|
return deviceProMapper.updateById(deviceProEntity) > 0 ; |
|
|
|
}else { |
|
|
|
deviceProEntity.setDeptName(LoginHelper.getDeptName()); |
|
|
|
deviceProEntity.setNickName(LoginHelper.getUsername()); |
|
|
|
deviceProEntity.setNickName(LoginHelper.getLoginUser().getNickname()); |
|
|
|
return deviceProMapper.insert(deviceProEntity) > 0; |
|
|
|
} |
|
|
|
} |
|
|
@ -119,10 +122,6 @@ public class DeviceProServiceImpl implements IDeviceProService { |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
//todo人员是否要删除
|
|
|
|
List<DeviceProUserEntity> proUserEntityList = deviceProUserMapper.selectList(new LambdaQueryWrapper<DeviceProUserEntity>().in(DeviceProUserEntity::getDeviceProId, ids)); |
|
|
|
|
|
|
|
|
|
|
|
return deviceProMapper.deleteByIds(ids)>0; |
|
|
|
} |
|
|
|
|
|
|
@ -130,78 +129,12 @@ public class DeviceProServiceImpl implements IDeviceProService { |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
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<Map> projectList = projects.stream()
|
|
|
|
// .filter(Map.class::isInstance)
|
|
|
|
// .map(Map.class::cast)
|
|
|
|
// .toList();
|
|
|
|
//
|
|
|
|
// //删除人员中所拥有的当前的项目组,然后构建新的存入redis
|
|
|
|
// List<Map> deviceProEntities = projectList.stream().filter(p -> !Integer.valueOf(p.get("id") + "").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<Map> deviceList = cacheList.stream()
|
|
|
|
// .filter(Map.class::isInstance)
|
|
|
|
// .map(Map.class::cast)
|
|
|
|
// .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(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<Map> projectList = projects.stream()
|
|
|
|
// .filter(Map.class::isInstance)
|
|
|
|
// .map(Map.class::cast)
|
|
|
|
// .toList();
|
|
|
|
//
|
|
|
|
// if (!projectList.stream().anyMatch(p-> Integer.valueOf(p.get("id") + "").equals(proUserEntity.getDeviceProId()))){
|
|
|
|
// Map proMap = objectMapper.convertValue(deviceProEntity, Map.class);
|
|
|
|
// RedisUtils.addCacheList(String.format(Constants.PRO_GROUP, proUserEntity.getUserId()), proMap);
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
} |
|
|
|
|
|
|
|
userEntity.forEach(deviceProUserEntity -> { |
|
|
|
deviceProUserEntity.setNickName(LoginHelper.getLoginUser().getNickname()); |
|
|
|
deviceProUserEntity.setDeptName(LoginHelper.getDeptName()); |
|
|
|
}); |
|
|
|
//添加新的项目组成员
|
|
|
|
deviceProUserMapper.insert(userEntity); |
|
|
|
return true; |
|
|
|
} catch (ServiceException e) { |
|
|
|
log.error(e.getMessage(),e); |
|
|
@ -229,28 +162,8 @@ public class DeviceProServiceImpl implements IDeviceProService { |
|
|
|
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<Map> deviceList = devices.stream()
|
|
|
|
// .filter(Map.class::isInstance)
|
|
|
|
// .map(Map.class::cast)
|
|
|
|
// .toList();
|
|
|
|
//
|
|
|
|
// if (!deviceList.stream().anyMatch(p-> Integer.valueOf(p.get("id") + "").equals(deviceEntity.getId()))){
|
|
|
|
// Map deviceMap = objectMapper.convertValue(deviceEntity, Map.class);
|
|
|
|
//
|
|
|
|
// RedisUtils.addCacheList(String.format(Constants.PRO_DEVICE, deviceProUserEntity.getUserId()), deviceMap);
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
// }
|
|
|
|
} catch (Exception e) { |
|
|
|
return false; |
|
|
|
} |
|
|
@ -270,6 +183,8 @@ public class DeviceProServiceImpl implements IDeviceProService { |
|
|
|
List<Integer> proIdList = proUserEntityList.stream().map(DeviceProUserEntity::getDeviceProId).distinct().toList(); |
|
|
|
LambdaQueryWrapper<DeviceProEntity> queryWrapper = new LambdaQueryWrapper<>(); |
|
|
|
queryWrapper.in(DeviceProEntity::getId, proIdList); |
|
|
|
//查询是否启用的设备组
|
|
|
|
queryWrapper.eq(DeviceProEntity::getBindType,1); |
|
|
|
return deviceProMapper.selectList(queryWrapper).stream().map(DeviceProEntity::getId).distinct().toList(); |
|
|
|
} |
|
|
|
|
|
|
@ -323,6 +238,29 @@ public class DeviceProServiceImpl implements IDeviceProService { |
|
|
|
return this.deviceProMapper.update(wrapper) > 0; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public PaginationData<DeviceProUserEntity> pageProUser(String searchValue, Integer proId,Page<DeviceProUserEntity> pageQuery) { |
|
|
|
LambdaQueryWrapper<DeviceProUserEntity> wrapper = new LambdaQueryWrapper<>(); |
|
|
|
wrapper.eq(DeviceProUserEntity::getDeviceProId,proId); |
|
|
|
|
|
|
|
if (ObjectUtil.isNotEmpty(searchValue)){ |
|
|
|
wrapper.like(DeviceProUserEntity::getUserName,searchValue); |
|
|
|
} |
|
|
|
|
|
|
|
Page<DeviceProUserEntity> pagination = deviceProUserMapper.selectPage(pageQuery, wrapper); |
|
|
|
|
|
|
|
return new PaginationData<DeviceProUserEntity>(pagination.getRecords(), new Pagination(pagination.getCurrent(), pagination.getSize(), pagination.getTotal())); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public Boolean deleteProUser(Long proUserId, Integer proId) { |
|
|
|
LambdaQueryWrapper<DeviceProUserEntity> wrapper = new LambdaQueryWrapper<>(); |
|
|
|
wrapper.eq(DeviceProUserEntity::getDeviceProId,proId); |
|
|
|
wrapper.eq(DeviceProUserEntity::getId,proUserId); |
|
|
|
return deviceProUserMapper.delete(wrapper) > 0; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public Boolean saveAndUpdate(DeviceProEntity entity) { |
|
|
|
boolean flag = true; |
|
|
|