INSERT INTO fhzg_dist_line_switch_section(line_id, load_switch_id, load_switch_name, start_switch_id, start_switch_name, start_switch_type, end_switch_id, end_switch_name, create_time, users_count) WITH res_tab AS (SELECT count(psr_id) zxkg_count FROM t_feeder_topo WHERE feeder = #{feeder} AND zxfz_type='主线' group by feeder) SELECT t.*, ifnull(v.user_count,0) user_count FROM ( WITH RECURSIVE hierarchy AS ( SELECT psr_id switch_id, name switch_name, zxfz_type, psr_id, name, start_kg_id, psr_type FROM t_feeder_topo WHERE is_start_kg = '1' and feeder = #{feeder} UNION ALL SELECT if(child.zxfz_type='主线' or (select * from res_tab)=0, child.psr_id, parent.switch_id) switch_id, if(child.zxfz_type='主线' or (select * from res_tab)=0, child.name, parent.switch_name) switch_name, child.zxfz_type, child.psr_id, child.name, child.start_kg_id, child.psr_type 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 #{item} ) SELECT #{feeder} lineId, parent.switch_id AS loadSwitchId, parent.switch_name AS loadSwitchName, 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, now() nowTime FROM hierarchy child RIGHT JOIN hierarchy parent ON child.start_kg_id = parent.psr_id GROUP BY parent.psr_id, parent.name , parent.psr_type, parent.switch_id, parent.switch_name) t left join (select start_kg_id, count(distinct if(d.psr_id is null,t.psr_id,d.join_ec)) user_count from t_feeder_topo t left join dwd_shb_ds_joinec_transformer_base d on t.psr_id = d.psr_id where t.psr_type in #{item} and t.feeder = #{feeder} group by t.start_kg_id) v on t.startSwitchId = v.start_kg_id insert into t_disable_llkg_config(LLSB_ID, CITY_CODE, CREATE_TIME, LAST_TIME, LLSB_TYPE) select distinct t.psr_id, t.city_code, now() c_time, now() u_time, if(t.sszf_type not in ('PD_30000004', 'PD_32400000', 'PD_20400000'), '0', '2') l_type from t_feeder_topo t left join t_disable_llkg_config f on t.psr_id = f.llsb_id where t.normal_open = 'true' and f.id is null update t_disable_llkg_config x, (select distinct t.psr_id, case when f.llsb_type in ('1', '3') then f.llsb_type when sszf_type not in ('PD_30000004', 'PD_32400000', 'PD_20400000') then '0' else '2' end llsb_type from t_feeder_topo t join t_disable_llkg_config f on t.psr_id = f.llsb_id where t.normal_open = 'true') y set x.llsb_type = y.llsb_type, x.last_time = now() where x.llsb_id = y.psr_id delete from fhzg_dist_line_switch_section where line_id = #{feeder} delete f.* from t_disable_llkg_config f join t_feeder_topo t on t.psr_id = f.llsb_id where t.normal_open = 'false'