AlarmCountMapper.xml 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.gyee.wisdom.alarm.schedule.mapper.AlarmCountMapper">
  4. <resultMap type="com.gyee.wisdom.alarm.schedule.entity.AlarmCount" id="myAlarmCount">
  5. <result property="id" column="id"/>
  6. <result property="alarmDate" column="alarmDate"/>
  7. <result property="snapId" column="snapId"/>
  8. <result property="count" column="count"/>
  9. <result property="time" column="time"/>
  10. <result property="alertValue" column="alertValue"/>
  11. <result property="windturbineId" column="windturbineId"/>
  12. </resultMap>
  13. <insert id="singleInsert" >
  14. insert into alarmcount (id, alarmdate, snapid, count)
  15. values
  16. (#{item.id}, cast(#{item.alarmDate} as timestamp), #{item.snapId}, #{item.count})
  17. </insert>
  18. <insert id="batchInsert" parameterType="java.util.List" useGeneratedKeys="false">
  19. insert into alarmcount ( ID, alarmdate, snapid, count,time )
  20. <foreach collection="list" item="item" index="index" separator="union all" >
  21. ( select
  22. #{item.id}, cast(#{item.alarmDate} as timestamp), #{item.snapId}, #{item.count} ,#{item.time}
  23. )
  24. </foreach>
  25. </insert>
  26. <select id="selectAlarmHistoryBySnapid" parameterType="java.util.Map" resultType="com.gyee.wisdom.alarm.schedule.entity.AlarmHistory" >
  27. select * from ${alarmhistory} where snapid = #{snapid}
  28. and alerttime &gt;= #{startdate,jdbcType=DATE} and alerttime &lt; #{enddate,jdbcType=DATE} order by alerttime asc
  29. </select>
  30. <select id="statAlarmCount1" parameterType="java.util.Map" resultType="com.gyee.wisdom.alarm.schedule.entity.AlarmStat1" >
  31. select t.*, s.stationid, s.windturbineid, s.alerttext from (
  32. select snapid, sum(count) as count,sum(time) time from alarmcount a
  33. left join alarmsnap ss on a.snapid = ss.id
  34. where ss.stationid = #{stationid} and ss.windturbineid is not null
  35. and alarmdate &gt;= #{startdate,jdbcType=DATE} and alarmdate &lt; #{enddate,jdbcType=DATE}
  36. group by snapid ) t
  37. left join alarmsnap s on t.snapid = s.id
  38. order by s.windturbineid
  39. </select>
  40. <select id="statAlarmCount5" parameterType="java.util.Map" resultType="com.gyee.wisdom.alarm.schedule.entity.AlarmStat1" >
  41. select * from alarmcount a
  42. LEFT JOIN alarmsnap s on a.snapid = s.id
  43. <where>
  44. 1=1
  45. <if test="startdate !=null and enddate !=null">
  46. and a.alarmdate &gt;= #{startdate,jdbcType=DATE} and a.alarmdate &lt;= #{enddate,jdbcType=DATE}
  47. </if>
  48. <if test="stationid !=null and stationid !=''">
  49. and s.stationid=#{stationid}
  50. </if>
  51. <if test="windturbineid !=null and windturbineid !=''">
  52. and s.windturbineid=#{windturbineid}
  53. </if>
  54. </where>
  55. </select>
  56. <select id="statAlarmCount" parameterType="java.util.Map" resultType="com.gyee.wisdom.alarm.schedule.entity.AlarmStat" >
  57. select t.snapid, t.count as sum, t.times as times, s.windturbineid as wtnum, s.alerttext as text from (
  58. select snapid, sum(count) as count, sum(time) as times from alarmcount a
  59. left join alarmsnap ss on a.snapid = ss.id
  60. where ss.stationid = #{stationid} and ss.windturbineid is not null
  61. and alarmdate >= #{startdate,jdbcType=DATE} and alarmdate &lt;= #{enddate,jdbcType=DATE}
  62. group by snapid ) t
  63. left join alarmsnap s on t.snapid = s.id
  64. order by s.windturbineid
  65. </select>
  66. <select id="statAlarmCount3" parameterType="java.util.Map" resultType="com.gyee.wisdom.alarm.schedule.entity.AlarmStat" >
  67. select t.snapid, t.count as sum, t.times as times, s.windturbineid as wtnum, s.alerttext as text from (
  68. select snapid, sum(count) as count, sum(time) as times from alarmcount a
  69. left join alarmsnap ss on a.snapid = ss.id
  70. <where>
  71. 1=1
  72. <if test="startdate !=null and enddate !=null">
  73. and a.alarmdate &gt;= #{startdate,jdbcType=DATE} and a.alarmdate &lt;= #{enddate,jdbcType=DATE}
  74. </if>
  75. <if test="stationid !=null and stationid !=''">
  76. and ss.stationid=#{stationid}
  77. </if>
  78. <if test="windturbineid !=null and windturbineid !=''">
  79. and ss.windturbineid=#{windturbineid}
  80. </if>
  81. </where>
  82. group by snapid ) t
  83. left join alarmsnap s on t.snapid = s.id
  84. order by s.windturbineid
  85. </select>
  86. <select id="statAlarmCountByName" parameterType="java.util.Map" resultType="com.gyee.wisdom.alarm.schedule.entity.AlarmStat" >
  87. select t.count as sum, s.windturbineid as wtnum, s.alerttext as text from (
  88. select snapid, sum(count) as count from alarmcount a
  89. left join alarmsnap ss on a.snapid = ss.id
  90. where ss.alerttext=#{name} and ss.stationid = #{stationid} and ss.windturbineid is not null
  91. and alarmdate >= #{startdate,jdbcType=DATE} and alarmdate &lt;= #{enddate,jdbcType=DATE}
  92. group by snapid ) t
  93. left join alarmsnap s on t.snapid = s.id
  94. order by s.windturbineid
  95. </select>
  96. <select id="selectAlertRuleNames" resultType="com.gyee.wisdom.alarm.schedule.model.CodeValue" >
  97. select name as code, description as value from alertrule2 group by name, description
  98. </select>
  99. <select id="statAlarmCount2" resultType="com.gyee.wisdom.alarm.schedule.entity.AlarmStat1">
  100. select t.*, s.stationid, s.windturbineid, s.alerttext from (
  101. select snapid, sum(count) as count,sum(time) time from alarmcount a
  102. left join alarmsnap ss on a.snapid = ss.id
  103. where
  104. ss.windturbineid is not null
  105. and a.alarmdate &gt;= #{currentDate,jdbcType=DATE}
  106. <if test="stationid !=null and stationid !=''">
  107. and ss.stationid = #{stationid}
  108. </if>
  109. group by snapid ) t
  110. left join alarmsnap s on t.snapid = s.id
  111. order by s.windturbineid
  112. </select>
  113. <select id="getAlarmCountInfo" parameterType="java.util.Map" resultType="com.gyee.wisdom.alarm.schedule.entity.AlarmCountInfo">
  114. SELECT
  115. a.id, a.alarmdate,a.snapid,a.count, a.time,
  116. s.ALERTTEXT, s.WINDTURBINEID, s.RANK,
  117. r.id as alertruleid, r.relatedParts, r.PROJECT
  118. FROM
  119. alarmcount a
  120. LEFT JOIN alarmsnap s ON a.snapid = s.id
  121. LEFT JOIN alertrule2 r ON s.ALERTVALUE = r.ednaValue
  122. WHERE
  123. a.alarmdate = #{currentDate}
  124. AND s.windturbineid = #{windturbineid}
  125. </select>
  126. <select id="getAlarmCountBySnapIdList" parameterType="java.util.Map" resultMap="myAlarmCount">
  127. SELECT
  128. a.id as id, a.alarmdate as alarmDate,a.snapid as snapId,a.count as count, a.time as time, s.alertvalue as alertValue, s.windturbineid as windturbineId
  129. FROM
  130. alarmcount a
  131. LEFT JOIN alarmsnap s ON a.snapid = s.id
  132. WHERE
  133. 1=1
  134. <if test="startTime !=null and endTime !=null">
  135. and a.alarmdate &gt;= #{startTime,jdbcType=DATE} and a.alarmdate &lt;#{endTime,jdbcType=DATE}
  136. </if>
  137. <if test="snapIdList !=null and snapIdList.size > 0">
  138. and a.snapid in
  139. <foreach collection="snapIdList" item="snapId" index="index" open="(" close=")" separator=",">
  140. #{snapId}
  141. </foreach>
  142. </if>
  143. </select>
  144. </mapper>