AlertStatisMapper.xml 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  3. "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
  4. <mapper namespace="com.zhyc.xps.aqpt.mapper.AlertStatisMapper">
  5. <!-- 按状态统计 -->
  6. <select id="counterByStatus" parameterType="java.util.Map" resultType="com.zhyc.xps.aqpt.vo.AlertByStatusVo">
  7. SELECT
  8. IFNULL(SUM( CASE WHEN A.status = 0 THEN 1 ELSE 0 END ), 0) AS 'active' ,
  9. IFNULL(SUM( CASE WHEN A.status = 1 THEN 1 ELSE 0 END ), 0) AS 'solved' ,
  10. IFNULL(SUM( CASE WHEN A.status = -1 THEN 1 ELSE 0 END ), 0) AS 'canceled'
  11. FROM alert AS A
  12. LEFT JOIN s_group AS B ON (A.oc_id = B.oc_id AND A.handle_group_id = B.group_id)
  13. WHERE 1 = 1
  14. <if test="ocId != null">
  15. AND A.oc_id = #{ocId}
  16. </if>
  17. <if test="nodeLeft != null and nodeRight != null">
  18. <![CDATA[
  19. AND B.node_left >= #{nodeLeft ,jdbcType=BIGINT}
  20. AND B.node_right <= #{nodeRight ,jdbcType=BIGINT}
  21. ]]>
  22. </if>
  23. </select>
  24. <!-- 按月份统计 -->
  25. <select id="counterByMonth" parameterType="java.util.Map" resultType="com.zhyc.xps.aqpt.vo.AlertByMonthVo">
  26. SELECT
  27. IFNULL(SUM(CASE MONTH(A.alert_time) WHEN '1' THEN 1 ELSE 0 END) ,0) AS M1,
  28. IFNULL(SUM(CASE MONTH(A.alert_time) WHEN '2' THEN 1 ELSE 0 END) ,0) AS M2,
  29. IFNULL(SUM(CASE MONTH(A.alert_time) WHEN '3' THEN 1 ELSE 0 END) ,0) AS M3,
  30. IFNULL(SUM(CASE MONTH(A.alert_time) WHEN '4' THEN 1 ELSE 0 END) ,0) AS M4,
  31. IFNULL(SUM(CASE MONTH(A.alert_time) WHEN '5' THEN 1 ELSE 0 END) ,0) AS M5,
  32. IFNULL(SUM(CASE MONTH(A.alert_time) WHEN '6' THEN 1 ELSE 0 END) ,0) AS M6,
  33. IFNULL(SUM(CASE MONTH(A.alert_time) WHEN '7' THEN 1 ELSE 0 END) ,0) AS M7,
  34. IFNULL(SUM(CASE MONTH(A.alert_time) WHEN '8' THEN 1 ELSE 0 END) ,0) AS M8,
  35. IFNULL(SUM(CASE MONTH(A.alert_time) WHEN '9' THEN 1 ELSE 0 END) ,0) AS M9,
  36. IFNULL(SUM(CASE MONTH(A.alert_time) WHEN '10' THEN 1 ELSE 0 END) ,0) AS M10,
  37. IFNULL(SUM(CASE MONTH(A.alert_time) WHEN '11' THEN 1 ELSE 0 END) ,0) AS M11,
  38. IFNULL(SUM(CASE MONTH(A.alert_time) WHEN '12' THEN 1 ELSE 0 END) ,0) AS M12
  39. FROM alert AS A
  40. WHERE A.status != -1
  41. <if test="ocId != null">
  42. AND A.oc_id = #{ocId}
  43. </if>
  44. <if test="status != null">
  45. AND A.status = #{status}
  46. </if>
  47. <if test="year != null">
  48. AND YEAR(A.handle_time) = #{year}
  49. </if>
  50. </select>
  51. <!-- 按条件统计 -->
  52. <select id="counterByCondition" parameterType="java.util.Map" resultType="int">
  53. SELECT
  54. count(*)
  55. FROM alert AS A
  56. LEFT JOIN s_group AS B ON (A.oc_id = B.oc_id AND A.handle_group_id = B.group_id)
  57. WHERE A.status != -1
  58. <if test="ocId != null">
  59. AND A.oc_id = #{ocId}
  60. </if>
  61. <if test="nodeLeft != null and nodeRight != null">
  62. <![CDATA[
  63. AND B.node_left >= #{nodeLeft ,jdbcType=BIGINT}
  64. AND B.node_right <= #{nodeRight ,jdbcType=BIGINT}
  65. ]]>
  66. </if>
  67. <if test="day != null">
  68. AND date_format(A.alert_time, '%Y-%m-%d') = #{day}
  69. </if>
  70. <if test="startDate != null and endDate != null">
  71. AND A.alert_time BETWEEN #{startDate} and #{endDate}
  72. </if>
  73. </select>
  74. <!-- 综合统计 -->
  75. <select id="getCounter" parameterType="java.util.Map" resultType="com.zhyc.xps.aqpt.vo.AlertCounterVo">
  76. SELECT count( 0 ) AS "total",
  77. IFNULL(SUM( IF ( A.alert_level = 1, 1, 0 )), 0) AS "level1",
  78. IFNULL(SUM( IF ( A.alert_level = 2, 1, 0 )), 0) AS "level2",
  79. IFNULL(SUM( IF ( A.alert_level = 3, 1, 0 )), 0) AS "level3",
  80. IFNULL(SUM( IF ( A.alert_level = 4, 1, 0 )), 0) AS "level4",
  81. IFNULL(SUM( IF ( A.alert_level = 5, 1, 0 )), 0) AS "level5",
  82. IFNULL(SUM( IF ( A.alert_level = 6, 1, 0 )), 0) AS "level6",
  83. IFNULL(SUM( IF ( A.status = 0, 1, 0 )), 0) AS "active",
  84. IFNULL(SUM( IF ( A.status = 1, 1, 0 )), 0) AS "solved",
  85. IFNULL(SUM( IF ( A.status = -1, 1, 0 )), 0) AS "canceled"
  86. FROM alert AS A
  87. LEFT JOIN s_group AS B ON (A.oc_id = B.oc_id AND A.handle_group_id = B.group_id)
  88. WHERE A.deleted_flag = 0
  89. <if test="ocId != null">
  90. AND A.oc_id = #{ocId ,jdbcType=BIGINT}
  91. </if>
  92. <if test="alertTime != null">
  93. AND DATE_FORMAT(A.alert_time,'%Y-%m-%d') = #{alertTime}
  94. </if>
  95. <if test="year != null">
  96. AND YEAR(A.alert_time) = #{year}
  97. </if>
  98. <if test="month != null">
  99. AND MONTH(A.alert_time) = #{month}
  100. </if>
  101. <if test="nodeLeft != null and nodeRight != null">
  102. <![CDATA[
  103. AND
  104. B.node_left >= #{nodeLeft, jdbcType=BIGINT}
  105. AND
  106. B.node_right <= #{nodeRight, jdbcType=BIGINT}
  107. ]]>
  108. </if>
  109. ORDER BY A.alert_time DESC
  110. </select>
  111. </mapper>