IotDevicePropertyMapper.xml 2.7 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.IotDevicePropertyMapper">
  6. <select id="getProductPropertySTableFieldList" resultType="cn.iocoder.yudao.module.iot.framework.tdengine.core.TDengineTableField">
  7. DESCRIBE product_property_${productKey}
  8. </select>
  9. <update id="createProductPropertySTable">
  10. CREATE STABLE product_property_${productKey} (
  11. ts TIMESTAMP,
  12. report_time TIMESTAMP,
  13. <foreach item="field" collection="fields" separator=",">
  14. ${field.field} ${field.type}
  15. <if test="field.length != null and field.length > 0">
  16. (${field.length})
  17. </if>
  18. </foreach>
  19. )
  20. TAGS (
  21. device_key NCHAR(50)
  22. )
  23. </update>
  24. <update id="alterProductPropertySTableAddField">
  25. ALTER STABLE product_property_${productKey}
  26. ADD COLUMN ${field.field} ${field.type}
  27. <if test="field.length != null and field.length > 0">
  28. (${field.length})
  29. </if>
  30. </update>
  31. <update id="alterProductPropertySTableModifyField">
  32. ALTER STABLE product_property_${productKey}
  33. MODIFY COLUMN ${field.field} ${field.type}
  34. <if test="field.length != null and field.length > 0">
  35. (${field.length})
  36. </if>
  37. </update>
  38. <update id="alterProductPropertySTableDropField">
  39. ALTER STABLE product_property_${productKey}
  40. DROP COLUMN ${field.field}
  41. </update>
  42. <insert id="insert">
  43. INSERT INTO device_property_${device.deviceKey}
  44. USING product_property_${device.productKey}
  45. TAGS ('${device.deviceKey}')
  46. (ts, report_time,
  47. <foreach item="key" collection="properties.keys" separator=",">
  48. ${key}
  49. </foreach>
  50. )
  51. VALUES
  52. (NOW, #{reportTime},
  53. <foreach item="value" collection="properties.values" separator=",">
  54. #{value}
  55. </foreach>
  56. )
  57. </insert>
  58. <select id="describeSuperTable" resultType="java.util.Map">
  59. DESCRIBE product_property_${productKey}
  60. </select>
  61. <select id="selectPageByHistory" resultType="cn.iocoder.yudao.module.iot.controller.admin.device.vo.data.IotDevicePropertyRespVO">
  62. SELECT ${reqVO.identifier} AS `value`, ts AS update_time
  63. FROM device_property_${reqVO.deviceKey}1
  64. WHERE ${reqVO.identifier} IS NOT NULL
  65. AND ts BETWEEN ${@cn.hutool.core.date.LocalDateTimeUtil@toEpochMilli(reqVO.times[0])}
  66. AND ${@cn.hutool.core.date.LocalDateTimeUtil@toEpochMilli(reqVO.times[1])}
  67. ORDER BY ts DESC
  68. </select>
  69. </mapper>