WatchThirdBpDataMapper.xml 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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.WatchThirdBpDataMapper">
  6. <resultMap id="BaseResultMap" type="com.fs.watch.domain.WatchThirdBpData">
  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="sbp" column="sbp" jdbcType="INTEGER"/>
  10. <result property="dbp" column="dbp" jdbcType="INTEGER"/>
  11. <result property="hr" column="hr" jdbcType="INTEGER"/>
  12. <result property="pulse" column="pulse" jdbcType="INTEGER"/>
  13. <result property="status" column="status" jdbcType="INTEGER"/>
  14. <result property="mode" column="mode" jdbcType="INTEGER"/>
  15. <result property="createTime" column="create_time" jdbcType="VARCHAR"/>
  16. </resultMap>
  17. <sql id="Base_Column_List">
  18. id,device_id,sbp,
  19. dbp,hr,pulse,status,
  20. mode,create_time
  21. </sql>
  22. <!-- 查询创建时间是否存在 -->
  23. <select id="queryByCreateTime" parameterType="String" resultType="Integer">
  24. SELECT COUNT(*)
  25. FROM watch_third_bp_data
  26. WHERE create_time = #{createTime}
  27. </select>
  28. <!-- 插入血压数据 -->
  29. <update id="insert" parameterType="com.fs.watch.domain.WatchThirdBpData">
  30. INSERT INTO watch_third_bp_data
  31. <trim prefix="(" suffix=")" suffixOverrides=",">
  32. <if test="data.id != null">
  33. id,
  34. </if>
  35. <if test="data.deviceId != null">
  36. device_id,
  37. </if>
  38. <if test="data.sbp != null">
  39. sbp,
  40. </if>
  41. <if test="data.dbp != null">
  42. dbp,
  43. </if>
  44. <if test="data.hr != null">
  45. hr,
  46. </if>
  47. <if test="data.pulse != null">
  48. pulse,
  49. </if>
  50. <if test="data.status != null">
  51. status,
  52. </if>
  53. <if test="data.mode != null">
  54. mode,
  55. </if>
  56. <if test="data.createTime != null">
  57. create_time,
  58. </if>
  59. </trim>
  60. <trim prefix="VALUES (" suffix=")" suffixOverrides=",">
  61. <if test="data.id != null">
  62. #{data.id},
  63. </if>
  64. <if test="data.deviceId != null">
  65. #{data.deviceId},
  66. </if>
  67. <if test="data.sbp != null">
  68. #{data.sbp},
  69. </if>
  70. <if test="data.dbp != null">
  71. #{data.dbp},
  72. </if>
  73. <if test="data.hr != null">
  74. #{data.hr},
  75. </if>
  76. <if test="data.pulse != null">
  77. #{data.pulse},
  78. </if>
  79. <if test="data.status != null">
  80. #{data.status},
  81. </if>
  82. <if test="data.mode != null">
  83. #{data.mode},
  84. </if>
  85. <if test="data.createTime != null">
  86. #{data.createTime},
  87. </if>
  88. </trim>
  89. </update>
  90. <!-- 查询某天某个设备的血压数据 -->
  91. <select id="queryByDateAndDeviceId" parameterType="map" resultMap="BaseResultMap">
  92. SELECT id, device_id, sbp, dbp, hr, pulse,status, mode, create_time
  93. FROM watch_third_bp_data
  94. WHERE device_id = #{deviceId}
  95. AND toDate(create_time) = #{date}
  96. ORDER BY create_time ASC
  97. </select>
  98. <select id="queryBpByDate" resultMap="BaseResultMap">
  99. SELECT
  100. <include refid="Base_Column_List"/>
  101. FROM
  102. watch_third_bp_data
  103. WHERE
  104. device_id = #{deviceId}
  105. AND create_time BETWEEN #{startTime} AND #{endTime}
  106. <if test="status != null and status !=''" >
  107. AND status = #{status}
  108. </if>
  109. ORDER BY
  110. create_time ASC
  111. </select>
  112. <select id="getLastByDeviceId" resultMap="BaseResultMap">
  113. select * from watch_third_bp_data where device_id like #{deviceId} order by create_time desc limit 1
  114. </select>
  115. <select id="getLast" resultMap="BaseResultMap">
  116. SELECT
  117. <include refid="Base_Column_List"/>
  118. FROM
  119. watch_third_bp_data
  120. WHERE
  121. device_id = #{deviceId}
  122. ORDER BY
  123. create_time DESC LIMIT 1
  124. </select>
  125. <select id="countBpByDate" resultType="java.util.Map">
  126. SELECT
  127. status,
  128. COUNT(*) AS count
  129. FROM
  130. watch_third_bp_data
  131. WHERE
  132. create_time BETWEEN #{startTime} AND #{endTime}
  133. AND device_id = #{deviceId}
  134. GROUP BY
  135. status
  136. </select>
  137. <select id="countBpPageByDate" resultType="java.lang.Integer">
  138. SELECT count(0)
  139. FROM watch_third_bp_data
  140. WHERE
  141. device_id = #{deviceId}
  142. <if test="status!=null and status !=''">
  143. and status = #{status}
  144. </if>
  145. AND (create_time BETWEEN #{startTime} AND #{endTime})
  146. </select>
  147. <select id="queryBgPageByDate" resultMap="BaseResultMap">
  148. SELECT
  149. <include refid="Base_Column_List"/>
  150. FROM watch_third_bp_data
  151. WHERE
  152. device_id = #{deviceId}
  153. <if test="status!=null and status !=''">
  154. and status = #{status}
  155. </if>
  156. AND create_time BETWEEN #{startTime} AND #{endTime}
  157. ORDER BY create_time ASC LIMIT #{num},#{size}
  158. </select>
  159. <select id="queryByMonth" resultMap="BaseResultMap">
  160. SELECT *
  161. FROM watch.watch_third_bp_data
  162. WHERE device_id like #{deviceId} and toYYYYMM(create_time) = #{monthStr}
  163. </select>
  164. </mapper>