guoshilong
2023-09-26 c5320fbf7fd671ba7ccefe66e951edeebb4252b2
src/main/java/com/dji/sample/manage/service/impl/DeviceServiceImpl.java
@@ -279,10 +279,13 @@
    public List<DeviceDTO> getDevicesByParams(DeviceQueryParam param) {
        return mapper.selectList(
                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()),
@@ -518,9 +521,37 @@
            }
            entity.setId(deviceEntity.getId());
            mapper.updateById(entity);
            return Optional.of(deviceEntity);
            fillNullField(entity, deviceEntity);
            return Optional.of(entity);
        }
        return mapper.insert(entity) > 0 ? Optional.of(entity) : Optional.empty();
    }
    private void fillNullField(DeviceEntity entity, DeviceEntity oldEntity) {
        if (Objects.isNull(entity) || Objects.isNull(oldEntity)) {
            return;
        }
        if (Objects.isNull(entity.getWorkspaceId())) {
            entity.setWorkspaceId(oldEntity.getWorkspaceId());
        }
        if (Objects.isNull(entity.getUserId())) {
            entity.setUserId(oldEntity.getUserId());
        }
        if (Objects.isNull(entity.getChildSn())) {
            entity.setChildSn(oldEntity.getChildSn());
        }
        if (Objects.isNull(entity.getBoundStatus())) {
            entity.setBoundStatus(oldEntity.getBoundStatus());
        }
        if (Objects.isNull(entity.getBoundTime())) {
            entity.setBoundTime(oldEntity.getBoundTime());
        }
        if (Objects.isNull(entity.getFirmwareVersion())) {
            entity.setFirmwareVersion(oldEntity.getFirmwareVersion());
        }
        if (Objects.isNull(entity.getDeviceIndex())) {
            entity.setDeviceIndex(oldEntity.getDeviceIndex());
        }
    }
    /**
@@ -650,7 +681,7 @@
            return;
        }
        if (entity.getFirmwareVersion().equals(firmwareReleaseNoteOpt.get().getProductVersion())) {
            deviceDTO.setFirmwareStatus(entity.getCompatibleStatus() ?
            deviceDTO.setFirmwareStatus(Objects.requireNonNullElse(entity.getCompatibleStatus(), true) ?
                    DeviceFirmwareStatusEnum.NOT_UPGRADE.getVal() :
                    DeviceFirmwareStatusEnum.CONSISTENT_UPGRADE.getVal());
            return;
@@ -1166,4 +1197,4 @@
        }
        return deviceBasic.getPayloads();
    }
}
}