<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.unis.safeStorage.modular.ssriskaccident.mapper.BizSsRiskAccidentMapper">

    <select id="getNumberByType" parameterType="java.util.Map" resultType="java.util.Map">
        SELECT
            -- c.zcdz_city zcdzCity,
            a.occurrence_time occurrenceTime,
            a.accident_type accidentType,
            COUNT(DISTINCT a.id) numberOccurrence
        FROM
            biz_ss_risk_accident a
                LEFT JOIN depot_qh.org_info b ON b.org_id = a.org_id
                LEFT JOIN biz_unit_info c ON c.id = a.unit_info_id
        WHERE 1=1
            <if test="orgName != null and orgName != ''" >
                AND b.org_name LIKE '%${orgName}%'
            </if>
            <if test="zcdzCity != null and zcdzCity != ''" >
                AND c.zcdz_city = #{zcdzCity}
            </if>
            <if test="startTime != null and startTime != ''" >
                AND a.occurrence_time >= #{startTime}
            </if>
            <if test="endTime != null and endTime != ''" >
                AND a.occurrence_time le #{endTime}
            </if>
        GROUP BY
            accidentType
    </select>

    <select id="getNumberByZcdzCity" parameterType="java.util.Map" resultType="java.util.Map">
        SELECT
        c.zcdz_city zcdzCity,
        d.dict_label zcdzName,
        a.occurrence_time occurrenceTime,
        -- a.accident_type accidentType,
        COUNT(DISTINCT a.id) numberOccurrence
        FROM
        biz_ss_risk_accident a
        LEFT JOIN depot_qh.org_info b ON b.org_id = a.org_id
        LEFT JOIN biz_unit_info c ON c.id = a.unit_info_id
        LEFT JOIN dev_dict d on d.id = c.zcdz_city
        WHERE 1=1
            <if test="orgName != null and orgName != ''" >
                AND b.org_name LIKE '%${orgName}%'
            </if>
            <if test="zcdzCity != null and zcdzCity != ''" >
                AND c.zcdz_city = #{zcdzCity}
            </if>
            <if test="startTime != null and startTime != ''" >
                AND a.occurrence_time >= #{startTime}
            </if>
            <if test="endTime != null and endTime != ''" >
                AND a.occurrence_time le #{endTime}
            </if>
        GROUP BY
           zcdzCity
    </select>
</mapper>