| | |
| | | package com.ard.sample.manage.service.impl; |
| | | |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.ard.common.annotation.DataScope; |
| | | import com.ard.common.annotation.DataScopePlus; |
| | | import com.ard.system.authorize.service.AuthorizeService; |
| | | import com.baomidou.mybatisplus.core.conditions.Wrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.ard.common.core.domain.entity.SysDept; |
| | |
| | | |
| | | // payloads |
| | | // subDevice.setPayloadsList(payloadService.getDevicePayloadEntitiesByDeviceSn(gateway.getChildDeviceSn())); |
| | | } |
| | | |
| | | @Override |
| | | public List<DeviceDTO> getDockList() { |
| | | List<DeviceDTO> devicesList = this.getDockListByParams( |
| | | DeviceQueryParam.builder() |
| | | .domains(List.of(DeviceDomainEnum.GATEWAY.getVal(), DeviceDomainEnum.DOCK.getVal())) |
| | | .build()); |
| | | |
| | | devicesList.stream() |
| | | .filter(gateway -> DeviceDomainEnum.DOCK.getVal() == gateway.getDomain() || |
| | | RedisOpsUtils.checkExist(RedisConst.DEVICE_ONLINE_PREFIX + gateway.getDeviceSn())) |
| | | .forEach(this::spliceDeviceTopoPer); |
| | | |
| | | return devicesList; |
| | | } |
| | | |
| | | @Override |
| | | public void spliceDeviceTopoPer(DeviceDTO gateway) { |
| | | |
| | | gateway.setStatus(RedisOpsUtils.checkExist(RedisConst.DEVICE_ONLINE_PREFIX + gateway.getDeviceSn())); |
| | | |
| | | // sub device |
| | | if (!StringUtils.hasText(gateway.getChildDeviceSn())) { |
| | | return; |
| | | } |
| | | |
| | | DeviceDTO subDevice = |
| | | getDevicesByParams(DeviceQueryParam.builder().deviceSn(gateway.getChildDeviceSn()).build()).get(0); |
| | | subDevice.setStatus(RedisOpsUtils.checkExist(RedisConst.DEVICE_ONLINE_PREFIX + subDevice.getDeviceSn())); |
| | | gateway.setChildren(subDevice); |
| | | |
| | | // payloads |
| | | // subDevice.setPayloadsList(payloadService.getDevicePayloadEntitiesByDeviceSn(gateway.getChildDeviceSn())); |
| | | } |
| | | |
| | | //@DataScope(deptAlias = "d") |
| | | @Override |
| | | public List<DeviceDTO> getDockListByParams(DeviceQueryParam param){ |
| | | |
| | | return mapper.selectListPer( |
| | | new LambdaQueryWrapper<DeviceEntity>() |
| | | .eq(StringUtils.hasText(param.getDeviceSn()), |
| | | DeviceEntity::getDeviceSn, param.getDeviceSn()) |
| | | .eq(param.getDeviceType() != null, |
| | | DeviceEntity::getDeviceType, param.getDeviceType()) |
| | | .eq(param.getSubType() != null, |
| | | DeviceEntity::getSubType, param.getSubType()) |
| | | .eq(StringUtils.hasText(param.getChildSn()), |
| | | DeviceEntity::getChildSn, param.getChildSn()) |
| | | .and(!CollectionUtils.isEmpty(param.getDomains()), wrapper -> { |
| | | for (Integer domain : param.getDomains()) { |
| | | wrapper.eq(DeviceEntity::getDomain, domain).or(); |
| | | } |
| | | }) |
| | | .eq(param.getBoundStatus() != null, DeviceEntity::getBoundStatus, |
| | | param.getBoundStatus()) |
| | | .orderBy(param.isOrderBy(), |
| | | param.isAsc(), DeviceEntity::getId)) |
| | | .stream() |
| | | .map(this::deviceEntityConvertToDTO) |
| | | .collect(Collectors.toList()); |
| | | } |
| | | |
| | | @Override |
| | |
| | | Long pageSize, Integer domain, Long deptId) { |
| | | |
| | | Page<DeviceEntity> pagination = mapper.selectPage(new Page<>(page, pageSize), |
| | | new LambdaQueryWrapper<DeviceEntity>() |
| | | .eq(DeviceEntity::getDomain, domain) |
| | | .eq(deptId != null, DeviceEntity::getDeptId, deptId) |
| | | .isNotNull(DeviceEntity::getDeptId)); |
| | | // .eq(DeviceEntity::getBoundStatus, true)); |
| | | new QueryWrapper<DeviceEntity>() |
| | | .eq("m.domain", domain) |
| | | .eq(deptId != null, "m.dept_id", deptId) |
| | | .isNotNull("m.dept_id")); |
| | | |
| | | //以前的写法 |
| | | // new LambdaQueryWrapper<DeviceEntity>() |
| | | // .eq(DeviceEntity::getDomain, domain) |
| | | // .eq(deptId != null, DeviceEntity::getDeptId, deptId) |
| | | // .isNotNull(DeviceEntity::getDeptId); |
| | | |
| | | List<DeviceDTO> devicesList = pagination.getRecords().stream().map(this::deviceEntityConvertToDTO) |
| | | .peek(device -> { |
| | | device.setStatus(RedisOpsUtils.checkExist(RedisConst.DEVICE_ONLINE_PREFIX + device.getDeviceSn())); |
| | |
| | | messageSender.publish(topic, builder.build()); |
| | | } |
| | | |
| | | @DataScopePlus(deptAlias="d") |
| | | @Override |
| | | public List<DeviceEntity> selectList(Wrapper<DeviceEntity> queryWrapper) { |
| | | return mapper.selectList(queryWrapper); |
| | | } |
| | | // @DataScopePlus(deptAlias="d") |
| | | // @Override |
| | | // public List<DeviceEntity> selectList(Wrapper<DeviceEntity> queryWrapper) { |
| | | // return mapper.selectList(queryWrapper); |
| | | // } |
| | | } |