Commit 46cf650a863f9181f78c09f9b1146972844449bc

Authored by 648540858
1 parent b6702f7c

优化通道选择是通道的查询

src/main/java/com/genersoft/iot/vmp/service/impl/StreamProxyServiceImpl.java
@@ -146,20 +146,23 @@ public class StreamProxyServiceImpl implements IStreamProxyService { @@ -146,20 +146,23 @@ public class StreamProxyServiceImpl implements IStreamProxyService {
146 result.append(", 关联国标平台[ " + param.getPlatformGbId() + " ]失败"); 146 result.append(", 关联国标平台[ " + param.getPlatformGbId() + " ]失败");
147 } 147 }
148 } 148 }
149 - // 查找开启了全部直播流共享的上级平台  
150 - List<ParentPlatform> parentPlatforms = parentPlatformMapper.selectAllAhareAllLiveStream();  
151 - if (parentPlatforms.size() > 0) {  
152 - for (ParentPlatform parentPlatform : parentPlatforms) {  
153 - param.setPlatformId(parentPlatform.getServerGBId());  
154 - param.setCatalogId(parentPlatform.getCatalogId());  
155 - String stream = param.getStream();  
156 - StreamProxyItem streamProxyItems = platformGbStreamMapper.selectOne(param.getApp(), stream, parentPlatform.getServerGBId());  
157 - if (streamProxyItems == null) {  
158 - platformGbStreamMapper.add(param);  
159 - eventPublisher.catalogEventPublishForStream(parentPlatform.getServerGBId(), param, CatalogEvent.ADD); 149 + if (!StringUtils.isEmpty(param.getGbId())) {
  150 + // 查找开启了全部直播流共享的上级平台
  151 + List<ParentPlatform> parentPlatforms = parentPlatformMapper.selectAllAhareAllLiveStream();
  152 + if (parentPlatforms.size() > 0) {
  153 + for (ParentPlatform parentPlatform : parentPlatforms) {
  154 + param.setPlatformId(parentPlatform.getServerGBId());
  155 + param.setCatalogId(parentPlatform.getCatalogId());
  156 + String stream = param.getStream();
  157 + StreamProxyItem streamProxyItems = platformGbStreamMapper.selectOne(param.getApp(), stream, parentPlatform.getServerGBId());
  158 + if (streamProxyItems == null) {
  159 + platformGbStreamMapper.add(param);
  160 + eventPublisher.catalogEventPublishForStream(parentPlatform.getServerGBId(), param, CatalogEvent.ADD);
  161 + }
160 } 162 }
161 } 163 }
162 } 164 }
  165 +
163 wvpResult.setMsg(result.toString()); 166 wvpResult.setMsg(result.toString());
164 return wvpResult; 167 return wvpResult;
165 } 168 }
src/main/java/com/genersoft/iot/vmp/storager/dao/DeviceChannelMapper.java
@@ -96,7 +96,7 @@ public interface DeviceChannelMapper { @@ -96,7 +96,7 @@ public interface DeviceChannelMapper {
96 "SELECT * FROM ( "+ 96 "SELECT * FROM ( "+
97 " SELECT dc.channelId, dc.deviceId, dc.name, de.manufacturer, de.hostAddress, " + 97 " SELECT dc.channelId, dc.deviceId, dc.name, de.manufacturer, de.hostAddress, " +
98 "(SELECT count(0) FROM device_channel WHERE parentId=dc.channelId) as subCount, " + 98 "(SELECT count(0) FROM device_channel WHERE parentId=dc.channelId) as subCount, " +
99 - "(SELECT pc.platformId FROM platform_gb_channel pc WHERE pc.deviceId=dc.deviceId AND pc.channelId = dc.channelId ) as platformId, " + 99 + "(SELECT pc.platformId FROM platform_gb_channel pc WHERE pc.deviceId=dc.deviceId AND pc.channelId = dc.channelId AND pc.platformId = #{platformId}) as platformId, " +
100 "(SELECT pc.catalogId FROM platform_gb_channel pc WHERE pc.deviceId=dc.deviceId AND pc.channelId = dc.channelId ) as catalogId " + 100 "(SELECT pc.catalogId FROM platform_gb_channel pc WHERE pc.deviceId=dc.deviceId AND pc.channelId = dc.channelId ) as catalogId " +
101 "FROM device_channel dc " + 101 "FROM device_channel dc " +
102 "LEFT JOIN device de ON dc.deviceId = de.deviceId " + 102 "LEFT JOIN device de ON dc.deviceId = de.deviceId " +
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/platform/PlatformController.java
@@ -87,6 +87,65 @@ public class PlatformController { @@ -87,6 +87,65 @@ public class PlatformController {
87 } 87 }
88 88
89 /** 89 /**
  90 + * 添加上级平台信息
  91 + * @param parentPlatform
  92 + * @return
  93 + */
  94 + @ApiOperation("添加上级平台信息")
  95 + @ApiImplicitParams({
  96 + @ApiImplicitParam(name = "parentPlatform", value = "上级平台信息", dataTypeClass = ParentPlatform.class),
  97 + })
  98 + @PostMapping("/add")
  99 + @ResponseBody
  100 + public ResponseEntity<WVPResult<String>> addPlatform(@RequestBody ParentPlatform parentPlatform){
  101 +
  102 + if (logger.isDebugEnabled()) {
  103 + logger.debug("保存上级平台信息API调用");
  104 + }
  105 + WVPResult<String> wvpResult = new WVPResult<>();
  106 + if (StringUtils.isEmpty(parentPlatform.getName())
  107 + ||StringUtils.isEmpty(parentPlatform.getServerGBId())
  108 + ||StringUtils.isEmpty(parentPlatform.getServerGBDomain())
  109 + ||StringUtils.isEmpty(parentPlatform.getServerIP())
  110 + ||StringUtils.isEmpty(parentPlatform.getServerPort())
  111 + ||StringUtils.isEmpty(parentPlatform.getDeviceGBId())
  112 + ||StringUtils.isEmpty(parentPlatform.getExpires())
  113 + ||StringUtils.isEmpty(parentPlatform.getKeepTimeout())
  114 + ||StringUtils.isEmpty(parentPlatform.getTransport())
  115 + ||StringUtils.isEmpty(parentPlatform.getCharacterSet())
  116 + ){
  117 + wvpResult.setCode(-1);
  118 + wvpResult.setMsg("missing parameters");
  119 + return new ResponseEntity<>(wvpResult, HttpStatus.BAD_REQUEST);
  120 + }
  121 +
  122 + ParentPlatform parentPlatformOld = storager.queryParentPlatByServerGBId(parentPlatform.getServerGBId());
  123 + if (parentPlatformOld != null) {
  124 + wvpResult.setCode(-1);
  125 + wvpResult.setMsg("平台 "+parentPlatform.getServerGBId()+" 已存在");
  126 + return new ResponseEntity<>(wvpResult, HttpStatus.OK);
  127 + }
  128 + boolean updateResult = storager.updateParentPlatform(parentPlatform);
  129 +
  130 + if (updateResult) {
  131 + // 保存时启用就发送注册
  132 + if (parentPlatform.isEnable()) {
  133 + // 只要保存就发送注册
  134 + commanderForPlatform.register(parentPlatform, null, null);
  135 + } else if (parentPlatformOld != null && parentPlatformOld.isEnable() && !parentPlatform.isEnable()){ // 关闭启用时注销
  136 + commanderForPlatform.unregister(parentPlatform, null, null);
  137 + }
  138 + wvpResult.setCode(0);
  139 + wvpResult.setMsg("success");
  140 + return new ResponseEntity<>(wvpResult, HttpStatus.OK);
  141 + } else {
  142 + wvpResult.setCode(-1);
  143 + wvpResult.setMsg("写入数据库失败");
  144 + return new ResponseEntity<>(wvpResult, HttpStatus.OK);
  145 + }
  146 + }
  147 +
  148 + /**
90 * 保存上级平台信息 149 * 保存上级平台信息
91 * @param parentPlatform 150 * @param parentPlatform
92 * @return 151 * @return
@@ -97,11 +156,12 @@ public class PlatformController { @@ -97,11 +156,12 @@ public class PlatformController {
97 }) 156 })
98 @PostMapping("/save") 157 @PostMapping("/save")
99 @ResponseBody 158 @ResponseBody
100 - public ResponseEntity<String> savePlatform(@RequestBody ParentPlatform parentPlatform){ 159 + public ResponseEntity<WVPResult<String>> savePlatform(@RequestBody ParentPlatform parentPlatform){
101 160
102 if (logger.isDebugEnabled()) { 161 if (logger.isDebugEnabled()) {
103 logger.debug("保存上级平台信息API调用"); 162 logger.debug("保存上级平台信息API调用");
104 } 163 }
  164 + WVPResult<String> wvpResult = new WVPResult<>();
105 if (StringUtils.isEmpty(parentPlatform.getName()) 165 if (StringUtils.isEmpty(parentPlatform.getName())
106 ||StringUtils.isEmpty(parentPlatform.getServerGBId()) 166 ||StringUtils.isEmpty(parentPlatform.getServerGBId())
107 ||StringUtils.isEmpty(parentPlatform.getServerGBDomain()) 167 ||StringUtils.isEmpty(parentPlatform.getServerGBDomain())
@@ -113,11 +173,10 @@ public class PlatformController { @@ -113,11 +173,10 @@ public class PlatformController {
113 ||StringUtils.isEmpty(parentPlatform.getTransport()) 173 ||StringUtils.isEmpty(parentPlatform.getTransport())
114 ||StringUtils.isEmpty(parentPlatform.getCharacterSet()) 174 ||StringUtils.isEmpty(parentPlatform.getCharacterSet())
115 ){ 175 ){
116 - return new ResponseEntity<>("missing parameters", HttpStatus.BAD_REQUEST); 176 + wvpResult.setCode(-1);
  177 + wvpResult.setMsg("missing parameters");
  178 + return new ResponseEntity<>(wvpResult, HttpStatus.BAD_REQUEST);
117 } 179 }
118 - // TODO 检查是否已经存在,且注册成功, 如果注册成功,需要先注销之前再,修改并注册  
119 -  
120 - // ParentPlatform parentPlatformOld = storager.queryParentPlatById(parentPlatform.getDeviceGBId());  
121 ParentPlatform parentPlatformOld = storager.queryParentPlatByServerGBId(parentPlatform.getServerGBId()); 180 ParentPlatform parentPlatformOld = storager.queryParentPlatByServerGBId(parentPlatform.getServerGBId());
122 181
123 boolean updateResult = storager.updateParentPlatform(parentPlatform); 182 boolean updateResult = storager.updateParentPlatform(parentPlatform);
@@ -130,9 +189,13 @@ public class PlatformController { @@ -130,9 +189,13 @@ public class PlatformController {
130 } else if (parentPlatformOld != null && parentPlatformOld.isEnable() && !parentPlatform.isEnable()){ // 关闭启用时注销 189 } else if (parentPlatformOld != null && parentPlatformOld.isEnable() && !parentPlatform.isEnable()){ // 关闭启用时注销
131 commanderForPlatform.unregister(parentPlatform, null, null); 190 commanderForPlatform.unregister(parentPlatform, null, null);
132 } 191 }
133 - return new ResponseEntity<>("success", HttpStatus.OK); 192 + wvpResult.setCode(0);
  193 + wvpResult.setMsg("success");
  194 + return new ResponseEntity<>(wvpResult, HttpStatus.OK);
134 } else { 195 } else {
135 - return new ResponseEntity<>("fail", HttpStatus.OK); 196 + wvpResult.setCode(0);
  197 + wvpResult.setMsg("写入数据库失败");
  198 + return new ResponseEntity<>(wvpResult, HttpStatus.OK);
136 } 199 }
137 } 200 }
138 201
web_src/src/components/dialog/platformEdit.vue
@@ -116,6 +116,7 @@ export default { @@ -116,6 +116,7 @@ export default {
116 showDialog: false, 116 showDialog: false,
117 isLoging: false, 117 isLoging: false,
118 onSubmit_text: "立即创建", 118 onSubmit_text: "立即创建",
  119 + saveUrl: "/api/platform/save",
119 120
120 platform: { 121 platform: {
121 id: null, 122 id: null,
@@ -163,6 +164,7 @@ export default { @@ -163,6 +164,7 @@ export default {
163 var that = this; 164 var that = this;
164 if (platform == null) { 165 if (platform == null) {
165 this.onSubmit_text = "立即创建"; 166 this.onSubmit_text = "立即创建";
  167 + this.saveUrl = "/api/platform/add";
166 this.$axios({ 168 this.$axios({
167 method: 'get', 169 method: 'get',
168 url:`/api/platform/server_config` 170 url:`/api/platform/server_config`
@@ -198,6 +200,7 @@ export default { @@ -198,6 +200,7 @@ export default {
198 this.platform.shareAllLiveStream = platform.shareAllLiveStream; 200 this.platform.shareAllLiveStream = platform.shareAllLiveStream;
199 this.platform.catalogId = platform.catalogId; 201 this.platform.catalogId = platform.catalogId;
200 this.onSubmit_text = "保存"; 202 this.onSubmit_text = "保存";
  203 + this.saveUrl = "/api/platform/save";
201 } 204 }
202 this.showDialog = true; 205 this.showDialog = true;
203 this.listChangeCallback = callback; 206 this.listChangeCallback = callback;
@@ -212,14 +215,13 @@ export default { @@ -212,14 +215,13 @@ export default {
212 this.platform.username = this.platform.deviceGBId ; 215 this.platform.username = this.platform.deviceGBId ;
213 }, 216 },
214 onSubmit: function () { 217 onSubmit: function () {
215 - console.log("onSubmit");  
216 var that = this; 218 var that = this;
217 that.$axios({ 219 that.$axios({
218 method: 'post', 220 method: 'post',
219 - url:`/api/platform/save`, 221 + url: this.saveUrl,
220 data: that.platform 222 data: that.platform
221 }).then(function (res) { 223 }).then(function (res) {
222 - if (res.data == "success") { 224 + if (res.data.code === 0) {
223 that.$message({ 225 that.$message({
224 showClose: true, 226 showClose: true,
225 message: "保存成功", 227 message: "保存成功",
@@ -229,6 +231,12 @@ export default { @@ -229,6 +231,12 @@ export default {
229 if (that.listChangeCallback != null) { 231 if (that.listChangeCallback != null) {
230 that.listChangeCallback(); 232 that.listChangeCallback();
231 } 233 }
  234 + }else {
  235 + that.$message({
  236 + showClose: true,
  237 + message: res.data.msg,
  238 + type: "error",
  239 + });
232 } 240 }
233 }).catch(function (error) { 241 }).catch(function (error) {
234 console.log(error); 242 console.log(error);