IotDeviceLogMapper.xml 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5. <mapper namespace="cn.iocoder.yudao.module.iot.dal.tdengine.IotDeviceLogMapper">
  6. <update id="createDeviceLogSTable">
  7. CREATE STABLE IF NOT EXISTS device_log (
  8. ts TIMESTAMP,
  9. id NCHAR(50),
  10. product_key NCHAR(50),
  11. device_name NCHAR(50),
  12. type NCHAR(50),
  13. identifier NCHAR(255),
  14. content NCHAR(1024),
  15. code INT,
  16. report_time TIMESTAMP
  17. ) TAGS (
  18. device_key NCHAR(50)
  19. )
  20. </update>
  21. <select id="showDeviceLogSTable" resultType="String">
  22. SHOW STABLES LIKE 'device_log'
  23. </select>
  24. <insert id="insert">
  25. INSERT INTO device_log_${deviceKey} (ts, id, product_key, device_name, type, identifier, content, code, report_time)
  26. USING device_log
  27. TAGS ('${deviceKey}')
  28. VALUES (
  29. NOW,
  30. #{id},
  31. #{productKey},
  32. #{deviceName},
  33. #{type},
  34. #{identifier},
  35. #{content},
  36. #{code},
  37. #{reportTime}
  38. )
  39. </insert>
  40. <select id="selectPage" resultType="cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceLogDO">
  41. SELECT ts, id, device_key, product_key, type, identifier, content, report_time
  42. FROM device_log_${reqVO.deviceKey}
  43. <where>
  44. <if test="reqVO.type != null and reqVO.type != ''">
  45. AND type = #{reqVO.type}
  46. </if>
  47. <if test="reqVO.identifier != null and reqVO.identifier != ''">
  48. AND identifier LIKE CONCAT('%',#{reqVO.identifier},'%')
  49. </if>
  50. </where>
  51. ORDER BY ts DESC
  52. </select>
  53. <select id="selectCountByCreateTime" resultType="Long">
  54. SELECT COUNT(*)
  55. FROM device_log
  56. <where>
  57. <if test="createTime != null">
  58. AND ts >= #{createTime}
  59. </if>
  60. </where>
  61. </select>
  62. <select id="selectDeviceLogUpCountByHour" resultType="java.util.Map">
  63. SELECT
  64. TIMETRUNCATE(ts, 1h) as time,
  65. COUNT(*) as data
  66. FROM
  67. <choose>
  68. <when test="deviceKey != null and deviceKey != ''">
  69. device_log_${deviceKey}
  70. </when>
  71. <otherwise>
  72. device_log
  73. </otherwise>
  74. </choose>
  75. <where>
  76. <if test="startTime != null">
  77. AND ts >= #{startTime}
  78. </if>
  79. <if test="endTime != null">
  80. AND ts &lt;= #{endTime}
  81. </if>
  82. AND (
  83. identifier IN ('online', 'offline', 'pull', 'progress', 'report', 'register', 'register_sub')
  84. )
  85. </where>
  86. GROUP BY TIMETRUNCATE(ts, 1h)
  87. ORDER BY time ASC
  88. </select>
  89. <select id="selectDeviceLogDownCountByHour" resultType="java.util.Map">
  90. SELECT
  91. TIMETRUNCATE(ts, 1h) as time,
  92. COUNT(*) as data
  93. FROM
  94. <choose>
  95. <when test="deviceKey != null and deviceKey != ''">
  96. device_log_${deviceKey}
  97. </when>
  98. <otherwise>
  99. device_log
  100. </otherwise>
  101. </choose>
  102. <where>
  103. <if test="startTime != null">
  104. AND ts >= #{startTime}
  105. </if>
  106. <if test="endTime != null">
  107. AND ts &lt;= #{endTime}
  108. </if>
  109. AND identifier IN ('set', 'get', 'upgrade', 'unregister_sub', 'topology_add')
  110. </where>
  111. GROUP BY TIMETRUNCATE(ts, 1h)
  112. ORDER BY time ASC
  113. </select>
  114. </mapper>