WatchSosCallLogsMapper.xml 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.fs.watch.mapper.WatchSosCallLogsMapper">
  4. <resultMap type="com.fs.watch.domain.WatchSosCallLogs" id="BaseResultMap">
  5. <result property="id" column="id" jdbcType="OTHER" typeHandler="com.fs.watch.handler.UUIDTypeHandler"/>
  6. <result property="deviceId" column="device_id" jdbcType="VARCHAR"/>
  7. <result property="alarmTime" column="alarm_time" jdbcType="VARCHAR"/>
  8. <result property="lat" column="lat" jdbcType="VARCHAR"/>
  9. <result property="lon" column="lon" jdbcType="VARCHAR"/>
  10. <result property="callLogs" column="call_logs" jdbcType="VARCHAR"/>
  11. </resultMap>
  12. <!-- 查询列列表 -->
  13. <sql id="Base_Column_List">
  14. id, device_id, alarm_time, lat, lon, call_logs
  15. </sql>
  16. <!-- 根据创建时间查询 -->
  17. <select id="queryByAlarmTime" parameterType="String" resultType="Integer">
  18. SELECT COUNT(*)
  19. FROM watch_sos_call_logs
  20. WHERE alarm_time = #{alarmTime}
  21. </select>
  22. <select id="getByDeviceIdAndTime" resultMap="BaseResultMap">
  23. select * from watch_sos_call_logs where device_id like #{deviceId}
  24. and alarm_time = #{alarmTime}
  25. </select>
  26. <select id="getByDeviceIdAndTimeOne" resultMap="BaseResultMap">
  27. SELECT *
  28. FROM watch_sos_call_logs
  29. WHERE device_id LIKE #{deviceId}
  30. ORDER BY abs(toUnixTimestamp(alarm_time) - #{alarmTime})
  31. LIMIT 1
  32. </select>
  33. <!-- 插入数据 -->
  34. <update id="insert" parameterType="com.fs.watch.domain.WatchSosCallLogs">
  35. INSERT INTO watch_sos_call_logs
  36. <trim prefix="(" suffix=")" suffixOverrides=",">
  37. <if test="data.id != null">
  38. id,
  39. </if>
  40. <if test="data.deviceId != null">
  41. device_id,
  42. </if>
  43. <if test="data.alarmTime != null">
  44. alarm_time,
  45. </if>
  46. <if test="data.lat != null">
  47. lat,
  48. </if>
  49. <if test="data.lon != null">
  50. lon,
  51. </if>
  52. <if test="data.callLogs != null">
  53. call_logs,
  54. </if>
  55. </trim>
  56. <trim prefix="VALUES (" suffix=")" suffixOverrides=",">
  57. <if test="data.id != null">
  58. #{data.id},
  59. </if>
  60. <if test="data.deviceId != null">
  61. #{data.deviceId},
  62. </if>
  63. <if test="data.alarmTime != null">
  64. #{data.alarmTime},
  65. </if>
  66. <if test="data.lat != null">
  67. #{data.lat},
  68. </if>
  69. <if test="data.lon != null">
  70. #{data.lon},
  71. </if>
  72. <if test="data.callLogs != null">
  73. #{data.callLogs},
  74. </if>
  75. </trim>
  76. </update>
  77. <update id="batchInsertData" parameterType="java.util.List">
  78. INSERT INTO watch_sos_call_logs (device_id, alarm_time, lat, lon, call_logs)
  79. VALUES
  80. <foreach collection="list" item="item" index="index" separator=",">
  81. (
  82. #{item.deviceId},
  83. #{item.alarmTime},
  84. #{item.lat},
  85. #{item.lon},
  86. #{item.callLogs}
  87. )
  88. </foreach>
  89. </update>
  90. </mapper>