From 91280e644c50a11f2f70a7cf62906bd00c0b1326 Mon Sep 17 00:00:00 2001 From: lishuai Date: Tue, 10 Sep 2024 11:27:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E8=A1=A5=E5=8F=91=E5=92=8C?= =?UTF-8?q?=E8=B6=85=E7=BA=A7API=E8=AE=BE=E7=BD=AE=202024=E5=B9=B49?= =?UTF-8?q?=E6=9C=8810=E6=97=A511:27:12?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/AnalysisDataServiceImpl.java | 11 +- .../controller/DataReissueController.java | 37 +++ .../dto/DataReissueCalculationDTO.java | 41 +++ .../com/thing/reissue/dto/DataReissueDTO.java | 36 +++ .../reissue/dto/DataReissueSettingDTO.java | 31 +++ .../reissue/entity/DataReissueEntity.java | 66 +++++ .../reissue/mapper/DataReissueMapper.java | 16 ++ .../reissue/service/DataReissueService.java | 25 ++ .../service/impl/DataReissueServiceImpl.java | 248 ++++++++++++++++++ .../service/impl/IotThingApiServiceImpl.java | 12 +- .../controller/IotThingEntityController.java | 6 +- .../thing/entity/dto/IotThingViewDTO.java | 5 + .../entity/dto/IotThingViewSourceDTO.java | 4 +- .../impl/IotThingEntityServiceImpl.java | 2 +- 14 files changed, 529 insertions(+), 11 deletions(-) create mode 100644 modules/thing/src/main/java/com/thing/reissue/controller/DataReissueController.java create mode 100644 modules/thing/src/main/java/com/thing/reissue/dto/DataReissueCalculationDTO.java create mode 100644 modules/thing/src/main/java/com/thing/reissue/dto/DataReissueDTO.java create mode 100644 modules/thing/src/main/java/com/thing/reissue/dto/DataReissueSettingDTO.java create mode 100644 modules/thing/src/main/java/com/thing/reissue/entity/DataReissueEntity.java create mode 100644 modules/thing/src/main/java/com/thing/reissue/mapper/DataReissueMapper.java create mode 100644 modules/thing/src/main/java/com/thing/reissue/service/DataReissueService.java create mode 100644 modules/thing/src/main/java/com/thing/reissue/service/impl/DataReissueServiceImpl.java diff --git a/modules/thing/src/main/java/com/thing/device/analysisdata/service/impl/AnalysisDataServiceImpl.java b/modules/thing/src/main/java/com/thing/device/analysisdata/service/impl/AnalysisDataServiceImpl.java index 4d0d2d8..f411136 100644 --- a/modules/thing/src/main/java/com/thing/device/analysisdata/service/impl/AnalysisDataServiceImpl.java +++ b/modules/thing/src/main/java/com/thing/device/analysisdata/service/impl/AnalysisDataServiceImpl.java @@ -45,6 +45,7 @@ import com.thing.sys.security.context.TenantContext; import com.thing.sys.security.domain.SecurityUser; import com.thing.sys.security.domain.UserDetail; import com.thing.thing.context.service.ThingManageContextService; +import com.thing.thing.dictRelation.dto.IotThingDictRelationDTO; import com.thing.thing.dictRelation.param.IotThingDictRelationParamDTO; import com.thing.thing.entity.dto.IotThingViewDTO; import com.thing.thing.entity.dto.IotThingViewSourceDTO; @@ -239,7 +240,8 @@ public class AnalysisDataServiceImpl implements AnalysisDataService { ).findFirst().ifPresent(thingSourceDTO -> relationDTO.setThingAttrBoundary(thingSourceDTO.getThingAttrBoundary())); }); // 将属性列表转换为 Map,并设置给当前的 IotThingViewDTO - Map dictRelationDTOMap = relationDTOList.stream().collect(Collectors.toMap(IotThingDictRelationParamDTO::getCode, Function.identity(), (k1, k2) -> k2)); + Map dictRelationDTOMap = relationDTOList.stream() + .collect(Collectors.toMap(IotThingDictRelationParamDTO::getCode, s-> ConvertUtils.sourceToTarget(s, IotThingDictRelationDTO.class), (k1, k2) -> k2)); viewSourceDTO.setAttrs(dictRelationDTOMap); relationDTOList.forEach(relationDTO ->{ Optional first = iotThingSourceList.stream().filter(iotThingSourceDTO -> @@ -336,8 +338,8 @@ public class AnalysisDataServiceImpl implements AnalysisDataService { String val = s.getVal(); for (Map.Entry entry : infoMap.entrySet()) { IotThingViewSourceDTO entryValue = entry.getValue(); - Map attrs = entryValue.getAttrs(); - IotThingDictRelationParamDTO iotThingDictRelationDTO = attrs.get(attr_key); + Map attrs = entryValue.getAttrs(); + IotThingDictRelationDTO iotThingDictRelationDTO = attrs.get(attr_key); if (!Objects.isNull(iotThingDictRelationDTO)) { String unit = iotThingDictRelationDTO.getUnit(); dataExcel.setThingAttrUnit(unit); @@ -883,7 +885,8 @@ public class AnalysisDataServiceImpl implements AnalysisDataService { } }); // 将属性列表转换为 Map,并设置给当前的 IotThingViewDTO - Map dictRelationDTOMap = relationDTOList.stream().collect(Collectors.toMap(IotThingDictRelationParamDTO::getCode, Function.identity(), (k1, k2) -> k2)); + Map dictRelationDTOMap = relationDTOList.stream() + .collect(Collectors.toMap(IotThingDictRelationParamDTO::getCode, s-> ConvertUtils.sourceToTarget(s,IotThingDictRelationDTO.class), (k1, k2) -> k2)); viewSourceDTO.setAttrs(dictRelationDTOMap); return viewSourceDTO; }, (existingValue, newValue) -> existingValue diff --git a/modules/thing/src/main/java/com/thing/reissue/controller/DataReissueController.java b/modules/thing/src/main/java/com/thing/reissue/controller/DataReissueController.java new file mode 100644 index 0000000..528bf36 --- /dev/null +++ b/modules/thing/src/main/java/com/thing/reissue/controller/DataReissueController.java @@ -0,0 +1,37 @@ +package com.thing.reissue.controller; + +import com.thing.common.core.web.response.Result; +import com.thing.reissue.dto.DataReissueDTO; +import com.thing.reissue.service.DataReissueService; +import com.thing.sys.tenant.dto.SysTenantDTO; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@RestController +@RequestMapping("data/reissue") +@Tag(name = "数据补发") +@RequiredArgsConstructor +public class DataReissueController { + + private final DataReissueService dataReissueService; + + @PostMapping("dataReissue") + @Operation(summary = "数据补发") + public Result dataReissue(@RequestBody DataReissueDTO dataReissue) { + dataReissueService.dataReissue(dataReissue); + return new Result<>(); + } + + @GetMapping("tenantList") + @Operation(summary="侧边栏所有有数据的企业列表") + public Result> tenantList(){ + List dtos =dataReissueService.tenantList(); + return new Result>().ok(dtos); + } + + +} \ No newline at end of file diff --git a/modules/thing/src/main/java/com/thing/reissue/dto/DataReissueCalculationDTO.java b/modules/thing/src/main/java/com/thing/reissue/dto/DataReissueCalculationDTO.java new file mode 100644 index 0000000..a0fdce5 --- /dev/null +++ b/modules/thing/src/main/java/com/thing/reissue/dto/DataReissueCalculationDTO.java @@ -0,0 +1,41 @@ +package com.thing.reissue.dto; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AllArgsConstructor; +import lombok.Data; + +import java.util.List; + +/** + * 数据补发计算 + * + * @author zhenghh. 2021-12-10 + **/ +@Data +@Schema(description = "数据补发计算") +public class DataReissueCalculationDTO { + + @Schema(description = "开始时间") + private Long startTime; + @Schema(description = "结束时间") + private Long endTime; + @Schema(description = "需要计算的物") + List list; + + @Data + @AllArgsConstructor + public static class ThingCalc { + + @Schema(description = "物ID") + private Long thingId; + @Schema(description = "设备Code") + private String thingCode; + @Schema(description = "设备ID") + private String entityId; + @Schema(description = "属性列表") + private List attrList; + @Schema(description = "部门ID") + private Long deptId; + } + +} diff --git a/modules/thing/src/main/java/com/thing/reissue/dto/DataReissueDTO.java b/modules/thing/src/main/java/com/thing/reissue/dto/DataReissueDTO.java new file mode 100644 index 0000000..989f79d --- /dev/null +++ b/modules/thing/src/main/java/com/thing/reissue/dto/DataReissueDTO.java @@ -0,0 +1,36 @@ +package com.thing.reissue.dto; + +import com.thing.common.core.validator.group.DefaultGroup; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import javax.validation.constraints.NotNull; +import java.io.Serial; +import java.io.Serializable; +import java.util.List; + +@Data +@Schema(name = "看板表") +public class DataReissueDTO implements Serializable { + + @Serial + private static final long serialVersionUID = 1L; + + private Long tenantCode; + + @Schema(description = "物entityIds") + private List entityIds; + + @Schema(description = "属性") + private List attributeKey; + + @Schema(description = "开始时间(13位时间戳)") + @NotNull(message="开始时间不能为空", groups = DefaultGroup.class) + private Long startTime; + + @Schema(description = "结束时间(13位时间戳)") + @NotNull(message="结束时间不能为空", groups = DefaultGroup.class) + private Long endTime; + + +} \ No newline at end of file diff --git a/modules/thing/src/main/java/com/thing/reissue/dto/DataReissueSettingDTO.java b/modules/thing/src/main/java/com/thing/reissue/dto/DataReissueSettingDTO.java new file mode 100644 index 0000000..be8a36c --- /dev/null +++ b/modules/thing/src/main/java/com/thing/reissue/dto/DataReissueSettingDTO.java @@ -0,0 +1,31 @@ +package com.thing.reissue.dto; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.io.Serial; +import java.io.Serializable; + + +/** + * 产品 + * + * @author WangJunLong 56583086@qq.com + * @since 1.0.0 2020-09-09 + */ +@Data +@Schema(description = "url用户名密码配置") +public class DataReissueSettingDTO implements Serializable { + + @Serial + private static final long serialVersionUID = 1L; + + @Schema(description = "url") + private String url; + + @Schema(description = "用户名") + private String userName; + + @Schema(description = "密码") + private String password; +} \ No newline at end of file diff --git a/modules/thing/src/main/java/com/thing/reissue/entity/DataReissueEntity.java b/modules/thing/src/main/java/com/thing/reissue/entity/DataReissueEntity.java new file mode 100644 index 0000000..ecfdb39 --- /dev/null +++ b/modules/thing/src/main/java/com/thing/reissue/entity/DataReissueEntity.java @@ -0,0 +1,66 @@ +package com.thing.reissue.entity; + +import com.mybatisflex.annotation.Table; +import com.thing.common.orm.entity.BaseInfoEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; + +import java.io.Serial; + +@Data +@Accessors(chain = true) +@EqualsAndHashCode(callSuper=false) +@Table("iot_dashboard") +public class DataReissueEntity extends BaseInfoEntity { + @Serial + private static final long serialVersionUID = 1L; + /** + * 看板管理id + */ + private Long dashboardGroupId; + /** + * svg图片地址 + */ + private String svgUrl; + /** + * 图片地址 + */ + private String imgUrl; + /** + * 看板类型/0:svg看板,1:组态设计看板 + */ + private String type="0"; + /** + * 组态看板url + */ + private String scadaUrl; + /** + * 标题 + */ + private String title; + /** + * 高度 + */ + private String height; + /** + * 宽度 + */ + private String width; + /** + * 背景颜色 + */ + private String backgroundColor; + /** + * 背景图片 + */ + private String backgroundPicture; + /** + * 描述 + */ + private String remark; + /** + * 排序 + */ + private Integer sort; +} \ No newline at end of file diff --git a/modules/thing/src/main/java/com/thing/reissue/mapper/DataReissueMapper.java b/modules/thing/src/main/java/com/thing/reissue/mapper/DataReissueMapper.java new file mode 100644 index 0000000..9a352b7 --- /dev/null +++ b/modules/thing/src/main/java/com/thing/reissue/mapper/DataReissueMapper.java @@ -0,0 +1,16 @@ +package com.thing.reissue.mapper; + +import com.thing.common.orm.mapper.PowerBaseMapper; +import com.thing.reissue.entity.DataReissueEntity; +import org.apache.ibatis.annotations.Mapper; + +/** + * 看板表 + * + * @author zzx + * @since 1.0.0 2022-12-05 + */ +@Mapper +public interface DataReissueMapper extends PowerBaseMapper { + +} \ No newline at end of file diff --git a/modules/thing/src/main/java/com/thing/reissue/service/DataReissueService.java b/modules/thing/src/main/java/com/thing/reissue/service/DataReissueService.java new file mode 100644 index 0000000..9a9afa1 --- /dev/null +++ b/modules/thing/src/main/java/com/thing/reissue/service/DataReissueService.java @@ -0,0 +1,25 @@ +package com.thing.reissue.service; + +import com.thing.common.orm.service.IBaseService; +import com.thing.reissue.dto.DataReissueCalculationDTO; +import com.thing.reissue.dto.DataReissueDTO; +import com.thing.reissue.entity.DataReissueEntity; +import com.thing.sys.tenant.dto.SysTenantDTO; + +import java.util.List; + +/** + * 看板表 + * + * @author zzx + * @since 1.0.0 2022-12-05 + */ +public interface DataReissueService extends IBaseService { + + void dataReissue(DataReissueDTO dataReissue); + + + List tenantList(); + + +} \ No newline at end of file diff --git a/modules/thing/src/main/java/com/thing/reissue/service/impl/DataReissueServiceImpl.java b/modules/thing/src/main/java/com/thing/reissue/service/impl/DataReissueServiceImpl.java new file mode 100644 index 0000000..fbb0e48 --- /dev/null +++ b/modules/thing/src/main/java/com/thing/reissue/service/impl/DataReissueServiceImpl.java @@ -0,0 +1,248 @@ +package com.thing.reissue.service.impl; + +import cn.hutool.core.collection.CollectionUtil; +import com.alibaba.fastjson.JSONObject; +import com.fasterxml.jackson.databind.JsonNode; +import com.mybatisflex.core.query.QueryWrapper; +import com.thing.common.core.enumeration.SuperAdminEnum; +import com.thing.common.core.exception.SysException; +import com.thing.common.data.tskv.TsKvDTO; +import com.thing.common.orm.service.impl.BaseServiceImpl; +import com.thing.common.tskv.event.TsKvEvent; +import com.thing.queue.util.Topics; +import com.thing.reissue.dto.DataReissueDTO; +import com.thing.reissue.dto.DataReissueSettingDTO; +import com.thing.reissue.entity.DataReissueEntity; +import com.thing.reissue.mapper.DataReissueMapper; +import com.thing.reissue.service.DataReissueService; +import com.thing.sys.biz.service.SysParamsService; +import com.thing.sys.security.context.TenantContext; +import com.thing.sys.security.domain.SecurityUser; +import com.thing.sys.security.domain.UserDetail; +import com.thing.sys.tenant.dto.SysTenantDTO; +import com.thing.sys.tenant.mapper.SysTenantMapper; +import com.thing.sys.tenant.service.SysTenantGroupService; +import com.thing.thing.context.service.ThingManageContextService; +import com.thing.thing.dictRelation.param.IotThingDictRelationParamDTO; +import com.thing.thing.entity.dto.IotThingEntityDTO; +import jakarta.annotation.Resource; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.jetbrains.annotations.Nullable; +import org.springframework.context.ApplicationEventPublisher; +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.http.*; +import org.springframework.stereotype.Service; +import org.springframework.web.client.RestTemplate; +import org.springframework.web.util.UriComponents; +import org.springframework.web.util.UriComponentsBuilder; +import org.thingsboard.server.common.data.Device; +import org.thingsboard.server.common.data.id.DeviceId; +import org.thingsboard.server.common.data.kv.TsKvEntry; + +import java.util.*; +import java.util.stream.Collectors; + +/** + * 看板表 + * + * @author zzx + * @since 1.0.0 2022-12-05 + */ +@Slf4j +@Service +@RequiredArgsConstructor +public class DataReissueServiceImpl extends BaseServiceImpl implements DataReissueService { + + private final ThingManageContextService thingManageContextService; + + private final String DATA_REISSUE = "DATA_REISSUE"; + + @Resource + private SysParamsService sysParamsService; + + @Resource + private SysTenantMapper sysTenantDao; + + @Resource + private SysTenantGroupService sysTenantGroupService; + + @Resource + private ApplicationEventPublisher publisher; + + @Resource + private RestTemplate restTemplate; + + @Override + public QueryWrapper getWrapper(Map params) { + String dashboardGroupId = (String) params.get("dashboardGroupId"); + QueryWrapper wrapper = new QueryWrapper(); + if (StringUtils.isBlank(dashboardGroupId)) throw new SysException("看板组id为必传字段"); + wrapper.eq("dashboard_group_id", Long.valueOf(dashboardGroupId)) + .orderBy(DataReissueEntity::getSort).asc() + .orderBy(DataReissueEntity::getCreateDate).desc(); + return wrapper; + } + + + @Override + public void dataReissue(DataReissueDTO dataReissue) { + //1.获取设备列表 + List entityIdList = dataReissue.getEntityIds(); + + Long tenantCode = dataReissue.getTenantCode(); + //过滤租户 + if(Objects.isNull(tenantCode)){ + tenantCode = TenantContext.getTenantCode(SecurityUser.getUser()); + } + + List thingsDTOS; + if(CollectionUtil.isNotEmpty(entityIdList)){ + thingsDTOS = thingManageContextService.findEntityAllById(entityIdList).orElse(Collections.emptyList()); + }else{ + thingsDTOS = thingManageContextService.findEntityAllByCode(null,tenantCode,true).orElse(Collections.emptyList()); + } + if(CollectionUtil.isEmpty(thingsDTOS)){ + throw new SysException("未获取到任何设备列表,数据补发失败"); + } + List thingsAttributesList = new ArrayList<>(); + List thingIdList = thingsDTOS.stream().map(IotThingEntityDTO::getId).collect(Collectors.toList()); + //2.获取属性列表 + if(CollectionUtil.isNotEmpty(dataReissue.getAttributeKey())){ + thingsAttributesList.addAll(thingManageContextService.findDictRelationAllByEntityIdsAndCodes(thingIdList, dataReissue.getAttributeKey()).orElse(Collections.emptyList())); + }else{ + thingsAttributesList.addAll(thingManageContextService.findDictRelationAllByEntityIdsAndCodes(thingIdList, dataReissue.getAttributeKey()).orElse(Collections.emptyList())); + } + if(CollectionUtil.isEmpty(thingsAttributesList)){ + throw new SysException("未获取到任何属性列表,数据补发失败"); + } + //3.获取数据补发时间 + Long startTime = dataReissue.getStartTime(); + Long endTime = dataReissue.getEndTime(); + if(Objects.isNull(startTime) || Objects.isNull(endTime)){ + throw new SysException("时间不能为空"); + } + + String dataReissueSetJson = sysParamsService.getValue(DATA_REISSUE); + if (StringUtils.isBlank(dataReissueSetJson)) { + throw new SysException("未获取到相关的配置信息!"); + } + DataReissueSettingDTO dataReissueSettingDTO = JSONObject.parseObject(dataReissueSetJson, DataReissueSettingDTO.class); + String token = login(dataReissueSettingDTO.getUrl(), dataReissueSettingDTO.getUserName(), dataReissueSettingDTO.getPassword()); + Map> longListMap = thingsAttributesList.stream().collect(Collectors.groupingBy(IotThingDictRelationParamDTO::getEntityId)); + longListMap.forEach((k,v)->{ + boolean flag = true; + String limit = "100"; + while (flag){ + String entityCode = v.get(0).getEntityCode(); + List keyList = v.stream().map(IotThingDictRelationParamDTO::getCode).collect(Collectors.toList()); + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_JSON); + headers.set("x-authorization","Bearer " + token); + HttpEntity requestEntity = new HttpEntity<>(null , headers); + ResponseEntity responseEntity = restTemplate.exchange( + dataReissueSettingDTO.getUrl() + "/api/tenant/devices?deviceName=" + entityCode, + HttpMethod.GET, + requestEntity, + Device.class + ); + Map> timeseries = getTskvtMap(responseEntity, token, dataReissueSettingDTO, keyList, startTime, endTime,limit); +// List tsKvEntries = RestJsonConverter.toTimeseries(timeseries); +// if(CollectionUtil.isNotEmpty(tsKvEntries)){ +// pushQueue(entityCode,tsKvEntries); +// +// }else{ +// flag = false; +// } + } + }); + } + + @Nullable + private Map> getTskvtMap(ResponseEntity responseEntity, String token, DataReissueSettingDTO dataReissueSettingDTO, + List keyList, Long startTime, Long endTime,String limit) { + DeviceId deviceId = responseEntity.getBody().getId(); + HttpHeaders headers1 = new HttpHeaders(); + headers1.setContentType(MediaType.APPLICATION_JSON); + headers1.set("x-authorization","Bearer " + token); + UriComponentsBuilder uriBuilder = UriComponentsBuilder.fromHttpUrl(dataReissueSettingDTO.getUrl()) + .path("/api/plugins/telemetry/{entityType}/{entityId}/values/timeseries") + .queryParam("keys", "{keys}") + .queryParam("interval", "{interval}") + .queryParam("agg", "{agg}") + .queryParam("limit", "{limit}") + .queryParam("orderBy", "{orderBy}") + .queryParam("useStrictDataTypes", "{useStrictDataTypes}"); + + Map params = new HashMap(); + params.put("entityType", deviceId.getEntityType().name()); + params.put("entityId", deviceId.getId().toString()); + params.put("keys", String.join(",", keyList)); + params.put("interval", "0"); + params.put("agg", "NONE"); + params.put("limit", limit); + params.put("orderBy", "DESC"); + params.put("useStrictDataTypes", Boolean.toString(Boolean.FALSE)); + if (startTime != null) { + uriBuilder.queryParam("&startTs={startTs}"); + params.put("startTs", String.valueOf(startTime)); + } + if (endTime != null) { + uriBuilder.queryParam("&endTs={endTs}"); + params.put("endTs", String.valueOf(endTime)); + } + UriComponents uriComponents = uriBuilder.buildAndExpand(params); + HttpEntity requestEntity = new HttpEntity<>(null , headers1); + + + Map> timeseries = restTemplate.exchange( + uriComponents.toUri(), + HttpMethod.GET, + requestEntity, + new ParameterizedTypeReference>>() {} + ).getBody(); + return timeseries; + } + + @Override + public List tenantList() { + Map params = new HashMap<>(); + UserDetail userDetail = SecurityUser.getUser(); + Long tenantCode = TenantContext.getTenantCode(userDetail); + List tenantCodeList = new ArrayList<>(); + if(!Objects.equals(userDetail.getSuperAdmin(), SuperAdminEnum.YES.value()) + || !Objects.equals(tenantCode, userDetail.getTenantCode())) { + tenantCodeList.add(tenantCode); + //根据 编码找下级编码 + List children = sysTenantGroupService.getChildren(tenantCode); + tenantCodeList.addAll(children); + params.put("tenantCodeList",tenantCodeList); + } + return sysTenantDao.queryList(params).parallelStream().sorted(Comparator.comparingLong(SysTenantDTO::getTenantCode)).collect(Collectors.toList()); + } + + + private String login(String url, String username, String password) { + Map loginRequest = new HashMap(); + loginRequest.put("username", username); + loginRequest.put("password", password); + ResponseEntity tokenInfo = restTemplate.postForEntity(url + "/api/auth/login", loginRequest, JsonNode.class, new Object[0]); + return tokenInfo.getBody().get("token").asText(); + } + + private void pushQueue(String thingCode, List timeSeries) { + if (CollectionUtil.isEmpty(timeSeries)) { + return ; + } + List list = timeSeries.parallelStream() + .filter(tsKv -> Objects.nonNull(tsKv.getValue())) + .map(tsKv -> new TsKvDTO(thingCode, tsKv.getKey(), tsKv.getTs(), tsKv.getValueAsString())) + .toList(); + //send 队列 + publisher.publishEvent(new TsKvEvent(Topics.V1_TSKV_HISTORY.getValue(), TsKvDTO.toDataProtoList(list))); + + } + + +} \ No newline at end of file diff --git a/modules/thing/src/main/java/com/thing/thing/api/service/impl/IotThingApiServiceImpl.java b/modules/thing/src/main/java/com/thing/thing/api/service/impl/IotThingApiServiceImpl.java index 854cf23..eb0a47e 100644 --- a/modules/thing/src/main/java/com/thing/thing/api/service/impl/IotThingApiServiceImpl.java +++ b/modules/thing/src/main/java/com/thing/thing/api/service/impl/IotThingApiServiceImpl.java @@ -57,6 +57,7 @@ import org.springframework.web.util.pattern.PathPattern; import java.lang.reflect.Method; import java.util.*; import java.util.concurrent.TimeUnit; +import java.util.function.Function; import java.util.stream.Collectors; /** @@ -513,7 +514,9 @@ public class IotThingApiServiceImpl extends BaseServiceImpl> dictRelationDTOList = thingManageContextService.findDictRelationAllByIds(attrIds); Collection dictCodes = dictRelationDTOList.orElseGet(Collections::emptyList).stream().map(IotThingDictRelationDTO::getCode).toList(); paramMap.put(code, dictCodes); - // Map collect = dictRelationDTOList.orElseGet(Collections::emptyList).stream().collect(Collectors.toMap(IotThingDictRelationDTO::getCode, Function.identity(),(existing, replacement) -> existing)); + Map collect = dictRelationDTOList.orElseGet(Collections::emptyList).stream() + .collect(Collectors.toMap(IotThingDictRelationDTO::getCode, Function.identity(),(existing, replacement) -> existing)); + optional.get().setAttrs(collect); entityInfoMap.put(code, optional.get()); } }); @@ -556,7 +559,12 @@ public class IotThingApiServiceImpl extends BaseServiceImpl dictCodes = dictRelationDTOS.stream().map(IotThingDictRelationParamDTO::getCode).toList(); paramMap.put(entityCode, dictCodes); - // Map collect = dictRelationDTOS.stream().collect(Collectors.toMap(IotThingDictRelationParamDTO::getCode, Function.identity())); + + Map collect = dictRelationDTOS.stream() + .collect(Collectors.toMap(IotThingDictRelationParamDTO::getCode, + s-> ConvertUtils.sourceToTarget(s,IotThingDictRelationDTO.class) + ,(existing, replacement) -> existing)); + optional.get().setAttrs(collect); entityInfoMap.put(entityCode, optional.get()); } }); diff --git a/modules/thing/src/main/java/com/thing/thing/entity/controller/IotThingEntityController.java b/modules/thing/src/main/java/com/thing/thing/entity/controller/IotThingEntityController.java index d219e18..3f3aa30 100644 --- a/modules/thing/src/main/java/com/thing/thing/entity/controller/IotThingEntityController.java +++ b/modules/thing/src/main/java/com/thing/thing/entity/controller/IotThingEntityController.java @@ -35,6 +35,7 @@ import org.springframework.web.multipart.MultipartFile; import java.io.IOException; import java.util.List; import java.util.Map; +import java.util.Objects; /** * 物实体表 @@ -81,10 +82,11 @@ public class IotThingEntityController { @Parameter(name = "realType", description = "真实/虚拟物") @RequestParam(required = false) String realType, @Parameter(name = "tags", description = "真实/虚拟物") @RequestParam(required = false) String tags, @Parameter(name = "enableStatus", description = "停用开启")@RequestParam(required = false) String enableStatus, - @Parameter(name = "enableStatus", description = "是否是物实体/模板")@RequestParam(required = false) String templateMark, + @Parameter(name = "templateMark", description = "是否是物实体/模板")@RequestParam(required = false) String templateMark, + @Parameter(name = "tenantCode", description = "是否是物实体/模板")@RequestParam(required = false) Long tenantCode, @Parameter(name = "status", description = "在线离线状态,0离线 1在线 2错误 3未接入") @RequestParam(required = false) String status) { - List list = service.findList(orderField,order,name,type, UserContext.getRealTenantCode(),deptId,realType,tags,enableStatus,templateMark,status); + List list = service.findList(orderField,order,name,type, Objects.isNull(tenantCode) ? UserContext.getRealTenantCode() : tenantCode,deptId,realType,tags,enableStatus,templateMark,status); return new Result>().ok(list); } diff --git a/modules/thing/src/main/java/com/thing/thing/entity/dto/IotThingViewDTO.java b/modules/thing/src/main/java/com/thing/thing/entity/dto/IotThingViewDTO.java index 79a70a1..47e2ae8 100644 --- a/modules/thing/src/main/java/com/thing/thing/entity/dto/IotThingViewDTO.java +++ b/modules/thing/src/main/java/com/thing/thing/entity/dto/IotThingViewDTO.java @@ -2,6 +2,7 @@ package com.thing.thing.entity.dto; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; +import com.thing.thing.dictRelation.dto.IotThingDictRelationDTO; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import lombok.EqualsAndHashCode; @@ -10,6 +11,8 @@ import lombok.experimental.Accessors; import java.io.Serial; import java.io.Serializable; +import java.util.List; +import java.util.Map; @Data @Accessors(chain = true) @@ -97,4 +100,6 @@ public class IotThingViewDTO implements Serializable { @Schema(description = "纬度") private String lat; + private Map attrs; + } \ No newline at end of file diff --git a/modules/thing/src/main/java/com/thing/thing/entity/dto/IotThingViewSourceDTO.java b/modules/thing/src/main/java/com/thing/thing/entity/dto/IotThingViewSourceDTO.java index e1ff4dc..be468b9 100644 --- a/modules/thing/src/main/java/com/thing/thing/entity/dto/IotThingViewSourceDTO.java +++ b/modules/thing/src/main/java/com/thing/thing/entity/dto/IotThingViewSourceDTO.java @@ -28,8 +28,8 @@ public class IotThingViewSourceDTO extends IotThingViewDTO implements Serializab @Serial private static final long serialVersionUID = 1L; - @Schema(description = "物属性相关信息:主要返回给前端超级API使用") - private Map attrs; +// @Schema(description = "物属性相关信息:主要返回给前端超级API使用") +// private Map attrs; @Schema(description = "物属性集合信息:暂时使用,后期删除") private List dictList; diff --git a/modules/thing/src/main/java/com/thing/thing/entity/service/impl/IotThingEntityServiceImpl.java b/modules/thing/src/main/java/com/thing/thing/entity/service/impl/IotThingEntityServiceImpl.java index 3f0b166..d43b621 100644 --- a/modules/thing/src/main/java/com/thing/thing/entity/service/impl/IotThingEntityServiceImpl.java +++ b/modules/thing/src/main/java/com/thing/thing/entity/service/impl/IotThingEntityServiceImpl.java @@ -373,7 +373,7 @@ public class IotThingEntityServiceImpl extends BaseServiceImpl> findByCodes(Collection codes,Long tenantCode,boolean isEntity) { return Optional.ofNullable(mapper.selectListByQueryAs(QueryWrapper.create() .in(IotThingEntity::getCode, codes,CollectionUtils.isNotEmpty(codes)) - .in(IotThingEntity::getCode, codes,CollectionUtils.isNotEmpty(codes)) + .in(IotThingEntity::getTenantCode, tenantCode,!Objects.isNull(tenantCode)) .eq(IotThingEntity::getTemplateMark,isEntity? "0":"1") ,IotThingEntityDTO.class)); }