left join <includerefid="com.elink.esua.epdc.modules.common.dao.EpdcTableNameDao.tb_events"/>.epdc_img t2 on t1.EVENT_ID = t2.REFERENCE_ID and t1.DEL_FLAG = '0'
left join <includerefid="com.elink.esua.epdc.modules.common.dao.EpdcTableNameDao.tb_events"/>.epdc_item_handle_process t3 on t3.ITEM_ID = t1.ID and t3.DEL_FLAG = '0' and t3.STATE = 10
when (t4.ID is not null and t1.STATE = 0 and t1.CREATED_TIME != (select min(t.CREATED_TIME) from <includerefid="com.elink.esua.epdc.modules.common.dao.EpdcTableNameDao.tb_events"/>.epdc_item_handle_process t where t.DEL_FLAG = '0' and t1.ITEM_ID = t.ITEM_ID group by t.ITEM_ID)) then 'transfer'
when (t4.ID is null and t1.STATE = 0 and t1.CREATED_TIME != (select min(t.CREATED_TIME) from <includerefid="com.elink.esua.epdc.modules.common.dao.EpdcTableNameDao.tb_events"/>.epdc_item_handle_process t where t.DEL_FLAG = '0' and t1.ITEM_ID = t.ITEM_ID group by t.ITEM_ID)) then 'response'
when (t1.STATE = 0 and t1.CREATED_TIME = (select min(t.CREATED_TIME) from <includerefid="com.elink.esua.epdc.modules.common.dao.EpdcTableNameDao.tb_events"/>.epdc_item_handle_process t where t.DEL_FLAG = '0' and t1.ITEM_ID = t.ITEM_ID group by t.ITEM_ID)) then 'created'
from <includerefid="com.elink.esua.epdc.modules.common.dao.EpdcTableNameDao.tb_events"/>.epdc_item_handle_process t1
left join <includerefid="com.elink.esua.epdc.modules.common.dao.EpdcTableNameDao.tb_events"/>.epdc_item_dept t4 on t4.ITEM_HANDLE_ID = t1.ID and t4.DEL_FLAG = '0'
left join <includerefid="com.elink.esua.epdc.modules.common.dao.EpdcTableNameDao.tb_events"/>.epdc_img t3 on t3.REFERENCE_ID = t.processId and t3.DEL_FLAG = '0'
count((it.ITEM_STATE=5 or it.ITEM_STATE=10) or null) as resolvedNum,
ifnull(format(round(count((it.ITEM_STATE=5 or it.ITEM_STATE=10) or null)/count(it.id),4),4),'0.0000') as
resolvedRatio,
ifnull(format(round(count((it.EVALUATION_SCORE=1 or it.EVALUATION_SCORE=2) or null)/count(it.id),4),4),'0.0000')
as goodRatio,
count( (it.EVALUATION_SCORE=0 or it.EVALUATION_SCORE=1 or it.EVALUATION_SCORE=2) or null) as evaluateTotal,
count( (it.EVALUATION_SCORE=1 or it.EVALUATION_SCORE=2) or null) as goodTotal,
count( it.EVALUATION_SCORE=0 or null) as badTotal,
ifnull(format(round(count(it.EVALUATION_SCORE=0 or null)/count( (it.EVALUATION_SCORE=0 or it.EVALUATION_SCORE=1 or it.EVALUATION_SCORE=2) or null),4),4),'0.0000') as badRatio
left join (select lin.* from (select * from <includerefid="com.elink.esua.epdc.modules.common.dao.EpdcTableNameDao.tb_events"/>.epdc_item order by id) lin
count((it.ITEM_STATE=5 or it.ITEM_STATE=10) or null) as resolvedNum,
ifnull(format(round(count((it.ITEM_STATE=5 or it.ITEM_STATE=10) or null)/count(it.id),4),4),'0.0000') as resolvedRatio,
ifnull(format(round(count((it.EVALUATION_SCORE=1 or it.EVALUATION_SCORE=2) or null)/count(it.id),4),4),'0.0000') as goodRatio,
count( (it.EVALUATION_SCORE=0 or it.EVALUATION_SCORE=1 or it.EVALUATION_SCORE=2) or null) as evaluateTotal,
count( (it.EVALUATION_SCORE=1 or it.EVALUATION_SCORE=2) or null) as goodTotal,
count( it.EVALUATION_SCORE=0 or null) as badTotal,
ifnull(format(round(count(it.EVALUATION_SCORE=0 or null)/count( (it.EVALUATION_SCORE=0 or it.EVALUATION_SCORE=1 or it.EVALUATION_SCORE=2) or null),4),4),'0.0000') as badRatio
FROM `esua_epdc_admin`.`sys_dept` sd
left join `esua_epdc_admin`.`sys_dept` co on co.id=sd.pid
left join `esua_epdc_admin`.`sys_dept` st on st.id=co.pid
left join `esua_epdc_admin`.`sys_dept` di on di.id=st.pid
left join (select lin.* from (select * from <includerefid="com.elink.esua.epdc.modules.common.dao.EpdcTableNameDao.tb_events"/>.epdc_item order by id) lin
AND date_format( lin.CREATED_TIME, '%Y-%m-%d' ) <=#{yesterDayDate}
group by lin.EVENT_ID) it on it.GRID_ID=sd.id
WHERE sd.`del_flag`= 0
AND sd.`type_key`= 'grid_party'
AND sd.`id` NOT IN( SELECT t.`dept_id`
FROM `esua_epdc_admin`.`sys_dept_config` t
WHERE t.`del_flag`= 0)
group by di.id
union all
SELECT st.`id` AS orgId,
'street' as orgType,
st.pid AS pid,
st.pids AS pids,
count(it.id) as projectTotal,
count((it.ITEM_STATE=5 or it.ITEM_STATE=10) or null) as resolvedNum,
ifnull(format(round(count((it.ITEM_STATE=5 or it.ITEM_STATE=10) or null)/count(it.id),4),4),'0.0000') as resolvedRatio,
ifnull(format(round(count((it.EVALUATION_SCORE=1 or it.EVALUATION_SCORE=2) or null)/count(it.id),4),4),'0.0000') as goodRatio,
count( (it.EVALUATION_SCORE=0 or it.EVALUATION_SCORE=1 or it.EVALUATION_SCORE=2) or null) as evaluateTotal,
count( (it.EVALUATION_SCORE=1 or it.EVALUATION_SCORE=2) or null) as goodTotal,
count( it.EVALUATION_SCORE=0 or null) as badTotal,
ifnull(format(round(count(it.EVALUATION_SCORE=0 or null)/count( (it.EVALUATION_SCORE=0 or it.EVALUATION_SCORE=1 or it.EVALUATION_SCORE=2) or null),4),4),'0.0000') as badRatio
FROM `esua_epdc_admin`.`sys_dept` sd
left join `esua_epdc_admin`.`sys_dept` co on co.id=sd.pid
left join `esua_epdc_admin`.`sys_dept` st on st.id=co.pid
left join (select lin.* from (select * from <includerefid="com.elink.esua.epdc.modules.common.dao.EpdcTableNameDao.tb_events"/>.epdc_item order by id) lin
AND date_format( lin.CREATED_TIME, '%Y-%m-%d' ) <=#{yesterDayDate}
group by lin.EVENT_ID) it on it.GRID_ID=sd.id
WHERE sd.`del_flag`= 0
AND sd.`type_key`= 'grid_party'
AND sd.`id` NOT IN( SELECT t.`dept_id`
FROM `esua_epdc_admin`.`sys_dept_config` t
WHERE t.`del_flag`= 0)
group by st.id
union all
SELECT co.`id` AS orgId,
'community' as orgType,
co.pid AS pid,
co.pids AS pids,
count(it.id) as projectTotal,
count((it.ITEM_STATE=5 or it.ITEM_STATE=10) or null) as resolvedNum,
ifnull(format(round(count((it.ITEM_STATE=5 or it.ITEM_STATE=10) or null)/count(it.id),4),4),'0.0000') as resolvedRatio,
ifnull(format(round(count((it.EVALUATION_SCORE=1 or it.EVALUATION_SCORE=2) or null)/count(it.id),4),4),'0.0000') as goodRatio,
count( (it.EVALUATION_SCORE=0 or it.EVALUATION_SCORE=1 or it.EVALUATION_SCORE=2) or null) as evaluateTotal,
count( (it.EVALUATION_SCORE=1 or it.EVALUATION_SCORE=2) or null) as goodTotal,
count( it.EVALUATION_SCORE=0 or null) as badTotal,
ifnull(format(round(count(it.EVALUATION_SCORE=0 or null)/count( (it.EVALUATION_SCORE=0 or it.EVALUATION_SCORE=1 or it.EVALUATION_SCORE=2) or null),4),4),'0.0000') as badRatio
FROM `esua_epdc_admin`.`sys_dept` sd
left join `esua_epdc_admin`.`sys_dept` co on co.id=sd.pid
left join (select lin.* from (select * from <includerefid="com.elink.esua.epdc.modules.common.dao.EpdcTableNameDao.tb_events"/>.epdc_item order by id) lin