AlarmHistoryMapper.xml 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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 in
  59. <foreach item="item" index="index" collection="category1.split(',')" open="(" separator="," close=")">
  60. #{item}
  61. </foreach>
  62. </if>
  63. <if test="category2 !=null and category2 !=''">
  64. and b.category2=#{category2}
  65. </if>
  66. <if test="rank !=null and rank !=''">
  67. and b.rank=#{rank}
  68. </if>
  69. <if test="modelid !=null and modelid !=''">
  70. and b.modelid=#{modelid}
  71. </if>
  72. <if test="snapid !=null ">
  73. and a.snapid=#{snapid}
  74. </if>
  75. <if test="messagetype !=null ">
  76. and a.messagetype=#{messagetype}
  77. </if>
  78. <if test="keyword !=null and keyword !=''">
  79. and b.alerttext like '%${keyword}%'
  80. </if>
  81. </where>
  82. order by a.alerttime desc
  83. </select>
  84. <!-- 联合查询 -->
  85. <select id="pageQueryAll2" parameterType="java.util.Map" resultType="com.gyee.wisdom.alarm.sharding.model.AlarmHistoryInfo">
  86. select a.*,
  87. b.stationid,
  88. b.windturbineid,
  89. b.projectid,
  90. b.lineid,
  91. b.alertvalue,
  92. b.category1,
  93. b.category2,
  94. b.category3,
  95. b.rank,
  96. b.stationname,
  97. b.projectname,
  98. b.linename,
  99. b.windturbinename,
  100. b.alerttext,
  101. b.modelid
  102. from (
  103. <foreach collection="simpleStationIdList" item="station" index="index" separator="union">
  104. select * from alarmhistory_${station}_${yearmonth}
  105. </foreach>
  106. ) a
  107. left join alarmsnap b on a.snapid = b.id
  108. <where>
  109. 1=1
  110. <if test="starttime !=null and endtime !=null">
  111. and a.alerttime &gt;= #{starttime,jdbcType=DATE} and a.alerttime &lt;= #{endtime,jdbcType=DATE}
  112. </if>
  113. <if test="stid !=null and stid !=''">
  114. and b.stationid=#{stid}
  115. </if>
  116. <if test="wtid !=null and wtid !=''">
  117. and b.windturbineid=#{wtid}
  118. </if>
  119. <if test="category1 !=null and category1 !=''">
  120. and b.category1 in
  121. <foreach item="item" index="index" collection="category1.split(',')" open="(" separator="," close=")">
  122. #{item}
  123. </foreach>
  124. </if>
  125. <if test="category2 !=null and category2 !=''">
  126. and b.category2=#{category2}
  127. </if>
  128. <if test="rank !=null and rank !=''">
  129. and b.rank=#{rank}
  130. </if>
  131. <if test="modelid !=null and modelid !=''">
  132. and b.modelid=#{modelid}
  133. </if>
  134. <if test="snapid !=null ">
  135. and a.snapid=#{snapid}
  136. </if>
  137. <if test="messagetype !=null ">
  138. and a.messagetype=#{messagetype}
  139. </if>
  140. <if test="keyword !=null and keyword !=''">
  141. and b.alerttext like '%${keyword}%'
  142. </if>
  143. </where>
  144. order by a.alerttime desc
  145. </select>
  146. <select id="selectSnapCount" parameterType="java.util.Map" resultType="java.lang.Integer">
  147. select count(*) from ${tbName} where snapid = #{snapid}
  148. and messagetype = '1'
  149. and alerttime &gt;= #{starttime,jdbcType=DATE} and alerttime &lt; #{endtime,jdbcType=DATE}
  150. </select>
  151. <select id="selectHistoryAlarmSnapAndWarning"
  152. resultType="com.gyee.wisdom.alarm.sharding.entity.FaultWarning">
  153. select h.id,
  154. a.stationid,
  155. h.snapid,
  156. a.windturbineid,
  157. a.windturbinename,
  158. a.lastupdatetime,
  159. w.ednavalue,
  160. h.alerttime,
  161. w.warningtypeid
  162. from alarmhistory_nss_202107 h
  163. left join alarmsnap a on h.snapid = a.id
  164. left join warning2 w on a.alertvalue = w.ednavalue
  165. and a.modelid = w.modelid
  166. <where>
  167. and a.category1 = 'windturbine'
  168. and h.messagetype = '1'
  169. <if test="starttime !=null and endtime !=null">
  170. h.alerttime &gt;= #{starttime,jdbcType=DATE} and h.alerttime &lt; #{endtime,jdbcType=DATE}
  171. </if>
  172. </where>
  173. </select>
  174. <update id="timedCreatTable">
  175. create table ALARMHISTORY_${stationname}_${yearmonth}
  176. (
  177. ID INTEGER not null,
  178. ALERTTIME DATE not null,
  179. MESSAGETYPE CHAR(1) default '1' not null,
  180. SNAPID INTEGER not null,
  181. DATAINFO VARCHAR2(1000),
  182. ALERTTEXTLAST VARCHAR2(50)
  183. )
  184. tablespace ${tablespace}
  185. pctfree 10
  186. initrans 1
  187. maxtrans 255
  188. storage
  189. (
  190. initial 16K
  191. minextents 1
  192. maxextents unlimited
  193. )
  194. </update>
  195. <update id="timedAlterTable">
  196. alter table ALARMHISTORY_${stationname}_${yearmonth}
  197. add constraint PK_ALARMHISTORY_${stationname}_${yearmonth} primary key (ID)
  198. using index
  199. tablespace ${tablespace}
  200. pctfree 10
  201. initrans 2
  202. maxtrans 255
  203. storage
  204. (
  205. initial 64K
  206. minextents 1
  207. maxextents unlimited
  208. )
  209. </update>
  210. <update id="timedCreatAlerttimeIndex">
  211. create index IX_AH_${stationname}_${yearmonth}_ALARMTIME on ALARMHISTORY_${stationname}_${yearmonth} (ALERTTIME)
  212. tablespace ${tablespace}
  213. pctfree 10
  214. initrans 2
  215. maxtrans 255
  216. storage
  217. (
  218. initial 64K
  219. minextents 1
  220. maxextents unlimited
  221. )
  222. </update>
  223. <update id="timedCreatSnapidIndex">
  224. create index IX_AH_${stationname}_${yearmonth}_SNAPID on ALARMHISTORY_${stationname}_${yearmonth} (SNAPID)
  225. tablespace ${tablespace}
  226. pctfree 10
  227. initrans 2
  228. maxtrans 255
  229. storage
  230. (
  231. initial 64K
  232. minextents 1
  233. maxextents unlimited
  234. )
  235. </update>
  236. <select id="isHasTable" resultType="java.lang.Integer">
  237. select count(*) from user_tables where table_name =upper('ALARMHISTORY_${stationname}_${yearmonth}')
  238. </select>
  239. </mapper>