| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 | <?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.zhyc.xps.aqpt.mapper.AlertStatisMapper">    <!-- 按状态统计 -->    <select id="counterByStatus" parameterType="java.util.Map" resultType="com.zhyc.xps.aqpt.vo.AlertByStatusVo">        SELECT            IFNULL(SUM( CASE WHEN A.status = 0  THEN 1 ELSE 0 END ), 0) AS 'active' ,            IFNULL(SUM( CASE WHEN A.status = 1  THEN 1 ELSE 0 END ), 0) AS 'solved' ,            IFNULL(SUM( CASE WHEN A.status = -1 THEN 1 ELSE 0 END ), 0) AS 'canceled'        FROM      alert      AS A        LEFT JOIN s_group    AS B ON (A.oc_id = B.oc_id AND A.handle_group_id = B.group_id)        WHERE 1 = 1        <if test="ocId != null">            AND A.oc_id = #{ocId}        </if>        <if test="nodeLeft != null and nodeRight != null">        <![CDATA[            AND B.node_left  >= #{nodeLeft ,jdbcType=BIGINT}            AND B.node_right <= #{nodeRight ,jdbcType=BIGINT}        ]]>        </if>    </select>    <!-- 按月份统计 -->    <select id="counterByMonth"  parameterType="java.util.Map" resultType="com.zhyc.xps.aqpt.vo.AlertByMonthVo">        SELECT            IFNULL(SUM(CASE MONTH(A.alert_time) WHEN '1'  THEN 1 ELSE 0 END) ,0) AS M1,            IFNULL(SUM(CASE MONTH(A.alert_time) WHEN '2'  THEN 1 ELSE 0 END) ,0) AS M2,            IFNULL(SUM(CASE MONTH(A.alert_time) WHEN '3'  THEN 1 ELSE 0 END) ,0) AS M3,            IFNULL(SUM(CASE MONTH(A.alert_time) WHEN '4'  THEN 1 ELSE 0 END) ,0) AS M4,            IFNULL(SUM(CASE MONTH(A.alert_time) WHEN '5'  THEN 1 ELSE 0 END) ,0) AS M5,            IFNULL(SUM(CASE MONTH(A.alert_time) WHEN '6'  THEN 1 ELSE 0 END) ,0) AS M6,            IFNULL(SUM(CASE MONTH(A.alert_time) WHEN '7'  THEN 1 ELSE 0 END) ,0) AS M7,            IFNULL(SUM(CASE MONTH(A.alert_time) WHEN '8'  THEN 1 ELSE 0 END) ,0) AS M8,            IFNULL(SUM(CASE MONTH(A.alert_time) WHEN '9'  THEN 1 ELSE 0 END) ,0) AS M9,            IFNULL(SUM(CASE MONTH(A.alert_time) WHEN '10' THEN 1 ELSE 0 END) ,0) AS M10,            IFNULL(SUM(CASE MONTH(A.alert_time) WHEN '11' THEN 1 ELSE 0 END) ,0) AS M11,            IFNULL(SUM(CASE MONTH(A.alert_time) WHEN '12' THEN 1 ELSE 0 END) ,0) AS M12        FROM  alert AS A        WHERE A.status != -1        <if test="ocId != null">            AND A.oc_id = #{ocId}        </if>        <if test="status != null">            AND A.status = #{status}        </if>        <if test="year != null">            AND YEAR(A.handle_time) = #{year}        </if>    </select>    <!-- 按条件统计 -->    <select id="counterByCondition" parameterType="java.util.Map" resultType="int">        SELECT            count(*)        FROM      alert    AS A        LEFT JOIN s_group  AS B ON (A.oc_id = B.oc_id AND A.handle_group_id = B.group_id)        WHERE A.status != -1        <if test="ocId != null">            AND A.oc_id = #{ocId}        </if>        <if test="nodeLeft != null and nodeRight != null">            <![CDATA[                AND B.node_left  >= #{nodeLeft  ,jdbcType=BIGINT}                AND B.node_right <= #{nodeRight ,jdbcType=BIGINT}            ]]>        </if>        <if test="day != null">            AND date_format(A.alert_time, '%Y-%m-%d') = #{day}        </if>        <if test="startDate != null and endDate != null">            AND A.alert_time BETWEEN #{startDate} and #{endDate}        </if>    </select>    <!-- 综合统计 -->    <select id="getCounter" parameterType="java.util.Map" resultType="com.zhyc.xps.aqpt.vo.AlertCounterVo">        SELECT  count( 0 )                                      AS "total",            IFNULL(SUM( IF ( A.alert_level = 1, 1, 0 )), 0)     AS "level1",            IFNULL(SUM( IF ( A.alert_level = 2, 1, 0 )), 0)     AS "level2",            IFNULL(SUM( IF ( A.alert_level = 3, 1, 0 )), 0)     AS "level3",            IFNULL(SUM( IF ( A.alert_level = 4, 1, 0 )), 0)     AS "level4",            IFNULL(SUM( IF ( A.alert_level = 5, 1, 0 )), 0)     AS "level5",            IFNULL(SUM( IF ( A.alert_level = 6, 1, 0 )), 0)     AS "level6",            IFNULL(SUM( IF ( A.status      = 0, 1, 0 )), 0)     AS "active",            IFNULL(SUM( IF ( A.status      = 1, 1, 0 )), 0)     AS "solved",            IFNULL(SUM( IF ( A.status     = -1, 1, 0 )), 0)     AS "canceled"        FROM      alert    AS A        LEFT JOIN s_group  AS B ON (A.oc_id = B.oc_id AND A.handle_group_id = B.group_id)        WHERE   A.deleted_flag = 0        <if test="ocId != null">            AND A.oc_id = #{ocId ,jdbcType=BIGINT}        </if>        <if test="alertTime != null">            AND DATE_FORMAT(A.alert_time,'%Y-%m-%d') = #{alertTime}        </if>        <if test="year != null">            AND YEAR(A.alert_time) = #{year}        </if>        <if test="month != null">            AND MONTH(A.alert_time) = #{month}        </if>        <if test="nodeLeft != null and nodeRight != null">        <![CDATA[             AND             B.node_left >= #{nodeLeft, jdbcType=BIGINT}             AND             B.node_right <= #{nodeRight, jdbcType=BIGINT}        ]]>        </if>        ORDER BY A.alert_time DESC    </select></mapper>
 |