Commit a2f08541387806c9299a43b38fbfeaa5da5904a9

Authored by 648540858
1 parent 381b3d15

优化通道录入性能,优化启动后读取配置写入数据库的过程

src/main/java/com/genersoft/iot/vmp/conf/MediaConfig.java
@@ -60,7 +60,7 @@ public class MediaConfig{ @@ -60,7 +60,7 @@ public class MediaConfig{
60 private String secret; 60 private String secret;
61 61
62 @Value("${media.stream-none-reader-delay-ms:18000}") 62 @Value("${media.stream-none-reader-delay-ms:18000}")
63 - private String streamNoneReaderDelayMS = "18000"; 63 + private int streamNoneReaderDelayMS = 18000;
64 64
65 @Value("${media.rtp.enable}") 65 @Value("${media.rtp.enable}")
66 private boolean rtpEnable; 66 private boolean rtpEnable;
@@ -141,7 +141,7 @@ public class MediaConfig{ @@ -141,7 +141,7 @@ public class MediaConfig{
141 return secret; 141 return secret;
142 } 142 }
143 143
144 - public String getStreamNoneReaderDelayMS() { 144 + public int getStreamNoneReaderDelayMS() {
145 return streamNoneReaderDelayMS; 145 return streamNoneReaderDelayMS;
146 } 146 }
147 147
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java
@@ -1163,7 +1163,7 @@ public class SIPCommander implements ISIPCommander { @@ -1163,7 +1163,7 @@ public class SIPCommander implements ISIPCommander {
1163 @Override 1163 @Override
1164 public boolean catalogQuery(Device device, SipSubscribe.Event errorEvent) { 1164 public boolean catalogQuery(Device device, SipSubscribe.Event errorEvent) {
1165 // 清空通道 1165 // 清空通道
1166 - storager.cleanChannelsForDevice(device.getDeviceId()); 1166 +// storager.cleanChannelsForDevice(device.getDeviceId());
1167 try { 1167 try {
1168 StringBuffer catalogXml = new StringBuffer(200); 1168 StringBuffer catalogXml = new StringBuffer(200);
1169 catalogXml.append("<?xml version=\"1.0\" encoding=\"GB2312\"?>\r\n"); 1169 catalogXml.append("<?xml version=\"1.0\" encoding=\"GB2312\"?>\r\n");
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/CatalogResponseMessageHandler.java
@@ -27,7 +27,9 @@ import javax.sip.RequestEvent; @@ -27,7 +27,9 @@ import javax.sip.RequestEvent;
27 import javax.sip.SipException; 27 import javax.sip.SipException;
28 import javax.sip.message.Response; 28 import javax.sip.message.Response;
29 import java.text.ParseException; 29 import java.text.ParseException;
  30 +import java.util.ArrayList;
30 import java.util.Iterator; 31 import java.util.Iterator;
  32 +import java.util.List;
31 33
32 import static com.genersoft.iot.vmp.gb28181.utils.XmlUtil.getText; 34 import static com.genersoft.iot.vmp.gb28181.utils.XmlUtil.getText;
33 35
@@ -69,7 +71,7 @@ public class CatalogResponseMessageHandler extends SIPRequestProcessorParent imp @@ -69,7 +71,7 @@ public class CatalogResponseMessageHandler extends SIPRequestProcessorParent imp
69 Element deviceListElement = rootElement.element("DeviceList"); 71 Element deviceListElement = rootElement.element("DeviceList");
70 Iterator<Element> deviceListIterator = deviceListElement.elementIterator(); 72 Iterator<Element> deviceListIterator = deviceListElement.elementIterator();
71 if (deviceListIterator != null) { 73 if (deviceListIterator != null) {
72 - 74 + List<DeviceChannel> channelList = new ArrayList<>();
73 // 遍历DeviceList 75 // 遍历DeviceList
74 while (deviceListIterator.hasNext()) { 76 while (deviceListIterator.hasNext()) {
75 Element itemDevice = deviceListIterator.next(); 77 Element itemDevice = deviceListIterator.next();
@@ -151,9 +153,10 @@ public class CatalogResponseMessageHandler extends SIPRequestProcessorParent imp @@ -151,9 +153,10 @@ public class CatalogResponseMessageHandler extends SIPRequestProcessorParent imp
151 deviceChannel.setPTZType(Integer.parseInt(getText(itemDevice, "PTZType"))); 153 deviceChannel.setPTZType(Integer.parseInt(getText(itemDevice, "PTZType")));
152 } 154 }
153 deviceChannel.setHasAudio(true); // 默认含有音频,播放时再检查是否有音频及是否AAC 155 deviceChannel.setHasAudio(true); // 默认含有音频,播放时再检查是否有音频及是否AAC
154 - storager.updateChannel(device.getDeviceId(), deviceChannel); 156 + // TODO 修改为批量插入
  157 + channelList.add(deviceChannel);
155 } 158 }
156 - 159 + storager.updateChannels(device.getDeviceId(), channelList);
157 RequestMessage msg = new RequestMessage(); 160 RequestMessage msg = new RequestMessage();
158 msg.setKey(key); 161 msg.setKey(key);
159 msg.setData(device); 162 msg.setData(device);
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRunner.java
@@ -49,8 +49,13 @@ public class ZLMRunner implements CommandLineRunner { @@ -49,8 +49,13 @@ public class ZLMRunner implements CommandLineRunner {
49 @Override 49 @Override
50 public void run(String... strings) throws Exception { 50 public void run(String... strings) throws Exception {
51 mediaServerService.clearMediaServerForOnline(); 51 mediaServerService.clearMediaServerForOnline();
52 - if (mediaServerService.getDefaultMediaServer() == null) { 52 + MediaServerItem defaultMediaServer = mediaServerService.getDefaultMediaServer();
  53 + if (defaultMediaServer == null) {
53 mediaServerService.addToDatabase(mediaConfig.getMediaSerItem()); 54 mediaServerService.addToDatabase(mediaConfig.getMediaSerItem());
  55 + }else {
  56 + MediaServerItem mediaSerItem = mediaConfig.getMediaSerItem();
  57 + mediaSerItem.setId(defaultMediaServer.getId());
  58 + mediaServerService.updateToDatabase(mediaSerItem);
54 } 59 }
55 60
56 // 订阅 zlm启动事件, 新的zlm也会从这里进入系统 61 // 订阅 zlm启动事件, 新的zlm也会从这里进入系统
@@ -61,7 +66,7 @@ public class ZLMRunner implements CommandLineRunner { @@ -61,7 +66,7 @@ public class ZLMRunner implements CommandLineRunner {
61 if (startGetMedia != null) { 66 if (startGetMedia != null) {
62 startGetMedia.remove(zlmServerConfig.getGeneralMediaServerId()); 67 startGetMedia.remove(zlmServerConfig.getGeneralMediaServerId());
63 } 68 }
64 - mediaServerService.handLeZLMServerConfig(zlmServerConfig); 69 + mediaServerService.zlmServerOnline(zlmServerConfig);
65 } 70 }
66 }); 71 });
67 72
@@ -107,7 +112,7 @@ public class ZLMRunner implements CommandLineRunner { @@ -107,7 +112,7 @@ public class ZLMRunner implements CommandLineRunner {
107 zlmServerConfig.setIp(mediaServerItem.getIp()); 112 zlmServerConfig.setIp(mediaServerItem.getIp());
108 zlmServerConfig.setHttpPort(mediaServerItem.getHttpPort()); 113 zlmServerConfig.setHttpPort(mediaServerItem.getHttpPort());
109 startGetMedia.remove(mediaServerItem.getId()); 114 startGetMedia.remove(mediaServerItem.getId());
110 - mediaServerService.handLeZLMServerConfig(zlmServerConfig); 115 + mediaServerService.zlmServerOnline(zlmServerConfig);
111 } 116 }
112 } 117 }
113 118
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMServerConfig.java
@@ -32,7 +32,7 @@ public class ZLMServerConfig { @@ -32,7 +32,7 @@ public class ZLMServerConfig {
32 private String generalMaxStreamWaitMS; 32 private String generalMaxStreamWaitMS;
33 33
34 @JSONField(name = "general.streamNoneReaderDelayMS") 34 @JSONField(name = "general.streamNoneReaderDelayMS")
35 - private String generalStreamNoneReaderDelayMS; 35 + private int generalStreamNoneReaderDelayMS;
36 36
37 @JSONField(name = "ip") 37 @JSONField(name = "ip")
38 private String ip; 38 private String ip;
@@ -296,11 +296,11 @@ public class ZLMServerConfig { @@ -296,11 +296,11 @@ public class ZLMServerConfig {
296 this.generalMaxStreamWaitMS = generalMaxStreamWaitMS; 296 this.generalMaxStreamWaitMS = generalMaxStreamWaitMS;
297 } 297 }
298 298
299 - public String getGeneralStreamNoneReaderDelayMS() { 299 + public int getGeneralStreamNoneReaderDelayMS() {
300 return generalStreamNoneReaderDelayMS; 300 return generalStreamNoneReaderDelayMS;
301 } 301 }
302 302
303 - public void setGeneralStreamNoneReaderDelayMS(String generalStreamNoneReaderDelayMS) { 303 + public void setGeneralStreamNoneReaderDelayMS(int generalStreamNoneReaderDelayMS) {
304 this.generalStreamNoneReaderDelayMS = generalStreamNoneReaderDelayMS; 304 this.generalStreamNoneReaderDelayMS = generalStreamNoneReaderDelayMS;
305 } 305 }
306 306
src/main/java/com/genersoft/iot/vmp/media/zlm/dto/MediaServerItem.java
@@ -37,7 +37,7 @@ public class MediaServerItem{ @@ -37,7 +37,7 @@ public class MediaServerItem{
37 37
38 private String secret; 38 private String secret;
39 39
40 - private String streamNoneReaderDelayMS; 40 + private int streamNoneReaderDelayMS;
41 41
42 private boolean rtpEnable; 42 private boolean rtpEnable;
43 43
@@ -206,11 +206,11 @@ public class MediaServerItem{ @@ -206,11 +206,11 @@ public class MediaServerItem{
206 this.secret = secret; 206 this.secret = secret;
207 } 207 }
208 208
209 - public String getStreamNoneReaderDelayMS() { 209 + public int getStreamNoneReaderDelayMS() {
210 return streamNoneReaderDelayMS; 210 return streamNoneReaderDelayMS;
211 } 211 }
212 212
213 - public void setStreamNoneReaderDelayMS(String streamNoneReaderDelayMS) { 213 + public void setStreamNoneReaderDelayMS(int streamNoneReaderDelayMS) {
214 this.streamNoneReaderDelayMS = streamNoneReaderDelayMS; 214 this.streamNoneReaderDelayMS = streamNoneReaderDelayMS;
215 } 215 }
216 216
src/main/java/com/genersoft/iot/vmp/service/IMediaServerService.java
@@ -28,7 +28,7 @@ public interface IMediaServerService { @@ -28,7 +28,7 @@ public interface IMediaServerService {
28 * @param zlmServerConfig 28 * @param zlmServerConfig
29 * @return 29 * @return
30 */ 30 */
31 - void handLeZLMServerConfig(ZLMServerConfig zlmServerConfig); 31 + void zlmServerOnline(ZLMServerConfig zlmServerConfig);
32 32
33 MediaServerItem getMediaServerForMinimumLoad(); 33 MediaServerItem getMediaServerForMinimumLoad();
34 34
@@ -56,6 +56,8 @@ public interface IMediaServerService { @@ -56,6 +56,8 @@ public interface IMediaServerService {
56 56
57 int addToDatabase(MediaServerItem mediaSerItem); 57 int addToDatabase(MediaServerItem mediaSerItem);
58 58
  59 + int updateToDatabase(MediaServerItem mediaSerItem);
  60 +
59 void resetOnlineServerItem(MediaServerItem serverItem); 61 void resetOnlineServerItem(MediaServerItem serverItem);
60 62
61 WVPResult<MediaServerItem> checkMediaServer(String ip, int port, String secret); 63 WVPResult<MediaServerItem> checkMediaServer(String ip, int port, String secret);
src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java
@@ -285,7 +285,7 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR @@ -285,7 +285,7 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR
285 mediaServerItem.setId(zlmServerConfig.getGeneralMediaServerId()); 285 mediaServerItem.setId(zlmServerConfig.getGeneralMediaServerId());
286 zlmServerConfig.setIp(mediaServerItem.getIp()); 286 zlmServerConfig.setIp(mediaServerItem.getIp());
287 mediaServerMapper.add(mediaServerItem); 287 mediaServerMapper.add(mediaServerItem);
288 - handLeZLMServerConfig(zlmServerConfig); 288 + zlmServerOnline(zlmServerConfig);
289 result.setCode(0); 289 result.setCode(0);
290 result.setMsg("success"); 290 result.setMsg("success");
291 }else { 291 }else {
@@ -305,12 +305,19 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR @@ -305,12 +305,19 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR
305 return mediaServerMapper.add(mediaSerItem); 305 return mediaServerMapper.add(mediaSerItem);
306 } 306 }
307 307
  308 + @Override
  309 + public int updateToDatabase(MediaServerItem mediaSerItem) {
  310 + return mediaServerMapper.update(mediaSerItem);
  311 + }
  312 +
  313 +
  314 +
308 /** 315 /**
309 * 处理zlm上线 316 * 处理zlm上线
310 * @param zlmServerConfig zlm上线携带的参数 317 * @param zlmServerConfig zlm上线携带的参数
311 */ 318 */
312 @Override 319 @Override
313 - public void handLeZLMServerConfig(ZLMServerConfig zlmServerConfig) { 320 + public void zlmServerOnline(ZLMServerConfig zlmServerConfig) {
314 logger.info("[ ZLM:{} ]-[ {}:{} ]已连接", 321 logger.info("[ ZLM:{} ]-[ {}:{} ]已连接",
315 zlmServerConfig.getGeneralMediaServerId(), zlmServerConfig.getIp(), zlmServerConfig.getHttpPort()); 322 zlmServerConfig.getGeneralMediaServerId(), zlmServerConfig.getIp(), zlmServerConfig.getHttpPort());
316 323
src/main/java/com/genersoft/iot/vmp/storager/IVideoManagerStorager.java
@@ -50,6 +50,14 @@ public interface IVideoManagerStorager { @@ -50,6 +50,14 @@ public interface IVideoManagerStorager {
50 public void updateChannel(String deviceId, DeviceChannel channel); 50 public void updateChannel(String deviceId, DeviceChannel channel);
51 51
52 /** 52 /**
  53 + * 批量添加设备通道
  54 + *
  55 + * @param deviceId 设备id
  56 + * @param channels 多个通道
  57 + */
  58 + public void updateChannels(String deviceId, List<DeviceChannel> channels);
  59 +
  60 + /**
53 * 开始播放 61 * 开始播放
54 * @param deviceId 设备id 62 * @param deviceId 设备id
55 * @param channelId 通道ID 63 * @param channelId 通道ID
src/main/java/com/genersoft/iot/vmp/storager/dao/DeviceChannelMapper.java
@@ -25,30 +25,30 @@ public interface DeviceChannelMapper { @@ -25,30 +25,30 @@ public interface DeviceChannelMapper {
25 @Update(value = {" <script>" + 25 @Update(value = {" <script>" +
26 "UPDATE device_channel " + 26 "UPDATE device_channel " +
27 "SET updateTime='${updateTime}'" + 27 "SET updateTime='${updateTime}'" +
28 - "<if test=\"name != null\">, name='${name}'</if>" +  
29 - "<if test=\"manufacture != null\">, manufacture='${manufacture}'</if>" +  
30 - "<if test=\"model != null\">, model='${model}'</if>" +  
31 - "<if test=\"owner != null\">, owner='${owner}'</if>" +  
32 - "<if test=\"civilCode != null\">, civilCode='${civilCode}'</if>" +  
33 - "<if test=\"block != null\">, block='${block}'</if>" +  
34 - "<if test=\"address != null\">, address='${address}'</if>" +  
35 - "<if test=\"parental != null\">, parental=${parental}</if>" +  
36 - "<if test=\"parentId != null\">, parentId='${parentId}'</if>" +  
37 - "<if test=\"safetyWay != null\">, safetyWay=${safetyWay}</if>" +  
38 - "<if test=\"registerWay != null\">, registerWay=${registerWay}</if>" +  
39 - "<if test=\"certNum != null\">, certNum='${certNum}'</if>" +  
40 - "<if test=\"certifiable != null\">, certifiable=${certifiable}</if>" +  
41 - "<if test=\"errCode != null\">, errCode=${errCode}</if>" +  
42 - "<if test=\"secrecy != null\">, secrecy='${secrecy}'</if>" +  
43 - "<if test=\"ipAddress != null\">, ipAddress='${ipAddress}'</if>" +  
44 - "<if test=\"port != null\">, port=${port}</if>" +  
45 - "<if test=\"password != null\">, password='${password}'</if>" +  
46 - "<if test=\"PTZType != null\">, PTZType=${PTZType}</if>" +  
47 - "<if test=\"status != null\">, status='${status}'</if>" +  
48 - "<if test=\"streamId != null\">, streamId='${streamId}'</if>" +  
49 - "<if test=\"hasAudio != null\">, hasAudio=${hasAudio}</if>" +  
50 - "<if test=\"longitude != null\">, longitude=${longitude}</if>" +  
51 - "<if test=\"latitude != null\">, latitude=${latitude}</if>" + 28 + "<if test='name != null'>, name='${name}'</if>" +
  29 + "<if test='manufacture != null'>, manufacture='${manufacture}'</if>" +
  30 + "<if test='model != null'>, model='${model}'</if>" +
  31 + "<if test='owner != null'>, owner='${owner}'</if>" +
  32 + "<if test='civilCode != null'>, civilCode='${civilCode}'</if>" +
  33 + "<if test='block != null'>, block='${block}'</if>" +
  34 + "<if test='address != null'>, address='${address}'</if>" +
  35 + "<if test='parental != null'>, parental=${parental}</if>" +
  36 + "<if test='parentId != null'>, parentId='${parentId}'</if>" +
  37 + "<if test='safetyWay != null'>, safetyWay=${safetyWay}</if>" +
  38 + "<if test='registerWay != null'>, registerWay=${registerWay}</if>" +
  39 + "<if test='certNum != null'>, certNum='${certNum}'</if>" +
  40 + "<if test='certifiable != null'>, certifiable=${certifiable}</if>" +
  41 + "<if test='errCode != null'>, errCode=${errCode}</if>" +
  42 + "<if test='secrecy != null'>, secrecy='${secrecy}'</if>" +
  43 + "<if test='ipAddress != null'>, ipAddress='${ipAddress}'</if>" +
  44 + "<if test='port != null'>, port=${port}</if>" +
  45 + "<if test='password != null'>, password='${password}'</if>" +
  46 + "<if test='PTZType != null'>, PTZType=${PTZType}</if>" +
  47 + "<if test='status != null'>, status='${status}'</if>" +
  48 + "<if test='streamId != null'>, streamId='${streamId}'</if>" +
  49 + "<if test='hasAudio != null'>, hasAudio=${hasAudio}</if>" +
  50 + "<if test='longitude != null'>, longitude=${longitude}</if>" +
  51 + "<if test='latitude != null'>, latitude=${latitude}</if>" +
52 "WHERE deviceId='${deviceId}' AND channelId='${channelId}'"+ 52 "WHERE deviceId='${deviceId}' AND channelId='${channelId}'"+
53 " </script>"}) 53 " </script>"})
54 int update(DeviceChannel channel); 54 int update(DeviceChannel channel);
@@ -57,16 +57,19 @@ public interface DeviceChannelMapper { @@ -57,16 +57,19 @@ public interface DeviceChannelMapper {
57 "SELECT * FROM ( "+ 57 "SELECT * FROM ( "+
58 " SELECT * , (SELECT count(0) FROM device_channel WHERE parentId=dc.channelId) as subCount FROM device_channel dc " + 58 " SELECT * , (SELECT count(0) FROM device_channel WHERE parentId=dc.channelId) as subCount FROM device_channel dc " +
59 " WHERE dc.deviceId=#{deviceId} " + 59 " WHERE dc.deviceId=#{deviceId} " +
60 - " <if test=\"query != null\"> AND (dc.channelId LIKE '%${query}%' OR dc.name LIKE '%${query}%' OR dc.name LIKE '%${query}%')</if> " +  
61 - " <if test=\"parentChannelId != null\"> AND dc.parentId=#{parentChannelId} </if> " +  
62 - " <if test=\"online == true\" > AND dc.status=1</if>" +  
63 - " <if test=\"online == false\" > AND dc.status=0</if>) dcr" + 60 + " <if test='query != null'> AND (dc.channelId LIKE '%${query}%' OR dc.name LIKE '%${query}%' OR dc.name LIKE '%${query}%')</if> " +
  61 + " <if test='parentChannelId != null'> AND dc.parentId=#{parentChannelId} </if> " +
  62 + " <if test='online == true' > AND dc.status=1</if>" +
  63 + " <if test='online == false' > AND dc.status=0</if>) dcr" +
64 " WHERE 1=1 " + 64 " WHERE 1=1 " +
65 - " <if test=\"hasSubChannel == true\" > AND subCount >0</if>" +  
66 - " <if test=\"hasSubChannel == false\" > AND subCount=0</if>" + 65 + " <if test='hasSubChannel == true' > AND subCount >0</if>" +
  66 + " <if test='hasSubChannel == false' > AND subCount=0</if>" +
67 " ORDER BY channelId ASC" + 67 " ORDER BY channelId ASC" +
68 " </script>"}) 68 " </script>"})
69 - List<DeviceChannel> queryChannelsByDeviceId(String deviceId, String parentChannelId, String query, Boolean hasSubChannel, Boolean online); 69 + List<DeviceChannel> queryChannels(String deviceId, String parentChannelId, String query, Boolean hasSubChannel, Boolean online);
  70 +
  71 + @Select("SELECT * FROM device_channel WHERE deviceId=#{deviceId}")
  72 + List<DeviceChannel> queryChannelsByDeviceId(String deviceId);
70 73
71 @Select("SELECT * FROM device_channel WHERE deviceId=#{deviceId} AND channelId=#{channelId}") 74 @Select("SELECT * FROM device_channel WHERE deviceId=#{deviceId} AND channelId=#{channelId}")
72 DeviceChannel queryChannel(String deviceId, String channelId); 75 DeviceChannel queryChannel(String deviceId, String channelId);
@@ -92,15 +95,15 @@ public interface DeviceChannelMapper { @@ -92,15 +95,15 @@ public interface DeviceChannelMapper {
92 "FROM device_channel dc " + 95 "FROM device_channel dc " +
93 "LEFT JOIN device de ON dc.deviceId = de.deviceId " + 96 "LEFT JOIN device de ON dc.deviceId = de.deviceId " +
94 " WHERE 1=1 " + 97 " WHERE 1=1 " +
95 - " <if test=\"query != null\"> AND (dc.channelId LIKE '%${query}%' OR dc.name LIKE '%${query}%' OR dc.name LIKE '%${query}%')</if> " +  
96 - " <if test=\"online == true\" > AND dc.status=1</if> " +  
97 - " <if test=\"online == false\" > AND dc.status=0</if> " + 98 + " <if test='query != null'> AND (dc.channelId LIKE '%${query}%' OR dc.name LIKE '%${query}%' OR dc.name LIKE '%${query}%')</if> " +
  99 + " <if test='online == true' > AND dc.status=1</if> " +
  100 + " <if test='online == false' > AND dc.status=0</if> " +
98 ") dcr" + 101 ") dcr" +
99 " WHERE 1=1 " + 102 " WHERE 1=1 " +
100 - " <if test=\"hasSubChannel!= null and hasSubChannel == true\" > AND subCount >0</if> " +  
101 - " <if test=\"hasSubChannel!= null and hasSubChannel == false\" > AND subCount=0</if> " +  
102 - " <if test=\"platformId != null and inPlatform == true \" > AND platformId='${platformId}'</if> " +  
103 - " <if test=\"platformId != null and inPlatform == false \" > AND (platformId != '${platformId}' OR platformId is NULL ) </if> " + 103 + " <if test='hasSubChannel!= null and hasSubChannel == true' > AND subCount >0</if> " +
  104 + " <if test='hasSubChannel!= null and hasSubChannel == false' > AND subCount=0</if> " +
  105 + " <if test='platformId != null and inPlatform == true ' > AND platformId='${platformId}'</if> " +
  106 + " <if test='platformId != null and inPlatform == false ' > AND (platformId != '${platformId}' OR platformId is NULL ) </if> " +
104 " ORDER BY deviceId, channelId ASC" + 107 " ORDER BY deviceId, channelId ASC" +
105 " </script>"}) 108 " </script>"})
106 109
@@ -114,4 +117,55 @@ public interface DeviceChannelMapper { @@ -114,4 +117,55 @@ public interface DeviceChannelMapper {
114 117
115 @Update(value = {"UPDATE device_channel SET status=1 WHERE deviceId=#{deviceId} AND channelId=#{channelId}"}) 118 @Update(value = {"UPDATE device_channel SET status=1 WHERE deviceId=#{deviceId} AND channelId=#{channelId}"})
116 void online(String deviceId, String channelId); 119 void online(String deviceId, String channelId);
  120 +
  121 + @Insert("<script> " +
  122 + "insert into device_channel " +
  123 + "(channelId, deviceId, name, manufacture, model, owner, civilCode, block, " +
  124 + " address, parental, parentId, safetyWay, registerWay, certNum, certifiable, errCode, secrecy, " +
  125 + " ipAddress, port, password, PTZType, status, streamId, longitude, latitude, createTime, updateTime) " +
  126 + "values " +
  127 + "<foreach collection='addChannels' index='index' item='item' separator=','> " +
  128 + "('${item.channelId}', '${item.deviceId}', '${item.name}', '${item.manufacture}', '${item.model}', " +
  129 + "'${item.owner}', '${item.civilCode}', '${item.block}'," +
  130 + "'${item.address}', ${item.parental}, '${item.parentId}', ${item.safetyWay}, ${item.registerWay}, " +
  131 + "'${item.certNum}', ${item.certifiable}, ${item.errCode}, '${item.secrecy}', " +
  132 + "'${item.ipAddress}', ${item.port}, '${item.password}', ${item.PTZType}, ${item.status}, " +
  133 + "'${item.streamId}', ${item.longitude}, ${item.latitude},'${item.createTime}', '${item.updateTime}')" +
  134 + "</foreach> " +
  135 + "</script>")
  136 + void batchAdd(List<DeviceChannel> addChannels);
  137 +
  138 + @Update({"<script>" +
  139 + "<foreach collection='updateChannels' item='item' separator=';'>" +
  140 + " UPDATE" +
  141 + " device_channel" +
  142 + " SET updateTime='${item.updateTime}'" +
  143 + "<if test='item.name != null'>, name='${item.name}'</if>" +
  144 + "<if test='item.manufacture != null'>, manufacture='${item.manufacture}'</if>" +
  145 + "<if test='item.model != null'>, model='${item.model}'</if>" +
  146 + "<if test='item.owner != null'>, owner='${item.owner}'</if>" +
  147 + "<if test='item.civilCode != null'>, civilCode='${item.civilCode}'</if>" +
  148 + "<if test='item.block != null'>, block='${item.block}'</if>" +
  149 + "<if test='item.address != null'>, address='${item.address}'</if>" +
  150 + "<if test='item.parental != null'>, parental=${item.parental}</if>" +
  151 + "<if test='item.parentId != null'>, parentId='${item.parentId}'</if>" +
  152 + "<if test='item.safetyWay != null'>, safetyWay=${item.safetyWay}</if>" +
  153 + "<if test='item.registerWay != null'>, registerWay=${item.registerWay}</if>" +
  154 + "<if test='item.certNum != null'>, certNum='${item.certNum}'</if>" +
  155 + "<if test='item.certifiable != null'>, certifiable=${item.certifiable}</if>" +
  156 + "<if test='item.errCode != null'>, errCode=${item.errCode}</if>" +
  157 + "<if test='item.secrecy != null'>, secrecy='${item.secrecy}'</if>" +
  158 + "<if test='item.ipAddress != null'>, ipAddress='${item.ipAddress}'</if>" +
  159 + "<if test='item.port != null'>, port=${item.port}</if>" +
  160 + "<if test='item.password != null'>, password='${item.password}'</if>" +
  161 + "<if test='item.PTZType != null'>, PTZType=${item.PTZType}</if>" +
  162 + "<if test='item.status != null'>, status='${item.status}'</if>" +
  163 + "<if test='item.streamId != null'>, streamId='${item.streamId}'</if>" +
  164 + "<if test='item.hasAudio != null'>, hasAudio=${item.hasAudio}</if>" +
  165 + "<if test='item.longitude != null'>, longitude=${item.longitude}</if>" +
  166 + "<if test='item.latitude != null'>, latitude=${item.latitude}</if>" +
  167 + "WHERE deviceId=#{item.deviceId} AND channelId=#{item.channelId}"+
  168 + "</foreach>" +
  169 + "</script>"})
  170 + void batchUpdate(List<DeviceChannel> updateChannels);
117 } 171 }
src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStoragerImpl.java
@@ -152,6 +152,49 @@ public class VideoManagerStoragerImpl implements IVideoManagerStorager { @@ -152,6 +152,49 @@ public class VideoManagerStoragerImpl implements IVideoManagerStorager {
152 } 152 }
153 153
154 @Override 154 @Override
  155 + public void updateChannels(String deviceId, List<DeviceChannel> channels) {
  156 + List<DeviceChannel> addChannels = new ArrayList<>();
  157 + List<DeviceChannel> updateChannels = new ArrayList<>();
  158 + HashMap<String, DeviceChannel> channelsInStore = new HashMap<>();
  159 + if (channels != null && channels.size() > 0) {
  160 + List<DeviceChannel> channelList = deviceChannelMapper.queryChannelsByDeviceId(deviceId);
  161 + if (channelList.size() == 0) {
  162 + for (DeviceChannel channel : channels) {
  163 + channel.setDeviceId(deviceId);
  164 + channel.setStreamId(streamSession.getStreamId(deviceId, channel.getChannelId()));
  165 + String now = this.format.format(System.currentTimeMillis());
  166 + channel.setUpdateTime(now);
  167 + channel.setCreateTime(now);
  168 + addChannels.add(channel);
  169 + }
  170 + }else {
  171 + for (DeviceChannel deviceChannel : channelList) {
  172 + channelsInStore.put(deviceChannel.getChannelId(), deviceChannel);
  173 + }
  174 + for (DeviceChannel channel : channels) {
  175 + String channelId = channel.getChannelId();
  176 + channel.setDeviceId(deviceId);
  177 + channel.setStreamId(streamSession.getStreamId(deviceId, channel.getChannelId()));
  178 + String now = this.format.format(System.currentTimeMillis());
  179 + channel.setUpdateTime(now);
  180 + if (channelsInStore.get(channel.getChannelId()) != null) {
  181 + updateChannels.add(channel);
  182 + }else {
  183 + addChannels.add(channel);
  184 + channel.setCreateTime(now);
  185 + }
  186 + }
  187 + }
  188 + if (addChannels.size() > 0) {
  189 + deviceChannelMapper.batchAdd(addChannels);
  190 + }
  191 + if (updateChannels.size() > 0) {
  192 + deviceChannelMapper.batchUpdate(updateChannels);
  193 + }
  194 + }
  195 + }
  196 +
  197 + @Override
155 public void deviceChannelOnline(String deviceId, String channelId) { 198 public void deviceChannelOnline(String deviceId, String channelId) {
156 deviceChannelMapper.online(deviceId, channelId); 199 deviceChannelMapper.online(deviceId, channelId);
157 } 200 }
@@ -186,19 +229,19 @@ public class VideoManagerStoragerImpl implements IVideoManagerStorager { @@ -186,19 +229,19 @@ public class VideoManagerStoragerImpl implements IVideoManagerStorager {
186 public PageInfo queryChannelsByDeviceId(String deviceId, String query, Boolean hasSubChannel, Boolean online, int page, int count) { 229 public PageInfo queryChannelsByDeviceId(String deviceId, String query, Boolean hasSubChannel, Boolean online, int page, int count) {
187 // 获取到所有正在播放的流 230 // 获取到所有正在播放的流
188 PageHelper.startPage(page, count); 231 PageHelper.startPage(page, count);
189 - List<DeviceChannel> all = deviceChannelMapper.queryChannelsByDeviceId(deviceId, null, query, hasSubChannel, online); 232 + List<DeviceChannel> all = deviceChannelMapper.queryChannels(deviceId, null, query, hasSubChannel, online);
190 return new PageInfo<>(all); 233 return new PageInfo<>(all);
191 } 234 }
192 235
193 @Override 236 @Override
194 public List<DeviceChannel> queryChannelsByDeviceId(String deviceId) { 237 public List<DeviceChannel> queryChannelsByDeviceId(String deviceId) {
195 - return deviceChannelMapper.queryChannelsByDeviceId(deviceId, null,null, null, null); 238 + return deviceChannelMapper.queryChannels(deviceId, null,null, null, null);
196 } 239 }
197 240
198 @Override 241 @Override
199 public PageInfo<DeviceChannel> querySubChannels(String deviceId, String parentChannelId, String query, Boolean hasSubChannel, String online, int page, int count) { 242 public PageInfo<DeviceChannel> querySubChannels(String deviceId, String parentChannelId, String query, Boolean hasSubChannel, String online, int page, int count) {
200 PageHelper.startPage(page, count); 243 PageHelper.startPage(page, count);
201 - List<DeviceChannel> all = deviceChannelMapper.queryChannelsByDeviceId(deviceId, parentChannelId, null, null, null); 244 + List<DeviceChannel> all = deviceChannelMapper.queryChannels(deviceId, parentChannelId, null, null, null);
202 return new PageInfo<>(all); 245 return new PageInfo<>(all);
203 } 246 }
204 247
src/main/resources/all-application.yml
@@ -38,6 +38,9 @@ spring: @@ -38,6 +38,9 @@ spring:
38 password: 38 password:
39 type: com.alibaba.druid.pool.DruidDataSource 39 type: com.alibaba.druid.pool.DruidDataSource
40 driver-class-name: org.sqlite.JDBC 40 driver-class-name: org.sqlite.JDBC
  41 + journal_mode: WAL
  42 + synchronous: NORMAL
  43 + transaction_mode: IMMEDIATE
41 max-active: 1 44 max-active: 1
42 min-idle: 1 45 min-idle: 1
43 46
src/main/resources/application-dev.yml
@@ -26,6 +26,9 @@ spring: @@ -26,6 +26,9 @@ spring:
26 password: 26 password:
27 type: com.alibaba.druid.pool.DruidDataSource 27 type: com.alibaba.druid.pool.DruidDataSource
28 driver-class-name: org.sqlite.JDBC 28 driver-class-name: org.sqlite.JDBC
  29 + journal_mode: WAL
  30 + synchronous: NORMAL
  31 + transaction_mode: IMMEDIATE
29 max-active: 1 32 max-active: 1
30 min-idle: 1 33 min-idle: 1
31 34
src/main/resources/application-docker.yml
@@ -26,6 +26,9 @@ spring: @@ -26,6 +26,9 @@ spring:
26 password: 26 password:
27 type: com.alibaba.druid.pool.DruidDataSource 27 type: com.alibaba.druid.pool.DruidDataSource
28 driver-class-name: org.sqlite.JDBC 28 driver-class-name: org.sqlite.JDBC
  29 + journal_mode: WAL
  30 + synchronous: NORMAL
  31 + transaction_mode: IMMEDIATE
29 max-active: 1 32 max-active: 1
30 min-idle: 1 33 min-idle: 1
31 34