Browse Source

配置中心增加俩个字段

2024年9月11日17:03:21
thing_master
lishuai 2 years ago
parent
commit
1c85fc4ca2
  1. 12
      modules/thing/src/main/java/com/thing/device/source/controller/IotThingSourceController.java
  2. 4
      modules/thing/src/main/java/com/thing/device/source/dto/IotThingSourceDTO.java
  3. 4
      modules/thing/src/main/java/com/thing/device/source/dto/IotThingSourceListDTO.java
  4. 3
      modules/thing/src/main/java/com/thing/device/source/entity/IotThingSourceEntity.java
  5. 7
      modules/thing/src/main/java/com/thing/device/source/service/IotThingSourceService.java
  6. 65
      modules/thing/src/main/java/com/thing/device/source/service/impl/IotThingSourceServiceImpl.java

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();
}
/**
* 自定义函数去重
*

Loading…
Cancel
Save