AlarmHistoryMapper.xml 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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.sharding.mapper.AlarmHisotryMapper">
  4. <insert id="singleInsert" >
  5. insert into ${tbName} (id, alerttime, messagetype,snapid, datainfo)
  6. values
  7. (#{item.id}, cast(#{item.alertTime} as timestamp), #{item.messageType},#{item.snapId},#{item.dataInfo})
  8. </insert>
  9. <insert id="batchInsert" parameterType="java.util.List" useGeneratedKeys="false">
  10. insert into ${tbName} ( ID, ALERTTIME, MESSAGETYPE, SNAPID, DATAINFO,ALERTTEXTLAST)
  11. <foreach collection="list" item="item" index="index" separator="union all" >
  12. ( select
  13. #{item.id}, cast(#{item.alertTime} as timestamp), #{item.messageType},#{item.snapId},#{item.dataInfo},#{item.alertTextLast}
  14. )
  15. </foreach>
  16. </insert>
  17. <!--<insert id="batchInsert" useGeneratedKeys="false">-->
  18. <!--INSERT ALL-->
  19. <!--<foreach item="item" index="index" collection="list">-->
  20. <!--into ${tbName}-->
  21. <!--values-->
  22. <!--(#{item.id}, #{item.alertTime}, #{item.messageType},#{item.snapId},#{item.dataInfo})-->
  23. <!--</foreach>-->
  24. <!--SELECT 1 FROM DUAL-->
  25. <!--</insert>-->
  26. <!-- 单表查询 -->
  27. <select id="pageQueryAll" parameterType="java.util.Map" resultType="com.gyee.wisdom.alarm.sharding.model.AlarmHistoryInfo">
  28. select a.*,
  29. b.stationid,
  30. b.windturbineid,
  31. b.projectid,
  32. b.lineid,
  33. b.alertvalue,
  34. b.category1,
  35. b.category2,
  36. b.category3,
  37. b.rank,
  38. b.stationname,
  39. b.projectname,
  40. b.linename,
  41. b.windturbinename,
  42. b.alerttext,
  43. b.modelid
  44. from ${tbName} a
  45. left join alarmsnap b on a.snapid = b.id
  46. <where>
  47. 1=1
  48. <if test="starttime !=null and endtime !=null">
  49. and a.alerttime &gt;= #{starttime} and a.alerttime &lt;= #{endtime}
  50. </if>
  51. <if test="stid !=null and stid !=''">
  52. and b.stationid=#{stid}
  53. </if>
  54. <if test="wtid !=null and wtid !=''">
  55. and b.windturbineid=#{wtid}
  56. </if>
  57. <if test="category1 !=null and category1 !=''">
  58. and b.category1=#{category1}
  59. </if>
  60. <if test="category2 !=null and category2 !=''">
  61. and b.category2=#{category2}
  62. </if>
  63. <if test="rank !=null and rank !=''">
  64. and b.rank=#{rank}
  65. </if>
  66. <if test="modelid !=null and modelid !=''">
  67. and b.modelid=#{modelid}
  68. </if>
  69. <if test="snapid !=null ">
  70. and a.snapid=#{snapid}
  71. </if>
  72. <if test="messagetype !=null ">
  73. and a.messagetype=#{messagetype}
  74. </if>
  75. <if test="keyword !=null and keyword !=''">
  76. and b.alerttext like '%${keyword}%'
  77. </if>
  78. </where>
  79. order by a.alerttime desc
  80. </select>
  81. <!-- 联合查询 -->
  82. <select id="pageQueryAll2" parameterType="java.util.Map" resultType="com.gyee.wisdom.alarm.sharding.model.AlarmHistoryInfo">
  83. select a.*,
  84. b.stationid,
  85. b.windturbineid,
  86. b.projectid,
  87. b.lineid,
  88. b.alertvalue,
  89. b.category1,
  90. b.category2,
  91. b.category3,
  92. b.rank,
  93. b.stationname,
  94. b.projectname,
  95. b.linename,
  96. b.windturbinename,
  97. b.alerttext,
  98. b.modelid
  99. from (
  100. <foreach collection="simpleStationIdList" item="station" index="index" separator="union">
  101. select * from alarmhistory_${station}_${yearmonth}
  102. </foreach>
  103. ) a
  104. left join alarmsnap b on a.snapid = b.id
  105. <where>
  106. 1=1
  107. <if test="starttime !=null and endtime !=null">
  108. and a.alerttime &gt;= #{starttime,jdbcType=DATE} and a.alerttime &lt;= #{endtime,jdbcType=DATE}
  109. </if>
  110. <if test="stid !=null and stid !=''">
  111. and b.stationid=#{stid}
  112. </if>
  113. <if test="wtid !=null and wtid !=''">
  114. and b.windturbineid=#{wtid}
  115. </if>
  116. <if test="category1 !=null and category1 !=''">
  117. and b.category1=#{category1}
  118. </if>
  119. <if test="category2 !=null and category2 !=''">
  120. and b.category2=#{category2}
  121. </if>
  122. <if test="rank !=null and rank !=''">
  123. and b.rank=#{rank}
  124. </if>
  125. <if test="modelid !=null and modelid !=''">
  126. and b.modelid=#{modelid}
  127. </if>
  128. <if test="snapid !=null ">
  129. and a.snapid=#{snapid}
  130. </if>
  131. <if test="messagetype !=null ">
  132. and a.messagetype=#{messagetype}
  133. </if>
  134. <if test="keyword !=null and keyword !=''">
  135. and b.alerttext like '%${keyword}%'
  136. </if>
  137. </where>
  138. order by a.alerttime desc
  139. </select>
  140. <select id="selectSnapCount" parameterType="java.util.Map" resultType="java.lang.Integer">
  141. select count(*) from ${tbName} where snapid = #{snapid}
  142. and messagetype = '1'
  143. and alerttime &gt;= #{starttime,jdbcType=DATE} and alerttime &lt; #{endtime,jdbcType=DATE}
  144. </select>
  145. <select id="selectHistoryAlarmSnapAndWarning"
  146. resultType="com.gyee.wisdom.alarm.sharding.entity.FaultWarning">
  147. select h.id,
  148. a.stationid,
  149. h.snapid,
  150. a.windturbineid,
  151. a.windturbinename,
  152. a.lastupdatetime,
  153. w.ednavalue,
  154. h.alerttime,
  155. w.warningtypeid
  156. from ${tbName} h
  157. left join alarmsnap a on h.snapid = a.id
  158. left join warning2 w on a.alertvalue = w.ednavalue
  159. and a.modelid = w.modelid
  160. <where>
  161. and a.category1 = 'windturbine'
  162. and h.messagetype = '1'
  163. and
  164. <if test="starttime !=null and endtime !=null">
  165. h.alerttime &gt;= #{starttime,jdbcType=DATE} and h.alerttime &lt; #{endtime,jdbcType=DATE}
  166. </if>
  167. </where>
  168. </select>
  169. <update id="timedCreatTable">
  170. CREATE TABLE alarmhistory_${stationname}_${yearmonth} (
  171. "id" numeric(20) not null
  172. constraint pk_alarmhistory_${stationname}_${yearmonth}
  173. primary key,
  174. "alerttime" timestamp not null,
  175. "messagetype" char not null,
  176. "snapid" numeric(20) not null,
  177. "datainfo" varchar(20),
  178. "alerttextlast" varchar(50)
  179. )
  180. </update>
  181. <update id="timedAlterTable">
  182. alter table alarmhistory_${stationname}_${yearmonth}
  183. owner to gdprod
  184. </update>
  185. <update id="timedCreatAlerttimeIndex">
  186. create index IX_AH_${stationname}_${yearmonth}_alerttime on alarmhistory_${stationname}_${yearmonth} ("alerttime")
  187. </update>
  188. <update id="timedCreatSnapidIndex">
  189. create index IX_AH_${stationname}_${yearmonth}_snapid on alarmhistory_${stationname}_${yearmonth} ("snapid")
  190. </update>
  191. <select id="isHasTable" resultType="java.lang.Integer">
  192. select count(*) from information_schema.TABLES where table_name =upper('alarmhistory_{stationname}_${yearmonth}')
  193. </select>
  194. <select id="getlatestAlarmHistory" parameterType="java.util.Map" resultType="com.gyee.wisdom.alarm.sharding.model.AlarmHistoryInfo">
  195. SELECT * FROM ${tbName} a
  196. <where>
  197. <!-- <if test="snapId !=null and snapId !=''">-->
  198. <!-- and a.SNAPID=#{snapId}-->
  199. <!-- </if>-->
  200. <if test="snapIdList!=null and snapIdList.size()>0">
  201. a.SNAPID in
  202. <foreach item="item" index="index" collection="snapIdList" open="(" separator="," close=")">
  203. #{item}
  204. </foreach>
  205. </if>
  206. <if test="messageType !=null and messageType !=''">
  207. and a.MESSAGETYPE=#{messageType}
  208. </if>
  209. <if test="starttime !=null and endtime !=null">
  210. and a.alerttime &gt;= #{starttime,jdbcType=DATE} and a.alerttime &lt;= #{endtime,jdbcType=DATE}
  211. </if>
  212. </where>
  213. order by a.ALERTTIME DESC LIMIT 0 OFFSET 1
  214. </select>
  215. </mapper>