select t.depart_id ,itpfg.equip_info_id from inspection_task_point_fill_group itpfg , inspection_task t
where itpfg.inspection_task_id = t.id and itpfg.equip_info_id IS NOT NULL AND itpfg.equip_info_id <> ''
AND t.task_state IN ('2','3')
<iftest="startDate != null ">
AND DATE_FORMAT(t.inspection_cycle_start_date,'%Y-%m-%d') >= #{startDate}
</if>
<iftest="endDate != null ">
AND DATE_FORMAT(t.inspection_cycle_start_date,'%Y-%m-%d') <= #{endDate}
</if>
group by t.depart_id , itpfg.equip_info_id
)aa group by aa.depart_id
)aaa on aaa.depart_id = d.id
left join (
select bb.depart_id ,count(1) 'count' from (
select t.depart_id ,itpfg.equip_info_id
from inspection_task_fill_content isfc ,inspection_task_point_fill_group itpfg,inspection_task t
where
isfc.inspection_task_id = itpfg.inspection_task_id and isfc.inspection_point_fill_group_id = itpfg.inspection_point_fill_group_id
and itpfg.inspection_task_id = t.id and isfc.inspection_task_id = t.id
AND t.task_state IN ('2','3')
<iftest="startDate != null ">
AND DATE_FORMAT(t.inspection_cycle_start_date,'%Y-%m-%d') >= #{startDate}
</if>
<iftest="endDate != null ">
AND DATE_FORMAT(t.inspection_cycle_start_date,'%Y-%m-%d') <= #{endDate}
</if>
and itpfg.equip_info_id IS NOT NULL AND itpfg.equip_info_id <> '' AND isfc.fill_content IS NOT NULL AND isfc.fill_content <> ''
GROUP BY t.depart_id ,itpfg.equip_info_id
)bb group by bb.depart_id
)bbb on bbb.depart_id = d.id
left join (
select cc.depart_id ,count(1) 'count' from (
select t.depart_id ,itpfg.equip_info_id
from inspection_task_fill_content isfc ,inspection_task_point_fill_group itpfg,inspection_task t
where
isfc.inspection_task_id = itpfg.inspection_task_id and isfc.inspection_point_fill_group_id = itpfg.inspection_point_fill_group_id
and itpfg.inspection_task_id = t.id and isfc.inspection_task_id = t.id
AND t.task_state IN ('2','3')
<iftest="startDate != null ">
AND DATE_FORMAT(t.inspection_cycle_start_date,'%Y-%m-%d') >= #{startDate}
</if>
<iftest="endDate != null ">
AND DATE_FORMAT(t.inspection_cycle_start_date,'%Y-%m-%d') <= #{endDate}
</if>
and itpfg.equip_info_id IS NOT NULL AND itpfg.equip_info_id <> '' AND isfc.fill_content IS NOT NULL AND isfc.fill_content <> '' and isfc.choice_state =0
GROUP BY t.depart_id ,itpfg.equip_info_id
)cc group by cc.depart_id
)ccc on ccc.depart_id = d.id
left join(
select t.depart_id ,
sum( IF( (SELECT ACT_ID_ AS EndActivityId FROM ACT_HI_ACTINST WHERE PROC_INST_ID_ = prp.process_instance_id AND END_TIME_ IS NOT NULL ORDER BY END_TIME_ DESC LIMIT 1) IS NULL, 0, 1) ) AS state
from problem_report_plan prp , inspection_task_problem_report itpr , inspection_task t
where prp.id = itpr.problem_report_plan_id and itpr.inspection_task_id = t.id
AND t.task_state IN ('2','3')
<iftest="startDate != null ">
AND DATE_FORMAT(t.inspection_cycle_start_date,'%Y-%m-%d') >= #{startDate}
</if>
<iftest="endDate != null ">
AND DATE_FORMAT(t.inspection_cycle_start_date,'%Y-%m-%d') <= #{endDate}
</if>
group by t.depart_id
)ddd on ddd.depart_id = d.id
left join (
select t.depart_id ,ifnull(count(1),0) 'count' from problem_report_plan prp , inspection_task_problem_report itpr , inspection_task t
where prp.id = itpr.problem_report_plan_id and itpr.inspection_task_id = t.id
AND t.task_state IN ('2','3')
<iftest="startDate != null ">
AND DATE_FORMAT(t.inspection_cycle_start_date,'%Y-%m-%d') >= #{startDate}
</if>
<iftest="endDate != null ">
AND DATE_FORMAT(t.inspection_cycle_start_date,'%Y-%m-%d') <= #{endDate}
sum(CASE WHEN t.task_state = '1' THEN 1 ELSE 0 END) AS 'count1' ,
sum(CASE WHEN t.task_state = '2' THEN 1 ELSE 0 END) AS 'count2',
sum(CASE WHEN t.task_state = '3' THEN 1 ELSE 0 END) AS 'count3'
from inspection_task t
where 1=1
<iftest="startDate != null ">
AND DATE_FORMAT(t.inspection_cycle_start_date,'%Y-%m-%d') >= #{startDate}
</if>
<iftest="endDate != null ">
AND DATE_FORMAT(t.inspection_cycle_start_date,'%Y-%m-%d') <= #{endDate}
</if>
group by t.depart_id
)aaa on aaa.depart_id = d.id
left join (
select cc.depart_id ,count(cc.inspection_task_id) 'count' from (
SELECT t.depart_id, itfc.inspection_task_id FROM inspection_task_fill_content itfc ,inspection_task t
WHERE inspection_task_id =t.id
and t.task_state IN ('2')
<iftest="startDate != null ">
AND DATE_FORMAT(t.inspection_cycle_start_date,'%Y-%m-%d') >= #{startDate}
</if>
<iftest="endDate != null ">
AND DATE_FORMAT(t.inspection_cycle_start_date,'%Y-%m-%d') <= #{endDate}
</if>
AND choice_state = '0'
GROUP BY itfc.inspection_task_id ,t.depart_id) cc group by cc.depart_id
)ccc on ccc.depart_id = d.id
left join(
select t.depart_id ,
sum( IF( (SELECT ACT_ID_ AS EndActivityId FROM ACT_HI_ACTINST WHERE PROC_INST_ID_ = prp.process_instance_id AND END_TIME_ IS NOT NULL ORDER BY END_TIME_ DESC LIMIT 1) IS NULL, 0, 1) ) AS state
from problem_report_plan prp , inspection_task_problem_report itpr , inspection_task t
where prp.id = itpr.problem_report_plan_id and itpr.inspection_task_id = t.id
and t.task_state IN ('2')
<iftest="startDate != null ">
AND DATE_FORMAT(t.inspection_cycle_start_date,'%Y-%m-%d') >= #{startDate}
</if>
<iftest="endDate != null ">
AND DATE_FORMAT(t.inspection_cycle_start_date,'%Y-%m-%d') <= #{endDate}
</if>
group by t.depart_id
)ddd on ddd.depart_id = d.id
left join (
select t.depart_id ,ifnull(count(1),0) 'count' from problem_report_plan prp , inspection_task_problem_report itpr , inspection_task t
where prp.id = itpr.problem_report_plan_id and itpr.inspection_task_id = t.id
and t.task_state IN ('2')
<iftest="startDate != null ">
AND DATE_FORMAT(t.inspection_cycle_start_date,'%Y-%m-%d') >= #{startDate}
</if>
<iftest="endDate != null ">
AND DATE_FORMAT(t.inspection_cycle_start_date,'%Y-%m-%d') <= #{endDate}