Răsfoiți Sursa

静态指标:处理停电时户数

lisonglin 3 săptămâni în urmă
părinte
comite
22dd8954f3

+ 2 - 2
services/load-transfer-bf/src/main/java/com/hdkj/lt/bf/entity/vo/StaticGridDashboardVO.java

@@ -74,8 +74,8 @@ public class StaticGridDashboardVO implements Serializable {
     // 二、供电可靠性
     // ============================================================
 
-    @ApiModelProperty(value = "停电时户数(预留,来自运行台账)")
-    private Integer outageDurationHoursHouseholds;
+    @ApiModelProperty(value = "停电时户数")
+    private BigDecimal outageDurationHoursHouseholds;
 
     @ApiModelProperty(value = "线路N-1通过率(%)")
     private BigDecimal lineNMinus1PassRate;

+ 6 - 0
services/load-transfer-bf/src/main/java/com/hdkj/lt/bf/mapper/SjztPwwyyqxtPrmPdrOutageMvDsMapper.java

@@ -3,6 +3,11 @@ package com.hdkj.lt.bf.mapper;
 import com.hdkj.lt.bf.entity.SjztPwwyyqxtPrmPdrOutageMvDs;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.math.BigDecimal;
+import java.time.LocalDateTime;
+import java.util.List;
 
 /**
 * @author lenovo
@@ -13,6 +18,7 @@ import org.apache.ibatis.annotations.Mapper;
 @Mapper
 public interface SjztPwwyyqxtPrmPdrOutageMvDsMapper extends BaseMapper<SjztPwwyyqxtPrmPdrOutageMvDs> {
 
+    BigDecimal selectStaticOutageDurationHoursHouseholds(@Param("feederNameList")List<String> feederNameList, @Param("startOfMonth")LocalDateTime startOfMonth, @Param("endOfToday")LocalDateTime endOfToday);
 }
 
 

+ 4 - 0
services/load-transfer-bf/src/main/java/com/hdkj/lt/bf/service/SjztPwwyyqxtPrmPdrOutageMvDsService.java

@@ -3,6 +3,9 @@ package com.hdkj.lt.bf.service;
 import com.hdkj.lt.bf.entity.SjztPwwyyqxtPrmPdrOutageMvDs;
 import com.baomidou.mybatisplus.extension.service.IService;
 
+import java.math.BigDecimal;
+import java.util.List;
+
 /**
 * @author lenovo
 * @description 针对表【sjzt_pwwyyqxt_prm_pdr_outage_mv_ds(un4113_02_pwwyyqxt_prm_pdr_outage_mv_ds)】的数据库操作Service
@@ -10,4 +13,5 @@ import com.baomidou.mybatisplus.extension.service.IService;
 */
 public interface SjztPwwyyqxtPrmPdrOutageMvDsService extends IService<SjztPwwyyqxtPrmPdrOutageMvDs> {
 
+    BigDecimal selectStaticOutageDurationHoursHouseholds(List<String> feederNameList);
 }

+ 21 - 0
services/load-transfer-bf/src/main/java/com/hdkj/lt/bf/service/impl/SjztPwwyyqxtPrmPdrOutageMvDsServiceImpl.java

@@ -4,8 +4,15 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.hdkj.lt.bf.entity.SjztPwwyyqxtPrmPdrOutageMvDs;
 import com.hdkj.lt.bf.service.SjztPwwyyqxtPrmPdrOutageMvDsService;
 import com.hdkj.lt.bf.mapper.SjztPwwyyqxtPrmPdrOutageMvDsMapper;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.math.BigDecimal;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+import java.util.List;
+
 /**
 * @author lenovo
 * @description 针对表【sjzt_pwwyyqxt_prm_pdr_outage_mv_ds(un4113_02_pwwyyqxt_prm_pdr_outage_mv_ds)】的数据库操作Service实现
@@ -15,6 +22,20 @@ import org.springframework.stereotype.Service;
 public class SjztPwwyyqxtPrmPdrOutageMvDsServiceImpl extends ServiceImpl<SjztPwwyyqxtPrmPdrOutageMvDsMapper, SjztPwwyyqxtPrmPdrOutageMvDs>
     implements SjztPwwyyqxtPrmPdrOutageMvDsService{
 
+    @Autowired
+    private SjztPwwyyqxtPrmPdrOutageMvDsMapper prmPdrOutageMvDsMapper;
+
+    /**
+     * 停电时户数查询(静态指标)
+     * @param feederNameList
+     * @return
+     */
+    @Override
+    public BigDecimal selectStaticOutageDurationHoursHouseholds(List<String> feederNameList) {
+        LocalDateTime startOfMonth = LocalDate.now().withDayOfMonth(1).atStartOfDay();
+        LocalDateTime endOfToday = LocalDateTime.of(LocalDate.now(), LocalTime.MAX);
+        return prmPdrOutageMvDsMapper.selectStaticOutageDurationHoursHouseholds(feederNameList,startOfMonth,endOfToday);
+    }
 }
 
 

+ 55 - 6
services/load-transfer-bf/src/main/java/com/hdkj/lt/bf/service/staticgrid/impl/StaticGridDashboardServiceImpl.java

@@ -2,13 +2,15 @@ package com.hdkj.lt.bf.service.staticgrid.impl;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.hdkj.fhzg.optimization.response.FeederGroupTreeNode;
+import com.hdkj.lt.bf.application.FeederGroupApplication;
 import com.hdkj.lt.bf.entity.staticgrid.StaticIndicatorMetric;
 import com.hdkj.lt.bf.entity.staticgrid.StaticIndicatorResult;
-import com.hdkj.lt.bf.entity.staticgrid.StaticProblemDetail;
 import com.hdkj.lt.bf.entity.vo.StaticGridDashboardVO;
 import com.hdkj.lt.bf.mapper.staticgrid.StaticIndicatorMetricMapper;
 import com.hdkj.lt.bf.mapper.staticgrid.StaticIndicatorResultMapper;
 import com.hdkj.lt.bf.mapper.staticgrid.StaticProblemDetailMapper;
+import com.hdkj.lt.bf.service.SjztPwwyyqxtPrmPdrOutageMvDsService;
 import com.hdkj.lt.bf.service.staticgrid.StaticGridDashboardService;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
@@ -41,6 +43,8 @@ public class StaticGridDashboardServiceImpl
 
     private final StaticIndicatorMetricMapper metricMapper;
     private final StaticProblemDetailMapper problemDetailMapper;
+    private final FeederGroupApplication feederGroupApplication;
+    private final SjztPwwyyqxtPrmPdrOutageMvDsService pwwyyqxtPrmPdrOutageMvDsService;
 
     @Override
     public StaticGridDashboardVO queryLatestDashboard() {
@@ -82,7 +86,7 @@ public class StaticGridDashboardServiceImpl
                 .eq(StaticIndicatorMetric::getResultId, resultId)
                 .eq(StaticIndicatorMetric::getLevel, "county");
         List<StaticIndicatorMetric> countyMetrics = metricMapper.selectList(metricWrapper);
-        Map<String, String> countyMetricMap = new HashMap<String, String>();
+        Map<String, String> countyMetricMap = new HashMap<>();
         for (StaticIndicatorMetric m : countyMetrics) {
             countyMetricMap.put(m.getMetricCode(), m.getValue());
         }
@@ -120,15 +124,15 @@ public class StaticGridDashboardServiceImpl
                 .wiringStandardizationRate(toBigDecimal(countyMetricMap.get("wiring_standardization_rate")))
                 .mainTrunkSectionStandardizationRate(toBigDecimal(countyMetricMap.get("main_trunk_section_standardization_rate")))
                 // 二、供电可靠性
-                .outageDurationHoursHouseholds(null)  // 预留:运行台账
+                .outageDurationHoursHouseholds(handleOutageDurationHoursHouseholds("BD69707EA19E4FED85C595AFB5D06720","BA6481B8F34143FDA7E1C35A76846911"))  // 暂时写死:洪湖7.1—现在的停电时户数
                 .lineNMinus1PassRate(toBigDecimal(countyMetricMap.get("n_minus_1_pass_rate")))
-                .interSubstationNoConnectionCount(toInteger(countyMetricMap.get("inter_substation_interconnection_rate"))) // 站间联络率相关
+                .interSubstationNoConnectionCount(toInteger(countyMetricMap.get("inter_substation_interconnection_rate")))
                 .sameBusInterconnectionIssueCount(toInteger(countyMetricMap.get("same_bus_interconnection_issue_count")))
                 .excessiveTiePointFeederCount(toInteger(countyMetricMap.get("excessive_tie_point_feeder_count")))
                 .singleRadialFeederCount(toInteger(countyMetricMap.get("single_radial_feeder_count")))
                 .largeBranchFeederCount(toInteger(countyMetricMap.get("large_branch_issue_feeder_count")))
                 .unreasonableSegmentCount(toInteger(countyMetricMap.get("unreasonable_segment_count_feeder_count")))
-                .mainTrunkSegmentDenseCount(null)  // 预留
+                .mainTrunkSegmentDenseCount(toInteger(countyMetricMap.get("main_trunk_lantern_issue_feeder_count")))
                 // 三、电压质量
                 .iecUserVoltageIndex(null)  // 预留
                 .supplyRadiusExceedFeederCount(toInteger(countyMetricMap.get("supply_radius_exceed_feeder_count")))
@@ -137,7 +141,7 @@ public class StaticGridDashboardServiceImpl
                 .regionalMaxLoadRate(null)  // 预留:运行态指标
                 .regionalAvgLoadRate(null)  // 预留:运行态指标
                 .lineOverloadCount(null)  // 预留:运行态指标
-                .mainTrunkSectionMismatchCount(null)  // 预留
+                .mainTrunkSectionMismatchCount(toInteger(countyMetricMap.get("main_trunk_bottleneck_feeder_count")))
                 .connectedCapacityExceedFeederCount(toInteger(countyMetricMap.get("connected_capacity_exceed_feeder_count")))
                 .loadGroupCapacityAnomalyCount(toInteger(countyMetricMap.get("load_group_capacity_anomaly_count")))
                 .comprehensiveLossRate(null)  // 预留:运行态指标
@@ -147,6 +151,51 @@ public class StaticGridDashboardServiceImpl
                 .build();
     }
 
+    //处理停电时户数
+    public BigDecimal handleOutageDurationHoursHouseholds(String cityId, String maintOrgId){
+        List<FeederGroupTreeNode> feederGroupTree = feederGroupApplication.getFeederGroupTree();
+        FeederGroupTreeNode type1 = findNodeRecursively(feederGroupTree,1,cityId);
+        if (type1 == null) {
+            return null;
+        }
+        FeederGroupTreeNode type2 = findNodeRecursively(feederGroupTree,2,maintOrgId);
+        if (type2 == null) {
+            return null;
+        }
+        List<String> type4Result = new ArrayList<>();
+        collectNodesByType(type2.getChildren(),type4Result);
+        return pwwyyqxtPrmPdrOutageMvDsService.selectStaticOutageDurationHoursHouseholds(type4Result);
+    }
+
+
+
+    //递归树
+    private FeederGroupTreeNode findNodeRecursively(List<FeederGroupTreeNode> nodes,int nodeType, String targetId){
+        if (nodes == null || nodes.isEmpty()) return null;
+        for (FeederGroupTreeNode node : nodes) {
+            if (node.getType() == nodeType && node.getId().equals(targetId)){
+                return node;
+            }
+            if (node.getChildren() != null && !node.getChildren().isEmpty()){
+                FeederGroupTreeNode found = findNodeRecursively(node.getChildren(), nodeType, targetId);
+                if (found != null) return found;
+            }
+        }
+        return null;
+    }
+
+    //收集树线路节点
+    private void collectNodesByType(List<FeederGroupTreeNode> nodes, List<String> collector) {
+        if (nodes == null || nodes.isEmpty()) return;
+        for (FeederGroupTreeNode node : nodes) {
+            if (node.getType() == 4) {
+                collector.add(node.getName());
+            } else if (node.getChildren()!= null && !node.getChildren().isEmpty()) {
+                collectNodesByType(node.getChildren(),collector);
+            }
+        }
+    }
+
     private BigDecimal toBigDecimal(String value) {
         if (StringUtils.isBlank(value)) {
             return null;

+ 12 - 0
services/load-transfer-bf/src/main/resources/mapper/SjztPwwyyqxtPrmPdrOutageMvDsMapper.xml

@@ -104,4 +104,16 @@
         city_auditor_time,province_auditor,headquarters_auditor,
         change_hc_num,locked_status
     </sql>
+
+    <select id="selectStaticOutageDurationHoursHouseholds" resultType="BigDecimal">
+        select SUM(td.outage_hc_num)
+        from sjzt_pwwyyqxt_prm_pdr_outage_mv_ds td
+        inner join(
+            <foreach collection="feederNameList" item="line" separator="UNION ALL">
+                select #{line} AS c
+            </foreach>
+        ) AS tmp ON td.outage_feeder_name = tmp.c
+        where td.outage_stime &gt; #{startOfMonth}
+        and td.outage_stime &lt; #{endOfToday}
+    </select>
 </mapper>