<?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.yeejoin.amos.boot.module.ccs.api.mapper.FireRpnChangeLogMapper">

    <select id="queryForRiseUp" resultType="java.util.Map">
      select
		d.countOfType0,
		d.countOfSource,
		CONCAT(ROUND(IFNULL(d.countOfType0/d.countOfSource,0)*100,2),'%')type0Rate
		 from
		(SELECT
			count(DISTINCT cl.risk_point_mrid) countOfType0,
			(select count(1) from asf_fire_risk_source rs where rs.station_code=cl.station_code ) countOfSource
		FROM
			asf_fire_rpn_change_log cl
		WHERE
			cl.level_change_type = 0
			and cl.station_code = #{stationCode}
			<choose>
                <when test="type = '1'">
                    and DATE_FORMAT( cl.create_date, '%Y%m' ) = DATE_FORMAT(CURDATE() , '%Y%m')
                </when>
                <when test="type = '2'">
                    and QUARTER(cl.create_date)=QUARTER(now());
                </when>
                <when test="type = '3'">
                    and year(cl.create_date)=year(now())
                </when>
            </choose>
		)d
    </select>
</mapper>
