WatchContinuousSpo2DataMapper.xml 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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.WatchContinuousSpo2DataMapper">
  6. <resultMap id="BaseResultMap" type="com.fs.watch.domain.WatchContinuousSpo2Data">
  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="spo2" column="json_data.spo2" jdbcType="ARRAY" typeHandler="com.fs.watch.handler.IntegerListTypeHandler"/>
  10. <result property="hr" column="json_data.hr" jdbcType="ARRAY" typeHandler="com.fs.watch.handler.IntegerListTypeHandler"/>
  11. <result property="perfusion" column="json_data.perfusion" jdbcType="ARRAY" typeHandler="com.fs.watch.handler.IntegerListTypeHandler"/>
  12. <result property="touch" column="json_data.touch" jdbcType="ARRAY" typeHandler="com.fs.watch.handler.IntegerListTypeHandler"/>
  13. <result property="createTime" column="create_time" jdbcType="VARCHAR"/>
  14. </resultMap>
  15. <sql id="Base_Column_List">
  16. id,device_id,json_data.spo2,
  17. json_data.hr,json_data.perfusion,json_data.touch,
  18. create_time
  19. </sql>
  20. <!-- 插入数据 -->
  21. <update id="insert" parameterType="com.fs.watch.domain.WatchContinuousSpo2Data">
  22. INSERT INTO watch_continuous_spo2_data
  23. <trim prefix="(" suffix=")" suffixOverrides=",">
  24. <if test="data.id != null">
  25. id,
  26. </if>
  27. <if test="data.deviceId != null">
  28. device_id,
  29. </if>
  30. <if test="data.spo2 != null">
  31. json_data.spo2,
  32. </if>
  33. <if test="data.hr != null">
  34. json_data.hr,
  35. </if>
  36. <if test="data.perfusion != null">
  37. json_data.perfusion,
  38. </if>
  39. <if test="data.touch != null">
  40. json_data.touch,
  41. </if>
  42. <if test="data.createTime != null">
  43. create_time,
  44. </if>
  45. </trim>
  46. <trim prefix="VALUES (" suffix=")" suffixOverrides=",">
  47. <if test="data.id != null">
  48. #{data.id},
  49. </if>
  50. <if test="data.deviceId != null">
  51. #{data.deviceId},
  52. </if>
  53. <if test="data.spo2 != null">
  54. #{data.spo2},
  55. </if>
  56. <if test="data.hr != null">
  57. #{data.hr},
  58. </if>
  59. <if test="data.perfusion != null">
  60. #{data.perfusion},
  61. </if>
  62. <if test="data.touch != null">
  63. #{data.touch},
  64. </if>
  65. <if test="data.createTime != null">
  66. #{data.createTime},
  67. </if>
  68. </trim>
  69. </update>
  70. <!-- 根据创建时间查询记录数 -->
  71. <select id="queryByCreateTime" resultType="java.lang.Integer">
  72. SELECT COUNT(*)
  73. FROM watch_continuous_spo2_data
  74. WHERE create_time = #{createTime}
  75. </select>
  76. <!-- &lt;!&ndash; 根据日期和设备 ID 查询数据 &ndash;&gt;-->
  77. <!-- <select id="queryOneByDateAndDeviceIdAndState" parameterType="map" resultMap="BaseResultMap">-->
  78. <!-- SELECT id, device_id, `json_data.spo2`, `json_data.hr`, `json_data.perfusion`, `json_data.touch`, create_time-->
  79. <!-- FROM watch_continuous_spo2_data-->
  80. <!-- WHERE device_id = #{deviceId}-->
  81. <!-- AND Date(create_time) = #{date}-->
  82. <!-- ORDER BY create_time-->
  83. <!-- </select>-->
  84. <select id="getLastByDeviceId" resultMap="BaseResultMap">
  85. select * from watch_continuous_spo2_data where device_id like #{deviceId} order by create_time desc limit 1
  86. </select>
  87. <select id="queryByDateAndDeviceIdAndState" resultMap="BaseResultMap">
  88. SELECT id, device_id, `json_data.spo2`, `json_data.hr`, `json_data.perfusion`, `json_data.touch`, create_time
  89. FROM watch_continuous_spo2_data
  90. WHERE device_id = #{deviceId}
  91. AND toDate(create_time) = #{date}
  92. ORDER BY create_time ASC
  93. </select>
  94. <select id="getLatest" resultMap="BaseResultMap">
  95. SELECT
  96. <include refid="Base_Column_List"/>
  97. FROM
  98. watch_continuous_spo2_data
  99. WHERE
  100. device_id = #{deviceId}
  101. ORDER BY
  102. create_time DESC LIMIT 1
  103. </select>
  104. <select id="querySpPageByDate" resultMap="BaseResultMap">
  105. SELECT <include refid="Base_Column_List"/>
  106. FROM watch_continuous_spo2_data
  107. WHERE
  108. device_id = #{deviceId}
  109. AND create_time BETWEEN #{startTime} AND #{endTime}
  110. ORDER BY create_time ASC LIMIT #{num},#{size}
  111. </select>
  112. <select id="countSpPageByDate" resultType="java.lang.Integer">
  113. SELECT count(0)
  114. FROM watch_continuous_spo2_data
  115. WHERE
  116. device_id = #{deviceId}
  117. AND (create_time BETWEEN #{startTime} AND #{endTime})
  118. </select>
  119. <select id="querySpByDate" resultMap="BaseResultMap">
  120. SELECT
  121. <include refid="Base_Column_List"></include>
  122. FROM
  123. watch_continuous_spo2_data
  124. WHERE
  125. device_id = #{deviceId}
  126. AND create_time BETWEEN #{startTime} AND #{endTime}
  127. ORDER BY
  128. create_time ASC
  129. </select>
  130. <!-- 根据日期和设备 ID 查询数据 -->
  131. <select id="queryOneByDateAndDeviceIdAndState" parameterType="map" resultMap="BaseResultMap">
  132. SELECT id, device_id, `json_data.spo2`, `json_data.hr`, `json_data.perfusion`, `json_data.touch`, create_time
  133. FROM watch_continuous_spo2_data
  134. WHERE device_id = #{deviceId}
  135. AND toDate(create_time) = #{date}
  136. ORDER BY create_time
  137. </select>
  138. <select id="queryByMonth" resultMap="BaseResultMap">
  139. SELECT *
  140. FROM watch.watch_continuous_spo2_data
  141. WHERE device_id like #{deviceId} and toYYYYMM(create_time) = #{monthStr}
  142. </select>
  143. </mapper>