|
|
|
@ -1,7 +1,6 @@ |
|
|
|
package com.thing.listener; |
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil; |
|
|
|
import cn.hutool.core.util.IdUtil; |
|
|
|
import com.fasterxml.jackson.databind.node.ObjectNode; |
|
|
|
import com.thing.common.cache.constants.CacheNameEnum; |
|
|
|
import com.thing.common.core.enumeration.GateWayStatus; |
|
|
|
@ -15,7 +14,6 @@ import com.thing.common.core.utils.JacksonUtil; |
|
|
|
import com.thing.common.core.utils.TokenGenerator; |
|
|
|
import com.thing.common.data.dto.QueueMsgDTO; |
|
|
|
import com.thing.thing.cache.service.ThingCache; |
|
|
|
import com.thing.thing.context.service.ThingManageContextService; |
|
|
|
import com.thing.thing.entity.dto.IotThingViewDTO; |
|
|
|
import com.thing.thing.entity.entity.IotThingEntity; |
|
|
|
import com.thing.thing.entity.service.IotThingEntityService; |
|
|
|
@ -23,7 +21,6 @@ import com.thing.thing.model.dto.IotThingModelDTO; |
|
|
|
import com.thing.thing.model.entity.IotThingModelEntity; |
|
|
|
import com.thing.thing.model.service.IotThingModelService; |
|
|
|
import com.thing.transport.api.adaptor.JsonConverter; |
|
|
|
import jakarta.annotation.Resource; |
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.commons.collections4.CollectionUtils; |
|
|
|
@ -40,8 +37,6 @@ import java.util.stream.Collectors; |
|
|
|
@RequiredArgsConstructor |
|
|
|
public class QueueDeviceEventListener { |
|
|
|
|
|
|
|
private final ThingManageContextService thingManageContextService; |
|
|
|
|
|
|
|
private final IotThingModelService thingModelService; |
|
|
|
|
|
|
|
private final IotThingEntityService entityService; |
|
|
|
@ -96,40 +91,27 @@ public class QueueDeviceEventListener { |
|
|
|
.setOrigin(origin); |
|
|
|
// modelEntity.setId(IdUtil.getSnowflake().nextId()) |
|
|
|
// .setCreateDate(DateTimeUtils.getCurrentTime()) |
|
|
|
// .setCreateDate(DateTimeUtils.getCurrentTime()) |
|
|
|
; |
|
|
|
// .setCreateDate(DateTimeUtils.getCurrentTime()); |
|
|
|
insertModelList.add(modelEntity); |
|
|
|
} |
|
|
|
//物实体的构建 |
|
|
|
// if (!Objects.equals(queueMsgDTO.getTenantCode(), 1001L)) { |
|
|
|
// ObjectNode entityNode = thingCache.findObjectNode(CacheNameEnum.THING_ENTITY, tenantCode + ":" + thingCode); |
|
|
|
// if (null == entityNode || entityNode.isEmpty()) { |
|
|
|
// IotThingEntity newThingEntity = createThingEntity(thingCode, queueMsgDTO.getTenantCode(), queueMsgDTO.getCompanyId(), queueMsgDTO.getDeptId()); |
|
|
|
// insertEntityList.add(newThingEntity); |
|
|
|
// } |
|
|
|
// } |
|
|
|
ObjectNode entityNode = thingCache.findObjectNode(CacheNameEnum.THING_ENTITY, tenantCode + ":" + thingCode); |
|
|
|
if (null == entityNode || entityNode.isEmpty()) { |
|
|
|
IotThingEntity newThingEntity = createThingEntity(thingCode, queueMsgDTO.getTenantCode(), queueMsgDTO.getCompanyId(), queueMsgDTO.getDeptId()); |
|
|
|
insertEntityList.add(newThingEntity); |
|
|
|
if (!Objects.equals(queueMsgDTO.getTenantCode(), 1001L)) { |
|
|
|
ObjectNode entityNode = thingCache.findObjectNode(CacheNameEnum.THING_ENTITY, tenantCode + ":" + thingCode); |
|
|
|
if (null == entityNode || entityNode.isEmpty()) { |
|
|
|
IotThingEntity newThingEntity = createThingEntity(thingCode, queueMsgDTO.getTenantCode(), queueMsgDTO.getCompanyId(), queueMsgDTO.getDeptId()); |
|
|
|
insertEntityList.add(newThingEntity); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//插入新的物模型 |
|
|
|
if (CollectionUtils.isNotEmpty(insertModelList)) { |
|
|
|
// thingModelService.saveBatch(insertModelList); |
|
|
|
} |
|
|
|
} |
|
|
|
//更新老的物模型 |
|
|
|
if (CollectionUtils.isNotEmpty(updateModelList)) { |
|
|
|
// thingModelService.updateBatch(updateModelList); |
|
|
|
insertModelList.addAll(updateModelList); |
|
|
|
} |
|
|
|
//更新物实体的模型:uniqueModelList有值,物实体不一定有值 |
|
|
|
|
|
|
|
List<IotThingEntity> distinctStudentFile = new ArrayList<>(); |
|
|
|
if (CollectionUtils.isNotEmpty(insertModelList)) { |
|
|
|
|
|
|
|
//物实体的插入和缓存更新 |
|
|
|
if (CollectionUtils.isNotEmpty(insertEntityList)) { |
|
|
|
distinctStudentFile.addAll(insertEntityList.stream() |
|
|
|
@ -146,7 +128,7 @@ public class QueueDeviceEventListener { |
|
|
|
}); |
|
|
|
if(CollectionUtils.isNotEmpty(insertModelList)){ |
|
|
|
thingModelService.saveOrUpdateBatch(insertModelList); |
|
|
|
updateModleCache(insertModelList); |
|
|
|
updateModelCache(insertModelList); |
|
|
|
} |
|
|
|
if(CollectionUtils.isNotEmpty(distinctStudentFile)){ |
|
|
|
entityService.saveOrUpdateBatch(distinctStudentFile); |
|
|
|
@ -157,7 +139,7 @@ public class QueueDeviceEventListener { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void updateModleCache(List<IotThingModelEntity> insertModelList) { |
|
|
|
private void updateModelCache(List<IotThingModelEntity> insertModelList) { |
|
|
|
List<IotThingModelDTO> iotThingModelDTOS = ConvertUtils.sourceToTarget(insertModelList, IotThingModelDTO.class); |
|
|
|
List<ObjectNode> modelList = JsonConverter.convertToJsonObjectListObjectNode(iotThingModelDTOS); |
|
|
|
List<ObjectNode> topicMap = thingCache.getTopicMap(CacheNameEnum.THING_MODEL); |
|
|
|
@ -180,7 +162,6 @@ public class QueueDeviceEventListener { |
|
|
|
private void updateEntityCache(List<IotThingEntity> distinctStudentFile) { |
|
|
|
//更新物实体缓存 |
|
|
|
List<IotThingViewDTO> entityList = distinctStudentFile.stream().map(e -> { |
|
|
|
// ObjectNode keyMap = thingCache.getKeyMap(CacheNameEnum.THING_ENTITY, e.getCode()); |
|
|
|
ObjectNode modelMap = thingCache.findAccurateObjectNode(CacheNameEnum.THING_MODEL, e.getCode()); |
|
|
|
return new IotThingViewDTO() |
|
|
|
.setLat(e.getLat()) |
|
|
|
|