(SELECT COUNT(1) FROM cb_firefighters t WHERE t.BIZ_ORG_CODE LIKE CONCAT(t2.BIZ_ORG_CODE, '%') AND t.PEOPLE_TYPE = 1601 AND t.IS_DELETE = false) AS firefighterNum,
ROUND(ROUND(IFNULL(t1.num, 0) / (SELECT COUNT(1) FROM cb_firefighters t WHERE t.BIZ_ORG_CODE LIKE CONCAT(t2.BIZ_ORG_CODE, '%') AND t.PEOPLE_TYPE = 1601 AND t.IS_DELETE = false), 4) * 100, 2) AS attendanceRate,
IF(IFNULL(t1.num, 0) >= #{targetPassNum}, '合格', '不合格') AS attendanceStatus
FROM (
SELECT
t.BIZ_ORG_CODE AS bizOrgCode,
COUNT( DISTINCT t.user_id ) AS num
FROM
cb_sign t
<where>
t.DATE = #{date}
<iftest="bizOrgCode != null and bizOrgCode != ''">
AND t.BIZ_ORG_CODE LIKE CONCAT(#{bizOrgCode}, '%')
</if>
</where>
GROUP BY
t.BIZ_ORG_CODE
) t1
RIGHT JOIN idx_biz_station_info t2 ON t2.BIZ_ORG_CODE = t1.bizOrgCode
<where>
<iftest="bizOrgCode != null and bizOrgCode != ''">
AND t2.BIZ_ORG_CODE LIKE CONCAT(#{bizOrgCode}, '%')
</if>
<iftest="stationType != null and stationType != ''">
AND t2.STATION_TYPE = #{stationType}
</if>
<iftest="attendanceStatus != null and attendanceStatus != ''">
AND IF(IFNULL(t1.num, 0) >= #{targetPassNum}, 'pass', 'fail') = #{attendanceStatus}