Browse Source

Merge pull request 'master' (#39) from master into V3

Reviewed-on: http://git.lrdaiot.cn:9000/thing/thing_api/pulls/39
qingyuan_dev_new
夏超 1 year ago
parent
commit
e02e7d6d29
  1. 11374
      help/sql/dml_1.0.0.sql
  2. 37557
      help/sql/visualv1.sql
  3. 12
      modules/thing/src/main/java/com/thing/device/source/controller/IotThingSourceController.java
  4. 4
      modules/thing/src/main/java/com/thing/device/source/dto/IotThingSourceDTO.java
  5. 4
      modules/thing/src/main/java/com/thing/device/source/dto/IotThingSourceListDTO.java
  6. 3
      modules/thing/src/main/java/com/thing/device/source/entity/IotThingSourceEntity.java
  7. 7
      modules/thing/src/main/java/com/thing/device/source/service/IotThingSourceService.java
  8. 65
      modules/thing/src/main/java/com/thing/device/source/service/impl/IotThingSourceServiceImpl.java
  9. 39
      modules/thing/src/main/java/com/thing/listener/QueueDeviceEventListener.java

11374
help/sql/dml_1.0.0.sql
File diff suppressed because it is too large
View File

37557
help/sql/visualv1.sql
File diff suppressed because it is too large
View File

12
modules/thing/src/main/java/com/thing/device/source/controller/IotThingSourceController.java

@ -142,4 +142,16 @@ public class IotThingSourceController {
return new Result<>();
}
@GetMapping("attrGroup")
@Operation(summary="标签组")
public Result<List<String>> attrGroup() {
return new Result<List<String>>().ok(iotThingSourceService.attrGroup());
}
@PostMapping("attrGroupList")
@Operation(summary="标签组")
public Result<List<IotThingSourceDTO>> attrGroupRootId(@RequestBody IotThingSourceReqDTO iotThingSourceDTO) {
return new Result<List<IotThingSourceDTO>>().ok(iotThingSourceService.attrGroupRootId(iotThingSourceDTO));
}
}

4
modules/thing/src/main/java/com/thing/device/source/dto/IotThingSourceDTO.java

@ -94,6 +94,10 @@ public class IotThingSourceDTO implements Serializable {
private Long updateDate;
@Schema(description = "数据处理规则js")
private String dataRule;
@Schema(description = "物属性名称组(标签组)")
private String thingAttrGroup;
@Schema(description = "启动标志:0启动 1不启动")
private String startStatus;
// @JsonIgnore
// private Long thingTenantId;
// /** 批量新增 同步 或者 更新 功能 **/

4
modules/thing/src/main/java/com/thing/device/source/dto/IotThingSourceListDTO.java

@ -80,5 +80,9 @@ public class IotThingSourceListDTO implements Serializable {
private String extendData;
@Schema(description = "数据处理规则js")
private String dataRule;
@Schema(description = "物属性名称组(标签组)")
private String thingAttrGroup;
@Schema(description = "启动标志:0启动 1不启动")
private String startStatus;
}

3
modules/thing/src/main/java/com/thing/device/source/entity/IotThingSourceEntity.java

@ -81,6 +81,9 @@ public class IotThingSourceEntity extends BaseInfoEntity {
//
// private Long updateDate;
private String thingAttrGroup;
private String startStatus;
}

7
modules/thing/src/main/java/com/thing/device/source/service/IotThingSourceService.java

@ -20,6 +20,9 @@ public interface IotThingSourceService extends IBaseService<IotThingSourceEntity
List<IotThingSourceDTO> findAllByFromIdAndThingIdAndConfigTypeAndAttrCode(Long fromId, List<Long> thingIds, String configType, Long rootId, Collection<String> attrCodes);
List<IotThingSourceDTO> findAllByFromIdAndThingIdAndConfigTypeAndAttrCodeAndAttrGroup(Long fromId, List<Long> thingIds, String configType,
Long rootId, Collection<String> attrCodes,String attrGroup);
List<IotThingSourceDTO> findAllByFromIdAndThingIdAndConfigType(List<Long> fromIds, List<Long> thingIds, String configType, List<Long> rootIds);
IotThingSourceDTO findById(Long id);
@ -43,4 +46,8 @@ public interface IotThingSourceService extends IBaseService<IotThingSourceEntity
List<IotThingSourceAttrRespDTO> getAttrListByThingRelationDTONew(IotThingSourceGetAttrDTO iotThingSourceGetAttrDTO);
void dragAndDrop(Long id,Long toId,Long sort);
List<String> attrGroup();
List<IotThingSourceDTO> attrGroupRootId(IotThingSourceReqDTO iotThingSourceDTO);
}

65
modules/thing/src/main/java/com/thing/device/source/service/impl/IotThingSourceServiceImpl.java

@ -116,6 +116,20 @@ public class IotThingSourceServiceImpl extends BaseServiceImpl<IotThingSourceMap
.eq(IotThingSourceEntity::getTenantCode, UserContext.getRealTenantCode()), IotThingSourceDTO.class);
}
@Override
public List<IotThingSourceDTO> findAllByFromIdAndThingIdAndConfigTypeAndAttrCodeAndAttrGroup(Long fromId, List<Long> thingIds, String configType, Long rootId, Collection<String> attrCodes, String attrGroup) {
return mapper.selectListByQueryAs(
new QueryWrapper()
.eq(IotThingSourceEntity::getFromId, fromId, Objects::nonNull)
.in(IotThingSourceEntity::getThingId, thingIds, CollectionUtil.isNotEmpty(thingIds))
.eq(IotThingSourceEntity::getConfigType, configType, StringUtils::isNotEmpty)
.eq(IotThingSourceEntity::getRootId, rootId, Objects::nonNull)
.in(IotThingSourceEntity::getThingAttrCode, attrCodes, CollectionUtil.isNotEmpty(attrCodes))
.eq(IotThingSourceEntity::getTenantCode, UserContext.getRealTenantCode())
.eq(IotThingSourceEntity::getThingAttrGroup, attrGroup,StringUtils.isNotBlank(attrGroup))
, IotThingSourceDTO.class);
}
@Override
public List<IotThingSourceDTO> findAllByFromIdAndThingIdAndConfigType(List<Long> fromIds, List<Long> thingIds, String configType, List<Long> rootIds) {
return mapper.selectListByQueryAs(
@ -134,9 +148,9 @@ public class IotThingSourceServiceImpl extends BaseServiceImpl<IotThingSourceMap
@Override
public void save(IotThingSourceDTO iotThingSourceDTO) {
List<IotThingSourceDTO> iotThingSourceDTOS = findAllByFromIdAndThingIdAndConfigTypeAndAttrCode(iotThingSourceDTO.getFromId(),
List<IotThingSourceDTO> iotThingSourceDTOS = findAllByFromIdAndThingIdAndConfigTypeAndAttrCodeAndAttrGroup(iotThingSourceDTO.getFromId(),
Collections.singletonList(iotThingSourceDTO.getThingId()), iotThingSourceDTO.getConfigType(), iotThingSourceDTO.getRootId(),
Collections.singletonList(iotThingSourceDTO.getThingAttrCode()));
Collections.singletonList(iotThingSourceDTO.getThingAttrCode()), iotThingSourceDTO.getThingAttrGroup());
if (CollectionUtil.isNotEmpty(iotThingSourceDTOS)) {
throw new SysException("同一个数据源下不允许重复添加相关属性数据:" + iotThingSourceDTO.getThingAttrCode());
}
@ -167,7 +181,10 @@ public class IotThingSourceServiceImpl extends BaseServiceImpl<IotThingSourceMap
.setThingIcon(iotThingSourceDTO.getThingIcon())
.setThingSerial(iotThingSourceDTO.getThingSerial())
.setDataTreatingMark(iotThingSourceDTO.getDataTreatingMark())
.setDataDealConfig(iotThingSourceDTO.getDataDealConfig());
.setDataDealConfig(iotThingSourceDTO.getDataDealConfig())
.setThingAttrGroup(iotThingSourceDTO.getThingAttrGroup())
.setStartStatus(iotThingSourceDTO.getStartStatus())
;
mapper.update(iotThingSourceEntity);
}
@ -280,7 +297,10 @@ public class IotThingSourceServiceImpl extends BaseServiceImpl<IotThingSourceMap
.setFromCode(entityDTO.getCode())
.setFromName(entityDTO.getName())
.setRemark(params.getRemark())
.setExtendData(params.getExtendData());
.setExtendData(params.getExtendData())
// .setThingAttrGroup(params.getThingAttrGroup())
// .setStartStatus(iotThingSourceDTO.getStartStatus())
;
iotThingSourceEntity.setTenantCode(UserContext.getRealTenantCode())
.setCompanyId(UserContext.getRealTenantCode())
.setDeptId(UserContext.getRealTenantCode());
@ -533,6 +553,43 @@ public class IotThingSourceServiceImpl extends BaseServiceImpl<IotThingSourceMap
this.updateBatch(resList);
}
@Override
public List<String> attrGroup() {
List<String> strings = mapper.selectListByQueryAs(QueryWrapper.create()
.select(IOT_THING_SOURCE_ENTITY.THING_ATTR_GROUP).eq(IotThingSourceEntity::getTenantCode, UserContext.getRealTenantCode()), String.class);
if(CollectionUtils.isEmpty(strings)){
return Lists.newArrayList();
}
return strings.stream().filter(s -> !StringUtils.isBlank(s)).distinct().collect(Collectors.toList());
}
@Override
public List<IotThingSourceDTO> attrGroupRootId(IotThingSourceReqDTO iotThingSourceDTO) {
List<IotThingSourceRelationDTO> iotThingSourceRelationDTOList = iotThingSourceDTO.getIotThingSourceRelationDTOList();
if (CollectionUtil.isEmpty(iotThingSourceRelationDTOList)) {
return null;
}
List<Long> thingIds = iotThingSourceRelationDTOList.stream().map(IotThingSourceRelationDTO::getThingId).toList();
List<Long> rootIds = iotThingSourceRelationDTOList.stream().map(IotThingSourceRelationDTO::getRootId).distinct().toList();
List<IotThingSourceDTO> iotThingSourceDTOS = mapper.selectListByQueryAs(QueryWrapper.create()
.in(IotThingSourceEntity::getFromId, thingIds, CollectionUtil.isNotEmpty(thingIds))
.in(IotThingSourceEntity::getRootId, rootIds, CollectionUtil.isNotEmpty(rootIds))
.eq(IotThingSourceEntity::getConfigType, iotThingSourceDTO.getConfigType())
.eq(IotThingSourceEntity::getThingAttrCodeType, iotThingSourceDTO.getThingAttrCodeType(),
StringUtils.isNotBlank(iotThingSourceDTO.getThingAttrCodeType()))
.eq(IotThingSourceEntity::getTenantCode, UserContext.getRealTenantCode())
.eq(IotThingSourceEntity::getStartStatus, "0")
.orderBy(IotThingSourceEntity::getSort,true)
, IotThingSourceDTO.class
);
// 根据 thingAttrGroup 去重
Set<String> seen = new LinkedHashSet<>();
return iotThingSourceDTOS.stream()
.filter(dto -> StringUtils.isNotBlank(dto.getThingAttrGroup()) && seen.add(dto.getThingAttrGroup()))
.toList();
}
/**
* 自定义函数去重
*

39
modules/thing/src/main/java/com/thing/listener/QueueDeviceEventListener.java

@ -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())

Loading…
Cancel
Save