WatchEcgDataMapper.xml 2.8 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="com.fs.watch.mapper.WatchEcgDataMapper">
  6. <resultMap id="BaseResultMap" type="com.fs.watch.domain.WatchEcgData">
  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="OTHER" typeHandler="com.fs.watch.handler.IntegerArrayTypeHandler"/>
  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. <update id="insert" parameterType="com.fs.watch.domain.WatchEcgData">
  19. INSERT INTO watch_ecg_data
  20. <trim prefix="(" suffix=")" suffixOverrides=",">
  21. <if test="data.id != null">
  22. id,
  23. </if>
  24. <if test="data.deviceId != null">
  25. device_id,
  26. </if>
  27. <if test="data.val != null">
  28. json_data.val,
  29. </if>
  30. <if test="data.count != null">
  31. count,
  32. </if>
  33. <if test="data.createTime != null">
  34. create_time,
  35. </if>
  36. </trim>
  37. <trim prefix="VALUES (" suffix=")" suffixOverrides=",">
  38. <if test="data.id != null">
  39. #{data.id},
  40. </if>
  41. <if test="data.deviceId != null">
  42. #{data.deviceId},
  43. </if>
  44. <if test="data.val != null">
  45. #{data.val},
  46. </if>
  47. <if test="data.count != null">
  48. #{data.count},
  49. </if>
  50. <if test="data.createTime != null">
  51. #{data.createTime},
  52. </if>
  53. </trim>
  54. </update>
  55. <!-- 查询数据是否存在 -->
  56. <select id="queryByCreateTime" resultType="java.lang.Integer">
  57. SELECT COUNT(*)
  58. FROM watch_ecg_data
  59. WHERE create_time = #{createTime}
  60. </select>
  61. <!-- 根据日期和设备ID查询心电图数据 -->
  62. <select id="getByDateAndDeviceId" resultMap="BaseResultMap">
  63. SELECT id, device_id, `json_data.val`, count, create_time
  64. FROM watch_ecg_data
  65. WHERE device_id = #{deviceId}
  66. AND toDate(create_time) = #{date}
  67. ORDER BY create_time ASC
  68. </select>
  69. <select id="getLastByDeviceId" resultMap="BaseResultMap">
  70. select * from watch_ecg_data where device_id like #{deviceId} order by create_time desc limit 1
  71. </select>
  72. </mapper>