SlopeDataMapper.xml 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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="selectListByLineOrderByCreateTime" 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. <insert id="insertData" parameterType="com.sckw.slope.detection.model.dos.tdengine.SlopeData">
  55. <!-- insert into devices.devicesv2202_2021-->
  56. insert into devicesv2.devices_#{slopeData.serialNumber} using devicesv2.devices (#{slopeData.tagsTitle}) tags (#{slopeData.tags})
  57. (ts, raw_ts, tslver_id, guid, line, val, create_time)
  58. VALUES (#{slopeData.ts}, #{slopeData.rawId},
  59. #{slopeData.tslverId}, #{slopeData.guid},
  60. #{slopeData.line}, #{slopeData.val}, #{slopeData.createTime})
  61. <!-- 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');-->
  62. </insert>
  63. <select id="selectLineList" resultType="com.sckw.slope.detection.model.dos.tdengine.SlopeData">
  64. SELECT
  65. <include refid="Base_List">
  66. </include>
  67. FROM devicesv2.device_#{snCode}
  68. where line = #{item} and ts &gt;= #{dateStart} and ts &lt;= #{dateEnd} order by ts desc
  69. </select>
  70. <select id="selectTableIsExit">
  71. select * from information_schema.ins_tables a where a.db_name = 'devices' and a.table_name = #{name}
  72. </select>
  73. <insert id="createTable">
  74. CREATE TABLE #{name} (
  75. ts TIMESTAMP,
  76. raw_id TIMESTAMP,
  77. tslver_id TINYINT(4),
  78. guid VARCHAR(64),
  79. line VARCHAR(16),
  80. val VARCHAR(16),
  81. create_time TIMESTAMP
  82. )
  83. </insert>
  84. <select id="selectListByMaster" resultType="com.sckw.slope.detection.model.vo.SlopeDataVo">
  85. SELECT
  86. <include refid="Base_List">
  87. </include>
  88. FROM devicesv2.devices
  89. <!-- <if test="(page != null and page !='') and ( pageSize != null and pageSize != '')">-->
  90. <if test="page != null and pageSize != null ">
  91. limit #{page},#{pageSize}
  92. </if>
  93. <!-- SELECT-->
  94. <!-- t1.ts,-->
  95. <!-- t1.raw_id as rawId,-->
  96. <!-- t1.tslver_id as tslverId,-->
  97. <!-- t1.guid,-->
  98. <!-- t1.line,-->
  99. <!-- t1.val,-->
  100. <!-- t1.create_time as createTime,-->
  101. <!-- t2.json_text as jsonText-->
  102. <!-- FROM devices.slope_data AS t1-->
  103. <!-- LEFT JOIN devices.slope_raw AS t2 ON t1.guid = t2.guid-->
  104. </select>
  105. <select id="selectListByMasterCount" resultType="com.sckw.slope.detection.model.vo.SlopeDataVo">
  106. SELECT
  107. <include refid="Base_List">
  108. </include>
  109. FROM devicesv2.devices
  110. </select>
  111. <select id="selectLastData" resultType="com.sckw.slope.detection.model.dos.tdengine.SlopeData">
  112. SELECT
  113. <include refid="Base_List">
  114. </include>
  115. FROM devicesv2.device_${deviceCode}
  116. order by ts desc limit 1
  117. </select>
  118. </mapper>