IotDeviceLogDataMapper.xml 2.9 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. <!-- TODO @super:下划线 sub_type -->
  14. subType NCHAR(50),
  15. content NCHAR(1024),
  16. report_time TIMESTAMP
  17. ) TAGS (
  18. device_key NCHAR(50)
  19. )
  20. </update>
  21. <!-- 创建设备日志子表 讨论:TDengine 在子表不存在的情况下 可在数据插入时 自动建表 要不要去掉创建子表的逻辑 由第一次插入数据时自动创建-->
  22. <update id="createDeviceLogTable">
  23. CREATE TABLE device_log_${deviceKey} USING device_log TAGS('${deviceKey}')
  24. </update>
  25. <!-- 插入设备日志数据 在子表不存在的情况下 可在数据插入时 自动建表 -->
  26. <insert id="insert">
  27. INSERT INTO device_log_${log.deviceKey} (ts, id, product_key, type, subType, content, report_time)
  28. USING device_log
  29. TAGS ('${log.deviceKey}')
  30. VALUES (
  31. #{log.ts},
  32. #{log.id},
  33. #{log.productKey},
  34. #{log.type},
  35. #{log.subType},
  36. #{log.content},
  37. #{log.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, subType, 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.subType != null and reqVO.subType != ''">
  48. AND subType = #{reqVO.subType}
  49. </if>
  50. <if test="reqVO.createTime != null">
  51. AND ts BETWEEN #{reqVO.createTime[0]} AND #{reqVO.createTime[1]}
  52. </if>
  53. </where>
  54. ORDER BY ts DESC
  55. LIMIT #{reqVO.pageSize} OFFSET #{reqVO.pageNo}
  56. </select>
  57. <select id="selectCount" resultType="Long">
  58. SELECT COUNT(*)
  59. FROM device_log_${reqVO.deviceKey}
  60. <where>
  61. <if test="reqVO.type != null and reqVO.type != ''">
  62. AND type = #{reqVO.type}
  63. </if>
  64. <if test="reqVO.subType != null and reqVO.subType != ''">
  65. AND subType = #{reqVO.subType}
  66. </if>
  67. <if test="reqVO.createTime != null">
  68. AND ts BETWEEN #{reqVO.createTime[0]} AND #{reqVO.createTime[1]}
  69. </if>
  70. </where>
  71. </select>
  72. </mapper>