Просмотр исходного кода

计划解析-删除关联表问题修复

liruikang 6 месяцев назад
Родитель
Сommit
ba7402e3c3

+ 35 - 0
services/load-transfer-mq/src/main/java/com/hdkj/lt/mq/mapper/plan/FhzgPlanAnalyzeCalculateDecudeMapper.java

@@ -77,4 +77,39 @@ public interface FhzgPlanAnalyzeCalculateDecudeMapper {
 
     void deleteSwitchSectionByConnect(@Param("planId") Long planId);
 
+    void deleteSwitchingLoopCheckByPlanId(Long planId);
+
+    void deleteSwitchingFinalCheckByPlanId(Long planId);
+
+    void deleteLoopSwCurrentDetailByPlanId(Long planId);
+
+    void deleteLoopSegCurrentDetailByPlanId(Long planId);
+
+    void deleteFinalSwCurrentDetailByPlanId(Long planId);
+
+    void deleteFinalSegCurrentDetailByPlanId(Long planId);
+
+    void deleteSwitchingSequenceByPlanId(Long planId);
+
+    void deleteBreakerSvgAfterByPlanId(Long planId);
+
+    void deletePathDetailByPlanId(Long planId);
+
+    void deleteOppositeLineLoadFactorByPlanId(Long planId);
+
+    void deleteSchemeUsersByPlanId(Long planId);
+
+    void deleteTransferableSchemeUsersByPlanId(Long planId);
+
+    void deleteOppositeLineConcatSwitchByPlanId(Long planId);
+
+    void deleteEvaluationIndexByPlanId(Long planId);
+
+    void deleteStrategyScoreByPlanId(Long planId);
+
+    void deleteCarryCapacityByPlanId(Long planId);
+
+    void deleteAwaitTransferUsersByPlanId(Long planId);
+
+    void deleteTransferSchemeByPlanId(Long planId);
 }

+ 333 - 126
services/load-transfer-mq/src/main/java/com/hdkj/lt/mq/mapper/plan/mapping/FhzgPlanAnalyzeCalculateDecudeMapper.xml

@@ -3,109 +3,134 @@
 <mapper namespace="com.hdkj.lt.mq.mapper.plan.FhzgPlanAnalyzeCalculateDecudeMapper">
 
     <select id="getLineNameByPlanId" resultType="com.hdkj.lt.mq.entity.po.FhzgPlanPowerCut">
-        select line_id,line_name from fhzg_plan_power_cut
+        select line_id, line_name
+        from fhzg_plan_power_cut
         where id = #{planId}
     </select>
 
     <select id="getSwitchSection" resultType="com.hdkj.lt.core.bizms.modle.po.plan.FhzgPlanAwaitTransferSwitchSection">
         WITH RECURSIVE hierarchy AS (
-            SELECT psr_id, `name`, start_kg_id, psr_type, psr_id link_id
-            FROM t_feeder_topo
-            WHERE feeder = #{feeder}
-            AND psr_id  = #{psrId}
-            UNION ALL
-            SELECT child.psr_id, child.name, child.start_kg_id, child.psr_type,
-                if(child.normal_open = 'true', '-', child.psr_id) link_id
-            FROM t_feeder_topo child
-            JOIN hierarchy parent ON child.start_kg_id = parent.psr_id
-            WHERE child.feeder = #{feeder}
-            AND child.psr_type IN
-            <foreach collection = 'kgPsrType' item = 'item' open = '(' separator = ',' close = ')'>
-                #{item}
-            </foreach>
+        SELECT psr_id, `name`, start_kg_id, psr_type, psr_id link_id
+        FROM t_feeder_topo
+        WHERE feeder = #{feeder}
+        AND psr_id = #{psrId}
+        UNION ALL
+        SELECT child.psr_id, child.name, child.start_kg_id, child.psr_type,
+        if(child.normal_open = 'true', '-', child.psr_id) link_id
+        FROM t_feeder_topo child
+        JOIN hierarchy parent ON child.start_kg_id = parent.psr_id
+        WHERE child.feeder = #{feeder}
+        AND child.psr_type IN
+        <foreach collection='kgPsrType' item='item' open='(' separator=',' close=')'>
+            #{item}
+        </foreach>
         ) SELECT parent.psr_id AS startSwitchId, parent.name AS startSwitchName, parent.psr_type as startSwitchType,
-            GROUP_CONCAT(child.psr_id SEPARATOR ',') AS endSwitchId,GROUP_CONCAT(child.name SEPARATOR ',') AS endSwitchName
-        FROM  hierarchy child RIGHT JOIN hierarchy parent ON child.start_kg_id = parent.psr_id where parent.link_id != '-'
+        GROUP_CONCAT(child.psr_id SEPARATOR ',') AS endSwitchId,GROUP_CONCAT(child.name SEPARATOR ',') AS endSwitchName
+        FROM hierarchy child RIGHT JOIN hierarchy parent ON child.start_kg_id = parent.psr_id where parent.link_id !=
+        '-'
         GROUP BY parent.psr_id, parent.name, parent.psr_type
     </select>
 
-    <insert id="saveSwitchSectionBatch" parameterType="com.hdkj.lt.core.bizms.modle.po.plan.FhzgPlanAwaitTransferSwitchSection"
+    <insert id="saveSwitchSectionBatch"
+            parameterType="com.hdkj.lt.core.bizms.modle.po.plan.FhzgPlanAwaitTransferSwitchSection"
             useGeneratedKeys="true" keyProperty="id">
-        insert into fhzg_plan_await_transfer_switch_section(plan_id,switch_name,start_switch_id,start_switch_name,area_psr_id,
-                                                            start_switch_type,end_switch_id,end_switch_name,switch_loads,creator,create_time)
+        insert into
+        fhzg_plan_await_transfer_switch_section(plan_id,switch_name,start_switch_id,start_switch_name,area_psr_id,
+        start_switch_type,end_switch_id,end_switch_name,switch_loads,creator,create_time)
         values
-        <foreach collection = 'switchSectionList' item = 'switchSection' separator = ',' >
+        <foreach collection='switchSectionList' item='switchSection' separator=','>
             (#{switchSection.planId},#{switchSection.switchName},#{switchSection.startSwitchId},#{switchSection.startSwitchName},
             #{switchSection.areaPsrId},#{switchSection.startSwitchType},#{switchSection.endSwitchId},#{switchSection.endSwitchName},
             #{switchSection.switchLoads},'111',NOW())
         </foreach>
     </insert>
 
-    <select id="getSwitchSectionList" resultType="com.hdkj.lt.core.bizms.modle.po.plan.FhzgPlanAwaitTransferSwitchSection">
+    <select id="getSwitchSectionList"
+            resultType="com.hdkj.lt.core.bizms.modle.po.plan.FhzgPlanAwaitTransferSwitchSection">
         select t.* from (
-            select t.psr_id, if(count(t.id) > 1, max(kg_section_id), max(id)) id,
-                   if(count(t.id) > 1, max(kg_id), max(start_switch_id)) start_switch_id,
-                   if(count(t.id) > 1, max(kg_name), max(start_switch_name)) start_switch_name
-            from (
-                select ifnull(c.join_ec,a.psr_id) psr_id, b.id, b.start_switch_id, b.start_switch_name,
-                       e.id kg_section_id, b.start_switch_id kg_id, e.start_switch_name kg_name
-                  from t_feeder_topo a
-                  join fhzg_plan_await_transfer_switch_section b on a.start_kg_id = b.start_switch_id
-                  left join dwd_shb_ds_joinec_transformer_base c on a.psr_id = c.psr_id
-                  left join t_feeder_topo d on a.start_kg_id = d.psr_id
-                  left join fhzg_plan_await_transfer_switch_section e on d.start_kg_id = e.start_switch_id
-                 where a.psr_type in
-                <foreach collection='kgPsrType' item='item' open='(' separator=',' close=')'>
-                    #{item}
-                </foreach>
-                   and a.feeder = #{feeder}
-                   and b.plan_id = #{planId}
-            ) t group by t.psr_id
+        select t.psr_id, if(count(t.id) > 1, max(kg_section_id), max(id)) id,
+        if(count(t.id) > 1, max(kg_id), max(start_switch_id)) start_switch_id,
+        if(count(t.id) > 1, max(kg_name), max(start_switch_name)) start_switch_name
+        from (
+        select ifnull(c.join_ec,a.psr_id) psr_id, b.id, b.start_switch_id, b.start_switch_name,
+        e.id kg_section_id, b.start_switch_id kg_id, e.start_switch_name kg_name
+        from t_feeder_topo a
+        join fhzg_plan_await_transfer_switch_section b on a.start_kg_id = b.start_switch_id
+        left join dwd_shb_ds_joinec_transformer_base c on a.psr_id = c.psr_id
+        left join t_feeder_topo d on a.start_kg_id = d.psr_id
+        left join fhzg_plan_await_transfer_switch_section e on d.start_kg_id = e.start_switch_id
+        where a.psr_type in
+        <foreach collection='kgPsrType' item='item' open='(' separator=',' close=')'>
+            #{item}
+        </foreach>
+        and a.feeder = #{feeder}
+        and b.plan_id = #{planId}
+        ) t group by t.psr_id
         ) t where t.psr_id in
-        <foreach collection = 'psyIdList' item = 'item' open = '(' separator = ',' close = ')'>
+        <foreach collection='psyIdList' item='item' open='(' separator=',' close=')'>
             #{item}
         </foreach>
     </select>
     <select id="getLineVoltageByLineId" resultType="com.hdkj.lt.mq.entity.vo.FeederDeviceVO">
         select t.psr_id,t.name,t.feeder_rate_capacity,s.LABEL volt_value
-          from dwd_shb_ds_feeder_base t
-          join sys_dict_data s on t.voltage_level=s.dict_value
-          join sys_dict_type d on d.dict_type = s.dict_type
-         where d.dict_type = 'voltage_level_map'
-           and t.psr_id in
-        <foreach collection = 'lineIds' item = 'item' open = '(' separator = ',' close = ')'>#{item}</foreach>
+        from dwd_shb_ds_feeder_base t
+        join sys_dict_data s on t.voltage_level=s.dict_value
+        join sys_dict_type d on d.dict_type = s.dict_type
+        where d.dict_type = 'voltage_level_map'
+        and t.psr_id in
+        <foreach collection='lineIds' item='item' open='(' separator=',' close=')'>#{item}</foreach>
     </select>
 
     <update id="updateSwitchSectionSwitchLoads">
-        update fhzg_plan_await_transfer_switch_section a set a.switch_loads
-                 = (select sum(user_loads) from fhzg_plan_await_transfer_users b where b.switch_section_id = a.id)
-           where a.plan_id = #{planId}
+        update fhzg_plan_await_transfer_switch_section a
+        set a.switch_loads
+                = (select sum(user_loads) from fhzg_plan_await_transfer_users b where b.switch_section_id = a.id)
+        where a.plan_id = #{planId}
     </update>
 
     <update id="updateSwitchingSequenceIsConnect">
-        update fhzg_plan_transfer_scheme_switching_sequence a  set switch_type = '1'
-        where exists (select 1 from fhzg_plan_transfer_scheme_path_detail b where b.switch_id = a.switch_id and b.scheme_id = a.scheme_id)
+        update fhzg_plan_transfer_scheme_switching_sequence a
+        set switch_type = '1'
+        where exists (select 1
+                      from fhzg_plan_transfer_scheme_path_detail b
+                      where b.switch_id = a.switch_id and b.scheme_id = a.scheme_id)
           and a.scheme_id in (select id from fhzg_plan_transfer_scheme where plan_id = #{planId})
     </update>
 
     <delete id="deleteTransferUserByPlanId">
-        delete from fhzg_plan_await_transfer_users where plan_id = #{planId}
+        delete
+        from fhzg_plan_await_transfer_users
+        where plan_id = #{planId}
     </delete>
 
     <delete id="deleteSwitchSectionByPlanId">
-        delete from fhzg_plan_await_transfer_switch_section where plan_id = #{planId}
+        delete
+        from fhzg_plan_await_transfer_switch_section
+        where plan_id = #{planId}
     </delete>
 
-    <insert id="saveSwitchingLoopCheck" parameterType="com.hdkj.lt.core.bizms.modle.po.plan.FhzgPlanTransferSchemeSwitchingLoopCheck"
+    <insert id="saveSwitchingLoopCheck"
+            parameterType="com.hdkj.lt.core.bizms.modle.po.plan.FhzgPlanTransferSchemeSwitchingLoopCheck"
             useGeneratedKeys="true" keyProperty="id">
-        insert into fhzg_plan_transfer_scheme_switching_loop_check(id,switching_id,line_id,line_name,opposite_line_id,opposite_line_name,
-                                                                   phase_angle_diff,phase_angle_diff_threshold,phase_angle_diff_check,line_voltage,opposite_line_voltage,
-                                                                   line_voltage_diff,line_voltage_diff_threshold, line_voltage_diff_check,loop_current,loop_current_threshold,
-                                                                   loop_current_check,switch_current_check,segment_current_check,creator,create_time,afdrate_Current,afd_Cur_Loop,rate_Current,bfd_Cur_Loop)
-        values(#{id},#{switchingId},#{lineId},#{lineName},#{oppositeLineId},#{oppositeLineName},#{phaseAngleDiff},
-               #{phaseAngleDiffThreshold},#{phaseAngleDiffCheck},#{lineVoltage},#{oppositeLineVoltage},#{lineVoltageDiff},
-               #{lineVoltageDiffThreshold},#{lineVoltageDiffCheck},#{loopCurrent},#{loopCurrentThreshold},#{loopCurrentCheck},#{switchCurrentCheck},
-               #{segmentCurrentCheck},'111',NOW(),#{afdrateCurrent},#{afdCurLoop},#{rateCurrent},#{bfdCurLoop})
+        insert into fhzg_plan_transfer_scheme_switching_loop_check(id, switching_id, line_id, line_name,
+                                                                   opposite_line_id, opposite_line_name,
+                                                                   phase_angle_diff, phase_angle_diff_threshold,
+                                                                   phase_angle_diff_check, line_voltage,
+                                                                   opposite_line_voltage,
+                                                                   line_voltage_diff, line_voltage_diff_threshold,
+                                                                   line_voltage_diff_check, loop_current,
+                                                                   loop_current_threshold,
+                                                                   loop_current_check, switch_current_check,
+                                                                   segment_current_check, creator, create_time,
+                                                                   afdrate_Current, afd_Cur_Loop, rate_Current,
+                                                                   bfd_Cur_Loop)
+        values (#{id}, #{switchingId}, #{lineId}, #{lineName}, #{oppositeLineId}, #{oppositeLineName},
+                #{phaseAngleDiff},
+                #{phaseAngleDiffThreshold}, #{phaseAngleDiffCheck}, #{lineVoltage}, #{oppositeLineVoltage},
+                #{lineVoltageDiff},
+                #{lineVoltageDiffThreshold}, #{lineVoltageDiffCheck}, #{loopCurrent}, #{loopCurrentThreshold},
+                #{loopCurrentCheck}, #{switchCurrentCheck},
+                #{segmentCurrentCheck}, '111', NOW(), #{afdrateCurrent}, #{afdCurLoop}, #{rateCurrent}, #{bfdCurLoop})
     </insert>
 
     <insert id="saveSwitchingSequence"
@@ -123,81 +148,263 @@
                 '111', NOW())
     </insert>
 
-    <insert id="saveSwitchingFinalCheck"  parameterType="com.hdkj.lt.core.bizms.modle.po.plan.FhzgPlanTransferSchemeSwitchingFinalCheck"
+    <insert id="saveSwitchingFinalCheck"
+            parameterType="com.hdkj.lt.core.bizms.modle.po.plan.FhzgPlanTransferSchemeSwitchingFinalCheck"
             useGeneratedKeys="true" keyProperty="id">
-        insert into fhzg_plan_transfer_scheme_switching_final_check(id,switching_id,line_id,line_name,opposite_line_id,opposite_line_name,allow_max_current,estimate_max_current,
-                                                                    estimate_max_load_factor,load_factor_threshold,load_factor_check,switch_current_check,segment_current_check,creator,create_time)
-        values(#{id},#{switchingId},#{lineId},#{lineName},#{oppositeLineId},#{oppositeLineName},#{allowMaxCurrent},
-            #{estimateMaxCurrent},#{estimateMaxLoadFactor},#{loadFactorThreshold},#{loadFactorCheck},
-            #{switchCurrentCheck},#{segmentCurrentCheck},'111',NOW())
+        insert into fhzg_plan_transfer_scheme_switching_final_check(id, switching_id, line_id, line_name,
+                                                                    opposite_line_id, opposite_line_name,
+                                                                    allow_max_current, estimate_max_current,
+                                                                    estimate_max_load_factor, load_factor_threshold,
+                                                                    load_factor_check, switch_current_check,
+                                                                    segment_current_check, creator, create_time)
+        values (#{id}, #{switchingId}, #{lineId}, #{lineName}, #{oppositeLineId}, #{oppositeLineName},
+                #{allowMaxCurrent},
+                #{estimateMaxCurrent}, #{estimateMaxLoadFactor}, #{loadFactorThreshold}, #{loadFactorCheck},
+                #{switchCurrentCheck}, #{segmentCurrentCheck}, '111', NOW())
     </insert>
 
     <delete id="deleteTransferSchemeAndLinkInfoByPlanId">
-        delete x.* from fhzg_plan_transfer_scheme_switching_loop_check x,(
-          SELECT t.id from fhzg_plan_transfer_scheme_switching_sequence t
-          join fhzg_plan_transfer_scheme s on t.scheme_id=s.id and s.plan_id = #{planId}
-        ) y where x.switching_id = y.id;
-        delete x.* from fhzg_plan_transfer_scheme_switching_final_check x,(
-          SELECT t.id from fhzg_plan_transfer_scheme_switching_sequence t
-          join fhzg_plan_transfer_scheme s on t.scheme_id=s.id and s.plan_id = #{planId}
-        ) y where x.switching_id = y.id;
-
-        delete x.* from fhzg_plan_transfer_scheme_switching_loop_sw_current_detail x,(
-          SELECT t.id from fhzg_plan_transfer_scheme_switching_sequence t
-          join fhzg_plan_transfer_scheme s on t.scheme_id=s.id and s.plan_id = #{planId}
-        ) y where x.switching_id = y.id;
-        delete x.* from fhzg_plan_transfer_scheme_switching_loop_seg_current_detail x,(
-          SELECT t.id from fhzg_plan_transfer_scheme_switching_sequence t
-          join fhzg_plan_transfer_scheme s on t.scheme_id=s.id and s.plan_id = #{planId}
-        ) y where x.switching_id = y.id;
-
-        delete x.* from fhzg_plan_transfer_scheme_switching_final_sw_current_detail x,(
-          SELECT t.id from fhzg_plan_transfer_scheme_switching_sequence t
-          join fhzg_plan_transfer_scheme s on t.scheme_id=s.id and s.plan_id = #{planId}
-        ) y where x.switching_id = y.id;
-        delete x.* from fhzg_plan_transfer_scheme_switching_final_seg_current_detail x,(
-          SELECT t.id from fhzg_plan_transfer_scheme_switching_sequence t
-          join fhzg_plan_transfer_scheme s on t.scheme_id=s.id and s.plan_id = #{planId}
-        ) y where x.switching_id = y.id;
-
-        delete x.* from fhzg_plan_transfer_scheme_switching_sequence x,
-          fhzg_plan_transfer_scheme y where x.scheme_id = y.id and y.plan_id = #{planId};
-        delete x.* from fhzg_info_breaker_svg_after x,
-          fhzg_plan_transfer_scheme y where x.scheme_id = y.id and y.plan_id = #{planId};
-
-        delete x.* from fhzg_plan_transfer_scheme_path_detail x,
-          fhzg_plan_transfer_scheme y where x.scheme_id = y.id and y.plan_id = #{planId};
-        delete x.* from fhzg_plan_transfer_scheme_opposite_line_load_factor x,
-          fhzg_plan_transfer_scheme y where x.scheme_id = y.id and y.plan_id = #{planId};
-        delete x.* from fhzg_plan_transfer_scheme_users x,
-          fhzg_plan_transfer_scheme y where x.scheme_id = y.id and y.plan_id = #{planId};
-        delete x.* from fhzg_plan_transferable_scheme_users x,
-          fhzg_plan_transfer_scheme y where x.scheme_id = y.id and y.plan_id = #{planId};
-
-        delete x.* from fhzg_plan_opposite_line_concat_switch x,
-          fhzg_plan_transfer_scheme y where x.scheme_id = y.id and y.plan_id = #{planId};
-        delete from fhzg_plan_opposite_line_carry_capacity where plan_id = #{planId};
-
-        delete x.* from fhzg_plan_transfer_scheme_evaluation_index x,
-          fhzg_plan_transfer_scheme y where x.scheme_id = y.id and y.plan_id = #{planId};
-		delete x.* from fhzg_plan_transfer_scheme_strategy_score x,
-          fhzg_plan_transfer_scheme y where x.scheme_id = y.id and y.plan_id = #{planId};
-
-        delete from fhzg_plan_await_transfer_users where plan_id = #{planId};
-        delete from fhzg_plan_transfer_scheme where plan_id = #{planId};
+        BEGIN;
+-- 删除依赖 switching_sequence 的子表
+        DELETE
+        FROM fhzg_plan_transfer_scheme_switching_loop_check
+        WHERE switching_id IN (SELECT t.id
+                               FROM fhzg_plan_transfer_scheme_switching_sequence t
+                                        JOIN fhzg_plan_transfer_scheme s ON t.scheme_id = s.id
+                               WHERE s.plan_id = #{planId});
+
+        DELETE
+        FROM fhzg_plan_transfer_scheme_switching_final_check
+        WHERE switching_id IN (SELECT t.id
+                               FROM fhzg_plan_transfer_scheme_switching_sequence t
+                                        JOIN fhzg_plan_transfer_scheme s ON t.scheme_id = s.id
+                               WHERE s.plan_id = #{planId});
+
+        DELETE
+        FROM fhzg_plan_transfer_scheme_switching_loop_sw_current_detail
+        WHERE switching_id IN (SELECT t.id
+                               FROM fhzg_plan_transfer_scheme_switching_sequence t
+                                        JOIN fhzg_plan_transfer_scheme s ON t.scheme_id = s.id
+                               WHERE s.plan_id = #{planId});
+
+        DELETE
+        FROM fhzg_plan_transfer_scheme_switching_loop_seg_current_detail
+        WHERE switching_id IN (SELECT t.id
+                               FROM fhzg_plan_transfer_scheme_switching_sequence t
+                                        JOIN fhzg_plan_transfer_scheme s ON t.scheme_id = s.id
+                               WHERE s.plan_id = #{planId});
+
+        DELETE
+        FROM fhzg_plan_transfer_scheme_switching_final_sw_current_detail
+        WHERE switching_id IN (SELECT t.id
+                               FROM fhzg_plan_transfer_scheme_switching_sequence t
+                                        JOIN fhzg_plan_transfer_scheme s ON t.scheme_id = s.id
+                               WHERE s.plan_id = #{planId});
+
+        DELETE
+        FROM fhzg_plan_transfer_scheme_switching_final_seg_current_detail
+        WHERE switching_id IN (SELECT t.id
+                               FROM fhzg_plan_transfer_scheme_switching_sequence t
+                                        JOIN fhzg_plan_transfer_scheme s ON t.scheme_id = s.id
+                               WHERE s.plan_id = #{planId});
+
+-- 删除 switching_sequence 本身
+        DELETE
+        FROM fhzg_plan_transfer_scheme_switching_sequence
+        WHERE scheme_id IN (SELECT id
+                            FROM fhzg_plan_transfer_scheme
+                            WHERE plan_id = #{planId});
+
+-- 删除其他直接关联 scheme 的表
+        DELETE
+        FROM fhzg_info_breaker_svg_after
+        WHERE scheme_id IN (SELECT id
+                            FROM fhzg_plan_transfer_scheme
+                            WHERE plan_id = #{planId});
+
+        DELETE
+        FROM fhzg_plan_transfer_scheme_path_detail
+        WHERE scheme_id IN (SELECT id
+                            FROM fhzg_plan_transfer_scheme
+                            WHERE plan_id = #{planId});
+
+        DELETE
+        FROM fhzg_plan_transfer_scheme_opposite_line_load_factor
+        WHERE scheme_id IN (SELECT id
+                            FROM fhzg_plan_transfer_scheme
+                            WHERE plan_id = #{planId});
+
+        DELETE
+        FROM fhzg_plan_transfer_scheme_users
+        WHERE scheme_id IN (SELECT id
+                            FROM fhzg_plan_transfer_scheme
+                            WHERE plan_id = #{planId});
+
+        DELETE
+        FROM fhzg_plan_transferable_scheme_users
+        WHERE scheme_id IN (SELECT id
+                            FROM fhzg_plan_transfer_scheme
+                            WHERE plan_id = #{planId});
+
+        DELETE
+        FROM fhzg_plan_opposite_line_concat_switch
+        WHERE scheme_id IN (SELECT id
+                            FROM fhzg_plan_transfer_scheme
+                            WHERE plan_id = #{planId});
+
+        DELETE
+        FROM fhzg_plan_transfer_scheme_evaluation_index
+        WHERE scheme_id IN (SELECT id
+                            FROM fhzg_plan_transfer_scheme
+                            WHERE plan_id = #{planId});
+
+        DELETE
+        FROM fhzg_plan_transfer_scheme_strategy_score
+        WHERE scheme_id IN (SELECT id
+                            FROM fhzg_plan_transfer_scheme
+                            WHERE plan_id = #{planId});
+
+-- 删除不通过 scheme_id 关联的表
+        DELETE
+        FROM fhzg_plan_opposite_line_carry_capacity
+        WHERE plan_id = #{planId};
+
+        DELETE
+        FROM fhzg_plan_await_transfer_users
+        WHERE plan_id = #{planId};
+
+-- 最后删除主表
+        DELETE
+        FROM fhzg_plan_transfer_scheme
+        WHERE plan_id = #{planId};
+
+        COMMIT;
+    </delete>
+
+    <sql id="schemeIdsByPlanId">
+        SELECT id
+        FROM fhzg_plan_transfer_scheme
+        WHERE plan_id = #{planId}
+    </sql>
+
+    <sql id="switchingIdsByPlanId">
+        SELECT t.id
+        FROM fhzg_plan_transfer_scheme_switching_sequence t
+                 JOIN fhzg_plan_transfer_scheme s ON t.scheme_id = s.id
+        WHERE s.plan_id = #{planId}
+    </sql>
+
+    <!-- 1. 删除 switching 相关子表 -->
+    <delete id="deleteSwitchingLoopCheckByPlanId">
+        DELETE FROM fhzg_plan_transfer_scheme_switching_loop_check
+        WHERE switching_id IN (<include refid="switchingIdsByPlanId"/>)
+    </delete>
+
+    <delete id="deleteSwitchingFinalCheckByPlanId">
+        DELETE FROM fhzg_plan_transfer_scheme_switching_final_check
+        WHERE switching_id IN (<include refid="switchingIdsByPlanId"/>)
+    </delete>
+
+    <delete id="deleteLoopSwCurrentDetailByPlanId">
+        DELETE FROM fhzg_plan_transfer_scheme_switching_loop_sw_current_detail
+        WHERE switching_id IN (<include refid="switchingIdsByPlanId"/>)
+    </delete>
+
+    <delete id="deleteLoopSegCurrentDetailByPlanId">
+        DELETE FROM fhzg_plan_transfer_scheme_switching_loop_seg_current_detail
+        WHERE switching_id IN (<include refid="switchingIdsByPlanId"/>)
+    </delete>
+
+    <delete id="deleteFinalSwCurrentDetailByPlanId">
+        DELETE FROM fhzg_plan_transfer_scheme_switching_final_sw_current_detail
+        WHERE switching_id IN (<include refid="switchingIdsByPlanId"/>)
+    </delete>
+
+    <delete id="deleteFinalSegCurrentDetailByPlanId">
+        DELETE FROM fhzg_plan_transfer_scheme_switching_final_seg_current_detail
+        WHERE switching_id IN (<include refid="switchingIdsByPlanId"/>)
+    </delete>
+
+    <!-- 2. 删除 switching_sequence -->
+    <delete id="deleteSwitchingSequenceByPlanId">
+        DELETE FROM fhzg_plan_transfer_scheme_switching_sequence
+        WHERE scheme_id IN (<include refid="schemeIdsByPlanId"/>)
+    </delete>
+
+    <!-- 3. 删除其他关联表 -->
+    <delete id="deleteBreakerSvgAfterByPlanId">
+        DELETE FROM fhzg_info_breaker_svg_after
+        WHERE scheme_id IN (<include refid="schemeIdsByPlanId"/>)
+    </delete>
+
+    <delete id="deletePathDetailByPlanId">
+        DELETE FROM fhzg_plan_transfer_scheme_path_detail
+        WHERE scheme_id IN (<include refid="schemeIdsByPlanId"/>)
+    </delete>
+
+    <delete id="deleteOppositeLineLoadFactorByPlanId">
+        DELETE FROM fhzg_plan_transfer_scheme_opposite_line_load_factor
+        WHERE scheme_id IN (<include refid="schemeIdsByPlanId"/>)
+    </delete>
+
+    <delete id="deleteSchemeUsersByPlanId">
+        DELETE FROM fhzg_plan_transfer_scheme_users
+        WHERE scheme_id IN (<include refid="schemeIdsByPlanId"/>)
+    </delete>
+
+    <delete id="deleteTransferableSchemeUsersByPlanId">
+        DELETE FROM fhzg_plan_transferable_scheme_users
+        WHERE scheme_id IN (<include refid="schemeIdsByPlanId"/>)
+    </delete>
+
+    <delete id="deleteOppositeLineConcatSwitchByPlanId">
+        DELETE FROM fhzg_plan_opposite_line_concat_switch
+        WHERE scheme_id IN (<include refid="schemeIdsByPlanId"/>)
+    </delete>
+
+    <delete id="deleteEvaluationIndexByPlanId">
+        DELETE FROM fhzg_plan_transfer_scheme_evaluation_index
+        WHERE scheme_id IN (<include refid="schemeIdsByPlanId"/>)
+    </delete>
+
+    <delete id="deleteStrategyScoreByPlanId">
+        DELETE FROM fhzg_plan_transfer_scheme_strategy_score
+        WHERE scheme_id IN (<include refid="schemeIdsByPlanId"/>)
+    </delete>
+
+    <!-- 4. 直接按 plan_id 删除的表 -->
+    <delete id="deleteCarryCapacityByPlanId">
+        DELETE
+        FROM fhzg_plan_opposite_line_carry_capacity
+        WHERE plan_id = #{planId}
+    </delete>
+
+    <delete id="deleteAwaitTransferUsersByPlanId">
+        DELETE
+        FROM fhzg_plan_await_transfer_users
+        WHERE plan_id = #{planId}
+    </delete>
+
+    <!-- 5. 最后删除主表 -->
+    <delete id="deleteTransferSchemeByPlanId">
+        DELETE
+        FROM fhzg_plan_transfer_scheme
+        WHERE plan_id = #{planId}
     </delete>
 
     <insert id="saveConcatSwitchList" useGeneratedKeys="true" keyProperty="id">
-         insert into fhzg_plan_opposite_line_concat_switch(scheme_id,capacity_id,concat_psr_id,concat_psr_name) values
-        <foreach collection='concatSwitchList' item='dto' separator=',' >
+        insert into fhzg_plan_opposite_line_concat_switch(scheme_id,capacity_id,concat_psr_id,concat_psr_name) values
+        <foreach collection='concatSwitchList' item='dto' separator=','>
             (#{dto.schemeId},#{dto.capacityId},#{dto.concatPsrId},#{dto.concatPsrName})
         </foreach>
     </insert>
 
-    <delete id="deleteSwitchSectionByConnect" >
-        delete a.* FROM fhzg_plan_await_transfer_switch_section a
+    <delete id="deleteSwitchSectionByConnect">
+        delete
+        a.* FROM fhzg_plan_await_transfer_switch_section a
         WHERE EXISTS ( SELECT 1 FROM fhzg_plan_transfer_scheme b, fhzg_plan_opposite_line_concat_switch c WHERE b.id = c.scheme_id AND b.plan_id = a.plan_id and a.start_switch_id = c.concat_psr_id )
-          AND a.plan_id = #{planId}
+          AND a.plan_id =
+        #{planId}
     </delete>
 
 

+ 47 - 12
services/load-transfer-mq/src/main/java/com/hdkj/lt/mq/service/plan/impl/AnalysisPlanTransferSchemeServiceImpl.java

@@ -54,10 +54,10 @@ public class AnalysisPlanTransferSchemeServiceImpl implements AnalysisPlanTransf
      * @date 2025/5/24 18:07
      * @discription 解析大对象终的转供方案落库
      **/
-    public void analysisPlanTransferScheme(Long planId,Map<Long,XferPlanDTO> xferPlanMap,List<FhzgPlanAwaitTransferUsers> awaitTransferUsers) {
+    public void analysisPlanTransferScheme(Long planId, Map<Long, XferPlanDTO> xferPlanMap, List<FhzgPlanAwaitTransferUsers> awaitTransferUsers) {
         // 生成方案前需要覆盖方案相关级联数据
-        fhzgPlanAnalyzeCalculateDecudeMapper.deleteTransferSchemeAndLinkInfoByPlanId(planId);
-
+        //fhzgPlanAnalyzeCalculateDecudeMapper.deleteTransferSchemeAndLinkInfoByPlanId(planId);
+        deleteTransferSchemeAndLinkInfoByPlanId(planId);
         //返回保存的主键和 计划的对象
 //        Map<Long,XferPlanDTO> idXferPlanDTOMap = new HashMap<>();
         List<FhzgPlanTransferScheme> fhzgPlanTransferSchemeList = new ArrayList<>();
@@ -79,7 +79,7 @@ public class AnalysisPlanTransferSchemeServiceImpl implements AnalysisPlanTransf
 
             fhzgPlanTransferScheme.setSchemeState("02");//方案选择状态默认 "02" 未选定
             fhzgPlanTransferScheme.setSwitchOperationCount(switchOperationCount);//开关动作次数(计算推演平台breakerOperationInfo动作开关计数)
-            this.setCountValue(fhzgPlanTransferScheme,xferSupplyAreaList, awaitTransferUsers);
+            this.setCountValue(fhzgPlanTransferScheme, xferSupplyAreaList, awaitTransferUsers);
             fhzgPlanTransferScheme.setCreateTime(LocalDateTime.now());
             fhzgPlanTransferScheme.setId(schemeId);
             fhzgPlanTransferScheme.setRowJson(JSON.toJSONString(xferPlanMap.get(schemeId)));
@@ -98,20 +98,18 @@ public class AnalysisPlanTransferSchemeServiceImpl implements AnalysisPlanTransf
     }
 
     /**
-     *
      * @author luorui
      * @date 2025/5/25 11:03
      * @discription 测试解析转供计划数据
-     *
      **/
     @Override
-    public Map<Long,XferPlanDTO> analysis(Long planId) {
+    public Map<Long, XferPlanDTO> analysis(Long planId) {
         PlanAwaitTransferAreaResultPO po = getTransferAreaResultByPlanId(planId);
         if (po != null) {
             ApiResponse response = JSON.parseObject(po.getTransferAreaJson(), ApiResponse.class);
             response.getData();
             ApiDataDTO data = JSON.parseObject(JSON.toJSONString(response.getData()), ApiDataDTO.class);
-            Snowflake snowflake = IdUtil.getSnowflake(1,1);
+            Snowflake snowflake = IdUtil.getSnowflake(1, 1);
             //将待转供区域的用户 负荷收集起来
             List<FhzgPlanAwaitTransferUsers> dataList = new ArrayList<>();
             List<SupplyAreaDTO> supplyAreaList = data.getSupplyAreaList();
@@ -149,6 +147,7 @@ public class AnalysisPlanTransferSchemeServiceImpl implements AnalysisPlanTransf
         }
         return null;
     }
+
     private BigDecimal getMetricValue(MetricValueDTO device) {
         return Optional.ofNullable(device)
                 .filter(d -> ObjectUtils.allNotNull(d, d.getValue()))
@@ -163,7 +162,7 @@ public class AnalysisPlanTransferSchemeServiceImpl implements AnalysisPlanTransf
     }
 
     //转供方案的子区域,设置统计字段
-    private void setCountValue(FhzgPlanTransferScheme fhzgPlanTransferScheme ,List<XferSupplyAreaDTO> xferSupplyAreaList,List<FhzgPlanAwaitTransferUsers> awaitTransferUsers) {
+    private void setCountValue(FhzgPlanTransferScheme fhzgPlanTransferScheme, List<XferSupplyAreaDTO> xferSupplyAreaList, List<FhzgPlanAwaitTransferUsers> awaitTransferUsers) {
         Integer lossUser = null;//损失用户,为不可转供区域的 中压用户和公变用户的数量之和
         //如果没有不可转供区域则 lossUser 为 0
         //计算是否为推荐方案
@@ -189,13 +188,13 @@ public class AnalysisPlanTransferSchemeServiceImpl implements AnalysisPlanTransf
                     // 公变信息列表
                     List<TransCustomerDTO> mvTransList = areaDeviceInfo.getMvTransList();
                     if (CollUtil.isNotEmpty(mvTransList)) {
-                        List<String> psrIdList = mvTransList.stream().filter(e->StrUtil.isNotBlank(e.getPsrID())).map(TransCustomerDTO::getPsrID).collect(Collectors.toList());
+                        List<String> psrIdList = mvTransList.stream().filter(e -> StrUtil.isNotBlank(e.getPsrID())).map(TransCustomerDTO::getPsrID).collect(Collectors.toList());
                         userList.addAll(psrIdList);
                     }
                     // 中压用户列表
                     List<TransCustomerDTO> mvCustomerList = areaDeviceInfo.getMvCustomerList();
                     if (CollUtil.isNotEmpty(mvCustomerList)) {
-                        List<String> psrIdList = mvCustomerList.stream().filter(e->StrUtil.isNotBlank(e.getPsrID())).map(TransCustomerDTO::getPsrID).collect(Collectors.toList());
+                        List<String> psrIdList = mvCustomerList.stream().filter(e -> StrUtil.isNotBlank(e.getPsrID())).map(TransCustomerDTO::getPsrID).collect(Collectors.toList());
                         userList.addAll(psrIdList);
                     }
                 }
@@ -210,7 +209,7 @@ public class AnalysisPlanTransferSchemeServiceImpl implements AnalysisPlanTransf
         }
         //方案中的不可转供区域如果没有的话 损失户数为 0
         Long nonArea = xferSupplyAreaList.stream().filter(e -> !Objects.equals(e.getPowerOnSuccess(), Boolean.TRUE)).count();
-        if (Objects.equals(nonArea,0L)) {
+        if (Objects.equals(nonArea, 0L)) {
             lossUser = 0;//前面可能为空
         }
         //从待转供用户中筛选出来可转供的用户 用来计算可转供负荷和 转供总负荷
@@ -232,4 +231,40 @@ public class AnalysisPlanTransferSchemeServiceImpl implements AnalysisPlanTransf
         fhzgPlanTransferScheme.setSchemeCheck(schemeCheck ? "1" : "0");//scheme_check	方案校验结果(1-通过,0-不通过)
     }
 
+    /**
+     * 删除所有方案相关表数据
+     *
+     * @param planId
+     */
+    public void deleteTransferSchemeAndLinkInfoByPlanId(Long planId) {
+        // 先删依赖 switching 的
+        fhzgPlanAnalyzeCalculateDecudeMapper.deleteSwitchingLoopCheckByPlanId(planId);
+        fhzgPlanAnalyzeCalculateDecudeMapper.deleteSwitchingFinalCheckByPlanId(planId);
+        fhzgPlanAnalyzeCalculateDecudeMapper.deleteLoopSwCurrentDetailByPlanId(planId);
+        fhzgPlanAnalyzeCalculateDecudeMapper.deleteLoopSegCurrentDetailByPlanId(planId);
+        fhzgPlanAnalyzeCalculateDecudeMapper.deleteFinalSwCurrentDetailByPlanId(planId);
+        fhzgPlanAnalyzeCalculateDecudeMapper.deleteFinalSegCurrentDetailByPlanId(planId);
+
+        // 再删 switching_sequence
+        fhzgPlanAnalyzeCalculateDecudeMapper.deleteSwitchingSequenceByPlanId(planId);
+
+        // 删除其他关联表
+        fhzgPlanAnalyzeCalculateDecudeMapper.deleteBreakerSvgAfterByPlanId(planId);
+        fhzgPlanAnalyzeCalculateDecudeMapper.deletePathDetailByPlanId(planId);
+        fhzgPlanAnalyzeCalculateDecudeMapper.deleteOppositeLineLoadFactorByPlanId(planId);
+        fhzgPlanAnalyzeCalculateDecudeMapper.deleteSchemeUsersByPlanId(planId);
+        fhzgPlanAnalyzeCalculateDecudeMapper.deleteTransferableSchemeUsersByPlanId(planId);
+        fhzgPlanAnalyzeCalculateDecudeMapper.deleteOppositeLineConcatSwitchByPlanId(planId);
+        fhzgPlanAnalyzeCalculateDecudeMapper.deleteEvaluationIndexByPlanId(planId);
+        fhzgPlanAnalyzeCalculateDecudeMapper.deleteStrategyScoreByPlanId(planId);
+
+        // 删除直接按 plan_id 关联的
+        fhzgPlanAnalyzeCalculateDecudeMapper.deleteCarryCapacityByPlanId(planId);
+        fhzgPlanAnalyzeCalculateDecudeMapper.deleteAwaitTransferUsersByPlanId(planId);
+
+        // 最后删主表
+        fhzgPlanAnalyzeCalculateDecudeMapper.deleteTransferSchemeByPlanId(planId);
+
+    }
+
 }