WatchFatigueDataMapper.xml 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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.WatchFatigueDataMapper">
  6. <resultMap id="BaseResultMap" type="com.fs.watch.domain.WatchFatigueData">
  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="fatigue" column="fatigue" jdbcType="INTEGER"/>
  10. <result property="createTime" column="create_time" jdbcType="VARCHAR"/>
  11. <result property="status" column="status" jdbcType="INTEGER"/>
  12. </resultMap>
  13. <sql id="Base_Column_List">
  14. id,device_id,fatigue,
  15. create_time,status
  16. </sql>
  17. <!-- 插入数据 -->
  18. <update id="insert" parameterType="com.fs.watch.domain.WatchFatigueData">
  19. INSERT INTO watch_fatigue_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.fatigue != null">
  28. fatigue,
  29. </if>
  30. <if test="data.createTime != null">
  31. create_time,
  32. </if>
  33. <if test="data.status != null">
  34. status,
  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.fatigue != null">
  45. #{data.fatigue},
  46. </if>
  47. <if test="data.createTime != null">
  48. #{data.createTime},
  49. </if>
  50. <if test="data.status != null">
  51. #{data.status},
  52. </if>
  53. </trim>
  54. </update>
  55. <!-- 查询数据是否存在 -->
  56. <select id="queryByCreateTime" resultType="java.lang.Integer">
  57. SELECT COUNT(*)
  58. FROM watch_fatigue_data
  59. WHERE create_time = #{createTime}
  60. </select>
  61. <select id="getLastByDeviceId" resultMap="BaseResultMap">
  62. select * from watch_fatigue_data where device_id like #{deviceId} order by create_time desc limit 1
  63. </select>
  64. <select id="page" resultType="com.fs.watch.domain.vo.WatchFatigueDataVo">
  65. SELECT id, device_id, 100-fatigue as pressure,create_time,status
  66. from watch_fatigue_data
  67. where device_id = #{deviceId}
  68. <if test="beginTime != null">
  69. and create_time <![CDATA[>=]]> #{beginTime}
  70. </if>
  71. <if test="endTime != null">
  72. and create_time <![CDATA[<=]]> #{endTime}
  73. </if>
  74. <!-- 数据范围过滤 -->
  75. ORDER BY create_time ASC
  76. ${params.dataScope}
  77. </select>
  78. <select id="queryByDateAndDeviceId" resultType="com.fs.watch.domain.vo.WatchFatigueDataVo">
  79. SELECT id, device_id, 100-fatigue as pressure,create_time
  80. FROM watch_fatigue_data
  81. WHERE device_id = #{deviceId}
  82. AND toDate(create_time) = #{date}
  83. ORDER BY create_time ASC
  84. </select>
  85. <select id="countByDate" resultType="java.util.Map">
  86. SELECT
  87. status,
  88. COUNT(*) AS count
  89. FROM
  90. watch_fatigue_data
  91. WHERE
  92. create_time BETWEEN #{startTime} AND #{endTime}
  93. AND device_id = #{deviceId}
  94. GROUP BY
  95. status
  96. </select>
  97. <select id="list" resultType="com.fs.watch.domain.vo.WatchFatigueDataVo">
  98. SELECT
  99. id, device_id, 100-fatigue as pressure,create_time,status
  100. from
  101. watch_fatigue_data
  102. WHERE
  103. device_id = #{deviceId}
  104. AND create_time BETWEEN #{startTime} AND #{endTime}
  105. ORDER BY
  106. create_time ASC
  107. </select>
  108. </mapper>