WatchRriDataMapper.xml 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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="com.fs.watch.mapper.WatchRriDataMapper">
  6. <resultMap id="BaseResultMap" type="com.fs.watch.domain.WatchRriData">
  7. <result property="id" column="id" jdbcType="OTHER" typeHandler="com.fs.watch.handler.UUIDTypeHandler"/>
  8. <result property="deviceId" column="device_id" jdbcType="VARCHAR"/>
  9. <result property="val" column="json_data.val" jdbcType="ARRAY" typeHandler="com.fs.watch.handler.ShortListTypeHandler"/>
  10. <result property="count" column="count" jdbcType="INTEGER"/>
  11. <result property="createTime" column="create_time" jdbcType="VARCHAR"/>
  12. </resultMap>
  13. <sql id="Base_Column_List">
  14. id,device_id,json_data.val,
  15. count,create_time
  16. </sql>
  17. <!-- 查询数据是否存在 -->
  18. <select id="queryByCreateTime" resultType="java.lang.Integer">
  19. SELECT COUNT(*)
  20. FROM watch_rri_data
  21. WHERE create_time = #{createTime}
  22. </select>
  23. <!-- 插入RRI数据 -->
  24. <update id="insert" parameterType="com.fs.watch.domain.WatchRriData">
  25. INSERT INTO watch_rri_data
  26. <trim prefix="(" suffix=")" suffixOverrides=",">
  27. <if test="data.id != null">
  28. id,
  29. </if>
  30. <if test="data.deviceId != null">
  31. device_id,
  32. </if>
  33. <if test="data.val != null">
  34. json_data.val,
  35. </if>
  36. <if test="data.count != null">
  37. count,
  38. </if>
  39. <if test="data.createTime != null">
  40. create_time,
  41. </if>
  42. </trim>
  43. <trim prefix="VALUES (" suffix=")" suffixOverrides=",">
  44. <if test="data.id != null">
  45. #{data.id},
  46. </if>
  47. <if test="data.deviceId != null">
  48. #{data.deviceId},
  49. </if>
  50. <if test="data.val != null">
  51. #{data.val},
  52. </if>
  53. <if test="data.count != null">
  54. #{data.count},
  55. </if>
  56. <if test="data.createTime != null">
  57. #{data.createTime},
  58. </if>
  59. </trim>
  60. </update>
  61. <!-- 查询指定日期和设备ID的RRI数据 -->
  62. <select id="getByDateAndDeviceId" resultMap="BaseResultMap">
  63. SELECT id, device_id, json_data.val, count, create_time
  64. FROM watch_rri_data
  65. WHERE device_id = #{deviceId}
  66. AND toDate(create_time) = #{date}
  67. ORDER BY create_time ASC
  68. </select>
  69. <select id="getLastByDateAndDeviceId" resultMap="BaseResultMap">
  70. SELECT *
  71. FROM watch_rri_data
  72. WHERE device_id LIKE #{deviceId}
  73. AND create_time &gt; toStartOfDay(parseDateTimeBestEffort(#{time}))
  74. AND create_time &lt; toStartOfDay(parseDateTimeBestEffort(#{time})) + INTERVAL 1 DAY
  75. </select>
  76. <select id="getLastTime" resultType="java.lang.String">
  77. SELECT MAX(create_time) AS latest_create_time
  78. FROM watch_rri_data
  79. WHERE device_id LIKE #{deviceId}
  80. </select>
  81. </mapper>