select
	 dep.glcname as name
	,dep.id as id
	,count(*) as taskTotal
	,SUM(CASE WHEN hi.END_TIME_ is not null THEN 1 ELSE 0 END) AS finishTotal
	,SUM(CASE WHEN hi.END_TIME_ is null  THEN 1 ELSE 0 END) AS noFinishTaskTotal
	,SUM(CASE WHEN hi.START_TIME_<ifnull(hi.END_TIME_,now()) +INTERVAL 0-:tookTime day THEN 1 ELSE 0 END) AS overdueCount

from
	ACT_HI_TASKINST hi
	inner join t_s_base_user bu on hi.ASSIGNEE_=bu.username
	inner join t_s_user_org org on org.user_id=bu.ID and ifpluralism='0' and org.status='0'
	inner join t_s_depart dep on org.org_id=dep.ID
where 1=1
<#if (entityParam.attType)??>
	and hi.START_TIME_ between :entityParam.attStartTime and :entityParam.attEndTime
</#if>

group by dep.id
order by taskTotal asc