WatchAlarmDataMapper.xml 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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.WatchAlarmDataMapper">
  6. <resultMap id="BaseResultMap" type="com.fs.watch.domain.WatchAlarmData">
  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="title" column="title" jdbcType="VARCHAR"/>
  10. <result property="description" column="description" jdbcType="VARCHAR"/>
  11. <result property="dateTime" column="date_time" jdbcType="TIMESTAMP"/>
  12. <result property="type" column="type" jdbcType="VARCHAR"/>
  13. <result property="extra" column="extra" jdbcType="VARCHAR"/>
  14. <result property="location" column="location" jdbcType="VARCHAR"/>
  15. <result property="status" column="status" jdbcType="TINYINT"/>
  16. <result property="appStatus" column="app_status" jdbcType="TINYINT"/>
  17. <result property="isDel" column="is_del" jdbcType="TINYINT"/>
  18. </resultMap>
  19. <sql id="Base_Column_List">
  20. id, device_id, title, description, date_time, type, extra, location, status,app_status,is_del
  21. </sql>
  22. <!-- 单条插入 -->
  23. <update id="insert" parameterType="com.fs.watch.domain.WatchAlarmData">
  24. INSERT INTO watch_alarm_data
  25. <trim prefix="(" suffix=")" suffixOverrides=",">
  26. <if test="data.id != null">
  27. id,
  28. </if>
  29. <if test="data.deviceId != null">
  30. device_id,
  31. </if>
  32. <if test="data.title != null">
  33. title,
  34. </if>
  35. <if test="data.description != null">
  36. description,
  37. </if>
  38. <if test="data.dateTime != null">
  39. date_time,
  40. </if>
  41. <if test="data.type != null">
  42. type,
  43. </if>
  44. <if test="data.extra != null">
  45. extra,
  46. </if>
  47. <if test="data.location != null">
  48. location,
  49. </if>
  50. </trim>
  51. <trim prefix="VALUES (" suffix=")" suffixOverrides=",">
  52. <if test="data.id != null">
  53. #{data.id},
  54. </if>
  55. <if test="data.deviceId != null">
  56. #{data.deviceId},
  57. </if>
  58. <if test="data.title != null">
  59. #{data.title},
  60. </if>
  61. <if test="data.description != null">
  62. #{data.description},
  63. </if>
  64. <if test="data.dateTime != null">
  65. #{data.dateTime},
  66. </if>
  67. <if test="data.type != null">
  68. #{data.type},
  69. </if>
  70. <if test="data.extra != null">
  71. #{data.extra},
  72. </if>
  73. <if test="data.location != null">
  74. #{data.location},
  75. </if>
  76. </trim>
  77. </update>
  78. <!-- 批量插入 -->
  79. <update id="batchInsertData" parameterType="java.util.List">
  80. INSERT INTO watch_alarm_data (device_id, title, description, date_time, type, extra, location,status,app_status,is_del)
  81. VALUES
  82. <foreach collection="list" item="item" index="index" separator=",">
  83. (
  84. #{item.deviceId},
  85. #{item.title},
  86. #{item.description},
  87. #{item.dateTime},
  88. #{item.type},
  89. #{item.extra},
  90. #{item.location},
  91. #{item.status},
  92. #{item.appStatus},
  93. #{item.isDel}
  94. )
  95. </foreach>
  96. </update>
  97. <!-- 根据状态查询 -->
  98. <select id="queryByStatus" resultMap="BaseResultMap">
  99. SELECT <include refid="Base_Column_List"/>
  100. FROM watch.watch_alarm_data WHERE is_del = 0
  101. <if test="status != null">
  102. and status = #{status}
  103. </if>
  104. ORDER BY date_time DESC
  105. </select>
  106. <!-- <update id="setAppStatusById">-->
  107. <!-- update watch_alarm_data set app_status = 1 WHERE id IN-->
  108. <!-- <foreach collection="ids" item="id" open="(" separator="," close=")">-->
  109. <!-- #{id}-->
  110. <!-- </foreach>-->
  111. <!-- </update>-->
  112. <update id="setAppStatusById">
  113. ALTER TABLE watch.watch_alarm_data UPDATE app_status = 1 WHERE id IN
  114. <foreach collection="ids" item="id" open="(" separator="," close=")">
  115. #{id}
  116. </foreach>
  117. </update>
  118. <update id="setIsDel">
  119. ALTER TABLE watch.watch_alarm_data UPDATE is_del = 1 WHERE id IN
  120. <foreach collection="ids" item="id" open="(" separator="," close=")">
  121. #{id}
  122. </foreach>
  123. </update>
  124. <update id="deleteByDeviceId">
  125. ALTER TABLE watch.watch_alarm_data UPDATE is_del = 1
  126. WHERE device_id
  127. like #{deviceId}
  128. </update>
  129. <!-- 根据ID批量更新状态 -->
  130. <update id="setStatusById" parameterType="java.util.List">
  131. ALTER TABLE watch.watch_alarm_data UPDATE status = 1 WHERE id IN
  132. <foreach collection="ids" item="id" open="(" separator="," close=")">
  133. #{id}
  134. </foreach>
  135. </update>
  136. <update id="setAppStatusByDeviceId">
  137. ALTER TABLE watch.watch_alarm_data UPDATE app_status = 1
  138. WHERE device_id
  139. like #{deviceId}
  140. </update>
  141. <update id="setLocation">
  142. ALTER TABLE watch.watch_alarm_data UPDATE location = #{data.location}
  143. WHERE id = #{data.id}
  144. </update>
  145. <!-- 分页查询 -->
  146. <select id="queryPageByStatus" resultMap="BaseResultMap">
  147. SELECT <include refid="Base_Column_List"/>
  148. FROM watch.watch_alarm_data where is_del = 0
  149. <if test="status != null">
  150. and status = #{status}
  151. </if>
  152. <if test="appStatus != null">
  153. and app_status = #{appStatus}
  154. </if>
  155. <if test="deviceId != null and deviceId!=''">
  156. and device_id like concat('%',#{deviceId},'%')
  157. </if>
  158. ORDER BY date_time DESC
  159. <!-- 数据范围过滤 -->
  160. ${params.dataScope}
  161. </select>
  162. <select id="queryByStatusAndDeviceid" resultMap="BaseResultMap">
  163. SELECT <include refid="Base_Column_List"/>
  164. FROM watch.watch_alarm_data where is_del = 0
  165. <if test="status != null ">
  166. and status = #{status}
  167. </if>
  168. <if test="appStatus != null ">
  169. and app_status = #{appStatus}
  170. </if>
  171. <if test="deviceId != null">
  172. and device_id like concat('%',#{deviceId},'%')
  173. </if>
  174. ORDER BY date_time DESC
  175. </select>
  176. <select id="getUnreadNum" resultType="java.lang.Integer">
  177. SELECT COUNT(1) FROM watch.watch_alarm_data WHERE app_status = 0 and is_del = 0
  178. <if test="deviceId != null and deviceId !=''">
  179. and device_id like concat('%',#{deviceId},'%')
  180. </if>
  181. </select>
  182. </mapper>