Browse Source

bug 修复

thing_master
xiachao 1 year ago
parent
commit
e533d8c02e
  1. 10
      modules/report-analysis/src/main/java/com/thing/carbon/energyloss/dto/EnergyLossReportParam.java
  2. 40
      modules/report-analysis/src/main/java/com/thing/carbon/energyloss/service/impl/EnergyLossServiceImpl.java

10
modules/report-analysis/src/main/java/com/thing/carbon/energyloss/dto/EnergyLossReportParam.java

@ -34,4 +34,14 @@ public class EnergyLossReportParam implements Serializable {
@Schema(description = "配置类型 例如:监控分析配置,用量分析配置")
private String configType;
public String getAttrCodeType(){
if(this.thingAttrCodeType.equals("date")){
return "hh";
}
if(this.thingAttrCodeType.equals("month")){
return "dd";
}
return "mm";
}
}

40
modules/report-analysis/src/main/java/com/thing/carbon/energyloss/service/impl/EnergyLossServiceImpl.java

@ -15,6 +15,7 @@ import com.thing.thing.context.service.ThingManageContextService;
import com.thing.thing.relation.detail.dto.IotThingRelationDetailDTO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -66,7 +67,8 @@ public class EnergyLossServiceImpl implements EnergyLossService {
.eq(IotThingSourceEntity::getRootId, rootId)
.eq(IotThingSourceEntity::getConfigType, param.getConfigType())
.eq(IotThingSourceEntity::getThingAttrGroup,labelGroupName)
.eq(IotThingSourceEntity::getStartStatus,"0"));
.eq(IotThingSourceEntity::getStartStatus,"0")
.eq(IotThingSourceEntity::getThingAttrCodeType,param.getAttrCodeType()));
String key=null;
if (CollectionUtil.isNotEmpty(iotThingSourceEntities)){
key = iotThingSourceEntities.get(0).getThingAttrCode();
@ -80,8 +82,8 @@ public class EnergyLossServiceImpl implements EnergyLossService {
}
//获取物 对应时间的能耗值
Map<String, BigDecimal> codeAndValueMap = new HashMap<>();
List<TsKvDTO> dataList = tsKvService.findTsKvByMultiMap(multiMap, beginTs, endTs, Boolean.FALSE);
Map<String, BigDecimal> codeAndValueMap = new HashMap<>();
if (CollectionUtil.isNotEmpty(dataList)){
codeAndValueMap = dataList.stream()
.filter(dto -> dto.getVal() != null && !dto.getVal().isEmpty())
@ -226,19 +228,27 @@ public class EnergyLossServiceImpl implements EnergyLossService {
dto.setCurrentValue(currentValue);
List<EnergyLossDTO> children = buildEnergyLossDTOListRecursive(fromIdMap,data.getToId(),codeAndValueMap);
dto.setChilds(children);
BigDecimal lastValue = children.stream()
.map(EnergyLossDTO::getCurrentValue)
.reduce(BigDecimal.ZERO, BigDecimal::add);
dto.setLastValue(lastValue);
BigDecimal differenceValue = currentValue.subtract(lastValue);
BigDecimal percentValue = currentValue.compareTo(BigDecimal.ZERO) == 0
? BigDecimal.ZERO
: differenceValue.divide(currentValue, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100));
dto.setDifferenceValue(differenceValue);
dto.setPercentValue(percentValue);
dtos.add(dto);
if(ObjectUtils.isNotEmpty(children)){
dto.setChilds(children);
BigDecimal lastValue = children.stream()
.map(EnergyLossDTO::getCurrentValue)
.reduce(BigDecimal.ZERO, BigDecimal::add);
dto.setLastValue(lastValue);
BigDecimal differenceValue = currentValue.subtract(lastValue);
BigDecimal percentValue = currentValue.compareTo(BigDecimal.ZERO) == 0
? BigDecimal.ZERO
: differenceValue.divide(currentValue, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100));
dto.setDifferenceValue(differenceValue);
dto.setPercentValue(percentValue);
dtos.add(dto);
}else {
dto.setLastValue(BigDecimal.ZERO);
dto.setChilds(new ArrayList<>());
dto.setDifferenceValue(BigDecimal.ZERO);
dto.setPercentValue(BigDecimal.ZERO);
dtos.add(dto);
}
}
return dtos;
}

Loading…
Cancel
Save