<iftest="userId!=null and userId!=0">AND FIND_IN_SET(#{userId}, user_id)>0</if>
<iftest="userId!=null and userId!=0">AND FIND_IN_SET(#{userId}, user_id)>0</if>
<iftest="routeId!=null and routeId!=0">AND route_id = #{routeId}</if>
<iftest="routeId!=null and routeId!=0">AND route_id = #{routeId}</if>
<!-- <if test="orgCode!=null">AND org_code LIKE #{orgCode}</if>-->
<!-- <if test="orgCode!=null">AND org_code LIKE #{orgCode}</if>-->
<iftest="orgCode!=null">AND org_code LIKE concat(#{orgCode},'%') </if>
<iftest="orgCode!=null">AND org_code LIKE concat(#{orgCode},'%') </if>
GROUP BY is_ok,time
GROUP BY is_ok,time
ORDER BY time
ORDER BY time
</select>
</select>
<selectid="planCount"resultType="Map">
SELECT
SUM ( CASE WHEN pt.finish_status = '0' THEN ( CASE WHEN pl.plan_type = #{type} THEN 1 ELSE 0 END) ELSE 0 END ) notStart,
SUM ( CASE WHEN pt.finish_status = '2' THEN ( CASE WHEN pl.plan_type = #{type} THEN ( CASE WHEN pt.risk_status = '1' THEN 1 ELSE 0 END) ELSE 0 END) ELSE 0 END ) riskEnd,
SUM ( CASE WHEN pt.finish_status = '2' THEN ( CASE WHEN pl.plan_type = #{type} THEN ( CASE WHEN pt.risk_status = '2' THEN 1 ELSE 0 END) ELSE 0 END) ELSE 0 END ) noRiskEnd,
SUM ( CASE WHEN pt.finish_status = '3' THEN ( CASE WHEN pl.plan_type = #{type} THEN 1 ELSE 0 END) ELSE 0 END ) timeOut,
(
CASE
WHEN '2' = #{type} THEN date_part('week',pt.check_date) ELSE ( DATE_FORMAT ( pt.check_date, ( CASE WHEN '1' = #{type} THEN '%Y-%m-%d' ELSE '%Y-%m' END ) ) )
END
) stime,
pl.plan_type as type
FROM
p_plan_task pt left join p_plan pl on pt.plan_id = pl.id
WHERE
pl.plan_type = #{type}
<iftest="type!=null and type==1">AND DATE_FORMAT(pt.check_date, '%Y-%m') = left(#{checkTime}, 7) </if>
<iftest="type!=null and type==2">AND DATE_FORMAT(pt.check_date, '%Y-%m') = left(#{checkTime}, 7)</if>
<iftest="type!=null and type==3">DATE_FORMAT(pt.check_date, '%Y') = left(#{checkTime}, 4)</if>
<iftest="userId!=null and userId!=0">AND FIND_IN_SET(#{userId}, pt.user_id)>0</if>
<!-- <if test="orgCode!=null">AND org_code LIKE #{orgCode}</if>-->
<iftest="orgCode!=null">AND pt.org_code LIKE concat(#{orgCode}::text,'%') </if>