<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//oos.juyouhx.com//DTD Mapper 3.0//EN" "http://oss.juyouhx.com/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.scpyun.platform.standard.jilinsscgsdp.focusareas" name="重点领域统计">

    <select id="getArea" resultType="String" parameterType="String">
        SELECT
        id
        FROM
        sys_area
        where
        type = #{type};
    </select>
    
    <select id="geteventCategoryId" resultType="String">
        select
        value
        from
        sys_dict
        where
        type = 'event_category'
        and parent_id='0'
        and value != 'event_category20'
    </select>
    
    <update id="updateinfo" parameterType="map">
        UPDATE `ji_warning_focus_areas`
        SET
        count	= #{count},
        percentage = #{percentage},
        alarm_level = #{alarmLevel}
        WHERE
        region_code = #{regionCode}
        and
        area_level = #{areaLevel}
        and
        statistical_time = #{statisticalTime}
        and
        event_category_id = #{eventCategoryId}
    </update>

    <select id="getFocusAreasCount" parameterType="com.scpyun.platform.jilinsscgsdp.bean.dto.FocusAreasStatisticsDTO" resultType="Integer">
        SELECT count(*) FROM ji_warning_focus_areas
        <where>
            statistical_time &gt;= CONCAT(YEAR(NOW()), '-01')
            AND statistical_time &lt;= CONCAT(YEAR(NOW()), '-12')
            <if test="alarmLevel == 1 or alarmLevel == 2">
                AND alarm_level = #{alarmLevel}
            </if>
            <if test="cityId != null and cityId != ''">
                AND area_level = 2 AND region_code = #{cityId}
            </if>
            <if test="areaId != null and areaId != ''">
                AND area_level = 3 AND region_code = #{areaId}
            </if>
            <if test="_user.company_grade == '2'.toString()">
                AND area_level = 1
            </if>
            <if test="_user.company_grade == '3'.toString()">
                AND area_level = 2 AND region_code  = #{_user.company_id}
            </if>
            <if test="_user.company_grade == '4'.toString()">
                AND area_level = 3 AND region_code  = #{_user.company_id}
            </if>
        </where>
    </select>
    <insert id="insertFocusArea" parameterType="com.scpyun.platform.jilinsscgsdp.bean.entity.FocusAreas">
        INSERT INTO ji_warning_focus_areas (
        fid,
        event_category_id,
        percentage,
        count,
        statistical_time,
        region_code,
        area_level,
        alarm_level,
        create_time
        )
        VALUES (
        #{fid},
        #{eventCategoryId},
        #{percentage},
        #{count},
        #{statisticalTime},
        #{regionCode},
        #{areaLevel},
        #{alarmLevel},
        now()
        )
    </insert>

    <delete id="truncateTable" parameterType="java.lang.String">
        delete from ji_warning_focus_areas
    </delete>

    <select id="getlevel" parameterType="map" resultType="integer">
        SELECT
        IFNULL(alarm_level, '0') AS alarmLevel
        FROM `ji_warning_focus_areas`
        WHERE
        event_category_id = #{eventCategoryId}
        AND statistical_time = #{statisticalTime}
        AND region_code = #{regionCode}
    </select>


    <select id="findAllOne" parameterType="map" resultType="com.scpyun.platform.jilinsscgsdp.bean.entity.FocusAreas">
        SELECT
        `id` id ,
        `fid` fid,
        `event_category_id` eventCategoryId,
        `percentage` percentage,
        `count` count,
        `statistical_time` statisticalTime,
        `region_code` regionCode,
        `area_level` areaLevel,
        `alarm_level` alarmLevel
        FROM `ji_warning_focus_areas`
        where
        event_category_id = #{eventCategoryId}
        and
        statistical_time = #{statisticalTime}
        and
        region_code =#{regionCode}
    </select>

    <select id="findAllFids" resultType="map">
        SELECT
        `fid` fid
        FROM `ji_warning_focus_areas`;
    </select>
</mapper>
