SlopeDataMapper.xml 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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.sckw.slope.detection.dao.tdengine.SlopeDataMapper">
  4. <resultMap id="BaseResultMap" type="com.sckw.slope.detection.model.dos.tdengine.SlopeData">
  5. <!--@mbg.generated-->
  6. <!--@Table slope_data-->
  7. <id column="ts" jdbcType="TIMESTAMP" property="ts"/>
  8. <result column="rawTs" jdbcType="TIMESTAMP" property="rawId"/>
  9. <result column="tslverId" jdbcType="TINYINT" property="tslverId"/>
  10. <result column="guid" jdbcType="VARCHAR" property="guid"/>
  11. <result column="line" jdbcType="VARCHAR" property="line"/>
  12. <result column="val" jdbcType="VARCHAR" property="val"/>
  13. <result column="createTime" jdbcType="TIMESTAMP" property="createTime"/>
  14. <!-- <result column="msgId" jdbcType="VARCHAR" property="msgId"/>-->
  15. <!-- <result column="name" jdbcType="TINYINT" property="name"/>-->
  16. </resultMap>
  17. <select id="selectList" resultType="com.sckw.slope.detection.model.vo.SlopeDataVo">
  18. <!-- ts, raw_id , device_id, item_name as itemName, item_value as itemValue, create_time as createTime-->
  19. SELECT ts,
  20. raw_ts as rawId,
  21. tslver_id as tslverId,
  22. guid,
  23. line,
  24. val,
  25. create_time as createTime,
  26. msg_id as msgId,
  27. name,
  28. json_text as jsonText
  29. FROM devicesv2.device_67
  30. </select>
  31. <sql id="Base_List">
  32. ts,
  33. raw_ts as rawId,
  34. tslver_id as tslverId,
  35. line,
  36. val
  37. </sql>
  38. <select id="selectListByLine" resultType="com.sckw.slope.detection.model.dos.tdengine.SlopeData">
  39. SELECT
  40. <include refid="Base_List">
  41. </include>
  42. FROM devicesv2.device_#{snCode}
  43. where line = #{item}
  44. order by ts desc limit 1
  45. </select>
  46. <select id="selectListByTwoLine" resultType="com.sckw.slope.detection.model.dos.tdengine.SlopeData">
  47. SELECT
  48. <include refid="Base_List">
  49. </include>
  50. FROM devicesv2.device_#{snCode}
  51. where line = #{item}
  52. order by ts desc limit 2
  53. </select>
  54. <select id="selectListByLineOrderByCreateTime" resultType="com.sckw.slope.detection.model.dos.tdengine.SlopeData">
  55. SELECT
  56. <include refid="Base_List">
  57. </include>
  58. FROM devicesv2.device_#{snCode}
  59. where line = #{item}
  60. order by ts desc limit 2
  61. </select>
  62. <insert id="insertData" parameterType="com.sckw.slope.detection.model.dos.tdengine.SlopeData">
  63. <!-- insert into devices.devicesv2202_2021-->
  64. insert into devicesv2.devices_#{slopeData.serialNumber} using devicesv2.devices (#{slopeData.tagsTitle}) tags (#{slopeData.tags})
  65. (ts, raw_ts, tslver_id, guid, line, val, create_time)
  66. VALUES (#{slopeData.ts}, #{slopeData.rawId},
  67. #{slopeData.tslverId}, #{slopeData.guid},
  68. #{slopeData.line}, #{slopeData.val}, #{slopeData.createTime})
  69. <!-- VALUES('2023-12-12 00:00:00.100', '2023-12-12 00:00:00.100', 111, '111', '1111', '111', '2023-12-12 00:00:00.100');-->
  70. </insert>
  71. <select id="selectLineList" resultType="com.sckw.slope.detection.model.dos.tdengine.SlopeData">
  72. SELECT
  73. <include refid="Base_List">
  74. </include>
  75. FROM devicesv2.device_${snCode}
  76. where line = #{item} and raw_ts &gt;= #{dateStart} and raw_ts &lt;= #{dateEnd} order by ts desc
  77. </select>
  78. <select id="selectLineListByArray" resultType="com.sckw.slope.detection.model.dos.tdengine.SlopeData">
  79. SELECT
  80. <include refid="Base_List">
  81. </include>
  82. FROM devicesv2.device_#{snCode}
  83. where raw_ts &gt;= #{dateStart} and raw_ts &lt;= #{dateEnd}
  84. <if test="parts != null">
  85. and line in
  86. <foreach collection="parts" index="index" separator="," open="(" close=")" item="parts">
  87. #{parts}
  88. </foreach>
  89. </if>
  90. order by ts desc limit 0,1000
  91. </select>
  92. <select id="selectLineListByList" resultType="com.sckw.slope.detection.model.dos.tdengine.SlopeData">
  93. SELECT
  94. line,
  95. val,
  96. msg_id as msgId,
  97. ts
  98. FROM devicesv2.device_#{snCode}
  99. where raw_ts &gt;= #{dateStart} and raw_ts &lt;= #{dateEnd}
  100. <if test="parts != null">
  101. and line in
  102. <foreach collection="parts" index="index" separator="," open="(" close=")" item="parts">
  103. #{parts}
  104. </foreach>
  105. </if>
  106. order by ts desc limit 0,50
  107. </select>
  108. <select id="selectTableIsExit">
  109. select * from information_schema.ins_tables a where a.db_name = 'devices' and a.table_name = #{name}
  110. </select>
  111. <insert id="createTable">
  112. CREATE TABLE #{name} (
  113. ts TIMESTAMP,
  114. raw_id TIMESTAMP,
  115. tslver_id TINYINT(4),
  116. guid VARCHAR(64),
  117. line VARCHAR(16),
  118. val VARCHAR(16),
  119. create_time TIMESTAMP
  120. )
  121. </insert>
  122. <select id="selectListByMaster" resultType="com.sckw.slope.detection.model.vo.SlopeDataVo">
  123. SELECT
  124. <include refid="Base_List">
  125. </include>
  126. FROM devicesv2.devices
  127. <!-- <if test="(page != null and page !='') and ( pageSize != null and pageSize != '')">-->
  128. <if test="page != null and pageSize != null ">
  129. limit #{page},#{pageSize}
  130. </if>
  131. <!-- SELECT-->
  132. <!-- t1.ts,-->
  133. <!-- t1.raw_id as rawId,-->
  134. <!-- t1.tslver_id as tslverId,-->
  135. <!-- t1.guid,-->
  136. <!-- t1.line,-->
  137. <!-- t1.val,-->
  138. <!-- t1.create_time as createTime,-->
  139. <!-- t2.json_text as jsonText-->
  140. <!-- FROM devices.slope_data AS t1-->
  141. <!-- LEFT JOIN devices.slope_raw AS t2 ON t1.guid = t2.guid-->
  142. </select>
  143. <select id="selectListByMasterCount" resultType="com.sckw.slope.detection.model.vo.SlopeDataVo">
  144. SELECT
  145. <include refid="Base_List">
  146. </include>
  147. FROM devicesv2.devices
  148. </select>
  149. <select id="selectLastData" resultType="com.sckw.slope.detection.model.dos.tdengine.SlopeData">
  150. SELECT
  151. <include refid="Base_List">
  152. </include>
  153. FROM devicesv2.device_${deviceCode}
  154. order by ts desc limit 1
  155. </select>
  156. </mapper>