IotDeviceLogDataMapper.xml 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. <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. report_time TIMESTAMP
  16. ) TAGS (
  17. device_key NCHAR(50)
  18. )
  19. </update>
  20. <select id="showDeviceLogSTable" resultType="String">
  21. SHOW STABLES LIKE 'device_log'
  22. </select>
  23. <insert id="insert">
  24. INSERT INTO device_log_${deviceKey} (ts, id, product_key, device_name, type, identifier, content, report_time)
  25. USING device_log
  26. TAGS ('${deviceKey}')
  27. VALUES (
  28. NOW,
  29. #{id},
  30. #{productKey},
  31. #{deviceName},
  32. #{type},
  33. #{identifier},
  34. #{content},
  35. #{reportTime}
  36. )
  37. </insert>
  38. <select id="selectPage" resultType="cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceLogDO">
  39. SELECT ts, id, device_key, product_key, type, sub_type, content, report_time
  40. FROM device_log_${reqVO.deviceKey}
  41. <where>
  42. <if test="reqVO.type != null and reqVO.type != ''">
  43. AND type = #{reqVO.type}
  44. </if>
  45. <if test="reqVO.subType != null and reqVO.subType != ''">
  46. AND subType = #{reqVO.subType}
  47. </if>
  48. <if test="reqVO.createTime != null">
  49. AND ts BETWEEN #{reqVO.createTime[0]} AND #{reqVO.createTime[1]}
  50. </if>
  51. </where>
  52. ORDER BY ts DESC
  53. LIMIT #{reqVO.pageSize} OFFSET #{reqVO.pageNo}
  54. </select>
  55. <!-- TODO 芋艿:看看能不能复用 mybatis-plus 的 selectCount 方法 -->
  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>