IotDeviceLogDataMapper.xml 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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.IotDeviceLogDataMapper">
  6. <!-- 创建设备日志超级表 初始化只创建一次-->
  7. <update id="createDeviceLogSTable">
  8. CREATE STABLE device_log (
  9. ts TIMESTAMP,
  10. id NCHAR(50),
  11. product_key NCHAR(50),
  12. type NCHAR(50),
  13. subType NCHAR(50),
  14. content NCHAR(1024),
  15. report_time TIMESTAMP
  16. )TAGS (
  17. device_key NCHAR(50)
  18. )
  19. </update>
  20. <!-- 创建设备日志子表 讨论:TDengine 在子表不存在的情况下 可在数据插入时 自动建表 要不要去掉创建子表的逻辑 由第一次插入数据时自动创建-->
  21. <update id="createDeviceLogTable">
  22. CREATE TABLE device_log_${deviceKey} USING device_log TAGS('${deviceKey}')
  23. </update>
  24. <!-- 插入设备日志数据 在子表不存在的情况下 可在数据插入时 自动建表 -->
  25. <insert id="insert">
  26. INSERT INTO device_log_${log.deviceKey} (ts, id, product_key, type, subType, content, report_time)
  27. USING device_log
  28. TAGS ('${log.deviceKey}')
  29. VALUES (
  30. #{log.ts},
  31. #{log.id},
  32. #{log.productKey},
  33. #{log.type},
  34. #{log.subType},
  35. #{log.content},
  36. #{log.reportTime}
  37. )
  38. </insert>
  39. <select id="selectPage" resultType="cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceLogDO">
  40. SELECT ts, id, device_key, product_key, type, subType, content, report_time
  41. FROM device_log_${reqVO.deviceKey}
  42. <where>
  43. <if test="reqVO.type != null and reqVO.type != ''">
  44. AND type = #{reqVO.type}
  45. </if>
  46. <if test="reqVO.subType != null and reqVO.subType != ''">
  47. AND subType = #{reqVO.subType}
  48. </if>
  49. <if test="reqVO.createTime != null">
  50. AND ts BETWEEN #{reqVO.createTime[0]} AND #{reqVO.createTime[1]}
  51. </if>
  52. </where>
  53. ORDER BY ts DESC
  54. LIMIT #{reqVO.pageSize} OFFSET #{reqVO.pageNo}
  55. </select>
  56. <select id="selectCount" resultType="Long">
  57. SELECT COUNT(*)
  58. FROM device_log_${reqVO.deviceKey}
  59. <where>
  60. <if test="reqVO.type != null and reqVO.type != ''">
  61. AND type = #{reqVO.type}
  62. </if>
  63. <if test="reqVO.subType != null and reqVO.subType != ''">
  64. AND subType = #{reqVO.subType}
  65. </if>
  66. <if test="reqVO.createTime != null">
  67. AND ts BETWEEN #{reqVO.createTime[0]} AND #{reqVO.createTime[1]}
  68. </if>
  69. </where>
  70. </select>
  71. </mapper>