SELECT
rsmc.maintenance_company_id,
mc.old_maintenance_company_id,
mc.maintenance_company_name,
rsmc.section_id,
s.old_section_id,
s.section_name,
IF(wo.dailyMaintenanceCount is null, 0, wo.dailyMaintenanceCount) as dailyMaintenanceCount,
IF(wo.streetTreeCount is null, 0, wo.streetTreeCount) as streetTreeCount,
IF(wo.greenSpaceCount is null, 0, wo.greenSpaceCount) as greenSpaceCount,
IF(wo.flowersCount is null, 0, wo.flowersCount) as flowersCount,
IF(wo.pestCount is null, 0, wo.pestCount) as pestCount,
IF(wo.otherCount is null, 0, wo.otherCount) as otherCount,
IF(com.complaintCount is null, 0, com.complaintCount) as complaintCount
/*15 as complaintCount*/
FROM
(
select DISTINCT
maintenance_company_id,
section_id,
del_flg
from
T_Lhzx_Road_Section_Maintenance_Company
WHERE
del_flg = 0
) rsmc
LEFT JOIN
T_Lhzx_Maintenance_Company mc on mc.id = rsmc.maintenance_company_id
LEFT JOIN
T_Lhzx_Section s on s.id = rsmc.section_id
LEFT JOIN
(
select
wob.F_YHDeptId,
wob.F_SGUserId,
count(1) as dailyMaintenanceCount,
sum(IF(wob.patrol_type = 1, 1, 0)) as streetTreeCount,
sum(IF(wob.patrol_type = 2, 1, 0)) as greenSpaceCount,
sum(IF(wob.patrol_type = 3, 1, 0)) as flowersCount,
sum(IF(wob.patrol_type = 4, 1, 0)) as pestCount,
sum(IF(wob.patrol_type is null, 1, 0)) as otherCount
from
T_WO_WorkOrderBase wob
where
wob.F_WorkOrderTypeId = 3
and
wob.F_DeleteFlag = 0
and
DATE_FORMAT(wob.F_CreateDate, '%Y-%m') = #{workOrderBaseVO.currentMonth}
and
wob.dept_type = 2
GROUP BY
wob.F_YHDeptId,
wob.F_SGUserId
) wo on wo.F_YHDeptId = mc.old_maintenance_company_id and wo.F_SGUserId = s.old_section_id
LEFT JOIN (
select
F_YHDeptId,
F_SGUserId,
count(1) as complaintCount
from
T_WO_WorkOrderBase
where
F_WorkOrderTypeId = 5
and
F_DeleteFlag = 0
and
DATE_FORMAT(F_CreateDate, '%Y-%m') = #{workOrderBaseVO.lastMonth}
and
dept_type = 2
group by
F_YHDeptId,
F_SGUserId
) com on com.F_YHDeptId = mc.old_maintenance_company_id and com.F_SGUserId = s.old_section_id
WHERE
rsmc.del_flg = 0
and rsmc.section_id = #{workOrderBaseVO.sectionId}
and rsmc.maintenance_company_id = #{workOrderBaseVO.maintenanceCompanyId}
ORDER BY
rsmc.section_id, rsmc.maintenance_company_id
select
rsmc.maintenance_company_id,
mc.old_maintenance_company_id,
mc.maintenance_company_name,
rsmc.section_id,
s.old_section_id,
s.section_name,
wo.workOrderCount,
wo.untreatedCount,
wo.processingCount,
wo.finishedCount,
wo.withdrawnCount
from (
select DISTINCT
maintenance_company_id,
section_id,
del_flg
from
T_Lhzx_Road_Section_Maintenance_Company
WHERE
del_flg = 0
) rsmc
LEFT JOIN
T_Lhzx_Maintenance_Company mc on mc.id = rsmc.maintenance_company_id
LEFT JOIN
T_Lhzx_Section s on s.id = rsmc.section_id
LEFT JOIN
(
select
wob.F_YHDeptId,
wob.F_SGUserId,
count(1) as workOrderCount,
sum(IF(wob.F_StateId = 2, 1, 0)) as untreatedCount,
sum(IF(wob.F_StateId = 3, 1, 0)) as processingCount,
sum(IF(wob.F_StateId = 4, 1, 0)) as finishedCount,
sum(IF(wob.F_StateId = 5, 1, 0)) as withdrawnCount
from
T_WO_WorkOrderBase wob
where
wob.is_center = 1
and
wob.F_DeleteFlag = 0
and
wob.dept_type = 2
and DATE_FORMAT(wob.F_CreateDate, '%Y-%m') = #{currentMonth}
GROUP BY
wob.F_YHDeptId,
wob.F_SGUserId
) wo on wo.F_YHDeptId = mc.old_maintenance_company_id and wo.F_SGUserId = s.old_section_id
WHERE
rsmc.del_flg = 0
and rsmc.section_id = #{sectionId}
and rsmc.maintenance_company_id = #{maintenanceCompanyId}
ORDER BY
rsmc.section_id,
rsmc.maintenance_company_id