DeviceMapper.java 13 KB

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