diff --git a/modules/thing/src/main/java/com/thing/device/source/controller/IotThingSourceController.java b/modules/thing/src/main/java/com/thing/device/source/controller/IotThingSourceController.java index 05923f8..d3d7761 100644 --- a/modules/thing/src/main/java/com/thing/device/source/controller/IotThingSourceController.java +++ b/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> attrGroup() { + return new Result>().ok(iotThingSourceService.attrGroup()); + } + + @PostMapping("attrGroupList") + @Operation(summary="标签组") + public Result> attrGroupRootId(@RequestBody IotThingSourceReqDTO iotThingSourceDTO) { + return new Result>().ok(iotThingSourceService.attrGroupRootId(iotThingSourceDTO)); + } + } diff --git a/modules/thing/src/main/java/com/thing/device/source/dto/IotThingSourceDTO.java b/modules/thing/src/main/java/com/thing/device/source/dto/IotThingSourceDTO.java index cace7d1..438608c 100644 --- a/modules/thing/src/main/java/com/thing/device/source/dto/IotThingSourceDTO.java +++ b/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; // /** 批量新增 同步 或者 更新 功能 **/ diff --git a/modules/thing/src/main/java/com/thing/device/source/dto/IotThingSourceListDTO.java b/modules/thing/src/main/java/com/thing/device/source/dto/IotThingSourceListDTO.java index 9201efb..060dc78 100644 --- a/modules/thing/src/main/java/com/thing/device/source/dto/IotThingSourceListDTO.java +++ b/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; } diff --git a/modules/thing/src/main/java/com/thing/device/source/entity/IotThingSourceEntity.java b/modules/thing/src/main/java/com/thing/device/source/entity/IotThingSourceEntity.java index ffac98a..5ad19de 100644 --- a/modules/thing/src/main/java/com/thing/device/source/entity/IotThingSourceEntity.java +++ b/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; + } \ No newline at end of file diff --git a/modules/thing/src/main/java/com/thing/device/source/service/IotThingSourceService.java b/modules/thing/src/main/java/com/thing/device/source/service/IotThingSourceService.java index 61ecd88..fcd88bc 100644 --- a/modules/thing/src/main/java/com/thing/device/source/service/IotThingSourceService.java +++ b/modules/thing/src/main/java/com/thing/device/source/service/IotThingSourceService.java @@ -20,6 +20,9 @@ public interface IotThingSourceService extends IBaseService findAllByFromIdAndThingIdAndConfigTypeAndAttrCode(Long fromId, List thingIds, String configType, Long rootId, Collection attrCodes); + List findAllByFromIdAndThingIdAndConfigTypeAndAttrCodeAndAttrGroup(Long fromId, List thingIds, String configType, + Long rootId, Collection attrCodes,String attrGroup); + List findAllByFromIdAndThingIdAndConfigType(List fromIds, List thingIds, String configType, List rootIds); IotThingSourceDTO findById(Long id); @@ -43,4 +46,8 @@ public interface IotThingSourceService extends IBaseService getAttrListByThingRelationDTONew(IotThingSourceGetAttrDTO iotThingSourceGetAttrDTO); void dragAndDrop(Long id,Long toId,Long sort); + + List attrGroup(); + + List attrGroupRootId(IotThingSourceReqDTO iotThingSourceDTO); } diff --git a/modules/thing/src/main/java/com/thing/device/source/service/impl/IotThingSourceServiceImpl.java b/modules/thing/src/main/java/com/thing/device/source/service/impl/IotThingSourceServiceImpl.java index da4b48e..1fd7882 100644 --- a/modules/thing/src/main/java/com/thing/device/source/service/impl/IotThingSourceServiceImpl.java +++ b/modules/thing/src/main/java/com/thing/device/source/service/impl/IotThingSourceServiceImpl.java @@ -116,6 +116,20 @@ public class IotThingSourceServiceImpl extends BaseServiceImpl findAllByFromIdAndThingIdAndConfigTypeAndAttrCodeAndAttrGroup(Long fromId, List thingIds, String configType, Long rootId, Collection 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 findAllByFromIdAndThingIdAndConfigType(List fromIds, List thingIds, String configType, List rootIds) { return mapper.selectListByQueryAs( @@ -134,9 +148,9 @@ public class IotThingSourceServiceImpl extends BaseServiceImpl iotThingSourceDTOS = findAllByFromIdAndThingIdAndConfigTypeAndAttrCode(iotThingSourceDTO.getFromId(), + List 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 attrGroup() { + List 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 attrGroupRootId(IotThingSourceReqDTO iotThingSourceDTO) { + List iotThingSourceRelationDTOList = iotThingSourceDTO.getIotThingSourceRelationDTOList(); + if (CollectionUtil.isEmpty(iotThingSourceRelationDTOList)) { + return null; + } + List thingIds = iotThingSourceRelationDTOList.stream().map(IotThingSourceRelationDTO::getThingId).toList(); + List rootIds = iotThingSourceRelationDTOList.stream().map(IotThingSourceRelationDTO::getRootId).distinct().toList(); + + List 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 seen = new LinkedHashSet<>(); + return iotThingSourceDTOS.stream() + .filter(dto -> StringUtils.isNotBlank(dto.getThingAttrGroup()) && seen.add(dto.getThingAttrGroup())) + .toList(); + } + /** * 自定义函数去重 *