WatchDeviceInfoMapper.xml 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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.WatchDeviceInfoMapper">
  6. <resultMap id="BaseResultMap" type="com.fs.watch.domain.WatchDeviceInfo">
  7. <id property="deviceId" column="device_id" jdbcType="BIGINT"/>
  8. <result property="companyId" column="company_id" jdbcType="BIGINT"/>
  9. <result property="companyUserId" column="company_user_id" jdbcType="BIGINT"/>
  10. <result property="doctorId" column="doctor_id" jdbcType="BIGINT"/>
  11. <result property="deviceNumber" column="device_number" jdbcType="VARCHAR"/>
  12. <result property="battery" column="battery" jdbcType="INTEGER"/>
  13. <result property="rssi" column="rssi" jdbcType="INTEGER"/>
  14. <result property="status" column="status" jdbcType="INTEGER"/>
  15. <result property="createBy" column="create_by" jdbcType="VARCHAR"/>
  16. <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
  17. <result property="updateBy" column="update_by" jdbcType="VARCHAR"/>
  18. <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
  19. <result property="isDel" column="is_del" jdbcType="TINYINT"/>
  20. <result property="lifeStatus" column="life_status" jdbcType="INTEGER"/>
  21. <result property="isNormal" column="is_normal" jdbcType="INTEGER"/>
  22. </resultMap>
  23. <sql id="Base_Column_List">
  24. device_id,company_id,company_user_id,doctor_id,device_number,
  25. battery,rssi,status,
  26. create_by,create_time,update_by,
  27. update_time,is_del,life_status,is_normal
  28. </sql>
  29. <insert id="insert">
  30. insert into watch_device_info
  31. <trim prefix="(" suffix=")" suffixOverrides=",">
  32. <if test="deviceId != null">device_id,</if>
  33. <if test="createTime != null">create_time,</if>
  34. <if test="createBy != null">create_by,</if>
  35. <if test="updateTime != null">update_time,</if>
  36. <if test="updateBy != null">update_by,</if>
  37. <if test="deviceNumber != null">device_number,</if>
  38. <if test="battery != null">battery,</if>
  39. <if test="rssi != null">rssi,</if>
  40. <if test="status != null">status,</if>
  41. <if test="lifeStatus != null">life_status,</if>
  42. <if test="isNormal != null">is_normal,</if>
  43. </trim>
  44. <trim prefix="values (" suffix=")" suffixOverrides=",">
  45. <if test="deviceId != null">#{deviceId},</if>
  46. <if test="createTime != null">#{createTime},</if>
  47. <if test="createBy != null">#{createBy},</if>
  48. <if test="updateTime != null">#{updateTime},</if>
  49. <if test="updateBy != null">#{updateBy},</if>
  50. <if test="deviceNumber != null">#{deviceNumber},</if>
  51. <if test="battery != null">#{battery},</if>
  52. <if test="rssi != null">#{rssi},</if>
  53. <if test="status != null">#{status},</if>
  54. <if test="lifeStatus != null">#{lifeStatus},</if>
  55. <if test="isNormal != null">#{isNormal},</if>
  56. </trim>
  57. </insert>
  58. <insert id="insertDeviceInfo" parameterType="WatchDeviceInfo" useGeneratedKeys="true" keyProperty="deviceId">
  59. insert into watch_device_info
  60. <trim prefix="(" suffix=")" suffixOverrides=",">
  61. <if test="createTime != null">create_time,</if>
  62. <if test="createBy != null">create_by,</if>
  63. <if test="updateTime != null">update_time,</if>
  64. <if test="updateBy != null">update_by,</if>
  65. <if test="deviceNumber != null">device_number,</if>
  66. <if test="battery != null">battery,</if>
  67. <if test="rssi != null">rssi,</if>
  68. <if test="status != null">status,</if>
  69. <if test="lifeStatus != null">life_status,</if>
  70. <if test="isNormal != null">is_normal,</if>
  71. </trim>
  72. <trim prefix="values (" suffix=")" suffixOverrides=",">
  73. <if test="createTime != null">#{createTime},</if>
  74. <if test="createBy != null">#{createBy},</if>
  75. <if test="updateTime != null">#{updateTime},</if>
  76. <if test="updateBy != null">#{updateBy},</if>
  77. <if test="deviceNumber != null">#{deviceNumber},</if>
  78. <if test="battery != null">#{battery},</if>
  79. <if test="rssi != null">#{rssi},</if>
  80. <if test="status != null">#{status},</if>
  81. <if test="lifeStatus != null">#{lifeStatus},</if>
  82. <if test="isNormal != null">#{isNormal},</if>
  83. </trim>
  84. </insert>
  85. <update id="updateByDeviceNumber">
  86. update watch_device_info
  87. <trim prefix="SET" suffixOverrides=",">
  88. <if test="createTime != null">create_time = #{createTime},</if>
  89. <if test="createBy != null">create_by = #{createBy},</if>
  90. <if test="updateTime != null">update_time = #{updateTime},</if>
  91. <if test="updateBy != null">update_by = #{updateBy},</if>
  92. <if test="userId != null">user_id = #{userId},</if>
  93. <if test="battery != null">battery = #{battery},</if>
  94. <if test="rssi != null">rssi = #{rssi},</if>
  95. <if test="status != null">status = #{status},</if>
  96. <if test="lifeStatus != null">life_status = #{lifeStatus},</if>
  97. <if test="isNormal != null">is_normal = #{isNormal},</if>
  98. </trim>
  99. where device_number like #{deviceNumber}
  100. </update>
  101. <update id="removeUserId">
  102. update watch_device_info
  103. <trim prefix="SET" suffixOverrides=",">
  104. <if test="createTime != null">create_time = #{createTime},</if>
  105. <if test="createBy != null">create_by = #{createBy},</if>
  106. <if test="updateTime != null">update_time = #{updateTime},</if>
  107. <if test="updateBy != null">update_by = #{updateBy},</if>
  108. user_id = #{userId},
  109. <if test="battery != null">battery = #{battery},</if>
  110. <if test="rssi != null">rssi = #{rssi},</if>
  111. <if test="status != null">status = #{status},</if>
  112. <if test="lifeStatus != null">life_status = #{lifeStatus},</if>
  113. <if test="isNormal != null">is_normal = #{isNormal},</if>
  114. </trim>
  115. where device_number like #{deviceNumber}
  116. </update>
  117. <update id="remove">
  118. update watch_device_info set is_del = 1 where device_number like #{deviceNumber}
  119. </update>
  120. <update id="updateDeviceInfo" parameterType="WatchDeviceInfo">
  121. update watch_device_info
  122. <trim prefix="SET" suffixOverrides=",">
  123. <if test="createTime != null">create_time = #{createTime},</if>
  124. <if test="createBy != null">create_by = #{createBy},</if>
  125. <if test="updateTime != null">update_time = #{updateTime},</if>
  126. <if test="updateBy != null">update_by = #{updateBy},</if>
  127. <if test="deviceNumber != null">device_number = #{deviceNumber},</if>
  128. <if test="battery != null">battery = #{battery},</if>
  129. <if test="rssi != null">rssi = #{rssi},</if>
  130. <if test="status != null">status = #{status},</if>
  131. <if test="lifeStatus != null">life_status = #{lifeStatus},</if>
  132. <if test="isNormal != null">is_normal = #{isNormal},</if>
  133. </trim>
  134. where device_id = #{deviceId}
  135. </update>
  136. <delete id="deleteDeviceInfoByDeviceIds" parameterType="String">
  137. <!-- delete from device_info where device_id in-->
  138. <!-- <foreach item="deviceId" collection="array" open="(" separator="," close=")">-->
  139. <!-- #{deviceId}-->
  140. <!-- </foreach>-->
  141. update watch_device_info set is_del = 1 where device_id in
  142. <foreach item="deviceId" collection="array" open="(" separator="," close=")">
  143. #{deviceId}
  144. </foreach>
  145. </delete>
  146. <select id="selectByDeviceNumber" resultType="com.fs.watch.domain.WatchDeviceInfo">
  147. SELECT * FROM watch_device_info WHERE device_number LIKE #{deviceNumber}
  148. </select>
  149. <select id="selectDeviceInfoList" parameterType="com.fs.watch.param.WatchDeviceInfoQueryParam" resultType="WatchDeviceInfoVo">
  150. SELECT a.*,
  151. IF(a.`status`=0,"OFFLINE",IF(a.`status` = 1,"ONLINE",IF(a.`status` = 3,"UNACTIVE",IF(a.`status` = 4,"DISABLE","NOT EXIST")))) as status_out,
  152. IF(a.`life_status`=0,"空置",IF(a.`life_status` = 1,"已送出","已激活")) as lifeStatusOut,fu.nick_name as watch_user_name,
  153. GROUP_CONCAT(DISTINCT c.company_name) AS company_name,
  154. GROUP_CONCAT(DISTINCT cu.nick_name) AS company_user_name,
  155. GROUP_CONCAT(DISTINCT fd.doctor_name) AS doctor_name,
  156. GROUP_CONCAT(DISTINCT fu2.nick_name) AS family_user_name
  157. FROM `watch_device_info` a
  158. LEFT JOIN watch_company wc ON wc.device_id = a.device_id
  159. LEFT JOIN watch_company_user wcu ON wcu.device_id = a.device_id
  160. LEFT JOIN watch_doctor wd ON wd.device_id = a.device_id
  161. LEFT JOIN watch_family wf ON wf.device_id = a.device_id
  162. LEFT JOIN fs_user fu ON fu.user_id = a.user_id
  163. LEFT JOIN company c ON c.company_id = wc.company_id
  164. LEFT JOIN fs_doctor fd ON fd.doctor_id = wd.doctor_id
  165. LEFT JOIN company_user cu ON cu.user_id = wcu.company_user_id
  166. LEFT JOIN fs_user fu2 ON fu2.user_id = wf.family_user_id
  167. where a.is_del = 0
  168. <if test="companyId != null "> and wc.company_id = #{companyId}</if>
  169. <if test="companyUserId != null "> and wcu.company_user_id = #{companyUserId}</if>
  170. <if test="doctorId != null ">and wd.doctor_id = #{doctorId}</if>
  171. <if test="userId != null "> and a.user_id = #{userId}</if>
  172. <if test="familyUserId != null "> and wf.family_user_id = #{familyUserId}</if>
  173. <if test="deviceNumber != null and deviceNumber != ''"> and a.device_number like concat("%",#{deviceNumber},"%")</if>
  174. <if test="battery != null "> and a.battery = #{battery}</if>
  175. <if test="rssi != null "> and a.rssi = #{rssi}</if>
  176. <if test="status != null "> and a.status = #{status}</if>
  177. <if test="lifeStatus != null">and a.life_status = #{lifeStatus}</if>
  178. <if test="isNormal != null">and a.is_normal = #{isNormal}</if>
  179. GROUP BY a.device_id
  180. </select>
  181. <select id="selectDeviceInfoList_COUNT" parameterType="com.fs.watch.param.WatchDeviceInfoQueryParam" resultType="long">
  182. SELECT COUNT(DISTINCT a.device_id) FROM `watch_device_info` a
  183. <if test="companyId != null ">
  184. LEFT JOIN watch_company wc ON wc.device_id = a.device_id
  185. </if>
  186. <if test="companyUserId != null ">
  187. LEFT JOIN watch_company_user wcu ON wcu.device_id = a.device_id
  188. </if>
  189. <if test="doctorId != null ">
  190. LEFT JOIN watch_doctor wd ON wd.device_id = a.device_id
  191. </if>
  192. <if test="userId != null ">
  193. LEFT JOIN fs_user fu ON fu.user_id = a.user_id
  194. </if>
  195. <if test="familyUserId != null ">
  196. LEFT JOIN watch_family wf ON wf.device_id = a.device_id
  197. </if>
  198. where a.is_del = 0
  199. <if test="companyId != null "> and wc.company_id = #{companyId}</if>
  200. <if test="companyUserId != null "> and wcu.company_user_id = #{companyUserId}</if>
  201. <if test="doctorId != null "> and wd.doctor_id = #{doctorId}</if>
  202. <if test="userId != null "> and a.user_id = #{userId}</if>
  203. <if test="familyUserId != null "> and wf.family_user_id = #{familyUserId}</if>
  204. <if test="deviceNumber != null and deviceNumber != ''"> and a.device_number like concat("%",#{deviceNumber},"%")</if>
  205. <if test="battery != null "> and a.battery = #{battery}</if>
  206. <if test="rssi != null "> and a.rssi = #{rssi}</if>
  207. <if test="status != null "> and a.status = #{status}</if>
  208. <if test="lifeStatus != null">and a.life_status = #{lifeStatus}</if>
  209. <if test="isNormal != null">and a.is_normal = #{isNormal}</if>
  210. </select>
  211. <select id="selectDeviceInfoByDeviceId" parameterType="Long" resultType="WatchDeviceInfoVo">
  212. <!-- <include refid="selectDeviceInfoVo"/>-->
  213. SELECT a.*,IF(a.`status`=0,"OFFLINE",IF(a.`status` = 1,"ONLINE",IF(a.`status` = 3,"UNACTIVE",IF(a.`status` = 4,"DISABLE","NOT EXIST")))) as status_out,
  214. IF(a.`life_status`=0,"空置",IF(a.`life_status` = 1,"已送出","已激活")) as lifeStatusOut,
  215. GROUP_CONCAT(DISTINCT c.company_name) AS company_name,
  216. GROUP_CONCAT(DISTINCT cu.nick_name) AS company_user_name,
  217. GROUP_CONCAT(DISTINCT fd.doctor_name) AS doctor_name,
  218. GROUP_CONCAT(DISTINCT fu2.nick_name) AS family_user_name,
  219. GROUP_CONCAT(DISTINCT c.company_id) AS company_id,
  220. GROUP_CONCAT(DISTINCT cu.user_id) AS company_user_id,
  221. GROUP_CONCAT(DISTINCT fd.doctor_id) AS doctor_id,
  222. GROUP_CONCAT(DISTINCT fu2.user_id) AS family_user_id
  223. FROM `watch_device_info` a
  224. LEFT JOIN watch_company wc ON wc.device_id = a.device_id
  225. LEFT JOIN watch_company_user wcu ON wcu.device_id = a.device_id
  226. LEFT JOIN watch_doctor wd ON wd.device_id = a.device_id
  227. LEFT JOIN watch_family wf ON wf.device_id = a.device_id
  228. LEFT JOIN fs_user fu ON fu.user_id = a.user_id
  229. LEFT JOIN company c ON c.company_id = wc.company_id
  230. LEFT JOIN fs_doctor fd ON fd.doctor_id = wd.doctor_id
  231. LEFT JOIN company_user cu ON cu.user_id = wcu.company_user_id
  232. LEFT JOIN fs_user fu2 ON fu2.user_id = wf.family_user_id
  233. where a.device_id = #{deviceId} and a.is_del = 0
  234. GROUP BY a.device_id
  235. </select>
  236. <select id="getByNumber" resultType="com.fs.watch.domain.vo.WatchDeviceInfoVo">
  237. SELECT a.*,IF(a.`status`=0,"OFFLINE",IF(a.`status` = 1,"ONLINE",IF(a.`status` = 3,"UNACTIVE",IF(a.`status` = 4,"DISABLE","NOT EXIST")))) as status_out,
  238. IF(a.`life_status`=0,"空置",IF(a.`life_status` = 1,"已送出","已激活")) as lifeStatusOut,
  239. GROUP_CONCAT(DISTINCT c.company_name) AS company_name,
  240. GROUP_CONCAT(DISTINCT cu.nick_name) AS company_user_name,
  241. GROUP_CONCAT(DISTINCT fd.doctor_name) AS doctor_name,
  242. GROUP_CONCAT(DISTINCT fu2.nick_name) AS family_user_name,
  243. GROUP_CONCAT(DISTINCT c.company_id) AS company_id,
  244. GROUP_CONCAT(DISTINCT cu.user_id) AS company_user_id,
  245. GROUP_CONCAT(DISTINCT fd.doctor_id) AS doctor_id,
  246. GROUP_CONCAT(DISTINCT fu2.user_id) AS family_user_id
  247. FROM `watch_device_info` a
  248. LEFT JOIN watch_company wc ON wc.device_id = a.device_id
  249. LEFT JOIN watch_company_user wcu ON wcu.device_id = a.device_id
  250. LEFT JOIN watch_doctor wd ON wd.device_id = a.device_id
  251. LEFT JOIN watch_family wf ON wf.device_id = a.device_id
  252. LEFT JOIN fs_user fu ON fu.user_id = a.user_id
  253. LEFT JOIN company c ON c.company_id = wc.company_id
  254. LEFT JOIN fs_doctor fd ON fd.doctor_id = wd.doctor_id
  255. LEFT JOIN company_user cu ON cu.user_id = wcu.company_user_id
  256. LEFT JOIN fs_user fu2 ON fu2.user_id = wf.family_user_id
  257. where a.device_number like #{number} and a.is_del = 0
  258. GROUP BY a.device_id
  259. </select>
  260. <select id="selectByUserExist" resultType="com.fs.watch.domain.WatchDeviceInfo">
  261. select a.*
  262. from `watch_device_info` a
  263. where a.is_del = 0 and user_id IS NOT NULL
  264. </select>
  265. <select id="selectListByUserOrFamilyUser" resultType="com.fs.watch.domain.WatchDeviceInfo">
  266. select i.*
  267. from `watch_device_info` i
  268. left join watch_family f on i.device_id = f.device_id
  269. where i.is_del = 0 and
  270. (f.family_user_id = #{userId} or i.user_id = #{userId} )
  271. </select>
  272. </mapper>