From 78382199e35d37b9ec348522c9faac81d80d3ade Mon Sep 17 00:00:00 2001 From: DYL <Dn1332079466> Date: 星期一, 10 二月 2025 19:33:49 +0800 Subject: [PATCH] 能源流向分析 --- zhitan-system/src/main/resources/mapper/model/NodeIndexMapper.xml | 10 + zhitan-system/src/main/java/com/zhitan/model/mapper/ModelNodeMapper.java | 19 + zhitan-system/src/main/java/com/zhitan/dataitem/mapper/DataItemMapper.java | 3 zhitan-system/src/main/java/com/zhitan/dataitem/service/impl/DataItemServiceImpl.java | 139 +++++++++++++ zhitan-system/src/main/resources/mapper/model/ModelNodeMapper.xml | 103 +++++++--- zhitan-system/src/main/java/com/zhitan/model/domain/NodeIndex.java | 26 ++ zhitan-system/src/main/java/com/zhitan/dataitem/service/IDataItemService.java | 10 + zhitan-system/src/main/java/com/zhitan/statisticalAnalysis/domain/vo/FlowChartsVO.java | 68 ++++++ zhitan-system/src/main/java/com/zhitan/statisticalAnalysis/domain/vo/FlowChartsItemVO.java | 34 +++ zhitan-system/src/main/java/com/zhitan/statisticalAnalysis/domain/dto/FlowChartsDTO.java | 57 +++++ zhitan-system/src/main/java/com/zhitan/model/mapper/NodeIndexMapper.java | 15 + zhitan-system/src/main/java/com/zhitan/dataitem/domain/vo/NodeIndexValueVO.java | 32 +++ zhitan-admin/src/main/java/com/zhitan/web/controller/statisticalAnalysis/EnergyDataItemController.java | 39 +++ zhitan-admin/src/main/resources/application.yml | 2 14 files changed, 520 insertions(+), 37 deletions(-) diff --git a/zhitan-admin/src/main/java/com/zhitan/web/controller/statisticalAnalysis/EnergyDataItemController.java b/zhitan-admin/src/main/java/com/zhitan/web/controller/statisticalAnalysis/EnergyDataItemController.java new file mode 100644 index 0000000..af79e0b --- /dev/null +++ b/zhitan-admin/src/main/java/com/zhitan/web/controller/statisticalAnalysis/EnergyDataItemController.java @@ -0,0 +1,39 @@ +package com.zhitan.web.controller.statisticalAnalysis; + +import com.zhitan.common.annotation.Log; +import com.zhitan.common.core.domain.AjaxResult; +import com.zhitan.dataitem.service.IDataItemService; +import com.zhitan.statisticalAnalysis.domain.dto.FlowChartsDTO; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + + +/** + * 鑳借�楃粺璁″垎鏋� + */ +@Api(tags = "鑳借�楃粺璁″垎鏋�") +@RestController +@RequestMapping("/statisticsAnalysis") +public class EnergyDataItemController { + + @Autowired + private IDataItemService dataItemService; + + /** + * 鑾峰彇鑳芥祦鍥惧舰鍒嗘瀽 + * + * @param dto 璇锋眰鍙傛暟 + * @return 缁撴灉 + */ + @Log(title = "鑾峰彇鑳芥祦鍥惧舰鍒嗘瀽") + @ApiOperation(value = "鑾峰彇鑳芥祦鍥惧舰鍒嗘瀽", notes = "鑾峰彇鑳芥祦鍥惧舰鍒嗘瀽") + @GetMapping(value = "/getFlowCharts") + public AjaxResult getFlowCharts(@Validated FlowChartsDTO dto) { + return AjaxResult.success(dataItemService.getFlowCharts(dto)); + } +} diff --git a/zhitan-admin/src/main/resources/application.yml b/zhitan-admin/src/main/resources/application.yml index b766372..86eed19 100644 --- a/zhitan-admin/src/main/resources/application.yml +++ b/zhitan-admin/src/main/resources/application.yml @@ -11,6 +11,8 @@ addressEnabled: true # 楠岃瘉鐮佺被鍨� math 鏁板瓧璁$畻 char 瀛楃楠岃瘉 captchaType: math + # 鍩熷悕鍦板潃 + domainName: https://demo-ems.zhitancloud.com/prod-api # 寮�鍙戠幆澧冮厤缃� server: diff --git a/zhitan-system/src/main/java/com/zhitan/dataitem/domain/vo/NodeIndexValueVO.java b/zhitan-system/src/main/java/com/zhitan/dataitem/domain/vo/NodeIndexValueVO.java new file mode 100644 index 0000000..33560fa --- /dev/null +++ b/zhitan-system/src/main/java/com/zhitan/dataitem/domain/vo/NodeIndexValueVO.java @@ -0,0 +1,32 @@ +package com.zhitan.dataitem.domain.vo; + +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @Author DYL + **/ +@Data +public class NodeIndexValueVO { + + /** + * 鑺傜偣id + */ + private String nodeId; + + /** + * 鑺傜偣鍚嶇О + */ + private String nodeName; + + /** + * 鐐逛綅id + */ + private String indexId; + + /** + * 绱Н閲� + */ + private BigDecimal value; +} diff --git a/zhitan-system/src/main/java/com/zhitan/dataitem/mapper/DataItemMapper.java b/zhitan-system/src/main/java/com/zhitan/dataitem/mapper/DataItemMapper.java index 2f6d9ab..94f00fe 100644 --- a/zhitan-system/src/main/java/com/zhitan/dataitem/mapper/DataItemMapper.java +++ b/zhitan-system/src/main/java/com/zhitan/dataitem/mapper/DataItemMapper.java @@ -1,5 +1,6 @@ package com.zhitan.dataitem.mapper; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.zhitan.carbonemission.domain.CarbonEmission; import com.zhitan.common.enums.TimeType; import com.zhitan.dataitem.domain.StagseDataEntry; @@ -16,7 +17,7 @@ * @author sys * @date 2020-03-25 */ -public interface DataItemMapper { +public interface DataItemMapper extends BaseMapper<DataItem> { /** * 闃舵鏁版嵁褰曞叆 * diff --git a/zhitan-system/src/main/java/com/zhitan/dataitem/service/IDataItemService.java b/zhitan-system/src/main/java/com/zhitan/dataitem/service/IDataItemService.java index 993beb7..99c2a1c 100644 --- a/zhitan-system/src/main/java/com/zhitan/dataitem/service/IDataItemService.java +++ b/zhitan-system/src/main/java/com/zhitan/dataitem/service/IDataItemService.java @@ -4,6 +4,8 @@ import com.zhitan.common.enums.TimeType; import com.zhitan.dataitem.domain.StagseDataEntry; import com.zhitan.realtimedata.domain.DataItem; +import com.zhitan.statisticalAnalysis.domain.dto.FlowChartsDTO; +import com.zhitan.statisticalAnalysis.domain.vo.FlowChartsVO; import java.math.BigDecimal; import java.util.Date; @@ -88,4 +90,12 @@ * @return */ List<DataItem> getDataItemHourInforByIndexIds(Date beginTime, Date endTime, String timeType, List<String> indexIds); + + /** + * 鑾峰彇鑳芥祦鍥惧舰鍒嗘瀽 + * + * @param dto 璇锋眰鍙傛暟 + * @return 缁撴灉 + */ + FlowChartsVO getFlowCharts(FlowChartsDTO dto); } diff --git a/zhitan-system/src/main/java/com/zhitan/dataitem/service/impl/DataItemServiceImpl.java b/zhitan-system/src/main/java/com/zhitan/dataitem/service/impl/DataItemServiceImpl.java index 1e29b7f..2f95c17 100644 --- a/zhitan-system/src/main/java/com/zhitan/dataitem/service/impl/DataItemServiceImpl.java +++ b/zhitan-system/src/main/java/com/zhitan/dataitem/service/impl/DataItemServiceImpl.java @@ -2,15 +2,29 @@ import com.zhitan.common.enums.TimeType; import com.zhitan.dataitem.domain.StagseDataEntry; +import com.zhitan.dataitem.domain.vo.NodeIndexValueVO; import com.zhitan.dataitem.mapper.DataItemMapper; import com.zhitan.dataitem.service.IDataItemService; +import com.zhitan.model.domain.ModelNode; +import com.zhitan.model.mapper.EnergyIndexMapper; +import com.zhitan.model.mapper.ModelNodeMapper; +import com.zhitan.model.mapper.NodeIndexMapper; import com.zhitan.realtimedata.domain.DataItem; +import com.zhitan.statisticalAnalysis.domain.dto.FlowChartsDTO; +import com.zhitan.statisticalAnalysis.domain.vo.FlowChartsItemVO; +import com.zhitan.statisticalAnalysis.domain.vo.FlowChartsVO; import lombok.AllArgsConstructor; +import org.apache.commons.lang3.ObjectUtils; import org.springframework.stereotype.Service; +import javax.annotation.Resource; import java.math.BigDecimal; -import java.util.Date; -import java.util.List; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.temporal.TemporalAdjusters; +import java.util.*; +import java.util.stream.Collectors; /** * stagseDataEntryService涓氬姟灞傚鐞� @@ -22,7 +36,14 @@ @AllArgsConstructor public class DataItemServiceImpl implements IDataItemService { - private final DataItemMapper dataItemMapper; + @Resource + private DataItemMapper dataItemMapper; + @Resource + private ModelNodeMapper modelNodeMapper; + @Resource + private EnergyIndexMapper energyIndexMapper; + @Resource + private NodeIndexMapper nodeIndexMapper; /** @@ -117,4 +138,116 @@ public List<DataItem> getDataItemHourInforByIndexIds(Date beginTime, Date endTime, String timeType, List<String> indexIds) { return dataItemMapper.getDataItemHourInforByIndexIds(beginTime, endTime, timeType, indexIds); } + + /** + * 鑾峰彇鑳芥祦鍥惧舰鍒嗘瀽 + * + * @param dto 璇锋眰鍙傛暟 + * @return 缁撴灉 + */ + @Override + public FlowChartsVO getFlowCharts(FlowChartsDTO dto) { + FlowChartsVO flowChartsVO = new FlowChartsVO(); + // 鐖惰妭鐐筰d + String nodeId = dto.getNodeId(); + String energyType = dto.getEnergyType(); + LocalDate queryTime = dto.getQueryTime(); + TimeType timeType = dto.getTimeType(); + + // 鑾峰彇鑺傜偣淇℃伅 + ModelNode modelNode = modelNodeMapper.selectModelNodeById(nodeId); + if (ObjectUtils.isEmpty(modelNode)) { + return flowChartsVO; + } + // 鑾峰彇鏌ヨ鏃堕棿 + Map<String, LocalDateTime> dateTimeMap = getDataItemByIndexId(timeType, queryTime); + + // 鑾峰彇鑺傜偣鍜岀偣浣嶇殑绱Н閲� + List<NodeIndexValueVO> parentDataItemList = modelNodeMapper.getDataItemByNodeId(nodeId, energyType, timeType, dateTimeMap); + + // 鑾峰彇瀛愯妭鐐逛笅鐨勭偣浣嶇殑绱Н閲� + List<NodeIndexValueVO> childDataItemList = modelNodeMapper.getDataItemByParentNodeId(nodeId, energyType, timeType, dateTimeMap); + + // 鑾峰彇鐖惰妭鐐逛笅鐨勮兘鑰楁暟鎹�诲拰 + if (ObjectUtils.isNotEmpty(parentDataItemList)) { + // 鐖惰妭鐐逛笅鐨勮兘鑰楁暟鎹�诲拰 + BigDecimal totalValue = parentDataItemList.stream().map(NodeIndexValueVO::getValue) + .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add); + // 鎬荤疮绉噺 + flowChartsVO.setTotalAccumulatedAmount(totalValue); + } + // 鑾峰彇瀛愯妭鐐逛笅鐨勮兘鑰楁暟鎹� + if (ObjectUtils.isNotEmpty(childDataItemList)) { + // 瀛愯妭鐐逛笅鐨勮兘鑰楁暟鎹�诲拰 + BigDecimal childTotalValue = childDataItemList.stream().map(NodeIndexValueVO::getValue) + .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add); + // 瀛愯妭鐐圭疮绉噺 + flowChartsVO.setChildNodeAccumulatedAmount(childTotalValue); + + // 鏍规嵁瀛愯妭鐐筰d鍒嗙粍 + Map<String, List<NodeIndexValueVO>> voMap = childDataItemList.stream() + .collect(Collectors.groupingBy(NodeIndexValueVO::getNodeId)); + List<FlowChartsItemVO> itemList = new ArrayList<>(); + + for (String childNodeId : voMap.keySet()) { + FlowChartsItemVO vo = new FlowChartsItemVO(); + vo.setSource(modelNode.getName()); + List<NodeIndexValueVO> valueList = voMap.getOrDefault(childNodeId, Collections.emptyList()); + if (ObjectUtils.isNotEmpty(valueList)) { + // 鍚勪釜瀛愯妭鐐圭殑鑳借�楁暟鎹�诲拰 + BigDecimal value = valueList.stream().map(NodeIndexValueVO::getValue) + .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add); + valueList.stream().findFirst().ifPresent(nodeIndexValueVO -> vo.setTarget(nodeIndexValueVO.getNodeName())); + vo.setValue(value); + } + itemList.add(vo); + } + flowChartsVO.setItemVOList(itemList); + } + return flowChartsVO; + } + + /** + * 鏍规嵁indexId鏌ヨ鑳借�楁暟鎹� + */ + private Map<String, LocalDateTime> getDataItemByIndexId(TimeType timeType, LocalDate queryTime) { + LocalDateTime startTime; + LocalDateTime endTime; + LocalDate startDate; + LocalDate endDate; + switch (timeType) { + case DAY: + // 褰撳ぉ鐨勫紑濮嬫椂闂� + startTime = LocalDateTime.of(queryTime, LocalTime.MIN); + // 褰撳ぉ鐨勭粨鏉熸椂闂� + endTime = LocalDateTime.of(queryTime, LocalTime.MAX); + break; + case MONTH: + // 褰撴湀鐨勫紑濮嬫椂闂� + startDate = queryTime.with(TemporalAdjusters.firstDayOfMonth()); + startTime = LocalDateTime.of(startDate, LocalTime.MIN); + // 褰撴湀鐨勭粨鏉熸椂闂� + endDate = queryTime.with(TemporalAdjusters.lastDayOfMonth()); + endTime = LocalDateTime.of(endDate, LocalTime.MAX); + break; + case YEAR: + // 褰撳勾鐨勫紑濮嬫椂闂� + startDate = queryTime.with(TemporalAdjusters.firstDayOfYear()); + startTime = LocalDateTime.of(startDate, LocalTime.MIN); + // 褰撳勾鐨勭粨鏉熸椂闂� + endDate = queryTime.with(TemporalAdjusters.lastDayOfYear()); + endTime = LocalDateTime.of(endDate, LocalTime.MAX); + break; + default: + // 褰撳ぉ鐨勫紑濮嬫椂闂� + startTime = LocalDateTime.of(queryTime, LocalTime.MIN); + // 褰撳ぉ鐨勭粨鏉熸椂闂� + endTime = LocalDateTime.of(queryTime, LocalTime.MAX); + break; + } + Map<String, LocalDateTime> localDateTimeMap = new HashMap<>(); + localDateTimeMap.put("startTime", startTime); + localDateTimeMap.put("endTime", endTime); + return localDateTimeMap; + } } diff --git a/zhitan-system/src/main/java/com/zhitan/model/domain/NodeIndex.java b/zhitan-system/src/main/java/com/zhitan/model/domain/NodeIndex.java new file mode 100644 index 0000000..b4de1e1 --- /dev/null +++ b/zhitan-system/src/main/java/com/zhitan/model/domain/NodeIndex.java @@ -0,0 +1,26 @@ +package com.zhitan.model.domain; + +import lombok.Data; + +import java.io.Serializable; + +/** + * 妯″瀷鑺傜偣涓庢寚鏍囩殑鍏宠仈鍏崇郴(NodeIndex)瀹炰綋绫� + * + * @author makejava + * @since 2025-02-10 15:08:14 + */ +@Data +public class NodeIndex implements Serializable { + private static final long serialVersionUID = 386292923712960012L; + /** + * 鑺傜偣涓婚敭 + */ + private String nodeId; + /** + * 鎸囨爣涓婚敭 + */ + private String indexId; + +} + diff --git a/zhitan-system/src/main/java/com/zhitan/model/mapper/ModelNodeMapper.java b/zhitan-system/src/main/java/com/zhitan/model/mapper/ModelNodeMapper.java index 3df1018..9b6bb93 100644 --- a/zhitan-system/src/main/java/com/zhitan/model/mapper/ModelNodeMapper.java +++ b/zhitan-system/src/main/java/com/zhitan/model/mapper/ModelNodeMapper.java @@ -5,11 +5,14 @@ import com.zhitan.basicdata.domain.MeterImplement; import com.zhitan.basicdata.domain.SysEnergy; import com.zhitan.basicdata.domain.SysProduct; +import com.zhitan.common.enums.TimeType; +import com.zhitan.dataitem.domain.vo.NodeIndexValueVO; import com.zhitan.model.domain.EnergyIndex; import com.zhitan.model.domain.ModelNode; import com.zhitan.model.domain.vo.ModelNodeIndexInfor; import org.apache.ibatis.annotations.Param; +import java.time.LocalDateTime; import java.util.List; import java.util.Map; @@ -196,4 +199,20 @@ ModelNode getFirstModeNodeInfo(String modelCode); List<ModelNodeIndexInfor> selectIndexByNodeIds(@Param("modelCode") String modelCode,@Param("nodeIds") List<String> nodeIds); + + /** + * 鏍规嵁鐖惰妭鐐筰d鍜岃兘婧愮被鍨嬫煡璇㈢偣浣嶄笅鐨勭疮绉噺 + */ + List<NodeIndexValueVO> getDataItemByParentNodeId(@Param("parentId") String parentId, + @Param("energyType") String energyType, + @Param("timeType") TimeType timeType, + @Param("dateTimeMap") Map<String, LocalDateTime> dateTimeMap); + + /** + * 鏍规嵁鑺傜偣id鍜岃兘婧愮被鍨嬫煡璇㈢偣浣嶄笅鐨勭疮绉噺 + */ + List<NodeIndexValueVO> getDataItemByNodeId(@Param("nodeId") String nodeId, + @Param("energyType") String energyType, + @Param("timeType") TimeType timeType, + @Param("dateTimeMap") Map<String, LocalDateTime> dateTimeMap); } diff --git a/zhitan-system/src/main/java/com/zhitan/model/mapper/NodeIndexMapper.java b/zhitan-system/src/main/java/com/zhitan/model/mapper/NodeIndexMapper.java new file mode 100644 index 0000000..92808f2 --- /dev/null +++ b/zhitan-system/src/main/java/com/zhitan/model/mapper/NodeIndexMapper.java @@ -0,0 +1,15 @@ +package com.zhitan.model.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.zhitan.model.domain.NodeIndex; + +/** + * 妯″瀷鑺傜偣涓庢寚鏍囩殑鍏宠仈鍏崇郴(NodeIndex)琛ㄦ暟鎹簱璁块棶灞� + * + * @author makejava + * @since 2025-02-10 15:09:17 + */ +public interface NodeIndexMapper extends BaseMapper<NodeIndex> { + +} + diff --git a/zhitan-system/src/main/java/com/zhitan/statisticalAnalysis/domain/dto/FlowChartsDTO.java b/zhitan-system/src/main/java/com/zhitan/statisticalAnalysis/domain/dto/FlowChartsDTO.java new file mode 100644 index 0000000..b9dc2f9 --- /dev/null +++ b/zhitan-system/src/main/java/com/zhitan/statisticalAnalysis/domain/dto/FlowChartsDTO.java @@ -0,0 +1,57 @@ +package com.zhitan.statisticalAnalysis.domain.dto; + +import com.baomidou.mybatisplus.annotation.EnumValue; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.zhitan.common.enums.TimeType; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import org.apache.commons.lang3.ObjectUtils; +import org.springframework.format.annotation.DateTimeFormat; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import java.time.LocalDate; + +/** + * 鑳芥祦鍥炬煡璇� + */ +@Data +public class FlowChartsDTO { + + /** + * 鑳芥簮绫诲瀷鍚嶇О + */ + @EnumValue + @ApiModelProperty(value = "鏃堕棿绫诲瀷") + private TimeType timeType; + + /** + * 鏌ヨ鏃堕棿 + */ + @NotNull(message = "鏌ヨ鏃堕棿涓嶈兘涓虹┖") + @DateTimeFormat(pattern = "yyyy-MM-dd") + @JsonFormat(pattern = "yyyy-MM-dd") + @ApiModelProperty(value = "鏌ヨ鏃堕棿") + private LocalDate queryTime; + + /** + * 鑳芥簮绫诲瀷 + */ + @NotBlank(message = "鑳芥簮绫诲瀷涓嶈兘涓虹┖") + @ApiModelProperty(value = "鑳芥簮绫诲瀷") + private String energyType; + + /** + * 鑺傜偣id + */ + @NotBlank(message = "鑺傜偣id涓嶈兘涓虹┖") + @ApiModelProperty(value = "鑺傜偣id") + private String nodeId; + + public TimeType getTimeType() { + if (ObjectUtils.isEmpty(timeType)) { + return TimeType.DAY; + } + return timeType; + } +} diff --git a/zhitan-system/src/main/java/com/zhitan/statisticalAnalysis/domain/vo/FlowChartsItemVO.java b/zhitan-system/src/main/java/com/zhitan/statisticalAnalysis/domain/vo/FlowChartsItemVO.java new file mode 100644 index 0000000..4696561 --- /dev/null +++ b/zhitan-system/src/main/java/com/zhitan/statisticalAnalysis/domain/vo/FlowChartsItemVO.java @@ -0,0 +1,34 @@ +package com.zhitan.statisticalAnalysis.domain.vo; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import java.math.BigDecimal; + +/** + * 鑳芥祦鍥炬煡璇� + */ +@Data +public class FlowChartsItemVO { + + /** + * 婧愬ご + */ + @ApiModelProperty(value = "婧愬ご") + private String source; + + /** + * 鐩爣 + */ + @ApiModelProperty(value = "鐩爣") + private String target; + + /** + * 鍊� + */ + @NotBlank(message = "鍊�") + @ApiModelProperty(value = "鍊�") + private BigDecimal value; + +} diff --git a/zhitan-system/src/main/java/com/zhitan/statisticalAnalysis/domain/vo/FlowChartsVO.java b/zhitan-system/src/main/java/com/zhitan/statisticalAnalysis/domain/vo/FlowChartsVO.java new file mode 100644 index 0000000..a0bf88e --- /dev/null +++ b/zhitan-system/src/main/java/com/zhitan/statisticalAnalysis/domain/vo/FlowChartsVO.java @@ -0,0 +1,68 @@ +package com.zhitan.statisticalAnalysis.domain.vo; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.util.Collections; +import java.util.List; + +/** + * 鑳芥祦鍥炬煡璇� + */ +@Data +public class FlowChartsVO { + + // 鎬荤疮绉噺 + @ApiModelProperty(value = "鎬荤疮绉噺") + private BigDecimal totalAccumulatedAmount; + + // 瀛愯妭鐐圭疮绉噺 + @ApiModelProperty(value = "瀛愯妭鐐圭疮绉噺") + private BigDecimal childNodeAccumulatedAmount; + + // 宸�� + @ApiModelProperty(value = "宸��") + private BigDecimal difference; + + // 鑳借�楁崯澶辨瘮渚� + @ApiModelProperty(value = "鑳借�楁崯澶辨瘮渚�") + private BigDecimal energyLossRatio; + + private List<FlowChartsItemVO> itemVOList; + + public BigDecimal getTotalAccumulatedAmount() { + if (totalAccumulatedAmount == null){ + return BigDecimal.ZERO; + } + return totalAccumulatedAmount; + } + + public BigDecimal getChildNodeAccumulatedAmount() { + if (childNodeAccumulatedAmount == null){ + return BigDecimal.ZERO; + } + return childNodeAccumulatedAmount; + } + + public BigDecimal getDifference() { + return difference = totalAccumulatedAmount.subtract(childNodeAccumulatedAmount); + } + + public BigDecimal getEnergyLossRatio() { + if (BigDecimal.ZERO.compareTo(totalAccumulatedAmount) == 0 + || BigDecimal.ZERO.compareTo(difference) == 0){ + return BigDecimal.ZERO; + } + return energyLossRatio = difference.divide(totalAccumulatedAmount, 2, RoundingMode.HALF_UP); + } + + public FlowChartsVO() { + this.totalAccumulatedAmount = BigDecimal.ZERO; + this.childNodeAccumulatedAmount = BigDecimal.ZERO; + this.difference = BigDecimal.ZERO; + this.energyLossRatio = BigDecimal.ZERO; + this.itemVOList = Collections.emptyList(); + } +} diff --git a/zhitan-system/src/main/resources/mapper/model/ModelNodeMapper.xml b/zhitan-system/src/main/resources/mapper/model/ModelNodeMapper.xml index 01c8c59..f0fe5ef 100644 --- a/zhitan-system/src/main/resources/mapper/model/ModelNodeMapper.xml +++ b/zhitan-system/src/main/resources/mapper/model/ModelNodeMapper.xml @@ -89,9 +89,9 @@ resultType="com.zhitan.model.domain.EnergyIndex"> select ei.index_id as indexId, code, name, index_type as indexType from energy_index ei - left join node_index ni on ei.index_id = ni.index_id + left join node_index ni on ei.index_id = ni.index_id where ni.node_id = #{nodeId} - and ei.index_type = #{indexType} + and ei.index_type = #{indexType} <if test="code != null and code != ''"> and code like concat('%', #{code}, '%') </if> @@ -332,11 +332,12 @@ node_category nodeCategory FROM "model_node" WHERE model_code = #{indexCode} - AND parent_id IS NULL LIMIT 1; + AND parent_id IS NULL + LIMIT 1; </select> <select id="selectIndexByModelCodeAndNodeId" resultType="com.zhitan.model.domain.vo.ModelNodeIndexInfor"> - SELECT mn.node_id nodeId, + SELECT mn.node_id nodeId, mn."name", ni.index_id indexId FROM model_node mn @@ -347,15 +348,15 @@ <select id="getSettingDeviceIndex" resultType="com.zhitan.basicdata.domain.MeterImplement"> SELECT distinct - m."id", - m.code, - m.meter_name AS meterName, - m.meter_type meterType, - m.wire_diameter wireDiameter, - m.max_allowable_power maxAllowablePower + m."id", + m.code, + m.meter_name AS meterName, + m.meter_type meterType, + m.wire_diameter wireDiameter, + m.max_allowable_power maxAllowablePower FROM meter_implement m - LEFT JOIN energy_index ei ON ei.meter_id = m."id" - LEFT JOIN node_index ni ON ni.index_id = ei.index_id + LEFT JOIN energy_index ei ON ei.meter_id = m."id" + LEFT JOIN node_index ni ON ni.index_id = ei.index_id WHERE ni.node_id = #{nodeId} <if test="energyType!=null and energyType!=''"> AND M.energy_type = #{energyType} @@ -365,11 +366,12 @@ <delete id="delIndexNodeIdAndIndexType"> delete from node_index - where node_id = #{nodeId} and index_id in ( - select ni.index_id - from node_index ni left join energy_index ei on ni.index_id = ei.index_id - where node_id = #{nodeId} and ei.index_type = #{indexType} - ); + where node_id = #{nodeId} + and index_id in (select ni.index_id + from node_index ni + left join energy_index ei on ni.index_id = ei.index_id + where node_id = #{nodeId} + and ei.index_type = #{indexType}); </delete> <insert id="setIndexAndNodeId"> <foreach collection="indexIds" item="indexId" separator=";"> @@ -379,11 +381,11 @@ </insert> <select id="getModelNodeIndexIdByNodeId" resultType="com.zhitan.model.domain.vo.ModelNodeIndexInfor"> - SELECT mn.node_id nodeId, - mn."name" "name", - ni.index_id indexId, - ei.energy_id energyId, - ei.index_type indexType + SELECT mn.node_id nodeId, + mn."name" "name", + ni.index_id indexId, + ei.energy_id energyId, + ei.index_type indexType FROM "model_node" mn LEFT JOIN "node_index" ni ON mn.node_id = ni.node_id LEFT JOIN energy_index ei on ni.index_id = ei.index_id @@ -400,16 +402,17 @@ FROM "model_node" mn LEFT JOIN "node_index" ni ON mn.node_id = ni.node_id left join energy_index ei on ni.index_id = ei.index_id - WHERE mn.parent_id = #{parentId} and ei.index_type = 'STATISTIC' + WHERE mn.parent_id = #{parentId} + and ei.index_type = 'STATISTIC' </select> <select id="getFirstModeNodeInfo" resultType="com.zhitan.model.domain.ModelNode"> <include refid="selectModelNodeVo"/> - where model_code = #{modelCode} AND parent_id is null + where model_code = #{modelCode} AND parent_id is null order by order_num </select> <select id="selectIndexByNodeIds" resultType="com.zhitan.model.domain.vo.ModelNodeIndexInfor"> - SELECT mn.node_id nodeId, - mn."name" "name", + SELECT mn.node_id nodeId, + mn."name" "name", ni.index_id indexId, ei.energy_id FROM "model_node" mn @@ -417,15 +420,49 @@ left join energy_index ei on ni.index_id = ei.index_id <where> mn.model_code = #{modelCode} - AND mn.node_id in - <foreach collection="nodeIds" index="index" item="item" open="(" separator="," close=")"> - #{item} - </foreach> - <if test="modelCode!=null and modelCode!='' and nodeIds.size>0"> - and ei.index_type='STATISTIC' - </if> + AND mn.node_id in + <foreach collection="nodeIds" index="index" item="item" open="(" separator="," close=")"> + #{item} + </foreach> + <if test="modelCode!=null and modelCode!='' and nodeIds.size>0"> + and ei.index_type='STATISTIC' + </if> </where> </select> + + <select id="getDataItemByParentNodeId" resultType="com.zhitan.dataitem.domain.vo.NodeIndexValueVO"> + SELECT mn.node_id nodeId, + mn."name" nodeName, + di.index_id indexId, + di."value" value + FROM model_node mn + LEFT JOIN "node_index" ni ON mn.node_id = ni.node_id + LEFT JOIN "energy_index" ei ON ei.index_id = ni.index_id + LEFT JOIN "data_item" di ON ei.index_id = di.index_id + WHERE mn.parent_id = #{parentId} + AND ei.energy_id = #{energyType} + AND ei.index_type = 'STATISTIC' + AND di.time_type = #{timeType.name} + AND di.data_time >= #{dateTimeMap.startTime} + AND di.data_time <= #{dateTimeMap.endTime} + </select> + + <select id="getDataItemByNodeId" resultType="com.zhitan.dataitem.domain.vo.NodeIndexValueVO"> + SELECT mn.node_id nodeId, + mn."name" nodeName, + di.index_id indexId, + di."value" value + FROM "model_node" mn + LEFT JOIN "node_index" ni ON mn.node_id = ni.node_id + LEFT JOIN "energy_index" ei ON ei.index_id = ni.index_id + LEFT JOIN "data_item" di ON ei.index_id = di.index_id + WHERE mn.node_id = #{nodeId} + AND ei.energy_id = #{energyType} + AND ei.index_type = 'STATISTIC' + AND di.time_type = #{timeType.name} + AND di.data_time >= #{dateTimeMap.startTime} + AND di.data_time <= #{dateTimeMap.endTime} + </select> </mapper> diff --git a/zhitan-system/src/main/resources/mapper/model/NodeIndexMapper.xml b/zhitan-system/src/main/resources/mapper/model/NodeIndexMapper.xml new file mode 100644 index 0000000..71e9b64 --- /dev/null +++ b/zhitan-system/src/main/resources/mapper/model/NodeIndexMapper.xml @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> +<mapper namespace="com.zhitan.model.mapper.NodeIndexMapper"> + + <resultMap type="com.zhitan.model.domain.NodeIndex" id="NodeIndexMap"> + <result property="nodeId" column="node_id" jdbcType="VARCHAR"/> + <result property="indexId" column="index_id" jdbcType="VARCHAR"/> + </resultMap> +</mapper> + -- Gitblit v1.9.3