id, plan_no, section_id, section_name, maintenance_company_id, maintenance_company_name, phone, user_id, user_code, user_name, start_time, end_time, plan_type, state, effect_date, remark, create_user_id, create_date, update_user_id, update_date, del_flg
select distinct
rsmc.section_id as sectionId,
s.section_name as sectionName,
rsmc.maintenance_company_id as maintenanceCompanyId,
mc.maintenance_company_name as maintenanceCompanyName,
s.section_type,
if(plan_count.planCount is null, 0, plan_count.planCount) as planCount,
if(complete_count.completeCount is null, 0, complete_count.completeCount) as completeCount,
if(
if(plan_count.planCount is null, 0, plan_count.planCount) - if(complete_count.completeCount is null, 0, complete_count.completeCount) 0,
0,
if(plan_count.planCount is null, 0, plan_count.planCount) - if(complete_count.completeCount is null, 0, complete_count.completeCount)
) as noCompleteCount
from
T_Lhzx_Road_Section_Maintenance_Company rsmc
left join
T_Lhzx_Section s on s.id = rsmc.section_id
left join
T_Lhzx_Maintenance_Company mc on mc.id = rsmc.maintenance_company_id
left join (
select
section_id,
maintenance_company_id,
count(id) as planCount
from
T_Lhzx_Street_Tree_Work_Plan
where
plan_type = 1
and
del_flg = 0
and upload_type = #{tLhzxStreetTreeWorkPlan.uploadType}
and date_format(start_time, '%Y-%m') = #{tLhzxStreetTreeWorkPlan.planMonth}
and date_format(start_time, '%Y') = #{tLhzxStreetTreeWorkPlan.planYear}
group by
section_id,
maintenance_company_id
) plan_count on plan_count.section_id = rsmc.section_id and plan_count.maintenance_company_id = rsmc.maintenance_company_id
left join (
select
section_id,
maintenance_company_id,
count(id) as completeCount
from
T_Lhzx_Street_Tree_Work_Plan
where
plan_type = 2
and
del_flg = 0
and upload_type = #{tLhzxStreetTreeWorkPlan.uploadType}
and date_format(start_time, '%Y-%m') = #{tLhzxStreetTreeWorkPlan.planMonth}
and date_format(start_time, '%Y') = #{tLhzxStreetTreeWorkPlan.planYear}
group by
section_id,
maintenance_company_id
) complete_count on complete_count.section_id = rsmc.section_id and complete_count.maintenance_company_id = rsmc.maintenance_company_id
where
rsmc.del_flg = 0
and rsmc.section_id = #{tLhzxStreetTreeWorkPlan.sectionId}
and rsmc.maintenance_company_id = #{tLhzxStreetTreeWorkPlan.maintenanceCompanyId}
and s.section_type = #{tLhzxStreetTreeWorkPlan.sectionType}
order by
rsmc.section_id,
rsmc.maintenance_company_id