DeviceMapper.java 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. package com.genersoft.iot.vmp.gb28181.dao;
  2. import com.genersoft.iot.vmp.gb28181.bean.Device;
  3. import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
  4. import org.apache.ibatis.annotations.*;
  5. import org.springframework.stereotype.Repository;
  6. import java.util.List;
  7. /**
  8. * 用于存储设备信息
  9. */
  10. @Mapper
  11. @Repository
  12. public interface DeviceMapper {
  13. @Select("SELECT " +
  14. "id, " +
  15. "device_id, " +
  16. "coalesce(custom_name, name) as name, " +
  17. "password, " +
  18. "manufacturer, " +
  19. "model, " +
  20. "firmware, " +
  21. "transport," +
  22. "stream_mode," +
  23. "ip," +
  24. "sdp_ip," +
  25. "local_ip," +
  26. "port," +
  27. "host_address," +
  28. "expires," +
  29. "register_time," +
  30. "keepalive_time," +
  31. "create_time," +
  32. "update_time," +
  33. "charset," +
  34. "subscribe_cycle_for_catalog," +
  35. "subscribe_cycle_for_mobile_position," +
  36. "mobile_position_submission_interval," +
  37. "subscribe_cycle_for_alarm," +
  38. "ssrc_check," +
  39. "as_message_channel," +
  40. "geo_coord_sys," +
  41. "on_line," +
  42. "media_server_id," +
  43. "broadcast_push_after_ack," +
  44. "(SELECT count(0) FROM wvp_device_channel dc WHERE dc.device_db_id= de.id) as channel_count "+
  45. " FROM wvp_device de WHERE de.device_id = #{deviceId}")
  46. Device getDeviceByDeviceId(String deviceId);
  47. @Insert("INSERT INTO wvp_device (" +
  48. "device_id, " +
  49. "name, " +
  50. "manufacturer, " +
  51. "model, " +
  52. "firmware, " +
  53. "transport," +
  54. "stream_mode," +
  55. "media_server_id," +
  56. "ip," +
  57. "sdp_ip," +
  58. "local_ip," +
  59. "port," +
  60. "host_address," +
  61. "expires," +
  62. "register_time," +
  63. "keepalive_time," +
  64. "keepalive_interval_time," +
  65. "create_time," +
  66. "update_time," +
  67. "charset," +
  68. "subscribe_cycle_for_catalog," +
  69. "subscribe_cycle_for_mobile_position,"+
  70. "mobile_position_submission_interval,"+
  71. "subscribe_cycle_for_alarm,"+
  72. "ssrc_check,"+
  73. "as_message_channel,"+
  74. "broadcast_push_after_ack,"+
  75. "geo_coord_sys,"+
  76. "on_line"+
  77. ") VALUES (" +
  78. "#{deviceId}," +
  79. "#{name}," +
  80. "#{manufacturer}," +
  81. "#{model}," +
  82. "#{firmware}," +
  83. "#{transport}," +
  84. "#{streamMode}," +
  85. "#{mediaServerId}," +
  86. "#{ip}," +
  87. "#{sdpIp}," +
  88. "#{localIp}," +
  89. "#{port}," +
  90. "#{hostAddress}," +
  91. "#{expires}," +
  92. "#{registerTime}," +
  93. "#{keepaliveTime}," +
  94. "#{keepaliveIntervalTime}," +
  95. "#{createTime}," +
  96. "#{updateTime}," +
  97. "#{charset}," +
  98. "#{subscribeCycleForCatalog}," +
  99. "#{subscribeCycleForMobilePosition}," +
  100. "#{mobilePositionSubmissionInterval}," +
  101. "#{subscribeCycleForAlarm}," +
  102. "#{ssrcCheck}," +
  103. "#{asMessageChannel}," +
  104. "#{broadcastPushAfterAck}," +
  105. "#{geoCoordSys}," +
  106. "#{onLine}" +
  107. ")")
  108. @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
  109. int add(Device device);
  110. @Update(value = {" <script>" +
  111. "UPDATE wvp_device " +
  112. "SET update_time=#{updateTime}" +
  113. "<if test=\"name != null\">, name=#{name}</if>" +
  114. "<if test=\"manufacturer != null\">, manufacturer=#{manufacturer}</if>" +
  115. "<if test=\"model != null\">, model=#{model}</if>" +
  116. "<if test=\"firmware != null\">, firmware=#{firmware}</if>" +
  117. "<if test=\"transport != null\">, transport=#{transport}</if>" +
  118. "<if test=\"ip != null\">, ip=#{ip}</if>" +
  119. "<if test=\"localIp != null\">, local_ip=#{localIp}</if>" +
  120. "<if test=\"port != null\">, port=#{port}</if>" +
  121. "<if test=\"hostAddress != null\">, host_address=#{hostAddress}</if>" +
  122. "<if test=\"onLine != null\">, on_line=#{onLine}</if>" +
  123. "<if test=\"registerTime != null\">, register_time=#{registerTime}</if>" +
  124. "<if test=\"keepaliveTime != null\">, keepalive_time=#{keepaliveTime}</if>" +
  125. "<if test=\"keepaliveIntervalTime != null\">, keepalive_interval_time=#{keepaliveIntervalTime}</if>" +
  126. "<if test=\"expires != null\">, expires=#{expires}</if>" +
  127. "WHERE device_id=#{deviceId}"+
  128. " </script>"})
  129. int update(Device device);
  130. @Select(
  131. " <script>" +
  132. "SELECT " +
  133. "id, " +
  134. "device_id, " +
  135. "coalesce(custom_name, name) as name, " +
  136. "password, " +
  137. "manufacturer, " +
  138. "model, " +
  139. "firmware, " +
  140. "transport," +
  141. "stream_mode," +
  142. "ip,"+
  143. "sdp_ip,"+
  144. "local_ip,"+
  145. "port,"+
  146. "host_address,"+
  147. "expires,"+
  148. "register_time,"+
  149. "keepalive_time,"+
  150. "create_time,"+
  151. "update_time,"+
  152. "charset,"+
  153. "subscribe_cycle_for_catalog,"+
  154. "subscribe_cycle_for_mobile_position,"+
  155. "mobile_position_submission_interval,"+
  156. "subscribe_cycle_for_alarm,"+
  157. "ssrc_check,"+
  158. "as_message_channel,"+
  159. "broadcast_push_after_ack,"+
  160. "geo_coord_sys,"+
  161. "on_line,"+
  162. "media_server_id,"+
  163. "(SELECT count(0) FROM wvp_device_channel dc WHERE dc.device_db_id= de.id) as channel_count " +
  164. "FROM wvp_device de" +
  165. "<if test=\"onLine != null\"> where de.on_line=${onLine}</if>"+
  166. " order by de.create_time desc "+
  167. " </script>"
  168. )
  169. List<Device> getDevices(Boolean onLine);
  170. @Delete("DELETE FROM wvp_device WHERE device_id=#{deviceId}")
  171. int del(String deviceId);
  172. @Select("SELECT " +
  173. "id, " +
  174. "device_id, " +
  175. "coalesce(custom_name, name) as name, " +
  176. "password, " +
  177. "manufacturer, " +
  178. "model, " +
  179. "firmware, " +
  180. "transport," +
  181. "stream_mode," +
  182. "ip," +
  183. "sdp_ip,"+
  184. "local_ip,"+
  185. "port,"+
  186. "host_address,"+
  187. "expires,"+
  188. "register_time,"+
  189. "keepalive_time,"+
  190. "create_time,"+
  191. "update_time,"+
  192. "charset,"+
  193. "subscribe_cycle_for_catalog,"+
  194. "subscribe_cycle_for_mobile_position,"+
  195. "mobile_position_submission_interval,"+
  196. "subscribe_cycle_for_alarm,"+
  197. "ssrc_check,"+
  198. "as_message_channel,"+
  199. "broadcast_push_after_ack,"+
  200. "geo_coord_sys,"+
  201. "on_line"+
  202. " FROM wvp_device WHERE on_line = true")
  203. List<Device> getOnlineDevices();
  204. @Select("SELECT " +
  205. "id,"+
  206. "device_id,"+
  207. "coalesce(custom_name,name)as name,"+
  208. "password,"+
  209. "manufacturer,"+
  210. "model,"+
  211. "firmware,"+
  212. "transport,"+
  213. "stream_mode,"+
  214. "ip,"+
  215. "sdp_ip,"+
  216. "local_ip,"+
  217. "port,"+
  218. "host_address,"+
  219. "expires,"+
  220. "register_time,"+
  221. "keepalive_time,"+
  222. "create_time,"+
  223. "update_time,"+
  224. "charset,"+
  225. "subscribe_cycle_for_catalog,"+
  226. "subscribe_cycle_for_mobile_position,"+
  227. "mobile_position_submission_interval,"+
  228. "subscribe_cycle_for_alarm,"+
  229. "ssrc_check,"+
  230. "as_message_channel,"+
  231. "broadcast_push_after_ack,"+
  232. "geo_coord_sys,"+
  233. "on_line"+
  234. " FROM wvp_device WHERE ip = #{host} AND port=#{port}")
  235. Device getDeviceByHostAndPort(@Param("host") String host, @Param("port") int port);
  236. @Update(value = {" <script>" +
  237. "UPDATE wvp_device " +
  238. "SET update_time=#{updateTime}, custom_name=#{name} , password=#{password}, stream_mode=#{streamMode}" +
  239. ", ip=#{ip}, sdp_ip=#{sdpIp}, port=#{port}, charset=#{charset}, subscribe_cycle_for_catalog=#{subscribeCycleForCatalog}" +
  240. ", subscribe_cycle_for_mobile_position=#{subscribeCycleForMobilePosition}, mobile_position_submission_interval=#{mobilePositionSubmissionInterval}" +
  241. ", subscribe_cycle_for_alarm=#{subscribeCycleForAlarm}, ssrc_check=#{ssrcCheck}, as_message_channel=#{asMessageChannel}" +
  242. ", broadcast_push_after_ack=#{broadcastPushAfterAck}, geo_coord_sys=#{geoCoordSys}, media_server_id=#{mediaServerId}" +
  243. " WHERE id=#{id}"+
  244. " </script>"})
  245. void updateCustom(Device device);
  246. @Insert("INSERT INTO wvp_device (" +
  247. "device_id,"+
  248. "custom_name,"+
  249. "password,"+
  250. "sdp_ip,"+
  251. "create_time,"+
  252. "update_time,"+
  253. "charset,"+
  254. "ssrc_check,"+
  255. "as_message_channel,"+
  256. "broadcast_push_after_ack,"+
  257. "geo_coord_sys,"+
  258. "on_line,"+
  259. "stream_mode," +
  260. "media_server_id"+
  261. ") VALUES (" +
  262. "#{deviceId}," +
  263. "#{name}," +
  264. "#{password}," +
  265. "#{sdpIp}," +
  266. "#{createTime}," +
  267. "#{updateTime}," +
  268. "#{charset}," +
  269. "#{ssrcCheck}," +
  270. "#{asMessageChannel}," +
  271. "#{broadcastPushAfterAck}," +
  272. "#{geoCoordSys}," +
  273. "#{onLine}," +
  274. "#{streamMode}," +
  275. "#{mediaServerId}" +
  276. ")")
  277. void addCustomDevice(Device device);
  278. @Select("select * FROM wvp_device")
  279. List<Device> getAll();
  280. @Select("select * FROM wvp_device where as_message_channel = true")
  281. List<Device> queryDeviceWithAsMessageChannel();
  282. @Select(" <script>" +
  283. "SELECT " +
  284. "id, " +
  285. "device_id, " +
  286. "coalesce(custom_name, name) as name, " +
  287. "password, " +
  288. "manufacturer, " +
  289. "model, " +
  290. "firmware, " +
  291. "transport," +
  292. "stream_mode," +
  293. "ip,"+
  294. "sdp_ip,"+
  295. "local_ip,"+
  296. "port,"+
  297. "host_address,"+
  298. "expires,"+
  299. "register_time,"+
  300. "keepalive_time,"+
  301. "create_time,"+
  302. "update_time,"+
  303. "charset,"+
  304. "subscribe_cycle_for_catalog,"+
  305. "subscribe_cycle_for_mobile_position,"+
  306. "mobile_position_submission_interval,"+
  307. "subscribe_cycle_for_alarm,"+
  308. "ssrc_check,"+
  309. "as_message_channel,"+
  310. "broadcast_push_after_ack,"+
  311. "geo_coord_sys,"+
  312. "on_line,"+
  313. "media_server_id,"+
  314. "(SELECT count(0) FROM wvp_device_channel dc WHERE dc.device_db_id= de.id) as channel_count " +
  315. " FROM wvp_device de" +
  316. " where 1 = 1 "+
  317. " <if test='status != null'> AND de.on_line=${status}</if>"+
  318. " <if test='query != null'> AND (coalesce(custom_name, name) LIKE '%${query}%' OR device_id LIKE '%${query}%' OR ip LIKE '%${query}%')</if> " +
  319. " order by create_time desc "+
  320. " </script>")
  321. List<Device> getDeviceList(@Param("query") String query, @Param("status") Boolean status);
  322. @Select("select * from wvp_device_channel where id = #{id}")
  323. DeviceChannel getRawChannel(@Param("id") int id);
  324. @Select("select * from wvp_device where id = #{id}")
  325. Device query(@Param("id") Integer id);
  326. @Select("select wd.* from wvp_device wd left join wvp_device_channel wdc on wd.id = wdc.device_db_id where wdc.id = #{channelId}")
  327. Device queryByChannelId(@Param("channelId") Integer channelId);
  328. @Select("select wd.* from wvp_device wd left join wvp_device_channel wdc on wd.id = wdc.device_db_id where wdc.device_id = #{channelDeviceId}")
  329. Device getDeviceBySourceChannelDeviceId(@Param("channelDeviceId") String channelDeviceId);
  330. }