|
|
@ -15,6 +15,7 @@ import com.thing.thing.context.service.ThingManageContextService; |
|
|
import com.thing.thing.relation.detail.dto.IotThingRelationDetailDTO; |
|
|
import com.thing.thing.relation.detail.dto.IotThingRelationDetailDTO; |
|
|
import lombok.RequiredArgsConstructor; |
|
|
import lombok.RequiredArgsConstructor; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
|
import org.apache.commons.lang3.ObjectUtils; |
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
@ -66,7 +67,8 @@ public class EnergyLossServiceImpl implements EnergyLossService { |
|
|
.eq(IotThingSourceEntity::getRootId, rootId) |
|
|
.eq(IotThingSourceEntity::getRootId, rootId) |
|
|
.eq(IotThingSourceEntity::getConfigType, param.getConfigType()) |
|
|
.eq(IotThingSourceEntity::getConfigType, param.getConfigType()) |
|
|
.eq(IotThingSourceEntity::getThingAttrGroup,labelGroupName) |
|
|
.eq(IotThingSourceEntity::getThingAttrGroup,labelGroupName) |
|
|
.eq(IotThingSourceEntity::getStartStatus,"0")); |
|
|
|
|
|
|
|
|
.eq(IotThingSourceEntity::getStartStatus,"0") |
|
|
|
|
|
.eq(IotThingSourceEntity::getThingAttrCodeType,param.getAttrCodeType())); |
|
|
String key=null; |
|
|
String key=null; |
|
|
if (CollectionUtil.isNotEmpty(iotThingSourceEntities)){ |
|
|
if (CollectionUtil.isNotEmpty(iotThingSourceEntities)){ |
|
|
key = iotThingSourceEntities.get(0).getThingAttrCode(); |
|
|
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); |
|
|
List<TsKvDTO> dataList = tsKvService.findTsKvByMultiMap(multiMap, beginTs, endTs, Boolean.FALSE); |
|
|
|
|
|
Map<String, BigDecimal> codeAndValueMap = new HashMap<>(); |
|
|
if (CollectionUtil.isNotEmpty(dataList)){ |
|
|
if (CollectionUtil.isNotEmpty(dataList)){ |
|
|
codeAndValueMap = dataList.stream() |
|
|
codeAndValueMap = dataList.stream() |
|
|
.filter(dto -> dto.getVal() != null && !dto.getVal().isEmpty()) |
|
|
.filter(dto -> dto.getVal() != null && !dto.getVal().isEmpty()) |
|
|
@ -226,19 +228,27 @@ public class EnergyLossServiceImpl implements EnergyLossService { |
|
|
dto.setCurrentValue(currentValue); |
|
|
dto.setCurrentValue(currentValue); |
|
|
|
|
|
|
|
|
List<EnergyLossDTO> children = buildEnergyLossDTOListRecursive(fromIdMap,data.getToId(),codeAndValueMap); |
|
|
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; |
|
|
return dtos; |
|
|
} |
|
|
} |
|
|
|