AlarmHistoryMapper.xml 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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}, #{item.alertTime}, #{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}, #{item.alertTime}, #{item.messageType},#{item.snapId},#{item.dataInfo},#{item.alertTextLast}
  14. from dual )
  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="selectAlarmSnapCount" parameterType="java.util.Map" resultType="java.lang.Integer">
  146. select count(*) from ${tbName} where id = #{id}
  147. </select>
  148. <select id="selectAlarmHistory" parameterType="java.util.Map" resultType="com.gyee.wisdom.alarm.sharding.entity.AlarmHistory">
  149. select * from ${tbName} where snapid = #{snapid}
  150. and messagetype = '1'
  151. and alerttime &gt;= #{starttime,jdbcType=DATE} and alerttime &lt; #{endtime,jdbcType=DATE}
  152. </select>
  153. <select id="selectHistoryAlarmSnapAndWarning"
  154. resultType="com.gyee.wisdom.alarm.sharding.entity.FaultWarning">
  155. select h.id,
  156. a.stationid,
  157. h.snapid,
  158. a.windturbineid,
  159. a.windturbinename,
  160. a.lastupdatetime,
  161. w.ednavalue,
  162. h.alerttime,
  163. w.warningtypeid
  164. from ${tbName} h
  165. left join alarmsnap a on h.snapid = a.id
  166. left join warning2 w on a.alertvalue = w.ednavalue
  167. and a.modelid = w.modelid
  168. <where>
  169. and a.category1 = 'windturbine'
  170. and h.messagetype = '1'
  171. and
  172. <if test="starttime !=null and endtime !=null">
  173. h.alerttime &gt;= #{starttime,jdbcType=DATE} and h.alerttime &lt; #{endtime,jdbcType=DATE}
  174. </if>
  175. </where>
  176. </select>
  177. <update id="timedCreatTable">
  178. CREATE TABLE alarmhistory_${stationname}_${yearmonth} (
  179. `ID` decimal(65,0) NOT NULL,
  180. `ALERTTIME` datetime(6) NOT NULL,
  181. `MESSAGETYPE` char(1) NOT NULL,
  182. `SNAPID` decimal(65,0) NOT NULL,
  183. `DATAINFO` text,
  184. `ALERTTEXTLAST` varchar(50)
  185. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  186. </update>
  187. <update id="timedAlterTable">
  188. alter table alarmhistory_${stationname}_${yearmonth}
  189. add primary key (`id`)
  190. </update>
  191. <update id="timedCreatAlerttimeIndex">
  192. create index IX_AH_${stationname}_${yearmonth}_ALARMTIME on alarmhistory_${stationname}_${yearmonth} (alerttime)
  193. </update>
  194. <update id="timedCreatSnapidIndex">
  195. create index IX_AH_${stationname}_${yearmonth}_SNAPID on alarmhistory_${stationname}_${yearmonth} (snapid)
  196. </update>
  197. <select id="isHasTable" resultType="java.lang.Integer">
  198. select count(*) from information_schema.TABLES where table_name =upper('ALARMHISTORY_${stationname}_${yearmonth}')
  199. </select>
  200. <select id="getlatestAlarmHistory" parameterType="java.util.Map" resultType="com.gyee.wisdom.alarm.sharding.model.AlarmHistoryInfo">
  201. SELECT * FROM ${tbName} a
  202. <where>
  203. <if test="snapId !=null and snapId !=''">
  204. and a.SNAPID=#{snapId}
  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,1
  214. </select>
  215. </mapper>