AlarmHistoryMapper.xml 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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||a.alerttextlast as 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,jdbcType=DATE} and a.alerttime &lt;= #{endtime,jdbcType=DATE}
  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||a.alerttextlast as alerttext,
  98. b.modelid
  99. from (select *
  100. from alarmhistory_nss_${yearmonth}
  101. union
  102. select *
  103. from alarmhistory_mhs_${yearmonth}
  104. union
  105. select *
  106. from alarmhistory_sbq_${yearmonth}
  107. union
  108. select *
  109. from alarmhistory_xs_${yearmonth}
  110. union
  111. select *
  112. from alarmhistory_qs_${yearmonth}
  113. union
  114. select *
  115. from alarmhistory_hzj_${yearmonth}
  116. union
  117. select *
  118. from alarmhistory_mch_${yearmonth}
  119. union
  120. select *
  121. from alarmhistory_dwk_${yearmonth}
  122. union
  123. select *
  124. from alarmhistory_pl_${yearmonth}
  125. union
  126. select * from alarmhistory_xh_${yearmonth}) a
  127. left join alarmsnap b on a.snapid = b.id
  128. <where>
  129. 1=1
  130. <if test="starttime !=null and endtime !=null">
  131. and a.alerttime &gt;= #{starttime,jdbcType=DATE} and a.alerttime &lt;= #{endtime,jdbcType=DATE}
  132. </if>
  133. <if test="stid !=null and stid !=''">
  134. and b.stationid=#{stid}
  135. </if>
  136. <if test="wtid !=null and wtid !=''">
  137. and b.windturbineid=#{wtid}
  138. </if>
  139. <if test="category1 !=null and category1 !=''">
  140. and b.category1=#{category1}
  141. </if>
  142. <if test="category2 !=null and category2 !=''">
  143. and b.category2=#{category2}
  144. </if>
  145. <if test="rank !=null and rank !=''">
  146. and b.rank=#{rank}
  147. </if>
  148. <if test="modelid !=null and modelid !=''">
  149. and b.modelid=#{modelid}
  150. </if>
  151. <if test="snapid !=null ">
  152. and a.snapid=#{snapid}
  153. </if>
  154. <if test="messagetype !=null ">
  155. and a.messagetype=#{messagetype}
  156. </if>
  157. <if test="keyword !=null and keyword !=''">
  158. and b.alerttext like #{keyword}
  159. </if>
  160. </where>
  161. order by a.alerttime desc
  162. </select>
  163. <select id="selectSnapCount" parameterType="java.util.Map" resultType="java.lang.Integer">
  164. select count(*) from ${tbName} where snapid = #{snapid}
  165. and messagetype = '1'
  166. and alerttime &gt;= #{starttime,jdbcType=DATE} and alerttime &lt; #{endtime,jdbcType=DATE}
  167. </select>
  168. <select id="selectHistoryAlarmSnapAndWarning"
  169. resultType="com.gyee.wisdom.alarm.sharding.entity.FaultWarning">
  170. select h.id,
  171. a.stationid,
  172. h.snapid,
  173. a.windturbineid,
  174. a.windturbinename,
  175. a.lastupdatetime,
  176. w.ednavalue,
  177. h.alerttime,
  178. w.warningtypeid
  179. from alarmhistory_nss_202107 h
  180. left join alarmsnap a on h.snapid = a.id
  181. left join warning2 w on a.alertvalue = w.ednavalue
  182. and a.modelid = w.modelid
  183. <where>
  184. and a.category1 = 'windturbine'
  185. and h.messagetype = '1'
  186. <if test="starttime !=null and endtime !=null">
  187. h.alerttime &gt;= #{starttime,jdbcType=DATE} and h.alerttime &lt; #{endtime,jdbcType=DATE}
  188. </if>
  189. </where>
  190. </select>
  191. <update id="timedCreatTable">
  192. create table ALARMHISTORY_${stationname}_${yearmonth}
  193. (
  194. ID INTEGER not null,
  195. ALERTTIME DATE not null,
  196. MESSAGETYPE CHAR(1) default '1' not null,
  197. SNAPID INTEGER not null,
  198. DATAINFO VARCHAR2(1000),
  199. ALERTTEXTLAST VARCHAR2(50)
  200. )
  201. tablespace ${tablespace}
  202. pctfree 10
  203. initrans 1
  204. maxtrans 255
  205. storage
  206. (
  207. initial 16K
  208. minextents 1
  209. maxextents unlimited
  210. )
  211. </update>
  212. <update id="timedAlterTable">
  213. alter table ALARMHISTORY_${stationname}_${yearmonth}
  214. add constraint PK_ALARMHISTORY_${stationname}_${yearmonth} primary key (ID)
  215. using index
  216. tablespace ${tablespace}
  217. pctfree 10
  218. initrans 2
  219. maxtrans 255
  220. storage
  221. (
  222. initial 64K
  223. minextents 1
  224. maxextents unlimited
  225. )
  226. </update>
  227. <update id="timedCreatAlerttimeIndex">
  228. create index IX_AH_${stationname}_${yearmonth}_ALARMTIME on ALARMHISTORY_${stationname}_${yearmonth} (ALERTTIME)
  229. tablespace ${tablespace}
  230. pctfree 10
  231. initrans 2
  232. maxtrans 255
  233. storage
  234. (
  235. initial 64K
  236. minextents 1
  237. maxextents unlimited
  238. )
  239. </update>
  240. <update id="timedCreatSnapidIndex">
  241. create index IX_AH_${stationname}_${yearmonth}_SNAPID on ALARMHISTORY_${stationname}_${yearmonth} (SNAPID)
  242. tablespace ${tablespace}
  243. pctfree 10
  244. initrans 2
  245. maxtrans 255
  246. storage
  247. (
  248. initial 64K
  249. minextents 1
  250. maxextents unlimited
  251. )
  252. </update>
  253. <select id="isHasTable" resultType="java.lang.Integer">
  254. select count(*) from user_tables where table_name =upper('ALARMHISTORY_${stationname}_${yearmonth}')
  255. </select>
  256. </mapper>