Commit aaf0707188a734380433c28cf1021bd74d6f1cff
Merge remote-tracking branch 'origin/i18n' into i18n
Showing
5 changed files
with
19 additions
and
39 deletions
... | ... | @@ -18,6 +18,7 @@ import org.thingsboard.server.queue.util.TbCoreComponent; |
18 | 18 | import org.thingsboard.server.service.edge.rpc.yunteng.TkEdgeProcessor; |
19 | 19 | import org.thingsboard.server.service.edge.rpc.yunteng.TkEdgeProcessorRepository; |
20 | 20 | import org.thingsboard.server.service.edge.rpc.yunteng.tk_device_profile_category.TkDeviceProfileCategoryRepository; |
21 | +import org.thingsboard.server.service.state.DeviceStateService; | |
21 | 22 | |
22 | 23 | import java.util.UUID; |
23 | 24 | ... | ... |
... | ... | @@ -3,6 +3,7 @@ package org.thingsboard.server.service.edge.rpc.yunteng.tk_event_kv; |
3 | 3 | import lombok.AllArgsConstructor; |
4 | 4 | import org.springframework.beans.BeanUtils; |
5 | 5 | import org.springframework.stereotype.Repository; |
6 | +import org.thingsboard.server.common.data.id.DeviceId; | |
6 | 7 | import org.thingsboard.server.common.data.id.EdgeId; |
7 | 8 | import org.thingsboard.server.common.data.id.EntityId; |
8 | 9 | import org.thingsboard.server.common.data.id.TenantId; |
... | ... | @@ -16,6 +17,7 @@ import org.thingsboard.server.dao.yunteng.jpa.entity.events.TkEventKvCompositeKe |
16 | 17 | import org.thingsboard.server.dao.yunteng.jpa.entity.events.TkEventKvEntity; |
17 | 18 | import org.thingsboard.server.dao.yunteng.jpa.repository.event.EventKvRepository; |
18 | 19 | import org.thingsboard.server.service.edge.rpc.yunteng.TkEdgeProcessorRepository; |
20 | +import org.thingsboard.server.service.state.DeviceStateService; | |
19 | 21 | |
20 | 22 | import java.util.List; |
21 | 23 | import java.util.Optional; |
... | ... | @@ -25,6 +27,7 @@ import java.util.Optional; |
25 | 27 | public class TkEventKvRepository implements TkEdgeProcessorRepository<TkEventKv> { |
26 | 28 | |
27 | 29 | private EventKvRepository eventKvRepository; |
30 | + private DeviceStateService deviceStateService; | |
28 | 31 | |
29 | 32 | @Override |
30 | 33 | public boolean updateFromEdge(TenantId tenantId, EdgeId edgeId, TkEventKv dto) throws Exception { |
... | ... | @@ -34,6 +37,7 @@ public class TkEventKvRepository implements TkEdgeProcessorRepository<TkEventKv> |
34 | 37 | id.setEventType(dto.getEventType()); |
35 | 38 | id.setEntityId(dto.getId().getId()); |
36 | 39 | Optional<TkEventKvEntity> optional = eventKvRepository.findById(id); |
40 | + deviceStateService.onDeviceActivity(tenantId,new DeviceId(dto.getId().getId()),System.currentTimeMillis()); | |
37 | 41 | if(optional.isPresent()){ |
38 | 42 | TkEventKvEntity model=optional.get(); |
39 | 43 | CopyUtils.copyProperties(dto, model); | ... | ... |
... | ... | @@ -292,9 +292,6 @@ public class DefaultDeviceStateService extends AbstractPartitionBasedService<Dev |
292 | 292 | //thingkit function |
293 | 293 | String tenantId = stateData.getTenantId().getId().toString(); |
294 | 294 | String tbDeviceId = deviceId.getId().toString(); |
295 | - tkDeviceService.updateDeviceStateByTbDeviceId(tenantId,tbDeviceId, | |
296 | - org.thingsboard.server.common.data.yunteng.enums.DeviceState.ONLINE); | |
297 | - //ThingsKit | |
298 | 295 | saveDeviceStateLog(tenantId,tbDeviceId, FastIotConstants.StateValue.ONLINE); |
299 | 296 | } |
300 | 297 | } else { |
... | ... | @@ -515,7 +512,7 @@ public class DefaultDeviceStateService extends AbstractPartitionBasedService<Dev |
515 | 512 | } |
516 | 513 | } |
517 | 514 | |
518 | - private boolean addDeviceUsingState(TopicPartitionInfo tpi, DeviceStateData state) { | |
515 | + private boolean addDeviceUsingState(TopicPartitionInfo tpi, final DeviceStateData state) { | |
519 | 516 | Set<DeviceId> deviceIds = partitionedEntities.get(tpi); |
520 | 517 | if (deviceIds != null) { |
521 | 518 | deviceIds.add(state.getDeviceId()); |
... | ... | @@ -547,7 +544,7 @@ public class DefaultDeviceStateService extends AbstractPartitionBasedService<Dev |
547 | 544 | if (e instanceof TenantNotFoundException) { |
548 | 545 | idsFromRemovedTenant.add(deviceId); |
549 | 546 | } else { |
550 | - log.warn("[{}] Failed to update inactivity state [{}]", deviceId, e.getMessage()); | |
547 | + log.error("[{}] Failed to update inactivity state [{}]", deviceId, e.getMessage()); | |
551 | 548 | } |
552 | 549 | } |
553 | 550 | } |
... | ... | @@ -592,17 +589,18 @@ public class DefaultDeviceStateService extends AbstractPartitionBasedService<Dev |
592 | 589 | if (!isActive(ts, state) |
593 | 590 | && (state.getLastInactivityAlarmTime() == 0L || state.getLastInactivityAlarmTime() <= state.getLastActivityTime()) |
594 | 591 | && stateData.getDeviceCreationTime() + state.getInactivityTimeout() <= ts) { |
592 | + | |
593 | + //thingskit code使设备下线,不必判断partition是不是isMyPartition,因为我也不知道if (partitionService.resolve(ServiceType.TB_CORE, stateData.getTenantId(), deviceId).isMyPartition())是干嘛的 | |
594 | + reportInactivity(ts, deviceId, stateData); | |
595 | + if(stateData.getState().getLastActivityTime()>0){ | |
596 | + String tenantId = stateData.getTenantId().getId().toString(); | |
597 | + String tbDeviceId = deviceId.getId().toString(); | |
598 | + saveDeviceStateLog(tenantId,tbDeviceId, FastIotConstants.StateValue.OFFLINE); | |
599 | + channelService.updateVideoChannelState(deviceId.getId().toString(), StatusEnum.OFFLINE); | |
600 | + } | |
601 | + | |
595 | 602 | if (partitionService.resolve(ServiceType.TB_CORE, stateData.getTenantId(), deviceId).isMyPartition()) { |
596 | - reportInactivity(ts, deviceId, stateData); | |
597 | - if(stateData.getState().getLastActivityTime()>0){ | |
598 | - String tenantId = stateData.getTenantId().getId().toString(); | |
599 | - String tbDeviceId = deviceId.getId().toString(); | |
600 | - tkDeviceService.updateDeviceStateByTbDeviceId(tenantId,tbDeviceId, | |
601 | - org.thingsboard.server.common.data.yunteng.enums.DeviceState.OFFLINE); | |
602 | - saveDeviceStateLog(tenantId,tbDeviceId, FastIotConstants.StateValue.OFFLINE); | |
603 | - //thingskit update tkDevice state | |
604 | - channelService.updateVideoChannelState(deviceId.getId().toString(), StatusEnum.OFFLINE); | |
605 | - } | |
603 | + | |
606 | 604 | } else { |
607 | 605 | cleanupEntity(deviceId); |
608 | 606 | } |
... | ... | @@ -619,6 +617,7 @@ public class DefaultDeviceStateService extends AbstractPartitionBasedService<Dev |
619 | 617 | state.setLastInactivityAlarmTime(ts); |
620 | 618 | save(deviceId, INACTIVITY_ALARM_TIME, ts); |
621 | 619 | onDeviceActivityStatusChange(deviceId, false, stateData); |
620 | + System.err.println("Inactivity Device : "+deviceId); | |
622 | 621 | } |
623 | 622 | |
624 | 623 | boolean isActive(long ts, DeviceState state) { | ... | ... |
... | ... | @@ -879,22 +879,6 @@ public class TkDeviceServiceImpl extends AbstractTbBaseService<DeviceMapper, TkD |
879 | 879 | .collect(Collectors.toList()); |
880 | 880 | } |
881 | 881 | |
882 | - @Override | |
883 | - public boolean updateDeviceStateByTbDeviceId( | |
884 | - String tenantId, String tbDeviceId, DeviceState deviceState) { | |
885 | - boolean result = false; | |
886 | - TkDeviceEntity entity = | |
887 | - baseMapper.selectOne( | |
888 | - new LambdaQueryWrapper<TkDeviceEntity>() | |
889 | - .eq(TkDeviceEntity::getTenantId, UUID.fromString(tenantId)) | |
890 | - .eq(TkDeviceEntity::getId, UUID.fromString(tbDeviceId))); | |
891 | - | |
892 | - if (null != entity) { | |
893 | - entity.setDeviceState(deviceState); | |
894 | - return baseMapper.updateById(entity) > FastIotConstants.MagicNumber.ZERO; | |
895 | - } | |
896 | - return result; | |
897 | - } | |
898 | 882 | |
899 | 883 | @Override |
900 | 884 | public DeviceDTO getDeviceByDeviceNameOrIdAndGateWayId(String tenantId, String nameOrTbDeviceId, String gateWayId) { | ... | ... |
... | ... | @@ -265,14 +265,6 @@ public interface TkDeviceService extends TbBaseService<TkDeviceEntity> { |
265 | 265 | */ |
266 | 266 | List<DeviceDTO> findDeviceInfoByTbDeviceIds(List<String> tbDeviceIds,String tenantId); |
267 | 267 | |
268 | - /** | |
269 | - * 根据TB的设备ID更新TK的设备状态 | |
270 | - * @param tenantId 租户ID | |
271 | - * @param tbDeviceId TB的设备ID | |
272 | - * @param deviceState 设备状态枚举值 | |
273 | - * @return true成功 false失败 | |
274 | - */ | |
275 | - boolean updateDeviceStateByTbDeviceId(String tenantId, String tbDeviceId, DeviceState deviceState); | |
276 | 268 | |
277 | 269 | /** |
278 | 270 | * 根据租户ID和设备名称或设备ID查询该设备的信息 | ... | ... |