Browse Source

Merge remote-tracking branch 'origin/master'

thing_master
xiachao 1 year ago
parent
commit
b6ec050528
  1. 7
      modules/carbon-public/src/main/java/com/thing/carbon/pub/dto/CarbonPubProductionReportDTO.java
  2. 5
      modules/carbon-public/src/main/java/com/thing/carbon/pub/dto/CockpitProductionCarbon.java
  3. 5
      modules/carbon-track/src/main/java/com/thing/carbontrack/outbound/dto/IotCarbonOutboundConfigDTO.java
  4. 7
      modules/carbon-track/src/main/java/com/thing/carbontrack/productionRecord/dto/IotCarbonProductionRecordDTO.java
  5. 7
      modules/carbon-track/src/main/java/com/thing/carbontrack/productionResult/dto/IotCarbonProductionResultDTO.java
  6. 7
      modules/carbon-track/src/main/java/com/thing/carbontrack/report/dto/IotCarbonProductionReportDTO.java
  7. 25
      modules/thing/src/main/java/com/thing/event/ThingRelationDetailUpdateEvent.java
  8. 14
      modules/thing/src/main/java/com/thing/extend/dto/TransportExtendCalculationDTO.java
  9. 2
      modules/thing/src/main/java/com/thing/extend/service/impl/TransportExtendCalculationServiceImpl.java
  10. 54
      modules/thing/src/main/java/com/thing/listener/ThingChangedUpdateRelationEventListener.java
  11. 62
      modules/thing/src/main/java/com/thing/reissue/service/impl/DataReissueServiceImpl.java
  12. 6
      modules/thing/src/main/java/com/thing/thing/entity/service/impl/IotThingEntityServiceImpl.java
  13. 2
      modules/thing/src/main/java/com/thing/thing/relation/detail/service/IotThingRelationDetailService.java
  14. 7
      modules/thing/src/main/java/com/thing/thing/relation/detail/service/impl/IotThingRelationDetailServiceImpl.java

7
modules/carbon-public/src/main/java/com/thing/carbon/pub/dto/CarbonPubProductionReportDTO.java

@ -1,5 +1,8 @@
package com.thing.carbon.pub.dto;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.thing.common.core.utils.DateTimeUtils;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@ -37,8 +40,12 @@ public class CarbonPubProductionReportDTO implements Serializable {
@Schema(description = "数据边界类型:1-自然月;2-自然年;3-自定义")
private Integer boundaryType;
@Schema(description = "数据边界开始时间")
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
@JsonFormat(pattern = DateTimeUtils.DATE_TIME_PATTERN_STR)
private Date boundaryStart;
@Schema(description = "数据边界结束时间")
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
@JsonFormat(pattern = DateTimeUtils.DATE_TIME_PATTERN_STR)
private Date boundaryEnd;
@Schema(description = "碳足迹值")
private BigDecimal totalCarbon;

5
modules/carbon-public/src/main/java/com/thing/carbon/pub/dto/CockpitProductionCarbon.java

@ -1,5 +1,8 @@
package com.thing.carbon.pub.dto;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.thing.common.core.utils.DateTimeUtils;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@ -28,5 +31,7 @@ public class CockpitProductionCarbon {
private BigDecimal carbon;
@Schema(description = "工单日期")
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
@JsonFormat(pattern = DateTimeUtils.DATE_TIME_PATTERN_STR)
private Date prDate;
}

5
modules/carbon-track/src/main/java/com/thing/carbontrack/outbound/dto/IotCarbonOutboundConfigDTO.java

@ -1,6 +1,9 @@
package com.thing.carbontrack.outbound.dto;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.thing.carbontrack.useConfig.dto.IotCarbonUseConfigDTO;
import com.thing.common.core.utils.DateTimeUtils;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@ -38,6 +41,8 @@ public class IotCarbonOutboundConfigDTO implements Serializable {
@Schema(description = "出库数量")
private Long num;
@Schema(description = "出库时间")
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
@JsonFormat(pattern = DateTimeUtils.DATE_TIME_PATTERN_STR)
private Date outboundTime;
private List<IotCarbonUseConfigDTO> configDTOList;

7
modules/carbon-track/src/main/java/com/thing/carbontrack/productionRecord/dto/IotCarbonProductionRecordDTO.java

@ -1,5 +1,8 @@
package com.thing.carbontrack.productionRecord.dto;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.thing.common.core.utils.DateTimeUtils;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@ -29,8 +32,12 @@ public class IotCarbonProductionRecordDTO implements Serializable {
@Schema(description = "生产车间")
private String workName;
@Schema(description = "生产开始时间")
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
@JsonFormat(pattern = DateTimeUtils.DATE_TIME_PATTERN_STR)
private Date startTime;
@Schema(description = "生产结束时间")
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
@JsonFormat(pattern = DateTimeUtils.DATE_TIME_PATTERN_STR)
private Date endTime;
@Schema(description = "生产数量")
private Long pNum;

7
modules/carbon-track/src/main/java/com/thing/carbontrack/productionResult/dto/IotCarbonProductionResultDTO.java

@ -1,5 +1,8 @@
package com.thing.carbontrack.productionResult.dto;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.thing.common.core.utils.DateTimeUtils;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@ -54,8 +57,12 @@ public class IotCarbonProductionResultDTO implements Serializable {
@Schema(description = "产品核算边界 1.摇篮到大门,2摇篮到坟墓")
private String boundary;
@Schema(description = "工单开始时间")
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
@JsonFormat(pattern = DateTimeUtils.DATE_TIME_PATTERN_STR)
private Date startTime;
@Schema(description = "工单完工时间")
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
@JsonFormat(pattern = DateTimeUtils.DATE_TIME_PATTERN_STR)
private Date finishTime;
@Schema(description = "生产耗时")
private Integer prDur;

7
modules/carbon-track/src/main/java/com/thing/carbontrack/report/dto/IotCarbonProductionReportDTO.java

@ -1,5 +1,8 @@
package com.thing.carbontrack.report.dto;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.thing.common.core.utils.DateTimeUtils;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@ -36,8 +39,12 @@ public class IotCarbonProductionReportDTO implements Serializable {
@Schema(description = "数据边界类型:1-自然月;2-自然年;3-自定义")
private Integer boundaryType;
@Schema(description = "数据边界开始时间")
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
@JsonFormat(pattern = DateTimeUtils.DATE_TIME_PATTERN_STR)
private Date boundaryStart;
@Schema(description = "数据边界结束时间")
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
@JsonFormat(pattern = DateTimeUtils.DATE_TIME_PATTERN_STR)
private Date boundaryEnd;
@Schema(description = "报告有效期")
private Long validEndTime;

25
modules/thing/src/main/java/com/thing/event/ThingRelationDetailUpdateEvent.java

@ -0,0 +1,25 @@
package com.thing.event;
import com.thing.thing.entity.entity.IotThingEntity;
import lombok.Getter;
import lombok.Setter;
import org.springframework.context.ApplicationEvent;
import java.util.List;
/**
* Author: SiYang
* Date: 2023/12/01 14:39
* Description: 新增物关系子节点事件
*/
@Getter
@Setter
public class ThingRelationDetailUpdateEvent extends ApplicationEvent {
private List<IotThingEntity> list;
public ThingRelationDetailUpdateEvent(Object source, List<IotThingEntity> list) {
super(source);
this.list = list;
}
}

14
modules/thing/src/main/java/com/thing/extend/dto/TransportExtendCalculationDTO.java

@ -56,20 +56,20 @@ public class TransportExtendCalculationDTO implements Serializable {
@Schema(description = "是否在线")
private Boolean online;
@Schema(description = "更新时间")
private Date lastDate;
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
@JsonFormat(pattern = DateTimeUtils.DATE_TIME_PATTERN_STR)
private Long lastDate;
@Schema(description = "创建者")
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
private Long creator;
@Schema(description = "创建时间")
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
@JsonFormat(pattern = DateTimeUtils.DATE_TIME_PATTERN_STR)
private Date createDate;
private Long createDate;
@Schema(description = "更新者")
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
private Long updater;
@Schema(description = "更新时间")
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
@JsonFormat(pattern = DateTimeUtils.DATE_TIME_PATTERN_STR)
private Date updateDate;
private Long updateDate;
}

2
modules/thing/src/main/java/com/thing/extend/service/impl/TransportExtendCalculationServiceImpl.java

@ -89,7 +89,7 @@ public class TransportExtendCalculationServiceImpl extends BaseServiceImpl<Trans
item.setInputMsg(msg.getInputMsg());
item.setOutputMsg(msg.getOutputMsg());
item.setErrorMsg(msg.getErrorMsg());
item.setLastDate(new Date(msg.getCreateDate()));
item.setLastDate(msg.getCreateDate());
}
})
.sorted(

54
modules/thing/src/main/java/com/thing/listener/ThingChangedUpdateRelationEventListener.java

@ -0,0 +1,54 @@
package com.thing.listener;
import com.thing.common.cache.constants.CacheNameEnum;
import com.thing.event.ThingRelationDetailUpdateEvent;
import com.thing.thing.cache.service.ThingCache;
import com.thing.thing.entity.entity.IotThingEntity;
import com.thing.thing.relation.detail.entity.IotThingRelationDetailEntity;
import com.thing.thing.relation.detail.service.IotThingRelationDetailService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;
import java.util.List;
/**
* @author siyang
* @date 2024/9/10 10:34
* @description 物变更事件监听器
*/
@Slf4j
@Component
@RequiredArgsConstructor
public class ThingChangedUpdateRelationEventListener {
private final IotThingRelationDetailService thingRelationDetailService;
private final ThingCache cache;
@EventListener(ThingRelationDetailUpdateEvent.class)
public void onThingChangedEvent(ThingRelationDetailUpdateEvent event) {
List<IotThingEntity> list = event.getList();
for (IotThingEntity thing : list) {
List<IotThingRelationDetailEntity> fromEntities = thingRelationDetailService.findByFromIdAndToId(thing.getId(),null);
if(CollectionUtils.isNotEmpty(fromEntities)){
for (IotThingRelationDetailEntity entity : fromEntities) {
entity.setFromName(thing.getName());
}
thingRelationDetailService.updateBatch(fromEntities);
}
List<IotThingRelationDetailEntity> toEntities = thingRelationDetailService.findByFromIdAndToId(null, thing.getId());
if(CollectionUtils.isNotEmpty(toEntities)){
for (IotThingRelationDetailEntity entity : toEntities) {
entity.setToName(thing.getName());
}
thingRelationDetailService.updateBatch(toEntities);
}
}
cache.clearTopic(CacheNameEnum.THING_DETAIL_RELATION);
}
}

62
modules/thing/src/main/java/com/thing/reissue/service/impl/DataReissueServiceImpl.java

@ -28,6 +28,7 @@ import com.thing.thing.entity.dto.IotThingEntityDTO;
import jakarta.annotation.Resource;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.Nullable;
import org.springframework.context.ApplicationEventPublisher;
@ -39,7 +40,7 @@ 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 org.thingsboard.server.common.data.kv.*;
import java.util.*;
import java.util.stream.Collectors;
@ -74,6 +75,9 @@ public class DataReissueServiceImpl extends BaseServiceImpl<DataReissueMapper, D
@Resource
private RestTemplate restTemplate;
private final Long ONE_DAY = 86400000L;
@Override
public QueryWrapper getWrapper(Map<String, Object> params) {
String dashboardGroupId = (String) params.get("dashboardGroupId");
@ -132,9 +136,8 @@ public class DataReissueServiceImpl extends BaseServiceImpl<DataReissueMapper, D
String token = login(dataReissueSettingDTO.getUrl(), dataReissueSettingDTO.getUserName(), dataReissueSettingDTO.getPassword());
Map<Long, List<IotThingDictRelationParamDTO>> longListMap = thingsAttributesList.stream().collect(Collectors.groupingBy(IotThingDictRelationParamDTO::getEntityId));
longListMap.forEach((k,v)->{
boolean flag = true;
String limit = "100";
while (flag){
Long start = startTime;
while (start < endTime){
String entityCode = v.get(0).getEntityCode();
List<String> keyList = v.stream().map(IotThingDictRelationParamDTO::getCode).collect(Collectors.toList());
HttpHeaders headers = new HttpHeaders();
@ -147,25 +150,22 @@ public class DataReissueServiceImpl extends BaseServiceImpl<DataReissueMapper, D
requestEntity,
Device.class
);
Map<String, List<JsonNode>> timeseries = getTskvtMap(responseEntity, token, dataReissueSettingDTO, keyList, startTime, endTime,limit);
// List<TsKvEntry> tsKvEntries = RestJsonConverter.toTimeseries(timeseries);
// if(CollectionUtil.isNotEmpty(tsKvEntries)){
// pushQueue(entityCode,tsKvEntries);
//
// }else{
// flag = false;
// }
Map<String, List<JsonNode>> timeseries = getTskvtMap(responseEntity, token, dataReissueSettingDTO, keyList, start, start+ONE_DAY);
if(MapUtils.isNotEmpty(timeseries)){
pushQueue(entityCode,timeseries);
}
start += ONE_DAY;
}
});
}
@Nullable
private Map<String, List<JsonNode>> getTskvtMap(ResponseEntity<Device> responseEntity, String token, DataReissueSettingDTO dataReissueSettingDTO,
List<String> keyList, Long startTime, Long endTime,String limit) {
List<String> keyList, Long startTime, Long endTime) {
DeviceId deviceId = responseEntity.getBody().getId();
HttpHeaders headers1 = new HttpHeaders();
headers1.setContentType(MediaType.APPLICATION_JSON);
headers1.set("x-authorization","Bearer " + token);
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.set("x-authorization","Bearer " + token);
UriComponentsBuilder uriBuilder = UriComponentsBuilder.fromHttpUrl(dataReissueSettingDTO.getUrl())
.path("/api/plugins/telemetry/{entityType}/{entityId}/values/timeseries")
.queryParam("keys", "{keys}")
@ -179,22 +179,21 @@ public class DataReissueServiceImpl extends BaseServiceImpl<DataReissueMapper, D
params.put("entityType", deviceId.getEntityType().name());
params.put("entityId", deviceId.getId().toString());
params.put("keys", String.join(",", keyList));
params.put("interval", "0");
params.put("interval","0");
params.put("agg", "NONE");
params.put("limit", limit);
params.put("limit", String.valueOf(Integer.MAX_VALUE));
params.put("orderBy", "DESC");
params.put("useStrictDataTypes", Boolean.toString(Boolean.FALSE));
if (startTime != null) {
uriBuilder.queryParam("&startTs={startTs}");
// uriBuilder.queryParam("&startTs={startTs}");
params.put("startTs", String.valueOf(startTime));
}
if (endTime != null) {
uriBuilder.queryParam("&endTs={endTs}");
// uriBuilder.queryParam("&endTs={endTs}");
params.put("endTs", String.valueOf(endTime));
}
UriComponents uriComponents = uriBuilder.buildAndExpand(params);
HttpEntity<String> requestEntity = new HttpEntity<>(null , headers1);
HttpEntity<String> requestEntity = new HttpEntity<>(null , headers);
Map<String, List<JsonNode>> timeseries = restTemplate.exchange(
uriComponents.toUri(),
@ -231,18 +230,17 @@ public class DataReissueServiceImpl extends BaseServiceImpl<DataReissueMapper, D
return tokenInfo.getBody().get("token").asText();
}
private void pushQueue(String thingCode, List<TsKvEntry> timeSeries) {
if (CollectionUtil.isEmpty(timeSeries)) {
private void pushQueue(String thingCode, Map<String, List<JsonNode>> timeseries) {
if (MapUtils.isEmpty(timeseries)) {
return ;
}
List<TsKvDTO> 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)));
timeseries.forEach((key, values) -> {
if(!values.isEmpty()){
List<TsKvDTO> list = values.stream().map(ts -> new TsKvDTO(thingCode, key, ts.get("ts").asLong(), ts.get("value").asText())).toList();
//send 队列
publisher.publishEvent(new TsKvEvent(Topics.V1_TSKV_HISTORY.getValue(), TsKvDTO.toDataProtoList(list)));
}
});
}
}

6
modules/thing/src/main/java/com/thing/thing/entity/service/impl/IotThingEntityServiceImpl.java

@ -23,6 +23,7 @@ import com.thing.common.data.tskv.TsKvDTO;
import com.thing.common.orm.service.impl.BaseServiceImpl;
import com.thing.common.tskv.service.TsKvService;
import com.thing.event.ThingChangedEvent;
import com.thing.event.ThingRelationDetailUpdateEvent;
import com.thing.sys.biz.entity.SysDeptEntity;
import com.thing.sys.biz.mapper.SysDeptMapper;
import com.thing.sys.oss.cloud.OSSFactory;
@ -531,6 +532,7 @@ public class IotThingEntityServiceImpl extends BaseServiceImpl<IotThingEntityMap
if (nameChanged) {
appEventPublisher.publishEvent(new ThingChangedEvent(this, thingEntity));
appEventPublisher.publishEvent(new ThingRelationDetailUpdateEvent(this, Lists.newArrayList(thingEntity)));
}
}
@ -687,12 +689,16 @@ public class IotThingEntityServiceImpl extends BaseServiceImpl<IotThingEntityMap
.setAuthNum(1L)
.setStatusTs(DateTimeUtils.getCurrentTime())
.setOrigin(QueueOriginType.MQTT_CLIENT.name())
.setRealType(data.getRealType())
.setToken(TokenGenerator.generateValue())).toList();
if(CollectionUtils.isNotEmpty(modelEntities)){
modelService.saveOrUpdateBatch(modelEntities);
}
cache.clearTopic(CacheNameEnum.THING_MODEL);
cache.clearTopic(CacheNameEnum.THING_ENTITY);
appEventPublisher.publishEvent(new ThingRelationDetailUpdateEvent(this, list));
}
}

2
modules/thing/src/main/java/com/thing/thing/relation/detail/service/IotThingRelationDetailService.java

@ -25,6 +25,8 @@ public interface IotThingRelationDetailService extends IBaseService<IotThingRela
IotThingRelationDetailEntity findByRootIdAndRootThingId(Long rootId,Long rootThingId);
List<IotThingRelationDetailEntity> findByFromIdAndToId(Long fromId,Long toId);
List<IotThingRelationDetailDTO> findByRootId(Long rootId);
Long findByMaxSort(Long rootId);

7
modules/thing/src/main/java/com/thing/thing/relation/detail/service/impl/IotThingRelationDetailServiceImpl.java

@ -191,6 +191,13 @@ public class IotThingRelationDetailServiceImpl extends BaseServiceImpl<IotThingR
.eq(IotThingRelationDetailEntity::getFromId, rootId));
}
@Override
public List<IotThingRelationDetailEntity> findByFromIdAndToId(Long fromId, Long toId) {
return mapper.selectListByQuery(QueryWrapper.create()
.eq(IotThingRelationDetailEntity::getToId, toId,!Objects.isNull(toId))
.eq(IotThingRelationDetailEntity::getFromId, fromId,!Objects.isNull(fromId)));
}
@Override
public List<IotThingRelationDetailDTO> findByRootId(Long rootId) {
return mapper.selectListByQueryAs(QueryWrapper.create()

Loading…
Cancel
Save